summaryrefslogtreecommitdiff
path: root/resources/js/game.js
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-26 20:46:22 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-26 20:46:22 +0200
commit36a5d5862c3744f899fe6a5712f81171af144795 (patch)
treeba3c4782ca2da1bdd6b9271371b3bab87f2816a8 /resources/js/game.js
parentb7db43abcaf8c9d9ccb4bcaff07c5416cb21ff62 (diff)
evolution items and shop interface
Diffstat (limited to 'resources/js/game.js')
-rw-r--r--resources/js/game.js59
1 files changed, 46 insertions, 13 deletions
diff --git a/resources/js/game.js b/resources/js/game.js
index b628553..c64d744 100644
--- a/resources/js/game.js
+++ b/resources/js/game.js
@@ -146,7 +146,10 @@ const Game = {
// whole party defeated
if (!Memory.state.player.monsters.some((monster) => monster.hp > 0)) {
Memory.state.Game.isInBattle = false;
- Memory.state.currentArea.monsterProgress = 0;
+
+ if (Memory.state.currentArea.monsterProgress < Memory.state.currentArea.requiredEncounters) {
+ Memory.state.currentArea.monsterProgress = 0;
+ }
// go to last visited town
await Game.goToArea(Memory.state.lastVisitedTown);
@@ -769,6 +772,7 @@ const Game = {
for (const itemConditionCode of item.conditions) {
const itemCondition = new ItemCondition(itemConditionCode);
let conditionIsApplicable = true;
+ console.log(monster.evolutions);
if (itemCondition.what === 'current_hp') {
const value = parseInt(itemCondition.value) * monster.stats.hp;
@@ -787,6 +791,15 @@ const Game = {
conditionIsApplicable = Memory.state.opponent.activeMonster.category === 'threat';
}
+ else if (itemCondition.what === 'level') {
+ const value = parseInt(itemCondition.value);
+ conditionIsApplicable = eval(`${monster.level} ${itemCondition.comparator} ${value}`);
+ }
+
+ else if (itemCondition.what === 'has_path') {
+ conditionIsApplicable = monster.evolutions.some((evolution) => evolution.path === 'item' && evolution.item === item.slug)
+ }
+
else {
conditionIsApplicable = false;
}
@@ -806,48 +819,68 @@ const Game = {
* @param {Monster}
*/
async useItem (item, monster) {
+ let useLowersQuantity = false;
+
for (const itemEffectCode of item.effects) {
const itemEffect = new ItemEffect(itemEffectCode);
if (itemEffect.type === 'heal') {
monster.hp += itemEffect.amount;
- item.quantity--;
+ useLowersQuantity = true;
UI.drawActiveMonster();
}
if (itemEffect.type === 'revive') {
monster.hp = itemEffect.amount;
monster.statusEffect = null;
- item.quantity--;
+ useLowersQuantity = true;
UI.drawActiveMonster();
}
else if (itemEffect.type === 'capture') {
- Memory.state.activeBall = item;
+ Memory.state.activeBall = item.slug;
UI.drawActiveBall();
}
else if (itemEffect.type === 'evolve') {
- const evolution = Memory.state.player.activeMonster.getPossibleEvolutions('item')[0];
+ const evolution = monster.evolutions.find((evolution) => evolution.path === 'item' && evolution.item === item.slug);
if (evolution) {
await fetchMonster(evolution.monster_slug);
- Memory.state.player.activeMonster.evolve(evolution);
+ monster.evolve(evolution);
UI.drawActiveMonster();
- item.quantity--;
+ useLowersQuantity = true;
}
}
}
+ // decrease quantity
+ if (useLowersQuantity) {
+ item.quantity--;
+
+ // remove from inventory
+ if (item.quantity === 0) {
+ Game.removeItemFromInventory(Memory.state.player.inventory, item.slug);
+ }
+ }
+
Memory.saveToLocalStorage();
},
/**
- * @param {Array} inventory
- * @param {InventoryItem} item
+ * @param {InventoryItem[]} inventory
+ * @param {ItemSlug} itemSlug
+ */
+ getItemFromInventory (inventory, itemSlug) {
+ return inventory.find((inventoryItem) => inventoryItem.slug === itemSlug);
+ },
+
+ /**
+ * @param {InventoryItem[]} inventory
+ * @param {ItemSlug} itemSlug
*/
- removeItemFromInventory (inventory, item) {
- inventory.splice(inventory.indexOf(item), 1);
+ removeItemFromInventory (inventory, itemSlug) {
+ inventory.splice(inventory.findIndex((inventoryItem) => inventoryItem.slug === itemSlug), 1);
},
@@ -867,13 +900,13 @@ const Game = {
const playerMonster = Memory.state.player.activeMonster;
const opposingMonster = Memory.state.opponent.activeMonster;
- const activeBall = Memory.state.activeBall;
+ const activeBall = Game.getItemFromInventory(Memory.state.player.inventory, Memory.state.activeBall);
// remove ball
activeBall.quantity--;
if (activeBall.quantity === 0) {
Game.removeItemFromInventory(Memory.state.player.inventory, Memory.state.activeBall);
- Memory.state.activeBall = null;
+ Memory.state.activeBall = '';
UI.drawActiveBall();
}