purge and purify

This commit is contained in:
ntr 2018-11-16 13:48:49 +11:00
parent 92ee2ad52e
commit 84debe6bbc
2 changed files with 109 additions and 9 deletions

View File

@ -9,7 +9,7 @@ use failure::err_msg;
use account::Account;
use rpc::{CrypSpawnParams};
use skill::{Skill, Cooldown, Effect, Cast};
use skill::{Skill, Cooldown, Effect, Cast, Source};
use game::{Log};
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]

View File

@ -148,13 +148,70 @@ impl Effect {
_ => panic!("{:?} does not have a mod effect", self),
}
}
pub fn source(&self) -> Source {
match self {
// physical
Effect::Stun => Source::Debuff,
Effect::Block => Source::Buff,
Effect::Bleed => Source::Debuff,
Effect::Leech => Source::Debuff,
Effect::Airborne => Source::Buff,
Effect::Untouchable => Source::Buff,
Effect::Deadly => Source::Buff,
Effect::Vulnerable => Source::Debuff,
Effect::Fury => Source::Buff,
Effect::Evasion => Source::Buff,
Effect::Blind => Source::Debuff,
Effect::Snare => Source::Debuff,
Effect::Empower => Source::Buff,
// magic
Effect::Hex => Source::Debuff,
Effect::Curse => Source::Debuff,
Effect::Banish => Source::Debuff, // todo randomise
Effect::Slow => Source::Debuff,
Effect::Haste => Source::Buff,
Effect::Enslave => Source::Debuff,
Effect::Mesmerise => Source::Debuff,
Effect::Amplify => Source::Buff,
Effect::Silence => Source::Debuff,
// magic immunity
Effect::Shield => Source::Buff,
// effects over time
Effect::Triage => Source::Buff,
Effect::Decay => Source::Debuff,
Effect::Regen => Source::Buff,
Effect::Drain => Source::Debuff,
Effect::SpeedDrain => Source::Debuff,
Effect::SpeedIncrease => Source::Buff,
}
}
}
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub enum Damage {
Physical,
Magic,
}
// #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
// enum Style {
// Offensive,
// Defensive,
// }
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub enum Source {
Buff,
Debuff,
Stat,
}
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub enum Skill {
Attack,
@ -217,6 +274,7 @@ pub enum Skill {
Silence,
Inquiry,
Purify,
Purge,
// Precision,
// -----------------
@ -299,6 +357,7 @@ impl Skill {
Skill::Silence => Some(2),
Skill::Inquiry => Some(2),
Skill::Purify => Some(1),
Skill::Purge => Some(1),
// -----------------
// Chaos
@ -382,6 +441,7 @@ impl Skill {
Skill::Silence => Damage::Magic,
Skill::Inquiry => Damage::Magic,
Skill::Purify => Damage::Magic,
Skill::Purge => Damage::Magic,
// -----------------
// Chaos
@ -466,6 +526,7 @@ impl Skill {
Skill::Silence => 2,
Skill::Inquiry => 2,
Skill::Purify => 1,
Skill::Purge => 1,
// -----------------
// Chaos
@ -542,7 +603,7 @@ impl Skill {
Skill::TriageTick => triage_tick(cryp, target, log), // hot
Skill::Throw => throw(cryp, target, log), // no dmg stun, adds vulnerable
Skill::Charm => panic!("nyi"), // target casts random spell on teammate
Skill::Calm => panic!("nyi"), // remove fear, taunt
Skill::Calm => panic!("nyi"), // physical fear, taunt removal
Skill::Rez => panic!("nyi"),
// -----------------
@ -555,8 +616,8 @@ impl Skill {
Skill::Drain => drain(cryp, target, log),
Skill::DrainTick => drain_tick(cryp, target, log), // hot
Skill::Curse => curse(cryp, target, log),
Skill::Plague => panic!("nyi"), // aoe dot
Skill::Ruin => panic!("nyi"), // aoe
Skill::Plague => panic!("nyi"), // dot that spreads every turn
Skill::Ruin => panic!("nyi"), // aoe version of blast
// -----------------
// Purity
@ -564,10 +625,11 @@ impl Skill {
// Skill::Precision => panic!("nyi"),
Skill::Empower => empower(cryp, target, log), // increased phys dmg
Skill::Slay => panic!("nyi"), // phys dmg mult by target magic dmg
Skill::Shield => panic!("nyi"), // target is immune to magic dmg and fx
Skill::Shield => shield(cryp, target, log), // target is immune to magic dmg and fx
Skill::Silence => silence(cryp, target, log), // target cannot cast spells
Skill::Inquiry => panic!("nyi"), //
Skill::Purify => panic!("nyi"), // dispel all debuffs
Skill::Purify => purify(cryp, target, log), // dispel all debuffs
Skill::Purge => purge(cryp, target, log), // dispel all buffs
// -----------------
// Chaos
@ -575,7 +637,7 @@ impl Skill {
Skill::Banish => banish(cryp, target, log), // TODO prevent all actions
Skill::Hex => hex(cryp, target, log), // todo prevent casting
Skill::Fear => panic!("nyi"), // cast random spell on self
Skill::Taunt => panic!("nyi"), // target
Skill::Taunt => panic!("nyi"), // target forced to attack
Skill::Pause => panic!("nyi"), // speed slow
// -----------------
@ -733,20 +795,44 @@ fn drain(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
}
fn drain_tick(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
// damage part
// Damage part
let (damage, _) = target.deal_spell_dmg(cryp.spell_dmg().wrapping_div(2));
log.push(format!("{:?} | Drain damage {:?}", target.name, damage));
log.push(format!("{:?} | Drain Damage {:?}", target.name, damage));
let (healing, overhealing) = target.heal(damage);
log.push(format!("{:?} | Drain healing {:?} ({:?} OH)", cryp.name, healing, overhealing));
}
fn shield(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
let effect = CrypEffect { effect: Effect::Shield, duration: Skill::Shield.duration(), tick: None };
target.effects.push(effect);
log.push(format!("{:?} < {:?} for {:?}T", target.name, effect.effect, effect.duration));
}
fn silence(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
let effect = CrypEffect { effect: Effect::Silence, duration: Skill::Silence.duration(), tick: None };
target.effects.push(effect);
log.push(format!("{:?} < {:?} for {:?}T", target.name, effect.effect, effect.duration));
}
fn purge(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
for (i, ce) in target.effects.clone().iter_mut().enumerate() {
if ce.effect.source() == Source::Buff {
target.effects.remove(i);
log.push(format!("{:?} < {:?} purged", target.name, ce.effect));
}
}
}
fn purify(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
for (i, ce) in target.effects.clone().iter_mut().enumerate() {
if ce.effect.source() == Source::Debuff {
target.effects.remove(i);
log.push(format!("{:?} < {:?} purified", target.name, ce.effect));
}
}
}
fn banish(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
let effect = CrypEffect { effect: Effect::Banish, duration: Skill::Banish.duration(), tick: None };
target.effects.push(effect);
@ -856,6 +942,20 @@ mod tests {
assert_eq!(x.spell_dmg(), 100);
}
#[test]
fn purify_test() {
let mut x = Cryp::new()
.named(&"muji".to_string())
.level(8)
.create();
let mut log = vec![];
decay(&mut x.clone(), &mut x, &mut log);
assert!(x.effects.iter().any(|e| e.effect == Effect::Decay));
purify(&mut x.clone(), &mut x, &mut log);
assert!(!x.effects.iter().any(|e| e.effect == Effect::Decay));
}
}
// #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]