aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2022-04-24 00:16:13 +0200
committerShauren <shauren.trinity@gmail.com>2022-04-24 00:16:13 +0200
commit41a04a0c496c8c0c521eeaa76e34fbeb531cc1d9 (patch)
tree481a8faf79ea916afa5c08dc6c4d8cb80addda68 /src/server/game/Entities
parentfddd6cdf3fb342b98d4878d23874f60498d7545a (diff)
Core/Scripts: Begin unifying triggering gameevents (not the game_event db stuff)
Diffstat (limited to 'src/server/game/Entities')
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp56
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h2
-rw-r--r--src/server/game/Entities/Object/Object.cpp14
-rw-r--r--src/server/game/Entities/Object/Object.h1
-rw-r--r--src/server/game/Entities/Transport/Transport.cpp4
5 files changed, 36 insertions, 41 deletions
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index 3996591d41d..f87dce96843 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -25,6 +25,7 @@
#include "CreatureAISelector.h"
#include "DatabaseEnv.h"
#include "DB2Stores.h"
+#include "GameEventSender.h"
#include "GameObjectAI.h"
#include "GameObjectModel.h"
#include "GameObjectPackets.h"
@@ -812,8 +813,9 @@ void GameObject::Update(uint32 diff)
{
if (Battleground* bg = map->GetBG())
{
- EventInform(GetGOInfo()->capturePoint.CaptureEventHorde);
- bg->SendBroadcastText(GetGOInfo()->capturePoint.CaptureBroadcastHorde, CHAT_MSG_BG_SYSTEM_HORDE);
+ if (goInfo->capturePoint.CaptureEventHorde)
+ GameEvents::Trigger(goInfo->capturePoint.CaptureEventHorde, this, this);
+ bg->SendBroadcastText(goInfo->capturePoint.CaptureBroadcastHorde, CHAT_MSG_BG_SYSTEM_HORDE);
}
}
}
@@ -824,8 +826,9 @@ void GameObject::Update(uint32 diff)
{
if (Battleground* bg = map->GetBG())
{
- EventInform(GetGOInfo()->capturePoint.CaptureEventAlliance);
- bg->SendBroadcastText(GetGOInfo()->capturePoint.CaptureBroadcastAlliance, CHAT_MSG_BG_SYSTEM_ALLIANCE);
+ if (goInfo->capturePoint.CaptureEventAlliance)
+ GameEvents::Trigger(goInfo->capturePoint.CaptureEventAlliance, this, this);
+ bg->SendBroadcastText(goInfo->capturePoint.CaptureBroadcastAlliance, CHAT_MSG_BG_SYSTEM_ALLIANCE);
}
}
}
@@ -1976,8 +1979,7 @@ void GameObject::Use(Unit* user)
if (info->goober.eventID)
{
TC_LOG_DEBUG("maps.script", "Goober ScriptStart id %u for GO entry %u (GUID " UI64FMTD ").", info->goober.eventID, GetEntry(), GetSpawnId());
- GetMap()->ScriptsStart(sEventScripts, info->goober.eventID, player, this);
- EventInform(info->goober.eventID, user);
+ GameEvents::Trigger(info->goober.eventID, player, this);
}
// possible quest objective for active quests
@@ -2034,10 +2036,7 @@ void GameObject::Use(Unit* user)
player->SendCinematicStart(info->camera.camera);
if (info->camera.eventID)
- {
- GetMap()->ScriptsStart(sEventScripts, info->camera.eventID, player, this);
- EventInform(info->camera.eventID, user);
- }
+ GameEvents::Trigger(info->camera.eventID, player, this);
return;
}
@@ -2525,22 +2524,6 @@ bool GameObject::IsInRange(float x, float y, float z, float radius) const
&& dz < info->GeoBoxMax.Z + radius && dz > info->GeoBoxMin.Z - radius;
}
-void GameObject::EventInform(uint32 eventId, WorldObject* invoker /*= nullptr*/)
-{
- if (!eventId)
- return;
-
- if (AI())
- AI()->EventInform(eventId);
-
- if (GetZoneScript())
- GetZoneScript()->ProcessEvent(this, eventId, invoker);
-
- if (BattlegroundMap* bgMap = GetMap()->ToBattlegroundMap())
- if (bgMap->GetBG())
- bgMap->GetBG()->ProcessEvent(this, eventId, invoker);
-}
-
uint32 GameObject::GetScriptId() const
{
if (GameObjectData const* gameObjectData = GetGameObjectData())
@@ -2680,7 +2663,8 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, WorldOb
break;
case GO_DESTRUCTIBLE_DAMAGED:
{
- EventInform(m_goInfo->destructibleBuilding.DamagedEvent, attackerOrHealer);
+ if (GetGOInfo()->destructibleBuilding.DamagedEvent)
+ GameEvents::Trigger(GetGOInfo()->destructibleBuilding.DamagedEvent, attackerOrHealer, this);
AI()->Damaged(attackerOrHealer, m_goInfo->destructibleBuilding.DamagedEvent);
RemoveFlag(GO_FLAG_DESTROYED);
@@ -2705,7 +2689,8 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, WorldOb
}
case GO_DESTRUCTIBLE_DESTROYED:
{
- EventInform(m_goInfo->destructibleBuilding.DestroyedEvent, attackerOrHealer);
+ if (GetGOInfo()->destructibleBuilding.DestroyedEvent)
+ GameEvents::Trigger(GetGOInfo()->destructibleBuilding.DestroyedEvent, attackerOrHealer, this);
AI()->Destroyed(attackerOrHealer, m_goInfo->destructibleBuilding.DestroyedEvent);
if (Player* player = attackerOrHealer ? attackerOrHealer->GetCharmerOrOwnerPlayerOrPlayerItself() : nullptr)
@@ -2731,7 +2716,8 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, WorldOb
}
case GO_DESTRUCTIBLE_REBUILDING:
{
- EventInform(m_goInfo->destructibleBuilding.RebuildingEvent, attackerOrHealer);
+ if (GetGOInfo()->destructibleBuilding.RebuildingEvent)
+ GameEvents::Trigger(GetGOInfo()->destructibleBuilding.RebuildingEvent, attackerOrHealer, this);
RemoveFlag(GO_FLAG_DAMAGED | GO_FLAG_DESTROYED);
uint32 modelId = m_goInfo->displayId;
@@ -3164,7 +3150,8 @@ void GameObject::AssaultCapturePoint(Player* player)
m_goValue.CapturePoint.State = WorldPackets::Battleground::BattlegroundCapturePointState::HordeCaptured;
battleground->SendBroadcastText(GetGOInfo()->capturePoint.DefendedBroadcastHorde, CHAT_MSG_BG_SYSTEM_HORDE, player);
UpdateCapturePoint();
- EventInform(GetGOInfo()->capturePoint.DefendedEventHorde, player);
+ if (GetGOInfo()->capturePoint.DefendedEventHorde)
+ GameEvents::Trigger(GetGOInfo()->capturePoint.DefendedEventHorde, player, this);
return;
}
@@ -3176,7 +3163,8 @@ void GameObject::AssaultCapturePoint(Player* player)
m_goValue.CapturePoint.State = WorldPackets::Battleground::BattlegroundCapturePointState::ContestedHorde;
battleground->SendBroadcastText(GetGOInfo()->capturePoint.AssaultBroadcastHorde, CHAT_MSG_BG_SYSTEM_HORDE, player);
UpdateCapturePoint();
- EventInform(GetGOInfo()->capturePoint.AssaultBroadcastHorde, player);
+ if (GetGOInfo()->capturePoint.ContestedEventHorde)
+ GameEvents::Trigger(GetGOInfo()->capturePoint.ContestedEventHorde, player, this);
m_goValue.CapturePoint.AssaultTimer = GetGOInfo()->capturePoint.CaptureTime;
break;
default:
@@ -3191,7 +3179,8 @@ void GameObject::AssaultCapturePoint(Player* player)
m_goValue.CapturePoint.State = WorldPackets::Battleground::BattlegroundCapturePointState::AllianceCaptured;
battleground->SendBroadcastText(GetGOInfo()->capturePoint.DefendedBroadcastAlliance, CHAT_MSG_BG_SYSTEM_ALLIANCE, player);
UpdateCapturePoint();
- EventInform(GetGOInfo()->capturePoint.DefendedEventAlliance, player);
+ if (GetGOInfo()->capturePoint.DefendedEventAlliance)
+ GameEvents::Trigger(GetGOInfo()->capturePoint.DefendedEventAlliance, player, this);
return;
}
@@ -3203,7 +3192,8 @@ void GameObject::AssaultCapturePoint(Player* player)
m_goValue.CapturePoint.State = WorldPackets::Battleground::BattlegroundCapturePointState::ContestedAlliance;
battleground->SendBroadcastText(GetGOInfo()->capturePoint.AssaultBroadcastAlliance, CHAT_MSG_BG_SYSTEM_ALLIANCE, player);
UpdateCapturePoint();
- EventInform(GetGOInfo()->capturePoint.ContestedEventAlliance, player);
+ if (GetGOInfo()->capturePoint.ContestedEventAlliance)
+ GameEvents::Trigger(GetGOInfo()->capturePoint.ContestedEventAlliance, player, this);
m_goValue.CapturePoint.AssaultTimer = GetGOInfo()->capturePoint.CaptureTime;
break;
default:
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index b032b0018bb..77c5385ccaa 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -295,8 +295,6 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
return GO_DESTRUCTIBLE_INTACT;
}
- void EventInform(uint32 eventId, WorldObject* invoker = nullptr);
-
// There's many places not ready for dynamic spawns. This allows them to live on for now.
void SetRespawnCompatibilityMode(bool mode = true) { m_respawnCompatibilityMode = mode; }
bool GetRespawnCompatibilityMode() {return m_respawnCompatibilityMode; }
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index aede0b4276f..59b82508f79 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -1921,20 +1921,26 @@ void Map::SummonCreatureGroup(uint8 group, std::list<TempSummon*>* list /*= null
list->push_back(summon);
}
-void WorldObject::SetZoneScript()
+ZoneScript* WorldObject::FindZoneScript() const
{
if (Map* map = FindMap())
{
if (InstanceMap* instanceMap = map->ToInstanceMap())
- m_zoneScript = reinterpret_cast<ZoneScript*>(instanceMap->GetInstanceScript());
+ return reinterpret_cast<ZoneScript*>(instanceMap->GetInstanceScript());
else if (!map->IsBattlegroundOrArena())
{
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(GetZoneId()))
- m_zoneScript = bf;
+ return bf;
else
- m_zoneScript = sOutdoorPvPMgr->GetZoneScript(GetZoneId());
+ return sOutdoorPvPMgr->GetZoneScript(GetZoneId());
}
}
+ return nullptr;
+}
+
+void WorldObject::SetZoneScript()
+{
+ m_zoneScript = FindZoneScript();
}
Scenario* WorldObject::GetScenario() const
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index cd1e47ca26a..8317e80f0b3 100644
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -557,6 +557,7 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
//used to check all object's GetMap() calls when object is not in world!
void SetZoneScript();
+ ZoneScript* FindZoneScript() const;
ZoneScript* GetZoneScript() const { return m_zoneScript; }
Scenario* GetScenario() const;
diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp
index 7046723c4bd..b61722ab83d 100644
--- a/src/server/game/Entities/Transport/Transport.cpp
+++ b/src/server/game/Entities/Transport/Transport.cpp
@@ -19,6 +19,7 @@
#include "Cell.h"
#include "CellImpl.h"
#include "Common.h"
+#include "GameEventSender.h"
#include "GameObjectAI.h"
#include "Log.h"
#include "MapManager.h"
@@ -759,8 +760,7 @@ void Transport::DoEventIfAny(KeyFrame const& node, bool departure)
if (uint32 eventid = departure ? node.Node->DepartureEventID : node.Node->ArrivalEventID)
{
TC_LOG_DEBUG("maps.script", "Taxi %s event %u of node %u of %s path", departure ? "departure" : "arrival", eventid, node.Node->NodeIndex, GetName().c_str());
- GetMap()->ScriptsStart(sEventScripts, eventid, this, this);
- EventInform(eventid);
+ GameEvents::Trigger(eventid, this, this);
}
}