make fortitude scale of difference from maximum health

This commit is contained in:
do-no-van 2024-01-21 20:15:24 +00:00
parent 8c5759cb5e
commit 646c57501f
9 changed files with 11 additions and 49 deletions

View File

@ -391,7 +391,6 @@ impl Attack {
time, time,
attacker.map(|a| a.uid), attacker.map(|a| a.uid),
target.stats, target.stats,
target.health,
applied_damage, applied_damage,
strength_modifier, strength_modifier,
)), )),
@ -611,7 +610,6 @@ impl Attack {
time, time,
attacker.map(|a| a.uid), attacker.map(|a| a.uid),
target.stats, target.stats,
target.health,
accumulated_damage, accumulated_damage,
strength_modifier, strength_modifier,
)), )),
@ -1179,7 +1177,6 @@ impl CombatBuff {
time: Time, time: Time,
uid: Option<Uid>, uid: Option<Uid>,
tgt_stats: Option<&Stats>, tgt_stats: Option<&Stats>,
tgt_health: Option<&Health>,
damage: f32, damage: f32,
strength_modifier: f32, strength_modifier: f32,
) -> Buff { ) -> Buff {
@ -1199,7 +1196,6 @@ impl CombatBuff {
source, source,
time, time,
tgt_stats, tgt_stats,
tgt_health,
) )
} }
} }

View File

@ -4,7 +4,7 @@ use crate::{
AttackEffect, CombatBuff, CombatBuffStrength, CombatEffect, CombatRequirement, AttackEffect, CombatBuff, CombatBuffStrength, CombatEffect, CombatRequirement,
DamagedEffect, DamagedEffect,
}, },
comp::{aura::AuraKey, Health, Stats}, comp::{aura::AuraKey, Stats},
resources::{Secs, Time}, resources::{Secs, Time},
uid::Uid, uid::Uid,
}; };
@ -70,12 +70,12 @@ pub enum BuffKind {
/// 50% increase, 1.0 is a 100% increase. /// 50% increase, 1.0 is a 100% increase.
Hastened, Hastened,
/// Increases resistance to incoming poise, and poise damage dealt as health /// Increases resistance to incoming poise, and poise damage dealt as health
/// is lost from the time the buff activated. /// is lost.
/// Strength scales the resistance non-linearly. 0.5 provides 50%, 1.0 /// Strength scales the resistance non-linearly. 0.5 provides 50%, 1.0
/// provides 67%. /// provides 67%.
/// Strength scales the poise damage increase linearly, a strength of 1.0 /// Strength scales the poise damage increase linearly, a strength of 1.0
/// and n health less from activation will cause poise damage to increase by /// and n health less from maximum health will cause poise damage to
/// n%. /// increase by n%.
Fortitude, Fortitude,
/// Increases both attack damage and vulnerability to damage. /// Increases both attack damage and vulnerability to damage.
/// Damage increases linearly with strength, 1.0 is a 100% increase. /// Damage increases linearly with strength, 1.0 is a 100% increase.
@ -268,12 +268,7 @@ impl BuffKind {
/// only the strongest. /// only the strongest.
pub fn stacks(self) -> bool { matches!(self, BuffKind::PotionSickness) } pub fn stacks(self) -> bool { matches!(self, BuffKind::PotionSickness) }
pub fn effects( pub fn effects(&self, data: &BuffData, stats: Option<&Stats>) -> Vec<BuffEffect> {
&self,
data: &BuffData,
stats: Option<&Stats>,
health: Option<&Health>,
) -> Vec<BuffEffect> {
// Normalized nonlinear scaling // Normalized nonlinear scaling
let nn_scaling = |a| a / (a + 0.5); let nn_scaling = |a| a / (a + 0.5);
let instance = rand::random(); let instance = rand::random();
@ -392,10 +387,7 @@ impl BuffKind {
], ],
BuffKind::Fortitude => vec![ BuffKind::Fortitude => vec![
BuffEffect::PoiseReduction(nn_scaling(data.strength)), BuffEffect::PoiseReduction(nn_scaling(data.strength)),
BuffEffect::PoiseDamageFromLostHealth { BuffEffect::PoiseDamageFromLostHealth(data.strength),
initial_health: health.map_or(0.0, |h| h.current()),
strength: data.strength,
},
], ],
BuffKind::Parried => vec![BuffEffect::AttackSpeed(0.5)], BuffKind::Parried => vec![BuffEffect::AttackSpeed(0.5)],
//TODO: Handle potion sickness in a more general way. //TODO: Handle potion sickness in a more general way.
@ -601,10 +593,7 @@ pub enum BuffEffect {
/// Reduces amount of speed increase by consumables /// Reduces amount of speed increase by consumables
MoveSpeedReduction(f32), MoveSpeedReduction(f32),
/// Increases poise damage dealt when health is lost /// Increases poise damage dealt when health is lost
PoiseDamageFromLostHealth { PoiseDamageFromLostHealth(f32),
initial_health: f32,
strength: f32,
},
/// Modifier to the amount of damage dealt with attacks /// Modifier to the amount of damage dealt with attacks
AttackDamage(f32), AttackDamage(f32),
/// Overrides the precision multiplier applied to an attack /// Overrides the precision multiplier applied to an attack
@ -679,9 +668,8 @@ impl Buff {
source: BuffSource, source: BuffSource,
time: Time, time: Time,
stats: Option<&Stats>, stats: Option<&Stats>,
health: Option<&Health>,
) -> Self { ) -> Self {
let effects = kind.effects(&data, stats, health); let effects = kind.effects(&data, stats);
let cat_ids = kind.extend_cat_ids(cat_ids); let cat_ids = kind.extend_cat_ids(cat_ids);
let start_time = Time(time.0 + data.delay.map_or(0.0, |delay| delay.0)); let start_time = Time(time.0 + data.delay.map_or(0.0, |delay| delay.0));
let end_time = if cat_ids let end_time = if cat_ids
@ -941,7 +929,6 @@ pub mod tests {
BuffSource::Unknown, BuffSource::Unknown,
time, time,
None, None,
None,
) )
} }

View File

@ -127,7 +127,6 @@ impl CharacterBehavior for Data {
BuffSource::Character { by: *data.uid }, BuffSource::Character { by: *data.uid },
*data.time, *data.time,
Some(data.stats), Some(data.stats),
data.health,
); );
output_events.emit_server(ServerEvent::Buff { output_events.emit_server(ServerEvent::Buff {
entity: data.entity, entity: data.entity,

View File

@ -232,7 +232,6 @@ fn activate_aura(
source, source,
*read_data.time, *read_data.time,
stats, stats,
Some(health),
)), )),
}); });
} }

