|
|
@ -41,7 +41,7 @@ async fn test_bank_items_sent_in_character_login() { |
|
|
|
menu: BLOCK_MENU_ID,
|
|
|
|
item: 1,
|
|
|
|
})).await.unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
assert!(matches!(&packets[0], (_, SendShipPacket::FullCharacter(fc)) if fc.character.bank.items[0].data1[0..3] == [0x00, 0x08, 0x04] ));
|
|
|
|
}
|
|
|
|
|
|
|
@ -278,7 +278,7 @@ async fn test_deposit_individual_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| {
|
|
|
@ -345,7 +345,7 @@ async fn test_deposit_stacked_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| {
|
|
|
@ -412,7 +412,7 @@ async fn test_deposit_partial_stacked_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| {
|
|
|
@ -505,7 +505,7 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() { |
|
|
|
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| {
|
|
|
@ -579,7 +579,7 @@ async fn test_deposit_stacked_item_with_full_stack_in_bank() { |
|
|
|
})))).await;
|
|
|
|
|
|
|
|
assert!(packets.is_err());
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
.filter_map(|item| {
|
|
|
@ -671,7 +671,7 @@ async fn test_deposit_individual_item_in_full_bank() { |
|
|
|
})))).await;
|
|
|
|
|
|
|
|
assert!(packets.is_err());
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
.filter_map(|item| {
|
|
|
@ -761,7 +761,7 @@ async fn test_deposit_stacked_item_in_full_bank() { |
|
|
|
})))).await;
|
|
|
|
|
|
|
|
assert!(packets.is_err());
|
|
|
|
|
|
|
|
|
|
|
|
let items = entity_gateway.get_items_by_character(&char1).await;
|
|
|
|
let bank_item_ids = items.iter()
|
|
|
|
.filter_map(|item| {
|
|
|
@ -995,7 +995,774 @@ async fn test_deposit_meseta_when_bank_is_maxed() { |
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[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);
|
|
|
|
}
|