speed initial cooldown reduction wip
This commit is contained in:
parent
549b9cdf65
commit
41921ad926
@ -56,6 +56,10 @@ impl ConstructSkill {
|
||||
disabled: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_cooldown(&mut self, cd: Cooldown) -> () {
|
||||
self.cd = cd;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||
@ -432,15 +436,37 @@ impl Construct {
|
||||
self.skills.iter().find(|s| s.skill == skill && s.cd.is_some())
|
||||
}
|
||||
|
||||
pub fn skill_set_cd(&mut self, skill: Skill) -> &mut Construct {
|
||||
pub fn set_construct_delays(&mut self) -> () {
|
||||
// for every multiple of speed threshold delays are reduced by 1 at start of game
|
||||
let speed_threshold = 250;
|
||||
let delay_reduction = self.speed.value.wrapping_div(speed_threshold);
|
||||
|
||||
self.skills
|
||||
.iter_mut()
|
||||
.for_each(|s| match s.skill.base_cd() {
|
||||
Some(cd) => {
|
||||
let reduced_delay = cd.saturating_sub(delay_reduction);
|
||||
match reduced_delay {
|
||||
0 => s.set_cooldown(None),
|
||||
_ => s.set_cooldown(Some(reduced_delay))
|
||||
}
|
||||
},
|
||||
None => s.set_cooldown(None)
|
||||
});
|
||||
}
|
||||
|
||||
pub fn skill_set_cd(&mut self, skill: Skill, cd: Cooldown) -> &mut Construct {
|
||||
// println!("{:?} {:?} skill cooldown set", self.name, skill);
|
||||
|
||||
// tests force resolve some skills
|
||||
// which cause the game to attempt to put them on cd
|
||||
// even though the construct doesn't know the skill
|
||||
if let Some(i) = self.skills.iter().position(|s| s.skill == skill) {
|
||||
self.skills.remove(i);
|
||||
self.skills.insert(i, ConstructSkill::new(skill));
|
||||
// if let Some(i) = self.skills.iter().position(|s| s.skill == skill) {
|
||||
// self.skills.remove(i);
|
||||
// self.skills.insert(i, ConstructSkill::new(skill));
|
||||
//}
|
||||
if let Some(sk) = self.skills.iter_mut().find(|s| s.skill == skill) {
|
||||
sk.set_cooldown(cd);
|
||||
}
|
||||
|
||||
self
|
||||
|
||||
@ -11,6 +11,7 @@ use failure::err_msg;
|
||||
|
||||
use construct::{Construct, ConstructEffect, Stat, EffectMeta};
|
||||
use skill::{Skill, Cast};
|
||||
use spec::{Spec};
|
||||
use effect::{Effect};
|
||||
|
||||
use player::{Player};
|
||||
@ -140,12 +141,19 @@ impl Game {
|
||||
&& self.players.iter().all(|t| t.constructs.len() == self.player_constructs)
|
||||
}
|
||||
|
||||
pub fn start(self) -> Game {
|
||||
pub fn start(mut self) -> Game {
|
||||
// both forfeit ddue to no skills
|
||||
if self.finished() {
|
||||
return self.finish();
|
||||
}
|
||||
|
||||
self.players
|
||||
.iter_mut()
|
||||
.for_each(|p| p.constructs
|
||||
.iter_mut()
|
||||
.for_each(|c| c.set_construct_delays())
|
||||
);
|
||||
|
||||
self.skill_phase_start(0)
|
||||
}
|
||||
|
||||
@ -593,7 +601,7 @@ impl Game {
|
||||
Event::Damage { construct, colour: _, amount: _, mitigation: _, display: _ } =>
|
||||
self.construct_by_id(construct).unwrap().damage_trigger_casts(&cast, &event),
|
||||
Event::Cast { construct, skill, player: _, target: _, direction: _ } => {
|
||||
self.construct_by_id(construct).unwrap().skill_set_cd(skill);
|
||||
self.construct_by_id(construct).unwrap().skill_set_cd(skill, skill.base_cd());
|
||||
vec![]
|
||||
}
|
||||
Event::Ko { construct } =>
|
||||
@ -1163,6 +1171,44 @@ mod tests {
|
||||
return;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delay_test() {
|
||||
let mut x = Construct::new()
|
||||
.named(&"pronounced \"creeep\"".to_string())
|
||||
.learn(Skill::Ruin);
|
||||
|
||||
let mut y = Construct::new()
|
||||
.named(&"lemongrass tea".to_string())
|
||||
.learn(Skill::Ruin);
|
||||
|
||||
// Ruin has 2 turn cd
|
||||
// 250 speed = 1 cd delay reduction
|
||||
x.speed.force(499);
|
||||
y.speed.force(700);
|
||||
|
||||
let mut game = Game::new();
|
||||
game.set_player_num(2).set_player_constructs(1);
|
||||
|
||||
let x_player_id = Uuid::new_v4();
|
||||
x.account = x_player_id;
|
||||
let x_player = Player::new(x_player_id, None, &"ntr".to_string(), vec![x]);
|
||||
|
||||
let y_player_id = Uuid::new_v4();
|
||||
y.account = y_player_id;
|
||||
let y_player = Player::new(y_player_id, None, &"mash".to_string(), vec![y]);
|
||||
|
||||
game
|
||||
.player_add(x_player).unwrap()
|
||||
.player_add(y_player).unwrap();
|
||||
|
||||
game = game.start();
|
||||
|
||||
assert!(game.players[0].constructs[0].skill_on_cd(Skill::Ruin).is_some());
|
||||
assert!(game.players[1].constructs[0].skill_on_cd(Skill::Ruin).is_none());
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn stun_test() {
|
||||
let mut game = create_test_game();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user