From 91d048ef0f994446aaee91e3afcbd99788e439d7 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 18 Aug 2023 23:19:13 +0200 Subject: item effects,conditions --- resources/js/classes/InventoryItem.js | 8 +++ resources/js/classes/Item.js | 8 +++ resources/js/classes/Technique.js | 6 +-- resources/js/classes/utility/ItemCondition.js | 18 +++++++ resources/js/classes/utility/ItemEffect.js | 51 ++++++++++++++++++ resources/js/classes/utility/TechniqueEffect.js | 72 +++++++++++++++++++++++++ 6 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 resources/js/classes/utility/ItemCondition.js create mode 100644 resources/js/classes/utility/ItemEffect.js create mode 100644 resources/js/classes/utility/TechniqueEffect.js (limited to 'resources/js/classes') diff --git a/resources/js/classes/InventoryItem.js b/resources/js/classes/InventoryItem.js index 9dfdbcc..2e9b764 100644 --- a/resources/js/classes/InventoryItem.js +++ b/resources/js/classes/InventoryItem.js @@ -37,4 +37,12 @@ class InventoryItem { get sprite () { return this.item.sprite; } + + get conditions () { + return this.item.conditions; + } + + get effects () { + return this.item.effects; + } } diff --git a/resources/js/classes/Item.js b/resources/js/classes/Item.js index 6207cc2..8a12b9a 100644 --- a/resources/js/classes/Item.js +++ b/resources/js/classes/Item.js @@ -18,4 +18,12 @@ class Item { get sprite () { return DB.items[this.slug].sprite; } + + get conditions () { + return DB.items[this.slug].conditions; + } + + get effects () { + return DB.items[this.slug].effects; + } } diff --git a/resources/js/classes/Technique.js b/resources/js/classes/Technique.js index 7558748..39028be 100644 --- a/resources/js/classes/Technique.js +++ b/resources/js/classes/Technique.js @@ -44,12 +44,12 @@ class Technique { return DB.techniques[this.slug].recharge; } - isUsable () { + isRecharging () { if (this.turnLastUse >= Game.turn) { - return true; + return false; } - return Game.turn - this.turnLastUse >= this.rechargeLength; + return this.rechargeLength > Game.turn - this.turnLastUse; } use () { diff --git a/resources/js/classes/utility/ItemCondition.js b/resources/js/classes/utility/ItemCondition.js new file mode 100644 index 0000000..c8c1fe2 --- /dev/null +++ b/resources/js/classes/utility/ItemCondition.js @@ -0,0 +1,18 @@ +class ItemCondition { + /** + * @param {string} conditionCode + */ + constructor (conditionCode) { + this.is = conditionCode.split(' ')[0]; + this.what = conditionCode.split(' ')[1]; + + if (conditionCode.includes(',')) { + this.comparator = conditionCode.split(' ')[2].split(',')[0]; + this.value = conditionCode.split(' ')[2].split(',')[1]; + } + + else { + this.value = conditionCode.split(' ')[2]; + } + } +} diff --git a/resources/js/classes/utility/ItemEffect.js b/resources/js/classes/utility/ItemEffect.js new file mode 100644 index 0000000..aa1c1df --- /dev/null +++ b/resources/js/classes/utility/ItemEffect.js @@ -0,0 +1,51 @@ +class ItemEffect { + /** + * @type {string} + */ + type = ''; + + /** + * @type {('increase')} + */ + application = ''; + + /** + * @type {number} + */ + amount = 0; + + /** + * @param {string} effectCode + */ + constructor (effectCode) { + if (effectCode.startsWith('heal')) { + this.type = 'heal'; + + this.amount = parseInt(effectCode.split(' ')[1]); + } + + else if (effectCode.startsWith('revive')) { + this.type = 'revive'; + + this.amount = effectCode.split(' ')[1]; + } + + else if (effectCode.startsWith('learn_')) { + this.type = effectCode.split(' ')[0]; + + this.what = effectCode.split(' ')[1]; + } + + else if (Object.values(StatType).includes(effectCode.split(' ')[1] || '')) { + this.type = 'stat'; + + this.application = effectCode.split(' ')[0]; + this.what = effectCode.split(' ')[1].split(',')[0]; + this.amount = effectCode.split(' ')[1].split(',')[1]; + } + + else { + this.type = effectCode; + } + } +} diff --git a/resources/js/classes/utility/TechniqueEffect.js b/resources/js/classes/utility/TechniqueEffect.js new file mode 100644 index 0000000..10e9399 --- /dev/null +++ b/resources/js/classes/utility/TechniqueEffect.js @@ -0,0 +1,72 @@ +class TechniqueEffect { + /** + * @type {string} + */ + type = ''; + + /** + * @type {(('user' | 'target')|Monster)} + */ + recipient = null; + + /** + * @type {('give' | 'remove')} + */ + application = ''; + + /** + * @type {StatusEffectType} + */ + statusEffect = null; + + /** + * @type {Monster} + */ + user = null; + + /** + * @type {Monster} + */ + target = null; + + /** + * @param {string} effectCode + */ + constructor (effectCode) { + if (effectCode.includes('status_')) { + this.type = 'status'; + + this.recipient = effectCode.split(',')[1]; + this.application = effectCode.split(' ')[0]; + this.statusEffect = effectCode.split(',')[0].split(' ')[1].split('_')[1]; + } + + else if (effectCode.includes('healing')) { + this.type = 'healing'; + + this.recipient = effectCode.split(' ')[1]; + } + + else { + this.type = effectCode; + } + } + + /** + * @type {Monster} + */ + setUser (user) { + if (this.recipient === 'user') { + this.recipient = user; + } + } + + /** + * @type {Monster} + */ + setTarget (target) { + if (this.recipient === 'target') { + this.recipient = target; + } + } +} -- cgit v1.2.3