int multiplier, remove floats

This commit is contained in:
Mashy 2019-05-01 13:12:30 +10:00
parent 6a4a24d080
commit 3e271d4455

View File

@ -1,6 +1,7 @@
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use uuid::Uuid; use uuid::Uuid;
use spec::{IntPct};
use cryp::{Cryp, CrypEffect, EffectMeta, Stat}; use cryp::{Cryp, CrypEffect, EffectMeta, Stat};
use vbox::{Var}; use vbox::{Var};
@ -69,9 +70,11 @@ pub fn resolve(skill: Skill, source: &mut Cryp, target: &mut Cryp, mut resolutio
Skill::Snare => snare(source, target, resolutions, Skill::Snare), Skill::Snare => snare(source, target, resolutions, Skill::Snare),
Skill::Strangle => strangle(source, target, resolutions, Skill::Strangle), Skill::Strangle => strangle(source, target, resolutions, Skill::Strangle),
Skill::StrangleTick => strangle_tick(source, target, resolutions, Skill::StrangleTick), Skill::StrangleTick => strangle_tick(source, target, resolutions, Skill::StrangleTick),
Skill::Strike => strike(source, target, resolutions, Skill::Strike), Skill::Strike => strike(source, target, resolutions, Skill::Strike),
Skill::StrikeII => strike(source, target, resolutions, Skill::StrikeII), Skill::StrikeII => strike(source, target, resolutions, Skill::StrikeII),
Skill::StrikeIII => strike(source, target, resolutions, Skill::StrikeIII), Skill::StrikeIII => strike(source, target, resolutions, Skill::StrikeIII),
Skill::Stun => stun(source, target, resolutions, Skill::Stun), Skill::Stun => stun(source, target, resolutions, Skill::Stun),
Skill::Taunt => taunt(source, target, resolutions, Skill::Taunt), Skill::Taunt => taunt(source, target, resolutions, Skill::Taunt),
Skill::Throw => throw(source, target, resolutions, Skill::Throw), // no damage stun, adds vulnerable Skill::Throw => throw(source, target, resolutions, Skill::Throw), // no damage stun, adds vulnerable
@ -536,21 +539,21 @@ pub enum Skill {
} }
impl Skill { impl Skill {
pub fn multiplier(&self) -> f64 { pub fn multiplier(&self) -> u64 {
match self { match self {
Skill::Attack => 1.0, // 1.0 to pass tests Skill::Attack => 100, // 1.0 to pass tests
Skill::Strike => 1.1, Skill::Strike => 110,
Skill::StrikeII => 1.3, Skill::StrikeII => 130,
Skill::StrikeIII => 1.5, Skill::StrikeIII => 150,
Skill::StrangleTick => 0.3, Skill::StrangleTick => 30,
Skill::Riposte => 1.0, Skill::Riposte => 100,
Skill::Heal => 1.0, // 1.0 to pass tests Skill::Heal => 100, // 1.0 to pass tests
Skill::TriageTick => 0.65, Skill::TriageTick => 65,
Skill::Blast => 1.3, Skill::Blast => 130,
Skill::CorruptionTick => 0.8, Skill::CorruptionTick => 80,
Skill::DecayTick => 0.6, Skill::DecayTick => 60,
Skill::SiphonTick => 1.0, // 1.0 to pass tests Skill::SiphonTick => 100, // 1.0 to pass tests
_ => 1.0, _ => 100,
} }
} }
@ -825,7 +828,7 @@ fn touch(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
} }
fn attack(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn attack(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = (source.red_damage() as f64 * skill.multiplier()).floor() as u64; let amount = source.red_damage().pct(skill.multiplier());
println!("{:?}", amount); println!("{:?}", amount);
target.deal_red_damage(skill, amount) target.deal_red_damage(skill, amount)
.into_iter() .into_iter()
@ -835,8 +838,7 @@ fn attack(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
} }
fn strike(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn strike(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.red_damage().pct(skill.multiplier());
let amount = (source.red_damage() as f64 * skill.multiplier()).floor() as u64;
target.deal_red_damage(skill, amount) target.deal_red_damage(skill, amount)
.into_iter() .into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e))); .for_each(|e| results.push(Resolution::new(source, target).event(e)));
@ -845,7 +847,7 @@ fn strike(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
} }
fn injure(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn injure(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = (source.red_damage() as f64 * skill.multiplier()).floor() as u64; let amount = source.red_damage().pct(skill.multiplier());
target.deal_red_damage(skill, amount) target.deal_red_damage(skill, amount)
.into_iter() .into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e))); .for_each(|e| results.push(Resolution::new(source, target).event(e)));
@ -895,7 +897,7 @@ fn strangle(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skil
} }
fn strangle_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn strangle_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = (source.red_damage() as f64 * skill.multiplier()).floor() as u64; let amount = source.red_damage().pct(skill.multiplier());
target.deal_red_damage(skill, amount) target.deal_red_damage(skill, amount)
.into_iter() .into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e))); .for_each(|e| results.push(Resolution::new(source, target).event(e)));
@ -926,7 +928,7 @@ fn parry(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
} }
fn riposte(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn riposte(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = (source.red_damage() as f64 * Skill::Riposte.multiplier()).floor() as u64; let amount = source.red_damage().pct(skill.multiplier());
target.deal_red_damage(skill, amount) target.deal_red_damage(skill, amount)
.into_iter() .into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e))); .for_each(|e| results.push(Resolution::new(source, target).event(e)));
@ -947,7 +949,7 @@ fn empower(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill
} }
fn heal(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn heal(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = (source.green_damage() as f64 * skill.multiplier()).floor() as u64; let amount = source.green_damage().pct(skill.multiplier());
target.deal_green_damage(skill, amount) target.deal_green_damage(skill, amount)
.into_iter() .into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e))); .for_each(|e| results.push(Resolution::new(source, target).event(e)));
@ -963,7 +965,7 @@ fn triage(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
} }
fn triage_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn triage_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = (source.green_damage() as f64 * skill.multiplier()).floor() as u64; let amount = source.green_damage().pct(skill.multiplier());
target.deal_green_damage(Skill::TriageTick, amount) target.deal_green_damage(Skill::TriageTick, amount)
.into_iter() .into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e))); .for_each(|e| results.push(Resolution::new(source, target).event(e)));
@ -971,7 +973,7 @@ fn triage_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, s
} }
fn blast(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn blast(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = (source.blue_damage() as f64 * skill.multiplier()).floor() as u64; let amount = source.blue_damage().pct(skill.multiplier());
target.deal_blue_damage(skill, amount) target.deal_blue_damage(skill, amount)
.into_iter() .into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e))); .for_each(|e| results.push(Resolution::new(source, target).event(e)));
@ -1005,7 +1007,7 @@ fn decay(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
} }
fn decay_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn decay_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = (source.blue_damage() as f64 * skill.multiplier()).floor() as u64; let amount = source.blue_damage().pct(skill.multiplier());
target.deal_blue_damage(skill, amount) target.deal_blue_damage(skill, amount)
.into_iter() .into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e))); .for_each(|e| results.push(Resolution::new(source, target).event(e)));
@ -1029,7 +1031,7 @@ fn corruption(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, sk
} }
fn corruption_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn corruption_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = (source.blue_damage() as f64 * skill.multiplier()).floor() as u64; let amount = source.blue_damage().pct(skill.multiplier());
target.deal_blue_damage(skill, amount) target.deal_blue_damage(skill, amount)
.into_iter() .into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e))); .for_each(|e| results.push(Resolution::new(source, target).event(e)));
@ -1095,7 +1097,7 @@ fn siphon(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
} }
fn siphon_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions { fn siphon_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = (source.blue_damage() as f64 * skill.multiplier()) as u64; let amount = source.blue_damage().pct(skill.multiplier());
let siphon_events = target.deal_blue_damage(Skill::SiphonTick, amount); let siphon_events = target.deal_blue_damage(Skill::SiphonTick, amount);
for e in siphon_events { for e in siphon_events {
@ -1223,7 +1225,7 @@ mod tests {
let mut y = Cryp::new() let mut y = Cryp::new()
.named(&"camel".to_string()); .named(&"camel".to_string());
x.red_damage.force(10000000000000); // can't convert u64 max to f64 x.red_damage.force(10000000000000); // multiplication of int max will cause overflow
clutch(&mut y.clone(), &mut y, vec![], Skill::Clutch); clutch(&mut y.clone(), &mut y, vec![], Skill::Clutch);
assert!(y.affected(Effect::Clutch)); assert!(y.affected(Effect::Clutch));