wip
This commit is contained in:
parent
e1acdc6fa7
commit
16c838db8b
@ -31,35 +31,14 @@ function registerEvents(registry, events) {
|
||||
registry.set('gameList', gameList);
|
||||
}
|
||||
|
||||
events.on('SET_ACTIVE_SKILL', function skillActive(skill) {
|
||||
const activeSkill = registry.get('activeSkill');
|
||||
if (activeSkill) {
|
||||
activeSkill.clearTint();
|
||||
} skill.setTint(0x00ff00);
|
||||
return setActiveSkill(skill);
|
||||
events.on('SEND_SKILL', function skillActive(gameId, crypId, targetTeamId, skill) {
|
||||
const ws = registry.get('ws');
|
||||
ws.sendGameSkill(gameId, crypId, targetTeamId, skill);
|
||||
});
|
||||
|
||||
events.on('SEND_ACTIVE_SKILL', function skillActive(cryp) {
|
||||
const activeSkill = registry.get('activeSkill');
|
||||
const game = registry.get('game');
|
||||
events.on('SEND_TARGET', function skillActive(gameId, crypId, skillId) {
|
||||
const ws = registry.get('ws');
|
||||
if (activeSkill) {
|
||||
// const friendlyTarget = activeSkill.cryp.account === cryp.account;
|
||||
// if (!friendlyTarget) {
|
||||
if (game.phase === 'Skill') {
|
||||
console.log(cryp.account);
|
||||
ws.sendGameSkill(game.id, activeSkill.cryp.id, cryp.account, activeSkill.skill.skill);
|
||||
} else if (game.phase === 'Target') {
|
||||
ws.sendGameTarget(game.id, cryp.id, activeSkill.skill.id);
|
||||
}
|
||||
activeSkill.setTint(0xff0000);
|
||||
registry.set('activeSkill', null);
|
||||
// } else if (friendlyTarget && activeSkill.skill.self_targeting) {
|
||||
// ws.sendGameSkill(game.id, activeSkill.cryp.id, null, activeSkill.skill.skill);
|
||||
// } else {
|
||||
// activeSkill.clearTint();
|
||||
// }
|
||||
}
|
||||
ws.sendGameTarget(gameId, crypId, skillId);
|
||||
});
|
||||
|
||||
events.on('CRYP_ACTIVE', function crypActiveCb(cryp) {
|
||||
|
||||
@ -30,7 +30,7 @@ class Combat extends Phaser.Scene {
|
||||
create() {
|
||||
this.registry.events.off('changedata', this.updateData);
|
||||
this.registry.events.on('changedata', this.updateData, this);
|
||||
this.input.keyboard.on('keydown_S', () => {
|
||||
this.input.keyboard.on('keydown_BACKSPACE', () => {
|
||||
this.endGame();
|
||||
}, 0, this);
|
||||
this.registry.set('gamePhase', false);
|
||||
@ -61,7 +61,8 @@ class Combat extends Phaser.Scene {
|
||||
this.registry.set('game', null);
|
||||
this.scene.get('CombatLog').cleanUp();
|
||||
this.scene.get('CombatCryps').cleanUp();
|
||||
this.scene.get('CombatSkills').cleanUp();
|
||||
|
||||
// this.scene.manager.remove('CombatSkills');
|
||||
this.scene.remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ const { TEXT, POSITIONS: { COMBAT } } = require('./constants');
|
||||
|
||||
const CRYP_KEY_MAP = ['keydown_ONE', 'keydown_TWO', 'keydown_THREE'];
|
||||
const SKILL_KEY_MAP = ['keydown_Q', 'keydown_W', 'keydown_E', 'keydown_R'];
|
||||
const TARGET_KEY_MAP = ['keydown_SEVEN', 'keydown_EIGHT', 'keydown_NINE', 'keydown_ZERO'];
|
||||
|
||||
const calcMargin = () => {
|
||||
const CRYP_MARGIN = COMBAT.height() / 5;
|
||||
@ -36,12 +37,28 @@ class CrypSkill extends Phaser.GameObjects.Text {
|
||||
this.cryp = cryp;
|
||||
this.skill = skill;
|
||||
this.scene = scene;
|
||||
|
||||
this.activeSkill = null;
|
||||
this.activeTarget = null;
|
||||
|
||||
this.setInteractive();
|
||||
}
|
||||
|
||||
clickHandler() {
|
||||
this.scene.game.events.emit('SET_ACTIVE_SKILL', this);
|
||||
}
|
||||
|
||||
select() {
|
||||
this.setTint(0x00ff00);
|
||||
}
|
||||
|
||||
activate() {
|
||||
this.setTint(0xff0000);
|
||||
}
|
||||
|
||||
deselect() {
|
||||
this.clearTint();
|
||||
}
|
||||
}
|
||||
|
||||
class CombatSkills extends Phaser.Scene {
|
||||
@ -52,36 +69,44 @@ class CombatSkills extends Phaser.Scene {
|
||||
create() {
|
||||
this.registry.events.on('changedata', this.updateData, this);
|
||||
this.account = this.registry.get('account');
|
||||
|
||||
// can't set this.game cause of phaser class named the same
|
||||
const game = this.registry.get('game');
|
||||
this.phase = game.phase;
|
||||
this.renderSkills(game);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
updateData(parent, key, data) {
|
||||
if (key === 'game' && data) {
|
||||
this.renderSkills(data);
|
||||
const shouldUpdate = data.phase !== this.phase;
|
||||
if (shouldUpdate) return this.scene.restart();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
renderSkills(game) {
|
||||
const shouldUpdate = game.phase !== this.phase;
|
||||
|
||||
if (!shouldUpdate) return false;
|
||||
|
||||
this.phase = game.phase;
|
||||
if (game.phase === 'Skill') return this.renderSkillPhase(game);
|
||||
if (game.phase === 'Target') return this.renderTargetPhase(game);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
renderSkillPhase(game) {
|
||||
const { account, scene } = this;
|
||||
const { keyboard } = this.input;
|
||||
|
||||
const addSkill = (i, j, skill, cryp) => {
|
||||
const skillTextPos = skillTextPosition(i, j + 2);
|
||||
const skillObj = new CrypSkill(this, skillTextPos[0], skillTextPos[1], skill, cryp);
|
||||
this.add.existing(skillObj);
|
||||
return skillObj;
|
||||
};
|
||||
|
||||
const team = game.teams.find(t => t.id === account.id);
|
||||
const enemyTeam = game.teams.find(t => t.id !== account.id);
|
||||
|
||||
team.cryps.forEach((cryp, i) => {
|
||||
const namePos = skillTextPosition(i, 0);
|
||||
@ -93,7 +118,17 @@ class CombatSkills extends Phaser.Scene {
|
||||
if (cryp.hp.base === 0) return true;
|
||||
|
||||
// draw the skills
|
||||
cryp.skills.forEach((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],
|
||||
() => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id),
|
||||
this
|
||||
);
|
||||
|
||||
keyboard.on('keydown_ESC',
|
||||
() => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id),
|
||||
this
|
||||
);
|
||||
|
||||
return true;
|
||||
});
|
||||
@ -101,13 +136,60 @@ class CombatSkills extends Phaser.Scene {
|
||||
return true;
|
||||
}
|
||||
|
||||
renderBlockPhase(game) {
|
||||
const { account, scene } = this;
|
||||
mapSkillKeys(skillButtons, gameId, crypId, alliesId, enemyId) {
|
||||
const { keyboard } = this.input;
|
||||
SKILL_KEY_MAP.forEach(k => keyboard.removeListener(k));
|
||||
|
||||
const skills = game.stack.find(skill => skill.target_team_id === account.id);
|
||||
// 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();
|
||||
|
||||
// clear existing keys
|
||||
CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k));
|
||||
TARGET_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;
|
||||
}));
|
||||
|
||||
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;
|
||||
}));
|
||||
|
||||
keyboard.on('keydown_ESC',
|
||||
() => {
|
||||
CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k));
|
||||
TARGET_KEY_MAP.forEach(k => keyboard.removeListener(k));
|
||||
},
|
||||
this
|
||||
);
|
||||
|
||||
}, this);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
renderTargetPhase(game) {
|
||||
const { account, scene } = this;
|
||||
const { keyboard } = this.input;
|
||||
|
||||
const skills = game.stack.filter(skill => skill.target_team_id === account.id);
|
||||
const friendlyCryps = game.teams.find(t => t.id === account.id).cryps;
|
||||
|
||||
skills.forEach((skill, i) => {
|
||||
const cryp = game.teams.find(t => t.cryps.find(c => c.id === skill.source_cryp_id));
|
||||
const crypTeam = game.teams.find(t => t.cryps.find(c => c.id === skill.source_cryp_id));
|
||||
const cryp = crypTeam.cryps.find(c => c.id === skill.source_cryp_id);
|
||||
|
||||
// Draw the cryp name
|
||||
const namePos = skillTextPosition(i, 0);
|
||||
@ -116,28 +198,50 @@ class CombatSkills extends Phaser.Scene {
|
||||
const skillPos = skillTextPosition(i, 2);
|
||||
const skillObj = new CrypSkill(this, skillPos[0], skillPos[1], skill, cryp);
|
||||
this.add.existing(skillObj);
|
||||
|
||||
keyboard.on(
|
||||
TARGET_KEY_MAP[i],
|
||||
() => this.mapTargetKeys(skillObj, game.id, friendlyCryps, i),
|
||||
this
|
||||
);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
crypKeyHandler(cryp, i) {
|
||||
if (CRYP_KEY_MAP[i]) {
|
||||
this.input.keyboard.removeListener(CRYP_KEY_MAP[i]);
|
||||
if (cryp.skills.length > 0) { // check there are cryp skills
|
||||
this.input.keyboard.on(CRYP_KEY_MAP[i], () => {
|
||||
SKILL_KEY_MAP.forEach(k => this.input.keyboard.removeListener(k));
|
||||
cryp.skills.forEach((skill, i) => {
|
||||
this.input.keyboard.on(SKILL_KEY_MAP[i], () => {
|
||||
this.game.events.emit('SET_ACTIVE_SKILL', skill);
|
||||
skill.setActive();
|
||||
}, this);
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
mapTargetKeys(button, gameId, friendlyCryps) {
|
||||
const { keyboard } = this.input;
|
||||
|
||||
CRYP_KEY_MAP.forEach(tKey => this.input.keyboard.removeListener(tKey));
|
||||
|
||||
// deselect any currently active button
|
||||
if (this.activeTarget) {
|
||||
this.activeTarget.deselect();
|
||||
}
|
||||
|
||||
button.select();
|
||||
this.activeTarget = button;
|
||||
|
||||
friendlyCryps.forEach((cryp, j) => {
|
||||
keyboard.on(
|
||||
CRYP_KEY_MAP[j],
|
||||
() => {
|
||||
this.game.events.emit('SEND_TARGET', gameId, cryp.id, button.skill.id);
|
||||
button.activate();
|
||||
this.activeTarget = null;
|
||||
},
|
||||
this
|
||||
);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
clearKeys() {
|
||||
TARGET_KEY_MAP.forEach(tKey => this.input.keyboard.removeListener(tKey));
|
||||
CRYP_KEY_MAP.forEach(tKey => this.input.keyboard.removeListener(tKey));
|
||||
SKILL_KEY_MAP.forEach(tKey => this.input.keyboard.removeListener(tKey));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CombatSkills;
|
||||
|
||||
@ -185,9 +185,9 @@ function createSocket(events) {
|
||||
});
|
||||
|
||||
if (!account) events.loginPrompt();
|
||||
// if (process.env.NODE_ENV !== 'production') {
|
||||
// send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
|
||||
// }
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -218,7 +218,9 @@ impl Cryp {
|
||||
}
|
||||
|
||||
pub fn available_skills(&self) -> Vec<&CrypSkill> {
|
||||
self.skills.iter().filter(|s| !self.disabled(s.skill).disabled).collect()
|
||||
self.skills.iter()
|
||||
.filter(|s| s.skill.cd().is_none())
|
||||
.filter(|s| !self.disabled(s.skill).disabled).collect()
|
||||
}
|
||||
|
||||
pub fn knows(&self, skill: Skill) -> bool {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user