From e3991f5d41c4f4465687ff5f1c21c1a70e63cd8e Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 23 May 2022 15:01:26 +0000 Subject: [PATCH] fix warnings from rebase --- src/bin/main.rs | 1 + src/entity/gateway/inmemory.rs | 2 +- src/entity/item/mod.rs | 33 +++++++++-------- src/ship/items/manager.rs | 67 ++++++++++++++++------------------ src/ship/shops/armor.rs | 1 + 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index c4eb697..aa12855 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -317,6 +317,7 @@ fn main() { Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], tekked: true, + kills: None, } ), }).await.unwrap(); diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index 885bfcc..8eaea02 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -352,7 +352,7 @@ impl EntityGateway for InMemoryGateway { async fn increment_kill_counter(&mut self, item_id: &ItemEntityId) -> Result<(), GatewayError> { if let Some(item_entity) = self.items.lock().unwrap().get_mut(item_id) { - item_entity.increase_kill_counter(); + item_entity.item.increment_kill_counter(); } Ok(()) } diff --git a/src/entity/item/mod.rs b/src/entity/item/mod.rs index a03f27f..2c96e16 100644 --- a/src/entity/item/mod.rs +++ b/src/entity/item/mod.rs @@ -173,28 +173,29 @@ impl ItemDetail { pub fn has_kill_counter(self) -> bool { match self { ItemDetail::Weapon(w) => w.kills.is_some(), - ItemDetail::Armor(a) => false, - ItemDetail::Shield(s) => false, + ItemDetail::Armor(_a) => false, + ItemDetail::Shield(_s) => false, // ItemDetail::Unit(u) => u.kills.is_some(), - ItemDetail::Unit(u) => false, - ItemDetail::Tool(t) => false, - ItemDetail::TechniqueDisk(d) => false, - ItemDetail::Mag(m) => false, - ItemDetail::ESWeapon(e) => false, + ItemDetail::Unit(_u) => false, + ItemDetail::Tool(_t) => false, + ItemDetail::TechniqueDisk(_d) => false, + ItemDetail::Mag(_m) => false, + ItemDetail::ESWeapon(_e) => false, } } // TODO: delete this - pub fn increment_kill_counter(&self) { + // jk actually we need this + pub fn increment_kill_counter(&mut self) { match self { - ItemDetail::Weapon(w) => {}, - ItemDetail::Armor(a) => {}, - ItemDetail::Shield(s) => {}, - ItemDetail::Unit(u) => {}, - ItemDetail::Tool(t) => {}, - ItemDetail::TechniqueDisk(d) => {}, - ItemDetail::Mag(m) => {}, - ItemDetail::ESWeapon(e) => {}, + ItemDetail::Weapon(w) => {w.increment_kill_counter()}, + ItemDetail::Armor(_a) => {}, + ItemDetail::Shield(_s) => {}, + ItemDetail::Unit(u) => {u.increment_kill_counter()}, + ItemDetail::Tool(_t) => {}, + ItemDetail::TechniqueDisk(_d) => {}, + ItemDetail::Mag(_m) => {}, + ItemDetail::ESWeapon(_e) => {}, } } } diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index 566e8f7..6ffb942 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -1193,6 +1193,38 @@ impl ItemManager { .await .map_err(|err| err.into()) } + + pub async fn increase_kill_counters(&mut self, entity_gateway: &mut EG, character: &CharacterEntity, equipped_items: &EquippedEntity) -> Result<(), anyhow::Error> { + let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; + if let Some(weapon_entity) = equipped_items.weapon { + let weapon_id = inventory.get_item_by_entity_id(weapon_entity).ok_or(ItemManagerError::EntityIdNotInInventory(weapon_entity))?.item_id(); + let mut weapon_handle = inventory.get_item_handle_by_id(weapon_id).ok_or(ItemManagerError::NoSuchItemId(weapon_id))?; + let individual_item_w = weapon_handle.item_mut() + .ok_or(ItemManagerError::NoSuchItemId(weapon_id))? + .individual_mut() + .ok_or(ItemManagerError::WrongItemType(weapon_id))?; + let weapon = individual_item_w + .weapon_mut() + .ok_or(ItemManagerError::WrongItemType(weapon_id))?; + + weapon.increment_kill_counter(); + } + for units in equipped_items.unit.iter().flatten() { + let unit_id = inventory.get_item_by_entity_id(*units).ok_or(ItemManagerError::EntityIdNotInInventory(*units))?.item_id(); + let mut unit_handle = inventory.get_item_handle_by_id(unit_id).ok_or(ItemManagerError::NoSuchItemId(unit_id))?; + let individual_item_u = unit_handle.item_mut() + .ok_or(ItemManagerError::NoSuchItemId(unit_id))? + .individual_mut() + .ok_or(ItemManagerError::WrongItemType(unit_id))?; + let unit = individual_item_u + .unit_mut() + .ok_or(ItemManagerError::WrongItemType(unit_id))?; + + unit.increment_kill_counter(); + } + entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; + Ok(()) + } } #[derive(Debug)] @@ -1375,41 +1407,6 @@ impl ItemAction for TradeMeseta { dest_meseta.0 += self.amount as u32; entity_gateway.set_character_meseta(&self.dest_character_id, *dest_meseta).await?; } - } - - pub async fn increase_kill_counters( &mut self, - entity_gateway: &mut EG, - character: &CharacterEntity, - equipped_items: &EquippedEntity) - -> Result<(), anyhow::Error> { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - if let Some(weapon_entity) = equipped_items.weapon { - let weapon_id = inventory.get_item_by_entity_id(weapon_entity).ok_or(ItemManagerError::EntityIdNotInInventory(weapon_entity))?.item_id(); - let mut weapon_handle = inventory.get_item_handle_by_id(weapon_id).ok_or(ItemManagerError::NoSuchItemId(weapon_id))?; - let individual_item_w = weapon_handle.item_mut() - .ok_or(ItemManagerError::NoSuchItemId(weapon_id))? - .individual_mut() - .ok_or(ItemManagerError::WrongItemType(weapon_id))?; - let weapon = individual_item_w - .weapon_mut() - .ok_or(ItemManagerError::WrongItemType(weapon_id))?; - - weapon.increment_kill_counter(); - } - for units in equipped_items.unit.iter().flatten() { - let unit_id = inventory.get_item_by_entity_id(*units).ok_or(ItemManagerError::EntityIdNotInInventory(*units))?.item_id(); - let mut unit_handle = inventory.get_item_handle_by_id(unit_id).ok_or(ItemManagerError::NoSuchItemId(unit_id))?; - let individual_item_u = unit_handle.item_mut() - .ok_or(ItemManagerError::NoSuchItemId(unit_id))? - .individual_mut() - .ok_or(ItemManagerError::WrongItemType(unit_id))?; - let unit = individual_item_u - .unit_mut() - .ok_or(ItemManagerError::WrongItemType(unit_id))?; - - unit.increment_kill_counter(); - } - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; Ok(()) } } diff --git a/src/ship/shops/armor.rs b/src/ship/shops/armor.rs index d13b2d1..233c1f9 100644 --- a/src/ship/shops/armor.rs +++ b/src/ship/shops/armor.rs @@ -334,6 +334,7 @@ impl ArmorShop { ArmorShopItem::Unit(Unit { unit: unit_detail.item, modifier: None, + kills: None, }) }) .collect()