summaryrefslogtreecommitdiff
path: root/resources/js/game.js
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-20 14:32:40 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-20 14:32:40 +0200
commitb227fc9c2ef361f8aa5ee2f24aa1ade6bc972a73 (patch)
tree8fdd7e980107bfd8fcd58ffe21f2299b37d310c8 /resources/js/game.js
parent2c7890e90e1aad371854cfe60ad63eaa88e64fec (diff)
area progress
Diffstat (limited to 'resources/js/game.js')
-rw-r--r--resources/js/game.js135
1 files changed, 109 insertions, 26 deletions
diff --git a/resources/js/game.js b/resources/js/game.js
index 1a95ce4..1a91f06 100644
--- a/resources/js/game.js
+++ b/resources/js/game.js
@@ -5,6 +5,7 @@ const Game = {
postAction: [],
},
+ isInBattle: false,
didTechniqueHit: false,
async progressTurn () {
@@ -41,14 +42,21 @@ const Game = {
await Game.evolveMonster(Memory.state.player.activeMonster);
}
- await Game.spawnOpponentMonster();
- }
+ Game.isInBattle = false;
- UI.drawOpponentMonster();
- UI.drawActiveMonster();
- UI.drawActiveTechniques();
+ if (Memory.state.opponent.type === 'monster') {
+ Memory.state.currentArea.monsterProgress++;
+ await Game.encounterWildMonster();
+ } else if (Memory.state.opponent.type === 'trainer') {
+ if (Memory.state.opponent.activeMonster === Memory.state.opponent.monsters[Memory.state.opponent.monsters.length - 1]) {
+ await Game.progressToArea(await fetchArea(Memory.state.currentArea.nextArea));
+ } else {
+ await Game.encounterNextTrainerMonster();
+ }
+ }
+ }
- UI.elements.money.textContent = `${Memory.state.money} €`;
+ UI.progressTurn();
},
/**
@@ -301,27 +309,10 @@ const Game = {
},
/**
- * @param {Monster} monster
- */
- async evolveMonster (monster) {
- await fetchMonster(monster.evolutions[0].monster_slug);
- monster.evolve(monster.evolutions[0]);
- },
-
- async spawnOpponentMonster () {
- Memory.state.opponent.activeMonster = await fetchMonster(DB.allMonsters[Math.floor(Math.random() * DB.allMonsters.length)]);
- Memory.state.opponent.activeMonster.level = Math.ceil(Math.random() * Memory.state.player.activeMonster.level);
-
- // Memory.state.opponent.activeMonster.experienceModifier = Memory.state.opponent.activeMonster.level;
- Memory.state.opponent.activeMonster.moneyModifier = Memory.state.opponent.activeMonster.level;
-
- UI.drawOpponentMonster();
- },
-
- /**
* @param {MouseEvent} event
*/
async battleClick (event) {
+ Game.isInBattle = true;
UI.battleClickEvent = event;
await Game.tryUseTechnique(Memory.state.activeTechnique, Memory.state.player.activeMonster, Memory.state.opponent.activeMonster);
@@ -357,18 +348,110 @@ const Game = {
}));
},
- catchMonster () {
+ /**
+ * @param {InventoryItem}
+ */
+ async useItem (item) {
+ for (const itemEffectCode of item.effects) {
+ const itemEffect = new ItemEffect(itemEffectCode);
+
+ if (itemEffect.type === 'evolve') {
+ const evolution = Memory.state.player.activeMonster.getPossibleEvolutions('item')[0];
+ if (evolution) {
+ await fetchMonster(evolution.monster_slug);
+ Memory.state.player.activeMonster.evolve(evolution);
+ UI.drawActiveMonster();
+ }
+ }
+ }
+ },
+
+ /**
+ * @param {Monster} monster
+ */
+ async evolveMonster (monster) {
+ await fetchMonster(monster.evolutions[0].monster_slug);
+ monster.evolve(monster.evolutions[0]);
+ },
+
+ async catchMonster () {
+ if (Memory.state.opponent.type === 'trainer') {
+ return;
+ }
+
const caughtMonster = new Monster(Memory.state.opponent.activeMonster.slug);
caughtMonster.initialize();
caughtMonster.level = Memory.state.opponent.activeMonster.level;
Memory.state.player.monsters.push(caughtMonster);
- Game.spawnOpponentMonster();
+ await Game.encounterWildMonster();
+ await Game.progressTurn();
+ },
+
+ getStageOfDaySimple () {
+ const hours = (new Date()).getHours();
+ if (hours >= 6 && hours < 18) {
+ return 'day';
+ } else {
+ return 'night';
+ }
+ },
+
+ /**
+ * @param {Area} area
+ */
+ async progressToArea (area) {
+ Memory.state.currentArea = area;
+
+ UI.drawArea(area);
+ UI.drawStatus();
+
+ if (area.encounters.length > 0) {
+ await Game.encounterWildMonster();
+ } else {
+ await Game.encounterTrainer();
+ }
+ },
+
+ 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([monster]);
+ wildMonster.type = 'monster';
+ await wildMonster.initialize();
+ Memory.state.opponent = wildMonster;
+
+ UI.drawOpponentMonster();
+ },
+
+ async encounterTrainer () {
+ const nextTrainer = Memory.state.currentArea.trainers[Memory.state.currentArea.trainerProgress];
+
+ const trainer = new Trainer(nextTrainer.monsters, nextTrainer.inventory);
+ if (nextTrainer.name === 'Rival') {
+ trainer.monsters.push(Memory.state.rivalMonster);
+ }
+ await trainer.initialize()
+ Memory.state.opponent = trainer;
+
+ UI.drawOpponentMonster();
+ },
+
+ 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();
},
};
// Game click bindings
+UI.elements.status.querySelector('[data-template-slot="next-trainer"]').addEventListener('click', Game.encounterTrainer);
UI.elements.battleOpponent.addEventListener('click', Game.battleClick);
UI.elements.techniques.addEventListener('click', Game.techniqueClick);
UI.elements.menuCatch.addEventListener('click', Game.catchMonster);