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:
天鹿
2024-04-12 21:55:54 +08:00
committed by GitHub
parent 9464068625
commit 1ecce50e06
2 changed files with 17 additions and 7 deletions

View File

@@ -23,13 +23,16 @@ void ScriptMgr::OnLootMoney(Player* player, uint32 gold)
{
ASSERT(player);
ExecuteScript<LootScript>([&](LootScript* script)
{
script->OnLootMoney(player, gold);
});
CALL_ENABLED_HOOKS(LootScript, LOOTHOOK_ON_LOOT_MONEY, 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));
}

View File

@@ -19,11 +19,18 @@
#define SCRIPT_OBJECT_LOOT_SCRIPT_H_
#include "ScriptObject.h"
#include <vector>
enum LootHook
{
LOOTHOOK_ON_LOOT_MONEY,
LOOTHOOK_END
};
class LootScript : public ScriptObject
{
protected:
LootScript(const char* name);
LootScript(const char* name, std::vector<uint16> enabledHooks = std::vector<uint16>());
public:
[[nodiscard]] bool IsDatabaseBound() const override { return false; }