From 09b6f455d33a062775a0bede2cb03e5a263a6d80 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 30 Oct 2018 20:20:08 +1100 Subject: [PATCH] self targeting client --- client/.eslintrc.js | 10 +++++----- client/src/components/game.container.js | 11 ++++++++--- client/src/components/game.jsx | 7 +++---- server/src/cryp.rs | 1 + server/src/game.rs | 8 ++++++++ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/client/.eslintrc.js b/client/.eslintrc.js index 2970baf5..507d7a3a 100755 --- a/client/.eslintrc.js +++ b/client/.eslintrc.js @@ -616,11 +616,11 @@ module.exports = { avoidQuotes: true, }], - // suggest using arrow functions as callbacks - 'prefer-arrow-callback': ['error', { - allowNamedFunctions: false, - allowUnboundThis: true, - }], + // // suggest using arrow functions as callbacks + // 'prefer-arrow-callback': ['error', { + // allowNamedFunctions: false, + // allowUnboundThis: true, + // }], // suggest using of const declaration for variables that are never modified after declared 'prefer-const': ['error', { diff --git a/client/src/components/game.container.js b/client/src/components/game.container.js index 10009920..8adac3fd 100644 --- a/client/src/components/game.container.js +++ b/client/src/components/game.container.js @@ -10,11 +10,16 @@ const addState = connect( function selectSkillTarget(targetTeamId) { if (activeSkill) { - return ws.sendGameSkill(game.id, activeSkill.crypId, targetTeamId, activeSkill.skill); + return ws.sendGameSkill(game.id, activeSkill.crypId, targetTeamId, activeSkill.skill.skill); } return false; } + // intercept self casting skills + if (activeSkill && activeSkill.skill.self_targeting) { + ws.sendGameSkill(game.id, activeSkill.crypId, null, activeSkill.skill.skill); + } + function selectIncomingTarget(crypId) { if (activeIncoming) { return ws.sendGameTarget(game.id, crypId, activeIncoming); @@ -27,11 +32,11 @@ const addState = connect( function receiveDispatch(dispatch) { function setActiveSkill(crypId, skill) { - dispatch(actions.setActiveSkill(crypId, skill)) + dispatch(actions.setActiveSkill(crypId, skill)); } function setActiveIncoming(skillId) { - dispatch(actions.setActiveIncoming(skillId)) + dispatch(actions.setActiveIncoming(skillId)); } diff --git a/client/src/components/game.jsx b/client/src/components/game.jsx index fc55cb35..71eeea98 100755 --- a/client/src/components/game.jsx +++ b/client/src/components/game.jsx @@ -21,7 +21,7 @@ function GamePanel(props) { const playerTeam = game.teams.find(t => t.id === account.id); - const incoming = game.skills.filter(s => s.target_team_id === playerTeam.id).map((inc) => { + const incoming = game.stack.filter(s => s.target_team_id === playerTeam.id).map((inc) => { key.unbind('1'); key('1', () => setActiveIncoming(inc.id)); return ( @@ -41,14 +41,14 @@ function GamePanel(props) { const skills = cryp.skills.map((skill, i) => { const hotkey = SKILL_HOT_KEYS[i]; key.unbind(hotkey); - key(hotkey, () => setActiveSkill(cryp.id, skill.skill)); + key(hotkey, () => setActiveSkill(cryp.id, skill)); return ( @@ -59,7 +59,6 @@ function GamePanel(props) {
{status} for {status.turns}T
)); - if (activeIncoming) console.log('should be a pointer'); return (
Result<&mut Cast, Error> { + if self.phase != Phase::Target { + return Err(err_msg("game not in target phase")); + } + { // whose team is this? let team = self.team_by_id(team_id); @@ -414,6 +418,10 @@ pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Accou let game_bytes: Vec = returned.get("data"); let mut game = from_slice::(&game_bytes)?; + if game.phase != Phase::Skill { + return Err(err_msg("game not in skill phase")) + } + game.add_skill(account.id, params.cryp_id, params.target_team_id, params.skill)?; if game.skill_phase_finished() {