[9329] Add spell chain for 50245/50519 and ranks.
[getmangos.git] / src / game / ObjectMgr.h
blob5eeb17aebf6941f42dabef7cee3d51b45be4fc66
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _OBJECTMGR_H
20 #define _OBJECTMGR_H
22 #include "Log.h"
23 #include "Object.h"
24 #include "Bag.h"
25 #include "Creature.h"
26 #include "Player.h"
27 #include "GameObject.h"
28 #include "Corpse.h"
29 #include "QuestDef.h"
30 #include "Path.h"
31 #include "ItemPrototype.h"
32 #include "NPCHandler.h"
33 #include "Database/DatabaseEnv.h"
34 #include "Mail.h"
35 #include "Map.h"
36 #include "ObjectAccessor.h"
37 #include "ObjectDefines.h"
38 #include "Policies/Singleton.h"
39 #include "Database/SQLStorage.h"
41 #include <string>
42 #include <map>
43 #include <limits>
45 extern SQLStorage sCreatureStorage;
46 extern SQLStorage sCreatureDataAddonStorage;
47 extern SQLStorage sCreatureInfoAddonStorage;
48 extern SQLStorage sCreatureModelStorage;
49 extern SQLStorage sEquipmentStorage;
50 extern SQLStorage sGOStorage;
51 extern SQLStorage sPageTextStore;
52 extern SQLStorage sItemStorage;
53 extern SQLStorage sInstanceTemplate;
55 class Group;
56 class Guild;
57 class ArenaTeam;
58 class Path;
59 class TransportPath;
60 class Item;
62 struct GameTele
64 float position_x;
65 float position_y;
66 float position_z;
67 float orientation;
68 uint32 mapId;
69 std::string name;
70 std::wstring wnameLow;
73 typedef UNORDERED_MAP<uint32, GameTele > GameTeleMap;
75 struct ScriptInfo
77 uint32 id;
78 uint32 delay;
79 uint32 command;
80 uint32 datalong;
81 uint32 datalong2;
82 int32 dataint;
83 float x;
84 float y;
85 float z;
86 float o;
89 typedef std::multimap<uint32, ScriptInfo> ScriptMap;
90 typedef std::map<uint32, ScriptMap > ScriptMapMap;
91 extern ScriptMapMap sQuestEndScripts;
92 extern ScriptMapMap sQuestStartScripts;
93 extern ScriptMapMap sSpellScripts;
94 extern ScriptMapMap sGameObjectScripts;
95 extern ScriptMapMap sEventScripts;
96 extern ScriptMapMap sGossipScripts;
98 struct SpellClickInfo
100 uint32 spellId;
101 uint32 questStart; // quest start (quest must be active or rewarded for spell apply)
102 uint32 questEnd; // quest end (quest don't must be rewarded for spell apply)
103 bool questStartCanActive; // if true then quest start can be active (not only rewarded)
104 uint8 castFlags;
106 // helpers
107 bool IsFitToRequirements(Player const* player) const;
110 typedef std::multimap<uint32, SpellClickInfo> SpellClickInfoMap;
111 typedef std::pair<SpellClickInfoMap::const_iterator,SpellClickInfoMap::const_iterator> SpellClickInfoMapBounds;
113 struct AreaTrigger
115 uint8 requiredLevel;
116 uint32 requiredItem;
117 uint32 requiredItem2;
118 uint32 heroicKey;
119 uint32 heroicKey2;
120 uint32 requiredQuest;
121 uint32 requiredQuestHeroic;
122 std::string requiredFailedText;
123 uint32 target_mapId;
124 float target_X;
125 float target_Y;
126 float target_Z;
127 float target_Orientation;
130 typedef std::set<uint32> CellGuidSet;
131 typedef std::map<uint32/*player guid*/,uint32/*instance*/> CellCorpseSet;
132 struct CellObjectGuids
134 CellGuidSet creatures;
135 CellGuidSet gameobjects;
136 CellCorpseSet corpses;
138 typedef UNORDERED_MAP<uint32/*cell_id*/,CellObjectGuids> CellObjectGuidsMap;
139 typedef UNORDERED_MAP<uint32/*(mapid,spawnMode) pair*/,CellObjectGuidsMap> MapObjectGuids;
141 typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
144 // mangos string ranges
145 #define MIN_MANGOS_STRING_ID 1 // 'mangos_string'
146 #define MAX_MANGOS_STRING_ID 2000000000
147 #define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID // 'db_script_string'
148 #define MAX_DB_SCRIPT_STRING_ID 2000010000
149 #define MIN_CREATURE_AI_TEXT_STRING_ID (-1) // 'creature_ai_texts'
150 #define MAX_CREATURE_AI_TEXT_STRING_ID (-1000000)
152 struct MangosStringLocale
154 std::vector<std::string> Content; // 0 -> default, i -> i-1 locale index
157 typedef UNORDERED_MAP<uint32,CreatureData> CreatureDataMap;
158 typedef UNORDERED_MAP<uint32,GameObjectData> GameObjectDataMap;
159 typedef UNORDERED_MAP<uint32,CreatureLocale> CreatureLocaleMap;
160 typedef UNORDERED_MAP<uint32,GameObjectLocale> GameObjectLocaleMap;
161 typedef UNORDERED_MAP<uint32,ItemLocale> ItemLocaleMap;
162 typedef UNORDERED_MAP<uint32,QuestLocale> QuestLocaleMap;
163 typedef UNORDERED_MAP<uint32,NpcTextLocale> NpcTextLocaleMap;
164 typedef UNORDERED_MAP<uint32,PageTextLocale> PageTextLocaleMap;
165 typedef UNORDERED_MAP<int32,MangosStringLocale> MangosStringLocaleMap;
166 typedef UNORDERED_MAP<uint32,GossipMenuItemsLocale> GossipMenuItemsLocaleMap;
167 typedef UNORDERED_MAP<uint32,PointOfInterestLocale> PointOfInterestLocaleMap;
169 typedef std::multimap<uint32,uint32> QuestRelations;
170 typedef std::multimap<uint32,ItemRequiredTarget> ItemRequiredTargetMap;
171 typedef std::pair<ItemRequiredTargetMap::const_iterator, ItemRequiredTargetMap::const_iterator> ItemRequiredTargetMapBounds;
173 struct PetLevelInfo
175 PetLevelInfo() : health(0), mana(0) { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
177 uint16 stats[MAX_STATS];
178 uint16 health;
179 uint16 mana;
180 uint16 armor;
183 struct MailLevelReward
185 MailLevelReward() : raceMask(0), mailTemplateId(0), senderEntry(0) {}
186 MailLevelReward(uint32 _raceMask, uint32 _mailTemplateId, uint32 _senderEntry) : raceMask(_raceMask), mailTemplateId(_mailTemplateId), senderEntry(_senderEntry) {}
188 uint32 raceMask;
189 uint32 mailTemplateId;
190 uint32 senderEntry;
193 typedef std::list<MailLevelReward> MailLevelRewardList;
194 typedef UNORDERED_MAP<uint8,MailLevelRewardList> MailLevelRewardMap;
196 struct ReputationOnKillEntry
198 uint32 repfaction1;
199 uint32 repfaction2;
200 bool is_teamaward1;
201 uint32 reputation_max_cap1;
202 int32 repvalue1;
203 bool is_teamaward2;
204 uint32 reputation_max_cap2;
205 int32 repvalue2;
206 bool team_dependent;
209 struct PointOfInterest
211 uint32 entry;
212 float x;
213 float y;
214 uint32 icon;
215 uint32 flags;
216 uint32 data;
217 std::string icon_name;
220 struct GossipMenuItems
222 uint32 menu_id;
223 uint32 id;
224 uint8 option_icon;
225 std::string option_text;
226 uint32 option_id;
227 uint32 npc_option_npcflag;
228 uint32 action_menu_id;
229 uint32 action_poi_id;
230 uint32 action_script_id;
231 bool box_coded;
232 uint32 box_money;
233 std::string box_text;
234 uint16 cond_1;
235 uint16 cond_2;
236 uint16 cond_3;
239 struct GossipMenus
241 uint32 entry;
242 uint32 text_id;
243 uint16 cond_1;
244 uint16 cond_2;
247 typedef std::multimap<uint32,GossipMenus> GossipMenusMap;
248 typedef std::pair<GossipMenusMap::const_iterator, GossipMenusMap::const_iterator> GossipMenusMapBounds;
249 typedef std::multimap<uint32,GossipMenuItems> GossipMenuItemsMap;
250 typedef std::pair<GossipMenuItemsMap::const_iterator, GossipMenuItemsMap::const_iterator> GossipMenuItemsMapBounds;
252 struct QuestPOIPoint
254 int32 x;
255 int32 y;
257 QuestPOIPoint() : x(0), y(0) {}
258 QuestPOIPoint(int32 _x, int32 _y) : x(_x), y(_y) {}
261 struct QuestPOI
263 int32 ObjectiveIndex;
264 uint32 MapId;
265 uint32 Unk1;
266 uint32 Unk2;
267 uint32 Unk3;
268 uint32 Unk4;
269 std::vector<QuestPOIPoint> points;
271 QuestPOI() : ObjectiveIndex(0), MapId(0), Unk1(0), Unk2(0), Unk3(0), Unk4(0) {}
272 QuestPOI(int32 objIndex, uint32 mapId, uint32 unk1, uint32 unk2, uint32 unk3, uint32 unk4) : ObjectiveIndex(objIndex), MapId(mapId), Unk1(unk1), Unk2(unk2), Unk3(unk3), Unk4(unk4) {}
275 typedef std::vector<QuestPOI> QuestPOIVector;
276 typedef UNORDERED_MAP<uint32, QuestPOIVector> QuestPOIMap;
278 #define WEATHER_SEASONS 4
279 struct WeatherSeasonChances
281 uint32 rainChance;
282 uint32 snowChance;
283 uint32 stormChance;
286 struct WeatherZoneChances
288 WeatherSeasonChances data[WEATHER_SEASONS];
291 struct GraveYardData
293 uint32 safeLocId;
294 uint32 team;
296 typedef std::multimap<uint32,GraveYardData> GraveYardMap;
298 enum ConditionType
299 { // value1 value2 for the Condition enumed
300 CONDITION_NONE = 0, // 0 0
301 CONDITION_AURA = 1, // spell_id effindex
302 CONDITION_ITEM = 2, // item_id count
303 CONDITION_ITEM_EQUIPPED = 3, // item_id 0
304 CONDITION_ZONEID = 4, // zone_id 0
305 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank
306 CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde)
307 CONDITION_SKILL = 7, // skill_id skill_value
308 CONDITION_QUESTREWARDED = 8, // quest_id 0
309 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active.
310 CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD commission aura active
311 CONDITION_NO_AURA = 11, // spell_id effindex
312 CONDITION_ACTIVE_EVENT = 12, // event_id 0
313 CONDITION_AREA_FLAG = 13, // area_flag area_flag_not
314 CONDITION_RACE_CLASS = 14, // race_mask class_mask
315 CONDITION_LEVEL = 15, // player_level 0, 1 or 2 (0: equal to, 1: equal or higher than, 2: equal or less than)
318 #define MAX_CONDITION 16 // maximum value in ConditionType enum
320 struct PlayerCondition
322 ConditionType condition; // additional condition type
323 uint32 value1; // data for the condition - see ConditionType definition
324 uint32 value2;
326 PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
327 : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
329 static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
330 // Checks correctness of values
331 bool Meets(Player const * APlayer) const; // Checks if the player meets the condition
332 bool operator == (PlayerCondition const& lc) const
334 return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
338 // NPC gossip text id
339 typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
341 typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
342 typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
344 enum SkillRangeType
346 SKILL_RANGE_LANGUAGE, // 300..300
347 SKILL_RANGE_LEVEL, // 1..max skill for level
348 SKILL_RANGE_MONO, // 1..1, grey monolite bar
349 SKILL_RANGE_RANK, // 1..skill for known rank
350 SKILL_RANGE_NONE, // 0..0 always
353 SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
355 #define MAX_PLAYER_NAME 12 // max allowed by client name length
356 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
357 #define MAX_PET_NAME 12 // max allowed by client name length
358 #define MAX_CHARTER_NAME 24 // max allowed by client name length
360 bool normalizePlayerName(std::string& name);
362 struct MANGOS_DLL_SPEC LanguageDesc
364 Language lang_id;
365 uint32 spell_id;
366 uint32 skill_id;
369 extern LanguageDesc lang_description[LANGUAGES_COUNT];
370 MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
372 class PlayerDumpReader;
374 class ObjectMgr
376 friend class PlayerDumpReader;
378 public:
379 ObjectMgr();
380 ~ObjectMgr();
382 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
384 typedef UNORDERED_MAP<uint32, Group*> GroupMap;
386 typedef UNORDERED_MAP<uint32, Guild*> GuildMap;
388 typedef UNORDERED_MAP<uint32, ArenaTeam*> ArenaTeamMap;
390 typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
392 typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
394 typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
396 typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
397 typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap;
399 typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
401 typedef std::vector<std::string> ScriptNameMap;
403 Player* GetPlayer(const char* name) const { return ObjectAccessor::FindPlayerByName(name);}
404 Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
406 static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
408 void LoadGameobjectInfo();
409 void AddGameobjectInfo(GameObjectInfo *goinfo);
411 Group* GetGroupById(uint32 id) const;
412 Group* GetGroupByLeaderLowGUID(uint32 guid) const; // slow way by leader guid
413 void AddGroup(Group* group);
414 void RemoveGroup(Group* group);
416 Guild* GetGuildByLeader(uint64 const&guid) const;
417 Guild* GetGuildById(uint32 GuildId) const;
418 Guild* GetGuildByName(const std::string& guildname) const;
419 std::string GetGuildNameById(uint32 GuildId) const;
420 void AddGuild(Guild* guild);
421 void RemoveGuild(uint32 Id);
423 ArenaTeam* GetArenaTeamById(uint32 arenateamid) const;
424 ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
425 ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
426 void AddArenaTeam(ArenaTeam* arenaTeam);
427 void RemoveArenaTeam(uint32 Id);
428 ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
429 ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
431 static CreatureInfo const *GetCreatureTemplate( uint32 id );
432 CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
433 CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
434 uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
435 EquipmentInfo const *GetEquipmentInfo( uint32 entry );
436 static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
438 return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
441 static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
443 return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
446 static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
448 static InstanceTemplate const* GetInstanceTemplate(uint32 map)
450 return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
453 PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
455 PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
457 if(class_ >= MAX_CLASSES) return NULL;
458 return &playerClassInfo[class_];
460 void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
462 PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
464 if(race >= MAX_RACES) return NULL;
465 if(class_ >= MAX_CLASSES) return NULL;
466 PlayerInfo const* info = &playerInfo[race][class_];
467 if(info->displayId_m==0 || info->displayId_f==0) return NULL;
468 return info;
470 void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
472 uint64 GetPlayerGUIDByName(std::string name) const;
473 bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
474 uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
475 uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
476 uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const;
478 uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team );
479 void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
480 uint32 GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_alt_team = false);
481 void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
482 void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
484 Quest const* GetQuestTemplate(uint32 quest_id) const
486 QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
487 return itr != mQuestTemplates.end() ? itr->second : NULL;
489 QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
491 uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
493 QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
494 if(itr != mQuestAreaTriggerMap.end())
495 return itr->second;
496 return 0;
498 bool IsTavernAreaTrigger(uint32 Trigger_ID) const
500 return mTavernAreaTriggerSet.find(Trigger_ID) != mTavernAreaTriggerSet.end();
503 bool IsGameObjectForQuests(uint32 entry) const
505 return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end();
508 GossipText const* GetGossipText(uint32 Text_ID) const;
510 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
511 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
512 void LoadGraveyardZones();
513 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
515 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
517 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
518 if( itr != mAreaTriggers.end( ) )
519 return &itr->second;
520 return NULL;
523 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
524 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
526 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
528 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
530 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
531 if(itr != mRepOnKill.end())
532 return &itr->second;
533 return NULL;
536 PointOfInterest const* GetPointOfInterest(uint32 id) const
538 PointOfInterestMap::const_iterator itr = mPointsOfInterest.find(id);
539 if(itr != mPointsOfInterest.end())
540 return &itr->second;
541 return NULL;
544 QuestPOIVector const* GetQuestPOIVector(uint32 questId)
546 QuestPOIMap::const_iterator itr = mQuestPOIMap.find(questId);
547 if(itr != mQuestPOIMap.end())
548 return &itr->second;
549 return NULL;
552 void LoadGuilds();
553 void LoadArenaTeams();
554 void LoadGroups();
555 void LoadQuests();
556 void LoadQuestRelations()
558 LoadGameobjectQuestRelations();
559 LoadGameobjectInvolvedRelations();
560 LoadCreatureQuestRelations();
561 LoadCreatureInvolvedRelations();
563 void LoadGameobjectQuestRelations();
564 void LoadGameobjectInvolvedRelations();
565 void LoadCreatureQuestRelations();
566 void LoadCreatureInvolvedRelations();
568 QuestRelations mGOQuestRelations;
569 QuestRelations mGOQuestInvolvedRelations;
570 QuestRelations mCreatureQuestRelations;
571 QuestRelations mCreatureQuestInvolvedRelations;
573 void LoadGameObjectScripts();
574 void LoadQuestEndScripts();
575 void LoadQuestStartScripts();
576 void LoadEventScripts();
577 void LoadSpellScripts();
578 void LoadGossipScripts();
580 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
581 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
582 void LoadDbScriptStrings();
583 void LoadCreatureLocales();
584 void LoadCreatureTemplates();
585 void LoadCreatures();
586 void LoadCreatureRespawnTimes();
587 void LoadCreatureAddons();
588 void LoadCreatureModelInfo();
589 void LoadEquipmentTemplates();
590 void LoadGameObjectLocales();
591 void LoadGameobjects();
592 void LoadGameobjectRespawnTimes();
593 void LoadItemPrototypes();
594 void LoadItemRequiredTarget();
595 void LoadItemLocales();
596 void LoadQuestLocales();
597 void LoadNpcTextLocales();
598 void LoadPageTextLocales();
599 void LoadGossipMenuItemsLocales();
600 void LoadPointOfInterestLocales();
601 void LoadInstanceTemplate();
602 void LoadMailLevelRewards();
604 void LoadGossipText();
606 void LoadAreaTriggerTeleports();
607 void LoadQuestAreaTriggers();
608 void LoadAreaTriggerScripts();
609 void LoadTavernAreaTriggers();
610 void LoadGameObjectForQuests();
612 void LoadItemTexts();
613 void LoadPageTexts();
615 void LoadPlayerInfo();
616 void LoadPetLevelInfo();
617 void LoadExplorationBaseXP();
618 void LoadPetNames();
619 void LoadPetNumber();
620 void LoadCorpses();
621 void LoadFishingBaseSkillLevel();
623 void LoadReputationOnKill();
624 void LoadPointsOfInterest();
625 void LoadQuestPOI();
627 void LoadNPCSpellClickSpells();
629 void LoadWeatherZoneChances();
630 void LoadGameTele();
632 void LoadNpcTextId();
634 void LoadGossipMenu();
635 void LoadGossipMenuItems();
637 void LoadVendors();
638 void LoadTrainerSpell();
640 std::string GeneratePetName(uint32 entry);
641 uint32 GetBaseXP(uint32 level) const;
642 uint32 GetXPForLevel(uint32 level) const;
643 uint32 GetXPForPetLevel(uint32 level) const { return GetXPForLevel(level)/20; }
645 int32 GetFishingBaseSkillLevel(uint32 entry) const
647 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
648 return itr != mFishingBaseForArea.end() ? itr->second : 0;
651 void ReturnOrDeleteOldMails(bool serverUp);
653 void SetHighestGuids();
654 uint32 GenerateLowGuid(HighGuid guidhigh);
655 uint32 GenerateArenaTeamId();
656 uint32 GenerateAuctionID();
657 uint64 GenerateEquipmentSetGuid();
658 uint32 GenerateGuildId();
659 uint32 GenerateGroupId();
660 uint32 GenerateItemTextID();
661 uint32 GenerateMailID();
662 uint32 GeneratePetNumber();
664 uint32 CreateItemText(std::string text);
665 void AddItemText(uint32 itemTextId, std::string text) { mItemTexts[itemTextId] = text; }
666 std::string GetItemText( uint32 id )
668 ItemTextMap::const_iterator itr = mItemTexts.find( id );
669 if ( itr != mItemTexts.end() )
670 return itr->second;
671 else
672 return "There is no info for this item";
675 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
676 ExclusiveQuestGroups mExclusiveQuestGroups;
678 MailLevelReward const* GetMailLevelReward(uint32 level,uint32 raceMask)
680 MailLevelRewardMap::const_iterator map_itr = m_mailLevelRewardMap.find(level);
681 if (map_itr == m_mailLevelRewardMap.end())
682 return NULL;
684 for(MailLevelRewardList::const_iterator set_itr = map_itr->second.begin(); set_itr != map_itr->second.end(); ++set_itr)
685 if (set_itr->raceMask & raceMask)
686 return &*set_itr;
688 return NULL;
691 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
693 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
694 if(itr != mWeatherZoneMap.end())
695 return &itr->second;
696 else
697 return NULL;
700 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
702 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
705 CreatureData const* GetCreatureData(uint32 guid) const
707 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
708 if(itr==mCreatureDataMap.end()) return NULL;
709 return &itr->second;
711 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
712 void DeleteCreatureData(uint32 guid);
713 CreatureLocale const* GetCreatureLocale(uint32 entry) const
715 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
716 if(itr==mCreatureLocaleMap.end()) return NULL;
717 return &itr->second;
719 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
721 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
722 if(itr==mGameObjectLocaleMap.end()) return NULL;
723 return &itr->second;
725 ItemLocale const* GetItemLocale(uint32 entry) const
727 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
728 if(itr==mItemLocaleMap.end()) return NULL;
729 return &itr->second;
731 QuestLocale const* GetQuestLocale(uint32 entry) const
733 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
734 if(itr==mQuestLocaleMap.end()) return NULL;
735 return &itr->second;
737 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
739 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
740 if(itr==mNpcTextLocaleMap.end()) return NULL;
741 return &itr->second;
743 PageTextLocale const* GetPageTextLocale(uint32 entry) const
745 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
746 if(itr==mPageTextLocaleMap.end()) return NULL;
747 return &itr->second;
749 GossipMenuItemsLocale const* GetGossipMenuItemsLocale(uint32 entry) const
751 GossipMenuItemsLocaleMap::const_iterator itr = mGossipMenuItemsLocaleMap.find(entry);
752 if(itr==mGossipMenuItemsLocaleMap.end()) return NULL;
753 return &itr->second;
755 PointOfInterestLocale const* GetPointOfInterestLocale(uint32 poi_id) const
757 PointOfInterestLocaleMap::const_iterator itr = mPointOfInterestLocaleMap.find(poi_id);
758 if(itr==mPointOfInterestLocaleMap.end()) return NULL;
759 return &itr->second;
762 GameObjectData const* GetGOData(uint32 guid) const
764 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
765 if(itr==mGameObjectDataMap.end()) return NULL;
766 return &itr->second;
768 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
769 void DeleteGOData(uint32 guid);
771 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
773 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
774 if(itr==mMangosStringLocaleMap.end()) return NULL;
775 return &itr->second;
777 const char *GetMangosString(int32 entry, int locale_idx) const;
778 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
779 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
780 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
782 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
783 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
785 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
786 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
787 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
788 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
789 void DeleteRespawnTimeForInstance(uint32 instance);
791 // grid objects
792 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
793 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
794 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
795 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
797 // reserved names
798 void LoadReservedPlayersNames();
799 bool IsReservedName(const std::string& name) const;
801 // name with valid structure and symbols
802 static uint8 CheckPlayerName( const std::string& name, bool create = false );
803 static PetNameInvalidReason CheckPetName( const std::string& name );
804 static bool IsValidCharterName( const std::string& name );
806 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
808 int GetIndexForLocale(LocaleConstant loc);
809 LocaleConstant GetLocaleForIndex(int i);
811 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
812 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
814 if(condition_id >= mConditions.size())
815 return false;
817 return mConditions[condition_id].Meets(player);
820 GameTele const* GetGameTele(uint32 id) const
822 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
823 if(itr==m_GameTeleMap.end()) return NULL;
824 return &itr->second;
826 GameTele const* GetGameTele(const std::string& name) const;
827 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
828 bool AddGameTele(GameTele& data);
829 bool DeleteGameTele(const std::string& name);
831 uint32 GetNpcGossip(uint32 entry) const
833 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
834 if(iter == m_mCacheNpcTextIdMap.end())
835 return 0;
837 return iter->second;
840 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
842 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
843 if(iter == m_mCacheTrainerSpellMap.end())
844 return NULL;
846 return &iter->second;
849 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
851 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
852 if(iter == m_mCacheVendorItemMap.end())
853 return NULL;
855 return &iter->second;
857 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
858 bool RemoveVendorItem(uint32 entry,uint32 item);
859 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
861 void LoadScriptNames();
862 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
863 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
864 uint32 GetScriptId(const char *name);
866 int GetOrNewIndexForLocale(LocaleConstant loc);
868 SpellClickInfoMapBounds GetSpellClickInfoMapBounds(uint32 creature_id) const
870 return SpellClickInfoMapBounds(mSpellClickInfoMap.lower_bound(creature_id),mSpellClickInfoMap.upper_bound(creature_id));
873 ItemRequiredTargetMapBounds GetItemRequiredTargetMapBounds(uint32 uiItemEntry) const
875 return ItemRequiredTargetMapBounds(m_ItemRequiredTarget.lower_bound(uiItemEntry),m_ItemRequiredTarget.upper_bound(uiItemEntry));
878 GossipMenusMapBounds GetGossipMenusMapBounds(uint32 uiMenuId) const
880 return GossipMenusMapBounds(m_mGossipMenusMap.lower_bound(uiMenuId),m_mGossipMenusMap.upper_bound(uiMenuId));
883 GossipMenuItemsMapBounds GetGossipMenuItemsMapBounds(uint32 uiMenuId) const
885 return GossipMenuItemsMapBounds(m_mGossipMenuItemsMap.lower_bound(uiMenuId),m_mGossipMenuItemsMap.upper_bound(uiMenuId));
888 protected:
890 // first free id for selected id type
891 uint32 m_arenaTeamId;
892 uint32 m_auctionid;
893 uint64 m_equipmentSetGuid;
894 uint32 m_guildId;
895 uint32 m_ItemTextId;
896 uint32 m_mailid;
897 uint32 m_hiPetNumber;
898 uint32 m_groupId;
900 // first free low guid for selected guid type
901 uint32 m_hiCharGuid;
902 uint32 m_hiCreatureGuid;
903 uint32 m_hiItemGuid;
904 uint32 m_hiGoGuid;
905 uint32 m_hiCorpseGuid;
907 QuestMap mQuestTemplates;
909 typedef UNORDERED_MAP<uint32, GossipText> GossipTextMap;
910 typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
911 typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
912 typedef std::set<uint32> TavernAreaTriggerSet;
913 typedef std::set<uint32> GameObjectForQuestSet;
915 GroupMap mGroupMap;
916 GuildMap mGuildMap;
917 ArenaTeamMap mArenaTeamMap;
919 ItemTextMap mItemTexts;
921 QuestAreaTriggerMap mQuestAreaTriggerMap;
922 TavernAreaTriggerSet mTavernAreaTriggerSet;
923 GameObjectForQuestSet mGameObjectForQuestSet;
924 GossipTextMap mGossipText;
925 AreaTriggerMap mAreaTriggers;
926 AreaTriggerScriptMap mAreaTriggerScripts;
928 RepOnKillMap mRepOnKill;
930 GossipMenusMap m_mGossipMenusMap;
931 GossipMenuItemsMap m_mGossipMenuItemsMap;
932 PointOfInterestMap mPointsOfInterest;
934 QuestPOIMap mQuestPOIMap;
936 WeatherZoneMap mWeatherZoneMap;
938 //character reserved names
939 typedef std::set<std::wstring> ReservedNamesMap;
940 ReservedNamesMap m_ReservedNames;
942 GraveYardMap mGraveYardMap;
944 GameTeleMap m_GameTeleMap;
946 ScriptNameMap m_scriptNames;
948 SpellClickInfoMap mSpellClickInfoMap;
950 ItemRequiredTargetMap m_ItemRequiredTarget;
952 typedef std::vector<LocaleConstant> LocalForIndex;
953 LocalForIndex m_LocalForIndex;
955 int DBCLocaleIndex;
957 private:
958 void LoadScripts(ScriptMapMap& scripts, char const* tablename);
959 void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids);
960 void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment);
961 void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
962 void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
964 MailLevelRewardMap m_mailLevelRewardMap;
966 typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
967 // PetLevelInfoMap[creature_id][level]
968 PetLevelInfoMap petInfo; // [creature_id][level]
970 PlayerClassInfo playerClassInfo[MAX_CLASSES];
972 void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
973 PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
975 typedef std::vector<uint32> PlayerXPperLevel; // [level]
976 PlayerXPperLevel mPlayerXPperLevel;
978 typedef std::map<uint32,uint32> BaseXPMap; // [area level][base xp]
979 BaseXPMap mBaseXPTable;
981 typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
982 FishingBaseSkillMap mFishingBaseForArea;
984 typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
985 HalfNameMap PetHalfName0;
986 HalfNameMap PetHalfName1;
988 MapObjectGuids mMapObjectGuids;
989 CreatureDataMap mCreatureDataMap;
990 CreatureLocaleMap mCreatureLocaleMap;
991 GameObjectDataMap mGameObjectDataMap;
992 GameObjectLocaleMap mGameObjectLocaleMap;
993 ItemLocaleMap mItemLocaleMap;
994 QuestLocaleMap mQuestLocaleMap;
995 NpcTextLocaleMap mNpcTextLocaleMap;
996 PageTextLocaleMap mPageTextLocaleMap;
997 MangosStringLocaleMap mMangosStringLocaleMap;
998 GossipMenuItemsLocaleMap mGossipMenuItemsLocaleMap;
999 PointOfInterestLocaleMap mPointOfInterestLocaleMap;
1000 RespawnTimes mCreatureRespawnTimes;
1001 RespawnTimes mGORespawnTimes;
1003 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
1004 typedef std::vector<PlayerCondition> ConditionStore;
1005 ConditionStore mConditions;
1007 CacheNpcTextIdMap m_mCacheNpcTextIdMap;
1008 CacheVendorItemMap m_mCacheVendorItemMap;
1009 CacheTrainerSpellMap m_mCacheTrainerSpellMap;
1012 #define sObjectMgr MaNGOS::Singleton<ObjectMgr>::Instance()
1014 // scripting access functions
1015 MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = MAX_CREATURE_AI_TEXT_STRING_ID, int32 end_value = std::numeric_limits<int32>::min());
1016 MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
1017 MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
1018 MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
1019 MANGOS_DLL_SPEC CreatureInfo const* GetCreatureTemplateStore(uint32 entry);
1020 MANGOS_DLL_SPEC Quest const* GetQuestTemplateStore(uint32 entry);
1022 #endif