Skip to content

Commit

Permalink
Spell: Move SpellReagents DBC into database
Browse files Browse the repository at this point in the history
  • Loading branch information
Niam5 committed May 21, 2024
1 parent 16bea56 commit 727bd4e
Show file tree
Hide file tree
Showing 11 changed files with 5,275 additions and 104 deletions.
38 changes: 38 additions & 0 deletions sql/base/dbc/cmangos_fixes/SpellReagents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ALTER TABLE spell_template ADD `Reagent1` INT NOT NULL DEFAULT '0' AFTER SpellReagentsId;
ALTER TABLE spell_template ADD `Reagent2` INT NOT NULL DEFAULT '0' AFTER Reagent1;
ALTER TABLE spell_template ADD `Reagent3` INT NOT NULL DEFAULT '0' AFTER Reagent2;
ALTER TABLE spell_template ADD `Reagent4` INT NOT NULL DEFAULT '0' AFTER Reagent3;
ALTER TABLE spell_template ADD `Reagent5` INT NOT NULL DEFAULT '0' AFTER Reagent4;
ALTER TABLE spell_template ADD `Reagent6` INT NOT NULL DEFAULT '0' AFTER Reagent5;
ALTER TABLE spell_template ADD `Reagent7` INT NOT NULL DEFAULT '0' AFTER Reagent6;
ALTER TABLE spell_template ADD `Reagent8` INT NOT NULL DEFAULT '0' AFTER Reagent7;
ALTER TABLE spell_template ADD `ReagentCount1` INT NOT NULL DEFAULT '0' AFTER Reagent8;
ALTER TABLE spell_template ADD `ReagentCount2` INT UNSIGNED NOT NULL DEFAULT '0' AFTER ReagentCount1;
ALTER TABLE spell_template ADD `ReagentCount3` INT UNSIGNED NOT NULL DEFAULT '0' AFTER ReagentCount2;
ALTER TABLE spell_template ADD `ReagentCount4` INT UNSIGNED NOT NULL DEFAULT '0' AFTER ReagentCount3;
ALTER TABLE spell_template ADD `ReagentCount5` INT UNSIGNED NOT NULL DEFAULT '0' AFTER ReagentCount4;
ALTER TABLE spell_template ADD `ReagentCount6` INT UNSIGNED NOT NULL DEFAULT '0' AFTER ReagentCount5;
ALTER TABLE spell_template ADD `ReagentCount7` INT UNSIGNED NOT NULL DEFAULT '0' AFTER ReagentCount6;
ALTER TABLE spell_template ADD `ReagentCount8` INT UNSIGNED NOT NULL DEFAULT '0' AFTER ReagentCount7;

UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.Reagent1 = spell_reagents.Reagent1;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.Reagent2 = spell_reagents.Reagent2;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.Reagent3 = spell_reagents.Reagent3;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.Reagent4 = spell_reagents.Reagent4;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.Reagent5 = spell_reagents.Reagent5;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.Reagent6 = spell_reagents.Reagent6;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.Reagent7 = spell_reagents.Reagent7;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.Reagent8 = spell_reagents.Reagent8;

UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.ReagentCount1 = spell_reagents.ReagentCount1;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.ReagentCount2 = spell_reagents.ReagentCount2;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.ReagentCount3 = spell_reagents.ReagentCount3;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.ReagentCount4 = spell_reagents.ReagentCount4;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.ReagentCount5 = spell_reagents.ReagentCount5;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.ReagentCount6 = spell_reagents.ReagentCount6;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.ReagentCount7 = spell_reagents.ReagentCount7;
UPDATE spell_template INNER JOIN spell_reagents ON (spell_template.SpellReagentsId = spell_reagents.Id) SET spell_template.ReagentCount8 = spell_reagents.ReagentCount8;

ALTER TABLE spell_template DROP COLUMN SpellReagentsId;

