This commit is contained in:
ntr 2018-11-08 22:56:57 +11:00
parent 58f186d2fd
commit 6c7b6b741f
3 changed files with 94 additions and 46 deletions

View File

@ -9,7 +9,6 @@ use failure::err_msg;
use account::Account; use account::Account;
use rpc::{CrypSpawnParams}; use rpc::{CrypSpawnParams};
use game::{Log};
use skill::{Skill, Cooldown, Effect}; use skill::{Skill, Cooldown, Effect};
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
@ -53,15 +52,21 @@ pub struct CrypStat {
} }
impl CrypStat { impl CrypStat {
fn set(&mut self, v: u64) -> &CrypStat { pub fn set(&mut self, v: u64) -> &CrypStat {
self.value = v; self.value = v;
self self
} }
pub fn reduce(&mut self, dmg: u64) -> &mut CrypStat { pub fn reduce(&mut self, amt: u64) -> &mut CrypStat {
self.value = self.value.saturating_sub(dmg); self.value = self.value.saturating_sub(amt);
self self
} }
pub fn increase(&mut self, amt: u64) -> &mut CrypStat {
self.value = self.value.saturating_add(amt);
self
}
} }
#[derive(Debug,Clone,Serialize,Deserialize)] #[derive(Debug,Clone,Serialize,Deserialize)]

View File

@ -229,9 +229,10 @@ impl Game {
} }
let skill = Cast::new(source_cryp_id, team_id, target_team_id, skill); let skill = Cast::new(source_cryp_id, team_id, target_team_id, skill);
let skill_id = skill.id;
self.stack.push(skill); self.stack.push(skill);
return Ok(skill.id); return Ok(skill_id);
} }
fn skill_phase_finished(&self) -> bool { fn skill_phase_finished(&self) -> bool {
@ -355,15 +356,16 @@ impl Game {
let mut source = self.cryp_by_id(skill.source_cryp_id).unwrap().clone(); 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(); let mut target = self.cryp_by_id(skill.target_cryp_id.unwrap()).unwrap().clone();
self.log.push(format!("{:?} uses {:?} on {:?}", source.name, skill.skill, target.name)); // self.log.push(format!("{:?} uses {:?} on {:?}", source.name, skill.skill, target.name));
let resolution = skill.set_resolution(&mut source, &mut target, &mut self.log); skill.set_resolution(&mut source, &mut target);
self.resolved.push(resolution.clone()); self.log.push(skill.resolution.text.clone());
self.resolved.push(skill.clone());
self.update_cryp(&mut source); self.update_cryp(&mut source);
self.update_cryp(&mut target); self.update_cryp(&mut target);
return resolution.clone(); return skill.clone();
}).collect::<Vec<Cast>>(); }).collect::<Vec<Cast>>();
// now Resolve has all been assigned // now Resolve has all been assigned
@ -836,9 +838,6 @@ mod tests {
let _y_block_id = game.add_skill(y_team.id, y_cryp.id, None, Skill::Block).unwrap(); let _y_block_id = game.add_skill(y_team.id, y_cryp.id, None, Skill::Block).unwrap();
game.target_phase_start(); game.target_phase_start();
// game.add_target(x_team.id, x_cryp.id, y_block_id).unwrap();
// game.add_target(y_team.id, y_cryp.id, x_block_id).unwrap();
// game.resolve_phase_start();
assert!(game.team_by_id(y_team.id).cryps[0].skill_on_cd(Skill::Block).is_some()); assert!(game.team_by_id(y_team.id).cryps[0].skill_on_cd(Skill::Block).is_some());
assert!(game.team_by_id(x_team.id).cryps[0].skill_on_cd(Skill::Block).is_some()); assert!(game.team_by_id(x_team.id).cryps[0].skill_on_cd(Skill::Block).is_some());
@ -876,5 +875,4 @@ mod tests {
assert!(game.team_by_id(x_team.id).cryps[0].is_stunned() == false); assert!(game.team_by_id(x_team.id).cryps[0].is_stunned() == false);
println!("{:#?}", game.log); println!("{:#?}", game.log);
} }
} }

View File

