mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 15:40:45 +01:00
Core/AreaTriggers: Areatrigger rework script system + fix priest angelic feather
Closes #19171
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "MapManager.h"
|
||||
#include "LFGScripts.h"
|
||||
#include "InstanceScript.h"
|
||||
#include "AreaTriggerAI.h"
|
||||
|
||||
// Trait which indicates whether this script type
|
||||
// must be assigned in the database.
|
||||
@@ -332,9 +333,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/// This hook is responsible for swapping Creature and GameObject AI's
|
||||
/// This hook is responsible for swapping Creature, GameObject and AreaTrigger AI's
|
||||
template<typename ObjectType, typename ScriptType, typename Base>
|
||||
class CreatureGameObjectScriptRegistrySwapHooks
|
||||
class CreatureGameObjectAreaTriggerScriptRegistrySwapHooks
|
||||
: public ScriptRegistrySwapHookBase
|
||||
{
|
||||
template<typename W>
|
||||
@@ -413,6 +414,20 @@ class CreatureGameObjectScriptRegistrySwapHooks
|
||||
"The AI should be null here!");
|
||||
}
|
||||
|
||||
// Hook which is called before a areatrigger is swapped
|
||||
static void UnloadResetScript(AreaTrigger* at)
|
||||
{
|
||||
at->AI()->OnRemove();
|
||||
}
|
||||
|
||||
static void UnloadDestroyScript(AreaTrigger* at)
|
||||
{
|
||||
at->AI_Destroy();
|
||||
|
||||
ASSERT(!at->AI(),
|
||||
"The AI should be null here!");
|
||||
}
|
||||
|
||||
// Hook which is called after a creature was swapped
|
||||
static void LoadInitializeScript(Creature* creature)
|
||||
{
|
||||
@@ -455,6 +470,20 @@ class CreatureGameObjectScriptRegistrySwapHooks
|
||||
gameobject->AI()->Reset();
|
||||
}
|
||||
|
||||
// Hook which is called after a areatrigger was swapped
|
||||
static void LoadInitializeScript(AreaTrigger* at)
|
||||
{
|
||||
ASSERT(!at->AI(),
|
||||
"The AI should be null here!");
|
||||
|
||||
at->AI_Initialize();
|
||||
}
|
||||
|
||||
static void LoadResetScript(AreaTrigger* at)
|
||||
{
|
||||
at->AI()->OnCreate();
|
||||
}
|
||||
|
||||
static Creature* GetEntityFromMap(std::common_type<Creature>, Map* map, ObjectGuid const& guid)
|
||||
{
|
||||
return map->GetCreature(guid);
|
||||
@@ -465,6 +494,11 @@ class CreatureGameObjectScriptRegistrySwapHooks
|
||||
return map->GetGameObject(guid);
|
||||
}
|
||||
|
||||
static AreaTrigger* GetEntityFromMap(std::common_type<AreaTrigger>, Map* map, ObjectGuid const& guid)
|
||||
{
|
||||
return map->GetAreaTrigger(guid);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void VisitObjectsToSwapOnMap(Map* map, std::unordered_set<uint32> const& idsToRemove, T visitor)
|
||||
{
|
||||
@@ -583,17 +617,24 @@ private:
|
||||
// This hook is responsible for swapping CreatureAI's
|
||||
template<typename Base>
|
||||
class ScriptRegistrySwapHooks<CreatureScript, Base>
|
||||
: public CreatureGameObjectScriptRegistrySwapHooks<
|
||||
: public CreatureGameObjectAreaTriggerScriptRegistrySwapHooks<
|
||||
Creature, CreatureScript, Base
|
||||
> { };
|
||||
|
||||
// This hook is responsible for swapping GameObjectAI's
|
||||
template<typename Base>
|
||||
class ScriptRegistrySwapHooks<GameObjectScript, Base>
|
||||
: public CreatureGameObjectScriptRegistrySwapHooks<
|
||||
: public CreatureGameObjectAreaTriggerScriptRegistrySwapHooks<
|
||||
GameObject, GameObjectScript, Base
|
||||
> { };
|
||||
|
||||
// This hook is responsible for swapping AreaTriggerAI's
|
||||
template<typename Base>
|
||||
class ScriptRegistrySwapHooks<AreaTriggerEntityScript, Base>
|
||||
: public CreatureGameObjectAreaTriggerScriptRegistrySwapHooks<
|
||||
AreaTrigger, AreaTriggerEntityScript, Base
|
||||
> { };
|
||||
|
||||
/// This hook is responsible for swapping BattlegroundScript's
|
||||
template<typename Base>
|
||||
class ScriptRegistrySwapHooks<BattlegroundScript, Base>
|
||||
@@ -666,35 +707,6 @@ private:
|
||||
bool swapped;
|
||||
};
|
||||
|
||||
/// This hook is responsible for swapping AreaTriggerEntityScript's
|
||||
template<typename Base>
|
||||
class ScriptRegistrySwapHooks<AreaTriggerEntityScript, Base>
|
||||
: public ScriptRegistrySwapHookBase
|
||||
{
|
||||
public:
|
||||
ScriptRegistrySwapHooks() : swapped(false) { }
|
||||
|
||||
void BeforeReleaseContext(std::string const& context) final override
|
||||
{
|
||||
auto const bounds = static_cast<Base*>(this)->_ids_of_contexts.equal_range(context);
|
||||
if (bounds.first != bounds.second)
|
||||
swapped = true;
|
||||
}
|
||||
|
||||
void BeforeSwapContext(bool /*initialize*/) override
|
||||
{
|
||||
swapped = false;
|
||||
}
|
||||
|
||||
void BeforeUnload() final override
|
||||
{
|
||||
ASSERT(!swapped);
|
||||
}
|
||||
|
||||
private:
|
||||
bool swapped;
|
||||
};
|
||||
|
||||
/// This hook is responsible for swapping SceneScript's
|
||||
template<typename Base>
|
||||
class ScriptRegistrySwapHooks<SceneScript, Base>
|
||||
@@ -771,7 +783,7 @@ class SpecializedScriptRegistry<ScriptType, true>
|
||||
friend class ScriptRegistrySwapHooks;
|
||||
|
||||
template<typename, typename, typename>
|
||||
friend class CreatureGameObjectScriptRegistrySwapHooks;
|
||||
friend class CreatureGameObjectAreaTriggerScriptRegistrySwapHooks;
|
||||
|
||||
public:
|
||||
SpecializedScriptRegistry() { }
|
||||
@@ -1734,6 +1746,14 @@ GameObjectAI* ScriptMgr::GetGameObjectAI(GameObject* gameobject)
|
||||
return tmpscript->GetAI(gameobject);
|
||||
}
|
||||
|
||||
AreaTriggerAI* ScriptMgr::GetAreaTriggerAI(AreaTrigger* areatrigger)
|
||||
{
|
||||
ASSERT(areatrigger);
|
||||
|
||||
GET_SCRIPT_RET(AreaTriggerEntityScript, areatrigger->GetScriptId(), tmpscript, NULL);
|
||||
return tmpscript->GetAI(areatrigger);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnCreatureUpdate(Creature* creature, uint32 diff)
|
||||
{
|
||||
ASSERT(creature);
|
||||
@@ -2382,73 +2402,6 @@ void ScriptMgr::ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& dama
|
||||
FOREACH_SCRIPT(PlayerScript)->ModifySpellDamageTaken(target, attacker, damage);
|
||||
}
|
||||
|
||||
// AreaTriggerEntityScript
|
||||
void ScriptMgr::OnAreaTriggerEntityInitialize(AreaTrigger* areaTrigger)
|
||||
{
|
||||
ASSERT(areaTrigger);
|
||||
|
||||
GET_SCRIPT(AreaTriggerEntityScript, areaTrigger->GetScriptId(), tmpscript);
|
||||
tmpscript->OnInitialize(areaTrigger);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAreaTriggerEntityCreate(AreaTrigger* areaTrigger)
|
||||
{
|
||||
ASSERT(areaTrigger);
|
||||
|
||||
GET_SCRIPT(AreaTriggerEntityScript, areaTrigger->GetScriptId(), tmpscript);
|
||||
tmpscript->OnCreate(areaTrigger);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAreaTriggerEntityUpdate(AreaTrigger* areaTrigger, uint32 diff)
|
||||
{
|
||||
ASSERT(areaTrigger);
|
||||
|
||||
GET_SCRIPT(AreaTriggerEntityScript, areaTrigger->GetScriptId(), tmpscript);
|
||||
tmpscript->OnUpdate(areaTrigger, diff);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAreaTriggerEntitySplineIndexReached(AreaTrigger* areaTrigger, int splineIndex)
|
||||
{
|
||||
ASSERT(areaTrigger);
|
||||
|
||||
GET_SCRIPT(AreaTriggerEntityScript, areaTrigger->GetScriptId(), tmpscript);
|
||||
tmpscript->OnSplineIndexReached(areaTrigger, splineIndex);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAreaTriggerEntityDestinationReached(AreaTrigger* areaTrigger)
|
||||
{
|
||||
ASSERT(areaTrigger);
|
||||
|
||||
GET_SCRIPT(AreaTriggerEntityScript, areaTrigger->GetScriptId(), tmpscript);
|
||||
tmpscript->OnDestinationReached(areaTrigger);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAreaTriggerEntityUnitEnter(AreaTrigger* areaTrigger, Unit* unit)
|
||||
{
|
||||
ASSERT(areaTrigger);
|
||||
ASSERT(unit);
|
||||
|
||||
GET_SCRIPT(AreaTriggerEntityScript, areaTrigger->GetScriptId(), tmpscript);
|
||||
tmpscript->OnUnitEnter(areaTrigger, unit);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAreaTriggerEntityUnitExit(AreaTrigger* areaTrigger, Unit* unit)
|
||||
{
|
||||
ASSERT(areaTrigger);
|
||||
ASSERT(unit);
|
||||
|
||||
GET_SCRIPT(AreaTriggerEntityScript, areaTrigger->GetScriptId(), tmpscript);
|
||||
tmpscript->OnUnitExit(areaTrigger, unit);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAreaTriggerEntityRemove(AreaTrigger* areaTrigger)
|
||||
{
|
||||
ASSERT(areaTrigger);
|
||||
|
||||
GET_SCRIPT(AreaTriggerEntityScript, areaTrigger->GetScriptId(), tmpscript);
|
||||
tmpscript->OnRemove(areaTrigger);
|
||||
}
|
||||
|
||||
// Scene
|
||||
void ScriptMgr::OnSceneStart(Player* player, uint32 sceneInstanceID, SceneTemplate const* sceneTemplate)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user