Browse Source

add kill counters to units (limiter)

kill_counters
andy 3 years ago
parent
commit
e39cf3eecc
  1. 2
      src/bin/main.rs
  2. 4
      src/ship/items/inventory.rs
  3. 36
      src/ship/items/manager.rs
  4. 2
      src/ship/packet/handler/message.rs

2
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(22995),
kills: Some(22998),
}
),
}).await.unwrap();

4
src/ship/items/inventory.rs

@ -7,6 +7,10 @@ use std::future::Future;
use crate::entity::character::CharacterEntityId;
use crate::entity::item::tool::ToolType;
use crate::entity::item::mag::Mag;
use crate::entity::item::weapon::Weapon;
use crate::ship::items::{ClientItemId, BankItem, BankItemHandle, ItemManagerError};
use crate::entity::item::unit::Unit;
use crate::ship::items::floor::{IndividualFloorItem, StackedFloorItem};
use crate::ship::shops::{ShopItem, ArmorShopItem, ToolShopItem, WeaponShopItem};
use crate::ship::items::state::ItemStateError;
use crate::ship::items::state::{IndividualItemDetail, StackedItemDetail, AddItemResult};

36
src/ship/items/manager.rs

@ -1423,33 +1423,39 @@ impl<EG: EntityGateway> ItemAction<EG> for TradeMeseta {
equipped_items: &EquippedEntity)
-> Result<(), anyhow::Error> {
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
// weapon
if let Some(weapon_entity) = equipped_items.weapon {
println!("updating weapon kill counter for weapon {:?}", weapon_entity);
// weapon_entity = &InventoryItem
// let weapon_id = weapon_entity.item_id();
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))?;
// weapon_handle = InventoryItemHandle
let individual_item = weapon_handle.item_mut()
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
let weapon = individual_item_w
.weapon_mut()
.ok_or(ItemManagerError::WrongItemType(weapon_id))?;
weapon.increment_kill_counter();
entity_gateway.increment_kill_counter(&weapon_entity).await?;
entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
}
// for units in equipped_items.unit {
// if let Some(unit_id) = units {
// println!("UNIMPLEMENTED - updating unit kill counter for unit {:?}", unit_id);
// // entity_gateway.increase_kill_counter(&unit_id).await?;
// // let unit = inventory.get_item_by_entity_id(&unit_id)
// }
// }
// limiter
for units in equipped_items.unit {
if let Some(unit_entity) = units {
let unit_id = inventory.get_item_by_entity_id(unit_entity).ok_or(ItemManagerError::EntityIdNotInInventory(unit_entity))?.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.increment_kill_counter(&unit_entity).await?;
}
}
entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
Ok(())
}
}

2
src/ship/packet/handler/message.rs

@ -411,7 +411,7 @@ where
}
pub async fn player_killed_monster<EG>( id: ClientId,
pkt: &KillMonster,
_pkt: &KillMonster, // use this later for turbo logging?
entity_gateway: &mut EG,
client_location: &ClientLocation,
clients: &Clients,

Loading…
Cancel
Save