Browse Source

fix kill count applying logic for later when we need to unseal things

kill_counters
andy 3 years ago
parent
commit
f2e7795b54
  1. 2
      src/bin/main.rs
  2. 6
      src/entity/gateway/inmemory.rs
  3. 22
      src/ship/items/manager.rs

2
src/bin/main.rs

@ -116,7 +116,7 @@ fn main() {
Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 30}), Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 30}),
None,], None,],
tekked: true, tekked: true,
kills: Some(22998),
kills: Some(22999),
} }
), ),
}).await.unwrap(); }).await.unwrap();

6
src/entity/gateway/inmemory.rs

@ -52,6 +52,9 @@ impl InMemoryGateway {
item.item = match item.item { item.item = match item.item {
ItemDetail::Weapon(mut weapon) => { ItemDetail::Weapon(mut weapon) => {
if let Some(weapon_modifiers) = self.weapon_modifiers.lock().unwrap().get(&item.id) { 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() { for weapon_modifier in weapon_modifiers.iter() {
weapon.apply_modifier(weapon_modifier); weapon.apply_modifier(weapon_modifier);
} }
@ -88,6 +91,9 @@ impl InMemoryGateway {
}, },
ItemDetail::Unit(mut unit) => { ItemDetail::Unit(mut unit) => {
if let Some(unit_modifiers) = self.unit_modifiers.lock().unwrap().get(&item.id) { 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() { for unit_modifier in unit_modifiers.iter() {
unit.apply_modifier(unit_modifier); unit.apply_modifier(unit_modifier);
} }

22
src/ship/items/manager.rs

@ -1199,11 +1199,33 @@ impl ItemManager {
pub async fn increase_kill_counters<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &CharacterEntity, equipped_items: &EquippedEntity, monstertype: MonsterType) -> Result<(), anyhow::Error> { pub async fn increase_kill_counters<EG: EntityGateway>(&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))?; let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
if let Some(weapon_entity) = equipped_items.weapon { 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 }; let wmodifier = WeaponModifier::AddKill { enemy: monstertype };
weapon.apply_modifier(&wmodifier);
entity_gateway.add_weapon_modifier(&weapon_entity, wmodifier).await?; entity_gateway.add_weapon_modifier(&weapon_entity, wmodifier).await?;
} }
for units in equipped_items.unit.iter().flatten() { 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))?;
let umodifier = UnitModifier::AddKill { enemy: monstertype }; let umodifier = UnitModifier::AddKill { enemy: monstertype };
unit.apply_modifier(&umodifier);
entity_gateway.add_unit_modifier(units, umodifier).await?; entity_gateway.add_unit_modifier(units, umodifier).await?;
} }
entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;

Loading…
Cancel
Save