|
|
@ -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::*;
|
|
|
@ -1105,3 +1106,44 @@ async fn test_player_sells_rare_unit() { |
|
|
|
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);
|
|
|
|
}
|