TrinityCore
GameEventSender.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "GameEventSender.h"
19#include "GameObject.h"
20#include "GameObjectAI.h"
21#include "Map.h"
22#include "ObjectMgr.h"
23#include "Player.h"
24#include "ScriptMgr.h"
25#include "Util.h"
26#include "ZoneScript.h"
27
28void GameEvents::Trigger(uint32 gameEventId, WorldObject* source, WorldObject* target)
29{
30 ASSERT(source || target, "At least one of [source] or [target] must be provided");
31
32 WorldObject* refForMapAndZoneScript = Coalesce<WorldObject>(source, target);
33
34 ZoneScript* zoneScript = refForMapAndZoneScript->GetZoneScript();
35 if (!zoneScript && refForMapAndZoneScript->IsPlayer())
36 zoneScript = refForMapAndZoneScript->FindZoneScript();
37
38 if (zoneScript)
39 zoneScript->ProcessEvent(target, gameEventId, source);
40
41 sScriptMgr->OnEventTrigger(target, source, gameEventId);
42
43 if (GameObject* goTarget = Object::ToGameObject(target))
44 if (GameObjectAI* goAI = goTarget->AI())
45 goAI->EventInform(gameEventId);
46
47 if (Player* sourcePlayer = Object::ToPlayer(source))
48 TriggerForPlayer(gameEventId, sourcePlayer);
49
50 Map* map = refForMapAndZoneScript->GetMap();
51 TriggerForMap(gameEventId, map, source, target);
52}
53
54void GameEvents::TriggerForPlayer(uint32 gameEventId, Player* source)
55{
56 Map* map = source->GetMap();
57 if (map->Instanceable())
58 {
59 source->FailCriteria(CriteriaFailEvent::SendEvent, gameEventId);
60 source->StartCriteria(CriteriaStartEvent::SendEvent, gameEventId);
61 }
62
63 source->UpdateCriteria(CriteriaType::PlayerTriggerGameEvent, gameEventId, 0, 0, source);
64
65 if (map->IsScenario())
66 source->UpdateCriteria(CriteriaType::AnyoneTriggerGameEventScenario, gameEventId, 0, 0, source);
67}
68
69void GameEvents::TriggerForMap(uint32 gameEventId, Map* map, WorldObject* source, WorldObject* target)
70{
71 map->ScriptsStart(sEventScripts, gameEventId, source, target);
72}
@ PlayerTriggerGameEvent
@ AnyoneTriggerGameEventScenario
uint32_t uint32
Definition: Define.h:142
#define ASSERT
Definition: Errors.h:68
ScriptMapMap sEventScripts
Definition: ObjectMgr.cpp:79
#define sScriptMgr
Definition: ScriptMgr.h:1418
Definition: Map.h:189
void ScriptsStart(std::map< uint32, std::multimap< uint32, ScriptInfo > > const &scripts, uint32 id, Object *source, Object *target)
Put scripts in the execution queue.
Definition: MapScripts.cpp:34
bool Instanceable() const
Definition: Map.cpp:3233
bool IsScenario() const
Definition: Map.cpp:3345
bool IsPlayer() const
Definition: Object.h:212
Player * ToPlayer()
Definition: Object.h:215
GameObject * ToGameObject()
Definition: Object.h:233
void StartCriteria(CriteriaStartEvent startEvent, uint32 entry, Milliseconds timeLost=Milliseconds::zero())
Definition: Player.cpp:26756
void UpdateCriteria(CriteriaType type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, WorldObject *ref=nullptr)
Definition: Player.cpp:26767
void FailCriteria(CriteriaFailEvent condition, int32 failAsset)
Definition: Player.cpp:26761
Map * GetMap() const
Definition: Object.h:624
ZoneScript * FindZoneScript() const
Definition: Object.cpp:1992
ZoneScript * GetZoneScript() const
Definition: Object.h:630
virtual void ProcessEvent(WorldObject *, uint32, WorldObject *)
Definition: ZoneScript.h:95
TC_GAME_API void TriggerForMap(uint32 gameEventId, Map *map, WorldObject *source=nullptr, WorldObject *target=nullptr)
TC_GAME_API void Trigger(uint32 gameEventId, WorldObject *source, WorldObject *target)
TC_GAME_API void TriggerForPlayer(uint32 gameEventId, Player *source)