TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GameEventMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITY_GAMEEVENT_MGR_H
20 #define TRINITY_GAMEEVENT_MGR_H
21 
22 #include "Common.h"
23 #include "SharedDefines.h"
24 #include "Define.h"
25 #include "ObjectGuid.h"
26 
27 #define max_ge_check_delay DAY // 1 day in seconds
28 
30 {
31  GAMEEVENT_NORMAL = 0, // standard game events
32  GAMEEVENT_WORLD_INACTIVE = 1, // not yet started
33  GAMEEVENT_WORLD_CONDITIONS = 2, // condition matching phase
34  GAMEEVENT_WORLD_NEXTPHASE = 3, // conditions are met, now 'length' timer to start next event
35  GAMEEVENT_WORLD_FINISHED = 4, // next events are started, unapply this one
36  GAMEEVENT_INTERNAL = 5 // never handled in update
37 };
38 
40 {
41  float reqNum; // required number // use float, since some events use percent
42  float done; // done number
43  uint32 max_world_state; // max resource count world state update id
44  uint32 done_world_state; // done resource count world state update id
45 };
46 
48 {
51  float num;
52 };
53 
54 typedef std::map<uint32 /*condition id*/, GameEventFinishCondition> GameEventConditionMap;
55 
57 {
59  announce(0) { }
60  time_t start; // occurs after this time
61  time_t end; // occurs before this time
62  time_t nextstart; // after this time the follow-up events count this phase completed
63  uint32 occurence; // time between end and start
64  uint32 length; // length of the event (minutes) after finishing all conditions
66  GameEventState state; // state of the game event, these are saved into the game_event table on change!
67  GameEventConditionMap conditions; // conditions to finish
68  std::set<uint16 /*gameevent id*/> prerequisite_events; // events that must be completed before starting this event
69  std::string description;
70  uint8 announce; // if 0 dont announce, if 1 announce, if 2 take config value
71 
72  bool isValid() const { return length > 0 || state > GAMEEVENT_NORMAL; }
73 };
74 
75 struct ModelEquip
76 {
81 };
82 
84 {
85  uint32 entry; // creature entry
86  uint32 item; // item id
87  int32 maxcount; // 0 for infinite
88  uint32 incrtime; // time for restore items amount if maxcount != 0
90  uint8 Type; // 1 item, 2 currency
91 };
92 
93 class Player;
94 class Creature;
95 class Quest;
96 
98 {
99  private:
100  GameEventMgr();
102 
103  public:
104  static GameEventMgr* instance();
105 
106  typedef std::set<uint16> ActiveEvents;
107  typedef std::vector<GameEventData> GameEventDataMap;
108  ActiveEvents const& GetActiveEventList() const { return m_ActiveEvents; }
109  GameEventDataMap const& GetEventMap() const { return mGameEvent; }
110  bool CheckOneGameEvent(uint16 entry) const;
111  uint32 NextCheck(uint16 entry) const;
112  void LoadFromDB();
113  uint32 Update();
114  bool IsActiveEvent(uint16 event_id) { return (m_ActiveEvents.find(event_id) != m_ActiveEvents.end()); }
115  uint32 StartSystem();
116  void Initialize();
117  void StartArenaSeason();
118  void StartInternalEvent(uint16 event_id);
119  bool StartEvent(uint16 event_id, bool overwrite = false);
120  void StopEvent(uint16 event_id, bool overwrite = false);
121  void HandleQuestComplete(uint32 quest_id); // called on world event type quest completions
122  void HandleWorldEventGossip(Player* player, Creature* c);
123  uint64 GetNPCFlag(Creature* cr);
124  uint32 GetNpcTextId(uint32 guid);
125  uint16 GetEventIdForQuest(Quest const* quest) const;
126  private:
127  void SendWorldStateUpdate(Player* player, uint16 event_id);
128  void AddActiveEvent(uint16 event_id) { m_ActiveEvents.insert(event_id); }
129  void RemoveActiveEvent(uint16 event_id) { m_ActiveEvents.erase(event_id); }
130  void ApplyNewEvent(uint16 event_id);
131  void UnApplyEvent(uint16 event_id);
132  void GameEventSpawn(int16 event_id);
133  void GameEventUnspawn(int16 event_id);
134  void ChangeEquipOrModel(int16 event_id, bool activate);
135  void UpdateEventQuests(uint16 event_id, bool activate);
136  void UpdateWorldStates(uint16 event_id, bool Activate);
137  void UpdateEventNPCFlags(uint16 event_id);
138  void UpdateEventNPCVendor(uint16 event_id, bool activate);
139  void UpdateBattlegroundSettings();
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 
148  typedef std::list<ObjectGuid::LowType> GuidList;
149  typedef std::list<uint32> IdList;
150  typedef std::vector<GuidList> GameEventGuidMap;
151  typedef std::vector<IdList> GameEventIdMap;
152  typedef std::pair<ObjectGuid::LowType, ModelEquip> ModelEquipPair;
153  typedef std::list<ModelEquipPair> ModelEquipList;
154  typedef std::vector<ModelEquipList> GameEventModelEquipMap;
155  typedef std::pair<uint32, uint32> QuestRelation;
156  typedef std::list<QuestRelation> QuestRelList;
157  typedef std::vector<QuestRelList> GameEventQuestMap;
158  typedef std::list<NPCVendorEntry> NPCVendorList;
159  typedef std::vector<NPCVendorList> GameEventNPCVendorMap;
161  typedef std::pair<ObjectGuid::LowType /*guid*/, uint64 /*npcflag*/> GuidNPCFlagPair;
162  typedef std::list<GuidNPCFlagPair> NPCFlagList;
163  typedef std::vector<NPCFlagList> GameEventNPCFlagMap;
164  typedef std::vector<uint32> GameEventBitmask;
165  GameEventQuestMap mGameEventCreatureQuests;
166  GameEventQuestMap mGameEventGameObjectQuests;
167  GameEventNPCVendorMap mGameEventVendors;
168  GameEventModelEquipMap mGameEventModelEquip;
169  //GameEventGuidMap mGameEventCreatureGuids;
170  //GameEventGuidMap mGameEventGameobjectGuids;
171  GameEventIdMap mGameEventPoolIds;
172  GameEventDataMap mGameEvent;
174  QuestIdToEventConditionMap mQuestToEventConditions;
175  GameEventNPCFlagMap mGameEventNPCFlags;
176  ActiveEvents m_ActiveEvents;
177  std::unordered_map<uint32, uint16> _questToEventLinks;
179  public:
180  GameEventGuidMap mGameEventCreatureGuids;
181  GameEventGuidMap mGameEventGameobjectGuids;
182 };
183 
184 #define sGameEventMgr GameEventMgr::instance()
185 
187 TC_GAME_API bool IsEventActive(uint16 event_id);
188 
189 #endif
190 
ActiveEvents const & GetActiveEventList() const
Definition: GameEventMgr.h:108
GameEventIdMap mGameEventPoolIds
Definition: GameEventMgr.h:171
Definition: GameEventMgr.h:36
GameEventDataMap mGameEvent
Definition: GameEventMgr.h:172
uint32 item
Definition: GameEventMgr.h:86
Definition: GameEventMgr.h:39
HolidayIds holiday_id
Definition: GameEventMgr.h:65
bool IsActiveEvent(uint16 event_id)
Definition: GameEventMgr.h:114
Definition: QuestDef.h:279
Definition: SharedDefines.h:3716
float reqNum
Definition: GameEventMgr.h:41
GameEventGuidMap mGameEventCreatureGuids
Definition: GameEventMgr.h:180
GameEventNPCFlagMap mGameEventNPCFlags
Definition: GameEventMgr.h:175
uint8 Type
Definition: GameEventMgr.h:90
void LoadFromDB()
Definition: AddonMgr.cpp:40
std::vector< uint32 > GameEventBitmask
Definition: GameEventMgr.h:164
Definition: GameEventMgr.h:47
GameEventNPCVendorMap mGameEventVendors
Definition: GameEventMgr.h:167
uint8 announce
Definition: GameEventMgr.h:70
GameEventGuidMap mGameEventGameobjectGuids
Definition: GameEventMgr.h:181
std::vector< GuidList > GameEventGuidMap
Definition: GameEventMgr.h:150
GameEventData()
Definition: GameEventMgr.h:58
std::vector< ModelEquipList > GameEventModelEquipMap
Definition: GameEventMgr.h:154
GameEventState
Definition: GameEventMgr.h:29
uint32 entry
Definition: GameEventMgr.h:85
GameEventDataMap const & GetEventMap() const
Definition: GameEventMgr.h:109
std::unordered_map< uint32, uint16 > _questToEventLinks
Definition: GameEventMgr.h:177
GameEventConditionMap conditions
Definition: GameEventMgr.h:67
Definition: Creature.h:467
uint8 equipment_id
Definition: GameEventMgr.h:79
uint32 ExtendedCost
Definition: GameEventMgr.h:89
Definition: GameEventMgr.h:33
time_t end
Definition: GameEventMgr.h:61
uint64 LowType
Definition: ObjectGuid.h:199
uint32 length
Definition: GameEventMgr.h:64
std::list< uint32 > IdList
Definition: GameEventMgr.h:149
ActiveEvents m_ActiveEvents
Definition: GameEventMgr.h:176
uint32 done_world_state
Definition: GameEventMgr.h:44
std::list< QuestRelation > QuestRelList
Definition: GameEventMgr.h:156
Definition: GameEventMgr.h:97
std::list< ObjectGuid::LowType > GuidList
Definition: GameEventMgr.h:148
std::list< NPCVendorEntry > NPCVendorList
Definition: GameEventMgr.h:158
Definition: GameEventMgr.h:35
uint32 modelid_prev
Definition: GameEventMgr.h:78
uint32 incrtime
Definition: GameEventMgr.h:88
QuestIdToEventConditionMap mQuestToEventConditions
Definition: GameEventMgr.h:174
std::vector< NPCFlagList > GameEventNPCFlagMap
Definition: GameEventMgr.h:163
TC_GAME_API bool IsHolidayActive(HolidayIds id)
Definition: GameEventMgr.cpp:1673
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
static void Initialize(PCASC_SALSA20 pState, LPBYTE pbKey, DWORD cbKeyLength, LPBYTE pbVector)
Definition: CascDecrypt.cpp:81
uint64_t uint64
Definition: Define.h:149
uint16_t uint16
Definition: Define.h:151
float num
Definition: GameEventMgr.h:51
std::pair< ObjectGuid::LowType, uint64 > GuidNPCFlagPair
Definition: GameEventMgr.h:161
time_t nextstart
Definition: GameEventMgr.h:62
uint32 max_world_state
Definition: GameEventMgr.h:43
std::set< uint16 > prerequisite_events
Definition: GameEventMgr.h:68
Definition: GameEventMgr.h:31
bool isSystemInit
Definition: GameEventMgr.h:178
uint8 equipement_id_prev
Definition: GameEventMgr.h:80
void AddActiveEvent(uint16 event_id)
Definition: GameEventMgr.h:128
GameEventState state
Definition: GameEventMgr.h:66
int32 maxcount
Definition: GameEventMgr.h:87
std::vector< QuestRelList > GameEventQuestMap
Definition: GameEventMgr.h:157
uint32 occurence
Definition: GameEventMgr.h:63
Definition: GameEventMgr.h:75
Definition: GameEventMgr.h:83
GameEventBitmask mGameEventBattlegroundHolidays
Definition: GameEventMgr.h:173
Definition: GameEventMgr.h:34
std::vector< NPCVendorList > GameEventNPCVendorMap
Definition: GameEventMgr.h:159
std::set< uint16 > ActiveEvents
Definition: GameEventMgr.h:106
std::map< uint32, GameEventQuestToEventConditionNum > QuestIdToEventConditionMap
Definition: GameEventMgr.h:160
std::pair< ObjectGuid::LowType, ModelEquip > ModelEquipPair
Definition: GameEventMgr.h:152
std::list< ModelEquipPair > ModelEquipList
Definition: GameEventMgr.h:153
uint32 modelid
Definition: GameEventMgr.h:77
#define TC_GAME_API
Definition: Define.h:134
GameEventQuestMap mGameEventGameObjectQuests
Definition: GameEventMgr.h:166
std::vector< GameEventData > GameEventDataMap
Definition: GameEventMgr.h:107
Definition: GameEventMgr.h:32
uint8_t uint8
Definition: Define.h:152
~GameEventMgr()
Definition: GameEventMgr.h:101
GameEventQuestMap mGameEventCreatureQuests
Definition: GameEventMgr.h:165
int16_t int16
Definition: Define.h:147
std::list< GuidNPCFlagPair > NPCFlagList
Definition: GameEventMgr.h:162
std::pair< uint32, uint32 > QuestRelation
Definition: GameEventMgr.h:155
TC_GAME_API bool IsEventActive(uint16 event_id)
Definition: GameEventMgr.cpp:1688
std::vector< IdList > GameEventIdMap
Definition: GameEventMgr.h:151
uint32 condition
Definition: GameEventMgr.h:50
Definition: GameEventMgr.h:56
std::string description
Definition: GameEventMgr.h:69
float done
Definition: GameEventMgr.h:42
uint16 event_id
Definition: GameEventMgr.h:49
bool isValid() const
Definition: GameEventMgr.h:72
HolidayIds
Definition: SharedDefines.h:3714
std::map< uint32, GameEventFinishCondition > GameEventConditionMap
Definition: GameEventMgr.h:54
GameEventModelEquipMap mGameEventModelEquip
Definition: GameEventMgr.h:168
void Update(uint32 diff)
Definition: WeatherMgr.cpp:150
void RemoveActiveEvent(uint16 event_id)
Definition: GameEventMgr.h:129
time_t start
Definition: GameEventMgr.h:60