From 555171d11d851e689dd772584346fb08980540d9 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 21 Oct 2020 00:54:23 -0300 Subject: [PATCH] server unequips units now. formatting and cleanup unuseds. fix merge conflict --- src/bin/main.rs | 2 +- src/ship/items/inventory.rs | 12 +++++------ src/ship/items/manager.rs | 1 - src/ship/packet/handler/message.rs | 34 ++++++++++++++++++++++++------ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 8c587a6..292aec2 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -247,7 +247,7 @@ fn main() { NewItemEntity { item: ItemDetail::Unit( item::unit::Unit { - unit: item::unit::UnitType::KnightPower, + unit: item::unit::UnitType::HeavenlyPower, modifier: Some(item::unit::UnitModifier::PlusPlus), } ), diff --git a/src/ship/items/inventory.rs b/src/ship/items/inventory.rs index 1328e80..4735d74 100644 --- a/src/ship/items/inventory.rs +++ b/src/ship/items/inventory.rs @@ -408,13 +408,9 @@ impl CharacterInventory { let (slot, _) = self.items.iter() .enumerate() .filter(|(_, item)| { - if let InventoryItem::Individual(individual_inventory_item) = item { - if let ItemDetail::Mag(_) = &individual_inventory_item.item { - return individual_inventory_item.equipped - } - } + if let InventoryItem::Individual(individual_inventory_item) = item {if let ItemDetail::Mag(_) = &individual_inventory_item.item {return individual_inventory_item.equipped }} false - }) + }) .nth(0)?; Some(InventoryItemHandle { inventory: self, @@ -573,5 +569,9 @@ impl CharacterInventory { pub fn iter(&self) -> impl Iterator { self.items.iter() } + + pub fn items(&self) -> &Vec { + &self.items + } } diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index ffecb3a..2a9a50c 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -678,7 +678,6 @@ impl ItemManager { Ok(()) } - pub async fn use_item(&mut self, used_item: ConsumedItem, entity_gateway: &mut EG, diff --git a/src/ship/packet/handler/message.rs b/src/ship/packet/handler/message.rs index 96a4d36..832c06e 100644 --- a/src/ship/packet/handler/message.rs +++ b/src/ship/packet/handler/message.rs @@ -1,13 +1,11 @@ use libpso::packet::ship::*; use libpso::packet::messages::*; use crate::entity::gateway::EntityGateway; -use crate::entity::item::ItemDetail; -use crate::entity::item::tool::ToolType; +use crate::entity::item::{ItemType}; use crate::common::serverstate::ClientId; use crate::common::leveltable::CharacterLevelTable; use crate::ship::ship::{SendShipPacket, ShipError, Rooms, Clients, ItemDropLocation}; use crate::ship::location::{ClientLocation, ClientLocationError}; -use crate::ship::map::{MapArea}; use crate::ship::items::{ItemManager, ClientItemId}; use crate::ship::packet::builder; @@ -275,7 +273,7 @@ pub async fn player_used_medical_center(id: ClientId, clients: &mut Clients) -> Result + Send>, ShipError> where -EG: EntityGateway + EG: EntityGateway { let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; if client.character.meseta >= 10 { @@ -332,7 +330,29 @@ where EG: EntityGateway { let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; - item_manager.player_unequips_item(entity_gateway, &client.character, ClientItemId(pkt.item_id)).await?; - Ok(Box::new(None.into_iter())) -} + let equipped_unit_ids: Vec = { + item_manager.player_unequips_item(entity_gateway, &client.character, ClientItemId(pkt.item_id)).await?; + let inventory = item_manager.get_character_inventory(&client.character).unwrap(); + let ue_item = inventory.get_item_by_id(ClientItemId(pkt.item_id)).ok_or(ShipError::ItemError)?; + if let ItemType::Armor(_) = ue_item.item_type() { + inventory.items() + .iter() + .filter(|inv_item| { + if let ItemType::Unit(_) = inv_item.item_type() { + return inv_item.equipped() + } + false + }) + .map(|u| u.item_id()) + .collect() + } else { + Vec::new() + } + }; + + for unit_id in equipped_unit_ids { + item_manager.player_unequips_item(entity_gateway, &client.character, unit_id).await; + } + Ok(Box::new(None.into_iter())) +} \ No newline at end of file