clear skills

This commit is contained in:
Mashy
2019-09-09 16:03:33 +10:00
parent 81a02421dd
commit 2cea9fd8fa
5 changed files with 50 additions and 6 deletions
+25
View File
@@ -322,6 +322,17 @@ impl Game {
return Ok(self);
}
fn clear_skill(&mut self, player_id: Uuid) -> Result<&mut Game, Error> {
self.player_by_id(player_id)?;
if self.phase != Phase::Skill {
return Err(err_msg("game not in skill phase"));
}
let mut game_state = self.clone();
self.stack.retain(|s| game_state.construct_by_id(s.source_construct_id).unwrap().account == player_id);
return Ok(self);
}
fn player_ready(&mut self, player_id: Uuid) -> Result<&mut Game, Error> {
if self.phase != Phase::Skill {
return Err(err_msg("game not in skill phase"));
@@ -877,6 +888,20 @@ pub fn game_skill(tx: &mut Transaction, account: &Account, game_id: Uuid, constr
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)?;
game.clear_skill(account.id)?;
if game.skill_phase_finished() {
game = game.resolve_phase_start();
}
game_update(tx, &game)?;
Ok(game)
}
pub fn game_ready(tx: &mut Transaction, account: &Account, id: Uuid) -> Result<Game, Error> {
let mut game = game_get(tx, id)?;
+5 -1
View File
@@ -20,7 +20,7 @@ use account::{Account};
use account;
use construct::{Construct};
use events::{Event};
use game::{Game, game_state, game_skill, game_ready};
use game::{Game, game_state, game_skill, game_skill_clear, game_ready};
use instance::{Instance, instance_state, instance_practice, instance_ready};
use item::{Item, ItemInfoCtr, item_info};
use mtx;
@@ -75,6 +75,7 @@ enum RpcRequest {
GameState { id: Uuid },
GameReady { id: Uuid },
GameSkill { game_id: Uuid, construct_id: Uuid, target_construct_id: Option<Uuid>, skill: Skill },
GameSkillClear { game_id: Uuid },
AccountState {},
AccountShop {},
@@ -169,6 +170,9 @@ impl Connection {
RpcRequest::GameSkill { game_id, construct_id, target_construct_id, skill } =>
Ok(RpcMessage::GameState(game_skill(&mut tx, account, game_id, construct_id, target_construct_id, skill)?)),
RpcRequest::GameSkillClear { game_id } =>
Ok(RpcMessage::GameState(game_skill_clear(&mut tx, account, game_id)?)),
RpcRequest::GameReady { id } =>
Ok(RpcMessage::GameState(game_ready(&mut tx, account, id)?)),