@ -1,10 +1,10 @@
use rand::prelude::*; use rand::{thread_rng, Rng};
use uuid::Uuid; use uuid::Uuid;
use game::{Log}; // use game::{Log};
use cryp::{Cryp, CrypEffect}; use cryp::{Cryp, CrypEffect};
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub struct Cast { pub struct Cast {
pub id: Uuid, pub id: Uuid,
pub skill: Skill, pub skill: Skill,
@ -12,7 +12,7 @@ pub struct Cast {
pub source_cryp_id: Uuid, pub source_cryp_id: Uuid,
pub target_cryp_id: Option<Uuid>, pub target_cryp_id: Option<Uuid>,
pub target_team_id: Uuid, pub target_team_id: Uuid,
pub resolution: Option<Resolution>, pub resolution: Resolution,
} }
impl Cast { impl Cast {
@ -30,12 +30,12 @@ impl Cast {
target_cryp_id, target_cryp_id,
target_team_id, target_team_id,
skill, skill,
resolution: None, resolution: Resolution { base: 0, result: None, text: String::new() },
}; };
} }
pub fn set_resolution(&mut self, cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) -> &mut Cast { pub fn set_resolution(&mut self, cryp: &mut Cryp, target: &mut Cryp) -> &mut Cast {
self.resolution = Some(self.skill.resolve(cryp, target, log)); self.resolution = self.skill.resolve(cryp, target);
self self
} }
@ -44,15 +44,16 @@ impl Cast {
self self
} }
pub fn used_cooldown(self) -> bool { pub fn used_cooldown(&self) -> bool {
return self.skill.cd().is_some(); return self.skill.cd().is_some();
} }
} }
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub struct Resolution { pub struct Resolution {
pub base: u64, pub base: u64,
pub result: Option<u64>, pub result: Option<u64>,
pub text: String,
} }
pub type Cooldown = Option<u8>; pub type Cooldown = Option<u8>;
@ -118,11 +119,11 @@ pub enum Skill {
Paralyse, Paralyse,
// Strangle Strangle, // physical dot and disable
Stun, Stun,
Dodge, Evade, // actively evade
Evasion, // additional layer of dmg avoidance Evasion, // adds evasion to cryp
// ----------------- // -----------------
@ -194,11 +195,12 @@ impl Skill {
Skill::Snare => Some(2), Skill::Snare => Some(2),
Skill::Paralyse => Some(3), Skill::Paralyse => Some(3),
Skill::Strangle => Some(3),
// Strangle // Strangle
Skill::Stun => Some(1), Skill::Stun => Some(1),
Skill::Dodge => Some(2), Skill::Evade => Some(2),
Skill::Evasion => Some(3), // additional layer of dmg avoidance Skill::Evasion => Some(3), // additional layer of dmg avoidance
// ----------------- // -----------------
@ -268,11 +270,12 @@ impl Skill {
// Nature // Nature
// ----------------- // -----------------
Skill::Block => 10, // reduce dmg Skill::Block => 10, // reduce dmg
Skill::Dodge => 10, Skill::Evade => 10,
Skill::Parry => 10, // avoid all dmg Skill::Parry => 10, // avoid all dmg
Skill::Snare => 10, Skill::Snare => 10,
Skill::Paralyse => 5, Skill::Paralyse => 5,
Skill::Strangle => 5,
// Strangle // Strangle
@ -338,11 +341,11 @@ 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 mut rng = thread_rng();
let base: u64 = rng.gen(); let base: u64 = rng.gen();
let mut res = Resolution { base, result: None }; let mut res = Resolution { base, result: None, text: String::new() };
// println!("{:?}'s stats", self.name); // println!("{:?}'s stats", self.name);
// println!("{:064b} <- finalised", roll.result); // println!("{:064b} <- finalised", roll.result);
@ -355,21 +358,19 @@ impl Skill {
// return Some(roll); // return Some(roll);
match self { match self {
Skill::Attack => { Skill::Attack => attack(cryp, target, &mut res),
target.hp.reduce(cryp.phys_dmg.value);
},
// ----------------- // -----------------
// Nature // Nature
// ----------------- // -----------------
Skill::Block => block(cryp, target, log), Skill::Block => block(cryp, target, &mut res),
Skill::Dodge => panic!("nyi"), Skill::Evade => panic!("nyi"), //
Skill::Parry => panic!("nyi"), // avoid all dmg Skill::Parry => panic!("nyi"), // avoid all dmg
Skill::Snare => panic!("nyi"), Skill::Snare => panic!("nyi"),
Skill::Paralyse => panic!("nyi"), Skill::Paralyse => panic!("nyi"), // no physical moves
// Strangle Skill::Strangle => panic!("nyi"), // no physical moves
Skill::Stun => stun(cryp, target, log), Skill::Stun => stun(cryp, target, &mut res),
Skill::Evasion => panic!("nyi"), // additional layer of dmg avoidance Skill::Evasion => panic!("nyi"), // additional layer of dmg avoidance
// ----------------- // -----------------
@ -384,7 +385,7 @@ impl Skill {
// ----------------- // -----------------
// Preservation // Preservation
// ----------------- // -----------------
Skill::Heal => panic!("nyi"), Skill::Heal => heal(cryp, target, &mut res),
Skill::Triage => panic!("nyi"), // hot Skill::Triage => panic!("nyi"), // hot
Skill::Throw => panic!("nyi"), // no dmg stun, adds vulnerable Skill::Throw => panic!("nyi"), // no dmg stun, adds vulnerable
Skill::Charm => panic!("nyi"), Skill::Charm => panic!("nyi"),
@ -426,8 +427,8 @@ impl Skill {
// Test // Test
// ----------------- // -----------------
Skill::TestTouch => (), Skill::TestTouch => (),
Skill::TestStun => stun(cryp, target, log), Skill::TestStun => stun(cryp, target, &mut res),
Skill::TestBlock => block(cryp, target, log), Skill::TestBlock => block(cryp, target, &mut res),
}; };
return res; return res;
@ -435,7 +436,7 @@ impl Skill {
pub fn duration(&self) -> u8 { pub fn duration(&self) -> u8 {
match self { match self {
Skill::Dodge => 1, Skill::Evade => 1,
Skill::Stun => 2, Skill::Stun => 2,
Skill::Block => 1, Skill::Block => 1,
@ -461,20 +462,64 @@ impl Skill {
} }
} }
fn stun(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) { fn attack(cryp: &mut Cryp, target: &mut Cryp, res: &mut Resolution) {
res.text = format!("{:?} -> {:?} | Attack for {:?}", cryp.name, target.name, cryp.phys_dmg);
target.hp.reduce(cryp.phys_dmg.value);
}
fn stun(cryp: &mut Cryp, target: &mut Cryp, res: &mut Resolution) {
if !target.effects.iter().any(|e| e.effect.prevents(Skill::Stun)) { if !target.effects.iter().any(|e| e.effect.prevents(Skill::Stun)) {
let stun = CrypEffect { effect: Effect::Stun, duration: Skill::Stun.duration() }; let stun = CrypEffect { effect: Effect::Stun, duration: Skill::Stun.duration() };
target.effects.push(stun); target.effects.push(stun);
log.push(format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, stun.effect, stun.duration)); res.text = format!("{:?} -> {:?} | {:?} for {:?}T", cryp.name, target.name, stun.effect, stun.duration);
} else { } else {
log.push(format!("{:?} blocks.", target.name)); res.text = format!("{:?} blocks.", target.name);
} }
} }
fn block(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) { fn block(_cryp: &mut Cryp, target: &mut Cryp, res: &mut Resolution) {
let effect = CrypEffect { effect: Effect::Block, duration: Skill::Block.duration() }; let effect = CrypEffect { effect: Effect::Block, duration: Skill::Block.duration() };
target.effects.push(effect); target.effects.push(effect);
log.push(format!("{:?} is {:?} for {:?}T", target.name, effect.effect, effect.duration)); res.text = format!("{:?} is {:?} for {:?}T", target.name, effect.effect, effect.duration);
}
fn heal(cryp: &mut Cryp, target: &mut Cryp, res: &mut Resolution) {
let new_hp = *[
target.hp.value.saturating_add(cryp.spell_dmg.value),
target.stamina.value
].iter().min().unwrap();
let healing = new_hp.saturating_sub(target.hp.value);
let overhealing = target.hp.value.saturating_add(cryp.phys_dmg.value).saturating_sub(target.stamina.value);
target.hp.value = new_hp;
res.text = format!("{:?} -> {:?} | Heal for {:?} ({:?}OH)", cryp.name, target.name, healing, overhealing);
}
#[cfg(test)]
mod tests {
use skill::*;
#[test]
fn heal_test() {
let mut x = Cryp::new()
.named(&"muji".to_string())
.level(8)
.learn(Skill::Heal)
.create();
let mut y = Cryp::new()
.named(&"camel".to_string())
.level(8)
.learn(Skill::Heal)
.create();
x.hp.reduce(5);
let mut resolution = Resolution { base: 0, result: None, text: String::new() };
heal(&mut y, &mut x, &mut resolution);
println!("{:?}", resolution);
}
} }
// #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] // #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]