|
@ -995,7 +995,774 @@ async fn test_deposit_meseta_when_bank_is_maxed() { |
|
|
|
|
|
|
|
|
let characters = entity_gateway.get_characters_by_user(&user1).await;
|
|
|
let characters = entity_gateway.get_characters_by_user(&user1).await;
|
|
|
let char = characters[0].as_ref().unwrap();
|
|
|
let char = characters[0].as_ref().unwrap();
|
|
|
println!("meseta {}", char.meseta);
|
|
|
|
|
|
assert!(char.meseta == 300);
|
|
|
assert!(char.meseta == 300);
|
|
|
assert!(char.bank_meseta == 999999);
|
|
|
assert!(char.bank_meseta == 999999);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_withdraw_individual_item() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "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::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;
|
|
|
|
|
|
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::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: 0x20000,
|
|
|
|
|
|
action: 1,
|
|
|
|
|
|
item_amount: 0,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.len() == 1);
|
|
|
|
|
|
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
|
|
|
|
|
|
if create_item.item_id == 0x20000
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
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_withdraw_stacked_item() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "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::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;
|
|
|
|
|
|
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::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: 0x20000,
|
|
|
|
|
|
action: 1,
|
|
|
|
|
|
item_amount: 3,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.len() == 1);
|
|
|
|
|
|
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
|
|
|
|
|
|
if create_item.item_id == 0x10002
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
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), item::ItemEntityId(3)]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_withdraw_partial_stacked_item() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "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::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;
|
|
|
|
|
|
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::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: 0x20000,
|
|
|
|
|
|
action: 1,
|
|
|
|
|
|
item_amount: 2,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.len() == 1);
|
|
|
|
|
|
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
|
|
|
|
|
|
if create_item.item_id == 0x10002
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
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(3)]);
|
|
|
|
|
|
|
|
|
|
|
|
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_withdraw_stacked_item_with_stack_already_in_inventory() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "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;
|
|
|
|
|
|
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::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: 0x20000,
|
|
|
|
|
|
action: 1,
|
|
|
|
|
|
item_amount: 2,
|
|
|
|
|
|
meseta_amount: 0,
|
|
|
|
|
|
unknown: 0,
|
|
|
|
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
assert!(packets.len() == 1);
|
|
|
|
|
|
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)}))
|
|
|
|
|
|
if create_item.item_id == 0x10000
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
|
|
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), item::ItemEntityId(3), item::ItemEntityId(4)]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_withdraw_stacked_item_with_full_stack_in_inventory() {
|
|
|
|
|
|
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::Bank {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
name: item::BankName("".into()),
|
|
|
|
|
|
}
|
|
|
|
|
|
}).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::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: 0x20000,
|
|
|
|
|
|
action: 1,
|
|
|
|
|
|
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 == 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.len() == 10);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_withdraw_individual_item_in_full_inventory() {
|
|
|
|
|
|
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::Bank {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
name: item::BankName("".to_string())
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
|
|
|
|
|
|
for i in 0..30 {
|
|
|
|
|
|
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: i,
|
|
|
|
|
|
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: 0x20000,
|
|
|
|
|
|
action: 1,
|
|
|
|
|
|
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 == vec![item::ItemEntityId(1)]);
|
|
|
|
|
|
|
|
|
|
|
|
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() == 30);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_withdraw_stacked_item_in_full_inventory() {
|
|
|
|
|
|
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::Bank {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
name: item::BankName("".to_string())
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for i in 0..30 {
|
|
|
|
|
|
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: i,
|
|
|
|
|
|
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: 0x20000,
|
|
|
|
|
|
action: 1,
|
|
|
|
|
|
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 == 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.len() == 30);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_withdraw_stacked_item_in_full_inventory_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::Bank {
|
|
|
|
|
|
character_id: char1.id,
|
|
|
|
|
|
name: item::BankName("".to_string())
|
|
|
|
|
|
}
|
|
|
|
|
|
}).await;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for i in 0..29 {
|
|
|
|
|
|
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: i,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}).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: 29,
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BankInteraction(BankInteraction {
|
|
|
|
|
|
client: 0,
|
|
|
|
|
|
target: 0,
|
|
|
|
|
|
item_id: 0x20000,
|
|
|
|
|
|
action: 1,
|
|
|
|
|
|
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() == 0);
|
|
|
|
|
|
|
|
|
|
|
|
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() == 33);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_withdraw_meseta() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
char1.bank_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: 1,
|
|
|
|
|
|
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();
|
|
|
|
|
|
assert!(char.meseta == 23);
|
|
|
|
|
|
assert!(char.bank_meseta == 277);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_withdraw_too_much_meseta() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
char1.meseta = 999980;
|
|
|
|
|
|
char1.bank_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: 1,
|
|
|
|
|
|
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();
|
|
|
|
|
|
assert!(char.meseta == 999980);
|
|
|
|
|
|
assert!(char.bank_meseta == 300);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
|
|
async fn test_withdraw_meseta_inventory_is_maxed() {
|
|
|
|
|
|
let mut entity_gateway = InMemoryGateway::new();
|
|
|
|
|
|
|
|
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
char1.meseta = 999999;
|
|
|
|
|
|
char1.bank_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: 1,
|
|
|
|
|
|
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();
|
|
|
|
|
|
assert!(char.meseta == 999999);
|
|
|
|
|
|
assert!(char.bank_meseta == 300);
|
|
|
|
|
|
}
|