feat(Core/ScriptMgr): correct execute bool hooks (#9574)

This commit is contained in:
Kargatum
2021-12-09 20:58:23 +07:00
committed by GitHub
parent d007fe1ca4
commit c8809f15c2
2 changed files with 48 additions and 28 deletions

View File

@@ -781,10 +781,12 @@ bool ScriptMgr::OnGossipHello(Player* player, Creature* creature)
ASSERT(player);
ASSERT(creature);
if (GetReturnBoolScripts<AllCreatureScript>(false, [&](AllCreatureScript* script)
auto ret = IsValidBoolScript<AllCreatureScript>([&](AllCreatureScript* script)
{
return script->CanCreatureGossipHello(player, creature);
}))
});
if (ret && *ret)
{
return true;
}
@@ -799,10 +801,12 @@ bool ScriptMgr::OnGossipSelect(Player* player, Creature* creature, uint32 sender
ASSERT(player);
ASSERT(creature);
if (GetReturnBoolScripts<AllCreatureScript>(false, [&](AllCreatureScript* script)
auto ret = IsValidBoolScript<AllCreatureScript>([&](AllCreatureScript* script)
{
return script->CanCreatureGossipSelect(player, creature, sender, action);
}))
});
if (ret && *ret)
{
return true;
}
@@ -817,10 +821,12 @@ bool ScriptMgr::OnGossipSelectCode(Player* player, Creature* creature, uint32 se
ASSERT(creature);
ASSERT(code);
if (GetReturnBoolScripts<AllCreatureScript>(false, [&](AllCreatureScript* script)
auto ret = IsValidBoolScript<AllCreatureScript>([&](AllCreatureScript* script)
{
return script->CanCreatureGossipSelectCode(player, creature, sender, action, code);
}))
});
if (ret && *ret)
{
return true;
}
@@ -835,10 +841,12 @@ bool ScriptMgr::OnQuestAccept(Player* player, Creature* creature, Quest const* q
ASSERT(creature);
ASSERT(quest);
if (GetReturnBoolScripts<AllCreatureScript>(false, [&](AllCreatureScript* script)
auto ret = IsValidBoolScript<AllCreatureScript>([&](AllCreatureScript* script)
{
return script->CanCreatureQuestAccept(player, creature, quest);
}))
});
if (ret && *ret)
{
return true;
}
@@ -876,10 +884,12 @@ bool ScriptMgr::OnQuestReward(Player* player, Creature* creature, Quest const* q
ASSERT(creature);
ASSERT(quest);
if (GetReturnBoolScripts<AllCreatureScript>(false, [&](AllCreatureScript* script)
auto ret = IsValidBoolScript<AllCreatureScript>([&](AllCreatureScript* script)
{
return script->CanCreatureQuestReward(player, creature, quest, opt);
}))
});
if (ret && *ret)
{
return true;
}
@@ -946,10 +956,12 @@ bool ScriptMgr::OnGossipHello(Player* player, GameObject* go)
ASSERT(player);
ASSERT(go);
if (GetReturnBoolScripts<AllGameObjectScript>(false, [&](AllGameObjectScript* script)
auto ret = IsValidBoolScript<AllGameObjectScript>([&](AllGameObjectScript* script)
{
return script->CanGameObjectGossipHello(player, go);
}))
});
if (ret && *ret)
{
return true;
}
@@ -964,10 +976,12 @@ bool ScriptMgr::OnGossipSelect(Player* player, GameObject* go, uint32 sender, ui
ASSERT(player);
ASSERT(go);
if (GetReturnBoolScripts<AllGameObjectScript>(false, [&](AllGameObjectScript* script)
auto ret = IsValidBoolScript<AllGameObjectScript>([&](AllGameObjectScript* script)
{
return script->CanGameObjectGossipSelect(player, go, sender, action);
}))
});
if (ret && *ret)
{
return true;
}
@@ -982,10 +996,12 @@ bool ScriptMgr::OnGossipSelectCode(Player* player, GameObject* go, uint32 sender
ASSERT(go);
ASSERT(code);
if (GetReturnBoolScripts<AllGameObjectScript>(false, [&](AllGameObjectScript* script)
auto ret = IsValidBoolScript<AllGameObjectScript>([&](AllGameObjectScript* script)
{
return script->CanGameObjectGossipSelectCode(player, go, sender, action, code);
}))
});
if (ret && *ret)
{
return true;
}
@@ -1000,10 +1016,12 @@ bool ScriptMgr::OnQuestAccept(Player* player, GameObject* go, Quest const* quest
ASSERT(go);
ASSERT(quest);
if (GetReturnBoolScripts<AllGameObjectScript>(false, [&](AllGameObjectScript* script)
auto ret = IsValidBoolScript<AllGameObjectScript>([&](AllGameObjectScript* script)
{
return script->CanGameObjectQuestAccept(player, go, quest);
}))
});
if (ret && *ret)
{
return true;
}
@@ -1019,10 +1037,12 @@ bool ScriptMgr::OnQuestReward(Player* player, GameObject* go, Quest const* quest
ASSERT(go);
ASSERT(quest);
if (GetReturnBoolScripts<AllGameObjectScript>(false, [&](AllGameObjectScript* script)
auto ret = IsValidBoolScript<AllGameObjectScript>([&](AllGameObjectScript* script)
{
return script->CanGameObjectQuestReward(player, go, quest, opt);
}))
});
if (ret && *ret)
{
return true;
}
@@ -1129,10 +1149,12 @@ bool ScriptMgr::OnAreaTrigger(Player* player, AreaTrigger const* trigger)
ASSERT(player);
ASSERT(trigger);
if (GetReturnBoolScripts<ElunaScript>(false, [&](ElunaScript* script)
auto ret = IsValidBoolScript<ElunaScript>([&](ElunaScript* script)
{
return script->CanAreaTrigger(player, trigger);
}))
});
if (ret && *ret)
{
return false;
}

View File

@@ -21,20 +21,18 @@
#include "ScriptMgr.h"
template<typename ScriptName, typename TCallBack>
inline bool GetReturnBoolScripts(bool ret, TCallBack&& callback)
inline Optional<bool> IsValidBoolScript(TCallBack&& callback)
{
if (ScriptRegistry<ScriptName>::ScriptPointerList.empty())
return ret;
bool needReturn = !ret;
return {};
for (auto const& [scriptID, script] : ScriptRegistry<ScriptName>::ScriptPointerList)
{
if (callback(script))
return needReturn;
return true;
}
return ret;
return false;
}
template<class ScriptName, class T, typename TCallBack>