Skip to content

Commit 3f10852

Browse files
committed
Core/Items: Replace hardcoded spell id 483 and 55884 checks with item_template.spelltrigger ITEM_SPELLTRIGGER_LEARN_SPELL_ID
1 parent 06dee8e commit 3f10852

File tree

3 files changed

+46
-73
lines changed

3 files changed

+46
-73
lines changed

src/server/game/Entities/Player/Player.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11472,9 +11472,18 @@ InventoryResult Player::CanUseItem(ItemTemplate const* proto) const
1147211472
return EQUIP_ERR_CLIENT_LOCKED_OUT;
1147311473

1147411474
// learning (recipes, mounts, pets, etc.)
11475-
if (proto->Spells[0].SpellId == 483 || proto->Spells[0].SpellId == 55884)
11476-
if (HasSpell(proto->Spells[1].SpellId))
11477-
return EQUIP_ERR_NONE;
11475+
uint32 learnableCount = 0;
11476+
uint32 learnedCount = 0;
11477+
for (_Spell const& itemEffect : proto->Spells)
11478+
{
11479+
if (itemEffect.SpellTrigger != ITEM_SPELLTRIGGER_LEARN_SPELL_ID)
11480+
continue;
11481+
11482+
++learnableCount;
11483+
learnedCount += HasSpell(itemEffect.SpellId) ? 1 : 0;
11484+
}
11485+
if (learnableCount && learnedCount == learnableCount)
11486+
return EQUIP_ERR_NONE;
1147811487

1147911488
return EQUIP_ERR_OK;
1148011489
}

src/server/game/Globals/ObjectMgr.cpp

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,79 +3287,22 @@ void ObjectMgr::LoadItemTemplates()
32873287
}
32883288
}
32893289

3290-
// special format
3291-
if ((itemTemplate.Spells[0].SpellId == 483) || (itemTemplate.Spells[0].SpellId == 55884))
3290+
for (uint8 j = 0; j < MAX_ITEM_PROTO_SPELLS; ++j)
32923291
{
3293-
// spell_1
3294-
if (itemTemplate.Spells[0].SpellTrigger != ITEM_SPELLTRIGGER_ON_USE)
3292+
if (itemTemplate.Spells[j].SpellTrigger >= MAX_ITEM_SPELLTRIGGER)
32953293
{
3296-
TC_LOG_ERROR("sql.sql", "Item (Entry: {}) has wrong item spell trigger value in spelltrigger_{} ({}) for special learning format", entry, 0+1, itemTemplate.Spells[0].SpellTrigger);
3297-
itemTemplate.Spells[0].SpellId = 0;
3298-
itemTemplate.Spells[0].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE;
3299-
itemTemplate.Spells[1].SpellId = 0;
3300-
itemTemplate.Spells[1].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE;
3294+
TC_LOG_ERROR("sql.sql", "Item (Entry: {}) has wrong item spell trigger value in spelltrigger_{} ({})", entry, j+1, itemTemplate.Spells[j].SpellTrigger);
3295+
itemTemplate.Spells[j].SpellId = 0;
3296+
itemTemplate.Spells[j].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE;
33013297
}
33023298

3303-
// spell_2 have learning spell
3304-
if (itemTemplate.Spells[1].SpellTrigger != ITEM_SPELLTRIGGER_LEARN_SPELL_ID)
3299+
if (itemTemplate.Spells[j].SpellId > 0)
33053300
{
3306-
TC_LOG_ERROR("sql.sql", "Item (Entry: {}) has wrong item spell trigger value in spelltrigger_{} ({}) for special learning format.", entry, 1+1, itemTemplate.Spells[1].SpellTrigger);
3307-
itemTemplate.Spells[0].SpellId = 0;
3308-
itemTemplate.Spells[1].SpellId = 0;
3309-
itemTemplate.Spells[1].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE;
3310-
}
3311-
else if (!itemTemplate.Spells[1].SpellId)
3312-
{
3313-
TC_LOG_ERROR("sql.sql", "Item (Entry: {}) does not have an expected spell in spellid_{} in special learning format.", entry, 1+1);
3314-
itemTemplate.Spells[0].SpellId = 0;
3315-
itemTemplate.Spells[1].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE;
3316-
}
3317-
else if (itemTemplate.Spells[1].SpellId != -1)
3318-
{
3319-
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itemTemplate.Spells[1].SpellId);
3320-
if (!spellInfo && !DisableMgr::IsDisabledFor(DISABLE_TYPE_SPELL, itemTemplate.Spells[1].SpellId, nullptr))
3321-
{
3322-
TC_LOG_ERROR("sql.sql", "Item (Entry: {}) has wrong (not existing) spell in spellid_{} ({})", entry, 1+1, itemTemplate.Spells[1].SpellId);
3323-
itemTemplate.Spells[0].SpellId = 0;
3324-
itemTemplate.Spells[1].SpellId = 0;
3325-
itemTemplate.Spells[1].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE;
3326-
}
3327-
// allowed only in special format
3328-
else if ((itemTemplate.Spells[1].SpellId == 483) || (itemTemplate.Spells[1].SpellId == 55884))
3329-
{
3330-
TC_LOG_ERROR("sql.sql", "Item (Entry: {}) has broken spell in spellid_{} ({})", entry, 1+1, itemTemplate.Spells[1].SpellId);
3331-
itemTemplate.Spells[0].SpellId = 0;
3332-
itemTemplate.Spells[1].SpellId = 0;
3333-
itemTemplate.Spells[1].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE;
3334-
}
3335-
}
3336-
}
3337-
// normal spell list
3338-
else
3339-
{
3340-
for (uint8 j = 0; j < MAX_ITEM_PROTO_SPELLS; ++j)
3341-
{
3342-
if (itemTemplate.Spells[j].SpellTrigger >= MAX_ITEM_SPELLTRIGGER || itemTemplate.Spells[j].SpellTrigger == ITEM_SPELLTRIGGER_LEARN_SPELL_ID)
3301+
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itemTemplate.Spells[j].SpellId);
3302+
if (!spellInfo && !DisableMgr::IsDisabledFor(DISABLE_TYPE_SPELL, itemTemplate.Spells[j].SpellId, nullptr))
33433303
{
3344-
TC_LOG_ERROR("sql.sql", "Item (Entry: {}) has wrong item spell trigger value in spelltrigger_{} ({})", entry, j+1, itemTemplate.Spells[j].SpellTrigger);
3304+
TC_LOG_ERROR("sql.sql", "Item (Entry: {}) has wrong (not existing) spell in spellid_{} ({})", entry, j+1, itemTemplate.Spells[j].SpellId);
33453305
itemTemplate.Spells[j].SpellId = 0;
3346-
itemTemplate.Spells[j].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE;
3347-
}
3348-
3349-
if (itemTemplate.Spells[j].SpellId && itemTemplate.Spells[j].SpellId != -1)
3350-
{
3351-
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itemTemplate.Spells[j].SpellId);
3352-
if (!spellInfo && !DisableMgr::IsDisabledFor(DISABLE_TYPE_SPELL, itemTemplate.Spells[j].SpellId, nullptr))
3353-
{
3354-
TC_LOG_ERROR("sql.sql", "Item (Entry: {}) has wrong (not existing) spell in spellid_{} ({})", entry, j+1, itemTemplate.Spells[j].SpellId);
3355-
itemTemplate.Spells[j].SpellId = 0;
3356-
}
3357-
// allowed only in special format
3358-
else if ((itemTemplate.Spells[j].SpellId == 483) || (itemTemplate.Spells[j].SpellId == 55884))
3359-
{
3360-
TC_LOG_ERROR("sql.sql", "Item (Entry: {}) has broken spell in spellid_{} ({})", entry, j+1, itemTemplate.Spells[j].SpellId);
3361-
itemTemplate.Spells[j].SpellId = 0;
3362-
}
33633306
}
33643307
}
33653308
}

