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 "ObjectGuid.h"
23#include "SharedDefines.h"
24#include "Define.h"
25#include <list>
26#include <map>
27#include <set>
28#include <unordered_map>
29#include <vector>
30
31#define max_ge_check_delay DAY // 1 day in seconds
32
34{
35 GAMEEVENT_NORMAL = 0, // standard game events
36 GAMEEVENT_WORLD_INACTIVE = 1, // not yet started
37 GAMEEVENT_WORLD_CONDITIONS = 2, // condition matching phase
38 GAMEEVENT_WORLD_NEXTPHASE = 3, // conditions are met, now 'length' timer to start next event
39 GAMEEVENT_WORLD_FINISHED = 4, // next events are started, unapply this one
40 GAMEEVENT_INTERNAL = 5 // never handled in update
41};
42
44{
45 float reqNum; // required number // use float, since some events use percent
46 float done; // done number
47 uint32 max_world_state; // max resource count world state update id
48 uint32 done_world_state; // done resource count world state update id
49};
50
57
58typedef std::map<uint32 /*condition id*/, GameEventFinishCondition> GameEventConditionMap;
59
61{
64 time_t start; // occurs after this time
65 time_t end; // occurs before this time
66 time_t nextstart; // after this time the follow-up events count this phase completed
67 uint32 occurence; // time between end and start
68 uint32 length; // length of the event (minutes) after finishing all conditions
71 GameEventState state; // state of the game event, these are saved into the game_event table on change!
72 GameEventConditionMap conditions; // conditions to finish
73 std::set<uint16 /*gameevent id*/> prerequisite_events; // events that must be completed before starting this event
74 std::string description;
75 uint8 announce; // if 0 dont announce, if 1 announce, if 2 take config value
76
77 bool isValid() const { return length > 0 || state > GAMEEVENT_NORMAL; }
78};
79
87
89{
90 uint32 entry; // creature entry
91 uint32 item; // item id
92 int32 maxcount; // 0 for infinite
93 uint32 incrtime; // time for restore items amount if maxcount != 0
95};
96
97class Player;
98class Creature;
99class Quest;
100
102{
103 private:
104 GameEventMgr();
106
107 public:
108 static GameEventMgr* instance();
109
110 typedef std::set<uint16> ActiveEvents;
111 typedef std::vector<GameEventData> GameEventDataMap;
112 ActiveEvents const& GetActiveEventList() const { return m_ActiveEvents; }
113 GameEventDataMap const& GetEventMap() const { return mGameEvent; }
114 bool CheckOneGameEvent(uint16 entry) const;
115 uint32 NextCheck(uint16 entry) const;
116 void LoadFromDB();
117 void LoadHolidayDates();
118 uint32 Update();
119 bool IsActiveEvent(uint16 event_id) { return (m_ActiveEvents.find(event_id) != m_ActiveEvents.end()); }
120 uint32 StartSystem();
121 void Initialize();
122 void StartArenaSeason();
123 void StartInternalEvent(uint16 event_id);
124 bool StartEvent(uint16 event_id, bool overwrite = false);
125 void StopEvent(uint16 event_id, bool overwrite = false);
126 void HandleQuestComplete(uint32 quest_id); // called on world event type quest completions
127 uint32 GetNPCFlag(Creature* cr);
128
129 private:
130 void SendWorldStateUpdate(Player* player, uint16 event_id);
131 void AddActiveEvent(uint16 event_id) { m_ActiveEvents.insert(event_id); }
132 void RemoveActiveEvent(uint16 event_id) { m_ActiveEvents.erase(event_id); }
133 void ApplyNewEvent(uint16 event_id);
134 void UnApplyEvent(uint16 event_id);
135 void GameEventSpawn(int16 event_id);
136 void GameEventUnspawn(int16 event_id);
137 void ChangeEquipOrModel(int16 event_id, bool activate);
138 void UpdateEventQuests(uint16 event_id, bool activate);
139 void UpdateWorldStates(uint16 event_id, bool Activate);
140 void UpdateEventNPCFlags(uint16 event_id);
141 void UpdateEventNPCVendor(uint16 event_id, bool activate);
142 void UpdateBattlegroundSettings();
143 void RunSmartAIScripts(uint16 event_id, bool activate);
144 bool CheckOneGameEventConditions(uint16 event_id);
145 void SaveWorldEventStateToDB(uint16 event_id);
146 bool hasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 event_id);
147 bool hasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 event_id);
148 bool hasCreatureActiveEventExcept(ObjectGuid::LowType creature_guid, uint16 event_id);
149 bool hasGameObjectActiveEventExcept(ObjectGuid::LowType go_guid, uint16 event_id);
150 void SetHolidayEventTime(GameEventData& event);
151 time_t GetLastStartTime(uint16 event_id) const;
152
153 typedef std::list<ObjectGuid::LowType> GuidList;
154 typedef std::list<uint32> IdList;
155 typedef std::vector<GuidList> GameEventGuidMap;
156 typedef std::vector<IdList> GameEventIdMap;
157 typedef std::pair<ObjectGuid::LowType, ModelEquip> ModelEquipPair;
158 typedef std::list<ModelEquipPair> ModelEquipList;
159 typedef std::vector<ModelEquipList> GameEventModelEquipMap;
160 typedef std::pair<uint32, uint32> QuestRelation;
161 typedef std::list<QuestRelation> QuestRelList;
162 typedef std::vector<QuestRelList> GameEventQuestMap;
163 typedef std::list<NPCVendorEntry> NPCVendorList;
164 typedef std::vector<NPCVendorList> GameEventNPCVendorMap;
166 typedef std::pair<ObjectGuid::LowType /*guid*/, uint32 /*npcflag*/> GuidNPCFlagPair;
167 typedef std::list<GuidNPCFlagPair> NPCFlagList;
168 typedef std::vector<NPCFlagList> GameEventNPCFlagMap;
169 typedef std::vector<uint32> GameEventBattlegroundMap;
174 //GameEventGuidMap mGameEventCreatureGuids;
175 //GameEventGuidMap mGameEventGameobjectGuids;
183
184 public:
187 std::vector<uint32> modifiedHolidays;
188};
189
190#define sGameEventMgr GameEventMgr::instance()
191
193TC_GAME_API bool IsEventActive(uint16 eventId);
194
195#endif
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
int16_t int16
Definition Define.h:130
int32_t int32
Definition Define.h:129
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
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
HolidayIds
@ HOLIDAY_NONE
GameEventDataMap const & GetEventMap() const
ActiveEvents m_ActiveEvents
GameEventDataMap mGameEvent
GameEventNPCFlagMap mGameEventNPCFlags
bool IsActiveEvent(uint16 event_id)
GameEventIdMap mGameEventPoolIds
std::vector< uint32 > GameEventBattlegroundMap
std::vector< GameEventData > GameEventDataMap
GameEventGuidMap mGameEventCreatureGuids
void RemoveActiveEvent(uint16 event_id)
void AddActiveEvent(uint16 event_id)
std::vector< GuidList > GameEventGuidMap
std::list< ObjectGuid::LowType > GuidList
std::vector< NPCVendorList > GameEventNPCVendorMap
GameEventModelEquipMap mGameEventModelEquip
ActiveEvents const & GetActiveEventList() const
std::list< ModelEquipPair > ModelEquipList
GameEventBattlegroundMap mGameEventBattlegroundHolidays
GameEventNPCVendorMap mGameEventVendors
GameEventQuestMap mGameEventCreatureQuests
GameEventGuidMap mGameEventGameobjectGuids
std::set< uint16 > ActiveEvents
std::pair< ObjectGuid::LowType, ModelEquip > ModelEquipPair
QuestIdToEventConditionMap mQuestToEventConditions
std::map< uint32, GameEventQuestToEventConditionNum > QuestIdToEventConditionMap
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::list< NPCVendorEntry > NPCVendorList
std::pair< uint32, uint32 > QuestRelation
std::pair< ObjectGuid::LowType, uint32 > GuidNPCFlagPair
std::vector< uint32 > modifiedHolidays
std::vector< NPCFlagList > GameEventNPCFlagMap
uint32 LowType
Definition ObjectGuid.h:142
GameEventState state
bool isValid() const
HolidayIds holiday_id
std::set< uint16 > prerequisite_events
GameEventConditionMap conditions
std::string description
uint32 modelid
uint8 equipement_id_prev
uint32 modelid_prev
uint8 equipment_id
uint32 ExtendedCost