tests pass, adding skills back in

This commit is contained in:
ntr 2019-12-04 15:35:19 +10:00
parent 8cb335fcc7
commit bab52f3406
3 changed files with 538 additions and 505 deletions

View File

@ -4,7 +4,7 @@ use rand::prelude::*;
use failure::Error;
use failure::err_msg;
use skill::{Skill, Cast, Immunity, Disable, EventVariant};
use skill::{Skill, Cast, Immunity, Disable, Event, EventVariant};
use game::{Colour};
use effect::{Cooldown, Effect};
use spec::{Spec};
@ -549,7 +549,7 @@ impl Construct {
// Should red type immunity block recharge???
if let Some(immunity) = self.immune(skill) {
if !self.is_ko() {
events.push(EventVariant::Immunity { skill, immunity });
events.push(Event::new(EventVariant::Immunity { skill, immunity }, self));
}
return events;
}
@ -568,7 +568,7 @@ impl Construct {
let blue = new_blue_life - current_blue_life;
if red != 0 || blue != 0 {
events.push(EventVariant::Recharge { red, blue, skill });
events.push(Event::new(EventVariant::Recharge { red, blue, skill }, self));
}
},
true => {
@ -594,12 +594,12 @@ impl Construct {
self.reduce_green_life(red_remainder);
let red_damage_amount = red_current_green_life - self.green_life();
events.push(EventVariant::Damage {
events.push(Event::new(EventVariant::Damage {
skill,
amount: red_damage_amount,
mitigation: red_mitigation,
colour: Colour::Red
});
}, self));
}
if blue_amount != 0 {
@ -623,12 +623,12 @@ impl Construct {
self.reduce_green_life(blue_remainder);
let blue_damage_amount = blue_current_green_life - self.green_life();
events.push(EventVariant::Damage {
events.push(Event::new(EventVariant::Damage {
skill,
amount: blue_damage_amount,
mitigation: blue_mitigation,
colour: Colour::Blue
});
}, self));
}
}
}
@ -639,7 +639,7 @@ impl Construct {
let mut events = vec![];
if let Some(immunity) = self.immune(skill) {
if !self.is_ko() {
events.push(EventVariant::Immunity { skill, immunity });
events.push(Event::new(EventVariant::Immunity { skill, immunity }, self));
}
return events;
}
@ -661,38 +661,38 @@ impl Construct {
let healing = new_green_life - current_green_life;
let overhealing = modified_power - healing;
events.push(EventVariant::Healing {
events.push(Event::new(EventVariant::Healing {
skill,
amount: healing,
overhealing,
});
}, self));
},
true => {
// events.push(EventVariant::Inversion { skill });
// events.push(Event::new(EventVariant::Inversion { skill }));
// there is no green shield (yet)
let current_green_life = self.green_life();
self.reduce_green_life(modified_power);
let delta = current_green_life - self.green_life();
events.push(EventVariant::Damage {
events.push(Event::new(EventVariant::Damage {
skill,
amount: delta,
mitigation: 0,
colour: Colour::Green,
});
}, self));
}
}
return events;
}
pub fn deal_red_damage(&mut self, skill: Skill, amount: usize) -> Vec<Resolution> {
pub fn deal_red_damage(&mut self, skill: Skill, amount: usize) -> Vec<Event> {
let mut events = vec![];
if let Some(immunity) = self.immune(skill) {
if !self.is_ko() {
events.push(EventVariant::Immunity { skill, immunity });
events.push(Event::new(EventVariant::Immunity { skill, immunity }, self));
}
return events;
}
@ -722,15 +722,18 @@ impl Construct {
self.reduce_green_life(remainder);
let delta = current_green_life - self.green_life();
events.push(EventVariant::Damage {
skill,
amount: delta,
mitigation,
colour: Colour::Red,
});
events.push(Event::new(
EventVariant::Damage {
skill,
amount: delta,
mitigation,
colour: Colour::Red,
},
self
));
},
true => {
// events.push(EventVariant::Inversion { skill });
// events.push(Event::new(EventVariant::Inversion { skill }));
let current_green_life = self.green_life();
self.green_life.increase(modified_power);
@ -743,15 +746,17 @@ impl Construct {
let recharge = self.red_life.value - current_life;
if healing > 0 {
events.push(EventVariant::Healing {
skill,
amount: healing,
overhealing: overhealing - recharge,
});
events.push(Event::new(
EventVariant::Healing{
skill,
amount: healing,
overhealing: overhealing - recharge,
}, self
));
}
if recharge > 0 {
events.push(EventVariant::Recharge { red: recharge, blue: 0, skill });
events.push(Event::new(EventVariant::Recharge { red: recharge, blue: 0, skill }, self));
}
}
};
@ -764,7 +769,7 @@ impl Construct {
if let Some(immunity) = self.immune(skill) {
if !self.is_ko() {
events.push(EventVariant::Immunity { skill, immunity });
events.push(Event::new(EventVariant::Immunity { skill, immunity }, self));
}
return events;
}
@ -790,15 +795,15 @@ impl Construct {
self.reduce_green_life(remainder);
let delta = current_green_life - self.green_life();
events.push(EventVariant::Damage {
events.push(Event::new(EventVariant::Damage {
skill,
amount: delta,
mitigation,
colour: Colour::Blue,
});
}, self));
},
true => {
// events.push(EventVariant::Inversion { skill });
// events.push(Event::new(EventVariant::Inversion { skill }));
let current_green_life = self.green_life();
self.green_life.increase(modified_power);
@ -811,15 +816,18 @@ impl Construct {
let recharge = self.blue_life.value - current_life;
if healing > 0 {
events.push(EventVariant::Healing {
skill,
amount: healing,
overhealing,
});
events.push(
Event::new(EventVariant::Healing {
skill,
amount: healing,
overhealing,
},
self
));
}
if recharge > 0 {
events.push(EventVariant::Recharge { red: 0, blue: recharge, skill });
events.push(Event::new(EventVariant::Recharge { red: 0, blue: recharge, skill }, self));
}
}
};
@ -829,10 +837,11 @@ impl Construct {
pub fn add_effect(&mut self, skill: Skill, effect: ConstructEffect) -> Event {
if let Some(immunity) = self.immune(skill) {
return EventVariant::Immunity {
skill,
immunity,
};
return Event::new(
EventVariant::Immunity{
skill,
immunity,
}, self);
}
if let Some(p) = self.effects.iter().position(|ce| ce.effect == effect.effect) {
@ -847,12 +856,14 @@ impl Construct {
}
// todo modified durations cause of buffs
let result = EventVariant::Effect {
effect: effect.effect,
duration: effect.duration,
construct_effects: self.effects.clone(),
skill,
};
let result = Event::new(
EventVariant::Effect {
effect: effect.effect,
duration: effect.duration,
construct_effects: self.effects.clone(),
skill,
}, self
);
return result;
}

View File

@ -10,7 +10,7 @@ use failure::Error;
use failure::err_msg;
use construct::{Construct, Stat};
use skill::{Skill, Cast, Resolution, Event, resolve};
use skill::{Skill, Cast, Event, resolve};
use effect::{Effect};
use player::{Player};
use instance::{TimeControl};
@ -53,7 +53,7 @@ pub struct Game {
pub players: Vec<Player>,
pub phase: Phase,
pub stack: Vec<Cast>,
pub resolutions: Vec<Vec<Resolution>>,
pub resolutions: Vec<Vec<Event>>,
pub instance: Option<Uuid>,
time_control: TimeControl,
phase_start: DateTime<Utc>,
@ -489,7 +489,7 @@ impl Game {
self.skill_phase_start(r_animation_ms)
}
fn resolution_add(&mut self, mut resolutions: Vec<Resolution>) -> &mut Game {
fn resolution_add(&mut self, mut resolutions: Vec<Event>) -> &mut Game {
self.resolutions.last_mut().unwrap().append(&mut resolutions);
self
}
@ -505,9 +505,8 @@ impl Game {
}
fn damage(&mut self, construct: Uuid, skill: Skill, values: Vec<Value>, colour: Colour) -> &mut Game {
let target = self.construct_by_id(construct).unwrap();
let resolutions = match colour {
_ => target.deal_red_damage(skill, 128) // fixme unwrap
_ => self.construct_by_id(construct).unwrap().deal_red_damage(skill, 128) // fixme unwrap
};
self.resolution_add(resolutions);
@ -535,8 +534,8 @@ impl Game {
self
}
// fn log_resolution(&mut self, speed: usize, resolution: &Resolution) -> &mut Game {
// let Resolution { source, target, event, stages: _ } = resolution;
// fn log_resolution(&mut self, speed: usize, resolution: &Event) -> &mut Game {
// let Event { source, target, event, stages: _ } = resolution;
// match event {
// Event::Ko { skill: _ }=>
// self.log.push(format!("{:} KO!", target.name)),
@ -1033,13 +1032,13 @@ mod tests {
// // game = game.resolve_phase_start();
// // assert!(game.construct_by_id(x_construct.id).unwrap().affected(Effect::Link));
// // let Resolution { source: _, target: _, event, stages: _ } = game.resolutions.last.unwrap().pop().unwrap();
// // let Event { source: _, target: _, event, stages: _ } = game.resolutions.last.unwrap().pop().unwrap();
// // match event {
// // Event::Effect { effect, skill: _, duration: _, construct_effects: _ } => assert_eq!(effect, Effect::Link),
// // _ => panic!("not siphon"),
// // };
// // let Resolution { source: _, target: _, event, stages: _ } = game.resolutions.last.unwrap().pop().unwrap();
// // let Event { source: _, target: _, event, stages: _ } = game.resolutions.last.unwrap().pop().unwrap();
// // match event {
// // Event::Recharge { red: _, blue: _, skill: _ } => (),
// // _ => panic!("link result was not recharge"),
@ -1051,7 +1050,7 @@ mod tests {
// // game.player_ready(y_player.id).unwrap();
// // game = game.resolve_phase_start();
// // let Resolution { source: _, target, event, stages: _ } = game.resolutions.last.unwrap().pop().unwrap();
// // let Event { source: _, target, event, stages: _ } = game.resolutions.last.unwrap().pop().unwrap();
// // assert_eq!(target.id, y_construct.id);
// // match event {
// // Event::Damage { amount, skill: _, mitigation: _, colour: _} =>
@ -1125,7 +1124,7 @@ mod tests {
// .last().unwrap()
// .into_iter()
// .filter(|r| {
// let Resolution { source, target: _, event, stages: _ } = r;
// let Event { source, target: _, event, stages: _ } = r;
// match source.id == x_construct.id {
// true => match event {
// Event::Effect { effect, duration, skill: _, construct_effects: _ } => {
@ -1175,7 +1174,7 @@ mod tests {
// assert!(game.resolutions.len() == 4);
// while let Some(r) = game.resolutions.last().unwrap().pop() {
// let Resolution { source , target, event: _, stages: _ } = r;
// let Event { source , target, event: _, stages: _ } = r;
// if [i_construct.id, j_construct.id].contains(&source.id) {
// assert!(target.id == x_construct.id);
// }
@ -1264,7 +1263,7 @@ mod tests {
// game = game.resolve_phase_start();
// assert!(game.construct_by_id(y_construct.id).unwrap().affected(Effect::Decay));
// let Resolution { source: _, target: _, event, stages: _ } = game.resolutions.last().unwrap().pop().unwrap();
// let Event { source: _, target: _, event, stages: _ } = game.resolutions.last().unwrap().pop().unwrap();
// match event {
// Event::Damage { amount: _, skill, mitigation: _, colour: _ } => assert_eq!(skill, Skill::DecayTick),
// _ => panic!("not decay"),
@ -1278,7 +1277,7 @@ mod tests {
// game.player_ready(y_player.id).unwrap();
// game = game.resolve_phase_start();
// while let Some(Resolution { source: _, target: _, event, stages: _ }) = game.resolutions.last().unwrap().pop() {
// while let Some(Event { source: _, target: _, event, stages: _ }) = game.resolutions.last().unwrap().pop() {
// match event {
// Event::Damage { amount: _, skill: _, mitigation: _, colour: _ } =>
// panic!("{:?} damage event", event),
@ -1298,7 +1297,7 @@ mod tests {
// game.player_ready(y_player.id).unwrap();
// game = game.resolve_phase_start();
// while let Some(Resolution { source: _, target: _, event, stages: _ }) = game.resolutions.last().unwrap().pop() {
// while let Some(Event { source: _, target: _, event, stages: _ }) = game.resolutions.last().unwrap().pop() {
// match event {
// Event::Damage { amount: _, skill: _, mitigation: _, colour: _ } =>
// panic!("{:#?} {:#?} damage event", game.resolutions, event),
@ -1323,10 +1322,7 @@ mod tests {
let player_id = game.players[0].id;
let source = game.players[0].constructs[0].id;
let target = game.players[1].constructs[0].id;
println!("{:?}", game);
game.add_skill(player_id, source, target, Skill::Attack).unwrap();
game = game.resolve_phase_start();
println!("{:?}", game.resolutions.last().unwrap());
}
}

File diff suppressed because it is too large Load Diff