Core/Scripts: Begin unifying triggering gameevents (not the game_event db stuff)
Port From (https://github.com/TrinityCore/TrinityCore/commit/41a04a0c496c8c0c521eeaa76e34fbeb531cc1d9)
This commit is contained in:
@@ -707,7 +707,8 @@ namespace Game.Entities
|
||||
Battleground bg = map.GetBG();
|
||||
if (bg != null)
|
||||
{
|
||||
EventInform(GetGoInfo().CapturePoint.CaptureEventHorde);
|
||||
if (goInfo.CapturePoint.CaptureEventHorde != 0)
|
||||
GameEvents.Trigger(goInfo.CapturePoint.CaptureEventHorde, this, this);
|
||||
bg.SendBroadcastText(GetGoInfo().CapturePoint.CaptureBroadcastHorde, ChatMsg.BgSystemHorde);
|
||||
}
|
||||
}
|
||||
@@ -721,7 +722,8 @@ namespace Game.Entities
|
||||
Battleground bg = map.GetBG();
|
||||
if (bg != null)
|
||||
{
|
||||
EventInform(GetGoInfo().CapturePoint.CaptureEventAlliance);
|
||||
if (goInfo.CapturePoint.CaptureEventAlliance != 0)
|
||||
GameEvents.Trigger(goInfo.CapturePoint.CaptureEventAlliance, this, this);
|
||||
bg.SendBroadcastText(GetGoInfo().CapturePoint.CaptureBroadcastAlliance, ChatMsg.BgSystemAlliance);
|
||||
}
|
||||
}
|
||||
@@ -1830,8 +1832,7 @@ namespace Game.Entities
|
||||
if (info.Goober.eventID != 0)
|
||||
{
|
||||
Log.outDebug(LogFilter.Scripts, "Goober ScriptStart id {0} for GO entry {1} (GUID {2}).", info.Goober.eventID, GetEntry(), GetSpawnId());
|
||||
GetMap().ScriptsStart(ScriptsType.Event, info.Goober.eventID, player, this);
|
||||
EventInform(info.Goober.eventID, user);
|
||||
GameEvents.Trigger(info.Goober.eventID, player, this);
|
||||
}
|
||||
|
||||
// possible quest objective for active quests
|
||||
@@ -1893,10 +1894,7 @@ namespace Game.Entities
|
||||
player.SendCinematicStart(info.Camera._camera);
|
||||
|
||||
if (info.Camera.eventID != 0)
|
||||
{
|
||||
GetMap().ScriptsStart(ScriptsType.Event, info.Camera.eventID, player, this);
|
||||
EventInform(info.Camera.eventID, user);
|
||||
}
|
||||
GameEvents.Trigger(info.Camera.eventID, player, this);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -2382,23 +2380,6 @@ namespace Game.Entities
|
||||
&& dz < info.GeoBoxMax.Z + radius && dz > info.GeoBoxMin.Z - radius;
|
||||
}
|
||||
|
||||
public void EventInform(uint eventId, WorldObject invoker = null)
|
||||
{
|
||||
if (eventId == 0)
|
||||
return;
|
||||
|
||||
if (GetAI() != null)
|
||||
GetAI().EventInform(eventId);
|
||||
|
||||
if (m_zoneScript != null)
|
||||
m_zoneScript.ProcessEvent(this, eventId, invoker);
|
||||
|
||||
BattlegroundMap bgMap = GetMap().ToBattlegroundMap();
|
||||
if (bgMap)
|
||||
if (bgMap.GetBG())
|
||||
bgMap.GetBG().ProcessEvent(this, eventId, invoker);
|
||||
}
|
||||
|
||||
public uint GetScriptId()
|
||||
{
|
||||
GameObjectData gameObjectData = GetGameObjectData();
|
||||
@@ -2644,7 +2625,8 @@ namespace Game.Entities
|
||||
break;
|
||||
case GameObjectDestructibleState.Damaged:
|
||||
{
|
||||
EventInform(m_goInfo.DestructibleBuilding.DamagedEvent, attackerOrHealer);
|
||||
if (GetGoInfo().DestructibleBuilding.DamagedEvent != 0)
|
||||
GameEvents.Trigger(GetGoInfo().DestructibleBuilding.DamagedEvent, attackerOrHealer, this);
|
||||
GetAI().Damaged(attackerOrHealer, m_goInfo.DestructibleBuilding.DamagedEvent);
|
||||
|
||||
RemoveFlag(GameObjectFlags.Destroyed);
|
||||
@@ -2670,7 +2652,8 @@ namespace Game.Entities
|
||||
}
|
||||
case GameObjectDestructibleState.Destroyed:
|
||||
{
|
||||
EventInform(m_goInfo.DestructibleBuilding.DestroyedEvent, attackerOrHealer);
|
||||
if (GetGoInfo().DestructibleBuilding.DestroyedEvent != 0)
|
||||
GameEvents.Trigger(GetGoInfo().DestructibleBuilding.DestroyedEvent, attackerOrHealer, this);
|
||||
GetAI().Destroyed(attackerOrHealer, m_goInfo.DestructibleBuilding.DestroyedEvent);
|
||||
|
||||
Player player = attackerOrHealer != null ? attackerOrHealer.GetCharmerOrOwnerPlayerOrPlayerItself() : null;
|
||||
@@ -2701,7 +2684,8 @@ namespace Game.Entities
|
||||
}
|
||||
case GameObjectDestructibleState.Rebuilding:
|
||||
{
|
||||
EventInform(m_goInfo.DestructibleBuilding.RebuildingEvent, attackerOrHealer);
|
||||
if (GetGoInfo().DestructibleBuilding.RebuildingEvent != 0)
|
||||
GameEvents.Trigger(GetGoInfo().DestructibleBuilding.RebuildingEvent, attackerOrHealer, this);
|
||||
RemoveFlag(GameObjectFlags.Damaged | GameObjectFlags.Destroyed);
|
||||
|
||||
uint modelId = m_goInfo.displayId;
|
||||
@@ -3115,7 +3099,8 @@ namespace Game.Entities
|
||||
m_goValue.CapturePoint.State = BattlegroundCapturePointState.HordeCaptured;
|
||||
battleground.SendBroadcastText(GetGoInfo().CapturePoint.DefendedBroadcastHorde, ChatMsg.BgSystemHorde, player);
|
||||
UpdateCapturePoint();
|
||||
EventInform(GetGoInfo().CapturePoint.DefendedEventHorde, player);
|
||||
if (GetGoInfo().CapturePoint.DefendedEventHorde != 0)
|
||||
GameEvents.Trigger(GetGoInfo().CapturePoint.DefendedEventHorde, player, this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3127,7 +3112,8 @@ namespace Game.Entities
|
||||
m_goValue.CapturePoint.State = BattlegroundCapturePointState.ContestedHorde;
|
||||
battleground.SendBroadcastText(GetGoInfo().CapturePoint.AssaultBroadcastHorde, ChatMsg.BgSystemHorde, player);
|
||||
UpdateCapturePoint();
|
||||
EventInform(GetGoInfo().CapturePoint.AssaultBroadcastHorde, player);
|
||||
if (GetGoInfo().CapturePoint.ContestedEventHorde != 0)
|
||||
GameEvents.Trigger(GetGoInfo().CapturePoint.ContestedEventHorde, player, this);
|
||||
m_goValue.CapturePoint.AssaultTimer = GetGoInfo().CapturePoint.CaptureTime;
|
||||
break;
|
||||
default:
|
||||
@@ -3142,7 +3128,8 @@ namespace Game.Entities
|
||||
m_goValue.CapturePoint.State = BattlegroundCapturePointState.AllianceCaptured;
|
||||
battleground.SendBroadcastText(GetGoInfo().CapturePoint.DefendedBroadcastAlliance, ChatMsg.BgSystemAlliance, player);
|
||||
UpdateCapturePoint();
|
||||
EventInform(GetGoInfo().CapturePoint.DefendedEventAlliance, player);
|
||||
if (GetGoInfo().CapturePoint.DefendedEventAlliance != 0)
|
||||
GameEvents.Trigger(GetGoInfo().CapturePoint.DefendedEventAlliance, player, this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3154,7 +3141,8 @@ namespace Game.Entities
|
||||
m_goValue.CapturePoint.State = BattlegroundCapturePointState.ContestedAlliance;
|
||||
battleground.SendBroadcastText(GetGoInfo().CapturePoint.AssaultBroadcastAlliance, ChatMsg.BgSystemAlliance, player);
|
||||
UpdateCapturePoint();
|
||||
EventInform(GetGoInfo().CapturePoint.ContestedEventAlliance, player);
|
||||
if (GetGoInfo().CapturePoint.ContestedEventAlliance != 0)
|
||||
GameEvents.Trigger(GetGoInfo().CapturePoint.ContestedEventAlliance, player, this);
|
||||
m_goValue.CapturePoint.AssaultTimer = GetGoInfo().CapturePoint.CaptureTime;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1451,23 +1451,30 @@ namespace Game.Entities
|
||||
map.AddObjectToRemoveList(this);
|
||||
}
|
||||
|
||||
public void SetZoneScript()
|
||||
public ZoneScript FindZoneScript()
|
||||
{
|
||||
Map map = GetMap();
|
||||
if (map != null)
|
||||
{
|
||||
InstanceMap instanceMap = map.ToInstanceMap();
|
||||
if (instanceMap != null)
|
||||
m_zoneScript = (ZoneScript)instanceMap.GetInstanceScript();
|
||||
return (ZoneScript)instanceMap.GetInstanceScript();
|
||||
else if (!map.IsBattlegroundOrArena())
|
||||
{
|
||||
BattleField bf = Global.BattleFieldMgr.GetBattlefieldToZoneId(GetZoneId());
|
||||
if (bf != null)
|
||||
m_zoneScript = bf;
|
||||
return bf;
|
||||
else
|
||||
m_zoneScript = Global.OutdoorPvPMgr.GetZoneScript(GetZoneId());
|
||||
return Global.OutdoorPvPMgr.GetZoneScript(GetZoneId());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetZoneScript()
|
||||
{
|
||||
m_zoneScript = FindZoneScript();
|
||||
}
|
||||
|
||||
public Scenario GetScenario()
|
||||
|
||||
@@ -772,8 +772,7 @@ namespace Game.Entities
|
||||
if (eventid != 0)
|
||||
{
|
||||
Log.outDebug(LogFilter.Scripts, "Taxi {0} event {1} of node {2} of {3} path", departure ? "departure" : "arrival", eventid, node.Node.NodeIndex, GetName());
|
||||
GetMap().ScriptsStart(ScriptsType.Event, eventid, this, this);
|
||||
EventInform(eventid);
|
||||
GameEvents.Trigger(eventid, this, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Collections;
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Game.DataStorage;
|
||||
@@ -23,7 +24,6 @@ using Game.Maps;
|
||||
using Game.Networking.Packets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Framework.Collections;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2020 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.AI;
|
||||
using Game.Entities;
|
||||
using Game.Maps;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
class GameEvents
|
||||
{
|
||||
public static void Trigger(uint gameEventId, WorldObject source, WorldObject target)
|
||||
{
|
||||
Cypher.Assert(source || target, "At least one of [source] or [target] must be provided");
|
||||
|
||||
WorldObject refForMapAndZoneScript = source ?? target;
|
||||
|
||||
ZoneScript zoneScript = refForMapAndZoneScript.GetZoneScript();
|
||||
if (zoneScript == null && refForMapAndZoneScript.IsPlayer())
|
||||
zoneScript = refForMapAndZoneScript.FindZoneScript();
|
||||
|
||||
if (zoneScript != null)
|
||||
zoneScript.ProcessEvent(target, gameEventId, source);
|
||||
|
||||
Map map = refForMapAndZoneScript.GetMap();
|
||||
if (target)
|
||||
{
|
||||
GameObject goTarget = target.ToGameObject();
|
||||
if (goTarget != null)
|
||||
{
|
||||
GameObjectAI goAI = goTarget.GetAI();
|
||||
if (goAI != null)
|
||||
goAI.EventInform(gameEventId);
|
||||
}
|
||||
|
||||
BattlegroundMap bgMap = map.ToBattlegroundMap();
|
||||
if (bgMap != null)
|
||||
bgMap.GetBG().ProcessEvent(target, gameEventId, source);
|
||||
}
|
||||
|
||||
map.ScriptsStart(ScriptsType.Event, gameEventId, source, target);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -248,7 +248,7 @@ namespace Game.Movement
|
||||
if (eventid != 0)
|
||||
{
|
||||
Log.outDebug(LogFilter.MapsScript, $"FlightPathMovementGenerator::DoEventIfAny: taxi {(departure ? "departure" : "arrival")} event {eventid} of node {node.NodeIndex} of path {node.PathID} for player {owner.GetName()}");
|
||||
owner.GetMap().ScriptsStart(ScriptsType.Event, eventid, owner, owner);
|
||||
GameEvents.Trigger(eventid, owner, owner);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -734,14 +734,7 @@ namespace Game.Spells
|
||||
|
||||
Log.outDebug(LogFilter.Spells, "Spell ScriptStart {0} for spellid {1} in EffectSendEvent ", effectInfo.MiscValue, m_spellInfo.Id);
|
||||
|
||||
ZoneScript zoneScript = m_caster.GetZoneScript();
|
||||
InstanceScript instanceScript = m_caster.GetInstanceScript();
|
||||
if (zoneScript != null)
|
||||
zoneScript.ProcessEvent(target, (uint)effectInfo.MiscValue, m_caster);
|
||||
else if (instanceScript != null) // needed in case Player is the caster
|
||||
instanceScript.ProcessEvent(target, (uint)effectInfo.MiscValue, m_caster);
|
||||
|
||||
m_caster.GetMap().ScriptsStart(ScriptsType.Event, (uint)effectInfo.MiscValue, m_caster, target);
|
||||
GameEvents.Trigger((uint)effectInfo.MiscValue, m_caster, target);
|
||||
}
|
||||
|
||||
[SpellEffectHandler(SpellEffectName.PowerBurn)]
|
||||
|
||||
Reference in New Issue
Block a user