|
@ -197,7 +197,6 @@ async fn test_request_bank_items_sorted() { |
|
|
unknown: 0,
|
|
|
unknown: 0,
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
println!("{:?}", packets);
|
|
|
|
|
|
assert!(matches!(&packets[0], (_, SendShipPacket::BankItemList (bank_item_list))
|
|
|
assert!(matches!(&packets[0], (_, SendShipPacket::BankItemList (bank_item_list))
|
|
|
if bank_item_list.item_count == 3
|
|
|
if bank_item_list.item_count == 3
|
|
|
&& bank_item_list.size == 0x18 * 3 + 0x14
|
|
|
&& bank_item_list.size == 0x18 * 3 + 0x14
|
|
@ -208,12 +207,781 @@ async fn test_request_bank_items_sorted() { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//test_deposit_individual_item
|
|
|
|
|
|
//test_deposit_stacked_item
|
|
|
|
|
|
//test_deposit_stacked_item_with_stack_already_in_bank
|
|
|
|
|
|
//test_deposit_stacked_item_when_full_stack_in_bank
|
|
|
|
|
|
//test_deposit_individual_item_in_full_bank
|
|
|
|
|
|
//test_deposit_stacked_item_in_full_bank
|
|
|
|
|
|
//test_deposit_meseta
|
|
|
|
|
|
//test_deposit_too_much_meseta
|
|
|
|
|
|
//test_deposit_when_bank_has_max_meseta
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_individual_item() {
|
|
|
|
|
|
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::Weapon(
|
|
|
|
|
|
item::weapon::Weapon {
|
|
|
|
|
|
weapon: item::weapon::WeaponType::Saber,
|
|
|
|
|
|
grind: 0,
|
|
|
|
|
|
special: None,
|
|
|
|
|
|
attrs: [None, None, None],
|
|
|
|
|
|
tekked: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
slot: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
item::NewItemEntity {
|
|
|
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
|
|
|
item::weapon::Weapon {
|
|
|
|
|
|
weapon: item::weapon::WeaponType::Handgun,
|
|
|
|
|
|
grind: 0,
|
|
|
|
|
|
special: None,
|
|
|
|
|
|
attrs: [None, None, None],
|
|
|
|
|
|
tekked: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
slot: 1,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0x10001,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 0,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.len() == 1);
|
|
|
|
|
|
assert!(matches!(&packets[0], (_, SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
|
|
|
|
|
|
if player_no_longer_has_item.item_id == 0x10001
|
|
|
|
|
|
&& player_no_longer_has_item.amount == 0
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Bank {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(bank_item_ids == vec![item::ItemEntityId(2)]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_stacked_item() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..3 {
|
|
|
|
|
|
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: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0x10000,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 3,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.len() == 1);
|
|
|
|
|
|
assert!(matches!(&packets[0], (_, SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
|
|
|
|
|
|
if player_no_longer_has_item.item_id == 0x10000
|
|
|
|
|
|
&& player_no_longer_has_item.amount == 3
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Bank {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(bank_item_ids == vec![item::ItemEntityId(1), item::ItemEntityId(2), item::ItemEntityId(3)]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_partial_stacked_item() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..3 {
|
|
|
|
|
|
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: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0x10000,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 2,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.len() == 1);
|
|
|
|
|
|
assert!(matches!(&packets[0], (_, SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
|
|
|
|
|
|
if player_no_longer_has_item.item_id == 0x10000
|
|
|
|
|
|
&& player_no_longer_has_item.amount == 2
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Bank {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(bank_item_ids == vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
|
|
|
|
|
|
|
|
|
|
|
|
let inventory_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Inventory {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(inventory_item_ids == vec![item::ItemEntityId(3)]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_stacked_item_with_stack_already_in_bank() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..2 {
|
|
|
|
|
|
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: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
item::NewItemEntity {
|
|
|
|
|
|
item: item::ItemDetail::Tool(
|
|
|
|
|
|
item::tool::Tool {
|
|
|
|
|
|
tool: item::tool::ToolType::Monomate,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
location: item::ItemLocation::Bank {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
name: item::BankName("".into()),
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0x10000,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 2,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.len() == 1);
|
|
|
|
|
|
assert!(matches!(&packets[0], (_, SendShipPacket::Message(Message {msg: GameMessage::PlayerNoLongerHasItem(player_no_longer_has_item)}))
|
|
|
|
|
|
if player_no_longer_has_item.item_id == 0x10000
|
|
|
|
|
|
&& player_no_longer_has_item.amount == 2
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Bank {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(bank_item_ids == vec![item::ItemEntityId(1), item::ItemEntityId(2), item::ItemEntityId(3), item::ItemEntityId(4)]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_stacked_item_with_full_stack_in_bank() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..2 {
|
|
|
|
|
|
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: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..10 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
item::NewItemEntity {
|
|
|
|
|
|
item: item::ItemDetail::Tool(
|
|
|
|
|
|
item::tool::Tool {
|
|
|
|
|
|
tool: item::tool::ToolType::Monomate,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
location: item::ItemLocation::Bank {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
name: item::BankName("".into()),
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0x10000,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 2,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await;
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.is_err());
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Bank {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(bank_item_ids.len() == 10);
|
|
|
|
|
|
|
|
|
|
|
|
let inventory_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Inventory {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(inventory_item_ids == vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_individual_item_in_full_bank() {
|
|
|
|
|
|
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::Weapon(
|
|
|
|
|
|
item::weapon::Weapon {
|
|
|
|
|
|
weapon: item::weapon::WeaponType::Vulcan,
|
|
|
|
|
|
grind: 0,
|
|
|
|
|
|
special: None,
|
|
|
|
|
|
attrs: [None, None, None],
|
|
|
|
|
|
tekked: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
location: item::ItemLocation::Inventory {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
slot: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..200 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
item::NewItemEntity {
|
|
|
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
|
|
|
item::weapon::Weapon {
|
|
|
|
|
|
weapon: item::weapon::WeaponType::Vulcan,
|
|
|
|
|
|
grind: 0,
|
|
|
|
|
|
special: None,
|
|
|
|
|
|
attrs: [None, None, None],
|
|
|
|
|
|
tekked: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
location: item::ItemLocation::Bank {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
name: item::BankName("".to_string())
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0x10000,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 0,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await;
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.is_err());
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Bank {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(bank_item_ids.len() == 200);
|
|
|
|
|
|
|
|
|
|
|
|
let inventory_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Inventory {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(inventory_item_ids == vec![item::ItemEntityId(1)]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_stacked_item_in_full_bank() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..2 {
|
|
|
|
|
|
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: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..200 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
item::NewItemEntity {
|
|
|
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
|
|
|
item::weapon::Weapon {
|
|
|
|
|
|
weapon: item::weapon::WeaponType::Vulcan,
|
|
|
|
|
|
grind: 0,
|
|
|
|
|
|
special: None,
|
|
|
|
|
|
attrs: [None, None, None],
|
|
|
|
|
|
tekked: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
location: item::ItemLocation::Bank {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
name: item::BankName("".to_string())
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0x10000,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 2,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await;
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.is_err());
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Bank {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(bank_item_ids.len() == 200);
|
|
|
|
|
|
|
|
|
|
|
|
let inventory_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Inventory {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(inventory_item_ids == vec![item::ItemEntityId(1), item::ItemEntityId(2)]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..2 {
|
|
|
|
|
|
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: 0,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..199 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
item::NewItemEntity {
|
|
|
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
|
|
|
item::weapon::Weapon {
|
|
|
|
|
|
weapon: item::weapon::WeaponType::Vulcan,
|
|
|
|
|
|
grind: 0,
|
|
|
|
|
|
special: None,
|
|
|
|
|
|
attrs: [None, None, None],
|
|
|
|
|
|
tekked: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
location: item::ItemLocation::Bank {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
name: item::BankName("".to_string())
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _ in 0..2 {
|
|
|
|
|
|
entity_gateway.create_item(
|
|
|
|
|
|
item::NewItemEntity {
|
|
|
|
|
|
item: item::ItemDetail::Tool(
|
|
|
|
|
|
item::tool::Tool {
|
|
|
|
|
|
tool: item::tool::ToolType::Monomate,
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
location: item::ItemLocation::Bank {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
name: item::BankName("".to_string())
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0x10000,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 2,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Bank {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(bank_item_ids.len() == 203);
|
|
|
|
|
|
|
|
|
|
|
|
let inventory_item_ids = items.iter()
|
|
|
|
|
|
.filter_map(|item| {
|
|
|
|
|
|
if let item::ItemLocation::Inventory {..} = item.location {
|
|
|
|
|
|
Some(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
assert!(inventory_item_ids.len() == 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_meseta() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
char1.meseta = 300;
|
|
|
|
|
|
entity_gateway.save_character(&char1).await;
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0xFFFFFFFF,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 0,
|
|
|
|
|
|
meseta_amount: 23,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let characters = entity_gateway.get_characters_by_user(&user1).await;
|
|
|
|
|
|
let char = characters[0].as_ref().unwrap();
|
|
|
|
|
|
println!("meseta {}", char.meseta);
|
|
|
|
|
|
assert!(char.meseta == 277);
|
|
|
|
|
|
assert!(char.bank_meseta == 23);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_too_much_meseta() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
char1.meseta = 300;
|
|
|
|
|
|
char1.bank_meseta = 999980;
|
|
|
|
|
|
entity_gateway.save_character(&char1).await;
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0xFFFFFFFF,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 0,
|
|
|
|
|
|
meseta_amount: 23,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let characters = entity_gateway.get_characters_by_user(&user1).await;
|
|
|
|
|
|
let char = characters[0].as_ref().unwrap();
|
|
|
|
|
|
println!("meseta {}", char.meseta);
|
|
|
|
|
|
assert!(char.meseta == 300);
|
|
|
|
|
|
assert!(char.bank_meseta == 999980);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_deposit_meseta_when_bank_is_maxed() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
char1.meseta = 300;
|
|
|
|
|
|
char1.bank_meseta = 999999;
|
|
|
|
|
|
entity_gateway.save_character(&char1).await;
|
|
|
|
|
|
|
|
|
|
|
|
let mut ship = ShipServerState::new(entity_gateway.clone());
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankRequest(BankRequest {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0xFFFFFFFF,
|
|
|
|
|
|
action: 0,
|
|
|
|
|
|
item_amount: 0,
|
|
|
|
|
|
meseta_amount: 23,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
|
|
|
|
let characters = entity_gateway.get_characters_by_user(&user1).await;
|
|
|
|
|
|
let char = characters[0].as_ref().unwrap();
|
|
|
|
|
|
println!("meseta {}", char.meseta);
|
|
|
|
|
|
assert!(char.meseta == 300);
|
|
|
|
|
|
assert!(char.bank_meseta == 999999);
|
|
|
|
|
|
}
|