From 7f422ce8e8c70fb743d73f083c485ffc4db47804 Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 29 May 2019 15:57:04 +1000 Subject: [PATCH 1/2] win conditions and some other stuff --- WORKLOG.md | 10 ++++-- client/index.html | 11 +----- client/src/components/game.component.jsx | 2 +- client/src/components/info.component.jsx | 5 ++- client/src/components/instance.component.jsx | 2 +- client/src/components/instance.equip.jsx | 2 -- client/src/constants.jsx | 1 - server/src/game.rs | 11 +++--- server/src/instance.rs | 35 ++++++++++++++++---- 9 files changed, 49 insertions(+), 30 deletions(-) diff --git a/WORKLOG.md b/WORKLOG.md index 782d0f24..601e950b 100644 --- a/WORKLOG.md +++ b/WORKLOG.md @@ -46,9 +46,8 @@ * eth adapter * pay for rerolls -* remove test variants of skills - -* itemise all skills and warn on some +* warden + * set upkeep_at timestamp for games and instances ## SOON @@ -63,6 +62,11 @@ * skills * private fields for opponents +* matchmaking + * elo + * password on MM game to prevent direct joins + + * flavour text * chat wheel trash talk * KO animations and trash talk diff --git a/client/index.html b/client/index.html index f2a78170..f0da3e9e 100644 --- a/client/index.html +++ b/client/index.html @@ -18,14 +18,5 @@ - + \ No newline at end of file diff --git a/client/src/components/game.component.jsx b/client/src/components/game.component.jsx index d199661d..fe110229 100644 --- a/client/src/components/game.component.jsx +++ b/client/src/components/game.component.jsx @@ -83,7 +83,7 @@ function GamePanel(props) { return null; } - const zero = Date.parse(game.phase_end) - (1000 * 60); + const zero = Date.parse(game.phase_start); const now = Date.now(); const end = Date.parse(game.phase_end); const timerPct = ((now - zero) / (end - zero) * 100); diff --git a/client/src/components/info.component.jsx b/client/src/components/info.component.jsx index cbbc714a..c70133e9 100644 --- a/client/src/components/info.component.jsx +++ b/client/src/components/info.component.jsx @@ -117,7 +117,9 @@ function InfoComponent(args) { function Combos() { if (!player) return false; - if (!(combiner.every(u => u === null))) { + + // show recipe for what's in combiner + if (combiner.some(u => u !== null)) { const filteredCombos = itemInfo.combos .filter(combo => combiner.every(u => u === null || combo.components.includes(player.vbox.bound[u]))); @@ -136,6 +138,7 @@ function InfoComponent(args) { ); } + if (!info) return false; const vboxCombos = itemInfo.combos.filter(c => c.components.includes(info)); if (vboxCombos.length > 6) return false; return ( diff --git a/client/src/components/instance.component.jsx b/client/src/components/instance.component.jsx index dff4d03c..2bc1b09c 100644 --- a/client/src/components/instance.component.jsx +++ b/client/src/components/instance.component.jsx @@ -64,7 +64,7 @@ function Instance(args) { : null; // TIMER - const zero = Date.parse(instance.phase_end) - (1000 * 120); + const zero = Date.parse(instance.phase_start); const now = Date.now(); const end = Date.parse(instance.phase_end); const timerPct = ((now - zero) / (end - zero) * 100); diff --git a/client/src/components/instance.equip.jsx b/client/src/components/instance.equip.jsx index 3a18908a..a5f8f813 100644 --- a/client/src/components/instance.equip.jsx +++ b/client/src/components/instance.equip.jsx @@ -64,8 +64,6 @@ function Equipment(props) { const isSkill = fullInfo && fullInfo.skill; const isSpec = fullInfo && fullInfo.spec; - console.log('isSkill', isSkill, fullInfo); - function skillClick(e, i) { if (itemUnequip && activeConstruct) return false; // const value = vbox.bound[i]; diff --git a/client/src/constants.jsx b/client/src/constants.jsx index e950b8ad..6bf4de39 100644 --- a/client/src/constants.jsx +++ b/client/src/constants.jsx @@ -1,6 +1,5 @@ module.exports = { TIMES: { - RESOLUTION_TIME_MS: 1000, START_SKILL: 700, END_SKILL: 700, POST_SKILL: 1000, diff --git a/server/src/game.rs b/server/src/game.rs index 51a544ef..5cbf6120 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -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) -> &mut Game { diff --git a/server/src/instance.rs b/server/src/instance.rs index d2de34ea..d564d49b 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -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, @@ -48,7 +53,10 @@ pub struct Instance { max_rounds: usize, password: Option, pub name: String, + + format: Format, phase_end: DateTime, + phase_start: DateTime, } 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 From ff496cd537cb0b8dda76b17cca2be64d89a3f92d Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 29 May 2019 16:04:25 +1000 Subject: [PATCH 2/2] formats --- server/src/instance.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/server/src/instance.rs b/server/src/instance.rs index d564d49b..7b2e420f 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -33,6 +33,7 @@ enum InstancePhase { #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] enum Format { Standard, + RoundRobin, } #[derive(Debug,Clone,Serialize,Deserialize)] @@ -45,18 +46,21 @@ struct Round { #[derive(Debug,Clone,Serialize,Deserialize)] pub struct Instance { id: Uuid, + pub name: String, + players: Vec, - phase: InstancePhase, rounds: Vec>, + open: bool, max_players: usize, max_rounds: usize, password: Option, - pub name: String, - format: Format, + phase: InstancePhase, phase_end: DateTime, phase_start: DateTime, + + format: Format, } impl Instance { @@ -74,7 +78,7 @@ impl Instance { phase_end: Utc::now(), phase_start: Utc::now(), - format: Format::Standard, + format: Format::RoundRobin, } } @@ -145,12 +149,8 @@ impl Instance { Ok(self) } - fn set_max_rounds(mut self, rounds: usize) -> Result { - if rounds == 0 { - return Err(err_msg("max rounds must be nonzero")); - } - - self.max_rounds = rounds; + fn set_format(mut self, format: Format) -> Result { + self.format = format; Ok(self) } @@ -311,7 +311,8 @@ impl Instance { fn win_condition(&self) -> bool { match self.format { - Format::Standard => self.players.iter().any(|p| p.score.wins > 2) + Format::Standard => self.players.iter().any(|p| p.score.wins > 2), + Format::RoundRobin => self.rounds.len() == self.players.len() / 2, } } @@ -753,7 +754,7 @@ mod tests { fn instance_pve_test() { let mut instance = Instance::new() .set_max_players(16).expect("unable to set max players") - .set_max_rounds(2).expect("max rounds failure") + .set_format(Format::RoundRobin).expect("format failure") .add_bots(); let player_account = Uuid::new_v4(); @@ -768,12 +769,12 @@ mod tests { assert_eq!(instance.phase, InstancePhase::Finished); assert_eq!(instance.rounds[0].len(), 8); - assert_eq!(instance.rounds.len(), 2); + assert_eq!(instance.rounds.len(), 8); } #[test] fn instance_bot_vbox_test() { - let instance = Instance::new(); + let _instance = Instance::new(); let player_account = Uuid::new_v4(); let constructs = instance_mobs(player_account); let _player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true); @@ -823,8 +824,8 @@ mod tests { #[test] fn instance_upkeep_test() { let mut instance = Instance::new() - .set_max_players(2) - .expect("could not create instance"); + .set_max_players(2).expect("could not create instance") + .set_format(Format::Standard).expect("format err"); let player_account = Uuid::new_v4(); let constructs = instance_mobs(player_account);