summaryrefslogtreecommitdiff
path: root/resources/js/classes/Trainer.js
blob: f2c2df969324e808f0d391f84ede8b9bc9ee3fc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Trainer {
  #monsters = [];
  #inventory = [];

  /**
   * @type {('trainer' | 'monster')}
   */
  type = 'trainer';

  /**
   * @type {Monster[]}
   */
  monsters = [];

  /**
   * @type {InventoryItem[]}
   */
  inventory = [];

  /**
   * @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);
    }
  }
}