From 3accbf5193f302195094cc287357c4fb99ec33d8 Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 5 Dec 2018 20:10:32 +1100 Subject: [PATCH] homg --- client/src/scenes/combat.skills.js | 71 +++++++++++++++--------------- server/src/game.rs | 15 ++++--- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/client/src/scenes/combat.skills.js b/client/src/scenes/combat.skills.js index da4da29d..52cf9593 100644 --- a/client/src/scenes/combat.skills.js +++ b/client/src/scenes/combat.skills.js @@ -97,6 +97,7 @@ class CombatSkills extends Phaser.Scene { renderSkillPhase(game) { const { account, scene } = this; const { keyboard } = this.input; + const { events } = this.game; const addSkill = (i, j, skill, cryp) => { const skillTextPos = skillTextPosition(i, j + 2); @@ -120,15 +121,12 @@ class CombatSkills extends Phaser.Scene { // draw the skills const skillButtons = cryp.skills.map((skill, j) => addSkill(i, j, skill, cryp)); - keyboard.on(CRYP_KEY_MAP[i], - () => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id), - this - ); + const bindCrypKeys = () => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id, i); - keyboard.on('keydown_ESC', - () => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id), - this - ); + // reset everything + keyboard.on('keydown_ESC', bindCrypKeys, this); + events.on('SEND_SKILL', bindCrypKeys, this); + bindCrypKeys(); return true; }); @@ -136,46 +134,47 @@ class CombatSkills extends Phaser.Scene { return true; } - mapSkillKeys(skillButtons, gameId, crypId, alliesId, enemyId) { + mapSkillKeys(skillButtons, gameId, crypId, alliesId, enemyId, i) { const { keyboard } = this.input; - SKILL_KEY_MAP.forEach(k => keyboard.removeListener(k)); // deselect any currently active button if (this.activeSkill) { this.activeSkill.deselect(); } - skillButtons.forEach((button, i) => { - keyboard.on(SKILL_KEY_MAP[i], () => { - this.activeSkill = button; - button.select(); + keyboard.removeListener(CRYP_KEY_MAP[i]); - // clear existing keys - CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k)); - TARGET_KEY_MAP.forEach(k => keyboard.removeListener(k)); + keyboard.on(CRYP_KEY_MAP[i], () => { + SKILL_KEY_MAP.forEach(k => keyboard.removeListener(k)); - CRYP_KEY_MAP.forEach(k => keyboard.on(k, () => { - this.game.events.emit('SEND_SKILL', gameId, crypId, alliesId, button.skill.skill); - button.activate(); - this.activeSkill = null; - })); + // deselect any currently active button + if (this.activeSkill) { + this.activeSkill.deselect(); + } - TARGET_KEY_MAP.forEach(k => keyboard.on(k, () => { - this.game.events.emit('SEND_SKILL', gameId, crypId, enemyId, button.skill.skill); - button.activate(); - this.activeSkill = null; - })); + skillButtons.forEach((button, j) => { + keyboard.on(SKILL_KEY_MAP[j], () => { + this.activeSkill = button; + button.select(); - keyboard.on('keydown_ESC', - () => { - CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k)); - TARGET_KEY_MAP.forEach(k => keyboard.removeListener(k)); - }, - this - ); + // clear existing keys + CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k)); + TARGET_KEY_MAP.forEach(k => keyboard.removeListener(k)); - }, this); - }); + CRYP_KEY_MAP.forEach(k => keyboard.on(k, () => { + button.activate(); + this.activeSkill = null; + this.game.events.emit('SEND_SKILL', gameId, crypId, alliesId, button.skill.skill); + })); + + TARGET_KEY_MAP.forEach(k => keyboard.on(k, () => { + button.activate(); + this.activeSkill = null; + this.game.events.emit('SEND_SKILL', gameId, crypId, enemyId, button.skill.skill); + })); + }, this); + }); + }, this); return true; } diff --git a/server/src/game.rs b/server/src/game.rs index 27c0560d..0003e391 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -35,7 +35,7 @@ impl Team { .filter(|c| !c.is_ko()) .filter(|c| c.available_skills().len() > 0) .collect::>().len(); - println!("{:?} requires {:?} skills this turn", self.id, required); + // println!("{:?} requires {:?} skills this turn", self.id, required); return required; } @@ -349,6 +349,8 @@ impl Game { let active_cryps = active_cryps as u32 as f64; let max_targets = (incoming / active_cryps).ceil(); + println!("targets {:?} / {:?} = {:?}", incoming, active_cryps, max_targets); + let targeted = self.stack.iter() .filter(|s| s.target_cryp_id.is_some()) .filter(|s| s.target_cryp_id.unwrap() == cryp_id) @@ -491,11 +493,14 @@ impl Game { // only reduce cooldowns if no cd was used // have to borrow self for the skill check { - let skill = self.stack.iter_mut().find(|s| s.source_cryp_id == cryp.id).unwrap(); - if skill.used_cooldown() { - cryp.skill_set_cd(skill.skill); + if let Some(skill) = self.stack.iter_mut().find(|s| s.source_cryp_id == cryp.id) { + if skill.used_cooldown() { + cryp.skill_set_cd(skill.skill); + } else { + cryp.reduce_cooldowns(); + } } else { - cryp.reduce_cooldowns(); + cryp.reduce_cooldowns(); } }