simplify immunities
This commit is contained in:
parent
1054833dfd
commit
34d9139140
@ -24,7 +24,6 @@ ensure all skills impl
|
|||||||
Skill::Ruin -> aoe stun
|
Skill::Ruin -> aoe stun
|
||||||
|
|
||||||
on attack
|
on attack
|
||||||
Skill::Reflect -> reflect incoming attacks back to opponent
|
|
||||||
Skill::Taunt -> redirect incomnig attacks to self
|
Skill::Taunt -> redirect incomnig attacks to self
|
||||||
Skill::Toxic -> apply debuff to attackers
|
Skill::Toxic -> apply debuff to attackers
|
||||||
|
|
||||||
|
|||||||
@ -258,9 +258,9 @@ impl Cryp {
|
|||||||
self.hp.value == 0
|
self.hp.value == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn immune(&self, skill: Skill) -> Immunity {
|
pub fn immune(&self, skill: Skill) -> Option<Immunity> {
|
||||||
if self.is_ko() {
|
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()
|
let immunities = self.effects.iter()
|
||||||
@ -269,10 +269,10 @@ impl Cryp {
|
|||||||
.collect::<Vec<Effect>>();
|
.collect::<Vec<Effect>>();
|
||||||
|
|
||||||
if immunities.len() > 0 {
|
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 {
|
pub fn disabled(&self, skill: Skill) -> Disable {
|
||||||
@ -450,14 +450,9 @@ impl Cryp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn recharge(&mut self) -> ResolutionResult {
|
pub fn recharge(&mut self) -> ResolutionResult {
|
||||||
let immunity = self.immune(Skill::Recharge);
|
if let Some(immunity) = self.immune(Skill::Recharge) {
|
||||||
let immune = immunity.immune;
|
return ResolutionResult::Immunity {
|
||||||
|
immunity,
|
||||||
if immune {
|
|
||||||
ResolutionResult::Recharge {
|
|
||||||
red: 0,
|
|
||||||
blue: 0,
|
|
||||||
immunity: immunity.clone(),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,18 +462,13 @@ impl Cryp {
|
|||||||
let blue = self.blue_shield.max.saturating_sub(self.blue_shield.value);
|
let blue = self.blue_shield.max.saturating_sub(self.blue_shield.value);
|
||||||
self.blue_shield.value = self.blue_shield.max;
|
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 {
|
pub fn deal_green_damage(&mut self, skill: Skill, amount: u64) -> ResolutionResult {
|
||||||
let immunity = self.immune(skill);
|
if let Some(immunity) = self.immune(skill) {
|
||||||
let immune = immunity.immune;
|
return ResolutionResult::Immunity {
|
||||||
|
immunity,
|
||||||
if immune {
|
|
||||||
return ResolutionResult::Healing {
|
|
||||||
amount: 0,
|
|
||||||
overhealing: 0,
|
|
||||||
immunity: immunity.clone(),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,7 +493,6 @@ impl Cryp {
|
|||||||
return ResolutionResult::Healing {
|
return ResolutionResult::Healing {
|
||||||
amount: healing,
|
amount: healing,
|
||||||
overhealing,
|
overhealing,
|
||||||
immunity,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
true => {
|
true => {
|
||||||
@ -517,21 +506,14 @@ impl Cryp {
|
|||||||
healing: 0,
|
healing: 0,
|
||||||
recharge: 0,
|
recharge: 0,
|
||||||
category: Category::GreenDamage,
|
category: Category::GreenDamage,
|
||||||
immunity,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deal_red_damage(&mut self, skill: Skill, amount: u64) -> ResolutionResult {
|
pub fn deal_red_damage(&mut self, skill: Skill, amount: u64) -> ResolutionResult {
|
||||||
let immunity = self.immune(skill);
|
if let Some(immunity) = self.immune(skill) {
|
||||||
let immune = immunity.immune;
|
return ResolutionResult::Immunity {
|
||||||
|
|
||||||
if immune {
|
|
||||||
return ResolutionResult::Damage {
|
|
||||||
amount: 0,
|
|
||||||
mitigation: 0,
|
|
||||||
category: Category::RedDamage,
|
|
||||||
immunity,
|
immunity,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -566,7 +548,6 @@ impl Cryp {
|
|||||||
amount: delta,
|
amount: delta,
|
||||||
mitigation,
|
mitigation,
|
||||||
category: Category::RedDamage,
|
category: Category::RedDamage,
|
||||||
immunity,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
true => {
|
true => {
|
||||||
@ -584,7 +565,6 @@ impl Cryp {
|
|||||||
damage: 0,
|
damage: 0,
|
||||||
healing,
|
healing,
|
||||||
recharge,
|
recharge,
|
||||||
immunity,
|
|
||||||
category: Category::RedDamage,
|
category: Category::RedDamage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -592,14 +572,8 @@ impl Cryp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn deal_blue_damage(&mut self, skill: Skill, amount: u64) -> ResolutionResult {
|
pub fn deal_blue_damage(&mut self, skill: Skill, amount: u64) -> ResolutionResult {
|
||||||
let immunity = self.immune(skill);
|
if let Some(immunity) = self.immune(skill) {
|
||||||
let immune = immunity.immune;
|
return ResolutionResult::Immunity {
|
||||||
|
|
||||||
if immune {
|
|
||||||
return ResolutionResult::Damage {
|
|
||||||
amount: 0,
|
|
||||||
mitigation: 0,
|
|
||||||
category: Category::BlueDamage,
|
|
||||||
immunity,
|
immunity,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -627,7 +601,6 @@ impl Cryp {
|
|||||||
amount: delta,
|
amount: delta,
|
||||||
mitigation,
|
mitigation,
|
||||||
category: Category::BlueDamage,
|
category: Category::BlueDamage,
|
||||||
immunity,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
true => {
|
true => {
|
||||||
@ -645,7 +618,6 @@ impl Cryp {
|
|||||||
damage: 0,
|
damage: 0,
|
||||||
healing,
|
healing,
|
||||||
recharge,
|
recharge,
|
||||||
immunity,
|
|
||||||
category: Category::BlueDamage,
|
category: Category::BlueDamage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -653,20 +625,20 @@ impl Cryp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_effect(&mut self, skill: Skill, effect: CrypEffect) -> ResolutionResult {
|
pub fn add_effect(&mut self, skill: Skill, effect: CrypEffect) -> ResolutionResult {
|
||||||
let immunity = self.immune(skill);
|
if let Some(immunity) = self.immune(skill) {
|
||||||
let immune = immunity.immune;
|
return ResolutionResult::Immunity {
|
||||||
|
immunity,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// todo modified durations cause of buffs
|
// todo modified durations cause of buffs
|
||||||
let result = ResolutionResult::Effect {
|
let result = ResolutionResult::Effect {
|
||||||
effect: effect.effect,
|
effect: effect.effect,
|
||||||
duration: effect.effect.duration(),
|
duration: effect.effect.duration(),
|
||||||
immunity,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if !immune {
|
// println!("{:?} {:?} adding effect", self.name, effect.effect);
|
||||||
// println!("{:?} {:?} adding effect", self.name, effect.effect);
|
self.effects.push(effect);
|
||||||
self.effects.push(effect);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -366,62 +366,41 @@ impl Game {
|
|||||||
|
|
||||||
for result in cast.resolution.results.iter() {
|
for result in cast.resolution.results.iter() {
|
||||||
match result {
|
match result {
|
||||||
ResolutionResult::Damage { amount, mitigation, category: _, immunity } => {
|
ResolutionResult::Immunity { immunity } =>
|
||||||
match immunity.immune {
|
self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
|
||||||
true => self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
|
cast.resolution.speed, source.name, cast.skill, target.name, immunity.effects)),
|
||||||
cast.resolution.speed, source.name, cast.skill, target.name, immunity.effects)),
|
|
||||||
false => self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:} mitigated)",
|
ResolutionResult::Damage { amount, mitigation, category: _ } =>
|
||||||
cast.resolution.speed, source.name, cast.skill, target.name, amount, mitigation)),
|
self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:} mitigated)",
|
||||||
|
cast.resolution.speed, source.name, cast.skill, target.name, amount, mitigation)),
|
||||||
|
|
||||||
|
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: _ } => {
|
||||||
|
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::Healing { amount, overhealing, immunity } => {
|
ResolutionResult::Effect { effect, duration } =>
|
||||||
match immunity.immune {
|
self.log.push(format!("[{:}] {:} {:?} {:} {:?} {:}T",
|
||||||
true => self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
|
cast.resolution.speed, source.name, cast.skill, target.name, effect, duration)),
|
||||||
cast.resolution.speed, source.name, cast.skill, target.name, immunity.effects)),
|
|
||||||
false => self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:}OH)",
|
ResolutionResult::Removal { effect } =>
|
||||||
cast.resolution.speed, source.name, cast.skill, target.name, amount, overhealing)),
|
self.log.push(format!("[{:}] {:?} removed {:} {:?}",
|
||||||
}
|
cast.resolution.speed, source.name, target.name, effect)),
|
||||||
},
|
|
||||||
ResolutionResult::Inversion { healing, damage, recharge, category: _, immunity } => {
|
ResolutionResult::Recharge { red, blue } =>
|
||||||
match immunity.immune {
|
self.log.push(format!("[{:}] {:} {:?} {:} {:}R {:}B",
|
||||||
true => self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
|
cast.resolution.speed, source.name, cast.skill, target.name, red, blue)),
|
||||||
cast.resolution.speed, source.name, cast.skill, target.name, immunity.effects)),
|
|
||||||
false => match *healing > 0 {
|
ResolutionResult::Evasion { skill: _, evasion_rating } =>
|
||||||
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",
|
|
||||||
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 {:} {:?}",
|
|
||||||
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",
|
|
||||||
cast.resolution.speed, source.name, cast.skill, target.name, red, blue)),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ResolutionResult::Evasion { skill: _, evasion_rating } => {
|
|
||||||
self.log.push(format!("[{:}] {:} {:?} {:} evaded ({:}%)",
|
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)),
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -60,12 +60,13 @@ impl Disable {
|
|||||||
|
|
||||||
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
|
||||||
pub enum ResolutionResult {
|
pub enum ResolutionResult {
|
||||||
Damage { amount: u64, mitigation: u64, category: Category , immunity: Immunity },
|
Immunity { immunity: Immunity },
|
||||||
Healing { amount: u64, overhealing: u64, immunity: Immunity },
|
Damage { amount: u64, mitigation: u64, category: Category },
|
||||||
Recharge { red: u64, blue: u64, immunity: Immunity },
|
Healing { amount: u64, overhealing: u64 },
|
||||||
Inversion { healing: u64, damage: u64, recharge: u64, category: Category, immunity: Immunity },
|
Recharge { red: u64, blue: u64 },
|
||||||
Effect { effect: Effect, duration: u8, immunity: Immunity },
|
Inversion { healing: u64, damage: u64, recharge: u64, category: Category },
|
||||||
Removal { effect: Effect, immunity: Immunity },
|
Effect { effect: Effect, duration: u8 },
|
||||||
|
Removal { effect: Effect },
|
||||||
Evasion { skill: Skill, evasion_rating: u64 },
|
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());
|
resolution.results.push(siphon_damage.clone());
|
||||||
|
|
||||||
match siphon_damage {
|
match siphon_damage {
|
||||||
ResolutionResult::Damage { amount, mitigation: _, category: _, immunity } => {
|
ResolutionResult::Damage { amount, mitigation: _, category: _, } => {
|
||||||
if !immunity.immune {
|
resolution.results.push(cryp.deal_green_damage(Skill::Heal, amount));
|
||||||
resolution.results.push(cryp.deal_green_damage(Skill::Heal, amount));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
_ => panic!("siphon tick damage not dealt {:?}", siphon_damage),
|
_ => 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 {
|
fn purge(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Resolution {
|
||||||
let immunity = target.immune(Skill::Purge);
|
if let Some(immunity) = target.immune(Skill::Purge) {
|
||||||
let immune = immunity.immune;
|
resolution.results.push(ResolutionResult::Immunity { immunity });
|
||||||
|
return resolution;
|
||||||
|
}
|
||||||
|
|
||||||
if !immune {
|
for (i, ce) in target.effects.clone().iter_mut().enumerate() {
|
||||||
for (i, ce) in target.effects.clone().iter_mut().enumerate() {
|
if ce.effect.category() == Category::BlueBuff {
|
||||||
if ce.effect.category() == Category::BlueBuff {
|
target.effects.remove(i);
|
||||||
target.effects.remove(i);
|
resolution.results.push(ResolutionResult::Removal { effect: ce.effect });
|
||||||
resolution.results.push(ResolutionResult::Removal { effect: ce.effect, immunity: immunity.clone() });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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 {
|
fn purify(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Resolution {
|
||||||
let immunity = target.immune(Skill::Purify);
|
if let Some(immunity) = target.immune(Skill::Purify) {
|
||||||
let immune = immunity.immune;
|
resolution.results.push(ResolutionResult::Immunity { immunity });
|
||||||
|
return resolution;
|
||||||
|
}
|
||||||
|
|
||||||
if !immune {
|
for (i, ce) in target.effects.clone().iter_mut().enumerate() {
|
||||||
for (i, ce) in target.effects.clone().iter_mut().enumerate() {
|
if ce.effect.category() == Category::BlueDebuff {
|
||||||
if ce.effect.category() == Category::BlueDebuff {
|
target.effects.remove(i);
|
||||||
target.effects.remove(i);
|
resolution.results.push(ResolutionResult::Removal { effect: ce.effect });
|
||||||
resolution.results.push(ResolutionResult::Removal { effect: ce.effect, immunity: immunity.clone() });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1032,7 +1031,7 @@ mod tests {
|
|||||||
let res = attack(&mut x, &mut y, Resolution::new(Skill::Attack));
|
let res = attack(&mut x, &mut y, Resolution::new(Skill::Attack));
|
||||||
|
|
||||||
match res.results[0] {
|
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"),
|
_ => panic!("not damage"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -1054,7 +1053,7 @@ mod tests {
|
|||||||
assert!(y.hp() == 1);
|
assert!(y.hp() == 1);
|
||||||
|
|
||||||
match res.results[0] {
|
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"),
|
_ => panic!("not damage"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -1084,7 +1083,7 @@ mod tests {
|
|||||||
assert!(y.hp() == 1024);
|
assert!(y.hp() == 1024);
|
||||||
|
|
||||||
match res.results[0] {
|
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"),
|
_ => panic!("not inversion"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -1107,7 +1106,7 @@ mod tests {
|
|||||||
assert!(x.hp() == 768);
|
assert!(x.hp() == 768);
|
||||||
|
|
||||||
match cast.resolution.results[0] {
|
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"),
|
_ => panic!("not damage"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -1160,7 +1159,7 @@ mod tests {
|
|||||||
res = recharge(&mut x, &mut y, res);
|
res = recharge(&mut x, &mut y, res);
|
||||||
|
|
||||||
match res.results[0] {
|
match res.results[0] {
|
||||||
ResolutionResult::Recharge { red, blue, immunity: _ } => {
|
ResolutionResult::Recharge { red, blue } => {
|
||||||
assert!(red == 5);
|
assert!(red == 5);
|
||||||
assert!(blue == 5);
|
assert!(blue == 5);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user