From 54e5ffaeb79f989463c144e58dfcd677b752c5a9 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 21 Aug 2023 22:44:21 +0200 Subject: log actions --- resources/js/game.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) (limited to 'resources/js/game.js') diff --git a/resources/js/game.js b/resources/js/game.js index fad882b..d5e8669 100644 --- a/resources/js/game.js +++ b/resources/js/game.js @@ -14,6 +14,8 @@ const Game = { }, }, + logMessages: [], + isLoadingArea: false, isProgressingTurn: false, playerIsChoosingNextMonster: false, @@ -32,6 +34,8 @@ const Game = { await Game.applyStatusEffect(Memory.state.opponent.activeMonster); await Game.applyStatusEffect(Memory.state.player.activeMonster); + Game.logTurn('begin'); + // Phases for (const phaseKey of Object.keys(Game.phases)) { for (const event of Game.phases[phaseKey].player) { @@ -53,6 +57,8 @@ const Game = { Game.phases[phaseKey].opponent = []; } + Game.logTurn('end'); + UI.progressTurn(); Game.isProgressingTurn = false; }, @@ -186,6 +192,14 @@ const Game = { async tryUseTechnique (technique, user, target) { let canUse = true; + const log = (message, indentation) => { + Game.addPhaseEvent(Game.phases.preAction, user, () => { + Game.log(message, indentation); + }); + }; + + log(`${user.name} attempts to use ${technique.name}!`); + // recharge if (technique.isRecharging()) { if (Game.doBattleAnimation) { @@ -194,6 +208,8 @@ const Game = { UI.drawActionFeedback(feedbackNode); } + log('But has to recharge!', 1); + canUse = false; } @@ -204,6 +220,8 @@ const Game = { UI.drawActionFeedback(feedbackNode); } + log('But is nodding off!', 1); + canUse = false; } @@ -216,6 +234,8 @@ const Game = { technique.use(); Game.doBattleAnimation && UI.drawDamageMiss(UI.createDamageMiss()); + log('But missed!', 1); + return; } @@ -231,6 +251,10 @@ const Game = { async useTechnique (technique, user, target) { technique.use(); + Game.addPhaseEvent(Game.phases.action, user, () => { + Game.log(`${user.name} is using ${technique.name}!`); + }); + for (const techniqueEffectCode of technique.effects) { const techniqueEffect = new TechniqueEffect(techniqueEffectCode); techniqueEffect.setUser(user); @@ -250,6 +274,8 @@ const Game = { UI.drawDamage(damageNode); UI.drawTechniqueAnimation(technique); } + + Game.log(`Deals ${damage} to ${target.name}!`, 1); }); } @@ -271,7 +297,12 @@ const Game = { // healing else if (techniqueEffect.type === 'healing') { for (const recipient of techniqueEffect.recipients) { - recipient.hp += (user.level + 7) * technique.healingPower; + Game.addPhaseEvent(Game.phases.action, user, () => { + const heal = (user.level + 7) * technique.healingPower; + recipient.hp += heal; + + Game.log(`Heals ${heal}!`, 1); + }); } } @@ -293,7 +324,7 @@ const Game = { statusEffect.issuer = user; } - Game.addPhaseEvent(Game.phases.postAction, user, () => { + Game.addPhaseEvent(Game.phases.action, user, () => { // add status effect const potency = Math.random(); const success = technique.potency >= potency; @@ -304,6 +335,8 @@ const Game = { if (recipient.statusEffect) continue; recipient.statusEffect = statusEffect; + + Game.log(`${techniqueEffect.recipients.map((recipient) => recipient.name).join(', ')} ${techniqueEffect.recipients.length > 1 ? 'are' : 'is'} now ${statusEffect.name}!`, 1); } } }); @@ -327,6 +360,8 @@ const Game = { // if still 0 turns left after remove action if (monster.statusEffect.turnsLeft === 0) { + Game.log(`${monster.name} is not ${monster.statusEffect.name} anymore!`); + monster.statusEffect = null; } else { Game.applyStatusEffect(monster); @@ -336,6 +371,10 @@ const Game = { return; } + const logStatusIs = () => { + Game.log(`${monster.name} is ${monster.statusEffect.name}!`); + } + // poison / burn if (monster.statusEffect.slug === 'poison' || monster.statusEffect.slug === 'burn') { const statusEffectDamage = Math.floor(monster.stats.hp / 8); @@ -348,6 +387,8 @@ const Game = { UI.applyStatusEffectToDamage(damageNode, monster.statusEffect); UI.drawDamage(damageNode); } + + logStatusIs(); }); } @@ -369,6 +410,8 @@ const Game = { UI.applyStatusEffectToDamage(damageNode, monster.statusEffect); UI.drawDamage(damageNode); } + + logStatusIs(); }); } @@ -384,6 +427,8 @@ const Game = { UI.applyStatusEffectToDamage(feedbackNode, monster.statusEffect); UI.drawActionFeedback(feedbackNode); } + + logStatusIs(); }); } @@ -394,6 +439,8 @@ const Game = { Game.addPhaseEvent(Game.phases.preAction, monster, () => { technique.potency = technique.stats.potency * 0.5; technique.power = technique.stats.power * 0.5; + + logStatusIs(); }); monster.statusEffect.onRemove = () => { @@ -410,6 +457,8 @@ const Game = { Game.addPhaseEvent(Game.phases.preAction, monster, () => { technique.potency = technique.stats.potency * 0.5; technique.power = technique.stats.power * 0.5; + + logStatusIs(); }); monster.statusEffect.onRemove = () => { @@ -423,6 +472,10 @@ const Game = { else if (monster.statusEffect.slug === 'charging') { const nextStatusEffect = await fetchStatusEffect('chargedup'); + Game.addPhaseEvent(Game.phases.preAction, monster, () => { + logStatusIs(); + }); + monster.statusEffect.onRemove = () => { monster.statusEffect = nextStatusEffect; }; @@ -438,6 +491,8 @@ const Game = { Game.addPhaseEvent(Game.phases.preAction, monster, () => { monster.setStatModifier(statType, modifiedValue); + + logStatusIs(); }); } @@ -533,6 +588,33 @@ const Game = { })); }, + /** + * @param {string} message + * @param {number} indentation + * @param {string} style + */ + log (message, indentation = 0, style) { + Game.logMessages.push({ + message: message, + indentation: indentation, + style: style, + }); + UI.drawLog(); + }, + + /** + * @param {('begin' | 'end')} + */ + logTurn (state) { + Game.log( + '- '.repeat(8) + `Turn ${Memory.state.turn} · ${slugToName(state)}` + ' -'.repeat(8), + 0, + { + textAlign: 'center', + } + ); + }, + /* Progression */ @@ -718,8 +800,9 @@ const Game = { Memory.state.player.monsters.push(caughtMonster); + Game.log(`Caught ${caughtMonster.name}!`); + await Game.encounterWildMonster(); - await Game.progressTurn(); }, -- cgit v1.2.3