From 6382302a301fa63d77fef6c0b2b82d32b8640304 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Thu, 8 Jun 2023 12:37:53 +0200 Subject: [PATCH] Defines/SpellTrigger * convert magic numbers to define and use as spell trigger types --- includes/defines.php | 8 ++++++++ includes/types/item.class.php | 12 ++++++------ pages/enchantment.php | 12 ++++++------ pages/item.php | 6 +++--- pages/spell.php | 22 +++++++++++----------- setup/tools/sqlgen/item_stats.func.php | 4 ++-- 6 files changed, 36 insertions(+), 28 deletions(-) diff --git a/includes/defines.php b/includes/defines.php index ce7837e8..a603e510 100644 --- a/includes/defines.php +++ b/includes/defines.php @@ -832,6 +832,14 @@ define('ITEM_MOD_SHADOW_POWER', 60); define('ITEM_MOD_NATURE_POWER', 61); define('ITEM_MOD_ARCANE_POWER', 62); +// item trigger and recipe handling +define('SPELL_TRIGGER_USE', 0); +define('SPELL_TRIGGER_EQUIP', 1); +define('SPELL_TRIGGER_HIT', 2); +define('SPELL_TRIGGER_SOULSTONE', 4); +define('SPELL_TRIGGER_USE_NODELAY', 5); +define('SPELL_TRIGGER_LEARN', 6); + // learn trigger spells on items - 483: learn recipe; 55884: learn mount/pet define('LEARN_SPELLS', [483, 55884]); diff --git a/includes/types/item.class.php b/includes/types/item.class.php index 7c08f533..154dbd2f 100644 --- a/includes/types/item.class.php +++ b/includes/types/item.class.php @@ -964,7 +964,7 @@ class ItemList extends BaseType else // build block with generic time $extra[] = Lang::item('cooldown', 0, [Lang::formatTime($cd, 'game', 'timeAbbrev', true)]); } - if ($this->curTpl['spellTrigger'.$j] == 2) + if ($this->curTpl['spellTrigger'.$j] == SPELL_TRIGGER_HIT) if ($ppm = $this->curTpl['spellppmRate'.$j]) $extra[] = Lang::spell('ppm', [$ppm]); @@ -2434,11 +2434,11 @@ class ItemListFilter extends Filter return [ 'OR', - ['AND', ['spellTrigger1', 0], ['spellId1', 0, '!'], ['spellCooldown1', 0, '>'], ['spellCooldown1', $cr[2], $cr[1]]], - ['AND', ['spellTrigger2', 0], ['spellId2', 0, '!'], ['spellCooldown2', 0, '>'], ['spellCooldown2', $cr[2], $cr[1]]], - ['AND', ['spellTrigger3', 0], ['spellId3', 0, '!'], ['spellCooldown3', 0, '>'], ['spellCooldown3', $cr[2], $cr[1]]], - ['AND', ['spellTrigger4', 0], ['spellId4', 0, '!'], ['spellCooldown4', 0, '>'], ['spellCooldown4', $cr[2], $cr[1]]], - ['AND', ['spellTrigger5', 0], ['spellId5', 0, '!'], ['spellCooldown5', 0, '>'], ['spellCooldown5', $cr[2], $cr[1]]], + ['AND', ['spellTrigger1', SPELL_TRIGGER_USE], ['spellId1', 0, '!'], ['spellCooldown1', 0, '>'], ['spellCooldown1', $cr[2], $cr[1]]], + ['AND', ['spellTrigger2', SPELL_TRIGGER_USE], ['spellId2', 0, '!'], ['spellCooldown2', 0, '>'], ['spellCooldown2', $cr[2], $cr[1]]], + ['AND', ['spellTrigger3', SPELL_TRIGGER_USE], ['spellId3', 0, '!'], ['spellCooldown3', 0, '>'], ['spellCooldown3', $cr[2], $cr[1]]], + ['AND', ['spellTrigger4', SPELL_TRIGGER_USE], ['spellId4', 0, '!'], ['spellCooldown4', 0, '>'], ['spellCooldown4', $cr[2], $cr[1]]], + ['AND', ['spellTrigger5', SPELL_TRIGGER_USE], ['spellId5', 0, '!'], ['spellCooldown5', 0, '>'], ['spellCooldown5', $cr[2], $cr[1]]], ]; } diff --git a/pages/enchantment.php b/pages/enchantment.php index f660014d..ffc57d99 100644 --- a/pages/enchantment.php +++ b/pages/enchantment.php @@ -218,12 +218,12 @@ class EnchantmentPage extends GenericPage $spellIds = $spellList->getFoundIDs(); $conditions = array( - 'OR', // [use, useUndelayed] - ['AND', ['spellTrigger1', [0, 5]], ['spellId1', $spellIds]], - ['AND', ['spellTrigger2', [0, 5]], ['spellId2', $spellIds]], - ['AND', ['spellTrigger3', [0, 5]], ['spellId3', $spellIds]], - ['AND', ['spellTrigger4', [0, 5]], ['spellId4', $spellIds]], - ['AND', ['spellTrigger5', [0, 5]], ['spellId5', $spellIds]] + 'OR', + ['AND', ['spellTrigger1', [SPELL_TRIGGER_USE, SPELL_TRIGGER_USE_NODELAY]], ['spellId1', $spellIds]], + ['AND', ['spellTrigger2', [SPELL_TRIGGER_USE, SPELL_TRIGGER_USE_NODELAY]], ['spellId2', $spellIds]], + ['AND', ['spellTrigger3', [SPELL_TRIGGER_USE, SPELL_TRIGGER_USE_NODELAY]], ['spellId3', $spellIds]], + ['AND', ['spellTrigger4', [SPELL_TRIGGER_USE, SPELL_TRIGGER_USE_NODELAY]], ['spellId4', $spellIds]], + ['AND', ['spellTrigger5', [SPELL_TRIGGER_USE, SPELL_TRIGGER_USE_NODELAY]], ['spellId5', $spellIds]] ); $ubItems = new ItemList($conditions); diff --git a/pages/item.php b/pages/item.php index fd397e9d..5037c214 100644 --- a/pages/item.php +++ b/pages/item.php @@ -168,7 +168,7 @@ class ItemPage extends genericPage $hasUse = false; for ($i = 1; $i < 6; $i++) { - if ($this->subject->getField('spellId'.$i) <= 0 || in_array($this->subject->getField('spellTrigger'.$i), [1, 2])) + if ($this->subject->getField('spellId'.$i) <= 0 || in_array($this->subject->getField('spellTrigger'.$i), [SPELL_TRIGGER_EQUIP, SPELL_TRIGGER_HIT])) continue; $hasUse = true; @@ -880,9 +880,9 @@ class ItemPage extends genericPage $ids = $indirect = []; for ($i = 1; $i < 6; $i++) { - if ($this->subject->getField('spellTrigger'.$i) == 6) + if ($this->subject->getField('spellTrigger'.$i) == SPELL_TRIGGER_LEARN) $ids[] = $this->subject->getField('spellId'.$i); - else if ($this->subject->getField('spellTrigger'.$i) == 0 && $this->subject->getField('spellId'.$i) > 0) + else if ($this->subject->getField('spellTrigger'.$i) == SPELL_TRIGGER_USE && $this->subject->getField('spellId'.$i) > 0) $indirect[] = $this->subject->getField('spellId'.$i); } diff --git a/pages/spell.php b/pages/spell.php index 3724e5e8..3a8f4c6b 100644 --- a/pages/spell.php +++ b/pages/spell.php @@ -588,12 +588,12 @@ class SpellPage extends GenericPage // tab: used by - item $conditions = array( - 'OR', // 6: learn spell - ['AND', ['spellTrigger1', 6, '!'], ['spellId1', $this->subject->id]], - ['AND', ['spellTrigger2', 6, '!'], ['spellId2', $this->subject->id]], - ['AND', ['spellTrigger3', 6, '!'], ['spellId3', $this->subject->id]], - ['AND', ['spellTrigger4', 6, '!'], ['spellId4', $this->subject->id]], - ['AND', ['spellTrigger5', 6, '!'], ['spellId5', $this->subject->id]] + 'OR', + ['AND', ['spellTrigger1', SPELL_TRIGGER_LEARN, '!'], ['spellId1', $this->subject->id]], + ['AND', ['spellTrigger2', SPELL_TRIGGER_LEARN, '!'], ['spellId2', $this->subject->id]], + ['AND', ['spellTrigger3', SPELL_TRIGGER_LEARN, '!'], ['spellId3', $this->subject->id]], + ['AND', ['spellTrigger4', SPELL_TRIGGER_LEARN, '!'], ['spellId4', $this->subject->id]], + ['AND', ['spellTrigger5', SPELL_TRIGGER_LEARN, '!'], ['spellId5', $this->subject->id]] ); $ubItems = new ItemList($conditions); @@ -1132,11 +1132,11 @@ class SpellPage extends GenericPage // tab: taught by item (i'd like to precheck $this->subject->sources, but there is no source:item only complicated crap like "drop" and "vendor") $conditions = array( 'OR', - ['AND', ['spellTrigger1', 6], ['spellId1', $this->subject->id]], - ['AND', ['spellTrigger2', 6], ['spellId2', $this->subject->id]], - ['AND', ['spellTrigger3', 6], ['spellId3', $this->subject->id]], - ['AND', ['spellTrigger4', 6], ['spellId4', $this->subject->id]], - ['AND', ['spellTrigger5', 6], ['spellId5', $this->subject->id]], + ['AND', ['spellTrigger1', SPELL_TRIGGER_LEARN], ['spellId1', $this->subject->id]], + ['AND', ['spellTrigger2', SPELL_TRIGGER_LEARN], ['spellId2', $this->subject->id]], + ['AND', ['spellTrigger3', SPELL_TRIGGER_LEARN], ['spellId3', $this->subject->id]], + ['AND', ['spellTrigger4', SPELL_TRIGGER_LEARN], ['spellId4', $this->subject->id]], + ['AND', ['spellTrigger5', SPELL_TRIGGER_LEARN], ['spellId5', $this->subject->id]], ); $tbItem = new ItemList($conditions); diff --git a/setup/tools/sqlgen/item_stats.func.php b/setup/tools/sqlgen/item_stats.func.php index 8ba294dc..bbcfd487 100644 --- a/setup/tools/sqlgen/item_stats.func.php +++ b/setup/tools/sqlgen/item_stats.func.php @@ -62,8 +62,8 @@ class ItemStatSetup extends ItemList continue; // armor & weapons only onEquip && consumables only onUse - if (!(in_array($this->curTpl['class'], [ITEM_CLASS_WEAPON, ITEM_CLASS_ARMOR]) && $this->curTpl['spellTrigger'.$h] == 1) && - !( $this->curTpl['class'] == ITEM_CLASS_CONSUMABLE && $this->curTpl['spellTrigger'.$h] == 0)) + if (!(in_array($this->curTpl['class'], [ITEM_CLASS_WEAPON, ITEM_CLASS_ARMOR]) && $this->curTpl['spellTrigger'.$h] == SPELL_TRIGGER_EQUIP) && + !( $this->curTpl['class'] == ITEM_CLASS_CONSUMABLE && $this->curTpl['spellTrigger'.$h] == SPELL_TRIGGER_USE)) continue; $equipSpells[] = $this->curTpl['spellId'.$h];