src/server/game/Loot/Loot.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,33 @@ bool LootItem::AllowedForPlayer(Player const* player, bool isGivenByMasterLooter
8989
}
9090

9191
// Don't allow loot for players without profession or those who already know the recipe
92-
if (pProto->HasFlag(ITEM_FLAG_HIDE_UNUSABLE_RECIPE) && (!player->HasSkill(pProto->RequiredSkill) || player->HasSpell(pProto->Spells[1].SpellId)))
93-
return false;
92+
if (pProto->HasFlag(ITEM_FLAG_HIDE_UNUSABLE_RECIPE))
93+
{
94+
if (!player->HasSkill(pProto->RequiredSkill))
95+
return false;
96+
97+
for (_Spell const& itemEffect : pProto->Spells)
98+
{
99+
if (itemEffect.SpellTrigger != ITEM_SPELLTRIGGER_LEARN_SPELL_ID)
100+
continue;
101+
102+
if (player->HasSpell(itemEffect.SpellId))
103+
return false;
104+
}
105+
}
94106

95107
// Don't allow to loot soulbound recipes that the player has already learned
96-
if (pProto->Class == ITEM_CLASS_RECIPE && pProto->Bonding == BIND_WHEN_PICKED_UP && pProto->Spells[1].SpellId != 0 && player->HasSpell(pProto->Spells[1].SpellId))
97-
return false;
108+
if (pProto->Class == ITEM_CLASS_RECIPE && pProto->Bonding == BIND_WHEN_PICKED_UP)
109+
{
110+
for (_Spell const& itemEffect : pProto->Spells)
111+
{
112+
if (itemEffect.SpellTrigger != ITEM_SPELLTRIGGER_LEARN_SPELL_ID)
113+
continue;
114+
115+
if (player->HasSpell(itemEffect.SpellId))
116+
return false;
117+
}
118+
}
98119

99120
if (needs_quest && !freeforall && player->GetGroup() && (player->GetGroup()->GetLootMethod() == GROUP_LOOT || player->GetGroup()->GetLootMethod() == ROUND_ROBIN) && !ownerGuid.IsEmpty() && ownerGuid != player->GetGUID())
100121
return false;

0 commit comments

Comments
 (0)