Merge branch 'master' of ssh://cryps.gg:40022/~/cryps

This commit is contained in:
Mashy 2019-03-26 13:24:40 +10:00
commit dda728bfb8
4 changed files with 177 additions and 101 deletions

View File

@ -22,6 +22,8 @@ ensure all skills impl
Skill::Slay -> red attack with bonus somethingorother for blue / maim no healing
Hatred -> damage received converted into bonus dmg
change inversion to several events
make parry semi-aggressive
constants
change to ownership pattern

View File

@ -439,8 +439,10 @@ impl Cryp {
}
pub fn recharge(&mut self) -> Event {
if let Some(immunity) = self.immune(Skill::Recharge) {
let skill = Skill::Recharge;
if let Some(immunity) = self.immune(skill) {
return Event::Immunity {
skill,
immunity,
};
}
@ -451,14 +453,17 @@ impl Cryp {
let blue = self.blue_shield.max.saturating_sub(self.blue_shield.value);
self.blue_shield.value = self.blue_shield.max;
Event::Recharge { red, blue }
Event::Recharge { red, blue, skill }
}
pub fn deal_green_damage(&mut self, skill: Skill, amount: u64) -> Event {
pub fn deal_green_damage(&mut self, skill: Skill, amount: u64) -> Vec<Event> {
let mut events = vec![];
if let Some(immunity) = self.immune(skill) {
return Event::Immunity {
events.push(Event::Immunity {
immunity,
};
skill,
});
return events;
}
let healing_mods = self.effects.iter()
@ -468,43 +473,52 @@ impl Cryp {
// println!("{:?}", healing_mods);
let modified_healing = healing_mods.iter().fold(amount, |acc, m| m.apply(acc));
let modified_green_damage = healing_mods.iter().fold(amount, |acc, m| m.apply(acc));
match self.affected(Effect::Invert) {
false => {
let current_hp = self.hp();
self.hp.increase(modified_healing);
self.hp.increase(modified_green_damage);
let new_hp = self.hp.value;
let healing = new_hp - current_hp;
let overhealing = modified_healing - healing;
let overhealing = modified_green_damage - healing;
return Event::Healing {
events.push(Event::Healing {
skill,
amount: healing,
overhealing,
};
});
},
true => {
events.push(Event::Inversion { skill });
// there is no green shield (yet)
let current_hp = self.hp();
self.reduce_hp(modified_healing);
self.reduce_hp(modified_green_damage);
let delta = current_hp - self.hp();
return Event::Inversion {
damage: delta,
healing: 0,
recharge: 0,
events.push(Event::Damage {
skill,
amount: delta,
mitigation: 0,
category: Category::GreenDamage,
};
});
}
}
return events;
}
pub fn deal_red_damage(&mut self, skill: Skill, amount: u64) -> Event {
pub fn deal_red_damage(&mut self, skill: Skill, amount: u64) -> Vec<Event> {
let mut events = vec![];
if let Some(immunity) = self.immune(skill) {
return Event::Immunity {
events.push(Event::Immunity {
skill,
immunity,
};
});
return events;
}
let red_damage_mods = self.effects.iter()
@ -533,13 +547,16 @@ impl Cryp {
self.reduce_hp(remainder);
let delta = current_hp - self.hp();
return Event::Damage {
events.push(Event::Damage {
skill,
amount: delta,
mitigation,
category: Category::RedDamage,
};
});
},
true => {
events.push(Event::Inversion { skill });
let current_hp = self.hp();
self.hp.increase(modified_damage);
let new_hp = self.hp.value;
@ -550,21 +567,32 @@ impl Cryp {
self.red_shield.increase(overhealing);
let recharge = self.red_shield.value - current_shield;
return Event::Inversion {
damage: 0,
healing,
recharge,
category: Category::RedDamage,
};
if healing > 0 {
events.push(Event::Healing {
skill,
amount: healing,
overhealing: overhealing - recharge,
});
}
if recharge > 0 {
events.push(Event::Recharge { red: recharge, blue: 0, skill });
}
}
}
};
return events;
}
pub fn deal_blue_damage(&mut self, skill: Skill, amount: u64) -> Event {
pub fn deal_blue_damage(&mut self, skill: Skill, amount: u64) -> Vec<Event> {
let mut events = vec![];
if let Some(immunity) = self.immune(skill) {
return Event::Immunity {
events.push(Event::Immunity {
skill,
immunity,
};
});
return events;
}
let blue_damage_mods = self.effects.iter()
@ -573,6 +601,7 @@ impl Cryp {
.collect::<Vec<Effect>>();
// println!("{:?}", blue_damage_mods);
let modified_damage = blue_damage_mods.iter().fold(amount, |acc, m| m.apply(acc));
match self.affected(Effect::Invert) {
@ -580,19 +609,24 @@ impl Cryp {
let remainder = modified_damage.saturating_sub(self.blue_shield.value);
let mitigation = modified_damage.saturating_sub(remainder);
// reduce blue_shield by mitigation amount
self.blue_shield.reduce(mitigation);
// deal remainder to hp
let current_hp = self.hp();
self.reduce_hp(remainder);
let delta = current_hp - self.hp();
return Event::Damage {
events.push(Event::Damage {
skill,
amount: delta,
mitigation,
category: Category::BlueDamage,
};
});
},
true => {
events.push(Event::Inversion { skill });
let current_hp = self.hp();
self.hp.increase(modified_damage);
let new_hp = self.hp.value;
@ -603,19 +637,27 @@ impl Cryp {
self.blue_shield.increase(overhealing);
let recharge = self.blue_shield.value - current_shield;
return Event::Inversion {
damage: 0,
healing,
recharge,
category: Category::BlueDamage,
};
if healing > 0 {
events.push(Event::Healing {
skill,
amount: healing,
overhealing,
});
}
if recharge > 0 {
events.push(Event::Recharge { red: 0, blue: recharge, skill });
}
}
}
};
return events;
}
pub fn add_effect(&mut self, skill: Skill, effect: CrypEffect) -> Event {
if let Some(immunity) = self.immune(skill) {
return Event::Immunity {
skill,
immunity,
};
}
@ -624,6 +666,7 @@ impl Cryp {
let result = Event::Effect {
effect: effect.effect,
duration: effect.effect.duration(),
skill,
};
// println!("{:?} {:?} adding effect", self.name, effect.effect);

View File

@ -435,7 +435,7 @@ impl Game {
resolutions.reverse();
while let Some(resolution) = resolutions.pop() {
// fixme for mash
self.log_resolution(cast.speed, cast.skill, &resolution);
self.log_resolution(cast.speed, &resolution);
// the results go into the resolutions
self.resolved.push(resolution);
}
@ -490,42 +490,37 @@ impl Game {
self
}
fn log_resolution(&mut self, speed: u64, skill: Skill, resolution: &Resolution) -> &mut Game {
fn log_resolution(&mut self, speed: u64, resolution: &Resolution) -> &mut Game {
let Resolution { source, target, event } = resolution;
match event {
Event::Ko =>
self.log.push(format!("{:} KO!", target.name)),
Event::Disable { disable } =>
Event::Disable { skill, disable } =>
self.log.push(format!("{:} {:?} {:} disabled {:?}",
source.name, skill, target.name, disable)),
Event::Immunity { immunity } =>
Event::Immunity { skill, immunity } =>
self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
speed, source.name, skill, target.name, immunity)),
Event::TargetKo =>
Event::TargetKo { skill } =>
self.log.push(format!("[{:}] {:} {:?} {:} - target is KO",
speed, source.name, skill, target.name)),
Event::Damage { amount, mitigation, category: _ } =>
Event::Damage { skill, amount, mitigation, category: _ } =>
self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:} mitigated)",
speed, source.name, skill, target.name, amount, mitigation)),
Event::Healing { amount, overhealing } =>
Event::Healing { skill, amount, overhealing } =>
self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:}OH)",
speed, source.name, skill, target.name, amount, overhealing)),
Event::Inversion { healing, damage, recharge, category: _ } => {
match *healing > 0 {
true => self.log.push(format!("[{:}] {:} {:?} {:} INVERTED {:} ({:} recharge)",
speed, source.name, skill, target.name, healing, recharge)),
false => self.log.push(format!("[{:}] {:} {:?} {:} INVERTED {:}",
speed, source.name, skill, target.name, damage)),
}
},
Event::Inversion { skill } =>
self.log.push(format!("[{:}] {:} {:?} {:} INVERTED",
speed, source.name, skill, target.name)),
Event::Effect { effect, duration } =>
Event::Effect { skill, effect, duration } =>
self.log.push(format!("[{:}] {:} {:?} {:} {:?} {:}T",
speed, source.name, skill, target.name, effect, duration)),
@ -533,11 +528,11 @@ impl Game {
self.log.push(format!("[{:}] {:?} removed {:} {:?}",
speed, source.name, target.name, effect)),
Event::Recharge { red, blue } =>
Event::Recharge { skill, red, blue } =>
self.log.push(format!("[{:}] {:} {:?} {:} {:}R {:}B",
speed, source.name, skill, target.name, red, blue)),
Event::Evasion { skill: _, evasion_rating } =>
Event::Evasion { skill, evasion_rating } =>
self.log.push(format!("[{:}] {:} {:?} {:} evaded ({:}%)",
speed, source.name, skill, target.name, evasion_rating)),
@ -1150,7 +1145,7 @@ mod tests {
let Resolution { source, target: _, event } = r;
match source.id == x_cryp.id {
true => match event {
Event::Effect { effect, duration } => {
Event::Effect { effect, duration, skill: _ } => {
assert!(*effect == Effect::Ruin);
assert!(*duration == 1);
true

View File

@ -72,16 +72,16 @@ impl Resolution {
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub enum Event {
TargetKo,
Disable { disable: Disable },
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 },
Disable { skill: Skill, disable: Disable },
Immunity { skill: Skill, immunity: Immunity },
Damage { skill: Skill, amount: u64, mitigation: u64, category: Category },
Healing { skill: Skill, amount: u64, overhealing: u64 },
Recharge { skill: Skill, red: u64, blue: u64 },
Inversion { skill: Skill },
Effect { skill: Skill, effect: Effect, duration: u8 },
Removal { effect: Effect },
Evasion { skill: Skill, evasion_rating: u64 },
TargetKo { skill: Skill },
Ko,
Incomplete,
@ -616,12 +616,12 @@ impl Skill {
let mut results = vec![];
if let Some(disable) = source.disabled(*self) {
results.push(Resolution::new(source, target).event(Event::Disable { disable }));
results.push(Resolution::new(source, target).event(Event::Disable { disable, skill: *self }));
return results;
}
if target.is_ko() {
results.push(Resolution::new(source, target).event(Event::TargetKo));
results.push(Resolution::new(source, target).event(Event::TargetKo { skill: *self }));
return results;
}
@ -700,7 +700,7 @@ impl Skill {
results = match target.affected(Effect::Corrupt) {
true => match results.iter().any(|r|
match r.event {
Event::Damage { amount: _, mitigation: _, category: _ } => true,
Event::Damage { amount: _, mitigation: _, category: _, skill: _ } => true,
_ => false,
}) {
true => corruption(target, source, results),
@ -746,16 +746,32 @@ impl Skill {
}
fn touch(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
results.push(Resolution::new(source, target).event(target.deal_red_damage(Skill::TestTouch, 0)));
target.deal_red_damage(Skill::TestTouch, 0)
.into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e)));
return results;
}
fn attack(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let amount = source.red_damage();
results.push(Resolution::new(source, target).event(target.deal_red_damage(Skill::Attack, amount)));
target.deal_red_damage(Skill::Attack, amount)
.into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e)));
return results;
}
fn strike(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let amount = source.red_damage();
target.deal_red_damage(Skill::Strike, amount)
.into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e)));
return results;
}
fn stun(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let effect = CrypEffect { effect: Effect::Stun, duration: Effect::Stun.duration(), tick: None };
results.push(Resolution::new(source, target).event(target.add_effect(Skill::Stun, effect)));
@ -799,7 +815,9 @@ fn strangle(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> R
fn strangle_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let amount = source.red_damage();
results.push(Resolution::new(source, target).event(target.deal_red_damage(Skill::StrangleTick, amount)));
target.deal_red_damage(Skill::StrangleTick, amount)
.into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e)));
// remove immunity if target ko
if target.is_ko() {
@ -841,7 +859,9 @@ fn empower(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Re
fn heal(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let amount = source.green_damage();
results.push(Resolution::new(source, target).event(target.deal_green_damage(Skill::Heal, amount)));
target.deal_green_damage(Skill::Heal, amount)
.into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e)));
return results;
}
@ -857,13 +877,17 @@ fn triage(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Res
fn triage_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let amount = source.green_damage().wrapping_div(2);
results.push(Resolution::new(source, target).event(target.deal_green_damage(Skill::TriageTick, amount)));
target.deal_green_damage(Skill::TriageTick, amount)
.into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e)));
return results;
}
fn blast(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let amount = source.blue_damage();
results.push(Resolution::new(source, target).event(target.deal_blue_damage(Skill::Blast, amount)));
target.deal_blue_damage(Skill::Blast, amount)
.into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e)));
return results;
}
@ -897,7 +921,9 @@ fn decay(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Reso
fn decay_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let amount = source.blue_damage();
results.push(Resolution::new(source, target).event(target.deal_blue_damage(Skill::DecayTick, amount)));
target.deal_blue_damage(Skill::DecayTick, amount)
.into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e)));
return results;
}
@ -921,7 +947,9 @@ fn corruption(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) ->
fn corruption_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let amount = source.blue_damage() / 2;
results.push(Resolution::new(source, target).event(target.deal_blue_damage(Skill::CorruptionTick, amount)));
target.deal_blue_damage(Skill::CorruptionTick, amount)
.into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e)));
return results;
}
@ -972,14 +1000,20 @@ fn siphon(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Res
fn siphon_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let amount = source.blue_damage();
let siphon_damage = target.deal_blue_damage(Skill::SiphonTick, amount);
results.push(Resolution::new(source, target).event(siphon_damage.clone()));
let siphon_events = target.deal_blue_damage(Skill::SiphonTick, amount);
match siphon_damage {
Event::Damage { amount, mitigation: _, category: _, } => {
results.push(Resolution::new(source, source).event(source.deal_green_damage(Skill::Heal, amount)));
},
_ => panic!("siphon tick damage not dealt {:?}", siphon_damage),
for e in siphon_events {
match e {
Event::Damage { amount, mitigation: _, category: _, skill: _ } => {
let dmg = source.deal_green_damage(Skill::Siphon, amount);
for e in dmg {
results.push(Resolution::new(source, target).event(e));
};
},
_ => (),
}
results.push(Resolution::new(source, target).event(e));
}
return results;
@ -1025,13 +1059,6 @@ fn banish(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Res
return results;
}
fn strike(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions {
let _amount = source.red_damage();
results.push(Resolution::new(source, target).event(target.deal_red_damage(Skill::Attack, u64::max_value())));
return results;
}
#[cfg(test)]
mod tests {
use skill::*;
@ -1087,7 +1114,7 @@ mod tests {
let Resolution { source: _, target: _, event } = results.remove(0);
match event {
Event::Damage { amount, mitigation: _, category: _ } => assert_eq!(amount, 50),
Event::Damage { amount, mitigation: _, category: _, skill: _ } => assert_eq!(amount, 50),
_ => panic!("not damage"),
};
}
@ -1110,7 +1137,7 @@ mod tests {
let Resolution { source: _, target: _, event } = results.remove(0);
match event {
Event::Damage { amount, mitigation: _, category: _ } => assert_eq!(amount, 1023),
Event::Damage { amount, mitigation: _, category: _, skill: _ } => assert_eq!(amount, 1023),
_ => panic!("not damage"),
};
}
@ -1139,11 +1166,20 @@ mod tests {
let mut results = attack(&mut x, &mut y, vec![]);
assert!(y.hp() == 1024);
let Resolution { source: _, target: _, event } = results.remove(0);
match event {
Event::Inversion { damage: _, healing: _, recharge, category: _ } => assert_eq!(recharge, 64),
match results.remove(0).event {
Event::Inversion { skill } => assert_eq!(skill, Skill::Attack),
_ => panic!("not inversion"),
};
match results.remove(0).event {
Event::Healing { skill: _, overhealing: _, amount } => assert_eq!(amount, 256),
_ => panic!("not healing from inversion"),
};
match results.remove(0).event {
Event::Recharge { skill: _, red, blue: _ } => assert_eq!(red, 64),
_ => panic!("not recharge from inversion"),
};
}
#[test]
@ -1163,7 +1199,7 @@ mod tests {
let Resolution { source: _, target: _, event } = results.remove(0);
match event {
Event::Damage { amount, mitigation: _, category: _ } => assert_eq!(amount, 256),
Event::Damage { amount, mitigation: _, category: _, skill: _ } => assert_eq!(amount, 256),
_ => panic!("not damage"),
};
}
@ -1226,7 +1262,7 @@ mod tests {
let Resolution { source: _, target: _, event } = results.remove(0);
match event {
Event::Recharge { red, blue } => {
Event::Recharge { red, blue, skill: _ } => {
assert!(red == 5);
assert!(blue == 5);
}