qds bullshit
This commit is contained in:
parent
797cdf47e2
commit
c226e8b933
@ -1,6 +1,10 @@
|
||||
const Phaser = require('phaser');
|
||||
|
||||
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 calcMargin = () => {
|
||||
const CRYP_MARGIN = COMBAT.height() / 5;
|
||||
const TEXT_MARGIN = COMBAT.height() / 35;
|
||||
@ -17,10 +21,15 @@ const skillTextPosition = (crypIter, skillIter) => {
|
||||
return [skillTextX, skillTextY];
|
||||
};
|
||||
|
||||
class CrypName extends Phaser.GameObjects.Text {
|
||||
constructor(scene, x, y, cryp) {
|
||||
super(scene, x, y, cryp.name, TEXT.HEADER);
|
||||
}
|
||||
}
|
||||
|
||||
class CrypSkill extends Phaser.GameObjects.Text {
|
||||
constructor(scene, x, y, skill, cryp) {
|
||||
// Avatar will be a property of cryp
|
||||
if (skill) {
|
||||
const CD_TEXT = skill.cd ? `(${skill.cd}T)` : '';
|
||||
const SKILL_TEXT = `${skill.skill} ${CD_TEXT}`;
|
||||
super(scene, x, y, SKILL_TEXT, TEXT.NORMAL);
|
||||
@ -28,9 +37,6 @@ class CrypSkill extends Phaser.GameObjects.Text {
|
||||
this.skill = skill;
|
||||
this.scene = scene;
|
||||
this.setInteractive();
|
||||
} else {
|
||||
super(scene, x, y, cryp.name, TEXT.HEADER);
|
||||
}
|
||||
}
|
||||
|
||||
clickHandler() {
|
||||
@ -43,81 +49,80 @@ class CombatSkills extends Phaser.Scene {
|
||||
super({ key: 'CombatSkills' });
|
||||
}
|
||||
|
||||
create(game) {
|
||||
create() {
|
||||
this.registry.events.on('changedata', this.updateData, this);
|
||||
this.input.on('pointerup', (pointer, obj) => {
|
||||
if (obj[0] instanceof CrypSkill) {
|
||||
obj[0].clickHandler();
|
||||
}
|
||||
});
|
||||
this.skills = this.add.group();
|
||||
this.account = this.registry.get('account');
|
||||
// this.drawSkills(game);
|
||||
return true;
|
||||
}
|
||||
|
||||
updateData(parent, key, data) {
|
||||
if (key === 'game') {
|
||||
if (!data) return false;
|
||||
const isAnimating = this.registry.get('gameAnimating');
|
||||
if (isAnimating) return false;
|
||||
// this.drawSkills(data);
|
||||
if (key === 'game' && data) {
|
||||
this.renderSkills(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
drawSkills(game) {
|
||||
// const addKeys = (game.phase === 'Skill' && !team) || (game.phase === 'Target' && team);
|
||||
const renderSkills = (scene, cryp, iter) => {
|
||||
const skillList = [];
|
||||
// If the cryps have been spawned already put the skills in a corresponding pos
|
||||
const namePos = skillTextPosition(iter, 0);
|
||||
const addSkill = (skill, i) => {
|
||||
// Draw skill group name as part of the "skill class" so we can destroy it later
|
||||
if (i === 0) this.skills.add(this.add.existing(new CrypSkill(scene, namePos[0], namePos[1], false, cryp)));
|
||||
const skillTextPos = skillTextPosition(iter, i + 2);
|
||||
renderSkills(game) {
|
||||
const shouldUpdate = game.phase !== this.phase;
|
||||
|
||||
if (!shouldUpdate) return false;
|
||||
|
||||
if (game.phase === 'Skill') return this.renderSkillPhase(game);
|
||||
if (game.phase === 'Target') return this.renderTargetPhase(game);
|
||||
|
||||
return this.scene.sleep();
|
||||
}
|
||||
|
||||
renderSkillPhase(game) {
|
||||
const { account, scene } = this;
|
||||
|
||||
const addSkill = (i, j, skill, cryp) => {
|
||||
const skillTextPos = skillTextPosition(i, j + 2);
|
||||
const skillObj = new CrypSkill(scene, skillTextPos[0], skillTextPos[1], skill, cryp);
|
||||
group.add(scene.add.existing(skillObj));
|
||||
skillList.push(skillObj);
|
||||
this.add(skillObj);
|
||||
};
|
||||
if (game.phase === 'Skill' && cryp.account === scene.account.id) {
|
||||
|
||||
const team = game.teams.find(t => t.id === account.id);
|
||||
|
||||
team.cryps.forEach((cryp, i) => {
|
||||
const namePos = skillTextPosition(i, 0);
|
||||
|
||||
// Draw the cryp name
|
||||
this.add(new CrypName(scene, namePos[0], namePos[1], cryp));
|
||||
|
||||
// return early if KOd
|
||||
if (cryp.hp.base === 0) return true;
|
||||
cryp.skills.forEach(addSkill);
|
||||
} else if (game.phase === 'Target' && cryp.account !== scene.account.id) {
|
||||
const blockSkill = game.stack.find(skill => skill.source_cryp_id === cryp.id);
|
||||
// cryp not casting this turn
|
||||
if (!blockSkill) return false;
|
||||
addSkill(blockSkill, 0);
|
||||
}
|
||||
|
||||
// draw the skills
|
||||
cryp.skills.forEach((skill, j) => addSkill(i, j, skill, cryp));
|
||||
|
||||
return true;
|
||||
};
|
||||
});
|
||||
|
||||
const allyTeam = game.teams.find(t => t.id === this.account.id);
|
||||
// in future there will be more than one
|
||||
const [enemyTeam] = game.teams.filter(t => t.id !== this.account.id);
|
||||
|
||||
allyTeam.cryps.forEach((cryp, i) => renderSkills(cryp, i, 0));
|
||||
if (!enemyTeam) return false;
|
||||
enemyTeam.cryps.forEach((cryp, i) => renderSkills(cryp, i, 1));
|
||||
|
||||
renderSkills(this, this.skills, cryp, game, crypObj.iter);
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
|
||||
cleanUp() {
|
||||
this.registry.events.off('changedata', this.updateData, this);
|
||||
this.scene.remove();
|
||||
renderBlockPhase(game) {
|
||||
const { account, scene } = this;
|
||||
|
||||
const skills = game.stack.find(skill => skill.target_team_id === account.id);
|
||||
|
||||
skills.forEach((skill, i) => {
|
||||
const cryp = game.teams.find(t => t.cryps.find(c => c.id === skill.source_cryp_id));
|
||||
|
||||
// Draw the cryp name
|
||||
const namePos = skillTextPosition(i, 0);
|
||||
this.add(new CrypName(scene, namePos[0], namePos[1], cryp));
|
||||
|
||||
const skillPos = skillTextPosition(i, 2);
|
||||
const skillObj = new CrypSkill(scene, skillPos[0], skillPos[1], skill, cryp);
|
||||
this.add(skillObj);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CombatSkills;
|
||||
|
||||
|
||||
/* clearSkills() {
|
||||
// console.log(this.scene.gameStart);
|
||||
this.children.entries.filter(obj => obj instanceof CrypSkill).forEach(obj => obj.destroy());
|
||||
}
|
||||
*/
|
||||
/* crypKeyHandler(cryp, iter) {
|
||||
crypKeyHandler(cryp, iter) {
|
||||
if (CRYP_KEY_MAP[iter]) {
|
||||
this.input.keyboard.removeListener(CRYP_KEY_MAP[iter]);
|
||||
if (cryp.skills.length > 0) { // check there are cryp skills
|
||||
@ -133,10 +138,7 @@ module.exports = CombatSkills;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
/*// has the phase changed?
|
||||
const phaseChange = (this.registry.get('gamePhase') === game.phase);
|
||||
if (phaseChange) return false;
|
||||
this.registry.set('gamePhase', game.phase);
|
||||
this.combatCryps.update(game);*/
|
||||
module.exports = CombatSkills;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user