DROP TABLE spell_reagents;
5,180 changes: 5,180 additions & 0 deletions sql/base/dbc/original_data/SpellReagents.sql

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions src/game/Entities/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,22 +746,21 @@ void Pet::Unsummon(PetSaveMode mode, Unit* owner /*= nullptr*/)
{
// returning of reagents only for players, so best done here
uint32 spellId = GetUInt32Value(UNIT_CREATED_BY_SPELL);
SpellEntry const *spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(spellId);
SpellReagentsEntry const* spellReagents = spellInfo ? spellInfo->GetSpellReagents() : NULL;
SpellEntry const* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(spellId);

if (spellReagents)
if (spellInfo)
{
for (uint32 i = 0; i < MAX_SPELL_REAGENTS; ++i)
{
if (spellReagents->Reagent[i] > 0)
if (spellInfo->Reagent[i] > 0)
{
ItemPosCountVec dest; //for succubus, voidwalker, felhunter and felguard credit soulshard when despawn reason other than death (out of range, logout)
uint8 msg = p_owner->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, spellReagents->Reagent[i], spellReagents->ReagentCount[i]);
uint8 msg = p_owner->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, spellInfo->Reagent[i], spellInfo->ReagentCount[i]);
if (msg == EQUIP_ERR_OK)
{
Item* item = p_owner->StoreNewItem(dest, spellReagents->Reagent[i], true);
Item* item = p_owner->StoreNewItem(dest, spellInfo->Reagent[i], true);
if (p_owner->IsInWorld())
p_owner->SendNewItem(item, spellReagents->ReagentCount[i], true, false);
p_owner->SendNewItem(item, spellInfo->ReagentCount[i], true, false);
}
}
}
Expand Down
30 changes: 8 additions & 22 deletions src/game/PlayerBot/Base/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,7 @@ uint32 PlayerbotAI::getSpellId(const char* args, bool master) const
continue;

bool isExactMatch = (name.length() == wnamepart.length()) ? true : false;
SpellReagentsEntry const* spellReagents = pSpellInfo->GetSpellReagents();
if (!spellReagents)
continue;
bool usesNoReagents = (spellReagents->Reagent[0] <= 0) ? true : false;
bool usesNoReagents = (pSpellInfo->Reagent[0] <= 0) ? true : false;

// if we already found a spell
bool useThisSpell = true;
Expand Down Expand Up @@ -319,10 +316,7 @@ uint32 PlayerbotAI::getPetSpellId(const char* args) const
continue;

bool isExactMatch = (name.length() == wnamepart.length()) ? true : false;
SpellReagentsEntry const* spellReagents = pSpellInfo->GetSpellReagents();
if (!spellReagents)
continue;
bool usesNoReagents = (spellReagents->Reagent[0] <= 0) ? true : false;
bool usesNoReagents = (pSpellInfo->Reagent[0] <= 0) ? true : false;

// if we already found a spell
bool useThisSpell = true;
Expand Down Expand Up @@ -5827,15 +5821,11 @@ bool PlayerbotAI::HasSpellReagents(uint32 spellId)

