OregonCore  revision fb2a440-git
Your Favourite TBC server
GameEventMgr.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 OREGON_GAMEEVENT_MGR_H
19 #define OREGON_GAMEEVENT_MGR_H
20 
21 #include "Platform/Define.h"
22 #include "Creature.h"
23 #include "GameObject.h"
24 
25 #define max_ge_check_delay 86400 // 1 day in seconds
26 
28 {
29  GAMEEVENT_NORMAL = 0, // standard game events
30  GAMEEVENT_WORLD_INACTIVE, // not yet started
31  GAMEEVENT_WORLD_CONDITIONS, // condition matching phase
32  GAMEEVENT_WORLD_NEXTPHASE, // conditions are met, now 'lenght' timer to start next event
33  GAMEEVENT_WORLD_FINISHED // next events are started, unapply this one
34 };
35 
37 {
38  float reqNum; // required number // use float, since some events use percent
39  float done; // done number
40  uint32 max_world_state; // max resource count world state update id
41  uint32 done_world_state; // done resource count world state update id
42 };
43 
45 {
48  float num;
49 };
50 
52 {
53  GameEventData() : start(1), end(0), nextstart(0), occurence(0), length(0), state(GAMEEVENT_NORMAL) {}
54  time_t start; // occurs after this time
55  time_t end; // occurs before this time
56  time_t nextstart; // after this time the follow-up events count this phase completed
57  uint32 occurence; // time between end and start
58  uint32 length; // length of the event (minutes) after finishing all conditions
59  GameEventState state; // state of the game event, these are saved into the game_event table on change!
60  std::map<uint32 /*condition id*/, GameEventFinishCondition> conditions; // conditions to finish
61  std::set<uint16 /*gameevent id*/> prerequisite_events; // events that must be completed before starting this event
62  std::string description;
63 
64  bool isValid() const
65  {
66  return ((length > 0) || (state > GAMEEVENT_NORMAL));
67  }
68 };
69 
70 struct ModelEquip
71 {
76 };
77 
79 {
80  uint32 entry; // creature entry
81  uint32 item; // item id
82  uint32 maxcount; // 0 for infinite
83  uint32 incrtime; // time for restore items amount if maxcount != 0
85 };
86 
87 class Player;
89 {
90  public:
91  GameEventMgr();
93  typedef std::set<uint16> ActiveEvents;
94  typedef std::vector<GameEventData> GameEventDataMap;
95  ActiveEvents const& GetActiveEventList() const
96  {
97  return m_ActiveEvents;
98  }
99  GameEventDataMap const& GetEventMap() const
100  {
101  return mGameEvent;
102  }
103  bool CheckOneGameEvent(uint16 entry) const;
104  uint32 NextCheck(uint16 entry) const;
105  void LoadFromDB();
106  uint32 Update();
107  bool IsActiveEvent(uint16 event_id)
108  {
109  return (m_ActiveEvents.find(event_id) != m_ActiveEvents.end());
110  }
111  uint32 Initialize();
112  bool StartEvent(uint16 event_id, bool overwrite = false);
113  void StopEvent(uint16 event_id, bool overwrite = false);
114  void HandleQuestComplete(uint32 quest_id); // called on world event type quest completions
115  void HandleWorldEventGossip(Player* plr, Creature* c);
116  uint32 GetNPCFlag(Creature* cr);
117  private:
118  void SendWorldStateUpdate(Player* plr, uint16 event_id);
119  void AddActiveEvent(uint16 event_id)
120  {
121  m_ActiveEvents.insert(event_id);
122  }
123  void RemoveActiveEvent(uint16 event_id)
124  {
125  m_ActiveEvents.erase(event_id);
126  }
127  void ApplyNewEvent(uint16 event_id);
128  void UnApplyEvent(uint16 event_id);
129  void GameEventSpawn(int16 event_id);
130  void GameEventUnspawn(int16 event_id);
131  void ChangeEquipOrModel(int16 event_id, bool activate);
132  void UpdateEventQuests(uint16 event_id, bool Activate);
133  void UpdateEventNPCFlags(uint16 event_id);
134  void UpdateEventNPCVendor(uint16 event_id, bool activate);
135  void UpdateBattlegroundSettings();
136  void RunSmartAIScripts(uint16 event_id, bool activate);
137  bool CheckOneGameEventConditions(uint16 event_id);
138  void SaveWorldEventStateToDB(uint16 event_id);
139  bool hasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 event_id);
140  bool hasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 event_id);
141  bool hasCreatureActiveEventExcept(uint32 creature_guid, uint16 event_id);
142  bool hasGameObjectActiveEventExcept(uint32 go_guid, uint16 event_id);
143  protected:
144  typedef std::list<uint32> GuidList;
145  typedef std::list<uint32> IdList;
146  typedef std::vector<GuidList> GameEventGuidMap;
147  typedef std::vector<IdList> GameEventIdMap;
148  typedef std::pair<uint32, ModelEquip> ModelEquipPair;
149  typedef std::list<ModelEquipPair> ModelEquipList;
150  typedef std::vector<ModelEquipList> GameEventModelEquipMap;
151  typedef std::pair<uint32, uint32> QuestRelation;
152  typedef std::list<QuestRelation> QuestRelList;
153  typedef std::vector<QuestRelList> GameEventQuestMap;
154  typedef std::list<NPCVendorEntry> NPCVendorList;
155  typedef std::vector<NPCVendorList> GameEventNPCVendorMap;
157  typedef std::pair<uint32 /*guid*/, uint32 /*npcflag*/> GuidNPCFlagPair;
158  typedef std::list<GuidNPCFlagPair> NPCFlagList;
159  typedef std::vector<NPCFlagList> GameEventNPCFlagMap;
160  typedef std::pair<uint16 /*event id*/, uint32 /*gossip id*/> EventNPCGossipIdPair;
161  typedef std::map<uint32 /*guid*/, EventNPCGossipIdPair> GuidEventNpcGossipIdMap;
162  typedef std::vector<uint32> GameEventBitmask;
163  GameEventQuestMap mGameEventCreatureQuests;
164  GameEventQuestMap mGameEventGameObjectQuests;
165  GameEventNPCVendorMap mGameEventVendors;
166  GameEventModelEquipMap mGameEventModelEquip;
167  GameEventGuidMap mGameEventCreatureGuids;
168  GameEventGuidMap mGameEventGameobjectGuids;
169  GameEventIdMap mGameEventPoolIds;
170  GameEventDataMap mGameEvent;
172  QuestIdToEventConditionMap mQuestToEventConditions;
173  GameEventNPCFlagMap mGameEventNPCFlags;
174  GuidEventNpcGossipIdMap mNPCGossipIds;
175  ActiveEvents m_ActiveEvents;
177 };
178 
179 #define sGameEventMgr Oregon::Singleton<GameEventMgr>::Instance()
180 #endif
181 
182 bool isGameEventActive(uint16 event_id);
183 
ActiveEvents const & GetActiveEventList() const
Definition: GameEventMgr.h:95
GameEventIdMap mGameEventPoolIds
Definition: GameEventMgr.h:169
GameEventDataMap mGameEvent
Definition: GameEventMgr.h:170
bool IsActiveEvent(uint16 event_id)
Definition: GameEventMgr.h:107
GameEventGuidMap mGameEventCreatureGuids
Definition: GameEventMgr.h:167
uint32 equipement_id_prev
Definition: GameEventMgr.h:75
GameEventNPCFlagMap mGameEventNPCFlags
Definition: GameEventMgr.h:173
std::list< uint32 > GuidList
Definition: GameEventMgr.h:144
std::vector< uint32 > GameEventBitmask
Definition: GameEventMgr.h:162
GameEventNPCVendorMap mGameEventVendors
Definition: GameEventMgr.h:165
GameEventGuidMap mGameEventGameobjectGuids
Definition: GameEventMgr.h:168
std::vector< GuidList > GameEventGuidMap
Definition: GameEventMgr.h:146
std::vector< ModelEquipList > GameEventModelEquipMap
Definition: GameEventMgr.h:150
GameEventState
Definition: GameEventMgr.h:27
std::pair< uint32, ModelEquip > ModelEquipPair
Definition: GameEventMgr.h:148
GameEventDataMap const & GetEventMap() const
Definition: GameEventMgr.h:99
uint32 ExtendedCost
Definition: GameEventMgr.h:84
std::list< uint32 > IdList
Definition: GameEventMgr.h:145
ActiveEvents m_ActiveEvents
Definition: GameEventMgr.h:175
std::list< QuestRelation > QuestRelList
Definition: GameEventMgr.h:152
std::list< NPCVendorEntry > NPCVendorList
Definition: GameEventMgr.h:154
uint32 modelid_prev
Definition: GameEventMgr.h:74
uint32 equipment_id
Definition: GameEventMgr.h:73
QuestIdToEventConditionMap mQuestToEventConditions
Definition: GameEventMgr.h:172
std::vector< NPCFlagList > GameEventNPCFlagMap
Definition: GameEventMgr.h:159
bool isGameEventActive(uint16 event_id)
time_t nextstart
Definition: GameEventMgr.h:56
std::set< uint16 > prerequisite_events
Definition: GameEventMgr.h:61
void AddActiveEvent(uint16 event_id)
Definition: GameEventMgr.h:119
GameEventState state
Definition: GameEventMgr.h:59
std::pair< uint16, uint32 > EventNPCGossipIdPair
Definition: GameEventMgr.h:160
std::vector< QuestRelList > GameEventQuestMap
Definition: GameEventMgr.h:153
uint32 occurence
Definition: GameEventMgr.h:57
GameEventBitmask mGameEventBattlegroundHolidays
Definition: GameEventMgr.h:171
std::vector< NPCVendorList > GameEventNPCVendorMap
Definition: GameEventMgr.h:155
std::set< uint16 > ActiveEvents
Definition: GameEventMgr.h:92
std::map< uint32, GameEventFinishCondition > conditions
Definition: GameEventMgr.h:60
std::map< uint32, GameEventQuestToEventConditionNum > QuestIdToEventConditionMap
Definition: GameEventMgr.h:156
std::list< ModelEquipPair > ModelEquipList
Definition: GameEventMgr.h:149
uint32 modelid
Definition: GameEventMgr.h:72
GameEventQuestMap mGameEventGameObjectQuests
Definition: GameEventMgr.h:164
std::vector< GameEventData > GameEventDataMap
Definition: GameEventMgr.h:94
GameEventQuestMap mGameEventCreatureQuests
Definition: GameEventMgr.h:163
std::list< GuidNPCFlagPair > NPCFlagList
Definition: GameEventMgr.h:158
ACE_UINT16 uint16
Definition: Define.h:72
std::pair< uint32, uint32 > GuidNPCFlagPair
Definition: GameEventMgr.h:157
ACE_INT16 int16
Definition: Define.h:68
std::pair< uint32, uint32 > QuestRelation
Definition: GameEventMgr.h:151
std::map< uint32, EventNPCGossipIdPair > GuidEventNpcGossipIdMap
Definition: GameEventMgr.h:161
ACE_UINT32 uint32
Definition: Define.h:71
std::vector< IdList > GameEventIdMap
Definition: GameEventMgr.h:147
std::string description
Definition: GameEventMgr.h:62
Definition: Player.h:922
bool isValid() const
Definition: GameEventMgr.h:64
GameEventModelEquipMap mGameEventModelEquip
Definition: GameEventMgr.h:166
void RemoveActiveEvent(uint16 event_id)
Definition: GameEventMgr.h:123
GuidEventNpcGossipIdMap mNPCGossipIds
Definition: GameEventMgr.h:174