mnml/server/src/skill.rs
2018-10-25 17:53:35 +11:00

97 lines
2.1 KiB
Rust
Executable File

use rand::prelude::*;
use uuid::Uuid;
use cryp::{Cryp};
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub struct Roll {
pub base: u64,
pub result: u64,
}
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub enum Skill {
Attack,
Block,
Heal,
Stun,
Dodge,
}
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub struct Cast {
pub id: Uuid,
pub skill: Skill,
pub cryp_id: Uuid,
pub target_cryp_id: Option<Uuid>,
pub target_team_id: Uuid,
}
impl Cast {
pub fn new(cryp_id: Uuid, target_team_id: Uuid, skill: Skill) -> Cast {
return Cast {
id: Uuid::new_v4(),
cryp_id,
target_cryp_id: None,
target_team_id,
skill,
};
}
pub fn resolve(&mut self, cryp: &mut Cryp, target: &mut Cryp) -> &mut Cast {
let roll = cryp.roll(self.skill);
match self.skill {
Skill::Stun => target.stun(roll),
_ => target.attack(roll),
};
println!("{:?} gettin clapped for {:?}", target.name, roll.result);
self
}
pub fn set_target(&mut self, cryp_id: Uuid) -> &mut Cast {
self.target_cryp_id = Some(cryp_id);
self
}
}
// #[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,
// }
// }