global game updates
This commit is contained in:
parent
5fe394370d
commit
b3eb770d80
@ -12,13 +12,14 @@ use rpc::{GameStateParams, GameSkillParams};
|
|||||||
use cryp::{Cryp};
|
use cryp::{Cryp};
|
||||||
use skill::{Skill, Cast, ResolutionResult};
|
use skill::{Skill, Cast, ResolutionResult};
|
||||||
use player::{Player};
|
use player::{Player};
|
||||||
use instance::{instance_game_finished};
|
use instance::{instance_game_finished, global_game_finished};
|
||||||
|
|
||||||
pub type Log = Vec<String>;
|
pub type Log = Vec<String>;
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct Team {
|
pub struct Team {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
|
pub player: Option<Uuid>,
|
||||||
pub bot: bool,
|
pub bot: bool,
|
||||||
cryps: Vec<Cryp>,
|
cryps: Vec<Cryp>,
|
||||||
}
|
}
|
||||||
@ -27,6 +28,7 @@ impl Team {
|
|||||||
pub fn new(account: Uuid) -> Team {
|
pub fn new(account: Uuid) -> Team {
|
||||||
return Team {
|
return Team {
|
||||||
id: account,
|
id: account,
|
||||||
|
player: None,
|
||||||
cryps: vec![],
|
cryps: vec![],
|
||||||
bot: false,
|
bot: false,
|
||||||
};
|
};
|
||||||
@ -741,7 +743,10 @@ pub fn game_update(game: &Game, tx: &mut Transaction) -> Result<(), Error> {
|
|||||||
|
|
||||||
if game.finished() {
|
if game.finished() {
|
||||||
if let Some(i) = game.instance {
|
if let Some(i) = game.instance {
|
||||||
instance_game_finished(tx, &game, i)?;
|
match i == Uuid::nil() {
|
||||||
|
true => instance_game_finished(tx, &game, i)?,
|
||||||
|
false => global_game_finished(tx, &game)?,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -476,6 +476,22 @@ pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account
|
|||||||
return Ok(game);
|
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> {
|
pub fn instance_game_finished(tx: &mut Transaction, game: &Game, instance_id: Uuid) -> Result<(), Error> {
|
||||||
// update scores
|
// update scores
|
||||||
let winner = game.winner().ok_or(err_msg("game not finished"))?;
|
let winner = game.winner().ok_or(err_msg("game not finished"))?;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user