|
|
@ -3,6 +3,7 @@ use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; |
|
|
|
use elseware::entity::item;
|
|
|
|
use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
|
|
|
|
use elseware::ship::room::Difficulty;
|
|
|
|
use elseware::ship::items::manager::ItemManagerError;
|
|
|
|
|
|
|
|
use libpso::packet::ship::*;
|
|
|
|
use libpso::packet::messages::*;
|
|
|
@ -208,7 +209,7 @@ async fn test_player_buys_multiple_from_tool_shop() { |
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert!(c1_meseta.0 < 999999);
|
|
|
|
assert_eq!(c1_meseta.0, 999749);
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(p1_items.items.len(), 1);
|
|
|
|
p1_items.items[0].with_stacked(|item| {
|
|
|
@ -255,7 +256,47 @@ async fn test_player_buys_from_armor_shop() { |
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_to_shop() {
|
|
|
|
async fn test_player_sells_3_attr_weapon_to_shop() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
|
item::weapon::Weapon {
|
|
|
|
weapon: item::weapon::WeaponType::Vulcan,
|
|
|
|
grind: 5,
|
|
|
|
special: Some(item::weapon::WeaponSpecial::Charge),
|
|
|
|
attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
|
|
|
|
Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
|
|
|
|
Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
|
|
|
|
tekked: true,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 4406);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
@ -574,3 +615,535 @@ async fn test_units_disappear_from_shop_when_bought() { |
|
|
|
}).unwrap();
|
|
|
|
}).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_untekked_weapon() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
|
item::weapon::Weapon {
|
|
|
|
weapon: item::weapon::WeaponType::Vulcan,
|
|
|
|
grind: 5,
|
|
|
|
special: Some(item::weapon::WeaponSpecial::Charge),
|
|
|
|
attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
|
|
|
|
Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
|
|
|
|
Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
|
|
|
|
tekked: false,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_rare_item() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Weapon(
|
|
|
|
item::weapon::Weapon {
|
|
|
|
weapon: item::weapon::WeaponType::DarkFlow,
|
|
|
|
grind: 5,
|
|
|
|
special: None,
|
|
|
|
attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
|
|
|
|
Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
|
|
|
|
Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
|
|
|
|
tekked: true,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_partial_photon_drop_stack() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
let mut photon_drops = Vec::new();
|
|
|
|
for _ in 0..7usize {
|
|
|
|
photon_drops.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Tool(
|
|
|
|
item::tool::Tool {
|
|
|
|
tool: item::tool::ToolType::PhotonDrop,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
p1_inv.push(item::InventoryItemEntity::Stacked(photon_drops));
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 3,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 3000);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_basic_frame() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Armor(
|
|
|
|
item::armor::Armor {
|
|
|
|
armor: item::armor::ArmorType::Frame,
|
|
|
|
dfp: 0,
|
|
|
|
evp: 0,
|
|
|
|
slots: 0,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_max_frame() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Armor(
|
|
|
|
item::armor::Armor {
|
|
|
|
armor: item::armor::ArmorType::Frame,
|
|
|
|
dfp: 2,
|
|
|
|
evp: 2,
|
|
|
|
slots: 4,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 74);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_basic_barrier() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Shield(
|
|
|
|
item::shield::Shield {
|
|
|
|
shield: item::shield::ShieldType::Barrier,
|
|
|
|
dfp: 0,
|
|
|
|
evp: 0,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 69);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_max_barrier() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Shield(
|
|
|
|
item::shield::Shield {
|
|
|
|
shield: item::shield::ShieldType::Barrier,
|
|
|
|
dfp: 5,
|
|
|
|
evp: 5,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 122);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_1_star_minusminus_unit() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Unit(
|
|
|
|
item::unit::Unit {
|
|
|
|
unit: item::unit::UnitType::PriestMind,
|
|
|
|
modifier: Some(item::unit::UnitModifier::MinusMinus),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 125);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_5_star_plusplus_unit() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Unit(
|
|
|
|
item::unit::Unit {
|
|
|
|
unit: item::unit::UnitType::GeneralHp,
|
|
|
|
modifier: Some(item::unit::UnitModifier::PlusPlus),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 625);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_rare_frame() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Armor(
|
|
|
|
item::armor::Armor {
|
|
|
|
armor: item::armor::ArmorType::StinkFrame,
|
|
|
|
dfp: 10,
|
|
|
|
evp: 20,
|
|
|
|
slots: 3,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_rare_barrier() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Shield(
|
|
|
|
item::shield::Shield {
|
|
|
|
shield: item::shield::ShieldType::RedRing,
|
|
|
|
dfp: 10,
|
|
|
|
evp: 20,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_sells_rare_unit() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Unit(
|
|
|
|
item::unit::Unit {
|
|
|
|
unit: item::unit::UnitType::V101,
|
|
|
|
modifier: None,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
async fn test_player_cant_sell_if_meseta_would_go_over_max() {
|
|
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
entity_gateway.set_character_meseta(&char1.id, item::Meseta(999995)).await.unwrap();
|
|
|
|
|
|
|
|
let mut p1_inv = Vec::new();
|
|
|
|
|
|
|
|
p1_inv.push(entity_gateway.create_item(
|
|
|
|
item::NewItemEntity {
|
|
|
|
item: item::ItemDetail::Unit(
|
|
|
|
item::unit::Unit {
|
|
|
|
unit: item::unit::UnitType::V101,
|
|
|
|
modifier: None,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
}).await.unwrap());
|
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
|
|
|
|
|
|
|
|
let mut ship = Box::new(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;
|
|
|
|
|
|
|
|
let ack = ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
|
|
|
client: 0,
|
|
|
|
target: 0,
|
|
|
|
item_id: 0x10000,
|
|
|
|
amount: 1,
|
|
|
|
})))).await.err().unwrap();
|
|
|
|
assert!(matches!(ack.downcast::<ItemManagerError>().unwrap(), ItemManagerError::WalletFull));
|
|
|
|
|
|
|
|
let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap();
|
|
|
|
assert_eq!(c1_meseta.0, 999995);
|
|
|
|
}
|