From a0747ea89a4ccd178791f69369982e120e751a35 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 24 May 2022 01:19:30 +0000 Subject: [PATCH] test for 1 kill increases every equipped kill counter --- tests/test_unseal_items.rs | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/tests/test_unseal_items.rs b/tests/test_unseal_items.rs index 7964610..8949df2 100644 --- a/tests/test_unseal_items.rs +++ b/tests/test_unseal_items.rs @@ -11,9 +11,9 @@ use elseware::common::serverstate::{ClientId, ServerState}; use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket}; -use elseware::entity::character::{SectionID}; -use elseware::ship::room::{Difficulty}; -use elseware::ship::monster::{MonsterType}; +use elseware::entity::character::SectionID; +use elseware::ship::room::Difficulty; +use elseware::ship::monster::MonsterType; use elseware::entity::item; use libpso::packet::ship::*; @@ -111,13 +111,40 @@ async fn test_all_equipped_kill_counters_increase_per_kill() { }; entity_gateway.set_character_equips(&char1.id, &equipped).await.unwrap(); - entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); + entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); 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; - assert!(true); + let enemy_id = { + let room = ship.blocks.0[0].rooms[0].as_ref().unwrap(); + let enemy_id = (0..).filter_map(|i| { + room.maps.enemy_by_id(i).ok().and_then(|enemy| { + if enemy.monster == MonsterType::Booma { + Some(i) + } + else { + None + } + }) + }).next().unwrap(); + enemy_id + }; + + ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::KillMonster(KillMonster{ + client: enemy_id as u8, + target: 16, + map_area: 1, + data: [8,0], + })))).await.unwrap().for_each(drop); + + let equipped_items = entity_gateway.get_character_equips(&char1.id).await.unwrap(); + let inventory = entity_gateway.get_character_inventory(&char1.id).await.unwrap(); + let w = inventory.items.iter().find(|x| x.individual().unwrap().id == equipped_items.weapon.unwrap()).unwrap().individual().unwrap(); + let u = inventory.items.iter().find(|x| x.individual().unwrap().id == equipped_items.unit[0].unwrap()).unwrap().individual().unwrap(); + + assert!(w.item.as_client_bytes()[11] == u.item.as_client_bytes()[11]); } // #[async_std::test]