concede game round
This commit is contained in:
@@ -349,6 +349,18 @@ impl Game {
|
||||
return Ok(self);
|
||||
}
|
||||
|
||||
fn concede(mut self, player_id: Uuid) -> Result<Game, Error> {
|
||||
if self.phase != Phase::Skill {
|
||||
return Err(err_msg("game not in skill phase"));
|
||||
}
|
||||
|
||||
self.player_by_id(player_id)?
|
||||
.forfeit();
|
||||
|
||||
return Ok(self.finish());
|
||||
}
|
||||
|
||||
|
||||
fn clear_skill(&mut self, player_id: Uuid) -> Result<&mut Game, Error> {
|
||||
self.player_by_id(player_id)?;
|
||||
if self.phase != Phase::Skill {
|
||||
@@ -940,6 +952,16 @@ pub fn game_offer_draw(tx: &mut Transaction, account: &Account, game_id: Uuid) -
|
||||
Ok(game)
|
||||
}
|
||||
|
||||
pub fn game_concede(tx: &mut Transaction, account: &Account, game_id: Uuid) -> Result<Game, Error> {
|
||||
let game = game_get(tx, game_id)?
|
||||
.concede(account.id)?;
|
||||
|
||||
game_update(tx, &game)?;
|
||||
|
||||
Ok(game)
|
||||
}
|
||||
|
||||
|
||||
pub fn game_skill_clear(tx: &mut Transaction, account: &Account, game_id: Uuid) -> Result<Game, Error> {
|
||||
let mut game = game_get(tx, game_id)?;
|
||||
|
||||
|
||||
+5
-1
@@ -22,7 +22,7 @@ use account::{Account};
|
||||
use account;
|
||||
use construct::{Construct};
|
||||
use events::{Event};
|
||||
use game::{Game, game_state, game_skill, game_skill_clear, game_ready, game_offer_draw};
|
||||
use game::{Game, game_state, game_skill, game_skill_clear, game_ready, game_offer_draw, game_concede};
|
||||
use instance::{Instance, ChatState, instance_state, instance_practice, instance_ready, instance_abandon, demo};
|
||||
use item::{Item, ItemInfoCtr, item_info};
|
||||
use mtx;
|
||||
@@ -92,6 +92,7 @@ pub enum RpcRequest {
|
||||
GameSkill { game_id: Uuid, construct_id: Uuid, target_construct_id: Uuid, skill: Skill },
|
||||
GameSkillClear { game_id: Uuid },
|
||||
GameOfferDraw { game_id: Uuid },
|
||||
GameConcede { game_id: Uuid },
|
||||
|
||||
AccountState {},
|
||||
AccountShop {},
|
||||
@@ -227,6 +228,9 @@ impl Connection {
|
||||
RpcRequest::GameReady { id } =>
|
||||
Ok(RpcMessage::GameState(game_ready(&mut tx, account, id)?)),
|
||||
|
||||
RpcRequest::GameConcede { game_id } =>
|
||||
Ok(RpcMessage::GameState(game_concede(&mut tx, account, game_id)?)),
|
||||
|
||||
RpcRequest::GameOfferDraw { game_id } =>
|
||||
Ok(RpcMessage::GameState(game_offer_draw(&mut tx, account, game_id)?)),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user