summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game/Loot/LootMgr.cpp38
-rw-r--r--src/game/Loot/LootMgr.h4
-rw-r--r--src/game/Scripting/ScriptMgr.cpp4
-rw-r--r--src/game/Scripting/ScriptMgr.h4
4 files changed, 28 insertions, 22 deletions
diff --git a/src/game/Loot/LootMgr.cpp b/src/game/Loot/LootMgr.cpp
index a7755648c2..e25cd1c362 100644
--- a/src/game/Loot/LootMgr.cpp
+++ b/src/game/Loot/LootMgr.cpp
@@ -84,7 +84,7 @@ class LootTemplate::LootGroup // A set of loot def
bool HasQuestDrop() const; // True if group includes at least 1 quest drop entry
bool HasQuestDropForPlayer(Player const* player) const;
// The same for active quests of the player
- void Process(Loot& loot, uint16 lootMode) const; // Rolls an item from the group (if any) and adds the item to the loot
+ void Process(Loot& loot, Player const *player, LootStore const& lootstore, uint16 lootMode) const; // Rolls an item from the group (if any) and adds the item to the loot
float RawTotalChance() const; // Overall chance for the group (without equal chanced items)
float TotalChance() const; // Overall chance for the group
@@ -98,7 +98,7 @@ class LootTemplate::LootGroup // A set of loot def
LootStoreItemList ExplicitlyChanced; // Entries with chances defined in DB
LootStoreItemList EqualChanced; // Zero chances - every entry takes the same chance
- LootStoreItem const* Roll(Loot& loot, uint16 lootMode) const; // Rolls an item from the group, returns NULL if all miss their chances
+ LootStoreItem const* Roll(Loot& loot, Player const *player, LootStore const& store, uint16 lootMode) const; // Rolls an item from the group, returns NULL if all miss their chances
// This class must never be copied - storing pointers
LootGroup(LootGroup const&);
@@ -279,19 +279,23 @@ void LootStore::ReportNotExistedId(uint32 id) const
// Checks if the entry (quest, non-quest, reference) takes it's chance (at loot generation)
// RATE_DROP_ITEMS is no longer used for all types of entries
-bool LootStoreItem::Roll(bool rate) const
+bool LootStoreItem::Roll(bool rate, Player const *player, Loot& loot, LootStore const& store) const
{
- if (chance >= 100.0f)
+ float _chance = chance;
+
+ sScriptMgr->OnItemRoll(player, this, _chance, loot, store);
+
+ if (_chance >= 100.0f)
return true;
if (mincountOrRef < 0) // reference case
- return roll_chance_f(chance* (rate ? sWorld->getRate(RATE_DROP_ITEM_REFERENCED) : 1.0f));
+ return roll_chance_f(_chance* (rate ? sWorld->getRate(RATE_DROP_ITEM_REFERENCED) : 1.0f));
ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(itemid);
float qualityModifier = pProto && rate ? sWorld->getRate(qualityToRate[pProto->Quality]) : 1.0f;
- return roll_chance_f(chance*qualityModifier);
+ return roll_chance_f(_chance*qualityModifier);
}
// Checks correctness of values
@@ -1102,7 +1106,7 @@ void LootTemplate::LootGroup::AddEntry(LootStoreItem* item)
}
// Rolls an item from the group, returns NULL if all miss their chances
-LootStoreItem const* LootTemplate::LootGroup::Roll(Loot& loot, uint16 lootMode) const
+LootStoreItem const* LootTemplate::LootGroup::Roll(Loot& loot, Player const *player, LootStore const& store, uint16 lootMode) const
{
LootStoreItemList possibleLoot = ExplicitlyChanced;
possibleLoot.remove_if(LootGroupInvalidSelector(loot, lootMode));
@@ -1114,10 +1118,14 @@ LootStoreItem const* LootTemplate::LootGroup::Roll(Loot& loot, uint16 lootMode)
for (LootStoreItemList::const_iterator itr = possibleLoot.begin(); itr != possibleLoot.end(); ++itr) // check each explicitly chanced entry in the template and modify its chance based on quality.
{
LootStoreItem* item = *itr;
- if (item->chance >= 100.0f)
+ float chance = item->chance;
+
+ sScriptMgr->OnItemRoll(player, item, chance, loot, store);
+
+ if (chance >= 100.0f)
return item;
- roll -= item->chance;
+ roll -= chance;
if (roll < 0)
return item;
}
@@ -1169,9 +1177,9 @@ void LootTemplate::LootGroup::CopyConditions(ConditionList /*conditions*/)
}
// Rolls an item from the group (if any takes its chance) and adds the item to the loot
-void LootTemplate::LootGroup::Process(Loot& loot, uint16 lootMode) const
+void LootTemplate::LootGroup::Process(Loot& loot, Player const *player, LootStore const& store, uint16 lootMode) const
{
- if (LootStoreItem const* item = Roll(loot, lootMode))
+ if (LootStoreItem const* item = Roll(loot, player, store, lootMode))
loot.AddItem(*item);
}
@@ -1309,7 +1317,7 @@ void LootTemplate::Process(Loot& loot, LootStore const& store, uint16 lootMode,
if (!Groups[groupId - 1])
return;
- Groups[groupId-1]->Process(loot, lootMode);
+ Groups[groupId-1]->Process(loot, player, store, lootMode);
return;
}
@@ -1319,10 +1327,8 @@ void LootTemplate::Process(Loot& loot, LootStore const& store, uint16 lootMode,
LootStoreItem* item = *i;
if (!(item->lootmode & lootMode)) // Do not add if mode mismatch
continue;
-
- sScriptMgr->OnBeforeItemRoll(player, loot, rate, lootMode, item, store);
- if (!item->Roll(rate))
+ if (!item->Roll(rate, player, loot, store))
continue; // Bad luck for the entry
if (item->mincountOrRef < 0) // References processing
@@ -1345,7 +1351,7 @@ void LootTemplate::Process(Loot& loot, LootStore const& store, uint16 lootMode,
// Now processing groups
for (LootGroups::const_iterator i = Groups.begin(); i != Groups.end(); ++i)
if (LootGroup* group = *i)
- group->Process(loot, lootMode);
+ group->Process(loot, player, store, lootMode);
}
// True if template includes at least 1 quest drop entry
diff --git a/src/game/Loot/LootMgr.h b/src/game/Loot/LootMgr.h
index 2dde0842ac..fc08f030af 100644
--- a/src/game/Loot/LootMgr.h
+++ b/src/game/Loot/LootMgr.h
@@ -110,6 +110,7 @@ enum LootSlotType
class Player;
class LootStore;
class ConditionMgr;
+struct Loot;
struct LootStoreItem
{
@@ -129,7 +130,7 @@ struct LootStoreItem
group(_group), needs_quest(_chanceOrQuestChance < 0), maxcount(_maxcount)
{}
- bool Roll(bool rate) const; // Checks if the entry takes it's chance (at loot generation)
+ bool Roll(bool rate, Player const *player, Loot& loot, LootStore const& store) const; // Checks if the entry takes it's chance (at loot generation)
bool IsValid(LootStore const& store, uint32 entry) const;
// Checks correctness of values
};
@@ -178,7 +179,6 @@ struct QuestItem
: index(_index), is_looted(_islooted) {}
};
-struct Loot;
class LootTemplate;
typedef std::vector<QuestItem> QuestItemList;
diff --git a/src/game/Scripting/ScriptMgr.cpp b/src/game/Scripting/ScriptMgr.cpp
index d876cc595e..2c2bf165c6 100644
--- a/src/game/Scripting/ScriptMgr.cpp
+++ b/src/game/Scripting/ScriptMgr.cpp
@@ -1519,8 +1519,8 @@ void ScriptMgr::OnBeforeDropAddItem(Player const* player, Loot& loot, bool canRa
FOREACH_SCRIPT(GlobalScript)->OnBeforeDropAddItem(player, loot, canRate, lootMode, LootStoreItem, store);
}
-void ScriptMgr::OnBeforeItemRoll(Player const* player, Loot& loot, bool canRate, uint16 lootMode, LootStoreItem* LootStoreItem, LootStore const& store) {
- FOREACH_SCRIPT(GlobalScript)->OnBeforeItemRoll(player, loot, canRate, lootMode, LootStoreItem, store);
+void ScriptMgr::OnItemRoll(Player const* player, LootStoreItem const* LootStoreItem, float &chance, Loot& loot, LootStore const& store) {
+ FOREACH_SCRIPT(GlobalScript)->OnItemRoll(player, LootStoreItem, chance, loot, store);
}
void ScriptMgr::OnInitializeLockedDungeons(Player* player, uint8& level, uint32& lockData)
diff --git a/src/game/Scripting/ScriptMgr.h b/src/game/Scripting/ScriptMgr.h
index ca936b4cad..c71c45dbff 100644
--- a/src/game/Scripting/ScriptMgr.h
+++ b/src/game/Scripting/ScriptMgr.h
@@ -1008,7 +1008,7 @@ class GlobalScript : public ScriptObject
// loot
virtual void OnAfterRefCount(Player const* /*player*/, LootStoreItem* /*LootStoreItem*/, Loot& /*loot*/, bool /*canRate*/, uint16 /*lootMode*/, uint32& /*maxcount*/, LootStore const& /*store*/) { }
virtual void OnBeforeDropAddItem(Player const* /*player*/, Loot& /*loot*/, bool /*canRate*/, uint16 /*lootMode*/, LootStoreItem* /*LootStoreItem*/, LootStore const& /*store*/) { }
- virtual void OnBeforeItemRoll(Player const* /*player*/, Loot& /*loot*/, bool /*canRate*/, uint16 /*lootMode*/, LootStoreItem* /*LootStoreItem*/, LootStore const& /*store*/) { };
+ virtual void OnItemRoll(Player const* /*player*/, LootStoreItem const* /*LootStoreItem*/, float& /*chance*/, Loot& /*loot*/, LootStore const& /*store*/) { };
virtual void OnInitializeLockedDungeons(Player* /*player*/, uint8& /*level*/, uint32& /*lockData*/) { }
virtual void OnAfterInitializeLockedDungeons(Player* /*player*/) { }
@@ -1281,7 +1281,7 @@ class ScriptMgr
void OnBeforeUpdateArenaPoints(ArenaTeam* at, std::map<uint32, uint32> &ap);
void OnAfterRefCount(Player const* player, Loot& loot, bool canRate, uint16 lootMode, LootStoreItem* LootStoreItem, uint32 &maxcount, LootStore const& store);
void OnBeforeDropAddItem(Player const* player, Loot& loot, bool canRate, uint16 lootMode, LootStoreItem* LootStoreItem, LootStore const& store);
- void OnBeforeItemRoll(Player const* player, Loot& loot, bool canRate, uint16 lootMode, LootStoreItem* LootStoreItem, LootStore const& store);
+ void OnItemRoll(Player const* player, LootStoreItem const* LootStoreItem, float &chance, Loot& loot, LootStore const& store);
void OnInitializeLockedDungeons(Player* player, uint8& level, uint32& lockData);
void OnAfterInitializeLockedDungeons(Player* player);