1 | /* |
---|
2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
3 | * |
---|
4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef TRINITY_GAMEEVENT_H |
---|
22 | #define TRINITY_GAMEEVENT_H |
---|
23 | |
---|
24 | #include "Platform/Define.h" |
---|
25 | #include "Creature.h" |
---|
26 | #include "GameObject.h" |
---|
27 | |
---|
28 | #define max_ge_check_delay 86400 // 1 day in seconds |
---|
29 | |
---|
30 | enum GameEventState |
---|
31 | { |
---|
32 | GAMEEVENT_NORMAL = 0, // standard game events |
---|
33 | GAMEEVENT_WORLD_INACTIVE, // not yet started |
---|
34 | GAMEEVENT_WORLD_CONDITIONS, // condition matching phase |
---|
35 | GAMEEVENT_WORLD_NEXTPHASE, // conditions are met, now 'lenght' timer to start next event |
---|
36 | GAMEEVENT_WORLD_FINISHED // next events are started, unapply this one |
---|
37 | }; |
---|
38 | |
---|
39 | struct GameEventFinishCondition |
---|
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 | |
---|
47 | struct GameEventQuestToEventConditionNum |
---|
48 | { |
---|
49 | uint16 event_id; |
---|
50 | uint32 condition; |
---|
51 | float num; |
---|
52 | }; |
---|
53 | |
---|
54 | struct GameEventData |
---|
55 | { |
---|
56 | GameEventData() : start(1),end(0),nextstart(0),occurence(0),length(0),state(GAMEEVENT_NORMAL) {} |
---|
57 | time_t start; // occurs after this time |
---|
58 | time_t end; // occurs before this time |
---|
59 | time_t nextstart; // after this time the follow-up events count this phase completed |
---|
60 | uint32 occurence; // time between end and start |
---|
61 | uint32 length; // length of the event (minutes) after finishing all conditions |
---|
62 | GameEventState state; // state of the game event, these are saved into the game_event table on change! |
---|
63 | std::map<uint32 /*condition id*/, GameEventFinishCondition> conditions; // conditions to finish |
---|
64 | std::set<uint16 /*gameevent id*/> prerequisite_events; // events that must be completed before starting this event |
---|
65 | std::string description; |
---|
66 | |
---|
67 | bool isValid() const { return ((length > 0) || (state > GAMEEVENT_NORMAL)); } |
---|
68 | }; |
---|
69 | |
---|
70 | struct ModelEquip |
---|
71 | { |
---|
72 | uint32 modelid; |
---|
73 | uint32 equipment_id; |
---|
74 | uint32 modelid_prev; |
---|
75 | uint32 equipement_id_prev; |
---|
76 | }; |
---|
77 | |
---|
78 | struct NPCVendorEntry |
---|
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 |
---|
84 | uint32 ExtendedCost; |
---|
85 | }; |
---|
86 | |
---|
87 | class Player; |
---|
88 | class GameEvent |
---|
89 | { |
---|
90 | public: |
---|
91 | GameEvent(); |
---|
92 | ~GameEvent() {}; |
---|
93 | typedef std::set<uint16> ActiveEvents; |
---|
94 | typedef std::vector<GameEventData> GameEventDataMap; |
---|
95 | ActiveEvents const& GetActiveEventList() const { return m_ActiveEvents; } |
---|
96 | GameEventDataMap const& GetEventMap() const { return mGameEvent; } |
---|
97 | bool CheckOneGameEvent(uint16 entry) const; |
---|
98 | uint32 NextCheck(uint16 entry) const; |
---|
99 | void LoadFromDB(); |
---|
100 | uint32 Update(); |
---|
101 | bool IsActiveEvent(uint16 event_id) { return ( m_ActiveEvents.find(event_id)!=m_ActiveEvents.end()); } |
---|
102 | uint32 Initialize(); |
---|
103 | bool StartEvent(uint16 event_id, bool overwrite = false); |
---|
104 | void StopEvent(uint16 event_id, bool overwrite = false); |
---|
105 | void HandleQuestComplete(uint32 quest_id); // called on world event type quest completions |
---|
106 | void HandleWorldEventGossip(Player * plr, Creature * c); |
---|
107 | uint32 GetNPCFlag(Creature * cr); |
---|
108 | uint32 GetNpcTextId(uint32 guid); |
---|
109 | private: |
---|
110 | void SendWorldStateUpdate(Player * plr, uint16 event_id); |
---|
111 | void AddActiveEvent(uint16 event_id) { m_ActiveEvents.insert(event_id); } |
---|
112 | void RemoveActiveEvent(uint16 event_id) { m_ActiveEvents.erase(event_id); } |
---|
113 | void ApplyNewEvent(uint16 event_id); |
---|
114 | void UnApplyEvent(uint16 event_id); |
---|
115 | void GameEventSpawn(int16 event_id); |
---|
116 | void GameEventUnspawn(int16 event_id); |
---|
117 | void ChangeEquipOrModel(int16 event_id, bool activate); |
---|
118 | void UpdateEventQuests(uint16 event_id, bool Activate); |
---|
119 | void UpdateEventNPCFlags(uint16 event_id); |
---|
120 | void UpdateEventNPCVendor(uint16 event_id, bool activate); |
---|
121 | bool CheckOneGameEventConditions(uint16 event_id); |
---|
122 | void SaveWorldEventStateToDB(uint16 event_id); |
---|
123 | bool hasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 event_id); |
---|
124 | bool hasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 event_id); |
---|
125 | bool hasCreatureActiveEventExcept(uint32 creature_guid, uint16 event_id); |
---|
126 | bool hasGameObjectActiveEventExcept(uint32 go_guid, uint16 event_id); |
---|
127 | protected: |
---|
128 | typedef std::list<uint32> GuidList; |
---|
129 | typedef std::vector<GuidList> GameEventGuidMap; |
---|
130 | typedef std::pair<uint32, ModelEquip> ModelEquipPair; |
---|
131 | typedef std::list<ModelEquipPair> ModelEquipList; |
---|
132 | typedef std::vector<ModelEquipList> GameEventModelEquipMap; |
---|
133 | typedef std::pair<uint32, uint32> QuestRelation; |
---|
134 | typedef std::list<QuestRelation> QuestRelList; |
---|
135 | typedef std::vector<QuestRelList> GameEventQuestMap; |
---|
136 | typedef std::list<NPCVendorEntry> NPCVendorList; |
---|
137 | typedef std::vector<NPCVendorList> GameEventNPCVendorMap; |
---|
138 | typedef std::map<uint32 /*quest id*/, GameEventQuestToEventConditionNum> QuestIdToEventConditionMap; |
---|
139 | typedef std::pair<uint32 /*guid*/, uint32 /*npcflag*/> GuidNPCFlagPair; |
---|
140 | typedef std::list<GuidNPCFlagPair> NPCFlagList; |
---|
141 | typedef std::vector<NPCFlagList> GameEventNPCFlagMap; |
---|
142 | typedef std::pair<uint16 /*event id*/, uint32 /*gossip id*/> EventNPCGossipIdPair; |
---|
143 | typedef std::map<uint32 /*guid*/, EventNPCGossipIdPair> GuidEventNpcGossipIdMap; |
---|
144 | GameEventQuestMap mGameEventCreatureQuests; |
---|
145 | GameEventQuestMap mGameEventGameObjectQuests; |
---|
146 | GameEventNPCVendorMap mGameEventVendors; |
---|
147 | GameEventModelEquipMap mGameEventModelEquip; |
---|
148 | GameEventGuidMap mGameEventCreatureGuids; |
---|
149 | GameEventGuidMap mGameEventGameobjectGuids; |
---|
150 | GameEventDataMap mGameEvent; |
---|
151 | QuestIdToEventConditionMap mQuestToEventConditions; |
---|
152 | GameEventNPCFlagMap mGameEventNPCFlags; |
---|
153 | GuidEventNpcGossipIdMap mNPCGossipIds; |
---|
154 | ActiveEvents m_ActiveEvents; |
---|
155 | bool isSystemInit; |
---|
156 | }; |
---|
157 | |
---|
158 | #define gameeventmgr Trinity::Singleton<GameEvent>::Instance() |
---|
159 | #endif |
---|