cryp speed stat

This commit is contained in:
ntr 2019-01-06 23:14:57 +11:00
parent 1d9a057775
commit 75a9046cf5
2 changed files with 35 additions and 2 deletions

View File

@ -42,6 +42,7 @@ pub enum Stat {
Agi, Agi,
Int, Int,
Hp, Hp,
Speed,
Stamina, Stamina,
PhysicalDamage, PhysicalDamage,
PhysicalDamageTaken, PhysicalDamageTaken,
@ -91,6 +92,7 @@ pub struct Cryp {
pub phys_dmg: CrypStat, pub phys_dmg: CrypStat,
pub spell_dmg: CrypStat, pub spell_dmg: CrypStat,
pub stamina: CrypStat, pub stamina: CrypStat,
pub speed: CrypStat,
pub hp: CrypStat, pub hp: CrypStat,
pub xp: u64, pub xp: u64,
pub lvl: u8, pub lvl: u8,
@ -113,6 +115,7 @@ impl Cryp {
account: id, account: id,
phys_dmg: CrypStat { base: 0, stat: Stat::PhysicalDamage }, phys_dmg: CrypStat { base: 0, stat: Stat::PhysicalDamage },
spell_dmg: CrypStat { base: 0, stat: Stat::SpellDamage }, spell_dmg: CrypStat { base: 0, stat: Stat::SpellDamage },
speed: CrypStat { base: 0, stat: Stat::SpellDamage },
stamina: CrypStat { base: 0, stat: Stat::Stamina }, stamina: CrypStat { base: 0, stat: Stat::Stamina },
hp: CrypStat { base: 0, stat: Stat::Hp }, hp: CrypStat { base: 0, stat: Stat::Hp },
lvl: 0, lvl: 0,
@ -193,6 +196,7 @@ impl Cryp {
match stat { match stat {
Stat::PhysicalDamage => self.phys_dmg.set(rng.gen_range(other_min, other_max)), Stat::PhysicalDamage => self.phys_dmg.set(rng.gen_range(other_min, other_max)),
Stat::SpellDamage => self.spell_dmg.set(rng.gen_range(other_min, other_max)), Stat::SpellDamage => self.spell_dmg.set(rng.gen_range(other_min, other_max)),
Stat::Speed => self.speed.set(rng.gen_range(other_min, other_max)),
Stat::Stamina => { Stat::Stamina => {
self.stamina.set(rng.gen_range(stam_min, stam_max)); self.stamina.set(rng.gen_range(stam_min, stam_max));
self.hp.set(self.stamina.base) self.hp.set(self.stamina.base)
@ -213,6 +217,7 @@ impl Cryp {
self.roll_stat(Stat::PhysicalDamage); self.roll_stat(Stat::PhysicalDamage);
self.roll_stat(Stat::SpellDamage); self.roll_stat(Stat::SpellDamage);
self.roll_stat(Stat::Speed);
self.roll_stat(Stat::Stamina); self.roll_stat(Stat::Stamina);
self self
@ -366,6 +371,16 @@ impl Cryp {
return modified_spell_dmg; return modified_spell_dmg;
} }
pub fn speed(&self) -> u64 {
let speed_mods = self.effects.iter()
.filter(|e| e.effect.modifications().contains(&Stat::Speed))
.map(|cryp_effect| cryp_effect.effect)
.collect::<Vec<Effect>>();
let modified_speed = speed_mods.iter().fold(self.speed.base, |acc, m| m.apply(acc));
return modified_speed;
}
pub fn hp(&self) -> u64 { pub fn hp(&self) -> u64 {
self.hp.base self.hp.base
} }

View File

@ -377,6 +377,19 @@ impl Game {
self self
} }
fn stack_sort_speed(&mut self) -> &mut Game {
let mut sorted = self.stack.clone();
sorted.sort_unstable_by_key(|s| -> u64 {
let caster = self.cryp_by_id(s.source_cryp_id).unwrap();
caster.speed().saturating_mul(s.skill.speed() as u64)
});
self.stack = sorted;
self.stack.reverse();
self
}
fn resolve_skills(&mut self) -> &mut Game { fn resolve_skills(&mut self) -> &mut Game {
if self.phase != Phase::Resolve { if self.phase != Phase::Resolve {
panic!("game not in Resolve phase"); panic!("game not in Resolve phase");
@ -395,8 +408,7 @@ impl Game {
// add them to the stack // add them to the stack
self.stack.append(&mut ticks); self.stack.append(&mut ticks);
self.stack.sort_unstable_by_key(|s| s.skill.speed()); self.stack_sort_speed();
self.stack.reverse();
// update the stack with the resolved skills // update the stack with the resolved skills
self.stack = self.stack.clone().iter_mut().map(|skill| { self.stack = self.stack.clone().iter_mut().map(|skill| {
@ -425,6 +437,11 @@ impl Game {
self.update_cryp(&mut source); self.update_cryp(&mut source);
self.update_cryp(&mut target); self.update_cryp(&mut target);
// find a way to
// resort the stack after each cast because
// the cryp speed may have changed
// self.stack_sort_speed();
return skill.clone(); return skill.clone();
}).collect::<Vec<Cast>>(); }).collect::<Vec<Cast>>();
@ -961,6 +978,7 @@ mod tests {
let y_cryp = y_team.cryps[0].clone(); let y_cryp = y_team.cryps[0].clone();
game.team_by_id(y_team.id).cryp_by_id(y_cryp.id).unwrap().phys_dmg.set(u64::max_value()); game.team_by_id(y_team.id).cryp_by_id(y_cryp.id).unwrap().phys_dmg.set(u64::max_value());
game.team_by_id(y_team.id).cryp_by_id(y_cryp.id).unwrap().speed.set(u64::max_value());
let _x_stun_id = game.add_skill(x_team.id, x_cryp.id, Some(y_cryp.id), Skill::TestStun).unwrap(); let _x_stun_id = game.add_skill(x_team.id, x_cryp.id, Some(y_cryp.id), Skill::TestStun).unwrap();
game.add_skill(y_team.id, y_cryp.id, Some(x_cryp.id), Skill::Attack).unwrap(); game.add_skill(y_team.id, y_cryp.id, Some(x_cryp.id), Skill::Attack).unwrap();