You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1168 lines
42 KiB
1168 lines
42 KiB
use elseware::common::serverstate::{ClientId, ServerState};
|
|
use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
|
|
use elseware::entity::item;
|
|
use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
|
|
use elseware::ship::room::Difficulty;
|
|
|
|
use libpso::packet::ship::*;
|
|
use libpso::packet::messages::*;
|
|
|
|
#[path = "common.rs"]
|
|
mod common;
|
|
use common::*;
|
|
|
|
#[async_std::test]
|
|
async fn test_player_opens_weapon_shop() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
char1.exp = 80000000;
|
|
entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 1
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(packets.len(), 1);
|
|
match &packets[0].1 {
|
|
SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
|
|
assert_eq!(shop_list.items.len(), 16)
|
|
}
|
|
_ => panic!("")
|
|
}
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_player_opens_tool_shop() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
char1.exp = 80000000;
|
|
entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 0
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(packets.len(), 1);
|
|
match &packets[0].1 {
|
|
SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
|
|
assert_eq!(shop_list.items.len(), 18)
|
|
}
|
|
_ => panic!("")
|
|
}
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_player_opens_armor_shop() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
char1.exp = 80000000;
|
|
entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 2
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(packets.len(), 1);
|
|
match &packets[0].1 {
|
|
SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
|
|
assert_eq!(shop_list.items.len(), 21)
|
|
}
|
|
_ => panic!("")
|
|
}
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_player_buys_from_weapon_shop() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
char1.exp = 80000000;
|
|
char1.meseta = 999999;
|
|
entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 1
|
|
})))).await.unwrap().for_each(drop);
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10000,
|
|
shop_type: 1,
|
|
shop_index: 0,
|
|
amount: 1,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert!(c1.meseta < 999999);
|
|
//let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap();
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
assert_eq!(p1_items.items.len(), 1);
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_player_buys_from_tool_shop() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
char1.exp = 80000000;
|
|
char1.meseta = 999999;
|
|
entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10000,
|
|
shop_type: 0,
|
|
shop_index: 0,
|
|
amount: 1,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert!(c1.meseta < 999999);
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
assert_eq!(p1_items.items.len(), 1);
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_player_buys_multiple_from_tool_shop() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
char1.exp = 80000000;
|
|
char1.meseta = 999999;
|
|
entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10000,
|
|
shop_type: 0,
|
|
shop_index: 0,
|
|
amount: 5,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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| {
|
|
assert_eq!(item.len(), 5);
|
|
assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
|
|
}).unwrap();
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_player_buys_from_armor_shop() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
char1.exp = 80000000;
|
|
char1.meseta = 999999;
|
|
entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 2
|
|
})))).await.unwrap().for_each(drop);
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10000,
|
|
shop_type: 2,
|
|
shop_index: 0,
|
|
amount: 1,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert!(c1.meseta < 999999);
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
assert_eq!(p1_items.items.len(), 1);
|
|
}
|
|
|
|
#[async_std::test]
|
|
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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 4406);
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_other_clients_see_purchase() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
char1.exp = 80000000;
|
|
char1.meseta = 999999;
|
|
entity_gateway.save_character(&char1).await.unwrap();
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
.gateway(entity_gateway.clone())
|
|
.build());
|
|
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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
join_room(&mut ship, ClientId(2), 0).await;
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 1
|
|
})))).await.unwrap().for_each(drop);
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10000,
|
|
shop_type: 1,
|
|
shop_index: 0,
|
|
amount: 1,
|
|
unknown1: 0,
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(packets.len(), 1);
|
|
assert_eq!(packets[0].0, ClientId(2));
|
|
match &packets[0].1 {
|
|
SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
|
|
_ => panic!(""),
|
|
}
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_other_clients_see_stacked_purchase() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
|
|
char1.exp = 80000000;
|
|
char1.meseta = 999999;
|
|
entity_gateway.save_character(&char1).await.unwrap();
|
|
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,
|
|
}
|
|
}).await.unwrap();
|
|
|
|
let mut ship = Box::new(ShipServerState::builder()
|
|
.gateway(entity_gateway.clone())
|
|
.build());
|
|
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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
join_room(&mut ship, ClientId(2), 0).await;
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 1
|
|
})))).await.unwrap().for_each(drop);
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10000,
|
|
shop_type: 1,
|
|
shop_index: 0,
|
|
amount: 1,
|
|
unknown1: 0,
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
assert_eq!(packets.len(), 1);
|
|
assert_eq!(packets[0].0, ClientId(2));
|
|
match &packets[0].1 {
|
|
SendShipPacket::Message(Message{msg: GameMessage::CreateItem(_)}) => {},
|
|
_ => panic!(""),
|
|
}
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_buying_item_without_enough_mseseta() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
|
|
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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 1
|
|
})))).await.unwrap().for_each(drop);
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10000,
|
|
shop_type: 1,
|
|
shop_index: 0,
|
|
amount: 1,
|
|
unknown1: 0,
|
|
})))).await;
|
|
|
|
assert!(packets.is_err());
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 0);
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
assert_eq!(p1_items.items.len(), 0);
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_player_double_buys_from_tool_shop() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
char1.exp = 80000000;
|
|
char1.meseta = 999999;
|
|
entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10000,
|
|
shop_type: 0,
|
|
shop_index: 0,
|
|
amount: 3,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10001,
|
|
shop_type: 0,
|
|
shop_index: 1,
|
|
amount: 2,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10002,
|
|
shop_type: 0,
|
|
shop_index: 0,
|
|
amount: 4,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert!(c1.meseta < 999999);
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
assert_eq!(p1_items.items.len(), 2);
|
|
p1_items.items[0].with_stacked(|item| {
|
|
assert_eq!(item.len(), 7);
|
|
assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Monomate));
|
|
}).unwrap();
|
|
p1_items.items[1].with_stacked(|item| {
|
|
assert_eq!(item.len(), 2);
|
|
assert_eq!(item[0].item.item_type(), item::ItemType::Tool(item::tool::ToolType::Dimate));
|
|
}).unwrap();
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
async fn test_techs_disappear_from_shop_when_bought() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
char1.exp = 80000000;
|
|
char1.meseta = 999999;
|
|
entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 0,
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
let first_tech = match &packets[0].1 {
|
|
SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
|
|
shop_list.items.iter()
|
|
.enumerate()
|
|
.filter(|(_, item)| {
|
|
item.item_bytes[0] == 3 && item.item_bytes[1] == 2
|
|
})
|
|
.nth(0).unwrap().0
|
|
},
|
|
_ => panic!(""),
|
|
};
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10000,
|
|
shop_type: 0,
|
|
shop_index: first_tech as u8,
|
|
amount: 1,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10001,
|
|
shop_type: 0,
|
|
shop_index: first_tech as u8,
|
|
amount: 1,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
p1_items.items[0].with_individual(|item1| {
|
|
p1_items.items[1].with_individual(|item2| {
|
|
assert_ne!(item1, item2);
|
|
}).unwrap();
|
|
}).unwrap();
|
|
}
|
|
|
|
// TOOD: this is not deterministic and can randomly fail
|
|
#[async_std::test]
|
|
async fn test_units_disappear_from_shop_when_bought() {
|
|
let mut entity_gateway = InMemoryGateway::default();
|
|
|
|
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
|
|
char1.exp = 80000000;
|
|
char1.meseta = 999999;
|
|
entity_gateway.save_character(&char1).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
|
|
|
let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
|
client: 255,
|
|
target: 255,
|
|
shop_type: 2,
|
|
})))).await.unwrap().collect::<Vec<_>>();
|
|
|
|
let first_unit = match &packets[0].1 {
|
|
SendShipPacket::Message(Message {msg: GameMessage::ShopList(shop_list)}) => {
|
|
shop_list.items.iter()
|
|
.enumerate()
|
|
.filter(|(_, item)| {
|
|
item.item_bytes[0] == 1 && item.item_bytes[1] == 3
|
|
})
|
|
.nth(0).unwrap().0
|
|
},
|
|
_ => panic!(""),
|
|
};
|
|
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10000,
|
|
shop_type: 2,
|
|
shop_index: first_unit as u8,
|
|
amount: 1,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::BuyItem(BuyItem {
|
|
client: 255,
|
|
target: 255,
|
|
item_id: 0x10001,
|
|
shop_type: 2,
|
|
shop_index: first_unit as u8,
|
|
amount: 1,
|
|
unknown1: 0,
|
|
})))).await.unwrap().for_each(drop);
|
|
|
|
let p1_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
|
|
p1_items.items[0].with_individual(|item1| {
|
|
p1_items.items[1].with_individual(|item2| {
|
|
assert_ne!(item1, item2);
|
|
}).unwrap();
|
|
}).unwrap();
|
|
}
|
|
|
|
#[async_std::test]
|
|
async fn test_selling_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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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),
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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),
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 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,
|
|
}
|
|
),
|
|
location: item::ItemLocation::Inventory {
|
|
character_id: char1.id,
|
|
}
|
|
}).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_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).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 characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap();
|
|
let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap();
|
|
assert_eq!(c1.meseta, 10);
|
|
}
|