TrinityCore
Loading...
Searching...
No Matches
GameEventMgr.h
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#ifndef TRINITY_GAMEEVENT_MGR_H
19#define TRINITY_GAMEEVENT_MGR_H
20
21#include "Common.h"
22#include "SharedDefines.h"
23#include "Define.h"
24#include "ObjectGuid.h"
25#include "Optional.h"
26#include <list>
27#include <map>
28#include <set>
29#include <unordered_map>
30#include <vector>
31
32#define max_ge_check_delay DAY // 1 day in seconds
33
35{
36 GAMEEVENT_NORMAL = 0, // standard game events
37 GAMEEVENT_WORLD_INACTIVE = 1, // not yet started
38 GAMEEVENT_WORLD_CONDITIONS = 2, // condition matching phase
39 GAMEEVENT_WORLD_NEXTPHASE = 3, // conditions are met, now 'length' timer to start next event
40 GAMEEVENT_WORLD_FINISHED = 4, // next events are started, unapply this one
41 GAMEEVENT_INTERNAL = 5 // never handled in update
42};
43
45{
46 float reqNum; // required number // use float, since some events use percent
47 float done; // done number
48 uint32 max_world_state; // max resource count world state update id
49 uint32 done_world_state; // done resource count world state update id
50};
51
58
59typedef std::map<uint32 /*condition id*/, GameEventFinishCondition> GameEventConditionMap;
60
62{
65 time_t start; // occurs after this time
66 time_t end; // occurs before this time
67 time_t nextstart; // after this time the follow-up events count this phase completed
68 uint32 occurence; // time between end and start
69 uint32 length; // length of the event (minutes) after finishing all conditions
73 GameEventState state; // state of the game event, these are saved into the game_event table on change!
74 GameEventConditionMap conditions; // conditions to finish
75 std::set<uint16 /*gameevent id*/> prerequisite_events; // events that must be completed before starting this event
76 std::string description;
77 uint8 announce; // if 0 dont announce, if 1 announce, if 2 take config value
78
79 bool isValid() const { return length > 0 || state > GAMEEVENT_NORMAL; }
80};
81
89
90class Creature;
91class Player;
92class Quest;
93struct VendorItem;
94
96{
97 private:
100
101 public:
102 GameEventMgr(GameEventMgr const&) = delete;
106
107 static GameEventMgr* instance();
108
109 typedef std::set<uint16> ActiveEvents;
110 typedef std::vector<GameEventData> GameEventDataMap;
111 ActiveEvents const& GetActiveEventList() const { return m_ActiveEvents; }
112 GameEventDataMap const& GetEventMap() const { return mGameEvent; }
113 bool CheckOneGameEvent(uint16 entry) const;
114 uint32 NextCheck(uint16 entry) const;
115 void LoadFromDB();
116 uint32 Update();
117 bool IsActiveEvent(uint16 event_id) const { return (m_ActiveEvents.contains(event_id)); }
118 uint32 StartSystem();
119 void Initialize();
120 void StartArenaSeason();
121 void StartInternalEvent(uint16 event_id);
122 bool StartEvent(uint16 event_id, bool overwrite = false);
123 void StopEvent(uint16 event_id, bool overwrite = false);
124 void HandleQuestComplete(uint32 quest_id); // called on world event type quest completions
125 uint64 GetNPCFlag(Creature* cr);
126
127 private:
128 void SendWorldStateUpdate(Player* player, uint16 event_id);
129 void AddActiveEvent(uint16 event_id);
130 void RemoveActiveEvent(uint16 event_id);
131 void ApplyNewEvent(uint16 event_id);
132 void UnApplyEvent(uint16 event_id);
133 void GameEventSpawn(int16 event_id);
134 void GameEventUnspawn(int16 event_id);
135 void ChangeEquipOrModel(int16 event_id, bool activate);
136 void UpdateEventQuests(uint16 event_id, bool activate);
137 void UpdateWorldStates(uint16 event_id, bool Activate);
138 void UpdateEventNPCFlags(uint16 event_id);
139 void UpdateEventNPCVendor(uint16 event_id, bool activate);
140 void RunSmartAIScripts(uint16 event_id, bool activate);
141 bool CheckOneGameEventConditions(uint16 event_id);
142 void SaveWorldEventStateToDB(uint16 event_id);
143 bool hasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 event_id);
144 bool hasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 event_id);
145 bool hasCreatureActiveEventExcept(ObjectGuid::LowType creature_guid, uint16 event_id);
146 bool hasGameObjectActiveEventExcept(ObjectGuid::LowType go_guid, uint16 event_id);
147 void SetHolidayEventTime(GameEventData& event);
148 time_t GetLastStartTime(uint16 event_id) const;
149
150 typedef std::list<ObjectGuid::LowType> GuidList;
151 typedef std::list<uint32> IdList;
152 typedef std::vector<GuidList> GameEventGuidMap;
153 typedef std::vector<IdList> GameEventIdMap;
154 typedef std::pair<ObjectGuid::LowType, ModelEquip> ModelEquipPair;
155 typedef std::list<ModelEquipPair> ModelEquipList;
156 typedef std::vector<ModelEquipList> GameEventModelEquipMap;
157 typedef std::pair<uint32, uint32> QuestRelation;
158 typedef std::list<QuestRelation> QuestRelList;
159 typedef std::vector<QuestRelList> GameEventQuestMap;
160 typedef std::unordered_map<uint32, std::vector<VendorItem>> NPCVendorMap;
161 typedef std::vector<NPCVendorMap> GameEventNPCVendorMap;
163 typedef std::pair<ObjectGuid::LowType /*guid*/, uint64 /*npcflag*/> GuidNPCFlagPair;
164 typedef std::list<GuidNPCFlagPair> NPCFlagList;
165 typedef std::vector<NPCFlagList> GameEventNPCFlagMap;
170 //GameEventGuidMap mGameEventCreatureGuids;
171 //GameEventGuidMap mGameEventGameobjectGuids;
178
179 public:
182};
183
184#define sGameEventMgr GameEventMgr::instance()
185
187TC_GAME_API bool IsEventActive(uint16 eventId);
188
189#endif
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
int16_t int16
Definition Define.h:151
uint64_t uint64
Definition Define.h:153
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
TC_GAME_API bool IsHolidayActive(HolidayIds id)
TC_GAME_API bool IsEventActive(uint16 eventId)
std::map< uint32, GameEventFinishCondition > GameEventConditionMap
GameEventState
@ GAMEEVENT_NORMAL
@ GAMEEVENT_INTERNAL
@ GAMEEVENT_WORLD_FINISHED
@ GAMEEVENT_WORLD_CONDITIONS
@ GAMEEVENT_WORLD_NEXTPHASE
@ GAMEEVENT_WORLD_INACTIVE
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
HolidayIds
@ HOLIDAY_NONE
GameEventDataMap const & GetEventMap() const
ActiveEvents m_ActiveEvents
bool IsActiveEvent(uint16 event_id) const
GameEventDataMap mGameEvent
GameEventNPCFlagMap mGameEventNPCFlags
GameEventIdMap mGameEventPoolIds
std::vector< GameEventData > GameEventDataMap
GameEventGuidMap mGameEventCreatureGuids
GameEventMgr(GameEventMgr const &)=delete
std::vector< GuidList > GameEventGuidMap
std::list< ObjectGuid::LowType > GuidList
std::pair< ObjectGuid::LowType, uint64 > GuidNPCFlagPair
GameEventModelEquipMap mGameEventModelEquip
ActiveEvents const & GetActiveEventList() const
std::list< ModelEquipPair > ModelEquipList
GameEventNPCVendorMap mGameEventVendors
GameEventQuestMap mGameEventCreatureQuests
GameEventGuidMap mGameEventGameobjectGuids
GameEventMgr & operator=(GameEventMgr &&)=delete
std::set< uint16 > ActiveEvents
std::pair< ObjectGuid::LowType, ModelEquip > ModelEquipPair
QuestIdToEventConditionMap mQuestToEventConditions
std::map< uint32, GameEventQuestToEventConditionNum > QuestIdToEventConditionMap
std::vector< NPCVendorMap > GameEventNPCVendorMap
GameEventMgr & operator=(GameEventMgr const &)=delete
GameEventMgr(GameEventMgr &&)=delete
std::list< GuidNPCFlagPair > NPCFlagList
std::list< uint32 > IdList
GameEventQuestMap mGameEventGameObjectQuests
std::vector< QuestRelList > GameEventQuestMap
std::vector< ModelEquipList > GameEventModelEquipMap
std::list< QuestRelation > QuestRelList
std::vector< IdList > GameEventIdMap
std::unordered_map< uint32, std::vector< VendorItem > > NPCVendorMap
std::pair< uint32, uint32 > QuestRelation
std::vector< NPCFlagList > GameEventNPCFlagMap
uint64 LowType
Definition ObjectGuid.h:321
GameEventState state
bool isValid() const
HolidayIds holiday_id
std::set< uint16 > prerequisite_events
GameEventConditionMap conditions
std::string description
Optional< int32 > WorldStateId
uint32 modelid
uint8 equipement_id_prev
uint32 modelid_prev
uint8 equipment_id