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.js230
1 files changed, 147 insertions, 83 deletions
diff --git a/resources/js/game.js b/resources/js/game.js
index d31d6e5..fad882b 100644
--- a/resources/js/game.js
+++ b/resources/js/game.js
@@ -22,6 +22,8 @@ const Game = {
isInBattle: false,
didTechniqueHit: false,
+ /* Battle */
+
async progressTurn () {
Game.isProgressingTurn = true;
Memory.state.turn++;
@@ -106,8 +108,37 @@ const Game = {
}
Game.removePhaseEvents('action', 'opponent');
- Game.playerIsChoosingNextMonster = true;
- UI.openPartyMenu();
+ // whole party defeated
+ if (!Memory.state.player.monsters.some((monster) => monster.hp > 0)) {
+ if (Game.isBattleType('trainer')) {
+ if (Memory.state.currentArea.encounters.length > 0) {
+ await Game.encounterWildMonster();
+ } else {
+ await Game.encounterTrainer();
+ }
+ }
+
+ else if (Game.isBattleType('monster')) {
+ if (Memory.state.currentArea.monsterProgress < Memory.state.currentArea.requiredEncounters) {
+ Memory.state.currentArea.monsterProgress = 0;
+ UI.drawStatus();
+ }
+
+ await Game.encounterWildMonster();
+ }
+
+ // heal all monsters full
+ for (const monster of Memory.state.player.monsters) {
+ monster.hp = monster.stats.hp;
+ }
+ }
+
+ // party members still left
+ else {
+ Game.playerIsChoosingNextMonster = true;
+ const monsterSelectionNode = UI.createPlayerDefeatedMonsterSelection();
+ UI.openPlayerDefeatedMonsterSelection(monsterSelectionNode);
+ }
}
},
@@ -325,6 +356,11 @@ const Game = {
const statusEffectLeech = Math.floor(monster.stats.hp / 16);
Game.addPhaseEvent(Game.phases.postAction, monster, () => {
+ // if issuer is defeated => don't
+ if (monster.statusEffect.issuer.hp <= 0) {
+ return;
+ }
+
monster.hp -= statusEffectLeech;
monster.statusEffect.issuer.hp += statusEffectLeech;
@@ -442,6 +478,7 @@ const Game = {
return;
}
+ // technique
Game.doBattleAnimation = false;
await Game.tryUseTechnique(
await fetchTechnique(Memory.state.opponent.activeMonster.getLearnableTechniques()[Math.floor(Math.random() * Memory.state.opponent.activeMonster.getLearnableTechniques().length)].technique),
@@ -452,6 +489,10 @@ const Game = {
await Game.progressTurn();
+ // item
+ if (Memory.state.opponent.inventory.length > 0) {
+ }
+
Game.opponentActionTimeout = null;
}, Math.max(500, 2000 - (speedDifference * 10)));
console.log(
@@ -473,7 +514,7 @@ const Game = {
}
let target = event.target;
- while (!target.classList.contains('techniques__technique')) {
+ while (target.dataset.gameElementType !== 'menuBattleTechniquesTechnique') {
target = target.parentNode;
}
@@ -492,6 +533,81 @@ const Game = {
}));
},
+
+ /* Progression */
+
+ async encounterWildMonster () {
+ const randomMonster = Memory.state.currentArea.encounters[Math.floor(Math.random() * Memory.state.currentArea.encounters.length)];
+ const randomLevel = Math.floor(Math.random() * (randomMonster.level_range[1] - randomMonster.level_range[0]) + randomMonster.level_range[0]);
+
+ const monster = await fetchMonster(randomMonster.monster);
+ monster.level = randomLevel;
+
+ const wildMonster = new Trainer({ monsters: [monster] });
+ wildMonster.type = 'monster';
+ await wildMonster.initialize();
+ Memory.state.opponent = wildMonster;
+
+ UI.drawOpponentMonster();
+ },
+
+ async encounterTrainer () {
+ Game.clearCurrentTurn();
+
+ const nextTrainer = Memory.state.currentArea.trainers[Memory.state.currentArea.trainerProgress];
+
+ const trainer = new Trainer(nextTrainer);
+ if (nextTrainer.name === 'Rival') {
+ trainer.monsters.push(Memory.state.rivalMonster);
+ }
+ await trainer.initialize()
+ Memory.state.opponent = trainer;
+
+ UI.drawOpponentMonster();
+ UI.drawStatus();
+ },
+
+ async encounterNextTrainerMonster () {
+ const activeMonsterIdx = Memory.state.opponent.monsters.indexOf(Memory.state.opponent.activeMonster);
+ Memory.state.opponent.activeMonster = Memory.state.opponent.monsters[activeMonsterIdx + 1];
+
+ UI.drawOpponentMonster();
+ },
+
+ async progressToNextArea () {
+ Game.isLoadingArea = true;
+ Game.clearCurrentTurn();
+
+ const currentArea = Memory.state.currentArea;
+ const nextArea = await fetchArea(currentArea.nextArea);
+
+ await Game.jumpToArea(nextArea);
+
+ if (nextArea.encounters.length > 0) {
+ await Game.encounterWildMonster();
+ } else {
+ await Game.encounterTrainer();
+ }
+
+ UI.drawStatus();
+
+ Game.isLoadingArea = false;
+ },
+
+ /**
+ * @param {Area} area
+ */
+ async jumpToArea (area) {
+ Game.clearCurrentTurn();
+
+ Memory.state.currentArea = area;
+
+ UI.drawArea(area);
+ },
+
+
+ /* Menu - Inventory */
+
/**
* @param {InventoryItem} item
* @param {Monster} monster
@@ -571,22 +687,8 @@ const Game = {
inventory.splice(inventory.indexOf(item), 1);
},
- /**
- * @param {string} type
- *
- * @returns {boolean}
- */
- isBattleType (type) {
- return Memory.state.opponent.type === type;
- },
- /**
- * @param {Monster} monster
- */
- async evolveMonster (monster) {
- await fetchMonster(monster.evolutions[0].monster_slug);
- monster.evolve(monster.evolutions[0]);
- },
+ /* Menu - Catch */
/**
* @returns {boolean}
@@ -620,82 +722,44 @@ const Game = {
await Game.progressTurn();
},
- getStageOfDaySimple () {
- const hours = (new Date()).getHours();
- if (hours >= 6 && hours < 18) {
- return 'day';
- } else {
- return 'night';
- }
- },
+
+ /* Helper */
/**
- * @param {Area} area
+ * @param {Monster} monster
*/
- async jumpToArea (area) {
- Game.clearCurrentTurn();
+ setActivePlayerMonster (monster) {
+ Memory.state.player.activeMonster = monster;
+ Memory.state.activeTechnique = Memory.state.player.activeMonster.activeTechniques[0];
- Memory.state.currentArea = area;
-
- UI.drawArea(area);
+ UI.drawActiveMonster();
+ UI.drawActiveTechniques();
},
- async progressToNextArea () {
- Game.isLoadingArea = true;
- Game.clearCurrentTurn();
-
- const currentArea = Memory.state.currentArea;
- const nextArea = await fetchArea(currentArea.nextArea);
-
- await Game.jumpToArea(nextArea);
-
- if (nextArea.encounters.length > 0) {
- await Game.encounterWildMonster();
- } else {
- await Game.encounterTrainer();
- }
-
- UI.drawStatus();
-
- Game.isLoadingArea = false;
+ /**
+ * @param {Monster} monster
+ */
+ async evolveMonster (monster) {
+ await fetchMonster(monster.evolutions[0].monster_slug);
+ monster.evolve(monster.evolutions[0]);
},
- async encounterWildMonster () {
- const randomMonster = Memory.state.currentArea.encounters[Math.floor(Math.random() * Memory.state.currentArea.encounters.length)];
- const randomLevel = Math.floor(Math.random() * (randomMonster.level_range[1] - randomMonster.level_range[0]) + randomMonster.level_range[0]);
-
- const monster = await fetchMonster(randomMonster.monster);
- monster.level = randomLevel;
-
- const wildMonster = new Trainer({ monsters: [monster] });
- wildMonster.type = 'monster';
- await wildMonster.initialize();
- Memory.state.opponent = wildMonster;
-
- UI.drawOpponentMonster();
+ /**
+ * @param {string} type
+ *
+ * @returns {boolean}
+ */
+ isBattleType (type) {
+ return Memory.state.opponent.type === type;
},
- async encounterTrainer () {
- Game.clearCurrentTurn();
-
- const nextTrainer = Memory.state.currentArea.trainers[Memory.state.currentArea.trainerProgress];
-
- const trainer = new Trainer(nextTrainer);
- if (nextTrainer.name === 'Rival') {
- trainer.monsters.push(Memory.state.rivalMonster);
+ getStageOfDaySimple () {
+ const hours = (new Date()).getHours();
+ if (hours >= 6 && hours < 18) {
+ return 'day';
+ } else {
+ return 'night';
}
- await trainer.initialize()
- Memory.state.opponent = trainer;
-
- UI.drawOpponentMonster();
- UI.drawStatus();
- },
-
- async encounterNextTrainerMonster () {
- const activeMonsterIdx = Memory.state.opponent.monsters.indexOf(Memory.state.opponent.activeMonster);
- Memory.state.opponent.activeMonster = Memory.state.opponent.monsters[activeMonsterIdx + 1];
-
- UI.drawOpponentMonster();
},
};