game finished
This commit is contained in:
parent
f37cb4a7e4
commit
b5b2e95f34
@ -12,7 +12,7 @@ use rpc::{GameStateParams, GameSkillParams};
|
|||||||
use cryp::{Cryp};
|
use cryp::{Cryp};
|
||||||
use skill::{Skill, Effect, Cast, Resolution, Event, resolve};
|
use skill::{Skill, Effect, Cast, Resolution, Event, resolve};
|
||||||
use player::{Player};
|
use player::{Player};
|
||||||
// use instance::{instance_game_finished, global_game_finished};
|
use instance::{instance_game_finished, global_game_finished};
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct Team {
|
pub struct Team {
|
||||||
@ -798,14 +798,14 @@ pub fn game_update(game: &Game, tx: &mut Transaction) -> Result<(), Error> {
|
|||||||
|
|
||||||
result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?;
|
result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?;
|
||||||
|
|
||||||
// if game.finished() {
|
if game.finished() {
|
||||||
// if let Some(i) = game.instance {
|
if let Some(i) = game.instance {
|
||||||
// match i == Uuid::nil() {
|
match i == Uuid::nil() {
|
||||||
// true => global_game_finished(tx, &game)?,
|
true => global_game_finished(tx, &game)?,
|
||||||
// false => instance_game_finished(tx, &game, i)?,
|
false => instance_game_finished(tx, &game, i)?,
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -228,6 +228,20 @@ impl Instance {
|
|||||||
.ok_or(err_msg("could not find matchup in current round"))?
|
.ok_or(err_msg("could not find matchup in current round"))?
|
||||||
.finished = true;
|
.finished = true;
|
||||||
|
|
||||||
|
let winner = game.winner().ok_or(err_msg("game not finished"))?;
|
||||||
|
|
||||||
|
for team in game.teams.iter() {
|
||||||
|
let mut player = self.account_player(team.id)?;
|
||||||
|
match team.id == winner.id {
|
||||||
|
true => player.add_win(),
|
||||||
|
false => player.add_loss(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.all_games_finished() {
|
||||||
|
self.next_round();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,112 +641,31 @@ pub fn instance_state(params: InstanceStateParams, tx: &mut Transaction, account
|
|||||||
Ok(RpcResult::InstanceState(instance))
|
Ok(RpcResult::InstanceState(instance))
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
|
pub fn global_game_finished(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
|
||||||
// let mut player = player_get(tx, account.id, params.instance_id)?;
|
let winner = game.winner().ok_or(err_msg("game not finished"))?;
|
||||||
|
|
||||||
// if params.instance_id == Uuid::nil() {
|
for team in game.teams.iter() {
|
||||||
// return instance_ready_global(tx, account, player);
|
let mut player = player_get(tx, team.id, Uuid::nil())?;
|
||||||
// }
|
match team.id == winner.id {
|
||||||
|
true => player.add_win(),
|
||||||
|
false => player.add_loss(),
|
||||||
|
};
|
||||||
|
player.vbox.fill();
|
||||||
|
player_update(tx, player, true)?;
|
||||||
|
}
|
||||||
|
|
||||||
// let mut instance = instance_get(tx, params.instance_id)?;
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// // attempting to re-ready
|
pub fn instance_game_finished(tx: &mut Transaction, game: &Game, instance_id: Uuid) -> Result<(), Error> {
|
||||||
// // send game state
|
let mut instance = instance_get(tx, instance_id)?;
|
||||||
// match instance.player_ready(player.id) {
|
instance.game_finished(game)?;
|
||||||
// Ok(_) => (),
|
// println!("{:?}", instance_get(tx, instance_id)?);
|
||||||
// Err(_) => return game_get(tx, instance.current_round(player.id).game_id),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let game_id = instance.current_round(player.id).game_id;
|
instance_update(tx, instance)?;
|
||||||
|
|
||||||
// let game = match instance.player_has_pve_game(&player) {
|
Ok(())
|
||||||
// true => match game_get(tx, game_id) {
|
}
|
||||||
// Ok(g) => g,
|
|
||||||
// Err(_) => {
|
|
||||||
// let game = instance.bot_vs_player_game(&player)?;
|
|
||||||
// game_write(&game, tx)?;
|
|
||||||
// game
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// false => match game_get(tx, game_id) {
|
|
||||||
// Ok(_g) => game_instance_join(tx, player.clone(), game_id)?,
|
|
||||||
// Err(_) => game_instance_new(tx, player.clone(), game_id)?,
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// player_update(tx, player, false)?;
|
|
||||||
// instance_update(tx, instance)?;
|
|
||||||
// return Ok(game);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn global_game_finished(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
|
|
||||||
// let winner = game.winner().ok_or(err_msg("game not finished"))?;
|
|
||||||
|
|
||||||
// for team in game.teams.iter() {
|
|
||||||
// let mut player = player_get(tx, team.id, Uuid::nil())?;
|
|
||||||
// match team.id == winner.id {
|
|
||||||
// true => player.add_win(),
|
|
||||||
// false => player.add_loss(),
|
|
||||||
// };
|
|
||||||
// player.vbox.fill();
|
|
||||||
// player_update(tx, player, true)?;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Ok(())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn instance_game_finished(tx: &mut Transaction, game: &Game, instance_id: Uuid) -> Result<(), Error> {
|
|
||||||
// // update scores
|
|
||||||
// let winner = game.winner().ok_or(err_msg("game not finished"))?;
|
|
||||||
|
|
||||||
// for team in game.teams.iter() {
|
|
||||||
// match team.bot {
|
|
||||||
// true => {
|
|
||||||
// let mut instance = instance_get(tx, instance_id)?;
|
|
||||||
// {
|
|
||||||
// let mut player = instance.players.iter_mut().find(|p| p.account == team.id).unwrap();
|
|
||||||
// match team.id == winner.id {
|
|
||||||
// true => player.add_win(),
|
|
||||||
// false => player.add_loss(),
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// instance_update(tx, instance)?;
|
|
||||||
// },
|
|
||||||
// false => {
|
|
||||||
// let mut player = player_get(tx, team.id, instance_id)?;
|
|
||||||
// match team.id == winner.id {
|
|
||||||
// true => player.add_win(),
|
|
||||||
// false => player.add_loss(),
|
|
||||||
// };
|
|
||||||
// player_update(tx, player, true)?;
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // update instance and persist
|
|
||||||
// let mut instance = instance_get(tx, instance_id)?;
|
|
||||||
// instance.game_finished(game)?;
|
|
||||||
// let mut instance = instance_update(tx, instance)?;
|
|
||||||
|
|
||||||
// // now modify the players and write them all
|
|
||||||
// // each player update will also update the instance in db
|
|
||||||
// if instance.all_games_finished() {
|
|
||||||
// instance.next_round();
|
|
||||||
// let instance = instance_update(tx, instance)?;
|
|
||||||
|
|
||||||
// for player in instance.players
|
|
||||||
// .iter()
|
|
||||||
// .filter(|p| !p.bot) {
|
|
||||||
// let mut player = player_get(tx, player.account, instance_id)?;
|
|
||||||
// player.vbox.fill();
|
|
||||||
// player_update(tx, player, false)?;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // println!("{:?}", instance_get(tx, instance_id)?);
|
|
||||||
|
|
||||||
// Ok(())
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user