summaryrefslogtreecommitdiff
path: root/resources/js/game.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/js/game.js')
-rw-r--r--resources/js/game.js90
1 files changed, 57 insertions, 33 deletions
diff --git a/resources/js/game.js b/resources/js/game.js
index 1f1f92b..140f9d5 100644
--- a/resources/js/game.js
+++ b/resources/js/game.js
@@ -9,9 +9,12 @@ const Game = {
},
didTechniqueHit: false,
+ turn: 0,
async progressTurn () {
+ Game.turn++;
+
await Game.applyStatusEffect(state.enemy.monster);
await Game.applyStatusEffect(state.activeMonster);
@@ -28,11 +31,30 @@ const Game = {
}
Game.phases.postAction = [];
+ // enemy defeated
+ if (state.enemy.monster.hp <= 0) {
+ // money
+ state.money += state.enemy.monster.level * state.enemy.monster.moneyModifier;
+
+ // exp
+ state.activeMonster.exp += calculateAwardedExperience(state.enemy.monster, [state.activeMonster])[0];
+
+ if (state.activeMonster.canLevelUp()) {
+ state.activeMonster.levelUp();
+ }
+ if (state.activeMonster.canEvolve()) {
+ await fetchMonster(state.activeMonster.evolutions[0].monster_slug);
+ state.activeMonster.evolve();
+ }
+
+ await Game.spawnEnemyMonster();
+ }
+
UI.drawEnemyMonster();
UI.drawActiveMonster();
UI.drawActiveTechniques();
- UI.elements.money.textContent = state.money;
+ UI.elements.money.textContent = `${state.money} €`;
},
/**
@@ -41,15 +63,13 @@ const Game = {
* @param {Monster} target
*/
async useTechnique (technique, user, target) {
+ technique.use();
+
if (!Game.didTechniqueHit) {
UI.drawDamageMiss(UI.createDamageMiss());
return;
}
- if (state.activeMonster.hp === state.activeMonster.stats.hp) {
- state.activeMonster.hp = 1;
- }
-
for (const techniqueEffect of technique.effects) {
// damage
@@ -62,15 +82,24 @@ const Game = {
UI.applyMultiplierToDamage(damageNode, simpleDamageMultiplier(state.activeTechnique.types, state.enemy.monster.types));
UI.applyTechniqueToDamage(damageNode, state.activeTechnique);
UI.drawDamage(damageNode);
+ UI.drawTechniqueAnimation();
});
}
else if (techniqueEffect === 'money') {
- state.money += Math.floor(Math.random() * target.level);
+ Game.phases.action.push(() => {
+ const money = Math.max(1, Math.floor(Math.random() * target.level));
+ state.money += money;
+
+ const damageNode = UI.createDamage(`${money} €`);
+ UI.applyTechniqueToDamage(damageNode, state.activeTechnique);
+ UI.drawDamage(damageNode);
+ UI.drawTechniqueAnimation();
+ });
}
else if (techniqueEffect === 'enhance') {
- UI.drawDamage(UI.createDamage('!!ENHANCE!!'));
+ UI.drawTechniqueAnimation();
}
// status effect
@@ -81,7 +110,10 @@ const Game = {
const statusEffect_effect = techniqueEffect.split(',')[0].split(' ')[1].split('_')[1];
const statusEffect = await fetchStatusEffect(statusEffect_effect);
- statusEffect.issuer = user;
+
+ if (statusEffect.slug === 'lifeleech') {
+ statusEffect.issuer = user;
+ }
let recipient;
if (statusEffect_recipient === 'user') {
@@ -108,6 +140,11 @@ const Game = {
}
},
+ rechargeTechnique () {
+ const feedbackNode = UI.createActionFeedback('recharge');
+ UI.drawActionFeedback(feedbackNode);
+ },
+
/**
* @param {Monster} monster
*/
@@ -165,9 +202,9 @@ const Game = {
Game.phases.postAction.push(() => {
monster.hp += statusEffectHeal;
- const damageNode = UI.createDamage(statusEffectHeal);
- UI.applyStatusEffectToDamage(damageNode, monster.statusEffect);
- UI.drawDamage(damageNode);
+ const feedbackNode = UI.createActionFeedback(statusEffectHeal);
+ UI.applyStatusEffectToDamage(feedbackNode, monster.statusEffect);
+ UI.drawActionFeedback(feedbackNode);
});
}
@@ -255,28 +292,11 @@ const Game = {
const accuracy = Math.random();
Game.didTechniqueHit = state.activeTechnique.accuracy >= accuracy;
- await Game.useTechnique(state.activeTechnique, state.activeMonster, state.enemy.monster);
-
- Game.phases.postAction.push(async () => {
- // enemy defeated
- if (state.enemy.monster.hp <= 0) {
- // money
- state.money += state.enemy.monster.level * state.enemy.monster.moneyModifier;
-
- // exp
- state.activeMonster.exp += calculateAwardedExperience(state.enemy.monster, [state.activeMonster])[0];
-
- if (state.activeMonster.canLevelUp()) {
- state.activeMonster.levelUp();
- }
- if (state.activeMonster.canEvolve()) {
- await fetchMonster(state.activeMonster.evolutions[0].monster_slug);
- state.activeMonster.evolve();
- }
-
- await Game.spawnEnemyMonster();
- }
- });
+ if (state.activeTechnique.isUsable()) {
+ await Game.useTechnique(state.activeTechnique, state.activeMonster, state.enemy.monster);
+ } else {
+ Game.rechargeTechnique();
+ }
Game.progressTurn();
},
@@ -327,6 +347,10 @@ const Game = {
monsterData.level = monsterState.level;
monsterData.hp = monsterState.hp;
+ if (monsterData.statusEffect && monsterData.statusEffect.slug === 'lifeleech') {
+ monsterData.statusEffect = null;
+ }
+
return monsterData;
};