mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-08 15:58:04 +00:00
feat(Core/ScriptMgr): correct execute bool hooks (#9574)
This commit is contained in:
@@ -781,10 +781,12 @@ bool ScriptMgr::OnGossipHello(Player* player, Creature* creature)
|
|||||||
ASSERT(player);
|
ASSERT(player);
|
||||||
ASSERT(creature);
|
ASSERT(creature);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<AllCreatureScript>(false, [&](AllCreatureScript* script)
|
auto ret = IsValidBoolScript<AllCreatureScript>([&](AllCreatureScript* script)
|
||||||
{
|
{
|
||||||
return script->CanCreatureGossipHello(player, creature);
|
return script->CanCreatureGossipHello(player, creature);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -799,10 +801,12 @@ bool ScriptMgr::OnGossipSelect(Player* player, Creature* creature, uint32 sender
|
|||||||
ASSERT(player);
|
ASSERT(player);
|
||||||
ASSERT(creature);
|
ASSERT(creature);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<AllCreatureScript>(false, [&](AllCreatureScript* script)
|
auto ret = IsValidBoolScript<AllCreatureScript>([&](AllCreatureScript* script)
|
||||||
{
|
{
|
||||||
return script->CanCreatureGossipSelect(player, creature, sender, action);
|
return script->CanCreatureGossipSelect(player, creature, sender, action);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -817,10 +821,12 @@ bool ScriptMgr::OnGossipSelectCode(Player* player, Creature* creature, uint32 se
|
|||||||
ASSERT(creature);
|
ASSERT(creature);
|
||||||
ASSERT(code);
|
ASSERT(code);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<AllCreatureScript>(false, [&](AllCreatureScript* script)
|
auto ret = IsValidBoolScript<AllCreatureScript>([&](AllCreatureScript* script)
|
||||||
{
|
{
|
||||||
return script->CanCreatureGossipSelectCode(player, creature, sender, action, code);
|
return script->CanCreatureGossipSelectCode(player, creature, sender, action, code);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -835,10 +841,12 @@ bool ScriptMgr::OnQuestAccept(Player* player, Creature* creature, Quest const* q
|
|||||||
ASSERT(creature);
|
ASSERT(creature);
|
||||||
ASSERT(quest);
|
ASSERT(quest);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<AllCreatureScript>(false, [&](AllCreatureScript* script)
|
auto ret = IsValidBoolScript<AllCreatureScript>([&](AllCreatureScript* script)
|
||||||
{
|
{
|
||||||
return script->CanCreatureQuestAccept(player, creature, quest);
|
return script->CanCreatureQuestAccept(player, creature, quest);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -876,10 +884,12 @@ bool ScriptMgr::OnQuestReward(Player* player, Creature* creature, Quest const* q
|
|||||||
ASSERT(creature);
|
ASSERT(creature);
|
||||||
ASSERT(quest);
|
ASSERT(quest);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<AllCreatureScript>(false, [&](AllCreatureScript* script)
|
auto ret = IsValidBoolScript<AllCreatureScript>([&](AllCreatureScript* script)
|
||||||
{
|
{
|
||||||
return script->CanCreatureQuestReward(player, creature, quest, opt);
|
return script->CanCreatureQuestReward(player, creature, quest, opt);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -946,10 +956,12 @@ bool ScriptMgr::OnGossipHello(Player* player, GameObject* go)
|
|||||||
ASSERT(player);
|
ASSERT(player);
|
||||||
ASSERT(go);
|
ASSERT(go);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<AllGameObjectScript>(false, [&](AllGameObjectScript* script)
|
auto ret = IsValidBoolScript<AllGameObjectScript>([&](AllGameObjectScript* script)
|
||||||
{
|
{
|
||||||
return script->CanGameObjectGossipHello(player, go);
|
return script->CanGameObjectGossipHello(player, go);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -964,10 +976,12 @@ bool ScriptMgr::OnGossipSelect(Player* player, GameObject* go, uint32 sender, ui
|
|||||||
ASSERT(player);
|
ASSERT(player);
|
||||||
ASSERT(go);
|
ASSERT(go);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<AllGameObjectScript>(false, [&](AllGameObjectScript* script)
|
auto ret = IsValidBoolScript<AllGameObjectScript>([&](AllGameObjectScript* script)
|
||||||
{
|
{
|
||||||
return script->CanGameObjectGossipSelect(player, go, sender, action);
|
return script->CanGameObjectGossipSelect(player, go, sender, action);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -982,10 +996,12 @@ bool ScriptMgr::OnGossipSelectCode(Player* player, GameObject* go, uint32 sender
|
|||||||
ASSERT(go);
|
ASSERT(go);
|
||||||
ASSERT(code);
|
ASSERT(code);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<AllGameObjectScript>(false, [&](AllGameObjectScript* script)
|
auto ret = IsValidBoolScript<AllGameObjectScript>([&](AllGameObjectScript* script)
|
||||||
{
|
{
|
||||||
return script->CanGameObjectGossipSelectCode(player, go, sender, action, code);
|
return script->CanGameObjectGossipSelectCode(player, go, sender, action, code);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1000,10 +1016,12 @@ bool ScriptMgr::OnQuestAccept(Player* player, GameObject* go, Quest const* quest
|
|||||||
ASSERT(go);
|
ASSERT(go);
|
||||||
ASSERT(quest);
|
ASSERT(quest);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<AllGameObjectScript>(false, [&](AllGameObjectScript* script)
|
auto ret = IsValidBoolScript<AllGameObjectScript>([&](AllGameObjectScript* script)
|
||||||
{
|
{
|
||||||
return script->CanGameObjectQuestAccept(player, go, quest);
|
return script->CanGameObjectQuestAccept(player, go, quest);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1019,10 +1037,12 @@ bool ScriptMgr::OnQuestReward(Player* player, GameObject* go, Quest const* quest
|
|||||||
ASSERT(go);
|
ASSERT(go);
|
||||||
ASSERT(quest);
|
ASSERT(quest);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<AllGameObjectScript>(false, [&](AllGameObjectScript* script)
|
auto ret = IsValidBoolScript<AllGameObjectScript>([&](AllGameObjectScript* script)
|
||||||
{
|
{
|
||||||
return script->CanGameObjectQuestReward(player, go, quest, opt);
|
return script->CanGameObjectQuestReward(player, go, quest, opt);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1129,10 +1149,12 @@ bool ScriptMgr::OnAreaTrigger(Player* player, AreaTrigger const* trigger)
|
|||||||
ASSERT(player);
|
ASSERT(player);
|
||||||
ASSERT(trigger);
|
ASSERT(trigger);
|
||||||
|
|
||||||
if (GetReturnBoolScripts<ElunaScript>(false, [&](ElunaScript* script)
|
auto ret = IsValidBoolScript<ElunaScript>([&](ElunaScript* script)
|
||||||
{
|
{
|
||||||
return script->CanAreaTrigger(player, trigger);
|
return script->CanAreaTrigger(player, trigger);
|
||||||
}))
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,20 +21,18 @@
|
|||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
|
|
||||||
template<typename ScriptName, typename TCallBack>
|
template<typename ScriptName, typename TCallBack>
|
||||||
inline bool GetReturnBoolScripts(bool ret, TCallBack&& callback)
|
inline Optional<bool> IsValidBoolScript(TCallBack&& callback)
|
||||||
{
|
{
|
||||||
if (ScriptRegistry<ScriptName>::ScriptPointerList.empty())
|
if (ScriptRegistry<ScriptName>::ScriptPointerList.empty())
|
||||||
return ret;
|
return {};
|
||||||
|
|
||||||
bool needReturn = !ret;
|
|
||||||
|
|
||||||
for (auto const& [scriptID, script] : ScriptRegistry<ScriptName>::ScriptPointerList)
|
for (auto const& [scriptID, script] : ScriptRegistry<ScriptName>::ScriptPointerList)
|
||||||
{
|
{
|
||||||
if (callback(script))
|
if (callback(script))
|
||||||
return needReturn;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ScriptName, class T, typename TCallBack>
|
template<class ScriptName, class T, typename TCallBack>
|
||||||
|
|||||||
Reference in New Issue
Block a user