From b227fc9c2ef361f8aa5ee2f24aa1ade6bc972a73 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 20 Aug 2023 14:32:40 +0200 Subject: area progress --- resources/js/classes/Trainer.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'resources/js/classes/Trainer.js') diff --git a/resources/js/classes/Trainer.js b/resources/js/classes/Trainer.js index 668c92b..f2c2df9 100644 --- a/resources/js/classes/Trainer.js +++ b/resources/js/classes/Trainer.js @@ -1,4 +1,12 @@ class Trainer { + #monsters = []; + #inventory = []; + + /** + * @type {('trainer' | 'monster')} + */ + type = 'trainer'; + /** * @type {Monster[]} */ @@ -13,4 +21,29 @@ class Trainer { * @type {Monster} */ activeMonster = []; + + constructor (monsters, inventory = []) { + this.#monsters = monsters; + this.#inventory = inventory; + } + + async initialize () { + for (const monsterData of this.#monsters) { + const monster = await fetchMonster(monsterData.slug); + + monster.level = monsterData.level || monster.level; + + this.monsters.push(monster); + } + + this.activeMonster = this.monsters[0]; + + for (const itemData of this.#inventory) { + const item = new InventoryItem(await fetchItem(itemData.slug)); + + item.amount = itemData.amount || 1; + + this.inventory.push(item); + } + } } -- cgit v1.2.3