bash is back

This commit is contained in:
ntr 2019-12-04 18:50:21 +10:00
parent 9b5261c95a
commit 7c486812f4
2 changed files with 34 additions and 31 deletions

View File

@ -54,7 +54,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<Event>>, pub events: 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>,
@ -70,7 +70,7 @@ impl Game {
players: vec![], players: vec![],
phase: Phase::Start, phase: Phase::Start,
stack: vec![], stack: vec![],
resolutions: vec![], events: vec![],
instance: None, instance: None,
time_control: TimeControl::Standard, time_control: TimeControl::Standard,
phase_end: None, phase_end: None,
@ -189,6 +189,8 @@ impl Game {
} }
fn skill_phase_start(mut self, resolution_animation_ms: i64) -> Game { fn skill_phase_start(mut self, resolution_animation_ms: i64) -> Game {
self.events.push(vec![]);
self.phase_start = Utc::now() self.phase_start = Utc::now()
.checked_add_signed(Duration::milliseconds(resolution_animation_ms)) .checked_add_signed(Duration::milliseconds(resolution_animation_ms))
.expect("could not set phase start"); .expect("could not set phase start");
@ -415,7 +417,6 @@ impl Game {
panic!("game not in skill phase"); panic!("game not in skill phase");
} }
self.phase = Phase::Resolve; self.phase = Phase::Resolve;
self.resolutions.push(vec![]);
// self.log.push("<Resolve Phase>".to_string()); // self.log.push("<Resolve Phase>".to_string());
self.resolve_stack() self.resolve_stack()
@ -467,10 +468,10 @@ impl Game {
// info!("{:} casts ", cast); // info!("{:} casts ", cast);
resolve(&mut self, cast); resolve(&mut self, cast);
// r_animation_ms = resolutions.iter().fold(r_animation_ms, |acc, r| acc + r.clone().get_delay()); // r_animation_ms = events.iter().fold(r_animation_ms, |acc, r| acc + r.clone().get_delay());
// if theres no resolution resolutions, the skill didn't trigger (disable etc) // if theres no resolution events, the skill didn't trigger (disable etc)
// if resolutions.len() > 0 && cast.used_cooldown() { // if events.len() > 0 && cast.used_cooldown() {
// casters.push(cast); // casters.push(cast);
// } // }
@ -490,8 +491,8 @@ impl Game {
self.skill_phase_start(r_animation_ms) self.skill_phase_start(r_animation_ms)
} }
fn resolution_add(&mut self, mut resolutions: Vec<Event>) -> &mut Game { fn resolution_add(&mut self, mut events: Vec<Event>) -> &mut Game {
self.resolutions.last_mut().unwrap().append(&mut resolutions); self.events.last_mut().unwrap().append(&mut events);
self self
} }
@ -508,27 +509,27 @@ impl Game {
} }
fn damage(&mut self, construct: Uuid, values: Vec<Value>, colour: Colour) -> &mut Game { fn damage(&mut self, construct: Uuid, values: Vec<Value>, colour: Colour) -> &mut Game {
let resolutions = match colour { let events = match colour {
_ => self.construct_by_id(construct).unwrap().deal_red_damage(128) // fixme unwrap _ => self.construct_by_id(construct).unwrap().deal_red_damage(128) // fixme unwrap
}; };
self.resolution_add(resolutions); self.resolution_add(events);
self self
} }
fn effect(&mut self, construct: Uuid, effect: ConstructEffect) -> &mut Game { fn effect(&mut self, construct: Uuid, effect: ConstructEffect) -> &mut Game {
let resolutions = self.construct_by_id(construct).unwrap().add_effect(effect); let events = self.construct_by_id(construct).unwrap().add_effect(effect);
self.resolution_add(resolutions); self.resolution_add(events);
self self
} }
fn increase_cooldowns(&mut self, construct: Uuid, turns: usize) -> &mut Game { fn increase_cooldowns(&mut self, construct: Uuid, turns: usize) -> &mut Game {
let resolutions = self.construct_by_id(construct).unwrap().increase_cooldowns(turns); let events = self.construct_by_id(construct).unwrap().increase_cooldowns(turns);
self.resolution_add(resolutions); self.resolution_add(events);
self self
} }
fn progress_durations(&mut self, resolutions: &Vec<Cast>) -> &mut Game { fn progress_durations(&mut self, events: &Vec<Cast>) -> &mut Game {
for mut construct in self.all_constructs() { for mut construct in self.all_constructs() {
// info!("progressing durations for {:}", construct.name); // info!("progressing durations for {:}", construct.name);
@ -536,7 +537,7 @@ impl Game {
continue; continue;
} }
match resolutions.iter().find(|s| s.source == construct.id) { match events.iter().find(|s| s.source == construct.id) {
Some(skill) => { construct.skill_set_cd(skill.skill); }, Some(skill) => { construct.skill_set_cd(skill.skill); },
None => { construct.reduce_cooldowns(); }, None => { construct.reduce_cooldowns(); },
}; };
@ -662,7 +663,7 @@ impl Game {
// player.forfeit(); // player.forfeit();
// info!("upkeep: {:} forfeited", player.name); // info!("upkeep: {:} forfeited", player.name);
// //todo // //todo
// // self.resolutions.push(forfeit) // // self.events.push(forfeit)
// // self.log.push(format!("{:} forfeited.", player.name)); // // self.log.push(format!("{:} forfeited.", player.name));
// } // }
} }
@ -1047,13 +1048,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 Event { source: _, target: _, event, stages: _ } = game.resolutions.last.unwrap().pop().unwrap(); // // let Event { source: _, target: _, event, stages: _ } = game.events.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 Event { source: _, target: _, event, stages: _ } = game.resolutions.last.unwrap().pop().unwrap(); // // let Event { source: _, target: _, event, stages: _ } = game.events.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"),
@ -1065,7 +1066,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 Event { source: _, target, event, stages: _ } = game.resolutions.last.unwrap().pop().unwrap(); // // let Event { source: _, target, event, stages: _ } = game.events.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: _} =>
@ -1135,7 +1136,7 @@ mod tests {
// assert!(game.skill_phase_finished()); // assert!(game.skill_phase_finished());
// game = game.resolve_phase_start(); // game = game.resolve_phase_start();
// let ruins = game.resolutions // let ruins = game.events
// .last().unwrap() // .last().unwrap()
// .into_iter() // .into_iter()
// .filter(|r| { // .filter(|r| {
@ -1187,8 +1188,8 @@ mod tests {
// game = game.resolve_phase_start(); // game = game.resolve_phase_start();
// assert!(game.resolutions.len() == 4); // assert!(game.events.len() == 4);
// while let Some(r) = game.resolutions.last().unwrap().pop() { // while let Some(r) = game.events.last().unwrap().pop() {
// let Event { 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);
@ -1278,13 +1279,13 @@ 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 Event { source: _, target: _, event, stages: _ } = game.resolutions.last().unwrap().pop().unwrap(); // let Event { source: _, target: _, event, stages: _ } = game.events.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"),
// }; // };
// game.resolutions.clear(); // game.events.clear();
// // remove // // remove
// game.add_skill(y_player.id, y_construct.id, y_construct.id, Skill::Purify).unwrap(); // game.add_skill(y_player.id, y_construct.id, y_construct.id, Skill::Purify).unwrap();
@ -1292,7 +1293,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(Event { source: _, target: _, event, stages: _ }) = game.resolutions.last().unwrap().pop() { // while let Some(Event { source: _, target: _, event, stages: _ }) = game.events.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),
@ -1305,17 +1306,17 @@ 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();
// game.resolutions.clear(); // game.events.clear();
// game.add_skill(y_player.id, y_construct.id, y_construct.id, Skill::Purify).unwrap(); // game.add_skill(y_player.id, y_construct.id, y_construct.id, Skill::Purify).unwrap();
// game.player_ready(x_player.id).unwrap(); // game.player_ready(x_player.id).unwrap();
// 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(Event { source: _, target: _, event, stages: _ }) = game.resolutions.last().unwrap().pop() { // while let Some(Event { source: _, target: _, event, stages: _ }) = game.events.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.events, event),
// _ => (), // _ => (),
// } // }
// }; // };
@ -1352,6 +1353,6 @@ mod tests {
game.actions(Cast::new(source, player_id, target, Skill::Bash).actions()); game.actions(Cast::new(source, player_id, target, Skill::Bash).actions());
println!("{:?}", game); println!("{:?}", game.events);
} }
} }

View File

@ -156,7 +156,9 @@ impl Cast {
} }
], ],
Skill::Bash => vec![ Skill::Bash |
Skill::BashPlus |
Skill::BashPlusPlus => vec![
Action::Damage { Action::Damage {
construct: self.target, construct: self.target,
colour: Colour::Red, colour: Colour::Red,