Browse Source

fix warnings from rebase

kill_counters
andy 3 years ago
parent
commit
e3991f5d41
  1. 1
      src/bin/main.rs
  2. 2
      src/entity/gateway/inmemory.rs
  3. 33
      src/entity/item/mod.rs
  4. 67
      src/ship/items/manager.rs
  5. 1
      src/ship/shops/armor.rs

1
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();

2
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(())
}

33
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) => {},
}
}
}

67
src/ship/items/manager.rs

@ -1193,6 +1193,38 @@ impl ItemManager {
.await
.map_err(|err| err.into())
}
pub async fn increase_kill_counters<EG: EntityGateway>(&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<EG: EntityGateway> ItemAction<EG> 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<EG: EntityGateway>( &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(())
}
}

1
src/ship/shops/armor.rs

@ -334,6 +334,7 @@ impl<R: Rng + SeedableRng> ArmorShop<R> {
ArmorShopItem::Unit(Unit {
unit: unit_detail.item,
modifier: None,
kills: None,
})
})
.collect()

Loading…
Cancel
Save