From 1bf0f981cc8f0f1706ae0b66c7f11281e8c05fd0 Mon Sep 17 00:00:00 2001 From: Matteo Emili Date: Wed, 28 Dec 2016 15:41:19 +0100 Subject: [PATCH] New hooks OnAfterRefCount and OnBeforeDropAddItem --- src/game/Loot/LootMgr.cpp | 9 ++++++--- src/game/Loot/LootMgr.h | 2 +- src/game/Scripting/ScriptMgr.cpp | 10 ++++++++++ src/game/Scripting/ScriptMgr.h | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/game/Loot/LootMgr.cpp b/src/game/Loot/LootMgr.cpp index 5c1bb5a62..e72121f4f 100644 --- a/src/game/Loot/LootMgr.cpp +++ b/src/game/Loot/LootMgr.cpp @@ -15,6 +15,7 @@ #include "Group.h" #include "Player.h" #include "Containers.h" +#include "ScriptMgr.h" static Rates const qualityToRate[MAX_ITEM_QUALITY] = { @@ -461,7 +462,7 @@ bool Loot::FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bo items.reserve(MAX_NR_LOOT_ITEMS); quest_items.reserve(MAX_NR_QUEST_ITEMS); - tab->Process(*this, store.IsRatesAllowed(), lootMode); // Processing is done there, callback via Loot::AddItem() + tab->Process(*this, store.IsRatesAllowed(), lootMode, lootOwner); // Processing is done there, callback via Loot::AddItem() // Setting access rights for group loot case Group* group = lootOwner->GetGroup(); @@ -1296,7 +1297,7 @@ void LootTemplate::CopyConditions(LootItem* li) const } // Rolls for every item in the template and adds the rolled items the the loot -void LootTemplate::Process(Loot& loot, bool rate, uint16 lootMode, uint8 groupId) const +void LootTemplate::Process(Loot& loot, bool rate, uint16 lootMode, Player const* player, uint8 groupId) const { if (groupId) // Group reference uses own processing of the group { @@ -1327,10 +1328,12 @@ void LootTemplate::Process(Loot& loot, bool rate, uint16 lootMode, uint8 groupId continue; // Error message already printed at loading stage uint32 maxcount = uint32(float(item->maxcount) * sWorld->getRate(RATE_DROP_ITEM_REFERENCED_AMOUNT)); + sScriptMgr->OnAfterRefCount(item, maxcount); for (uint32 loop = 0; loop < maxcount; ++loop) // Ref multiplicator - Referenced->Process(loot, rate, lootMode, item->group); + Referenced->Process(loot, rate, lootMode, player, item->group); } else // Plain entries (not a reference, not grouped) + sScriptMgr->OnBeforeDropAddItem(player, loot, item); loot.AddItem(*item); // Chance is already checked, just add } diff --git a/src/game/Loot/LootMgr.h b/src/game/Loot/LootMgr.h index 6f8a3b355..4af00d3f8 100644 --- a/src/game/Loot/LootMgr.h +++ b/src/game/Loot/LootMgr.h @@ -237,7 +237,7 @@ class LootTemplate // Adds an entry to the group (at loading stage) void AddEntry(LootStoreItem* item); // Rolls for every item in the template and adds the rolled items the the loot - void Process(Loot& loot, bool rate, uint16 lootMode, uint8 groupId = 0) const; + void Process(Loot& loot, bool rate, uint16 lootMode, Player const* player, uint8 groupId = 0) const; void CopyConditions(ConditionList conditions); void CopyConditions(LootItem* li) const; diff --git a/src/game/Scripting/ScriptMgr.cpp b/src/game/Scripting/ScriptMgr.cpp index ec5e6c825..98ae415d8 100644 --- a/src/game/Scripting/ScriptMgr.cpp +++ b/src/game/Scripting/ScriptMgr.cpp @@ -1475,6 +1475,16 @@ void ScriptMgr::OnBeforeUpdateArenaPoints(ArenaTeam* at, std::mapOnBeforeUpdateArenaPoints(at,ap); } +void ScriptMgr::OnAfterRefCount(LootStoreItem* LootStoreItem, uint32 &maxcount) +{ + FOREACH_SCRIPT(GlobalScript)->OnAfterRefCount(LootStoreItem, maxcount); +} + +void ScriptMgr::OnBeforeDropAddItem(Player const* player, Loot& loot, LootStoreItem* LootStoreItem) +{ + FOREACH_SCRIPT(GlobalScript)->OnBeforeDropAddItem(player, loot, LootStoreItem); +} + uint32 ScriptMgr::DealDamage(Unit* AttackerUnit, Unit *pVictim, uint32 damage, DamageEffectType damagetype) { FOR_SCRIPTS_RET(UnitScript, itr, end, damage) diff --git a/src/game/Scripting/ScriptMgr.h b/src/game/Scripting/ScriptMgr.h index b7fa6efe7..078a81c75 100644 --- a/src/game/Scripting/ScriptMgr.h +++ b/src/game/Scripting/ScriptMgr.h @@ -965,6 +965,8 @@ class GlobalScript : public ScriptObject // items virtual void OnItemDelFromDB(SQLTransaction& /*trans*/, uint32 /*itemGuid*/) { } virtual void OnMirrorImageDisplayItem(const Item* /*item*/, uint32& /*display*/) { } + virtual void OnAfterRefCount(LootStoreItem* /*LootStoreItem*/, uint32& /*maxcount*/) { } + virtual void OnBeforeDropAddItem(Player const* /*player*/, Loot& /*loot*/, LootStoreItem* /*LootStoreItem*/) { } // On Before arena points distribution virtual void OnBeforeUpdateArenaPoints(ArenaTeam* /*at*/, std::map & /*ap*/) { } @@ -1217,6 +1219,8 @@ class ScriptMgr void OnGlobalItemDelFromDB(SQLTransaction& trans, uint32 itemGuid); void OnGlobalMirrorImageDisplayItem(const Item *item, uint32 &display); void OnBeforeUpdateArenaPoints(ArenaTeam* at, std::map &ap); + void OnAfterRefCount(LootStoreItem* LootStoreItem, uint32 &maxcount); + void OnBeforeDropAddItem(Player const* player, Loot& loot, LootStoreItem* LootStoreItem); public: /* Scheduled scripts */