mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Items now lose durability on death
This commit is contained in:
parent
df13741be9
commit
a07e042fa2
@ -25,6 +25,26 @@ pub enum ArmorKind {
|
|||||||
Bag,
|
Bag,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ArmorKind {
|
||||||
|
pub fn has_durability(self) -> bool {
|
||||||
|
use ArmorKind::*;
|
||||||
|
match self {
|
||||||
|
Shoulder => true,
|
||||||
|
Chest => true,
|
||||||
|
Belt => true,
|
||||||
|
Hand => true,
|
||||||
|
Pants => true,
|
||||||
|
Foot => true,
|
||||||
|
Back => true,
|
||||||
|
Ring => false,
|
||||||
|
Neck => false,
|
||||||
|
Head => false,
|
||||||
|
Tabard => false,
|
||||||
|
Bag => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Armor {
|
impl Armor {
|
||||||
/// Determines whether two pieces of armour are superficially equivalent to
|
/// Determines whether two pieces of armour are superficially equivalent to
|
||||||
/// one another (i.e: one may be substituted for the other in crafting
|
/// one another (i.e: one may be substituted for the other in crafting
|
||||||
|
@ -5,11 +5,11 @@ pub mod tool;
|
|||||||
|
|
||||||
// Reexports
|
// Reexports
|
||||||
pub use modular::{MaterialStatManifest, ModularBase, ModularComponent};
|
pub use modular::{MaterialStatManifest, ModularBase, ModularComponent};
|
||||||
pub use tool::{AbilitySet, AbilitySpec, Hands, Tool, ToolKind};
|
pub use tool::{AbilityMap, AbilitySet, AbilitySpec, Hands, Tool, ToolKind};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assets::{self, AssetExt, BoxedError, Error},
|
assets::{self, AssetExt, BoxedError, Error},
|
||||||
comp::inventory::{item::tool::AbilityMap, InvSlot},
|
comp::inventory::InvSlot,
|
||||||
effect::Effect,
|
effect::Effect,
|
||||||
recipe::RecipeInput,
|
recipe::RecipeInput,
|
||||||
terrain::Block,
|
terrain::Block,
|
||||||
@ -793,6 +793,7 @@ impl Item {
|
|||||||
hash: 0,
|
hash: 0,
|
||||||
durability: None,
|
durability: None,
|
||||||
};
|
};
|
||||||
|
item.durability = item.has_durability().then_some(0);
|
||||||
item.update_item_state(ability_map, msm);
|
item.update_item_state(ability_map, msm);
|
||||||
item
|
item
|
||||||
}
|
}
|
||||||
@ -1199,14 +1200,29 @@ impl Item {
|
|||||||
const MAX_DURABILITY: u32 = 8;
|
const MAX_DURABILITY: u32 = 8;
|
||||||
let durability = self.durability.map_or(0, |x| x.clamp(0, MAX_DURABILITY));
|
let durability = self.durability.map_or(0, |x| x.clamp(0, MAX_DURABILITY));
|
||||||
const DURABILITY_THRESHOLD: u32 = 4;
|
const DURABILITY_THRESHOLD: u32 = 4;
|
||||||
const MIN_FRAC: f32 = 0.25;
|
const MIN_FRAC: f32 = 0.2;
|
||||||
let mult = durability.saturating_sub(DURABILITY_THRESHOLD) as f32
|
let mult = (1.0
|
||||||
/ (MAX_DURABILITY - DURABILITY_THRESHOLD) as f32
|
- durability.saturating_sub(DURABILITY_THRESHOLD) as f32
|
||||||
|
/ (MAX_DURABILITY - DURABILITY_THRESHOLD) as f32)
|
||||||
* (1.0 - MIN_FRAC)
|
* (1.0 - MIN_FRAC)
|
||||||
+ MIN_FRAC;
|
+ MIN_FRAC;
|
||||||
DurabilityMultiplier(mult)
|
DurabilityMultiplier(mult)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_durability(&self) -> bool {
|
||||||
|
match &*self.kind() {
|
||||||
|
ItemKind::Tool(_) => true,
|
||||||
|
ItemKind::Armor(armor) => armor.kind.has_durability(),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn apply_durability(&mut self) {
|
||||||
|
if let Some(durability) = &mut self.durability {
|
||||||
|
*durability += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn create_test_item_from_kind(kind: ItemKind) -> Self {
|
pub fn create_test_item_from_kind(kind: ItemKind) -> Self {
|
||||||
let ability_map = &AbilityMap::load().read();
|
let ability_map = &AbilityMap::load().read();
|
||||||
|
@ -416,6 +416,25 @@ impl Loadout {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Increments durability by 1 of all valid items
|
||||||
|
pub(super) fn apply_durability(
|
||||||
|
&mut self,
|
||||||
|
ability_map: &item::tool::AbilityMap,
|
||||||
|
msm: &item::MaterialStatManifest,
|
||||||
|
) {
|
||||||
|
self.slots
|
||||||
|
.iter_mut()
|
||||||
|
.filter(|slot| slot.slot.as_ref().map_or(false, |i| i.has_durability()))
|
||||||
|
.for_each(|slot| {
|
||||||
|
if let Some(item) = &mut slot.slot {
|
||||||
|
item.apply_durability();
|
||||||
|
// Update item state after applying durability because stats have potential to
|
||||||
|
// change from different durability
|
||||||
|
item.update_item_state(ability_map, msm);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -878,6 +878,15 @@ impl Inventory {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Increments durability of all valid items equipped in loaodut by 1
|
||||||
|
pub fn apply_durability(
|
||||||
|
&mut self,
|
||||||
|
ability_map: &item::tool::AbilityMap,
|
||||||
|
msm: &item::MaterialStatManifest,
|
||||||
|
) {
|
||||||
|
self.loadout.apply_durability(ability_map, msm)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for Inventory {
|
impl Component for Inventory {
|
||||||
|
@ -18,7 +18,7 @@ use common::{
|
|||||||
comp::{
|
comp::{
|
||||||
self, aura, buff,
|
self, aura, buff,
|
||||||
chat::{KillSource, KillType},
|
chat::{KillSource, KillType},
|
||||||
inventory::item::MaterialStatManifest,
|
inventory::item::{AbilityMap, MaterialStatManifest},
|
||||||
loot_owner::LootOwnerKind,
|
loot_owner::LootOwnerKind,
|
||||||
Alignment, Auras, Body, CharacterState, Energy, Group, Health, HealthChange, Inventory,
|
Alignment, Auras, Body, CharacterState, Energy, Group, Health, HealthChange, Inventory,
|
||||||
Player, Poise, Pos, SkillSet, Stats,
|
Player, Poise, Pos, SkillSet, Stats,
|
||||||
@ -511,6 +511,13 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, last_change: Healt
|
|||||||
true
|
true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Modify durability on all equipped items
|
||||||
|
if let Some(mut inventory) = state.ecs().write_storage::<Inventory>().get_mut(entity) {
|
||||||
|
let ability_map = state.ecs().read_resource::<AbilityMap>();
|
||||||
|
let msm = state.ecs().read_resource::<MaterialStatManifest>();
|
||||||
|
inventory.apply_durability(&ability_map, &msm);
|
||||||
|
}
|
||||||
|
|
||||||
if should_delete {
|
if should_delete {
|
||||||
if let Some(rtsim_entity) = state
|
if let Some(rtsim_entity) = state
|
||||||
.ecs()
|
.ecs()
|
||||||
|
Loading…
Reference in New Issue
Block a user