Browse Source

lol maybe if we actually apply modifiers the tests will stop failing

kill_counters
andy 2 years ago
parent
commit
b2f3dc9f50
  1. 10
      src/entity/gateway/inmemory.rs
  2. 4
      src/entity/item/weapon.rs
  3. 11
      src/ship/items/manager.rs

10
src/entity/gateway/inmemory.rs

@ -85,7 +85,15 @@ impl InMemoryGateway {
} }
} }
ItemDetail::Mag(mag) ItemDetail::Mag(mag)
}
},
ItemDetail::Unit(mut unit) => {
if let Some(unit_modifiers) = self.unit_modifiers.lock().unwrap().get(&item.id) {
for unit_modifier in unit_modifiers.iter() {
unit.apply_modifier(unit_modifier);
}
}
ItemDetail::Unit(unit)
},
_ => { _ => {
item.item item.item
} }

4
src/entity/item/weapon.rs

@ -1535,9 +1535,7 @@ impl Weapon {
}, },
WeaponModifier::AddKill{enemy: _} => { WeaponModifier::AddKill{enemy: _} => {
if let Some(kills) = self.kills { if let Some(kills) = self.kills {
println!("{:?} currently has {:?} kills", self.weapon, self.kills);
self.kills = Some(kills + 1); self.kills = Some(kills + 1);
println!("now {:?} has {:?} kills", self.weapon, self.kills);
} }
}, },
}; };
@ -1558,8 +1556,6 @@ impl Weapon {
if self.weapon.has_counter() { if self.weapon.has_counter() {
result[10..12].copy_from_slice(&self.kills.unwrap_or(0u16).to_be_bytes()); result[10..12].copy_from_slice(&self.kills.unwrap_or(0u16).to_be_bytes());
result[10] += 0x80; result[10] += 0x80;
// TODO: what to do with the 3rd attr?
// self.attrs[2] = None;
} else { } else {
result[10..12].copy_from_slice(&self.attrs[2].map(|s| s.value()).unwrap_or([0,0])); result[10..12].copy_from_slice(&self.attrs[2].map(|s| s.value()).unwrap_or([0,0]));
} }

11
src/ship/items/manager.rs

@ -1203,18 +1203,7 @@ impl ItemManager {
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