concede game round

This commit is contained in:
ntr 2019-11-20 12:39:09 +11:00
parent 40ca99d185
commit 8e6561499a
5 changed files with 58 additions and 4 deletions

View File

@ -4,8 +4,6 @@
*PRODUCTION* *PRODUCTION*
* can't reset password without knowing password =\ * can't reset password without knowing password =\
* ws gzip encoding
* concede round * concede round
* look into ruin event bug * look into ruin event bug
@ -50,7 +48,13 @@
* Graphical status effects instead of text * Graphical status effects instead of text
* theme toasts * theme toasts
* rework vecs into sets * rework vecs into sets
* constructs
* effects
* parent
* children
* remove names so games/instances are copy * remove names so games/instances are copy
* consolidate game and instance * consolidate game and instance

View File

@ -20,12 +20,17 @@ const addState = connect(
return ws.sendGameOfferDraw(game.id); return ws.sendGameOfferDraw(game.id);
} }
function sendConcede() {
return ws.sendGameConcede(game.id);
}
return { return {
game, game,
account, account,
sendAbandon, sendAbandon,
sendDraw, sendDraw,
sendConcede,
animating, animating,
}; };
}, },
@ -49,11 +54,12 @@ function GameCtrlTopBtns(args) {
leave, leave,
sendAbandon, sendAbandon,
sendDraw, sendDraw,
sendConcede,
animating, animating,
} = args; } = args;
const finished = game && game.phase === 'Finished'; const finished = game && game.phase === 'Finished';
const { abandonState, drawState } = this.state; const { abandonState, drawState, concedeState } = this.state;
const player = game.players.find(p => p.id === account.id); const player = game.players.find(p => p.id === account.id);
const drawOffered = player && player.draw_offered; const drawOffered = player && player.draw_offered;
@ -70,6 +76,12 @@ function GameCtrlTopBtns(args) {
setTimeout(() => this.setState({ drawState: false }), 2000); setTimeout(() => this.setState({ drawState: false }), 2000);
}; };
const concedeStateTrue = e => {
e.stopPropagation();
this.setState({ concedeState: true });
setTimeout(() => this.setState({ concedeState: false }), 2000);
};
const abandonClasses = `abandon ${abandonState ? 'confirming' : ''}`; const abandonClasses = `abandon ${abandonState ? 'confirming' : ''}`;
const abandonText = abandonState ? 'Confirm' : 'Abandon'; const abandonText = abandonState ? 'Confirm' : 'Abandon';
const abandonAction = abandonState ? sendAbandon : abandonStateTrue; const abandonAction = abandonState ? sendAbandon : abandonStateTrue;
@ -83,9 +95,15 @@ function GameCtrlTopBtns(args) {
const drawAction = drawState ? sendDraw : drawStateTrue; const drawAction = drawState ? sendDraw : drawStateTrue;
const drawBtn = <button class={drawClasses} disabled={finished || animating || drawOffered} onClick={drawAction}>{drawText}</button>; const drawBtn = <button class={drawClasses} disabled={finished || animating || drawOffered} onClick={drawAction}>{drawText}</button>;
const concedeClasses = `draw ${concedeState ? 'confirming' : ''}`;
const concedeText = concedeState ? 'Round' : 'Concede';
const concedeAction = concedeState ? sendConcede : concedeStateTrue;
const concedeBtn = <button class={concedeClasses} disabled={finished || animating } onClick={concedeAction}>{concedeText}</button>;
return ( return (
<div class="instance-ctrl-btns"> <div class="instance-ctrl-btns">
{abandonBtn} {abandonBtn}
{concedeBtn}
{drawBtn} {drawBtn}
</div> </div>
); );

View File

@ -138,6 +138,11 @@ function createSocket(events) {
events.setActiveSkill(null); events.setActiveSkill(null);
} }
function sendGameConcede(gameId) {
send(['GameConcede', { game_id: gameId }]);
events.setActiveSkill(null);
}
function sendGameTarget(gameId, constructId, skillId) { function sendGameTarget(gameId, constructId, skillId) {
send(['GameTarget', { game_id: gameId, construct_id: constructId, skill_id: skillId }]); send(['GameTarget', { game_id: gameId, construct_id: constructId, skill_id: skillId }]);
events.setActiveSkill(null); events.setActiveSkill(null);
@ -391,6 +396,7 @@ function createSocket(events) {
sendGameSkill, sendGameSkill,
sendGameSkillClear, sendGameSkillClear,
sendGameOfferDraw, sendGameOfferDraw,
sendGameConcede,
sendGameTarget, sendGameTarget,
sendInstanceAbandon, sendInstanceAbandon,

View File

@ -349,6 +349,18 @@ impl Game {
return Ok(self); 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> { fn clear_skill(&mut self, player_id: Uuid) -> Result<&mut Game, Error> {
self.player_by_id(player_id)?; self.player_by_id(player_id)?;
if self.phase != Phase::Skill { if self.phase != Phase::Skill {
@ -940,6 +952,16 @@ pub fn game_offer_draw(tx: &mut Transaction, account: &Account, game_id: Uuid) -
Ok(game) 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> { pub fn game_skill_clear(tx: &mut Transaction, account: &Account, game_id: Uuid) -> Result<Game, Error> {
let mut game = game_get(tx, game_id)?; let mut game = game_get(tx, game_id)?;

View File

@ -22,7 +22,7 @@ use account::{Account};
use account; use account;
use construct::{Construct}; use construct::{Construct};
use events::{Event}; 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 instance::{Instance, ChatState, instance_state, instance_practice, instance_ready, instance_abandon, demo};
use item::{Item, ItemInfoCtr, item_info}; use item::{Item, ItemInfoCtr, item_info};
use mtx; use mtx;
@ -92,6 +92,7 @@ pub enum RpcRequest {
GameSkill { game_id: Uuid, construct_id: Uuid, target_construct_id: Uuid, skill: Skill }, GameSkill { game_id: Uuid, construct_id: Uuid, target_construct_id: Uuid, skill: Skill },
GameSkillClear { game_id: Uuid }, GameSkillClear { game_id: Uuid },
GameOfferDraw { game_id: Uuid }, GameOfferDraw { game_id: Uuid },
GameConcede { game_id: Uuid },
AccountState {}, AccountState {},
AccountShop {}, AccountShop {},
@ -227,6 +228,9 @@ impl Connection {
RpcRequest::GameReady { id } => RpcRequest::GameReady { id } =>
Ok(RpcMessage::GameState(game_ready(&mut tx, account, 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 } => RpcRequest::GameOfferDraw { game_id } =>
Ok(RpcMessage::GameState(game_offer_draw(&mut tx, account, game_id)?)), Ok(RpcMessage::GameState(game_offer_draw(&mut tx, account, game_id)?)),