From cc685bfe02b42b592987117fa008a4461785f53c Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 17 Aug 2023 02:53:14 +0200 Subject: refactor --- resources/js/classes/StatusEffect.js | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 resources/js/classes/StatusEffect.js (limited to 'resources/js/classes/StatusEffect.js') diff --git a/resources/js/classes/StatusEffect.js b/resources/js/classes/StatusEffect.js new file mode 100644 index 0000000..ac6ae54 --- /dev/null +++ b/resources/js/classes/StatusEffect.js @@ -0,0 +1,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; + } +} -- cgit v1.2.3