From 395ce2fbbeb0a44508d0937a4f11564b08e50ff6 Mon Sep 17 00:00:00 2001 From: jake Date: Mon, 31 Aug 2020 23:47:06 -0600 Subject: [PATCH] mag test --- tests/test_mags.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/test_mags.rs diff --git a/tests/test_mags.rs b/tests/test_mags.rs new file mode 100644 index 0000000..b9bf032 --- /dev/null +++ b/tests/test_mags.rs @@ -0,0 +1,74 @@ +use elseware::common::serverstate::{ClientId, ServerState}; +use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; +use elseware::entity::item; +use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket}; + +use libpso::packet::ship::*; +use libpso::packet::messages::*; + +#[path = "common.rs"] +mod common; +use common::*; + +#[async_std::test] +async fn test_mag_feed() { + 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::Mag( + item::mag::Mag::baby_mag(0) + ), + location: item::ItemLocation::Inventory { + character_id: char1.id, + slot: 0, + equipped: true, + } + }).await; + for _ in 0..7 { + 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: 1, + equipped: false, + } + }).await; + } + + let mut ship = 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; + + for _ in 0..7 { + ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerFeedMag(PlayerFeedMag { + client: 0, + target: 0, + mag_id: 0x10000, + item_id: 0x10001, + })))).await.unwrap().for_each(drop); + } + + let p1_items = entity_gateway.get_items_by_character(&char1).await; + let mag = p1_items.get(0).unwrap(); + match &mag.item { + item::ItemDetail::Mag(mag) => { + assert!(mag.level() == 7); + assert!(mag.def() == 5); + assert!(mag.pow() == 2); + assert!(mag.dex() == 0); + assert!(mag.mind() == 0); + } + _ => panic!() + } +}