various instance fixs

This commit is contained in:
ntr 2019-03-03 12:17:40 +11:00
parent f4e1c368e0
commit 228d64d73d
2 changed files with 20 additions and 10 deletions

View File

@ -141,7 +141,7 @@ function createSocket(events) {
} }
function sendInstanceJoin(cryps) { function sendInstanceJoin(cryps) {
send({ method: 'instance_join', params: { cryp_ids: cryps, pve: false } }); send({ method: 'instance_join', params: { cryp_ids: cryps, pve: true } });
} }
function sendInstanceReady(instanceId) { function sendInstanceReady(instanceId) {
@ -255,7 +255,7 @@ function createSocket(events) {
if (!account) events.loginPrompt(); if (!account) events.loginPrompt();
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
// send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } }); send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
} }
return true; return true;

View File

@ -85,9 +85,9 @@ impl Instance {
Ok(self) Ok(self)
} }
fn player_ready(mut self, mut player: Player) -> Result<Instance, Error> { fn player_ready(&mut self, mut player: Player) -> Result<&mut Instance, Error> {
if self.phase != InstancePhase::Vbox { if self.phase != InstancePhase::Vbox {
panic!("instance not in vbox phase"); return Err(err_msg("instance not in vbox phase"));
} }
let i = self.players let i = self.players
@ -113,7 +113,8 @@ impl Instance {
game game
.set_pve(true) .set_pve(true)
.set_team_num(2) .set_team_num(2)
.set_team_size(3); .set_team_size(3)
.set_instance(self.id);
// add the players // add the players
let mut plr_team = Team::new(plr.account); let mut plr_team = Team::new(plr.account);
@ -141,13 +142,13 @@ impl Instance {
fn start(&mut self) -> &mut Instance { fn start(&mut self) -> &mut Instance {
// self.players.sort_unstable_by_key(|p| p.id); // self.players.sort_unstable_by_key(|p| p.id);
self.generate_rounds();
self.open = false; self.open = false;
self.vbox_phase_start() self.vbox_phase_start()
} }
fn vbox_phase_start(&mut self) -> &mut Instance { fn vbox_phase_start(&mut self) -> &mut Instance {
self.phase = InstancePhase::Vbox; self.phase = InstancePhase::Vbox;
self.generate_rounds();
self.bot_vbox_phase(); self.bot_vbox_phase();
self self
@ -405,11 +406,20 @@ pub fn instance_join(params: InstanceJoinParams, tx: &mut Transaction, account:
pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> { pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
let player = player_get(tx, account.id, params.instance_id)?; let player = player_get(tx, account.id, params.instance_id)?;
let instance = instance_get(tx, params.instance_id)? let mut instance = instance_get(tx, params.instance_id)?;
.player_ready(player.clone())?;
let game_id = instance.current_round(&player).game_id; let game_id = instance.current_round(&player).game_id;
// attempting to re-ready
// send game state
match instance.player_ready(player.clone()) {
Ok(_) => (),
Err(_) => return game_get(tx, game_id),
};
if instance.vbox_phase_finished() {
instance.games_phase_start();
}
let game = match instance.pve { let game = match instance.pve {
true => match game_get(tx, game_id) { true => match game_get(tx, game_id) {
Ok(g) => g, Ok(g) => g,
@ -490,7 +500,7 @@ mod tests {
assert_eq!(instance.rounds[0].len(), 8); assert_eq!(instance.rounds[0].len(), 8);
let player = instance.players.clone().into_iter().find(|p| p.account == player_id).unwrap(); let player = instance.players.clone().into_iter().find(|p| p.account == player_id).unwrap();
let mut instance = instance.player_ready(player).unwrap(); instance.player_ready(player).unwrap();
assert!(instance.vbox_phase_finished()); assert!(instance.vbox_phase_finished());
instance.games_phase_start(); instance.games_phase_start();