feat(Core/Scripts): Optimize LootScript (#18715)
* Add files via upload * Add files via upload * Add files via upload * Add files via upload * Add files via upload * Update LootScript.h
This commit is contained in:
@@ -23,13 +23,16 @@ void ScriptMgr::OnLootMoney(Player* player, uint32 gold)
|
|||||||
{
|
{
|
||||||
ASSERT(player);
|
ASSERT(player);
|
||||||
|
|
||||||
ExecuteScript<LootScript>([&](LootScript* script)
|
CALL_ENABLED_HOOKS(LootScript, LOOTHOOK_ON_LOOT_MONEY, script->OnLootMoney(player, gold));
|
||||||
{
|
|
||||||
script->OnLootMoney(player, gold);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LootScript::LootScript(const char* name) : ScriptObject(name)
|
LootScript::LootScript(const char* name, std::vector<uint16> enabledHooks)
|
||||||
|
: ScriptObject(name, LOOTHOOK_END)
|
||||||
{
|
{
|
||||||
ScriptRegistry<LootScript>::AddScript(this);
|
// If empty - enable all available hooks.
|
||||||
|
if (enabledHooks.empty())
|
||||||
|
for (uint16 i = 0; i < LOOTHOOK_END; ++i)
|
||||||
|
enabledHooks.emplace_back(i);
|
||||||
|
|
||||||
|
ScriptRegistry<LootScript>::AddScript(this, std::move(enabledHooks));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,18 @@
|
|||||||
#define SCRIPT_OBJECT_LOOT_SCRIPT_H_
|
#define SCRIPT_OBJECT_LOOT_SCRIPT_H_
|
||||||
|
|
||||||
#include "ScriptObject.h"
|
#include "ScriptObject.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
enum LootHook
|
||||||
|
{
|
||||||
|
LOOTHOOK_ON_LOOT_MONEY,
|
||||||
|
LOOTHOOK_END
|
||||||
|
};
|
||||||
|
|
||||||
class LootScript : public ScriptObject
|
class LootScript : public ScriptObject
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
LootScript(const char* name);
|
LootScript(const char* name, std::vector<uint16> enabledHooks = std::vector<uint16>());
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] bool IsDatabaseBound() const override { return false; }
|
[[nodiscard]] bool IsDatabaseBound() const override { return false; }
|
||||||
|
|||||||
Reference in New Issue
Block a user