You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
4.5 KiB
140 lines
4.5 KiB
use elseware::common::serverstate::{ClientId, ServerState};
|
|
use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
|
|
use elseware::entity::item;
|
|
use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
|
|
use elseware::entity::character::{CharacterClass, SectionID};
|
|
|
|
use libpso::packet::ship::*;
|
|
use libpso::packet::messages::*;
|
|
|
|
#[path = "common.rs"]
|
|
mod common;
|
|
use common::*;
|
|
|
|
#[async_std::test]
|
|
async fn test_mag_feed() {
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
entity_gateway.create_item(
|
|
item::NewItemEntity {
|
|
item: item::ItemDetail::Mag(
|
|
item::mag::Mag::baby_mag(0)
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
slot: 0,
|
|
equipped: true,
|
|
}
|
|
}).await;
|
|
for _ in 0..7 {
|
|
entity_gateway.create_item(
|
|
item::NewItemEntity {
|
|
item: item::ItemDetail::Tool(
|
|
item::tool::Tool {
|
|
tool: item::tool::ToolType::Monomate,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
slot: 1,
|
|
equipped: false,
|
|
}
|
|
}).await;
|
|
}
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
.gateway(entity_gateway.clone())
|
|
.build();
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
join_lobby(&mut ship, ClientId(1)).await;
|
|
create_room(&mut ship, ClientId(1), "room", "").await;
|
|
|
|
for _ in 0..7 {
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerFeedMag(PlayerFeedMag {
|
|
client: 0,
|
|
target: 0,
|
|
mag_id: 0x10000,
|
|
item_id: 0x10001,
|
|
})))).await.unwrap().for_each(drop);
|
|
}
|
|
|
|
let p1_items = entity_gateway.get_items_by_character(&char1).await;
|
|
let mag = p1_items.get(0).unwrap();
|
|
match &mag.item {
|
|
item::ItemDetail::Mag(mag) => {
|
|
assert!(mag.level() == 7);
|
|
assert!(mag.def() == 5);
|
|
assert!(mag.pow() == 2);
|
|
assert!(mag.dex() == 0);
|
|
assert!(mag.mind() == 0);
|
|
}
|
|
_ => panic!()
|
|
}
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_mag_change_owner() {
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
char1.char_class = CharacterClass::RAmarl;
|
|
char1.section_id = SectionID::Redria;
|
|
entity_gateway.save_character(&char1).await;
|
|
char2.char_class = CharacterClass::FOmarl;
|
|
char2.section_id = SectionID::Whitill;
|
|
entity_gateway.save_character(&char2).await;
|
|
|
|
entity_gateway.create_item(
|
|
item::NewItemEntity {
|
|
item: item::ItemDetail::Mag(
|
|
item::mag::Mag::baby_mag(0)
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
slot: 0,
|
|
equipped: true,
|
|
}
|
|
}).await;
|
|
|
|
let mut ship = ShipServerState::builder()
|
|
.gateway(entity_gateway.clone())
|
|
.build();
|
|
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
|
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
|
join_lobby(&mut ship, ClientId(1)).await;
|
|
join_lobby(&mut ship, ClientId(2)).await;
|
|
create_room(&mut ship, ClientId(1), "room", "").await;
|
|
join_room(&mut ship, ClientId(2), 0).await;
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerDropItem(PlayerDropItem {
|
|
client: 0,
|
|
target: 0,
|
|
unknown1: 0,
|
|
map_area: 0,
|
|
item_id: 0x10000,
|
|
x: 0.0,
|
|
y: 0.0,
|
|
z: 0.0,
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
ship.handle(ClientId(2), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
|
|
client: 0,
|
|
target: 0,
|
|
item_id: 0x10000,
|
|
map_area: 0,
|
|
unknown: [0; 3]
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
let p2_items = entity_gateway.get_items_by_character(&char2).await;
|
|
let mag = p2_items.get(0).unwrap();
|
|
match &mag.item {
|
|
item::ItemDetail::Mag(mag) => {
|
|
assert!(mag.class == CharacterClass::FOmarl);
|
|
assert!(mag.id == SectionID::Whitill);
|
|
},
|
|
_ => panic!()
|
|
}
|
|
}
|