From f2e7795b540608f86727ec5d489f970ac0c43b9d Mon Sep 17 00:00:00 2001 From: andy Date: Sat, 18 Jun 2022 15:19:40 +0000 Subject: [PATCH] fix kill count applying logic for later when we need to unseal things --- src/bin/main.rs | 2 +- src/entity/gateway/inmemory.rs | 6 ++++++ src/ship/items/manager.rs | 26 ++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index aa12855..3ce4ed7 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -116,7 +116,7 @@ fn main() { Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 30}), None,], tekked: true, - kills: Some(22998), + kills: Some(22999), } ), }).await.unwrap(); diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index 41cc851..7d616dc 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -52,6 +52,9 @@ impl InMemoryGateway { item.item = match item.item { ItemDetail::Weapon(mut weapon) => { if let Some(weapon_modifiers) = self.weapon_modifiers.lock().unwrap().get(&item.id) { + if weapon.weapon.has_counter() { + weapon.kills = Some(0); + } for weapon_modifier in weapon_modifiers.iter() { weapon.apply_modifier(weapon_modifier); } @@ -88,6 +91,9 @@ impl InMemoryGateway { }, ItemDetail::Unit(mut unit) => { if let Some(unit_modifiers) = self.unit_modifiers.lock().unwrap().get(&item.id) { + if unit.unit.has_counter() { + unit.kills = Some(0); + } for unit_modifier in unit_modifiers.iter() { unit.apply_modifier(unit_modifier); } diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index 7af8cd2..4019eb2 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -1199,12 +1199,34 @@ impl ItemManager { pub async fn increase_kill_counters(&mut self, entity_gateway: &mut EG, character: &CharacterEntity, equipped_items: &EquippedEntity, monstertype: MonsterType) -> 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))?; + let wmodifier = WeaponModifier::AddKill { enemy: monstertype }; + weapon.apply_modifier(&wmodifier); entity_gateway.add_weapon_modifier(&weapon_entity, wmodifier).await?; } for units in equipped_items.unit.iter().flatten() { - let umodifier = UnitModifier::AddKill { enemy: monstertype }; - entity_gateway.add_unit_modifier(units, umodifier).await?; + 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))?; + + let umodifier = UnitModifier::AddKill { enemy: monstertype }; + unit.apply_modifier(&umodifier); + entity_gateway.add_unit_modifier(units, umodifier).await?; } entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; Ok(())