This commit is contained in:
ntr 2018-12-05 20:10:32 +11:00
parent 50e2c7b931
commit 3accbf5193
2 changed files with 45 additions and 41 deletions

View File

@ -97,6 +97,7 @@ class CombatSkills extends Phaser.Scene {
renderSkillPhase(game) { renderSkillPhase(game) {
const { account, scene } = this; const { account, scene } = this;
const { keyboard } = this.input; const { keyboard } = this.input;
const { events } = this.game;
const addSkill = (i, j, skill, cryp) => { const addSkill = (i, j, skill, cryp) => {
const skillTextPos = skillTextPosition(i, j + 2); const skillTextPos = skillTextPosition(i, j + 2);
@ -120,15 +121,12 @@ class CombatSkills extends Phaser.Scene {
// draw the skills // draw the skills
const skillButtons = cryp.skills.map((skill, j) => addSkill(i, j, skill, cryp)); const skillButtons = cryp.skills.map((skill, j) => addSkill(i, j, skill, cryp));
keyboard.on(CRYP_KEY_MAP[i], const bindCrypKeys = () => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id, i);
() => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id),
this
);
keyboard.on('keydown_ESC', // reset everything
() => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id), keyboard.on('keydown_ESC', bindCrypKeys, this);
this events.on('SEND_SKILL', bindCrypKeys, this);
); bindCrypKeys();
return true; return true;
}); });
@ -136,46 +134,47 @@ class CombatSkills extends Phaser.Scene {
return true; return true;
} }
mapSkillKeys(skillButtons, gameId, crypId, alliesId, enemyId) { mapSkillKeys(skillButtons, gameId, crypId, alliesId, enemyId, i) {
const { keyboard } = this.input; const { keyboard } = this.input;
SKILL_KEY_MAP.forEach(k => keyboard.removeListener(k));
// deselect any currently active button // deselect any currently active button
if (this.activeSkill) { if (this.activeSkill) {
this.activeSkill.deselect(); this.activeSkill.deselect();
} }
skillButtons.forEach((button, i) => { keyboard.removeListener(CRYP_KEY_MAP[i]);
keyboard.on(SKILL_KEY_MAP[i], () => {
this.activeSkill = button;
button.select();
// clear existing keys keyboard.on(CRYP_KEY_MAP[i], () => {
CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k)); SKILL_KEY_MAP.forEach(k => keyboard.removeListener(k));
TARGET_KEY_MAP.forEach(k => keyboard.removeListener(k));
CRYP_KEY_MAP.forEach(k => keyboard.on(k, () => { // deselect any currently active button
this.game.events.emit('SEND_SKILL', gameId, crypId, alliesId, button.skill.skill); if (this.activeSkill) {
button.activate(); this.activeSkill.deselect();
this.activeSkill = null; }
}));
TARGET_KEY_MAP.forEach(k => keyboard.on(k, () => { skillButtons.forEach((button, j) => {
this.game.events.emit('SEND_SKILL', gameId, crypId, enemyId, button.skill.skill); keyboard.on(SKILL_KEY_MAP[j], () => {
button.activate(); this.activeSkill = button;
this.activeSkill = null; button.select();
}));
keyboard.on('keydown_ESC', // clear existing keys
() => { CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k));
CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k)); TARGET_KEY_MAP.forEach(k => keyboard.removeListener(k));
TARGET_KEY_MAP.forEach(k => keyboard.removeListener(k));
},
this
);
}, 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; return true;
} }

View File

@ -35,7 +35,7 @@ impl Team {
.filter(|c| !c.is_ko()) .filter(|c| !c.is_ko())
.filter(|c| c.available_skills().len() > 0) .filter(|c| c.available_skills().len() > 0)
.collect::<Vec<&Cryp>>().len(); .collect::<Vec<&Cryp>>().len();
println!("{:?} requires {:?} skills this turn", self.id, required); // println!("{:?} requires {:?} skills this turn", self.id, required);
return required; return required;
} }
@ -349,6 +349,8 @@ impl Game {
let active_cryps = active_cryps as u32 as f64; let active_cryps = active_cryps as u32 as f64;
let max_targets = (incoming / active_cryps).ceil(); let max_targets = (incoming / active_cryps).ceil();
println!("targets {:?} / {:?} = {:?}", incoming, active_cryps, max_targets);
let targeted = self.stack.iter() let targeted = self.stack.iter()
.filter(|s| s.target_cryp_id.is_some()) .filter(|s| s.target_cryp_id.is_some())
.filter(|s| s.target_cryp_id.unwrap() == cryp_id) .filter(|s| s.target_cryp_id.unwrap() == cryp_id)
@ -491,11 +493,14 @@ impl Game {
// only reduce cooldowns if no cd was used // only reduce cooldowns if no cd was used
// have to borrow self for the skill check // have to borrow self for the skill check
{ {
let skill = self.stack.iter_mut().find(|s| s.source_cryp_id == cryp.id).unwrap(); if let Some(skill) = self.stack.iter_mut().find(|s| s.source_cryp_id == cryp.id) {
if skill.used_cooldown() { if skill.used_cooldown() {
cryp.skill_set_cd(skill.skill); cryp.skill_set_cd(skill.skill);
} else {
cryp.reduce_cooldowns();
}
} else { } else {
cryp.reduce_cooldowns(); cryp.reduce_cooldowns();
} }
} }