we're back, no logs

This commit is contained in:
ntr 2018-11-27 11:55:39 +11:00
parent 2a002d08d4
commit 4f0d349cd6
2 changed files with 175 additions and 178 deletions

View File

@ -374,6 +374,7 @@ impl Game {
.flat_map(
|c| c.effects
.iter()
.cloned()
.filter_map(|e| e.tick))
.collect::<Vec<Cast>>();
@ -389,7 +390,7 @@ impl Game {
let mut source = self.cryp_by_id(skill.source_cryp_id).unwrap().clone();
let mut target = self.cryp_by_id(skill.target_cryp_id.unwrap()).unwrap().clone();
skill.set_resolution(&mut source, &mut target, &mut self.log);
skill.set_resolution(&mut source, &mut target);
self.resolved.push(skill.clone());
self.update_cryp(&mut source);
@ -768,7 +769,7 @@ mod tests {
use cryp::*;
fn create_test_game() -> Game {
let mut x = Cryp::new()
let x = Cryp::new()
.named(&"pronounced \"creeep\"".to_string())
.level(8)
.learn(Skill::TestStun)
@ -816,58 +817,58 @@ mod tests {
return game;
}
fn create_2v2_test_game() -> Game {
let mut i = Cryp::new()
.named(&"pretaliate".to_string())
.level(8)
.learn(Skill::Attack)
.create();
// fn create_2v2_test_game() -> Game {
// let mut i = Cryp::new()
// .named(&"pretaliate".to_string())
// .level(8)
// .learn(Skill::Attack)
// .create();
let mut j = Cryp::new()
.named(&"poy sian".to_string())
.level(8)
.learn(Skill::Attack)
.create();
// let mut j = Cryp::new()
// .named(&"poy sian".to_string())
// .level(8)
// .learn(Skill::Attack)
// .create();
let mut x = Cryp::new()
.named(&"pronounced \"creeep\"".to_string())
.level(8)
.learn(Skill::Attack)
.create();
// let mut x = Cryp::new()
// .named(&"pronounced \"creeep\"".to_string())
// .level(8)
// .learn(Skill::Attack)
// .create();
let mut y = Cryp::new()
.named(&"lemongrass tea".to_string())
.level(8)
.learn(Skill::Attack)
.create();
// let mut y = Cryp::new()
// .named(&"lemongrass tea".to_string())
// .level(8)
// .learn(Skill::Attack)
// .create();
let mut game = Game::new();
// let mut game = Game::new();
game
.set_team_num(2)
.set_team_size(2)
.set_pve(false);
// game
// .set_team_num(2)
// .set_team_size(2)
// .set_pve(false);
let x_team_id = Uuid::new_v4();
let mut x_team = Team::new(x_team_id);
x_team
.set_cryps(vec![x]);
// let x_team_id = Uuid::new_v4();
// let mut x_team = Team::new(x_team_id);
// x_team
// .set_cryps(vec![x]);
let y_team_id = Uuid::new_v4();
let mut y_team = Team::new(y_team_id);
y_team
.set_cryps(vec![y]);
// let y_team_id = Uuid::new_v4();
// let mut y_team = Team::new(y_team_id);
// y_team
// .set_cryps(vec![y]);
game
.team_add(x_team).unwrap()
.team_add(y_team).unwrap();
// game
// .team_add(x_team).unwrap()
// .team_add(y_team).unwrap();
assert!(game.can_start());
// assert!(game.can_start());
game.start();
// game.start();
return game;
}
// return game;
// }
#[test]
fn phase_test() {

View File

@ -40,8 +40,8 @@ impl Cast {
return cast;
}
pub fn set_resolution(&mut self, cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> &mut Cast {
self.resolution = self.skill.resolve(cryp, target, log);
pub fn set_resolution(&mut self, cryp: &mut Cryp, target: &mut Cryp) -> &mut Cast {
self.resolution = self.skill.resolve(cryp, target);
self
}
@ -77,7 +77,7 @@ pub struct Resolution {
pub type Cooldown = Option<u8>;
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub enum Effect {
// physical
Stun,
@ -563,24 +563,24 @@ impl Skill {
}
}
pub fn resolve(&self, cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
pub fn resolve(&self, cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let mut rng = thread_rng();
let base: u64 = rng.gen();
match self {
Skill::Attack => attack(cryp, target, log),
Skill::Attack => attack(cryp, target),
// -----------------
// Nature
// -----------------
Skill::Block => block(cryp, target, log),
Skill::Block => block(cryp, target),
Skill::Evade => panic!("nyi"), //
Skill::Parry => panic!("nyi"), // avoid all dmg
Skill::Snare => snare(cryp, target, log), // TODO prevent physical moves
Skill::Snare => snare(cryp, target), // TODO prevent physical moves
Skill::Paralyse => panic!("nyi"), // no physical moves
Skill::Strangle => panic!("nyi"), // no physical moves
Skill::Stun => stun(cryp, target, log),
Skill::Stun => stun(cryp, target),
Skill::Evasion => panic!("nyi"), // additional layer of dmg avoidance
// -----------------
@ -595,10 +595,10 @@ impl Skill {
// -----------------
// Preservation
// -----------------
Skill::Heal => heal(cryp, target, log),
Skill::Triage => triage(cryp, target, log), // hot
Skill::TriageTick => triage_tick(cryp, target, log), // hot
Skill::Throw => throw(cryp, target, log), // no dmg stun, adds vulnerable
Skill::Heal => heal(cryp, target),
Skill::Triage => triage(cryp, target), // hot
Skill::TriageTick => triage_tick(cryp, target), // hot
Skill::Throw => throw(cryp, target), // no dmg stun, adds vulnerable
Skill::Charm => panic!("nyi"), // target casts random spell on teammate
Skill::Calm => panic!("nyi"), // physical fear, taunt removal
Skill::Rez => panic!("nyi"),
@ -606,13 +606,13 @@ impl Skill {
// -----------------
// Destruction
// -----------------
Skill::Blast => blast(cryp, target, log),
Skill::Amplify => amplify(cryp, target, log), // increase magic dmg
Skill::Decay => decay(cryp, target, log), // dot
Skill::DecayTick => decay_tick(cryp, target, log), // hot
Skill::Drain => drain(cryp, target, log),
Skill::DrainTick => drain_tick(cryp, target, log), // hot
Skill::Curse => curse(cryp, target, log),
Skill::Blast => blast(cryp, target),
Skill::Amplify => amplify(cryp, target), // increase magic dmg
Skill::Decay => decay(cryp, target), // dot
Skill::DecayTick => decay_tick(cryp, target), // hot
Skill::Drain => drain(cryp, target),
Skill::DrainTick => drain_tick(cryp, target), // hot
Skill::Curse => curse(cryp, target),
Skill::Plague => panic!("nyi"), // dot that spreads every turn
Skill::Ruin => panic!("nyi"), // aoe version of blast
@ -620,19 +620,19 @@ impl Skill {
// Purity
// -----------------
// Skill::Precision => panic!("nyi"),
Skill::Empower => empower(cryp, target, log), // increased phys dmg
Skill::Empower => empower(cryp, target), // increased phys dmg
Skill::Slay => panic!("nyi"), // phys dmg mult by target magic dmg
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::Shield => shield(cryp, target), // target is immune to magic dmg and fx
Skill::Silence => silence(cryp, target), // target cannot cast spells
Skill::Inquiry => panic!("nyi"), //
Skill::Purify => purify(cryp, target, log), // dispel all debuffs
Skill::Purge => purge(cryp, target, log), // dispel all buffs
Skill::Purify => purify(cryp, target), // dispel all debuffs
Skill::Purge => purge(cryp, target), // dispel all buffs
// -----------------
// Chaos
// -----------------
Skill::Banish => banish(cryp, target, log), // TODO prevent all actions
Skill::Hex => hex(cryp, target, log), // todo prevent casting
Skill::Banish => banish(cryp, target), // TODO prevent all actions
Skill::Hex => hex(cryp, target), // todo prevent casting
Skill::Fear => panic!("nyi"), // cast random spell on self
Skill::Taunt => panic!("nyi"), // target forced to attack
Skill::Pause => panic!("nyi"), // speed slow
@ -641,9 +641,9 @@ impl Skill {
// Test
// -----------------
Skill::TestTouch => Resolution { skill: Skill::TestTouch, results: vec![] },
Skill::TestStun => stun(cryp, target, log),
Skill::TestBlock => block(cryp, target, log),
Skill::TestDrain => drain(cryp, target, log),
Skill::TestStun => stun(cryp, target),
Skill::TestBlock => block(cryp, target),
Skill::TestDrain => drain(cryp, target),
}
}
@ -681,9 +681,10 @@ impl Skill {
}
}
fn attack(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn attack(cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let amount = cryp.phys_dmg();
let immunity = target.immune(Skill::Attack);
let immune = immunity.immune;
let attack_result = ResolutionResult::Damage {
amount,
@ -691,20 +692,20 @@ fn attack(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Attack, results: vec![attack_result] };
let resolution = Resolution { skill: Skill::Attack, results: vec![attack_result] };
if !immunity.immune {
if !immune {
target.deal_phys_dmg(amount);
}
log.push(format!("{:?} -> {:?} | Attack for {:?}", cryp.name, target.name, cryp.phys_dmg));
return resolution;
}
fn stun(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn stun(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let stun = CrypEffect { effect: Effect::Stun, duration: Skill::Stun.duration(), tick: None };
let immunity = target.immune(Skill::Stun);
let immune = immunity.immune;
let attack_result = ResolutionResult::Effect {
effect: stun.effect,
@ -712,25 +713,25 @@ fn stun(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Stun, results: vec![attack_result] };
let resolution = Resolution { skill: Skill::Stun, results: vec![attack_result] };
if !immunity.immune {
if !immune {
target.effects.push(stun);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, stun.effect, stun.duration));
return resolution;
}
fn throw(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn throw(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let stun = CrypEffect { effect: Effect::Stun, duration: Skill::Stun.duration(), tick: None };
let vulnerable = CrypEffect { effect: Effect::Vulnerable, duration: Skill::Stun.duration(), tick: None };
let immunity = target.immune(Skill::Throw);
let immune = immunity.immune;
let stun_result = ResolutionResult::Effect {
effect: stun.effect,
duration: stun.duration,
immunity,
immunity: immunity.clone(),
};
let vulnerable_result = ResolutionResult::Effect {
@ -739,21 +740,21 @@ fn throw(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Throw, results: vec![stun_result, vulnerable_result] };
let resolution = Resolution { skill: Skill::Throw, results: vec![stun_result, vulnerable_result] };
if !immunity.immune {
if !immune {
target.effects.push(stun);
target.effects.push(vulnerable);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, stun.effect, stun.duration));
return resolution;
}
fn block(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn block(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let block = CrypEffect { effect: Effect::Block, duration: Skill::Block.duration(), tick: None };
let immunity = target.immune(Skill::Block);
let immune = immunity.immune;
let block_result = ResolutionResult::Effect {
effect: block.effect,
@ -761,19 +762,19 @@ fn block(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Block, results: vec![block_result] };
let resolution = Resolution { skill: Skill::Block, results: vec![block_result] };
if !immunity.immune {
if !immune {
target.effects.push(block);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", target.name, target.name, block.effect, block.duration));
return resolution;
}
fn snare(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn snare(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let snare = CrypEffect { effect: Effect::Snare, duration: Skill::Snare.duration(), tick: None };
let immunity = target.immune(Skill::Snare);
let immune = immunity.immune;
let snare_result = ResolutionResult::Effect {
effect: snare.effect,
@ -781,19 +782,19 @@ fn snare(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Snare, results: vec![snare_result] };
let resolution = Resolution { skill: Skill::Snare, results: vec![snare_result] };
if !immunity.immune {
if !immune {
target.effects.push(snare);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, snare.effect, snare.duration));
return resolution;
}
fn empower(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn empower(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let empower = CrypEffect { effect: Effect::Empower, duration: Skill::Empower.duration(), tick: None };
let immunity = target.immune(Skill::Empower);
let immune = immunity.immune;
let snare_result = ResolutionResult::Effect {
effect: empower.effect,
@ -801,20 +802,20 @@ fn empower(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Empower, results: vec![snare_result] };
let resolution = Resolution { skill: Skill::Empower, results: vec![snare_result] };
if !immunity.immune {
if !immune {
target.effects.push(empower);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, empower.effect, empower.duration));
return resolution;
}
// TODO put overhealing back
fn heal(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn heal(cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let amount = cryp.phys_dmg();
let immunity = target.immune(Skill::Heal);
let immune = immunity.immune;
let heal_result = ResolutionResult::Damage {
amount,
@ -822,25 +823,25 @@ fn heal(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Heal, results: vec![heal_result] };
let resolution = Resolution { skill: Skill::Heal, results: vec![heal_result] };
if !immunity.immune {
let (healing, overhealing) = target.heal(amount);
if !immune {
let (_healing, _overhealing) = target.heal(amount);
}
log.push(format!("{:?} -> {:?} | Attack for {:?}", cryp.name, target.name, amount));
return resolution;
}
fn triage(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn triage(cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let triage = CrypEffect {
effect: Effect::Triage,
duration: Skill::Triage.duration(),
tick: Some(Cast::new_tick(cryp, target, Skill::TriageTick)),
};
let immunity = target.immune(Skill::Triage);
let immune = immunity.immune;
let snare_result = ResolutionResult::Effect {
effect: triage.effect,
@ -848,19 +849,19 @@ fn triage(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Triage, results: vec![snare_result] };
let resolution = Resolution { skill: Skill::Triage, results: vec![snare_result] };
if !immunity.immune {
if !immune {
target.effects.push(triage);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, triage.effect, triage.duration));
return resolution;
}
fn triage_tick(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn triage_tick(cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let amount = cryp.spell_dmg().wrapping_div(2);
let immunity = target.immune(Skill::TriageTick);
let immune = immunity.immune;
let heal_result = ResolutionResult::Damage {
amount,
@ -868,20 +869,20 @@ fn triage_tick(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution
immunity,
};
let mut resolution = Resolution { skill: Skill::TriageTick, results: vec![heal_result] };
let resolution = Resolution { skill: Skill::TriageTick, results: vec![heal_result] };
if !immunity.immune {
let (healing, overhealing) = target.heal(amount);
if !immune {
let (_healing, _overhealing) = target.heal(amount);
}
log.push(format!("{:?} -> {:?} | Attack for {:?}", cryp.name, target.name, amount));
return resolution;
}
fn blast(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn blast(cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let amount = cryp.spell_dmg();
let immunity = target.immune(Skill::Blast);
let immune = immunity.immune;
let blast_result = ResolutionResult::Damage {
amount,
@ -889,18 +890,19 @@ fn blast(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Blast, results: vec![blast_result] };
let resolution = Resolution { skill: Skill::Blast, results: vec![blast_result] };
if !immunity.immune {
if !immune {
target.deal_spell_dmg(amount);
}
return resolution;
}
fn amplify(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn amplify(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let amplify = CrypEffect { effect: Effect::Amplify, duration: Skill::Amplify.duration(), tick: None };
let immunity = target.immune(Skill::Amplify);
let immune = immunity.immune;
let amplify_result = ResolutionResult::Effect {
effect: amplify.effect,
@ -908,23 +910,23 @@ fn amplify(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Amplify, results: vec![amplify_result] };
let resolution = Resolution { skill: Skill::Amplify, results: vec![amplify_result] };
if !immunity.immune {
if !immune {
target.effects.push(amplify);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, amplify.effect, amplify.duration));
return resolution;;
}
fn decay(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn decay(cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let decay = CrypEffect {
effect: Effect::Decay,
duration: Skill::Decay.duration(),
tick: Some(Cast::new_tick(cryp, target, Skill::DecayTick)),
};
let immunity = target.immune(Skill::Empower);
let immune = immunity.immune;
let decay_result = ResolutionResult::Effect {
effect: decay.effect,
@ -932,19 +934,19 @@ fn decay(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Decay, results: vec![decay_result] };
let resolution = Resolution { skill: Skill::Decay, results: vec![decay_result] };
if !immunity.immune {
if !immune {
target.effects.push(decay);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, decay.effect, decay.duration));
return resolution;
}
fn decay_tick(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn decay_tick(cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let amount = cryp.spell_dmg();
let immunity = target.immune(Skill::DecayTick);
let immune = immunity.immune;
let decay_tick_result = ResolutionResult::Damage {
amount,
@ -952,18 +954,19 @@ fn decay_tick(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::DecayTick, results: vec![decay_tick_result] };
let resolution = Resolution { skill: Skill::DecayTick, results: vec![decay_tick_result] };
if !immunity.immune {
if !immune {
target.deal_spell_dmg(amount);
}
return resolution;
}
fn hex(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn hex(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let hex = CrypEffect { effect: Effect::Hex, duration: Skill::Hex.duration(), tick: None };
let immunity = target.immune(Skill::Hex);
let immune = immunity.immune;
let hex_result = ResolutionResult::Effect {
effect: hex.effect,
@ -971,19 +974,19 @@ fn hex(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Hex, results: vec![hex_result] };
let resolution = Resolution { skill: Skill::Hex, results: vec![hex_result] };
if !immunity.immune {
if !immune {
target.effects.push(hex);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, hex.effect, hex.duration));
return resolution;;
}
fn curse(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn curse(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let curse = CrypEffect { effect: Effect::Curse, duration: Skill::Curse.duration(), tick: None };
let immunity = target.immune(Skill::Curse);
let immune = immunity.immune;
let curse_result = ResolutionResult::Effect {
effect: curse.effect,
@ -991,23 +994,23 @@ fn curse(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Curse, results: vec![curse_result] };
let resolution = Resolution { skill: Skill::Curse, results: vec![curse_result] };
if !immunity.immune {
if !immune {
target.effects.push(curse);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, curse.effect, curse.duration));
return resolution;;
}
fn drain(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn drain(cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let drain = CrypEffect {
effect: Effect::Drain,
duration: Skill::Drain.duration(),
tick: Some(Cast::new_tick(cryp, target, Skill::DrainTick)),
};
let immunity = target.immune(Skill::Drain);
let immune = immunity.immune;
let drain_result = ResolutionResult::Effect {
effect: drain.effect,
@ -1015,25 +1018,25 @@ fn drain(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Drain, results: vec![drain_result] };
let resolution = Resolution { skill: Skill::Drain, results: vec![drain_result] };
if !immunity.immune {
if !immune {
target.effects.push(drain);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, drain.effect, drain.duration));
return resolution;;
}
// TODO is fukt
fn drain_tick(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn drain_tick(cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let amount = cryp.spell_dmg().wrapping_div(2);
let immunity = target.immune(Skill::DrainTick);
let immune = immunity.immune;
let drain_tick_dmg_result = ResolutionResult::Damage {
amount,
category: Category::SpellDmg,
immunity,
immunity: immunity.clone(),
};
let drain_tick_heal_result = ResolutionResult::Damage {
@ -1043,20 +1046,21 @@ fn drain_tick(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
};
let mut resolution = Resolution { skill: Skill::DrainTick, results: vec![drain_tick_dmg_result, drain_tick_heal_result] };
let resolution = Resolution { skill: Skill::DrainTick, results: vec![drain_tick_dmg_result, drain_tick_heal_result] };
if !immunity.immune {
if !immune {
// need to saturate amount and check caster immunity to healing
target.deal_spell_dmg(amount);
let (healing, overhealing) = cryp.heal(amount);
let (_healing, _overhealing) = cryp.heal(amount);
}
return resolution;
}
fn shield(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn shield(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let shield = CrypEffect { effect: Effect::Shield, duration: Skill::Shield.duration(), tick: None };
let immunity = target.immune(Skill::Shield);
let immune = immunity.immune;
let shield_result = ResolutionResult::Effect {
effect: shield.effect,
@ -1064,19 +1068,19 @@ fn shield(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Shield, results: vec![shield_result] };
let resolution = Resolution { skill: Skill::Shield, results: vec![shield_result] };
if !immunity.immune {
if !immune {
target.effects.push(shield);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, shield.effect, shield.duration));
return resolution;
}
fn silence(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn silence(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let silence = CrypEffect { effect: Effect::Silence, duration: Skill::Silence.duration(), tick: None };
let immunity = target.immune(Skill::Silence);
let immune = immunity.immune;
let silence_result = ResolutionResult::Effect {
effect: silence.effect,
@ -1084,27 +1088,26 @@ fn silence(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Silence, results: vec![silence_result] };
let resolution = Resolution { skill: Skill::Silence, results: vec![silence_result] };
if !immunity.immune {
if !immune {
target.effects.push(silence);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, silence.effect, silence.duration));
return resolution;
}
fn purge(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn purge(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let immunity = target.immune(Skill::Purge);
let immune = immunity.immune;
let mut resolution = Resolution { skill: Skill::Silence, results: vec![] };
if !immunity.immune {
if !immune {
for (i, ce) in target.effects.clone().iter_mut().enumerate() {
if ce.effect.category() == Category::SpellBuff {
target.effects.remove(i);
resolution.results.push(ResolutionResult::Removal { effect: ce.effect, immunity });
log.push(format!("{:?} < {:?} purged", target.name, ce.effect));
resolution.results.push(ResolutionResult::Removal { effect: ce.effect, immunity: immunity.clone() });
}
}
}
@ -1112,17 +1115,17 @@ fn purge(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
return resolution;
}
fn purify(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn purify(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let immunity = target.immune(Skill::Purify);
let immune = immunity.immune;
let mut resolution = Resolution { skill: Skill::Silence, results: vec![] };
if !immunity.immune {
if !immune {
for (i, ce) in target.effects.clone().iter_mut().enumerate() {
if ce.effect.category() == Category::SpellDebuff {
target.effects.remove(i);
resolution.results.push(ResolutionResult::Removal { effect: ce.effect, immunity });
log.push(format!("{:?} < {:?} purified", target.name, ce.effect));
resolution.results.push(ResolutionResult::Removal { effect: ce.effect, immunity: immunity.clone() });
}
}
}
@ -1130,9 +1133,10 @@ fn purify(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
return resolution;
}
fn banish(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
fn banish(_cryp: &mut Cryp, target: &mut Cryp) -> Resolution {
let banish = CrypEffect { effect: Effect::Banish, duration: Skill::Banish.duration(), tick: None };
let immunity = target.immune(Skill::Banish);
let immune = immunity.immune;
let banish_result = ResolutionResult::Effect {
effect: banish.effect,
@ -1140,13 +1144,12 @@ fn banish(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> Resolution {
immunity,
};
let mut resolution = Resolution { skill: Skill::Banish, results: vec![banish_result] };
let resolution = Resolution { skill: Skill::Banish, results: vec![banish_result] };
if !immunity.immune {
if !immune {
target.effects.push(banish);
}
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, banish.effect, banish.duration));
return resolution;
}
@ -1171,8 +1174,7 @@ mod tests {
x.deal_phys_dmg(5);
let mut log = vec![];
heal(&mut y, &mut x, &mut log);
heal(&mut y, &mut x);
}
#[test]
@ -1188,12 +1190,12 @@ mod tests {
.create();
let mut log = vec![];
decay(&mut x, &mut y, &mut log);
decay(&mut x, &mut y);
assert!(y.effects.iter().any(|e| e.effect == Effect::Decay));
y.reduce_effect_durations(&mut log);
let decay = y.effects.iter().find(|e| e.effect == Effect::Decay);
let _decay = y.effects.iter().find(|e| e.effect == Effect::Decay);
// assert!(y.hp() == y.stamina().saturating_sub(decay.unwrap().tick.unwrap().amount));
}
@ -1209,18 +1211,16 @@ mod tests {
.level(8)
.create();
let mut log = vec![];
// ensure it doesn't have 0 sd
x.spell_dmg.set(50);
y.deal_phys_dmg(5);
let prev_hp = y.hp();
triage(&mut x, &mut y, &mut log);
triage(&mut x, &mut y);
assert!(y.effects.iter().any(|e| e.effect == Effect::Triage));
triage_tick(&mut x, &mut y, &mut log);
triage_tick(&mut x, &mut y);
assert!(y.hp() > prev_hp);
}
@ -1231,9 +1231,7 @@ mod tests {
.level(8)
.create();
let mut log = vec![];
silence(&mut x.clone(), &mut x, &mut log);
silence(&mut x.clone(), &mut x);
assert!(x.effects.iter().any(|e| e.effect == Effect::Silence));
assert!(!Skill::Decay.castable(&x));
}
@ -1247,8 +1245,7 @@ mod tests {
x.spell_dmg.set(50);
let mut log = vec![];
amplify(&mut x.clone(), &mut x, &mut log);
amplify(&mut x.clone(), &mut x);
assert!(x.effects.iter().any(|e| e.effect == Effect::Amplify));
assert_eq!(x.spell_dmg(), 100);
}
@ -1260,11 +1257,10 @@ mod tests {
.level(8)
.create();
let mut log = vec![];
decay(&mut x.clone(), &mut x, &mut log);
decay(&mut x.clone(), &mut x);
assert!(x.effects.iter().any(|e| e.effect == Effect::Decay));
purify(&mut x.clone(), &mut x, &mut log);
purify(&mut x.clone(), &mut x);
assert!(!x.effects.iter().any(|e| e.effect == Effect::Decay));
}
}