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