simplify immunities

This commit is contained in:
ntr 2019-03-24 16:41:36 +11:00
parent 1054833dfd
commit 34d9139140
4 changed files with 84 additions and 135 deletions

View File

@ -24,7 +24,6 @@ ensure all skills impl
Skill::Ruin -> aoe stun
on attack
Skill::Reflect -> reflect incoming attacks back to opponent
Skill::Taunt -> redirect incomnig attacks to self
Skill::Toxic -> apply debuff to attackers

View File

@ -258,9 +258,9 @@ impl Cryp {
self.hp.value == 0
}
pub fn immune(&self, skill: Skill) -> Immunity {
pub fn immune(&self, skill: Skill) -> Option<Immunity> {
if self.is_ko() {
return Immunity { immune: true, effects: vec![Effect::Ko]};
return Some(Immunity { immune: true, effects: vec![Effect::Ko]});
}
let immunities = self.effects.iter()
@ -269,10 +269,10 @@ impl Cryp {
.collect::<Vec<Effect>>();
if immunities.len() > 0 {
return Immunity { immune: true, effects: immunities};
return Some(Immunity { immune: true, effects: immunities});
}
return Immunity { immune: false, effects: vec![]};
None
}
pub fn disabled(&self, skill: Skill) -> Disable {
@ -450,14 +450,9 @@ impl Cryp {
}
pub fn recharge(&mut self) -> ResolutionResult {
let immunity = self.immune(Skill::Recharge);
let immune = immunity.immune;
if immune {
ResolutionResult::Recharge {
red: 0,
blue: 0,
immunity: immunity.clone(),
if let Some(immunity) = self.immune(Skill::Recharge) {
return ResolutionResult::Immunity {
immunity,
};
}
@ -467,18 +462,13 @@ impl Cryp {
let blue = self.blue_shield.max.saturating_sub(self.blue_shield.value);
self.blue_shield.value = self.blue_shield.max;
ResolutionResult::Recharge { red, blue, immunity }
ResolutionResult::Recharge { red, blue }
}
pub fn deal_green_damage(&mut self, skill: Skill, amount: u64) -> ResolutionResult {
let immunity = self.immune(skill);
let immune = immunity.immune;
if immune {
return ResolutionResult::Healing {
amount: 0,
overhealing: 0,
immunity: immunity.clone(),
if let Some(immunity) = self.immune(skill) {
return ResolutionResult::Immunity {
immunity,
};
}
@ -503,7 +493,6 @@ impl Cryp {
return ResolutionResult::Healing {
amount: healing,
overhealing,
immunity,
};
},
true => {
@ -517,21 +506,14 @@ impl Cryp {
healing: 0,
recharge: 0,
category: Category::GreenDamage,
immunity,
};
}
}
}
pub fn deal_red_damage(&mut self, skill: Skill, amount: u64) -> ResolutionResult {
let immunity = self.immune(skill);
let immune = immunity.immune;
if immune {
return ResolutionResult::Damage {
amount: 0,
mitigation: 0,
category: Category::RedDamage,
if let Some(immunity) = self.immune(skill) {
return ResolutionResult::Immunity {
immunity,
};
}
@ -566,7 +548,6 @@ impl Cryp {
amount: delta,
mitigation,
category: Category::RedDamage,
immunity,
};
},
true => {
@ -584,7 +565,6 @@ impl Cryp {
damage: 0,
healing,
recharge,
immunity,
category: Category::RedDamage,
};
}
@ -592,14 +572,8 @@ impl Cryp {
}
pub fn deal_blue_damage(&mut self, skill: Skill, amount: u64) -> ResolutionResult {
let immunity = self.immune(skill);
let immune = immunity.immune;
if immune {
return ResolutionResult::Damage {
amount: 0,
mitigation: 0,
category: Category::BlueDamage,
if let Some(immunity) = self.immune(skill) {
return ResolutionResult::Immunity {
immunity,
};
}
@ -627,7 +601,6 @@ impl Cryp {
amount: delta,
mitigation,
category: Category::BlueDamage,
immunity,
};
},
true => {
@ -645,7 +618,6 @@ impl Cryp {
damage: 0,
healing,
recharge,
immunity,
category: Category::BlueDamage,
};
}
@ -653,20 +625,20 @@ impl Cryp {
}
pub fn add_effect(&mut self, skill: Skill, effect: CrypEffect) -> ResolutionResult {
let immunity = self.immune(skill);
let immune = immunity.immune;
if let Some(immunity) = self.immune(skill) {
return ResolutionResult::Immunity {
immunity,
};
}
// todo modified durations cause of buffs
let result = ResolutionResult::Effect {
effect: effect.effect,
duration: effect.effect.duration(),
immunity,
};
if !immune {
// println!("{:?} {:?} adding effect", self.name, effect.effect);
self.effects.push(effect);
}
return result;
}

View File

@ -366,62 +366,41 @@ impl Game {
for result in cast.resolution.results.iter() {
match result {
ResolutionResult::Damage { amount, mitigation, category: _, immunity } => {
match immunity.immune {
true => self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
ResolutionResult::Immunity { immunity } =>
self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
cast.resolution.speed, source.name, cast.skill, target.name, immunity.effects)),
false => self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:} mitigated)",
ResolutionResult::Damage { amount, mitigation, category: _ } =>
self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:} mitigated)",
cast.resolution.speed, source.name, cast.skill, target.name, amount, mitigation)),
}
},
ResolutionResult::Healing { amount, overhealing, immunity } => {
match immunity.immune {
true => self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
cast.resolution.speed, source.name, cast.skill, target.name, immunity.effects)),
false => self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:}OH)",
ResolutionResult::Healing { amount, overhealing } =>
self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:}OH)",
cast.resolution.speed, source.name, cast.skill, target.name, amount, overhealing)),
}
},
ResolutionResult::Inversion { healing, damage, recharge, category: _, immunity } => {
match immunity.immune {
true => self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
cast.resolution.speed, source.name, cast.skill, target.name, immunity.effects)),
false => match *healing > 0 {
ResolutionResult::Inversion { healing, damage, recharge, category: _ } => {
match *healing > 0 {
true => self.log.push(format!("[{:}] {:} {:?} {:} INVERTED {:} ({:} recharge)",
cast.resolution.speed, source.name, cast.skill, target.name, healing, recharge)),
false => self.log.push(format!("[{:}] {:} {:?} {:} INVERTED {:}",
cast.resolution.speed, source.name, cast.skill, target.name, damage)),
}
}
},
ResolutionResult::Effect { effect, duration, immunity } => {
match immunity.immune {
true => self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
cast.resolution.speed, source.name, cast.skill, target.name, immunity.effects)),
false => self.log.push(format!("[{:}] {:} {:?} {:} {:?} {:}T",
ResolutionResult::Effect { effect, duration } =>
self.log.push(format!("[{:}] {:} {:?} {:} {:?} {:}T",
cast.resolution.speed, source.name, cast.skill, target.name, effect, duration)),
}
},
ResolutionResult::Removal { effect, immunity } => {
match immunity.immune {
true => self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
cast.resolution.speed, source.name, cast.skill, target.name, immunity.effects)),
false => self.log.push(format!("[{:}] {:?} removed {:} {:?}",
ResolutionResult::Removal { effect } =>
self.log.push(format!("[{:}] {:?} removed {:} {:?}",
cast.resolution.speed, source.name, target.name, effect)),
}
},
ResolutionResult::Recharge { red, blue, immunity } => {
match immunity.immune {
true => self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
cast.resolution.speed, source.name, cast.skill, target.name, immunity.effects)),
false => self.log.push(format!("[{:}] {:} {:?} {:} {:}R {:}B",
ResolutionResult::Recharge { red, blue } =>
self.log.push(format!("[{:}] {:} {:?} {:} {:}R {:}B",
cast.resolution.speed, source.name, cast.skill, target.name, red, blue)),
}
},
ResolutionResult::Evasion { skill: _, evasion_rating } => {
ResolutionResult::Evasion { skill: _, evasion_rating } =>
self.log.push(format!("[{:}] {:} {:?} {:} evaded ({:}%)",
cast.resolution.speed, source.name, cast.skill, target.name, evasion_rating));
},
cast.resolution.speed, source.name, cast.skill, target.name, evasion_rating)),
}
}

