quick skill rework

This commit is contained in:
ntr
2018-12-17 17:05:19 +11:00
parent 6bacdb9181
commit 0d833f9b7d
5 changed files with 98 additions and 78 deletions
+28 -10
View File
@@ -9,7 +9,7 @@ use failure::err_msg;
use account::Account;
use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams};
use skill::{Skill, Cooldown, Effect, Cast, Immunity, Disable};
use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable};
use game::{Log};
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
@@ -298,23 +298,24 @@ impl Cryp {
// Stats
pub fn phys_dmg(&self) -> u64 {
let phys_dmg_mods = self.effects.iter()
.filter(|e| e.effect.category() == Category::PhysBuff)
.filter(|e| e.effect.modifications().contains(&Stat::PhysDmg))
.map(|cryp_effect| cryp_effect.effect)
.collect::<Vec<Effect>>();
// println!("{:?} phys_dmg mods : {:?}", self.name, phys_dmg_mods);
let modified_phys_dmg = phys_dmg_mods.iter().fold(self.phys_dmg.base, |acc, m| m.apply(acc));
// println!("{:?} phys_dmg : {:?}", self.name, modified_phys_dmg);
return modified_phys_dmg;
}
pub fn spell_dmg(&self) -> u64 {
let spell_dmg_mods = self.effects.iter()
.filter(|e| e.effect.category() == Category::SpellBuff)
.filter(|e| e.effect.modifications().contains(&Stat::SpellDmg))
.map(|cryp_effect| cryp_effect.effect)
.collect::<Vec<Effect>>();
// println!("{:?} spell_dmg mods : {:?}", self.name, spell_dmg_mods);
let modified_spell_dmg = spell_dmg_mods.iter().fold(self.spell_dmg.base, |acc, m| m.apply(acc));
// println!("{:?} spell_dmg : {:?}", self.name, modified_spell_dmg);
return modified_spell_dmg;
}
@@ -342,14 +343,31 @@ impl Cryp {
}
pub fn deal_phys_dmg(&mut self, amount: u64) -> (u64, u64) {
self.hp.reduce(amount);
// println!("{:?} dealt {:?} phys dmg", self.name, amount);
return (amount, 0);
let phys_dmg_mods = self.effects.iter()
.filter(|e| e.effect.category() == Category::PhysDebuff)
.filter(|e| e.effect.modifications().contains(&Stat::PhysDmg))
.map(|cryp_effect| cryp_effect.effect)
.collect::<Vec<Effect>>();
let modified_phys_dmg = phys_dmg_mods.iter().fold(amount, |acc, m| m.apply(acc));
self.hp.reduce(modified_phys_dmg);
return (modified_phys_dmg, 0);
}
pub fn deal_spell_dmg(&mut self, amount: u64) -> (u64, u64) {
self.hp.reduce(amount);
return (amount, 0);
let spell_dmg_mods = self.effects.iter()
.filter(|e| e.effect.category() == Category::SpellDebuff)
.filter(|e| e.effect.modifications().contains(&Stat::SpellDmg))
.map(|cryp_effect| cryp_effect.effect)
.collect::<Vec<Effect>>();
let modified_spell_dmg = spell_dmg_mods.iter().fold(amount, |acc, m| m.apply(acc));
self.hp.reduce(modified_spell_dmg);
return (modified_spell_dmg, 0);
}
}
+4 -2
View File
@@ -888,6 +888,7 @@ mod tests {
.learn(Skill::TestStun)
.learn(Skill::TestTouch)
.learn(Skill::TestBlock)
.learn(Skill::TestParry)
.learn(Skill::TestDrain)
.learn(Skill::Empower)
.learn(Skill::Block)
@@ -899,6 +900,7 @@ mod tests {
.learn(Skill::TestStun)
.learn(Skill::TestTouch)
.learn(Skill::TestBlock)
.learn(Skill::TestParry)
.learn(Skill::TestDrain)
.learn(Skill::Empower)
.learn(Skill::Block)
@@ -1117,7 +1119,7 @@ mod tests {
}
#[test]
fn block_test() {
fn parry_test() {
let mut game = create_test_game();
let x_team = game.teams[0].clone();
@@ -1126,7 +1128,7 @@ mod tests {
let x_cryp = x_team.cryps[0].clone();
let y_cryp = y_team.cryps[0].clone();
let _x_block_id = game.add_skill(x_team.id, x_cryp.id, None, Skill::TestBlock).unwrap();
let _x_block_id = game.add_skill(x_team.id, x_cryp.id, None, Skill::TestParry).unwrap();
let y_attack_id = game.add_skill(y_team.id, y_cryp.id, Some(x_team.id), Skill::TestStun).unwrap();
game.target_phase_start();
+36 -41
View File
@@ -106,6 +106,7 @@ pub type Cooldown = Option<u8>;
pub enum Effect {
// physical
Stun,
Parry,
Block,
Bleed,
Leech,
@@ -149,7 +150,7 @@ pub enum Effect {
impl Effect {
pub fn immune(&self, skill: Skill) -> bool {
match self {
Effect::Block => match skill.category() {
Effect::Parry => match skill.category() {
Category::Spell => false,
Category::Physical => true,
_ => false,
@@ -172,6 +173,8 @@ impl Effect {
pub fn disables_skill(&self, skill: Skill) -> bool {
match self {
Effect::Stun => true,
Effect::Hex => true,
Effect::Banish => true,
Effect::Silence => match skill.category() {
Category::Spell => true,
Category::Physical => false,
@@ -195,6 +198,7 @@ impl Effect {
match self {
Effect::Amplify => vec![Stat::SpellDmg],
Effect::Empower => vec![Stat::PhysDmg],
Effect::Block => vec![Stat::PhysDmg],
_ => vec![],
}
}
@@ -204,6 +208,7 @@ impl Effect {
// and OR with base stat
pub fn apply(&self, value: u64) -> u64 {
match self {
Effect::Block => value >> 1,
Effect::Amplify => value << 1,
Effect::Empower => value << 1,
_ => panic!("{:?} does not have a mod effect", self),
@@ -215,6 +220,7 @@ impl Effect {
// physical
Effect::Stun => Category::PhysDebuff,
Effect::Block => Category::PhysBuff,
Effect::Parry => Category::PhysBuff,
Effect::Bleed => Category::PhysDebuff,
Effect::Leech => Category::PhysDebuff,
Effect::Airborne => Category::PhysDebuff,
@@ -351,6 +357,7 @@ pub enum Skill {
TestTouch,
TestStun,
TestBlock,
TestParry,
TestDrain,
}
@@ -436,6 +443,7 @@ impl Skill {
Skill::TestStun => None,
Skill::TestBlock => None,
Skill::TestDrain => None,
Skill::TestParry => None,
}
}
@@ -519,6 +527,7 @@ impl Skill {
// -----------------
Skill::TestTouch => Category::Physical,
Skill::TestStun => Category::Physical,
Skill::TestParry => Category::Physical,
Skill::TestBlock => Category::Physical,
Skill::TestDrain => Category::Spell,
}
@@ -614,6 +623,7 @@ impl Skill {
Skill::TestTouch => 10,
Skill::TestStun => 5,
Skill::TestBlock => 10,
Skill::TestParry => 10,
Skill::TestDrain => 10,
}
}
@@ -638,8 +648,8 @@ impl Skill {
// Nature
// -----------------
Skill::Block => block(cryp, target, resolution),
Skill::Parry => parry(cryp, target, resolution),
Skill::Evade => evade(cryp, target, resolution),
Skill::Parry => panic!("nyi"), // avoid all dmg
Skill::Snare => snare(cryp, target, resolution), // TODO prevent physical moves
Skill::Paralyse => panic!("nyi"), // no physical moves
@@ -708,6 +718,7 @@ impl Skill {
Skill::TestTouch => Resolution { skill: Skill::TestTouch, results: vec![], disable: Disable::new() },
Skill::TestStun => stun(cryp, target, resolution),
Skill::TestBlock => block(cryp, target, resolution),
Skill::TestParry => parry(cryp, target, resolution),
Skill::TestDrain => drain(cryp, target, resolution),
}
}
@@ -728,6 +739,7 @@ impl Skill {
Skill::Silence => 3,
Skill::TestBlock => 1,
Skill::TestParry => 1,
Skill::TestStun => 2,
_ => {
println!("{:?} does not have a duration", self);
@@ -742,6 +754,7 @@ impl Skill {
Skill::Evasion => true,
Skill::Parry => true,
Skill::TestBlock => true,
Skill::TestParry => true,
_ => false,
}
}
@@ -838,6 +851,27 @@ fn block(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Res
return resolution;
}
fn parry(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Resolution {
let parry = CrypEffect { effect: Effect::Parry, duration: Skill::Parry.duration(), tick: None };
let immunity = target.immune(Skill::Parry);
let immune = immunity.immune;
let result = ResolutionResult::Effect {
effect: parry.effect,
duration: parry.duration,
immunity,
};
resolution.results.push(result);
if !immune {
target.effects.push(parry);
}
return resolution;
}
fn evade(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Resolution {
let evade = CrypEffect { effect: Effect::Evasion, duration: Skill::Evade.duration(), tick: None };
let immunity = target.immune(Skill::Evade);
@@ -1355,42 +1389,3 @@ mod tests {
assert!(!x.effects.iter().any(|e| e.effect == Effect::Decay));
}
}
// #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
// pub enum Skill {
// Stoney,
// Evasive,
// }
// impl Skill {
// pub fn apply(&self, roll: Roll) -> Roll {
// match self {
// Skill::Stoney => stoney(self, roll),
// Skill::Evasive => evasive(self, roll),
// }
// }
// }
// fn stoney(_s: &Skill, mut roll: Roll) -> Roll {
// let effect = 0b11110000;
// match roll.kind {
// StatKind::Def => {
// // println!("{:064b} | <- {:?}", effect, s);
// roll.result = roll.result | effect;
// roll
// },
// _ => roll,
// }
// }
// fn evasive(_s: &Skill, mut roll: Roll) -> Roll {
// match roll.kind {
// StatKind::Def => {
// if roll.result.is_power_of_two() {
// roll.result = u64::max_value()
// }
// roll
// },
// _ => roll,
// }
// }