mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-06 12:27:48 +00:00
Core/LootMgr: Update lootMgr to normalize loot_template tables (#1137)
* Core/LootMgr: Update lootMgr to normalize loot_template tables original by trinitycore team
This commit is contained in:
@@ -131,7 +131,7 @@ uint32 LootStore::LoadLootTable()
|
||||
Clear();
|
||||
|
||||
// 0 1 2 3 4 5 6
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT entry, item, ChanceOrQuestChance, lootmode, groupid, mincountOrRef, maxcount FROM %s", GetName());
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT Entry, Item, Reference, Chance, QuestRequired, LootMode, GroupId, MinCount, MaxCount FROM %s", GetName());
|
||||
|
||||
if (!result)
|
||||
return 0;
|
||||
@@ -144,25 +144,27 @@ uint32 LootStore::LoadLootTable()
|
||||
|
||||
uint32 entry = fields[0].GetUInt32();
|
||||
uint32 item = fields[1].GetUInt32();
|
||||
float chanceOrQuestChance = fields[2].GetFloat();
|
||||
uint16 lootmode = fields[3].GetUInt16();
|
||||
uint8 group = fields[4].GetUInt8();
|
||||
int32 mincountOrRef = fields[5].GetInt32();
|
||||
int32 maxcount = fields[6].GetUInt8();
|
||||
uint32 reference = fields[2].GetUInt32();
|
||||
float chance = fields[3].GetFloat();
|
||||
bool needsquest = fields[4].GetBool();
|
||||
uint16 lootmode = fields[5].GetUInt16();
|
||||
uint8 groupid = fields[6].GetUInt8();
|
||||
int32 mincount = fields[7].GetUInt8();
|
||||
int32 maxcount = fields[8].GetUInt8();
|
||||
|
||||
if (maxcount > std::numeric_limits<uint8>::max())
|
||||
{
|
||||
sLog->outErrorDb("Table '%s' entry %d item %d: maxcount value (%u) to large. must be less %u - skipped", GetName(), entry, item, maxcount, std::numeric_limits<uint8>::max());
|
||||
sLog->outErrorDb("Table '%s' Entry %d Item %d: MaxCount value (%u) to large. must be less %u - skipped", GetName(), entry, item, maxcount, std::numeric_limits<uint8>::max());
|
||||
continue; // error already printed to log/console.
|
||||
}
|
||||
|
||||
if (lootmode == 0)
|
||||
{
|
||||
sLog->outError("Table '%s' entry %d item %d: lootmode is equal to 0, item will never drop - setting mode 1", GetName(), entry, item);
|
||||
sLog->outError("Table '%s' Entry %d Item %d: LootMode is equal to 0, item will never drop - setting mode 1", GetName(), entry, item);
|
||||
lootmode = 1;
|
||||
}
|
||||
|
||||
LootStoreItem* storeitem = new LootStoreItem(item, chanceOrQuestChance, lootmode, group, mincountOrRef, maxcount);
|
||||
LootStoreItem* storeitem = new LootStoreItem(item, reference, chance, needsquest, lootmode, groupid, mincount, maxcount);
|
||||
|
||||
if (!storeitem->IsValid(*this, entry)) // Validity checks
|
||||
{
|
||||
@@ -265,12 +267,17 @@ void LootStore::ReportUnusedIds(LootIdSet const& lootIdSet) const
|
||||
{
|
||||
// all still listed ids isn't referenced
|
||||
for (LootIdSet::const_iterator itr = lootIdSet.begin(); itr != lootIdSet.end(); ++itr)
|
||||
sLog->outErrorDb("Table '%s' entry %d isn't %s and not referenced from loot, and then useless.", GetName(), *itr, GetEntryName());
|
||||
sLog->outErrorDb("Table '%s' Entry %d isn't %s and not referenced from loot, and thus useless.", GetName(), *itr, GetEntryName());
|
||||
}
|
||||
|
||||
void LootStore::ReportNotExistedId(uint32 id) const
|
||||
void LootStore::ReportNonExistingId(uint32 lootId) const
|
||||
{
|
||||
sLog->outErrorDb("Table '%s' entry %d (%s) does not exist but used as loot id in DB.", GetName(), id, GetEntryName());
|
||||
sLog->outErrorDb("Table '%s' Entry %d does not exist", GetName(), lootId);
|
||||
}
|
||||
|
||||
void LootStore::ReportNonExistingId(uint32 lootId, const char* ownerType, uint32 ownerId) const
|
||||
{
|
||||
sLog->outErrorDb("Table '%s' Entry %d does not exist but it is used by %s %d", GetName(), lootId, ownerType, ownerId);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -288,7 +295,7 @@ bool LootStoreItem::Roll(bool rate, Player const *player, Loot& loot, LootStore
|
||||
if (_chance >= 100.0f)
|
||||
return true;
|
||||
|
||||
if (mincountOrRef < 0) // reference case
|
||||
if (reference > 0) // reference case
|
||||
return roll_chance_f(_chance* (rate ? sWorld->getRate(RATE_DROP_ITEM_REFERENCED) : 1.0f));
|
||||
|
||||
ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(itemid);
|
||||
@@ -301,53 +308,53 @@ bool LootStoreItem::Roll(bool rate, Player const *player, Loot& loot, LootStore
|
||||
// Checks correctness of values
|
||||
bool LootStoreItem::IsValid(LootStore const& store, uint32 entry) const
|
||||
{
|
||||
if (group >= 1 << 7) // it stored in 7 bit field
|
||||
if (groupid >= 1 << 7) // it stored in 7 bit field
|
||||
{
|
||||
sLog->outErrorDb("Table '%s' entry %d item %d: group (%u) must be less %u - skipped", store.GetName(), entry, itemid, group, 1 << 7);
|
||||
sLog->outErrorDb("Table '%s' Entry %d Item %d: GroupId (%u) must be less %u - skipped", store.GetName(), entry, itemid, groupid, 1 << 7);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mincountOrRef == 0)
|
||||
if (mincount == 0)
|
||||
{
|
||||
sLog->outErrorDb("Table '%s' entry %d item %d: wrong mincountOrRef (%d) - skipped", store.GetName(), entry, itemid, mincountOrRef);
|
||||
sLog->outErrorDb("Table '%s' Entry %d Item %d: wrong MinCount (%d) - skipped", store.GetName(), entry, itemid, mincount);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mincountOrRef > 0) // item (quest or non-quest) entry, maybe grouped
|
||||
if (reference == 0) // item (quest or non-quest) entry, maybe grouped
|
||||
{
|
||||
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemid);
|
||||
if (!proto)
|
||||
{
|
||||
sLog->outErrorDb("Table '%s' entry %d item %d: item entry not listed in `item_template` - skipped", store.GetName(), entry, itemid);
|
||||
sLog->outErrorDb("Table '%s' Entry %d Item %d: item entry not listed in `item_template` - skipped", store.GetName(), entry, itemid);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chance == 0 && group == 0) // Zero chance is allowed for grouped entries only
|
||||
if (chance == 0 && groupid == 0) // Zero chance is allowed for grouped entries only
|
||||
{
|
||||
sLog->outErrorDb("Table '%s' entry %d item %d: equal-chanced grouped entry, but group not defined - skipped", store.GetName(), entry, itemid);
|
||||
sLog->outErrorDb("Table '%s' Entry %d Item %d: equal-chanced grouped entry, but group not defined - skipped", store.GetName(), entry, itemid);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chance != 0 && chance < 0.000001f) // loot with low chance
|
||||
{
|
||||
sLog->outErrorDb("Table '%s' entry %d item %d: low chance (%f) - skipped",
|
||||
sLog->outErrorDb("Table '%s' Entry %d Item %d: low chance (%f) - skipped",
|
||||
store.GetName(), entry, itemid, chance);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (maxcount < mincountOrRef) // wrong max count
|
||||
if (maxcount < mincount) // wrong max count
|
||||
{
|
||||
sLog->outErrorDb("Table '%s' entry %d item %d: max count (%u) less that min count (%i) - skipped", store.GetName(), entry, itemid, int32(maxcount), mincountOrRef);
|
||||
sLog->outErrorDb("Table '%s' Entry %d Item %d: MaxCount (%u) less that MinCount (%i) - skipped", store.GetName(), entry, itemid, int32(maxcount), mincount);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else // mincountOrRef < 0
|
||||
else // if reference loot
|
||||
{
|
||||
if (needs_quest)
|
||||
sLog->outErrorDb("Table '%s' entry %d item %d: quest chance will be treated as non-quest chance", store.GetName(), entry, itemid);
|
||||
sLog->outErrorDb("Table '%s' Entry %d Item %d: quest required will be ignored", store.GetName(), entry, itemid);
|
||||
else if (chance == 0) // no chance for the reference
|
||||
{
|
||||
sLog->outErrorDb("Table '%s' entry %d item %d: zero chance is specified for a reference, skipped", store.GetName(), entry, itemid);
|
||||
sLog->outErrorDb("Table '%s' Entry %d Item %d: zero chance is specified for a reference, skipped", store.GetName(), entry, itemid);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -426,7 +433,7 @@ void Loot::AddItem(LootStoreItem const& item)
|
||||
if (!proto)
|
||||
return;
|
||||
|
||||
uint32 count = urand(item.mincountOrRef, item.maxcount);
|
||||
uint32 count = urand(item.mincount, item.maxcount);
|
||||
uint32 stacks = count / proto->GetMaxStackSize() + (count % proto->GetMaxStackSize() ? 1 : 0);
|
||||
|
||||
std::vector<LootItem>& lootItems = item.needs_quest ? quest_items : items;
|
||||
@@ -1225,24 +1232,24 @@ void LootTemplate::LootGroup::CheckLootRefs(LootTemplateMap const& /*store*/, Lo
|
||||
for (LootStoreItemList::const_iterator ieItr = ExplicitlyChanced.begin(); ieItr != ExplicitlyChanced.end(); ++ieItr)
|
||||
{
|
||||
LootStoreItem* item = *ieItr;
|
||||
if (item->mincountOrRef < 0)
|
||||
if (item->reference > 0)
|
||||
{
|
||||
if (!LootTemplates_Reference.GetLootFor(-item->mincountOrRef))
|
||||
LootTemplates_Reference.ReportNotExistedId(-item->mincountOrRef);
|
||||
if (!LootTemplates_Reference.GetLootFor(item->reference))
|
||||
LootTemplates_Reference.ReportNonExistingId(item->reference, "Reference", item->itemid);
|
||||
else if (ref_set)
|
||||
ref_set->erase(-item->mincountOrRef);
|
||||
ref_set->erase(item->reference);
|
||||
}
|
||||
}
|
||||
|
||||
for (LootStoreItemList::const_iterator ieItr = EqualChanced.begin(); ieItr != EqualChanced.end(); ++ieItr)
|
||||
{
|
||||
LootStoreItem* item = *ieItr;
|
||||
if (item->mincountOrRef < 0)
|
||||
if (item->reference > 0)
|
||||
{
|
||||
if (!LootTemplates_Reference.GetLootFor(-item->mincountOrRef))
|
||||
LootTemplates_Reference.ReportNotExistedId(-item->mincountOrRef);
|
||||
if (!LootTemplates_Reference.GetLootFor(item->reference))
|
||||
LootTemplates_Reference.ReportNonExistingId(item->reference, "Reference", item->itemid);
|
||||
else if (ref_set)
|
||||
ref_set->erase(-item->mincountOrRef);
|
||||
ref_set->erase(item->reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1267,16 +1274,16 @@ LootTemplate::~LootTemplate()
|
||||
// Adds an entry to the group (at loading stage)
|
||||
void LootTemplate::AddEntry(LootStoreItem* item)
|
||||
{
|
||||
if (item->group > 0 && item->mincountOrRef > 0) // Group
|
||||
if (item->groupid > 0 && item->reference == 0) // Group
|
||||
{
|
||||
if (item->group >= Groups.size())
|
||||
Groups.resize(item->group, NULL); // Adds new group the the loot template if needed
|
||||
if (!Groups[item->group - 1])
|
||||
Groups[item->group - 1] = new LootGroup();
|
||||
if (item->groupid >= Groups.size())
|
||||
Groups.resize(item->groupid, NULL); // Adds new group the the loot template if needed
|
||||
if (!Groups[item->groupid - 1])
|
||||
Groups[item->groupid - 1] = new LootGroup();
|
||||
|
||||
Groups[item->group-1]->AddEntry(item); // Adds new entry to the group
|
||||
Groups[item->groupid - 1]->AddEntry(item); // Adds new entry to the group
|
||||
}
|
||||
else // Non-grouped entries and references are stored together
|
||||
else // Non-grouped entries and references are stored together
|
||||
Entries.push_back(item);
|
||||
}
|
||||
|
||||
@@ -1317,7 +1324,7 @@ void LootTemplate::Process(Loot& loot, LootStore const& store, uint16 lootMode,
|
||||
if (!Groups[groupId - 1])
|
||||
return;
|
||||
|
||||
Groups[groupId-1]->Process(loot, player, store, lootMode);
|
||||
Groups[groupId - 1]->Process(loot, player, store, lootMode);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1331,16 +1338,16 @@ void LootTemplate::Process(Loot& loot, LootStore const& store, uint16 lootMode,
|
||||
if (!item->Roll(rate, player, loot, store))
|
||||
continue; // Bad luck for the entry
|
||||
|
||||
if (item->mincountOrRef < 0) // References processing
|
||||
if (item->reference > 0) // References processing
|
||||
{
|
||||
LootTemplate const* Referenced = LootTemplates_Reference.GetLootFor(-item->mincountOrRef);
|
||||
LootTemplate const* Referenced = LootTemplates_Reference.GetLootFor(item->reference);
|
||||
if (!Referenced)
|
||||
continue; // Error message already printed at loading stage
|
||||
|
||||
uint32 maxcount = uint32(float(item->maxcount) * sWorld->getRate(RATE_DROP_ITEM_REFERENCED_AMOUNT));
|
||||
sScriptMgr->OnAfterRefCount(player, loot, rate, lootMode, item, maxcount, store);
|
||||
for (uint32 loop = 0; loop < maxcount; ++loop) // Ref multiplicator
|
||||
Referenced->Process(loot, store, lootMode, player, item->group);
|
||||
Referenced->Process(loot, store, lootMode, player, item->groupid);
|
||||
} else {
|
||||
// Plain entries (not a reference, not grouped)
|
||||
sScriptMgr->OnBeforeDropAddItem(player, loot, rate, lootMode, item, store);
|
||||
@@ -1371,12 +1378,12 @@ bool LootTemplate::HasQuestDrop(LootTemplateMap const& store, uint8 groupId) con
|
||||
for (LootStoreItemList::const_iterator i = Entries.begin(); i != Entries.end(); ++i)
|
||||
{
|
||||
LootStoreItem* item = *i;
|
||||
if (item->mincountOrRef < 0) // References
|
||||
if (item->reference > 0) // References
|
||||
{
|
||||
LootTemplateMap::const_iterator Referenced = store.find(-item->mincountOrRef);
|
||||
LootTemplateMap::const_iterator Referenced = store.find(item->reference);
|
||||
if (Referenced == store.end())
|
||||
continue; // Error message [should be] already printed at loading stage
|
||||
if (Referenced->second->HasQuestDrop(store, item->group))
|
||||
if (Referenced->second->HasQuestDrop(store, item->groupid))
|
||||
return true;
|
||||
}
|
||||
else if (item->needs_quest)
|
||||
@@ -1403,19 +1410,19 @@ bool LootTemplate::HasQuestDropForPlayer(LootTemplateMap const& store, Player co
|
||||
if (!Groups[groupId - 1])
|
||||
return false;
|
||||
|
||||
return Groups[groupId-1]->HasQuestDropForPlayer(player);
|
||||
return Groups[groupId - 1]->HasQuestDropForPlayer(player);
|
||||
}
|
||||
|
||||
// Checking non-grouped entries
|
||||
for (LootStoreItemList::const_iterator i = Entries.begin(); i != Entries.end(); ++i)
|
||||
{
|
||||
LootStoreItem* item = *i;
|
||||
if (item->mincountOrRef < 0) // References processing
|
||||
if (item->reference > 0) // References processing
|
||||
{
|
||||
LootTemplateMap::const_iterator Referenced = store.find(-item->mincountOrRef);
|
||||
LootTemplateMap::const_iterator Referenced = store.find(item->reference);
|
||||
if (Referenced == store.end())
|
||||
continue; // Error message already printed at loading stage
|
||||
if (Referenced->second->HasQuestDropForPlayer(store, player, item->group))
|
||||
if (Referenced->second->HasQuestDropForPlayer(store, player, item->groupid))
|
||||
return true;
|
||||
}
|
||||
else if (player->HasQuestForItem(item->itemid))
|
||||
@@ -1447,12 +1454,12 @@ void LootTemplate::CheckLootRefs(LootTemplateMap const& store, LootIdSet* ref_se
|
||||
for (LootStoreItemList::const_iterator ieItr = Entries.begin(); ieItr != Entries.end(); ++ieItr)
|
||||
{
|
||||
LootStoreItem* item = *ieItr;
|
||||
if (item->mincountOrRef < 0)
|
||||
if (item->reference > 0)
|
||||
{
|
||||
if (!LootTemplates_Reference.GetLootFor(-item->mincountOrRef))
|
||||
LootTemplates_Reference.ReportNotExistedId(-item->mincountOrRef);
|
||||
if (!LootTemplates_Reference.GetLootFor(item->reference))
|
||||
LootTemplates_Reference.ReportNonExistingId(item->reference, "Reference", item->itemid);
|
||||
else if (ref_set)
|
||||
ref_set->erase(-item->mincountOrRef);
|
||||
ref_set->erase(item->reference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1522,7 +1529,7 @@ bool LootTemplate::addConditionItem(Condition* cond)
|
||||
bool LootTemplate::isReference(uint32 id) const
|
||||
{
|
||||
for (LootStoreItemList::const_iterator ieItr = Entries.begin(); ieItr != Entries.end(); ++ieItr)
|
||||
if ((*ieItr)->itemid == id && (*ieItr)->mincountOrRef < 0)
|
||||
if ((*ieItr)->itemid == id && (*ieItr)->reference > 0)
|
||||
return true;
|
||||
|
||||
return false;//not found or not reference
|
||||
@@ -1544,7 +1551,7 @@ void LoadLootTemplates_Creature()
|
||||
if (uint32 lootid = itr->second.lootid)
|
||||
{
|
||||
if (lootIdSet.find(lootid) == lootIdSet.end())
|
||||
LootTemplates_Creature.ReportNotExistedId(lootid);
|
||||
LootTemplates_Creature.ReportNonExistingId(lootid, "Creature", itr->second.Entry);
|
||||
else
|
||||
lootIdSetUsed.insert(lootid);
|
||||
}
|
||||
@@ -1579,7 +1586,7 @@ void LoadLootTemplates_Disenchant()
|
||||
if (uint32 lootid = itr->second.DisenchantID)
|
||||
{
|
||||
if (lootIdSet.find(lootid) == lootIdSet.end())
|
||||
LootTemplates_Disenchant.ReportNotExistedId(lootid);
|
||||
LootTemplates_Disenchant.ReportNonExistingId(lootid);
|
||||
else
|
||||
lootIdSetUsed.insert(lootid);
|
||||
}
|
||||
@@ -1640,7 +1647,7 @@ void LoadLootTemplates_Gameobject()
|
||||
if (uint32 lootid = itr->second.GetLootId())
|
||||
{
|
||||
if (lootIdSet.find(lootid) == lootIdSet.end())
|
||||
LootTemplates_Gameobject.ReportNotExistedId(lootid);
|
||||
LootTemplates_Gameobject.ReportNonExistingId(lootid, "Gameobject", itr->second.entry);
|
||||
else
|
||||
lootIdSetUsed.insert(lootid);
|
||||
}
|
||||
@@ -1733,7 +1740,7 @@ void LoadLootTemplates_Pickpocketing()
|
||||
if (uint32 lootid = itr->second.pickpocketLootId)
|
||||
{
|
||||
if (lootIdSet.find(lootid) == lootIdSet.end())
|
||||
LootTemplates_Pickpocketing.ReportNotExistedId(lootid);
|
||||
LootTemplates_Pickpocketing.ReportNonExistingId(lootid, "Creature", itr->second.Entry);
|
||||
else
|
||||
lootIdSetUsed.insert(lootid);
|
||||
}
|
||||
@@ -1826,7 +1833,7 @@ void LoadLootTemplates_Skinning()
|
||||
if (uint32 lootid = itr->second.SkinLootId)
|
||||
{
|
||||
if (lootIdSet.find(lootid) == lootIdSet.end())
|
||||
LootTemplates_Skinning.ReportNotExistedId(lootid);
|
||||
LootTemplates_Skinning.ReportNonExistingId(lootid, "Creature", itr->second.Entry);
|
||||
else
|
||||
lootIdSetUsed.insert(lootid);
|
||||
}
|
||||
@@ -1872,7 +1879,7 @@ void LoadLootTemplates_Spell()
|
||||
// ignore 61756 (Northrend Inscription Research (FAST QA VERSION) for example
|
||||
if (!spellInfo->HasAttribute(SPELL_ATTR0_NOT_SHAPESHIFT) || spellInfo->HasAttribute(SPELL_ATTR0_TRADESPELL))
|
||||
{
|
||||
LootTemplates_Spell.ReportNotExistedId(spell_id);
|
||||
LootTemplates_Spell.ReportNonExistingId(spell_id, "Spell", spellInfo->Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user