View File

@ -60,12 +60,13 @@ impl Disable {
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub enum ResolutionResult {
Damage { amount: u64, mitigation: u64, category: Category , immunity: Immunity },
Healing { amount: u64, overhealing: u64, immunity: Immunity },
Recharge { red: u64, blue: u64, immunity: Immunity },
Inversion { healing: u64, damage: u64, recharge: u64, category: Category, immunity: Immunity },
Effect { effect: Effect, duration: u8, immunity: Immunity },
Removal { effect: Effect, immunity: Immunity },
Immunity { immunity: Immunity },
Damage { amount: u64, mitigation: u64, category: Category },
Healing { amount: u64, overhealing: u64 },
Recharge { red: u64, blue: u64 },
Inversion { healing: u64, damage: u64, recharge: u64, category: Category },
Effect { effect: Effect, duration: u8 },
Removal { effect: Effect },
Evasion { skill: Skill, evasion_rating: u64 },
}
@ -909,10 +910,8 @@ fn siphon_tick(cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -
resolution.results.push(siphon_damage.clone());
match siphon_damage {
ResolutionResult::Damage { amount, mitigation: _, category: _, immunity } => {
if !immunity.immune {
ResolutionResult::Damage { amount, mitigation: _, category: _, } => {
resolution.results.push(cryp.deal_green_damage(Skill::Heal, amount));
}
},
_ => panic!("siphon tick damage not dealt {:?}", siphon_damage),
}
@ -933,15 +932,15 @@ fn silence(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> R
}
fn purge(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Resolution {
let immunity = target.immune(Skill::Purge);
let immune = immunity.immune;
if let Some(immunity) = target.immune(Skill::Purge) {
resolution.results.push(ResolutionResult::Immunity { immunity });
return resolution;
}
if !immune {
for (i, ce) in target.effects.clone().iter_mut().enumerate() {
if ce.effect.category() == Category::BlueBuff {
target.effects.remove(i);
resolution.results.push(ResolutionResult::Removal { effect: ce.effect, immunity: immunity.clone() });
}
resolution.results.push(ResolutionResult::Removal { effect: ce.effect });
}
}
@ -949,15 +948,15 @@ fn purge(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Res
}
fn purify(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Resolution {
let immunity = target.immune(Skill::Purify);
let immune = immunity.immune;
if let Some(immunity) = target.immune(Skill::Purify) {
resolution.results.push(ResolutionResult::Immunity { immunity });
return resolution;
}
if !immune {
for (i, ce) in target.effects.clone().iter_mut().enumerate() {
if ce.effect.category() == Category::BlueDebuff {
target.effects.remove(i);
resolution.results.push(ResolutionResult::Removal { effect: ce.effect, immunity: immunity.clone() });
}
resolution.results.push(ResolutionResult::Removal { effect: ce.effect });
}
}
@ -1032,7 +1031,7 @@ mod tests {
let res = attack(&mut x, &mut y, Resolution::new(Skill::Attack));
match res.results[0] {
ResolutionResult::Damage { amount, mitigation: _, category: _, immunity: _ } => assert_eq!(amount, 50),
ResolutionResult::Damage { amount, mitigation: _, category: _ } => assert_eq!(amount, 50),
_ => panic!("not damage"),
};
}
@ -1054,7 +1053,7 @@ mod tests {
assert!(y.hp() == 1);
match res.results[0] {
ResolutionResult::Damage { amount, mitigation: _, category: _, immunity: _ } => assert_eq!(amount, 1023),
ResolutionResult::Damage { amount, mitigation: _, category: _ } => assert_eq!(amount, 1023),
_ => panic!("not damage"),
};
}
@ -1084,7 +1083,7 @@ mod tests {
assert!(y.hp() == 1024);
match res.results[0] {
ResolutionResult::Inversion { damage: _, healing: _, recharge, category: _, immunity: _ } => assert_eq!(recharge, 64),
ResolutionResult::Inversion { damage: _, healing: _, recharge, category: _ } => assert_eq!(recharge, 64),
_ => panic!("not inversion"),
};
}
@ -1107,7 +1106,7 @@ mod tests {
assert!(x.hp() == 768);
match cast.resolution.results[0] {
ResolutionResult::Damage { amount, mitigation: _, category: _, immunity: _ } => assert_eq!(amount, 256),
ResolutionResult::Damage { amount, mitigation: _, category: _ } => assert_eq!(amount, 256),
_ => panic!("not damage"),
};
}
@ -1160,7 +1159,7 @@ mod tests {
res = recharge(&mut x, &mut y, res);
match res.results[0] {
ResolutionResult::Recharge { red, blue, immunity: _ } => {
ResolutionResult::Recharge { red, blue } => {
assert!(red == 5);
assert!(blue == 5);
}