win conditions and some other stuff

This commit is contained in:
ntr
2019-05-29 15:57:04 +10:00
parent cbe83b3a1e
commit 7f422ce8e8
9 changed files with 49 additions and 30 deletions
+7 -4
View File
@@ -162,13 +162,14 @@ impl Game {
return self.finish();
}
self.skill_phase_start()
self.skill_phase_start(0)
}
fn skill_phase_start(mut self) -> Game {
fn skill_phase_start(mut self, num_resolutions: usize) -> Game {
let phase_add_time_ms = 60000 + num_resolutions * 2500;
self.phase_start = Utc::now();
self.phase_end = Utc::now()
.checked_add_signed(Duration::seconds(60))
.checked_add_signed(Duration::milliseconds(phase_add_time_ms as i64))
.expect("could not set phase end");
for player in self.players.iter_mut() {
@@ -426,12 +427,14 @@ impl Game {
// temp vec of this round's resolving skills
// because need to check cooldown use before pushing them into the complete list
let mut casts = vec![];
let mut turn_events = 0;
while let Some(cast) = self.stack.pop() {
// info!("{:} casts ", cast);
let mut resolutions = resolution_steps(&cast, &mut self);
resolutions.reverse();
turn_events += resolutions.len();
while let Some(resolution) = resolutions.pop() {
self.log_resolution(cast.speed, &resolution);
// the results go into the resolutions
@@ -455,7 +458,7 @@ impl Game {
return self.finish()
}
self.skill_phase_start()
self.skill_phase_start(turn_events)
}
fn progress_durations(&mut self, resolved: &Vec<Cast>) -> &mut Game {
+28 -7
View File
@@ -30,6 +30,11 @@ enum InstancePhase {
Finished,
}
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
enum Format {
Standard,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct Round {
player_ids: Vec<Uuid>,
@@ -48,7 +53,10 @@ pub struct Instance {
max_rounds: usize,
password: Option<String>,
pub name: String,
format: Format,
phase_end: DateTime<Utc>,
phase_start: DateTime<Utc>,
}
impl Instance {
@@ -64,6 +72,9 @@ impl Instance {
name: String::new(),
password: None,
phase_end: Utc::now(),
phase_start: Utc::now(),
format: Format::Standard,
}
}
@@ -78,7 +89,10 @@ impl Instance {
max_rounds: 1,
name: "Global Matchmaking".to_string(),
password: None,
phase_start: Utc::now(),
phase_end: Utc::now(),
format: Format::Standard,
}
}
@@ -273,16 +287,17 @@ impl Instance {
}
fn next_round(&mut self) -> &mut Instance {
self.phase = InstancePhase::InProgress;
self.phase_end = Utc::now()
.checked_add_signed(Duration::seconds(15000))
.expect("could not set phase end");
if self.rounds.len() >= self.max_rounds {
if self.win_condition() {
return self.finish();
}
self.phase = InstancePhase::InProgress;
self.phase_start = Utc::now();
self.phase_end = Utc::now()
.checked_add_signed(Duration::seconds(120))
.expect("could not set phase end");
self.players.iter_mut().for_each(|p| {
p.set_ready(false);
p.vbox.fill();
@@ -294,6 +309,12 @@ impl Instance {
self
}
fn win_condition(&self) -> bool {
match self.format {
Format::Standard => self.players.iter().any(|p| p.score.wins > 2)
}
}
fn finish(&mut self) -> &mut Instance {
self.phase = InstancePhase::Finished;
self