[8809] Revert "[8799] Implemented thread safe bg queue updates."
[getmangos.git] / src / game / ObjectMgr.h
blobe4c90aadbcf5cb93645eac06023706b7102e9683
1 /*
2 * Copyright (C) 2005-2009 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;
97 struct SpellClickInfo
99 uint32 spellId;
100 uint32 questStart; // quest start (quest must be active or rewarded for spell apply)
101 uint32 questEnd; // quest end (quest don't must be rewarded for spell apply)
102 bool questStartCanActive; // if true then quest start can be active (not only rewarded)
103 uint8 castFlags;
105 // helpers
106 bool IsFitToRequirements(Player const* player) const;
109 typedef std::multimap<uint32, SpellClickInfo> SpellClickInfoMap;
110 typedef std::pair<SpellClickInfoMap::const_iterator,SpellClickInfoMap::const_iterator> SpellClickInfoMapBounds;
112 struct AreaTrigger
114 uint8 requiredLevel;
115 uint32 requiredItem;
116 uint32 requiredItem2;
117 uint32 heroicKey;
118 uint32 heroicKey2;
119 uint32 requiredQuest;
120 uint32 requiredQuestHeroic;
121 std::string requiredFailedText;
122 uint32 target_mapId;
123 float target_X;
124 float target_Y;
125 float target_Z;
126 float target_Orientation;
129 typedef std::set<uint32> CellGuidSet;
130 typedef std::map<uint32/*player guid*/,uint32/*instance*/> CellCorpseSet;
131 struct CellObjectGuids
133 CellGuidSet creatures;
134 CellGuidSet gameobjects;
135 CellCorpseSet corpses;
137 typedef UNORDERED_MAP<uint32/*cell_id*/,CellObjectGuids> CellObjectGuidsMap;
138 typedef UNORDERED_MAP<uint32/*(mapid,spawnMode) pair*/,CellObjectGuidsMap> MapObjectGuids;
140 typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
143 // mangos string ranges
144 #define MIN_MANGOS_STRING_ID 1 // 'mangos_string'
145 #define MAX_MANGOS_STRING_ID 2000000000
146 #define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID // 'db_script_string'
147 #define MAX_DB_SCRIPT_STRING_ID 2000010000
148 #define MIN_CREATURE_AI_TEXT_STRING_ID (-1) // 'creature_ai_texts'
149 #define MAX_CREATURE_AI_TEXT_STRING_ID (-1000000)
151 struct MangosStringLocale
153 std::vector<std::string> Content; // 0 -> default, i -> i-1 locale index
156 typedef UNORDERED_MAP<uint32,CreatureData> CreatureDataMap;
157 typedef UNORDERED_MAP<uint32,GameObjectData> GameObjectDataMap;
158 typedef UNORDERED_MAP<uint32,CreatureLocale> CreatureLocaleMap;
159 typedef UNORDERED_MAP<uint32,GameObjectLocale> GameObjectLocaleMap;
160 typedef UNORDERED_MAP<uint32,ItemLocale> ItemLocaleMap;
161 typedef UNORDERED_MAP<uint32,QuestLocale> QuestLocaleMap;
162 typedef UNORDERED_MAP<uint32,NpcTextLocale> NpcTextLocaleMap;
163 typedef UNORDERED_MAP<uint32,PageTextLocale> PageTextLocaleMap;
164 typedef UNORDERED_MAP<int32,MangosStringLocale> MangosStringLocaleMap;
165 typedef UNORDERED_MAP<uint32,NpcOptionLocale> NpcOptionLocaleMap;
166 typedef UNORDERED_MAP<uint32,PointOfInterestLocale> PointOfInterestLocaleMap;
168 typedef std::multimap<uint32,uint32> QuestRelations;
169 typedef std::multimap<uint32,ItemRequiredTarget> ItemRequiredTargetMap;
170 typedef std::pair<ItemRequiredTargetMap::const_iterator, ItemRequiredTargetMap::const_iterator> ItemRequiredTargetMapBounds;
172 struct PetLevelInfo
174 PetLevelInfo() : health(0), mana(0) { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
176 uint16 stats[MAX_STATS];
177 uint16 health;
178 uint16 mana;
179 uint16 armor;
182 struct MailLevelReward
184 MailLevelReward() : raceMask(0), mailTemplateId(0), senderEntry(0) {}
185 MailLevelReward(uint32 _raceMask, uint32 _mailTemplateId, uint32 _senderEntry) : raceMask(_raceMask), mailTemplateId(_mailTemplateId), senderEntry(_senderEntry) {}
187 uint32 raceMask;
188 uint32 mailTemplateId;
189 uint32 senderEntry;
192 typedef std::list<MailLevelReward> MailLevelRewardList;
193 typedef UNORDERED_MAP<uint8,MailLevelRewardList> MailLevelRewardMap;
195 struct ReputationOnKillEntry
197 uint32 repfaction1;
198 uint32 repfaction2;
199 bool is_teamaward1;
200 uint32 reputation_max_cap1;
201 int32 repvalue1;
202 bool is_teamaward2;
203 uint32 reputation_max_cap2;
204 int32 repvalue2;
205 bool team_dependent;
208 struct PointOfInterest
210 uint32 entry;
211 float x;
212 float y;
213 uint32 icon;
214 uint32 flags;
215 uint32 data;
216 std::string icon_name;
219 #define WEATHER_SEASONS 4
220 struct WeatherSeasonChances
222 uint32 rainChance;
223 uint32 snowChance;
224 uint32 stormChance;
227 struct WeatherZoneChances
229 WeatherSeasonChances data[WEATHER_SEASONS];
232 struct GraveYardData
234 uint32 safeLocId;
235 uint32 team;
237 typedef std::multimap<uint32,GraveYardData> GraveYardMap;
239 enum ConditionType
240 { // value1 value2 for the Condition enumed
241 CONDITION_NONE = 0, // 0 0
242 CONDITION_AURA = 1, // spell_id effindex
243 CONDITION_ITEM = 2, // item_id count
244 CONDITION_ITEM_EQUIPPED = 3, // item_id 0
245 CONDITION_ZONEID = 4, // zone_id 0
246 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank
247 CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde)
248 CONDITION_SKILL = 7, // skill_id skill_value
249 CONDITION_QUESTREWARDED = 8, // quest_id 0
250 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active.
251 CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD commission aura active
252 CONDITION_NO_AURA = 11, // spell_id effindex
253 CONDITION_ACTIVE_EVENT = 12, // event_id
256 #define MAX_CONDITION 13 // maximum value in ConditionType enum
258 struct PlayerCondition
260 ConditionType condition; // additional condition type
261 uint32 value1; // data for the condition - see ConditionType definition
262 uint32 value2;
264 PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
265 : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
267 static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
268 // Checks correctness of values
269 bool Meets(Player const * APlayer) const; // Checks if the player meets the condition
270 bool operator == (PlayerCondition const& lc) const
272 return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
276 // NPC gossip text id
277 typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
278 typedef std::list<GossipOption> CacheNpcOptionList;
280 typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
281 typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
283 enum SkillRangeType
285 SKILL_RANGE_LANGUAGE, // 300..300
286 SKILL_RANGE_LEVEL, // 1..max skill for level
287 SKILL_RANGE_MONO, // 1..1, grey monolite bar
288 SKILL_RANGE_RANK, // 1..skill for known rank
289 SKILL_RANGE_NONE, // 0..0 always
292 SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
294 #define MAX_PLAYER_NAME 12 // max allowed by client name length
295 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
296 #define MAX_PET_NAME 12 // max allowed by client name length
297 #define MAX_CHARTER_NAME 24 // max allowed by client name length
299 bool normalizePlayerName(std::string& name);
301 struct MANGOS_DLL_SPEC LanguageDesc
303 Language lang_id;
304 uint32 spell_id;
305 uint32 skill_id;
308 extern LanguageDesc lang_description[LANGUAGES_COUNT];
309 MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
311 class PlayerDumpReader;
313 class ObjectMgr
315 friend class PlayerDumpReader;
317 public:
318 ObjectMgr();
319 ~ObjectMgr();
321 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
323 typedef std::set< Group * > GroupSet;
325 typedef UNORDERED_MAP<uint32, Guild *> GuildMap;
327 typedef UNORDERED_MAP<uint32, ArenaTeam*> ArenaTeamMap;
329 typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
331 typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
333 typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
335 typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
336 typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap;
338 typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
340 typedef std::vector<std::string> ScriptNameMap;
342 Player* GetPlayer(const char* name) const { return ObjectAccessor::FindPlayerByName(name);}
343 Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
345 static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
347 void LoadGameobjectInfo();
348 void AddGameobjectInfo(GameObjectInfo *goinfo);
350 Group * GetGroupByLeader(const uint64 &guid) const;
351 void AddGroup(Group* group) { mGroupSet.insert( group ); }
352 void RemoveGroup(Group* group) { mGroupSet.erase( group ); }
354 Guild* GetGuildByLeader(uint64 const&guid) const;
355 Guild* GetGuildById(uint32 GuildId) const;
356 Guild* GetGuildByName(const std::string& guildname) const;
357 std::string GetGuildNameById(uint32 GuildId) const;
358 void AddGuild(Guild* guild);
359 void RemoveGuild(uint32 Id);
361 ArenaTeam* GetArenaTeamById(uint32 arenateamid) const;
362 ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
363 ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
364 void AddArenaTeam(ArenaTeam* arenaTeam);
365 void RemoveArenaTeam(uint32 Id);
366 ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
367 ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
369 static CreatureInfo const *GetCreatureTemplate( uint32 id );
370 CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
371 CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
372 uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
373 EquipmentInfo const *GetEquipmentInfo( uint32 entry );
374 static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
376 return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
379 static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
381 return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
384 static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
386 static InstanceTemplate const* GetInstanceTemplate(uint32 map)
388 return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
391 PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
393 PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
395 if(class_ >= MAX_CLASSES) return NULL;
396 return &playerClassInfo[class_];
398 void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
400 PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
402 if(race >= MAX_RACES) return NULL;
403 if(class_ >= MAX_CLASSES) return NULL;
404 PlayerInfo const* info = &playerInfo[race][class_];
405 if(info->displayId_m==0 || info->displayId_f==0) return NULL;
406 return info;
408 void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
410 uint64 GetPlayerGUIDByName(std::string name) const;
411 bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
412 uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
413 uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
414 uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const;
416 uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team );
417 void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
418 uint32 GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_alt_team = false);
419 void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
420 void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
422 Quest const* GetQuestTemplate(uint32 quest_id) const
424 QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
425 return itr != mQuestTemplates.end() ? itr->second : NULL;
427 QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
429 uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
431 QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
432 if(itr != mQuestAreaTriggerMap.end())
433 return itr->second;
434 return 0;
436 bool IsTavernAreaTrigger(uint32 Trigger_ID) const
438 return mTavernAreaTriggerSet.find(Trigger_ID) != mTavernAreaTriggerSet.end();
441 bool IsGameObjectForQuests(uint32 entry) const
443 return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end();
446 GossipText const* GetGossipText(uint32 Text_ID) const;
448 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
449 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
450 void LoadGraveyardZones();
451 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
453 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
455 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
456 if( itr != mAreaTriggers.end( ) )
457 return &itr->second;
458 return NULL;
461 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
462 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
464 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
466 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
468 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
469 if(itr != mRepOnKill.end())
470 return &itr->second;
471 return NULL;
474 PointOfInterest const* GetPointOfInterest(uint32 id) const
476 PointOfInterestMap::const_iterator itr = mPointsOfInterest.find(id);
477 if(itr != mPointsOfInterest.end())
478 return &itr->second;
479 return NULL;
482 void LoadGuilds();
483 void LoadArenaTeams();
484 void LoadGroups();
485 void LoadQuests();
486 void LoadQuestRelations()
488 LoadGameobjectQuestRelations();
489 LoadGameobjectInvolvedRelations();
490 LoadCreatureQuestRelations();
491 LoadCreatureInvolvedRelations();
493 void LoadGameobjectQuestRelations();
494 void LoadGameobjectInvolvedRelations();
495 void LoadCreatureQuestRelations();
496 void LoadCreatureInvolvedRelations();
498 QuestRelations mGOQuestRelations;
499 QuestRelations mGOQuestInvolvedRelations;
500 QuestRelations mCreatureQuestRelations;
501 QuestRelations mCreatureQuestInvolvedRelations;
503 void LoadGameObjectScripts();
504 void LoadQuestEndScripts();
505 void LoadQuestStartScripts();
506 void LoadEventScripts();
507 void LoadSpellScripts();
509 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
510 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
511 void LoadDbScriptStrings();
512 void LoadCreatureLocales();
513 void LoadCreatureTemplates();
514 void LoadCreatures();
515 void LoadCreatureRespawnTimes();
516 void LoadCreatureAddons();
517 void LoadCreatureModelInfo();
518 void LoadEquipmentTemplates();
519 void LoadGameObjectLocales();
520 void LoadGameobjects();
521 void LoadGameobjectRespawnTimes();
522 void LoadItemPrototypes();
523 void LoadItemRequiredTarget();
524 void LoadItemLocales();
525 void LoadQuestLocales();
526 void LoadNpcTextLocales();
527 void LoadPageTextLocales();
528 void LoadNpcOptionLocales();
529 void LoadPointOfInterestLocales();
530 void LoadInstanceTemplate();
531 void LoadMailLevelRewards();
533 void LoadGossipText();
535 void LoadAreaTriggerTeleports();
536 void LoadQuestAreaTriggers();
537 void LoadAreaTriggerScripts();
538 void LoadTavernAreaTriggers();
539 void LoadGameObjectForQuests();
541 void LoadItemTexts();
542 void LoadPageTexts();
544 void LoadPlayerInfo();
545 void LoadPetLevelInfo();
546 void LoadExplorationBaseXP();
547 void LoadPetNames();
548 void LoadPetNumber();
549 void LoadCorpses();
550 void LoadFishingBaseSkillLevel();
552 void LoadReputationOnKill();
553 void LoadPointsOfInterest();
555 void LoadNPCSpellClickSpells();
557 void LoadWeatherZoneChances();
558 void LoadGameTele();
560 void LoadNpcOptions();
561 void LoadNpcTextId();
562 void LoadVendors();
563 void LoadTrainerSpell();
565 std::string GeneratePetName(uint32 entry);
566 uint32 GetBaseXP(uint32 level);
567 uint32 GetXPForLevel(uint32 level);
569 int32 GetFishingBaseSkillLevel(uint32 entry) const
571 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
572 return itr != mFishingBaseForArea.end() ? itr->second : 0;
575 void ReturnOrDeleteOldMails(bool serverUp);
577 void SetHighestGuids();
578 uint32 GenerateLowGuid(HighGuid guidhigh);
579 uint32 GenerateArenaTeamId();
580 uint32 GenerateAuctionID();
581 uint64 GenerateEquipmentSetGuid();
582 uint32 GenerateGuildId();
583 uint32 GenerateItemTextID();
584 uint32 GenerateMailID();
585 uint32 GeneratePetNumber();
587 uint32 CreateItemText(std::string text);
588 void AddItemText(uint32 itemTextId, std::string text) { mItemTexts[itemTextId] = text; }
589 std::string GetItemText( uint32 id )
591 ItemTextMap::const_iterator itr = mItemTexts.find( id );
592 if ( itr != mItemTexts.end() )
593 return itr->second;
594 else
595 return "There is no info for this item";
598 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
599 ExclusiveQuestGroups mExclusiveQuestGroups;
601 MailLevelReward const* GetMailLevelReward(uint32 level,uint32 raceMask)
603 MailLevelRewardMap::const_iterator map_itr = m_mailLevelRewardMap.find(level);
604 if (map_itr == m_mailLevelRewardMap.end())
605 return NULL;
607 for(MailLevelRewardList::const_iterator set_itr = map_itr->second.begin(); set_itr != map_itr->second.end(); ++set_itr)
608 if (set_itr->raceMask & raceMask)
609 return &*set_itr;
611 return NULL;
614 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
616 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
617 if(itr != mWeatherZoneMap.end())
618 return &itr->second;
619 else
620 return NULL;
623 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
625 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
628 CreatureData const* GetCreatureData(uint32 guid) const
630 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
631 if(itr==mCreatureDataMap.end()) return NULL;
632 return &itr->second;
634 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
635 void DeleteCreatureData(uint32 guid);
636 CreatureLocale const* GetCreatureLocale(uint32 entry) const
638 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
639 if(itr==mCreatureLocaleMap.end()) return NULL;
640 return &itr->second;
642 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
644 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
645 if(itr==mGameObjectLocaleMap.end()) return NULL;
646 return &itr->second;
648 ItemLocale const* GetItemLocale(uint32 entry) const
650 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
651 if(itr==mItemLocaleMap.end()) return NULL;
652 return &itr->second;
654 QuestLocale const* GetQuestLocale(uint32 entry) const
656 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
657 if(itr==mQuestLocaleMap.end()) return NULL;
658 return &itr->second;
660 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
662 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
663 if(itr==mNpcTextLocaleMap.end()) return NULL;
664 return &itr->second;
666 PageTextLocale const* GetPageTextLocale(uint32 entry) const
668 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
669 if(itr==mPageTextLocaleMap.end()) return NULL;
670 return &itr->second;
672 NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const
674 NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry);
675 if(itr==mNpcOptionLocaleMap.end()) return NULL;
676 return &itr->second;
678 PointOfInterestLocale const* GetPointOfInterestLocale(uint32 poi_id) const
680 PointOfInterestLocaleMap::const_iterator itr = mPointOfInterestLocaleMap.find(poi_id);
681 if(itr==mPointOfInterestLocaleMap.end()) return NULL;
682 return &itr->second;
685 GameObjectData const* GetGOData(uint32 guid) const
687 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
688 if(itr==mGameObjectDataMap.end()) return NULL;
689 return &itr->second;
691 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
692 void DeleteGOData(uint32 guid);
694 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
696 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
697 if(itr==mMangosStringLocaleMap.end()) return NULL;
698 return &itr->second;
700 const char *GetMangosString(int32 entry, int locale_idx) const;
701 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
702 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
703 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
705 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
706 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
708 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
709 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
710 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
711 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
712 void DeleteRespawnTimeForInstance(uint32 instance);
714 // grid objects
715 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
716 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
717 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
718 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
720 // reserved names
721 void LoadReservedPlayersNames();
722 bool IsReservedName(const std::string& name) const;
724 // name with valid structure and symbols
725 static uint8 CheckPlayerName( const std::string& name, bool create = false );
726 static PetNameInvalidReason CheckPetName( const std::string& name );
727 static bool IsValidCharterName( const std::string& name );
729 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
731 int GetIndexForLocale(LocaleConstant loc);
732 LocaleConstant GetLocaleForIndex(int i);
734 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
735 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
737 if(condition_id >= mConditions.size())
738 return false;
740 return mConditions[condition_id].Meets(player);
743 GameTele const* GetGameTele(uint32 id) const
745 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
746 if(itr==m_GameTeleMap.end()) return NULL;
747 return &itr->second;
749 GameTele const* GetGameTele(const std::string& name) const;
750 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
751 bool AddGameTele(GameTele& data);
752 bool DeleteGameTele(const std::string& name);
754 CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; }
756 uint32 GetNpcGossip(uint32 entry) const
758 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
759 if(iter == m_mCacheNpcTextIdMap.end())
760 return 0;
762 return iter->second;
765 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
767 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
768 if(iter == m_mCacheTrainerSpellMap.end())
769 return NULL;
771 return &iter->second;
774 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
776 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
777 if(iter == m_mCacheVendorItemMap.end())
778 return NULL;
780 return &iter->second;
782 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
783 bool RemoveVendorItem(uint32 entry,uint32 item);
784 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
786 void LoadScriptNames();
787 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
788 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
789 uint32 GetScriptId(const char *name);
791 int GetOrNewIndexForLocale(LocaleConstant loc);
793 SpellClickInfoMapBounds GetSpellClickInfoMapBounds(uint32 creature_id) const
795 return SpellClickInfoMapBounds(mSpellClickInfoMap.lower_bound(creature_id),mSpellClickInfoMap.upper_bound(creature_id));
798 ItemRequiredTargetMapBounds GetItemRequiredTargetMapBounds(uint32 uiItemEntry) const
800 return ItemRequiredTargetMapBounds(m_ItemRequiredTarget.lower_bound(uiItemEntry),m_ItemRequiredTarget.upper_bound(uiItemEntry));
803 protected:
805 // first free id for selected id type
806 uint32 m_arenaTeamId;
807 uint32 m_auctionid;
808 uint64 m_equipmentSetGuid;
809 uint32 m_guildId;
810 uint32 m_ItemTextId;
811 uint32 m_mailid;
812 uint32 m_hiPetNumber;
814 // first free low guid for seelcted guid type
815 uint32 m_hiCharGuid;
816 uint32 m_hiCreatureGuid;
817 uint32 m_hiItemGuid;
818 uint32 m_hiGoGuid;
819 uint32 m_hiCorpseGuid;
821 QuestMap mQuestTemplates;
823 typedef UNORDERED_MAP<uint32, GossipText> GossipTextMap;
824 typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
825 typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
826 typedef std::set<uint32> TavernAreaTriggerSet;
827 typedef std::set<uint32> GameObjectForQuestSet;
829 GroupSet mGroupSet;
830 GuildMap mGuildMap;
831 ArenaTeamMap mArenaTeamMap;
833 ItemTextMap mItemTexts;
835 QuestAreaTriggerMap mQuestAreaTriggerMap;
836 TavernAreaTriggerSet mTavernAreaTriggerSet;
837 GameObjectForQuestSet mGameObjectForQuestSet;
838 GossipTextMap mGossipText;
839 AreaTriggerMap mAreaTriggers;
840 AreaTriggerScriptMap mAreaTriggerScripts;
842 RepOnKillMap mRepOnKill;
844 PointOfInterestMap mPointsOfInterest;
846 WeatherZoneMap mWeatherZoneMap;
848 //character reserved names
849 typedef std::set<std::wstring> ReservedNamesMap;
850 ReservedNamesMap m_ReservedNames;
852 GraveYardMap mGraveYardMap;
854 GameTeleMap m_GameTeleMap;
856 ScriptNameMap m_scriptNames;
858 SpellClickInfoMap mSpellClickInfoMap;
860 ItemRequiredTargetMap m_ItemRequiredTarget;
862 typedef std::vector<LocaleConstant> LocalForIndex;
863 LocalForIndex m_LocalForIndex;
865 int DBCLocaleIndex;
867 private:
868 void LoadScripts(ScriptMapMap& scripts, char const* tablename);
869 void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids);
870 void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment);
871 void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
872 void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
874 MailLevelRewardMap m_mailLevelRewardMap;
876 typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
877 // PetLevelInfoMap[creature_id][level]
878 PetLevelInfoMap petInfo; // [creature_id][level]
880 PlayerClassInfo playerClassInfo[MAX_CLASSES];
882 void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
883 PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
885 typedef std::vector<uint32> PlayerXPperLevel; // [level]
886 PlayerXPperLevel mPlayerXPperLevel;
888 typedef std::map<uint32,uint32> BaseXPMap; // [area level][base xp]
889 BaseXPMap mBaseXPTable;
891 typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
892 FishingBaseSkillMap mFishingBaseForArea;
894 typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
895 HalfNameMap PetHalfName0;
896 HalfNameMap PetHalfName1;
898 MapObjectGuids mMapObjectGuids;
899 CreatureDataMap mCreatureDataMap;
900 CreatureLocaleMap mCreatureLocaleMap;
901 GameObjectDataMap mGameObjectDataMap;
902 GameObjectLocaleMap mGameObjectLocaleMap;
903 ItemLocaleMap mItemLocaleMap;
904 QuestLocaleMap mQuestLocaleMap;
905 NpcTextLocaleMap mNpcTextLocaleMap;
906 PageTextLocaleMap mPageTextLocaleMap;
907 MangosStringLocaleMap mMangosStringLocaleMap;
908 NpcOptionLocaleMap mNpcOptionLocaleMap;
909 PointOfInterestLocaleMap mPointOfInterestLocaleMap;
910 RespawnTimes mCreatureRespawnTimes;
911 RespawnTimes mGORespawnTimes;
913 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
914 typedef std::vector<PlayerCondition> ConditionStore;
915 ConditionStore mConditions;
917 CacheNpcOptionList m_mCacheNpcOptionList;
918 CacheNpcTextIdMap m_mCacheNpcTextIdMap;
919 CacheVendorItemMap m_mCacheVendorItemMap;
920 CacheTrainerSpellMap m_mCacheTrainerSpellMap;
923 #define sObjectMgr MaNGOS::Singleton<ObjectMgr>::Instance()
925 // scripting access functions
926 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());
927 MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
928 MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
929 MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
930 MANGOS_DLL_SPEC CreatureInfo const* GetCreatureTemplateStore(uint32 entry);
931 MANGOS_DLL_SPEC Quest const* GetQuestTemplateStore(uint32 entry);
933 #endif