[9232] Replace list bool fields with exclusive true values by subtype field in Creature.
[getmangos.git] / src / game / ObjectMgr.h
blob9099dc5a54a8e3cdec2f7a3401dfe3392fc56830
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 "Group.h"
37 #include "Guild.h"
38 #include "ArenaTeam.h"
39 #include "ObjectAccessor.h"
40 #include "ObjectDefines.h"
41 #include "Policies/Singleton.h"
42 #include "Database/SQLStorage.h"
44 #include <string>
45 #include <map>
46 #include <limits>
48 extern SQLStorage sCreatureStorage;
49 extern SQLStorage sCreatureDataAddonStorage;
50 extern SQLStorage sCreatureInfoAddonStorage;
51 extern SQLStorage sCreatureModelStorage;
52 extern SQLStorage sEquipmentStorage;
53 extern SQLStorage sGOStorage;
54 extern SQLStorage sPageTextStore;
55 extern SQLStorage sItemStorage;
56 extern SQLStorage sInstanceTemplate;
58 class Group;
59 class Guild;
60 class ArenaTeam;
61 class Path;
62 class TransportPath;
63 class Item;
65 struct GameTele
67 float position_x;
68 float position_y;
69 float position_z;
70 float orientation;
71 uint32 mapId;
72 std::string name;
73 std::wstring wnameLow;
76 typedef UNORDERED_MAP<uint32, GameTele > GameTeleMap;
78 struct ScriptInfo
80 uint32 id;
81 uint32 delay;
82 uint32 command;
83 uint32 datalong;
84 uint32 datalong2;
85 int32 dataint;
86 float x;
87 float y;
88 float z;
89 float o;
92 typedef std::multimap<uint32, ScriptInfo> ScriptMap;
93 typedef std::map<uint32, ScriptMap > ScriptMapMap;
94 extern ScriptMapMap sQuestEndScripts;
95 extern ScriptMapMap sQuestStartScripts;
96 extern ScriptMapMap sSpellScripts;
97 extern ScriptMapMap sGameObjectScripts;
98 extern ScriptMapMap sEventScripts;
99 extern ScriptMapMap sGossipScripts;
101 struct SpellClickInfo
103 uint32 spellId;
104 uint32 questStart; // quest start (quest must be active or rewarded for spell apply)
105 uint32 questEnd; // quest end (quest don't must be rewarded for spell apply)
106 bool questStartCanActive; // if true then quest start can be active (not only rewarded)
107 uint8 castFlags;
109 // helpers
110 bool IsFitToRequirements(Player const* player) const;
113 typedef std::multimap<uint32, SpellClickInfo> SpellClickInfoMap;
114 typedef std::pair<SpellClickInfoMap::const_iterator,SpellClickInfoMap::const_iterator> SpellClickInfoMapBounds;
116 struct AreaTrigger
118 uint8 requiredLevel;
119 uint32 requiredItem;
120 uint32 requiredItem2;
121 uint32 heroicKey;
122 uint32 heroicKey2;
123 uint32 requiredQuest;
124 uint32 requiredQuestHeroic;
125 std::string requiredFailedText;
126 uint32 target_mapId;
127 float target_X;
128 float target_Y;
129 float target_Z;
130 float target_Orientation;
133 typedef std::set<uint32> CellGuidSet;
134 typedef std::map<uint32/*player guid*/,uint32/*instance*/> CellCorpseSet;
135 struct CellObjectGuids
137 CellGuidSet creatures;
138 CellGuidSet gameobjects;
139 CellCorpseSet corpses;
141 typedef UNORDERED_MAP<uint32/*cell_id*/,CellObjectGuids> CellObjectGuidsMap;
142 typedef UNORDERED_MAP<uint32/*(mapid,spawnMode) pair*/,CellObjectGuidsMap> MapObjectGuids;
144 typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
147 // mangos string ranges
148 #define MIN_MANGOS_STRING_ID 1 // 'mangos_string'
149 #define MAX_MANGOS_STRING_ID 2000000000
150 #define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID // 'db_script_string'
151 #define MAX_DB_SCRIPT_STRING_ID 2000010000
152 #define MIN_CREATURE_AI_TEXT_STRING_ID (-1) // 'creature_ai_texts'
153 #define MAX_CREATURE_AI_TEXT_STRING_ID (-1000000)
155 struct MangosStringLocale
157 std::vector<std::string> Content; // 0 -> default, i -> i-1 locale index
160 typedef UNORDERED_MAP<uint32,CreatureData> CreatureDataMap;
161 typedef UNORDERED_MAP<uint32,GameObjectData> GameObjectDataMap;
162 typedef UNORDERED_MAP<uint32,CreatureLocale> CreatureLocaleMap;
163 typedef UNORDERED_MAP<uint32,GameObjectLocale> GameObjectLocaleMap;
164 typedef UNORDERED_MAP<uint32,ItemLocale> ItemLocaleMap;
165 typedef UNORDERED_MAP<uint32,QuestLocale> QuestLocaleMap;
166 typedef UNORDERED_MAP<uint32,NpcTextLocale> NpcTextLocaleMap;
167 typedef UNORDERED_MAP<uint32,PageTextLocale> PageTextLocaleMap;
168 typedef UNORDERED_MAP<int32,MangosStringLocale> MangosStringLocaleMap;
169 typedef UNORDERED_MAP<uint32,GossipMenuItemsLocale> GossipMenuItemsLocaleMap;
170 typedef UNORDERED_MAP<uint32,PointOfInterestLocale> PointOfInterestLocaleMap;
172 typedef std::multimap<uint32,uint32> QuestRelations;
173 typedef std::multimap<uint32,ItemRequiredTarget> ItemRequiredTargetMap;
174 typedef std::pair<ItemRequiredTargetMap::const_iterator, ItemRequiredTargetMap::const_iterator> ItemRequiredTargetMapBounds;
176 struct PetLevelInfo
178 PetLevelInfo() : health(0), mana(0) { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
180 uint16 stats[MAX_STATS];
181 uint16 health;
182 uint16 mana;
183 uint16 armor;
186 struct MailLevelReward
188 MailLevelReward() : raceMask(0), mailTemplateId(0), senderEntry(0) {}
189 MailLevelReward(uint32 _raceMask, uint32 _mailTemplateId, uint32 _senderEntry) : raceMask(_raceMask), mailTemplateId(_mailTemplateId), senderEntry(_senderEntry) {}
191 uint32 raceMask;
192 uint32 mailTemplateId;
193 uint32 senderEntry;
196 typedef std::list<MailLevelReward> MailLevelRewardList;
197 typedef UNORDERED_MAP<uint8,MailLevelRewardList> MailLevelRewardMap;
199 struct ReputationOnKillEntry
201 uint32 repfaction1;
202 uint32 repfaction2;
203 bool is_teamaward1;
204 uint32 reputation_max_cap1;
205 int32 repvalue1;
206 bool is_teamaward2;
207 uint32 reputation_max_cap2;
208 int32 repvalue2;
209 bool team_dependent;
212 struct PointOfInterest
214 uint32 entry;
215 float x;
216 float y;
217 uint32 icon;
218 uint32 flags;
219 uint32 data;
220 std::string icon_name;
223 struct GossipMenuItems
225 uint32 menu_id;
226 uint32 id;
227 uint8 option_icon;
228 std::string option_text;
229 uint32 option_id;
230 uint32 npc_option_npcflag;
231 uint32 action_menu_id;
232 uint32 action_poi_id;
233 uint32 action_script_id;
234 bool box_coded;
235 uint32 box_money;
236 std::string box_text;
237 uint16 cond_1;
238 uint16 cond_2;
239 uint16 cond_3;
242 struct GossipMenus
244 uint32 entry;
245 uint32 text_id;
246 uint16 cond_1;
247 uint16 cond_2;
250 typedef std::multimap<uint32,GossipMenus> GossipMenusMap;
251 typedef std::pair<GossipMenusMap::const_iterator, GossipMenusMap::const_iterator> GossipMenusMapBounds;
252 typedef std::multimap<uint32,GossipMenuItems> GossipMenuItemsMap;
253 typedef std::pair<GossipMenuItemsMap::const_iterator, GossipMenuItemsMap::const_iterator> GossipMenuItemsMapBounds;
255 struct QuestPOIPoint
257 int32 x;
258 int32 y;
260 QuestPOIPoint() : x(0), y(0) {}
261 QuestPOIPoint(int32 _x, int32 _y) : x(_x), y(_y) {}
264 struct QuestPOI
266 int32 ObjectiveIndex;
267 uint32 MapId;
268 uint32 Unk1;
269 uint32 Unk2;
270 uint32 Unk3;
271 uint32 Unk4;
272 std::vector<QuestPOIPoint> points;
274 QuestPOI() : ObjectiveIndex(0), MapId(0), Unk1(0), Unk2(0), Unk3(0), Unk4(0) {}
275 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) {}
278 typedef std::vector<QuestPOI> QuestPOIVector;
279 typedef UNORDERED_MAP<uint32, QuestPOIVector> QuestPOIMap;
281 #define WEATHER_SEASONS 4
282 struct WeatherSeasonChances
284 uint32 rainChance;
285 uint32 snowChance;
286 uint32 stormChance;
289 struct WeatherZoneChances
291 WeatherSeasonChances data[WEATHER_SEASONS];
294 struct GraveYardData
296 uint32 safeLocId;
297 uint32 team;
299 typedef std::multimap<uint32,GraveYardData> GraveYardMap;
301 enum ConditionType
302 { // value1 value2 for the Condition enumed
303 CONDITION_NONE = 0, // 0 0
304 CONDITION_AURA = 1, // spell_id effindex
305 CONDITION_ITEM = 2, // item_id count
306 CONDITION_ITEM_EQUIPPED = 3, // item_id 0
307 CONDITION_ZONEID = 4, // zone_id 0
308 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank
309 CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde)
310 CONDITION_SKILL = 7, // skill_id skill_value
311 CONDITION_QUESTREWARDED = 8, // quest_id 0
312 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active.
313 CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD commission aura active
314 CONDITION_NO_AURA = 11, // spell_id effindex
315 CONDITION_ACTIVE_EVENT = 12, // event_id 0
316 CONDITION_AREA_FLAG = 13, // area_flag area_flag_not
317 CONDITION_RACE_CLASS = 14, // race_mask class_mask
318 CONDITION_LEVEL = 15, // player_level 0, 1 or 2 (0: equal to, 1: equal or higher than, 2: equal or less than)
321 #define MAX_CONDITION 16 // maximum value in ConditionType enum
323 struct PlayerCondition
325 ConditionType condition; // additional condition type
326 uint32 value1; // data for the condition - see ConditionType definition
327 uint32 value2;
329 PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
330 : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
332 static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
333 // Checks correctness of values
334 bool Meets(Player const * APlayer) const; // Checks if the player meets the condition
335 bool operator == (PlayerCondition const& lc) const
337 return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
341 // NPC gossip text id
342 typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
344 typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
345 typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
347 enum SkillRangeType
349 SKILL_RANGE_LANGUAGE, // 300..300
350 SKILL_RANGE_LEVEL, // 1..max skill for level
351 SKILL_RANGE_MONO, // 1..1, grey monolite bar
352 SKILL_RANGE_RANK, // 1..skill for known rank
353 SKILL_RANGE_NONE, // 0..0 always
356 SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
358 #define MAX_PLAYER_NAME 12 // max allowed by client name length
359 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
360 #define MAX_PET_NAME 12 // max allowed by client name length
361 #define MAX_CHARTER_NAME 24 // max allowed by client name length
363 bool normalizePlayerName(std::string& name);
365 struct MANGOS_DLL_SPEC LanguageDesc
367 Language lang_id;
368 uint32 spell_id;
369 uint32 skill_id;
372 extern LanguageDesc lang_description[LANGUAGES_COUNT];
373 MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
375 class PlayerDumpReader;
377 class ObjectMgr
379 friend class PlayerDumpReader;
381 public:
382 ObjectMgr();
383 ~ObjectMgr();
385 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
387 typedef UNORDERED_MAP<uint32, Group*> GroupMap;
389 typedef UNORDERED_MAP<uint32, Guild*> GuildMap;
391 typedef UNORDERED_MAP<uint32, ArenaTeam*> ArenaTeamMap;
393 typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
395 typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
397 typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
399 typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
400 typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap;
402 typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
404 typedef std::vector<std::string> ScriptNameMap;
406 Player* GetPlayer(const char* name) const { return ObjectAccessor::FindPlayerByName(name);}
407 Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
409 static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
411 void LoadGameobjectInfo();
412 void AddGameobjectInfo(GameObjectInfo *goinfo);
414 Group * GetGroupByLeaderLowGUID(uint32 lowguid) const;
415 void AddGroup(Group* group) { mGroupMap[GUID_LOPART(group->GetLeaderGUID())] = group ; }
416 void RemoveGroup(Group* group) { mGroupMap.erase(GUID_LOPART(group->GetLeaderGUID())); }
418 Guild* GetGuildByLeader(uint64 const&guid) const;
419 Guild* GetGuildById(uint32 GuildId) const;
420 Guild* GetGuildByName(const std::string& guildname) const;
421 std::string GetGuildNameById(uint32 GuildId) const;
422 void AddGuild(Guild* guild) { mGuildMap[guild->GetId()] = guild ; }
423 void RemoveGuild(uint32 Id) { mGuildMap.erase(Id); }
425 ArenaTeam* GetArenaTeamById(uint32 arenateamid) const;
426 ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
427 ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
428 void AddArenaTeam(ArenaTeam* arenaTeam) { mArenaTeamMap[arenaTeam->GetId()] = arenaTeam; }
429 void RemoveArenaTeam(uint32 Id) { mArenaTeamMap.erase(Id); }
430 ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
431 ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
433 static CreatureInfo const *GetCreatureTemplate( uint32 id );
434 CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
435 CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
436 uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
437 EquipmentInfo const *GetEquipmentInfo( uint32 entry );
438 static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
440 return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
443 static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
445 return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
448 static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
450 static InstanceTemplate const* GetInstanceTemplate(uint32 map)
452 return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
455 PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
457 PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
459 if(class_ >= MAX_CLASSES) return NULL;
460 return &playerClassInfo[class_];
462 void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
464 PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
466 if(race >= MAX_RACES) return NULL;
467 if(class_ >= MAX_CLASSES) return NULL;
468 PlayerInfo const* info = &playerInfo[race][class_];
469 if(info->displayId_m==0 || info->displayId_f==0) return NULL;
470 return info;
472 void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
474 uint64 GetPlayerGUIDByName(std::string name) const;
475 bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
476 uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
477 uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
478 uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const;
480 uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team );
481 void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
482 uint32 GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_alt_team = false);
483 void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
484 void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
486 Quest const* GetQuestTemplate(uint32 quest_id) const
488 QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
489 return itr != mQuestTemplates.end() ? itr->second : NULL;
491 QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
493 uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
495 QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
496 if(itr != mQuestAreaTriggerMap.end())
497 return itr->second;
498 return 0;
500 bool IsTavernAreaTrigger(uint32 Trigger_ID) const
502 return mTavernAreaTriggerSet.find(Trigger_ID) != mTavernAreaTriggerSet.end();
505 bool IsGameObjectForQuests(uint32 entry) const
507 return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end();
510 GossipText const* GetGossipText(uint32 Text_ID) const;
512 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
513 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
514 void LoadGraveyardZones();
515 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
517 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
519 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
520 if( itr != mAreaTriggers.end( ) )
521 return &itr->second;
522 return NULL;
525 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
526 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
528 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
530 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
532 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
533 if(itr != mRepOnKill.end())
534 return &itr->second;
535 return NULL;
538 PointOfInterest const* GetPointOfInterest(uint32 id) const
540 PointOfInterestMap::const_iterator itr = mPointsOfInterest.find(id);
541 if(itr != mPointsOfInterest.end())
542 return &itr->second;
543 return NULL;
546 QuestPOIVector const* GetQuestPOIVector(uint32 questId)
548 QuestPOIMap::const_iterator itr = mQuestPOIMap.find(questId);
549 if(itr != mQuestPOIMap.end())
550 return &itr->second;
551 return NULL;
554 void LoadGuilds();
555 void LoadArenaTeams();
556 void LoadGroups();
557 void LoadQuests();
558 void LoadQuestRelations()
560 LoadGameobjectQuestRelations();
561 LoadGameobjectInvolvedRelations();
562 LoadCreatureQuestRelations();
563 LoadCreatureInvolvedRelations();
565 void LoadGameobjectQuestRelations();
566 void LoadGameobjectInvolvedRelations();
567 void LoadCreatureQuestRelations();
568 void LoadCreatureInvolvedRelations();
570 QuestRelations mGOQuestRelations;
571 QuestRelations mGOQuestInvolvedRelations;
572 QuestRelations mCreatureQuestRelations;
573 QuestRelations mCreatureQuestInvolvedRelations;
575 void LoadGameObjectScripts();
576 void LoadQuestEndScripts();
577 void LoadQuestStartScripts();
578 void LoadEventScripts();
579 void LoadSpellScripts();
580 void LoadGossipScripts();
582 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
583 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
584 void LoadDbScriptStrings();
585 void LoadCreatureLocales();
586 void LoadCreatureTemplates();
587 void LoadCreatures();
588 void LoadCreatureRespawnTimes();
589 void LoadCreatureAddons();
590 void LoadCreatureModelInfo();
591 void LoadEquipmentTemplates();
592 void LoadGameObjectLocales();
593 void LoadGameobjects();
594 void LoadGameobjectRespawnTimes();
595 void LoadItemPrototypes();
596 void LoadItemRequiredTarget();
597 void LoadItemLocales();
598 void LoadQuestLocales();
599 void LoadNpcTextLocales();
600 void LoadPageTextLocales();
601 void LoadGossipMenuItemsLocales();
602 void LoadPointOfInterestLocales();
603 void LoadInstanceTemplate();
604 void LoadMailLevelRewards();
606 void LoadGossipText();
608 void LoadAreaTriggerTeleports();
609 void LoadQuestAreaTriggers();
610 void LoadAreaTriggerScripts();
611 void LoadTavernAreaTriggers();
612 void LoadGameObjectForQuests();
614 void LoadItemTexts();
615 void LoadPageTexts();
617 void LoadPlayerInfo();
618 void LoadPetLevelInfo();
619 void LoadExplorationBaseXP();
620 void LoadPetNames();
621 void LoadPetNumber();
622 void LoadCorpses();
623 void LoadFishingBaseSkillLevel();
625 void LoadReputationOnKill();
626 void LoadPointsOfInterest();
627 void LoadQuestPOI();
629 void LoadNPCSpellClickSpells();
631 void LoadWeatherZoneChances();
632 void LoadGameTele();
634 void LoadNpcTextId();
636 void LoadGossipMenu();
637 void LoadGossipMenuItems();
639 void LoadVendors();
640 void LoadTrainerSpell();
642 std::string GeneratePetName(uint32 entry);
643 uint32 GetBaseXP(uint32 level) const;
644 uint32 GetXPForLevel(uint32 level) const;
645 uint32 GetXPForPetLevel(uint32 level) const { return GetXPForLevel(level)/20; }
647 int32 GetFishingBaseSkillLevel(uint32 entry) const
649 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
650 return itr != mFishingBaseForArea.end() ? itr->second : 0;
653 void ReturnOrDeleteOldMails(bool serverUp);
655 void SetHighestGuids();
656 uint32 GenerateLowGuid(HighGuid guidhigh);
657 uint32 GenerateArenaTeamId();
658 uint32 GenerateAuctionID();
659 uint64 GenerateEquipmentSetGuid();
660 uint32 GenerateGuildId();
661 uint32 GenerateItemTextID();
662 uint32 GenerateMailID();
663 uint32 GeneratePetNumber();
665 uint32 CreateItemText(std::string text);
666 void AddItemText(uint32 itemTextId, std::string text) { mItemTexts[itemTextId] = text; }
667 std::string GetItemText( uint32 id )
669 ItemTextMap::const_iterator itr = mItemTexts.find( id );
670 if ( itr != mItemTexts.end() )
671 return itr->second;
672 else
673 return "There is no info for this item";
676 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
677 ExclusiveQuestGroups mExclusiveQuestGroups;
679 MailLevelReward const* GetMailLevelReward(uint32 level,uint32 raceMask)
681 MailLevelRewardMap::const_iterator map_itr = m_mailLevelRewardMap.find(level);
682 if (map_itr == m_mailLevelRewardMap.end())
683 return NULL;
685 for(MailLevelRewardList::const_iterator set_itr = map_itr->second.begin(); set_itr != map_itr->second.end(); ++set_itr)
686 if (set_itr->raceMask & raceMask)
687 return &*set_itr;
689 return NULL;
692 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
694 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
695 if(itr != mWeatherZoneMap.end())
696 return &itr->second;
697 else
698 return NULL;
701 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
703 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
706 CreatureData const* GetCreatureData(uint32 guid) const
708 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
709 if(itr==mCreatureDataMap.end()) return NULL;
710 return &itr->second;
712 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
713 void DeleteCreatureData(uint32 guid);
714 CreatureLocale const* GetCreatureLocale(uint32 entry) const
716 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
717 if(itr==mCreatureLocaleMap.end()) return NULL;
718 return &itr->second;
720 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
722 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
723 if(itr==mGameObjectLocaleMap.end()) return NULL;
724 return &itr->second;
726 ItemLocale const* GetItemLocale(uint32 entry) const
728 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
729 if(itr==mItemLocaleMap.end()) return NULL;
730 return &itr->second;
732 QuestLocale const* GetQuestLocale(uint32 entry) const
734 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
735 if(itr==mQuestLocaleMap.end()) return NULL;
736 return &itr->second;
738 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
740 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
741 if(itr==mNpcTextLocaleMap.end()) return NULL;
742 return &itr->second;
744 PageTextLocale const* GetPageTextLocale(uint32 entry) const
746 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
747 if(itr==mPageTextLocaleMap.end()) return NULL;
748 return &itr->second;
750 GossipMenuItemsLocale const* GetGossipMenuItemsLocale(uint32 entry) const
752 GossipMenuItemsLocaleMap::const_iterator itr = mGossipMenuItemsLocaleMap.find(entry);
753 if(itr==mGossipMenuItemsLocaleMap.end()) return NULL;
754 return &itr->second;
756 PointOfInterestLocale const* GetPointOfInterestLocale(uint32 poi_id) const
758 PointOfInterestLocaleMap::const_iterator itr = mPointOfInterestLocaleMap.find(poi_id);
759 if(itr==mPointOfInterestLocaleMap.end()) return NULL;
760 return &itr->second;
763 GameObjectData const* GetGOData(uint32 guid) const
765 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
766 if(itr==mGameObjectDataMap.end()) return NULL;
767 return &itr->second;
769 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
770 void DeleteGOData(uint32 guid);
772 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
774 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
775 if(itr==mMangosStringLocaleMap.end()) return NULL;
776 return &itr->second;
778 const char *GetMangosString(int32 entry, int locale_idx) const;
779 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
780 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
781 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
783 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
784 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
786 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
787 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
788 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
789 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
790 void DeleteRespawnTimeForInstance(uint32 instance);
792 // grid objects
793 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
794 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
795 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
796 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
798 // reserved names
799 void LoadReservedPlayersNames();
800 bool IsReservedName(const std::string& name) const;
802 // name with valid structure and symbols
803 static uint8 CheckPlayerName( const std::string& name, bool create = false );
804 static PetNameInvalidReason CheckPetName( const std::string& name );
805 static bool IsValidCharterName( const std::string& name );
807 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
809 int GetIndexForLocale(LocaleConstant loc);
810 LocaleConstant GetLocaleForIndex(int i);
812 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
813 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
815 if(condition_id >= mConditions.size())
816 return false;
818 return mConditions[condition_id].Meets(player);
821 GameTele const* GetGameTele(uint32 id) const
823 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
824 if(itr==m_GameTeleMap.end()) return NULL;
825 return &itr->second;
827 GameTele const* GetGameTele(const std::string& name) const;
828 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
829 bool AddGameTele(GameTele& data);
830 bool DeleteGameTele(const std::string& name);
832 uint32 GetNpcGossip(uint32 entry) const
834 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
835 if(iter == m_mCacheNpcTextIdMap.end())
836 return 0;
838 return iter->second;
841 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
843 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
844 if(iter == m_mCacheTrainerSpellMap.end())
845 return NULL;
847 return &iter->second;
850 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
852 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
853 if(iter == m_mCacheVendorItemMap.end())
854 return NULL;
856 return &iter->second;
858 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
859 bool RemoveVendorItem(uint32 entry,uint32 item);
860 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
862 void LoadScriptNames();
863 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
864 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
865 uint32 GetScriptId(const char *name);
867 int GetOrNewIndexForLocale(LocaleConstant loc);
869 SpellClickInfoMapBounds GetSpellClickInfoMapBounds(uint32 creature_id) const
871 return SpellClickInfoMapBounds(mSpellClickInfoMap.lower_bound(creature_id),mSpellClickInfoMap.upper_bound(creature_id));
874 ItemRequiredTargetMapBounds GetItemRequiredTargetMapBounds(uint32 uiItemEntry) const
876 return ItemRequiredTargetMapBounds(m_ItemRequiredTarget.lower_bound(uiItemEntry),m_ItemRequiredTarget.upper_bound(uiItemEntry));
879 GossipMenusMapBounds GetGossipMenusMapBounds(uint32 uiMenuId) const
881 return GossipMenusMapBounds(m_mGossipMenusMap.lower_bound(uiMenuId),m_mGossipMenusMap.upper_bound(uiMenuId));
884 GossipMenuItemsMapBounds GetGossipMenuItemsMapBounds(uint32 uiMenuId) const
886 return GossipMenuItemsMapBounds(m_mGossipMenuItemsMap.lower_bound(uiMenuId),m_mGossipMenuItemsMap.upper_bound(uiMenuId));
889 protected:
891 // first free id for selected id type
892 uint32 m_arenaTeamId;
893 uint32 m_auctionid;
894 uint64 m_equipmentSetGuid;
895 uint32 m_guildId;
896 uint32 m_ItemTextId;
897 uint32 m_mailid;
898 uint32 m_hiPetNumber;
900 // first free low guid for seelcted 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