summaryrefslogtreecommitdiff
path: root/resources/js/classes/StatusEffect.js
blob: ac6ae54558d8df34409369013269856e217707e9 (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
50
51
52
53
54
55
class StatusEffect {
  turnsLeft = 0;
  onRemove = null;

  /**
   * @type {Monster}
   */
  issuer = null;

  constructor (slug) {
    this.slug = slug;

    if (['recover', 'lifeleech'].includes(this.slug)) {
      this.turnsLeft = 1;
    }
    else if (['charging'].includes(this.slug)) {
      this.turnsLeft = 2;
    }
    else if (this.category === 'positive') {
      this.turnsLeft = Math.ceil(Math.random() * 6) + 4;
    }
    else if (this.category === 'negative') {
      this.turnsLeft = Math.ceil(Math.random() * 3) + 2;
    }
    else {
      this.turnsLeft = Math.ceil(Math.random() * 3) + 2;
    }
  }

  /**
   * @returns {string[]}
   */
  get effects () {
    return DB.statusEffects[this.slug].effects;
  }

  get category () {
    return DB.statusEffects[this.slug].category;
  }

  get name () {
    return slugToName(this.slug);
  }

  get stats () {
    const stats = {};

    const statsChangeKeys = Object.keys(DB.statusEffects[this.slug]).filter((key) => key.startsWith('stat'));
    for (const statChangeKey of statsChangeKeys) {
      stats[statChangeKey.replace('stat', '')] = DB.statusEffects[this.slug][statChangeKey];
    }

    return stats;
  }
}