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) {
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;
}

View File

@ -35,7 +35,7 @@ impl Team {
.filter(|c| !c.is_ko())
.filter(|c| c.available_skills().len() > 0)
.collect::<Vec<&Cryp>>().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();
}
}