View File

@ -153,7 +153,6 @@ impl<'a> System<'a> for Sys {
BuffSource::World, BuffSource::World,
*read_data.time, *read_data.time,
Some(&stat), Some(&stat),
Some(health),
)), )),
}); });
} }
@ -171,7 +170,6 @@ impl<'a> System<'a> for Sys {
BuffSource::World, BuffSource::World,
*read_data.time, *read_data.time,
Some(&stat), Some(&stat),
Some(health),
)), )),
}); });
} }
@ -202,7 +200,6 @@ impl<'a> System<'a> for Sys {
BuffSource::World, BuffSource::World,
*read_data.time, *read_data.time,
Some(&stat), Some(&stat),
Some(health),
)), )),
}); });
} }
@ -221,7 +218,6 @@ impl<'a> System<'a> for Sys {
BuffSource::World, BuffSource::World,
*read_data.time, *read_data.time,
Some(&stat), Some(&stat),
Some(health),
)), )),
}); });
} }
@ -239,7 +235,6 @@ impl<'a> System<'a> for Sys {
BuffSource::World, BuffSource::World,
*read_data.time, *read_data.time,
Some(&stat), Some(&stat),
Some(health),
)), )),
}); });
} }
@ -257,7 +252,6 @@ impl<'a> System<'a> for Sys {
BuffSource::World, BuffSource::World,
*read_data.time, *read_data.time,
Some(&stat), Some(&stat),
Some(health),
)), )),
}); });
// When standing on IceSpike also apply Frozen // When standing on IceSpike also apply Frozen
@ -270,7 +264,6 @@ impl<'a> System<'a> for Sys {
BuffSource::World, BuffSource::World,
*read_data.time, *read_data.time,
Some(&stat), Some(&stat),
Some(health),
)), )),
}); });
} }
@ -288,7 +281,6 @@ impl<'a> System<'a> for Sys {
BuffSource::World, BuffSource::World,
*read_data.time, *read_data.time,
Some(&stat), Some(&stat),
Some(health),
)), )),
}); });
} }
@ -310,7 +302,6 @@ impl<'a> System<'a> for Sys {
BuffSource::World, BuffSource::World,
*read_data.time, *read_data.time,
Some(&stat), Some(&stat),
Some(health),
)), )),
}); });
} else if matches!( } else if matches!(
@ -387,7 +378,6 @@ impl<'a> System<'a> for Sys {
buff.source, buff.source,
*read_data.time, *read_data.time,
Some(&stat), Some(&stat),
Some(health),
)), )),
}); });
} }
@ -701,11 +691,8 @@ fn execute_effect(
BuffEffect::MoveSpeedReduction(red) => { BuffEffect::MoveSpeedReduction(red) => {
stat.move_speed_multiplier *= 1.0 - *red; stat.move_speed_multiplier *= 1.0 - *red;
}, },
BuffEffect::PoiseDamageFromLostHealth { BuffEffect::PoiseDamageFromLostHealth(strength) => {
initial_health, let lost_health = health.maximum() - health.current();
strength,
} => {
let lost_health = (*initial_health - health.current()).max(0.0);
stat.poise_damage_modifier *= lost_health / 100.0 * *strength; stat.poise_damage_modifier *= lost_health / 100.0 * *strength;
}, },
BuffEffect::AttackDamage(dam) => { BuffEffect::AttackDamage(dam) => {

View File

@ -713,7 +713,7 @@ impl<'a> AgentData<'a> {
}, },
Effect::Buff(BuffEffect { kind, data, .. }) => { Effect::Buff(BuffEffect { kind, data, .. }) => {
if let Some(duration) = data.duration { if let Some(duration) = data.duration {
for effect in kind.effects(data, self.stats, self.health) { for effect in kind.effects(data, self.stats) {
match effect { match effect {
comp::BuffEffect::HealthChangeOverTime { rate, kind, .. } => { comp::BuffEffect::HealthChangeOverTime { rate, kind, .. } => {
let amount = match kind { let amount = match kind {

View File

@ -4287,7 +4287,6 @@ fn cast_buff(buffkind: BuffKind, data: BuffData, server: &mut Server, target: Ec
let ecs = &server.state.ecs(); let ecs = &server.state.ecs();
let mut buffs_all = ecs.write_storage::<comp::Buffs>(); let mut buffs_all = ecs.write_storage::<comp::Buffs>();
let stats = ecs.read_storage::<comp::Stats>(); let stats = ecs.read_storage::<comp::Stats>();
let healths = ecs.read_storage::<comp::Health>();
let time = ecs.read_resource::<Time>(); let time = ecs.read_resource::<Time>();
if let Some(mut buffs) = buffs_all.get_mut(target) { if let Some(mut buffs) = buffs_all.get_mut(target) {
buffs.insert( buffs.insert(
@ -4298,7 +4297,6 @@ fn cast_buff(buffkind: BuffKind, data: BuffData, server: &mut Server, target: Ec
BuffSource::Command, BuffSource::Command,
*time, *time,
stats.get(target), stats.get(target),
healths.get(target),
), ),
*time, *time,
); );

View File

@ -1417,7 +1417,6 @@ pub fn handle_parry_hook(
}; };
let time = ecs.read_resource::<Time>(); let time = ecs.read_resource::<Time>();
let stats = ecs.read_storage::<comp::Stats>(); let stats = ecs.read_storage::<comp::Stats>();
let healths = ecs.read_storage::<comp::Health>();
let buff = buff::Buff::new( let buff = buff::Buff::new(
BuffKind::Parried, BuffKind::Parried,
data, data,
@ -1425,7 +1424,6 @@ pub fn handle_parry_hook(
source, source,
*time, *time,
stats.get(attacker), stats.get(attacker),
healths.get(attacker),
); );
server_eventbus.emit_now(ServerEvent::Buff { server_eventbus.emit_now(ServerEvent::Buff {
entity: attacker, entity: attacker,

View File

@ -253,7 +253,6 @@ impl StateExt for State {
Effect::Buff(buff) => { Effect::Buff(buff) => {
let time = self.ecs().read_resource::<Time>(); let time = self.ecs().read_resource::<Time>();
let stats = self.ecs().read_storage::<comp::Stats>(); let stats = self.ecs().read_storage::<comp::Stats>();
let healths = self.ecs().read_storage::<comp::Health>();
self.ecs() self.ecs()
.write_storage::<comp::Buffs>() .write_storage::<comp::Buffs>()
.get_mut(entity) .get_mut(entity)
@ -266,7 +265,6 @@ impl StateExt for State {
comp::BuffSource::Item, comp::BuffSource::Item,
*time, *time,
stats.get(entity), stats.get(entity),
healths.get(entity),
), ),
*time, *time,
) )