for (uint32 i = 0; i < MAX_SPELL_REAGENTS; ++i)
{
SpellReagentsEntry const* spellReagents = pSpellInfo->GetSpellReagents();
if (!spellReagents)
continue;

if (spellReagents->Reagent[i] <= 0)
if (pSpellInfo->Reagent[i] <= 0)
continue;

uint32 itemid = spellReagents->Reagent[i];
uint32 count = spellReagents->ReagentCount[i];
uint32 itemid = pSpellInfo->Reagent[i];
uint32 count = pSpellInfo->ReagentCount[i];

if (!m_bot->HasItemCount(itemid, count))
return false;
Expand All @@ -5857,16 +5847,12 @@ uint32 PlayerbotAI::GetSpellCharges(uint32 spellId)
std::list<uint32> chargeList;
for (uint32 i = 0; i < MAX_SPELL_REAGENTS; ++i)
{
SpellReagentsEntry const* spellReagents = pSpellInfo->GetSpellReagents();
if (!spellReagents)
continue;

if (spellReagents->Reagent[i] <= 0)
if (pSpellInfo->Reagent[i] <= 0)
continue;

uint32 totalcount = 0;
uint32 itemid = spellReagents->Reagent[i];
uint32 count = spellReagents->ReagentCount[i];
uint32 itemid = pSpellInfo->Reagent[i];
uint32 count = pSpellInfo->ReagentCount[i];
ItemCountInInv(itemid, totalcount);
chargeList.push_back((totalcount / count));
}
Expand Down
2 changes: 0 additions & 2 deletions src/game/Server/DBCStores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ SpellCategoryStore sSpellCategoryStore;
ItemSpellCategoryStore sItemSpellCategoryStore;
PetFamilySpellsStore sPetFamilySpellsStore;

DBCStorage <SpellReagentsEntry> sSpellReagentsStore(SpellReagentsEntryfmt);
DBCStorage <SpellScalingEntry> sSpellScalingStore(SpellScalingEntryfmt);
DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftEntryfmt);
DBCStorage <SpellTargetRestrictionsEntry> sSpellTargetRestrictionsStore(SpellTargetRestrictionsEntryfmt);
Expand Down Expand Up @@ -618,7 +617,6 @@ void LoadDBCStores(const std::string& dataPath)
}
}

LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellReagentsStore, dbcPath,"SpellReagents.dbc");
LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellScalingStore, dbcPath,"SpellScaling.dbc");
LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore, dbcPath,"SpellShapeshift.dbc");
LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellTargetRestrictionsStore, dbcPath,"SpellTargetRestrictions.dbc");
Expand Down
1 change: 0 additions & 1 deletion src/game/Server/DBCStores.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ extern DBCStorage <SpellRangeEntry> sSpellRangeStore;
extern DBCStorage <SpellRuneCostEntry> sSpellRuneCostStore;
extern DBCStorage <SpellShapeshiftFormEntry> sSpellShapeshiftFormStore;
extern DBCStorage <SpellCategoriesEntry> sSpellCategoriesStore;
extern DBCStorage <SpellReagentsEntry> sSpellReagentsStore;
extern DBCStorage <SpellScalingEntry> sSpellScalingStore;
extern DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore;
extern DBCStorage <SpellTargetRestrictionsEntry> sSpellTargetRestrictionsStore;
Expand Down
5 changes: 0 additions & 5 deletions src/game/Server/DBCStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ SpellEffectEntry const* SpellEntry::GetSpellEffect(SpellEffectIndex eff) const
return GetSpellEffectEntry(Id, eff);
}

SpellReagentsEntry const* SpellEntry::GetSpellReagents() const
{
return SpellReagentsId ? sSpellReagentsStore.LookupEntry(SpellReagentsId) : NULL;
}

SpellScalingEntry const* SpellEntry::GetSpellScaling() const
{
return SpellScalingId ? sSpellScalingStore.LookupEntry(SpellScalingId) : NULL;
Expand Down
23 changes: 9 additions & 14 deletions src/game/Server/DBCStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -1858,14 +1858,6 @@ struct SpellRangeEntry
//char* ShortName; // 23-38 m_displayNameShort_lang
};

// SpellReagents.dbc
struct SpellReagentsEntry
{
//uint32 Id; // 0 m_ID
int32 Reagent[MAX_SPELL_REAGENTS]; // 54-61 m_reagent
uint32 ReagentCount[MAX_SPELL_REAGENTS]; // 62-69 m_reagentCount
};

