[2] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 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 |
---|
[44] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 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 |
---|
[44] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 19 | */ |
---|
| 20 | |
---|
[44] | 21 | #ifndef TRINITY_GAMEEVENT_H |
---|
| 22 | #define TRINITY_GAMEEVENT_H |
---|
[2] | 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 | |
---|
[44] | 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 | |
---|
[2] | 54 | struct GameEventData |
---|
| 55 | { |
---|
[44] | 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 |
---|
[2] | 65 | std::string description; |
---|
| 66 | |
---|
[44] | 67 | bool isValid() const { return ((length > 0) || (state > GAMEEVENT_NORMAL)); } |
---|
[2] | 68 | }; |
---|
| 69 | |
---|
| 70 | struct ModelEquip |
---|
| 71 | { |
---|
| 72 | uint32 modelid; |
---|
| 73 | uint32 equipment_id; |
---|
| 74 | uint32 modelid_prev; |
---|
| 75 | uint32 equipement_id_prev; |
---|
| 76 | }; |
---|
| 77 | |
---|
[44] | 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; |
---|
[2] | 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(); |
---|
[44] | 103 | bool StartEvent(uint16 event_id, bool overwrite = false); |
---|
[2] | 104 | void StopEvent(uint16 event_id, bool overwrite = false); |
---|
[44] | 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); |
---|
[2] | 109 | private: |
---|
[44] | 110 | void SendWorldStateUpdate(Player * plr, uint16 event_id); |
---|
[2] | 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); |
---|
[44] | 119 | void UpdateEventNPCFlags(uint16 event_id); |
---|
| 120 | void UpdateEventNPCVendor(uint16 event_id, bool activate); |
---|
[50] | 121 | void UpdateBattleGroundSettings(); |
---|
[44] | 122 | bool CheckOneGameEventConditions(uint16 event_id); |
---|
| 123 | void SaveWorldEventStateToDB(uint16 event_id); |
---|
| 124 | bool hasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 event_id); |
---|
| 125 | bool hasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 event_id); |
---|
| 126 | bool hasCreatureActiveEventExcept(uint32 creature_guid, uint16 event_id); |
---|
| 127 | bool hasGameObjectActiveEventExcept(uint32 go_guid, uint16 event_id); |
---|
[2] | 128 | protected: |
---|
| 129 | typedef std::list<uint32> GuidList; |
---|
| 130 | typedef std::vector<GuidList> GameEventGuidMap; |
---|
| 131 | typedef std::pair<uint32, ModelEquip> ModelEquipPair; |
---|
| 132 | typedef std::list<ModelEquipPair> ModelEquipList; |
---|
| 133 | typedef std::vector<ModelEquipList> GameEventModelEquipMap; |
---|
| 134 | typedef std::pair<uint32, uint32> QuestRelation; |
---|
| 135 | typedef std::list<QuestRelation> QuestRelList; |
---|
| 136 | typedef std::vector<QuestRelList> GameEventQuestMap; |
---|
[44] | 137 | typedef std::list<NPCVendorEntry> NPCVendorList; |
---|
| 138 | typedef std::vector<NPCVendorList> GameEventNPCVendorMap; |
---|
| 139 | typedef std::map<uint32 /*quest id*/, GameEventQuestToEventConditionNum> QuestIdToEventConditionMap; |
---|
| 140 | typedef std::pair<uint32 /*guid*/, uint32 /*npcflag*/> GuidNPCFlagPair; |
---|
| 141 | typedef std::list<GuidNPCFlagPair> NPCFlagList; |
---|
| 142 | typedef std::vector<NPCFlagList> GameEventNPCFlagMap; |
---|
| 143 | typedef std::pair<uint16 /*event id*/, uint32 /*gossip id*/> EventNPCGossipIdPair; |
---|
| 144 | typedef std::map<uint32 /*guid*/, EventNPCGossipIdPair> GuidEventNpcGossipIdMap; |
---|
[50] | 145 | typedef std::vector<uint32> GameEventBitmask; |
---|
[44] | 146 | GameEventQuestMap mGameEventCreatureQuests; |
---|
| 147 | GameEventQuestMap mGameEventGameObjectQuests; |
---|
| 148 | GameEventNPCVendorMap mGameEventVendors; |
---|
[2] | 149 | GameEventModelEquipMap mGameEventModelEquip; |
---|
| 150 | GameEventGuidMap mGameEventCreatureGuids; |
---|
| 151 | GameEventGuidMap mGameEventGameobjectGuids; |
---|
| 152 | GameEventDataMap mGameEvent; |
---|
[50] | 153 | GameEventBitmask mGameEventBattleGroundHolidays; |
---|
[44] | 154 | QuestIdToEventConditionMap mQuestToEventConditions; |
---|
| 155 | GameEventNPCFlagMap mGameEventNPCFlags; |
---|
| 156 | GuidEventNpcGossipIdMap mNPCGossipIds; |
---|
[2] | 157 | ActiveEvents m_ActiveEvents; |
---|
| 158 | bool isSystemInit; |
---|
| 159 | }; |
---|
| 160 | |
---|
[44] | 161 | #define gameeventmgr Trinity::Singleton<GameEvent>::Instance() |
---|
[2] | 162 | #endif |
---|