feat: added armour passives

This commit is contained in:
TotallyNot 2025-11-04 13:04:56 +01:00
parent cfe2631578
commit b92ad37a5b
Signed by: pyrite
GPG key ID: 7F1BA9170CD35D15
17 changed files with 520 additions and 316 deletions

View file

@ -183,7 +183,7 @@ impl BonusPartDamageBonus {
}
}
#[derive(Clone, Copy, Debug, Display)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Component, Display)]
#[cfg_attr(feature = "json", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "json", serde(rename_all = "snake_case"))]
pub enum ArmourBonusType {

View file

@ -5,7 +5,7 @@ use crate::bundle::{
Name,
bonus::BonusPartDamageBonus,
passive::EducationPartDamageBonus,
stat::{CritRate, DamageBonus, SimpleStatBundle, WeaponAccuracy},
stat::{CritRate, DamageBonus, MaxHealth, SimpleStatBundle, WeaponAccuracy},
weapon::WeaponSlot,
};
@ -37,13 +37,7 @@ impl Default for Level {
}
#[derive(Component, Debug)]
pub struct MaxHealth(pub u16);
impl Default for MaxHealth {
fn default() -> Self {
Self(100)
}
}
pub struct Health(pub u16);
#[derive(Component, Debug, Default)]
pub struct CombatTurns(pub u16);
@ -158,6 +152,7 @@ pub struct PlayerBundle {
pub name: Name,
pub player: Player,
pub level: Level,
pub max_health: SimpleStatBundle<MaxHealth>,
pub crit_rate: SimpleStatBundle<CritRate>,
// TODO: since these two need to be tracked here anyways it might be preferable to shift all
// player specific passives here instead of tracking them on the weapons
@ -174,6 +169,12 @@ impl PlayerBundle {
name: Name(name.to_string()),
player: Player,
level: Level(level),
max_health: SimpleStatBundle::new(match level {
1..=8 => 100 + (level - 1) * 25,
9..=95 => 275 + (level - 8) * 50,
96.. => 4625 + (level - 95) * 75,
0 => unreachable!(),
}),
crit_rate: SimpleStatBundle::new(24),
acc_bonus: SimpleStatBundle::new(0.0),
dmg_bonus: SimpleStatBundle::new(0.0),

View file

@ -226,9 +226,23 @@ impl SimpleStatMarker for Clips {
}
#[derive(Default)]
pub struct Health;
pub struct MaxHealth;
impl SimpleStatMarker for Health {
impl SimpleStatMarker for MaxHealth {
type ValueType = u16;
type BonusType = f32;
fn apply_bonus(value: Self::ValueType, bonus: Self::BonusType) -> Self::ValueType {
((value as f32) * bonus) as u16
}
fn revert_bonus(value: Self::ValueType, bonus: Self::BonusType) -> Self::ValueType {
((value as f32) / bonus) as u16
}
}
#[derive(Default)]
pub struct ArmourBonusValue;
impl SimpleStatMarker for ArmourBonusValue {
type ValueType = u16;
type BonusType = u16;
fn apply_bonus(value: Self::ValueType, bonus: Self::BonusType) -> Self::ValueType {

View file

@ -8,6 +8,7 @@ use crate::{
Name,
armour::{Armour, ArmourCoverage, ArmourValue, Immunities, Immunity},
bonus::ArmourBonusType,
stat::{ArmourBonusValue, SimpleStatBundle},
},
dto::draw_id,
};
@ -27,7 +28,7 @@ pub enum ArmourSlot {
#[cfg_attr(feature = "json", derive(serde::Deserialize, serde::Serialize))]
pub struct ArmourBonusInfo {
pub kind: ArmourBonusType,
pub value: Option<i16>,
pub value: Option<u16>,
}
#[derive(Debug, Clone)]
@ -60,7 +61,7 @@ pub struct ArmourDto {
}
impl ArmourDto {
pub fn new(name: &str, armour: Option<f32>, bonus: Option<i16>) -> Option<Self> {
pub fn new(name: &str, armour: Option<f32>, bonus: Option<u16>) -> Option<Self> {
let base = match name {
"Leather Vest" => Self::LEATHER_VEST,
"Police Vest" => Self::POLICE_VEST,
@ -197,6 +198,13 @@ impl ArmourDto {
Immunities(self.immunities.to_vec()),
));
if let Some(bonus) = self.bonus {
commands.insert((
bonus.kind,
SimpleStatBundle::<ArmourBonusValue>::new(bonus.value.unwrap_or_default()),
));
}
commands.id()
}

View file

@ -12,6 +12,11 @@ pub enum EntityInfo {
owner: usize,
id: usize,
},
Armour {
name: String,
owner: usize,
id: usize,
},
Global,
}