// SpellRuneCost.dbc
struct SpellRuneCostEntry
{
Expand Down Expand Up @@ -2014,11 +2006,15 @@ struct SpellEntry
uint32 ManaPerSecondPerLevel; // 69 m_manaPerSecondPerLevel
//uint32 PowerDisplayId; // 70 m_powerDisplayID - id from PowerDisplay.dbc, new in 3.1
float ManaCostPercentageFloat; // 71 4.3.0
uint32 SpellReagentsId; // 72 SpellReagents.dbc
uint32 SpellShapeshiftId; // 73 SpellShapeshift.dbc
uint32 SpellTargetRestrictionsId; // 74 SpellTargetRestrictions.dbc
uint32 SpellTotemsId; // 75 SpellTotems.dbc
//uint32 ResearchProjectId; // 76 ResearchProject.dbc

//uint32 SpellReagentsId; // 72 SpellReagents.dbc
int32 Reagent[MAX_SPELL_REAGENTS]; // 72-79 m_reagent
uint32 ReagentCount[MAX_SPELL_REAGENTS]; // 80-87 m_reagentCount

uint32 SpellShapeshiftId; // 88 SpellShapeshift.dbc
uint32 SpellTargetRestrictionsId; // 89 SpellTargetRestrictions.dbc
uint32 SpellTotemsId; // 90 SpellTotems.dbc
//uint32 ResearchProjectId; // 91 ResearchProject.dbc

// helpers
int32 CalculateSimpleValue(SpellEffectIndex eff) const;
Expand All @@ -2027,7 +2023,6 @@ struct SpellEntry
// struct access functions
SpellCategoriesEntry const* GetSpellCategories() const;
SpellEffectEntry const* GetSpellEffect(SpellEffectIndex eff) const;
SpellReagentsEntry const* GetSpellReagents() const;
SpellScalingEntry const* GetSpellScaling() const;
SpellShapeshiftEntry const* GetSpellShapeshift() const;
SpellTargetRestrictionsEntry const* GetSpellTargetRestrictions() const;
Expand Down
2 changes: 1 addition & 1 deletion src/game/Server/SQLStorages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const char InstanceTemplatedstfmt[] = "iiiiil";
const char WorldTemplatesrcfmt[] = "is";
const char WorldTemplatedstfmt[] = "ii";
const char ConditionsFmt[] = "iiiix";
const char SpellEntryfmt[] = "iiiiiiiiiiiiiiiifiiiissiiiiiiiiiiiiiiiiiiiiiLiiiiiiiiiiiiiiiiiifiiii";
const char SpellEntryfmt[] = "iiiiiiiiiiiiiiiifiiiissiiiiiiiiiiiiiiiiiiiiiLiiiiiiiiiiiiiiiiiifiiiiiiiiiiiiiiiiiii";
//const char SpellTemplatesrcfmt[] = "iiiiiiiiiiiiiiiix";
// 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 185
//const char SpellTemplatedstfmt[] = "ixxxiiiixxxxxxxxxxxxxxxxxxxxxxxxiixxxxixxxxxxFxxxxxxxxxxxxxxxxxxxxxxixxxxxFFFxxxxxxixxixxixxixxxxxFFFxxxxxxixxixxixxFFFxxxxxxxxxxxxxppppppppppppppppppppppppppppppppxxxxxxxxxxxFFFxxxxxx";
Expand Down
65 changes: 25 additions & 40 deletions src/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5018,17 +5018,13 @@ void Spell::TakeReagents()
if (p_caster->CanNoReagentCast(m_spellInfo))
return;

SpellReagentsEntry const* spellReagents = m_spellInfo->GetSpellReagents();

for(uint32 x = 0; x < MAX_SPELL_REAGENTS; ++x)
{
if(!spellReagents)
continue;
if(spellReagents->Reagent[x] <= 0)
if(m_spellInfo->Reagent[x] <= 0)
continue;

uint32 itemid = spellReagents->Reagent[x];
uint32 itemcount = spellReagents->ReagentCount[x];
uint32 itemid = m_spellInfo->Reagent[x];
uint32 itemcount = m_spellInfo->ReagentCount[x];

// if CastItem is also spell reagent
if (m_CastItem)
Expand Down Expand Up @@ -7130,14 +7126,7 @@ bool Spell::IgnoreItemRequirements() const

/// Some triggered spells have same reagents that have master spell
/// expected in test: master spell have reagents in first slot then triggered don't must use own
if (m_triggeredBySpellInfo)
{
SpellReagentsEntry const* spellReagents = m_triggeredBySpellInfo->GetSpellReagents();
if (!spellReagents || !spellReagents->Reagent[0])
return false;
}

return true;
return !(m_triggeredBySpellInfo && !m_triggeredBySpellInfo->Reagent[0]);
}

return false;
Expand Down Expand Up @@ -7262,39 +7251,35 @@ SpellCastResult Spell::CheckItems()
{
if (!p_caster->CanNoReagentCast(m_spellInfo))
{
SpellReagentsEntry const* spellReagents = m_spellInfo->GetSpellReagents();
if(spellReagents)
for(uint32 i = 0; i < MAX_SPELL_REAGENTS; ++i)
{
for(uint32 i = 0; i < MAX_SPELL_REAGENTS; ++i)
{
if(spellReagents->Reagent[i] <= 0)
continue;
if(m_spellInfo->Reagent[i] <= 0)
continue;

uint32 itemid = spellReagents->Reagent[i];
uint32 itemcount = spellReagents->ReagentCount[i];
uint32 itemid = m_spellInfo->Reagent[i];
uint32 itemcount = m_spellInfo->ReagentCount[i];

// if CastItem is also spell reagent
if (m_CastItem && m_CastItem->GetEntry() == itemid)
{
ItemPrototype const* proto = m_CastItem->GetProto();
if (!proto)
return SPELL_FAILED_REAGENTS;

// if CastItem is also spell reagent
if (m_CastItem && m_CastItem->GetEntry() == itemid)
for (int s = 0; s < MAX_ITEM_PROTO_SPELLS; ++s)
{
ItemPrototype const* proto = m_CastItem->GetProto();
if (!proto)
return SPELL_FAILED_REAGENTS;

for (int s = 0; s < MAX_ITEM_PROTO_SPELLS; ++s)
// CastItem will be used up and does not count as reagent
int32 charges = m_CastItem->GetSpellCharges(s);
if (proto->Spells[s].SpellCharges < 0 && abs(charges) < 2)
{
// CastItem will be used up and does not count as reagent
int32 charges = m_CastItem->GetSpellCharges(s);
if (proto->Spells[s].SpellCharges < 0 && abs(charges) < 2)
{
++itemcount;
break;
}
++itemcount;
break;
}
}

if (!p_caster->HasItemCount(itemid, itemcount))
return SPELL_FAILED_REAGENTS;
}

if (!p_caster->HasItemCount(itemid, itemcount))
return SPELL_FAILED_REAGENTS;
}
}

Expand Down
20 changes: 8 additions & 12 deletions src/game/Spells/SpellMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3842,22 +3842,18 @@ bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg)

if (need_check_reagents)
{
SpellReagentsEntry const* spellReagents = spellInfo->GetSpellReagents();
if(spellReagents)
for(int j : spellInfo->Reagent)
{
for(int j = 0; j < MAX_SPELL_REAGENTS; ++j)
if(j > 0 && !ObjectMgr::GetItemPrototype(j))
{
if(spellReagents->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype( spellReagents->Reagent[j] ))
if(msg)
{
if(msg)
{
if(pl)
ChatHandler(pl).PSendSysMessage("Craft spell %u requires reagent item (Entry: %u) but item does not exist in item_template.",spellInfo->Id,spellReagents->Reagent[j]);
else
sLog.outErrorDb("Craft spell %u requires reagent item (Entry: %u) but item does not exist in item_template.",spellInfo->Id,spellReagents->Reagent[j]);
}
return false;
if(pl)
ChatHandler(pl).PSendSysMessage("Craft spell %u requires reagent item (Entry: %u) but item does not exist in item_template.",spellInfo->Id, j);
else
sLog.outErrorDb("Craft spell %u requires reagent item (Entry: %u) but item does not exist in item_template.",spellInfo->Id, j);
}
return false;
}
}
}
Expand Down

0 comments on commit 727bd4e

Please sign in to comment.