tests pass, adding skills back in
This commit is contained in:
parent
8cb335fcc7
commit
bab52f3406
@ -4,7 +4,7 @@ use rand::prelude::*;
|
|||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use skill::{Skill, Cast, Immunity, Disable, EventVariant};
|
use skill::{Skill, Cast, Immunity, Disable, Event, EventVariant};
|
||||||
use game::{Colour};
|
use game::{Colour};
|
||||||
use effect::{Cooldown, Effect};
|
use effect::{Cooldown, Effect};
|
||||||
use spec::{Spec};
|
use spec::{Spec};
|
||||||
@ -549,7 +549,7 @@ impl Construct {
|
|||||||
// Should red type immunity block recharge???
|
// Should red type immunity block recharge???
|
||||||
if let Some(immunity) = self.immune(skill) {
|
if let Some(immunity) = self.immune(skill) {
|
||||||
if !self.is_ko() {
|
if !self.is_ko() {
|
||||||
events.push(EventVariant::Immunity { skill, immunity });
|
events.push(Event::new(EventVariant::Immunity { skill, immunity }, self));
|
||||||
}
|
}
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
@ -568,7 +568,7 @@ impl Construct {
|
|||||||
let blue = new_blue_life - current_blue_life;
|
let blue = new_blue_life - current_blue_life;
|
||||||
|
|
||||||
if red != 0 || blue != 0 {
|
if red != 0 || blue != 0 {
|
||||||
events.push(EventVariant::Recharge { red, blue, skill });
|
events.push(Event::new(EventVariant::Recharge { red, blue, skill }, self));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
true => {
|
true => {
|
||||||
@ -594,12 +594,12 @@ impl Construct {
|
|||||||
self.reduce_green_life(red_remainder);
|
self.reduce_green_life(red_remainder);
|
||||||
let red_damage_amount = red_current_green_life - self.green_life();
|
let red_damage_amount = red_current_green_life - self.green_life();
|
||||||
|
|
||||||
events.push(EventVariant::Damage {
|
events.push(Event::new(EventVariant::Damage {
|
||||||
skill,
|
skill,
|
||||||
amount: red_damage_amount,
|
amount: red_damage_amount,
|
||||||
mitigation: red_mitigation,
|
mitigation: red_mitigation,
|
||||||
colour: Colour::Red
|
colour: Colour::Red
|
||||||
});
|
}, self));
|
||||||
}
|
}
|
||||||
|
|
||||||
if blue_amount != 0 {
|
if blue_amount != 0 {
|
||||||
@ -623,12 +623,12 @@ impl Construct {
|
|||||||
self.reduce_green_life(blue_remainder);
|
self.reduce_green_life(blue_remainder);
|
||||||
let blue_damage_amount = blue_current_green_life - self.green_life();
|
let blue_damage_amount = blue_current_green_life - self.green_life();
|
||||||
|
|
||||||
events.push(EventVariant::Damage {
|
events.push(Event::new(EventVariant::Damage {
|
||||||
skill,
|
skill,
|
||||||
amount: blue_damage_amount,
|
amount: blue_damage_amount,
|
||||||
mitigation: blue_mitigation,
|
mitigation: blue_mitigation,
|
||||||
colour: Colour::Blue
|
colour: Colour::Blue
|
||||||
});
|
}, self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -639,7 +639,7 @@ impl Construct {
|
|||||||
let mut events = vec![];
|
let mut events = vec![];
|
||||||
if let Some(immunity) = self.immune(skill) {
|
if let Some(immunity) = self.immune(skill) {
|
||||||
if !self.is_ko() {
|
if !self.is_ko() {
|
||||||
events.push(EventVariant::Immunity { skill, immunity });
|
events.push(Event::new(EventVariant::Immunity { skill, immunity }, self));
|
||||||
}
|
}
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
@ -661,38 +661,38 @@ impl Construct {
|
|||||||
let healing = new_green_life - current_green_life;
|
let healing = new_green_life - current_green_life;
|
||||||
let overhealing = modified_power - healing;
|
let overhealing = modified_power - healing;
|
||||||
|
|
||||||
events.push(EventVariant::Healing {
|
events.push(Event::new(EventVariant::Healing {
|
||||||
skill,
|
skill,
|
||||||
amount: healing,
|
amount: healing,
|
||||||
overhealing,
|
overhealing,
|
||||||
});
|
}, self));
|
||||||
},
|
},
|
||||||
true => {
|
true => {
|
||||||
// events.push(EventVariant::Inversion { skill });
|
// events.push(Event::new(EventVariant::Inversion { skill }));
|
||||||
|
|
||||||
// there is no green shield (yet)
|
// there is no green shield (yet)
|
||||||
let current_green_life = self.green_life();
|
let current_green_life = self.green_life();
|
||||||
self.reduce_green_life(modified_power);
|
self.reduce_green_life(modified_power);
|
||||||
let delta = current_green_life - self.green_life();
|
let delta = current_green_life - self.green_life();
|
||||||
|
|
||||||
events.push(EventVariant::Damage {
|
events.push(Event::new(EventVariant::Damage {
|
||||||
skill,
|
skill,
|
||||||
amount: delta,
|
amount: delta,
|
||||||
mitigation: 0,
|
mitigation: 0,
|
||||||
colour: Colour::Green,
|
colour: Colour::Green,
|
||||||
});
|
}, self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return events;
|
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![];
|
let mut events = vec![];
|
||||||
|
|
||||||
if let Some(immunity) = self.immune(skill) {
|
if let Some(immunity) = self.immune(skill) {
|
||||||
if !self.is_ko() {
|
if !self.is_ko() {
|
||||||
events.push(EventVariant::Immunity { skill, immunity });
|
events.push(Event::new(EventVariant::Immunity { skill, immunity }, self));
|
||||||
}
|
}
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
@ -722,15 +722,18 @@ impl Construct {
|
|||||||
self.reduce_green_life(remainder);
|
self.reduce_green_life(remainder);
|
||||||
let delta = current_green_life - self.green_life();
|
let delta = current_green_life - self.green_life();
|
||||||
|
|
||||||
events.push(EventVariant::Damage {
|
events.push(Event::new(
|
||||||
skill,
|
EventVariant::Damage {
|
||||||
amount: delta,
|
skill,
|
||||||
mitigation,
|
amount: delta,
|
||||||
colour: Colour::Red,
|
mitigation,
|
||||||
});
|
colour: Colour::Red,
|
||||||
|
},
|
||||||
|
self
|
||||||
|
));
|
||||||
},
|
},
|
||||||
true => {
|
true => {
|
||||||
// events.push(EventVariant::Inversion { skill });
|
// events.push(Event::new(EventVariant::Inversion { skill }));
|
||||||
|
|
||||||
let current_green_life = self.green_life();
|
let current_green_life = self.green_life();
|
||||||
self.green_life.increase(modified_power);
|
self.green_life.increase(modified_power);
|
||||||
@ -743,15 +746,17 @@ impl Construct {
|
|||||||
let recharge = self.red_life.value - current_life;
|
let recharge = self.red_life.value - current_life;
|
||||||
|
|
||||||
if healing > 0 {
|
if healing > 0 {
|
||||||
events.push(EventVariant::Healing {
|
events.push(Event::new(
|
||||||
skill,
|
EventVariant::Healing{
|
||||||
amount: healing,
|
skill,
|
||||||
overhealing: overhealing - recharge,
|
amount: healing,
|
||||||
});
|
overhealing: overhealing - recharge,
|
||||||
|
}, self
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if recharge > 0 {
|
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 let Some(immunity) = self.immune(skill) {
|
||||||
if !self.is_ko() {
|
if !self.is_ko() {
|
||||||
events.push(EventVariant::Immunity { skill, immunity });
|
events.push(Event::new(EventVariant::Immunity { skill, immunity }, self));
|
||||||
}
|
}
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
@ -790,15 +795,15 @@ impl Construct {
|
|||||||
self.reduce_green_life(remainder);
|
self.reduce_green_life(remainder);
|
||||||
let delta = current_green_life - self.green_life();
|
let delta = current_green_life - self.green_life();
|
||||||
|
|
||||||
events.push(EventVariant::Damage {
|
events.push(Event::new(EventVariant::Damage {
|
||||||
skill,
|
skill,
|
||||||
amount: delta,
|
amount: delta,
|
||||||
mitigation,
|
mitigation,
|
||||||
colour: Colour::Blue,
|
colour: Colour::Blue,
|
||||||
});
|
}, self));
|
||||||
},
|
},
|
||||||
true => {
|
true => {
|
||||||
// events.push(EventVariant::Inversion { skill });
|
// events.push(Event::new(EventVariant::Inversion { skill }));
|
||||||
|
|
||||||
let current_green_life = self.green_life();
|
let current_green_life = self.green_life();
|
||||||
self.green_life.increase(modified_power);
|
self.green_life.increase(modified_power);
|
||||||
@ -811,15 +816,18 @@ impl Construct {
|
|||||||
let recharge = self.blue_life.value - current_life;
|
let recharge = self.blue_life.value - current_life;
|
||||||
|
|
||||||
if healing > 0 {
|
if healing > 0 {
|
||||||
events.push(EventVariant::Healing {
|
events.push(
|
||||||
skill,
|
Event::new(EventVariant::Healing {
|
||||||
amount: healing,
|
skill,
|
||||||
overhealing,
|
amount: healing,
|
||||||
});
|
overhealing,
|
||||||
|
},
|
||||||
|
self
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if recharge > 0 {
|
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 {
|
pub fn add_effect(&mut self, skill: Skill, effect: ConstructEffect) -> Event {
|
||||||
if let Some(immunity) = self.immune(skill) {
|
if let Some(immunity) = self.immune(skill) {
|
||||||
return EventVariant::Immunity {
|
return Event::new(
|
||||||
skill,
|
EventVariant::Immunity{
|
||||||
immunity,
|
skill,
|
||||||
};
|
immunity,
|
||||||
|
}, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(p) = self.effects.iter().position(|ce| ce.effect == effect.effect) {
|
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
|
// todo modified durations cause of buffs
|
||||||
let result = EventVariant::Effect {
|
let result = Event::new(
|
||||||
effect: effect.effect,
|
EventVariant::Effect {
|
||||||
duration: effect.duration,
|
effect: effect.effect,
|
||||||
construct_effects: self.effects.clone(),
|
duration: effect.duration,
|
||||||
skill,
|
construct_effects: self.effects.clone(),
|
||||||
};
|
skill,
|
||||||
|
}, self
|
||||||
|
);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use failure::Error;
|
|||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use construct::{Construct, Stat};
|
use construct::{Construct, Stat};
|
||||||
use skill::{Skill, Cast, Resolution, Event, resolve};
|
use skill::{Skill, Cast, Event, resolve};
|
||||||
use effect::{Effect};
|
use effect::{Effect};
|
||||||
use player::{Player};
|
use player::{Player};
|
||||||
use instance::{TimeControl};
|
use instance::{TimeControl};
|
||||||
@ -53,7 +53,7 @@ pub struct Game {
|
|||||||
pub players: Vec<Player>,
|
pub players: Vec<Player>,
|
||||||
pub phase: Phase,
|
pub phase: Phase,
|
||||||
pub stack: Vec<Cast>,
|
pub stack: Vec<Cast>,
|
||||||
pub resolutions: Vec<Vec<Resolution>>,
|
pub resolutions: Vec<Vec<Event>>,
|
||||||
pub instance: Option<Uuid>,
|
pub instance: Option<Uuid>,
|
||||||
time_control: TimeControl,
|
time_control: TimeControl,
|
||||||
phase_start: DateTime<Utc>,
|
phase_start: DateTime<Utc>,
|
||||||
@ -489,7 +489,7 @@ impl Game {
|
|||||||
self.skill_phase_start(r_animation_ms)
|
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.resolutions.last_mut().unwrap().append(&mut resolutions);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -505,9 +505,8 @@ impl Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn damage(&mut self, construct: Uuid, skill: Skill, values: Vec<Value>, colour: Colour) -> &mut 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 {
|
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);
|
self.resolution_add(resolutions);
|
||||||
@ -535,8 +534,8 @@ impl Game {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn log_resolution(&mut self, speed: usize, resolution: &Resolution) -> &mut Game {
|
// fn log_resolution(&mut self, speed: usize, resolution: &Event) -> &mut Game {
|
||||||
// let Resolution { source, target, event, stages: _ } = resolution;
|
// let Event { source, target, event, stages: _ } = resolution;
|
||||||
// match event {
|
// match event {
|
||||||
// Event::Ko { skill: _ }=>
|
// Event::Ko { skill: _ }=>
|
||||||
// self.log.push(format!("{:} KO!", target.name)),
|
// self.log.push(format!("{:} KO!", target.name)),
|
||||||
@ -1033,13 +1032,13 @@ mod tests {
|
|||||||
// // game = game.resolve_phase_start();
|
// // game = game.resolve_phase_start();
|
||||||
// // assert!(game.construct_by_id(x_construct.id).unwrap().affected(Effect::Link));
|
// // 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 {
|
// // match event {
|
||||||
// // Event::Effect { effect, skill: _, duration: _, construct_effects: _ } => assert_eq!(effect, Effect::Link),
|
// // Event::Effect { effect, skill: _, duration: _, construct_effects: _ } => assert_eq!(effect, Effect::Link),
|
||||||
// // _ => panic!("not siphon"),
|
// // _ => 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 {
|
// // match event {
|
||||||
// // Event::Recharge { red: _, blue: _, skill: _ } => (),
|
// // Event::Recharge { red: _, blue: _, skill: _ } => (),
|
||||||
// // _ => panic!("link result was not recharge"),
|
// // _ => panic!("link result was not recharge"),
|
||||||
@ -1051,7 +1050,7 @@ mod tests {
|
|||||||
// // game.player_ready(y_player.id).unwrap();
|
// // game.player_ready(y_player.id).unwrap();
|
||||||
// // game = game.resolve_phase_start();
|
// // 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);
|
// // assert_eq!(target.id, y_construct.id);
|
||||||
// // match event {
|
// // match event {
|
||||||
// // Event::Damage { amount, skill: _, mitigation: _, colour: _} =>
|
// // Event::Damage { amount, skill: _, mitigation: _, colour: _} =>
|
||||||
@ -1125,7 +1124,7 @@ mod tests {
|
|||||||
// .last().unwrap()
|
// .last().unwrap()
|
||||||
// .into_iter()
|
// .into_iter()
|
||||||
// .filter(|r| {
|
// .filter(|r| {
|
||||||
// let Resolution { source, target: _, event, stages: _ } = r;
|
// let Event { source, target: _, event, stages: _ } = r;
|
||||||
// match source.id == x_construct.id {
|
// match source.id == x_construct.id {
|
||||||
// true => match event {
|
// true => match event {
|
||||||
// Event::Effect { effect, duration, skill: _, construct_effects: _ } => {
|
// Event::Effect { effect, duration, skill: _, construct_effects: _ } => {
|
||||||
@ -1175,7 +1174,7 @@ mod tests {
|
|||||||
|
|
||||||
// assert!(game.resolutions.len() == 4);
|
// assert!(game.resolutions.len() == 4);
|
||||||
// while let Some(r) = game.resolutions.last().unwrap().pop() {
|
// 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) {
|
// if [i_construct.id, j_construct.id].contains(&source.id) {
|
||||||
// assert!(target.id == x_construct.id);
|
// assert!(target.id == x_construct.id);
|
||||||
// }
|
// }
|
||||||
@ -1264,7 +1263,7 @@ mod tests {
|
|||||||
// game = game.resolve_phase_start();
|
// game = game.resolve_phase_start();
|
||||||
// assert!(game.construct_by_id(y_construct.id).unwrap().affected(Effect::Decay));
|
// 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 {
|
// match event {
|
||||||
// Event::Damage { amount: _, skill, mitigation: _, colour: _ } => assert_eq!(skill, Skill::DecayTick),
|
// Event::Damage { amount: _, skill, mitigation: _, colour: _ } => assert_eq!(skill, Skill::DecayTick),
|
||||||
// _ => panic!("not decay"),
|
// _ => panic!("not decay"),
|
||||||
@ -1278,7 +1277,7 @@ mod tests {
|
|||||||
// game.player_ready(y_player.id).unwrap();
|
// game.player_ready(y_player.id).unwrap();
|
||||||
// game = game.resolve_phase_start();
|
// 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 {
|
// match event {
|
||||||
// Event::Damage { amount: _, skill: _, mitigation: _, colour: _ } =>
|
// Event::Damage { amount: _, skill: _, mitigation: _, colour: _ } =>
|
||||||
// panic!("{:?} damage event", event),
|
// panic!("{:?} damage event", event),
|
||||||
@ -1298,7 +1297,7 @@ mod tests {
|
|||||||
// game.player_ready(y_player.id).unwrap();
|
// game.player_ready(y_player.id).unwrap();
|
||||||
// game = game.resolve_phase_start();
|
// 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 {
|
// match event {
|
||||||
// Event::Damage { amount: _, skill: _, mitigation: _, colour: _ } =>
|
// Event::Damage { amount: _, skill: _, mitigation: _, colour: _ } =>
|
||||||
// panic!("{:#?} {:#?} damage event", game.resolutions, event),
|
// panic!("{:#?} {:#?} damage event", game.resolutions, event),
|
||||||
@ -1323,10 +1322,7 @@ mod tests {
|
|||||||
let player_id = game.players[0].id;
|
let player_id = game.players[0].id;
|
||||||
let source = game.players[0].constructs[0].id;
|
let source = game.players[0].constructs[0].id;
|
||||||
let target = game.players[1].constructs[0].id;
|
let target = game.players[1].constructs[0].id;
|
||||||
println!("{:?}", game);
|
|
||||||
game.add_skill(player_id, source, target, Skill::Attack).unwrap();
|
game.add_skill(player_id, source, target, Skill::Attack).unwrap();
|
||||||
game = game.resolve_phase_start();
|
game = game.resolve_phase_start();
|
||||||
|
|
||||||
println!("{:?}", game.resolutions.last().unwrap());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user