Merge commit 'origin/master' into 310
[AHbot.git] / src / game / ObjectMgr.h
blob4e4947ef0121dd6799aecfb0d0f01d67c7a42a5f
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 "DynamicObject.h"
28 #include "GameObject.h"
29 #include "Corpse.h"
30 #include "QuestDef.h"
31 #include "Path.h"
32 #include "ItemPrototype.h"
33 #include "NPCHandler.h"
34 #include "Database/DatabaseEnv.h"
35 #include "Mail.h"
36 #include "Map.h"
37 #include "ObjectAccessor.h"
38 #include "ObjectDefines.h"
39 #include "Policies/Singleton.h"
40 #include "Database/SQLStorage.h"
42 #include <string>
43 #include <map>
44 #include <limits>
46 extern SQLStorage sCreatureStorage;
47 extern SQLStorage sCreatureDataAddonStorage;
48 extern SQLStorage sCreatureInfoAddonStorage;
49 extern SQLStorage sCreatureModelStorage;
50 extern SQLStorage sEquipmentStorage;
51 extern SQLStorage sGOStorage;
52 extern SQLStorage sPageTextStore;
53 extern SQLStorage sItemStorage;
54 extern SQLStorage sInstanceTemplate;
56 class Group;
57 class Guild;
58 class ArenaTeam;
59 class Path;
60 class TransportPath;
61 class Item;
63 struct GameTele
65 float position_x;
66 float position_y;
67 float position_z;
68 float orientation;
69 uint32 mapId;
70 std::string name;
71 std::wstring wnameLow;
74 typedef UNORDERED_MAP<uint32, GameTele > GameTeleMap;
76 struct ScriptInfo
78 uint32 id;
79 uint32 delay;
80 uint32 command;
81 uint32 datalong;
82 uint32 datalong2;
83 int32 dataint;
84 float x;
85 float y;
86 float z;
87 float o;
90 typedef std::multimap<uint32, ScriptInfo> ScriptMap;
91 typedef std::map<uint32, ScriptMap > ScriptMapMap;
92 extern ScriptMapMap sQuestEndScripts;
93 extern ScriptMapMap sQuestStartScripts;
94 extern ScriptMapMap sSpellScripts;
95 extern ScriptMapMap sGameObjectScripts;
96 extern ScriptMapMap sEventScripts;
98 struct SpellClickInfo
100 uint32 spellId;
101 uint32 questId;
102 uint8 castFlags;
105 typedef std::multimap<uint32, SpellClickInfo> SpellClickInfoMap;
107 struct AreaTrigger
109 uint8 requiredLevel;
110 uint32 requiredItem;
111 uint32 requiredItem2;
112 uint32 heroicKey;
113 uint32 heroicKey2;
114 uint32 requiredQuest;
115 uint32 requiredQuestHeroic;
116 std::string requiredFailedText;
117 uint32 target_mapId;
118 float target_X;
119 float target_Y;
120 float target_Z;
121 float target_Orientation;
124 typedef std::set<uint32> CellGuidSet;
125 typedef std::map<uint32/*player guid*/,uint32/*instance*/> CellCorpseSet;
126 struct CellObjectGuids
128 CellGuidSet creatures;
129 CellGuidSet gameobjects;
130 CellCorpseSet corpses;
132 typedef UNORDERED_MAP<uint32/*cell_id*/,CellObjectGuids> CellObjectGuidsMap;
133 typedef UNORDERED_MAP<uint32/*(mapid,spawnMode) pair*/,CellObjectGuidsMap> MapObjectGuids;
135 typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
138 // mangos string ranges
139 #define MIN_MANGOS_STRING_ID 1
140 #define MAX_MANGOS_STRING_ID 2000000000
141 #define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID
142 #define MAX_DB_SCRIPT_STRING_ID 2000010000
144 struct MangosStringLocale
146 std::vector<std::string> Content; // 0 -> default, i -> i-1 locale index
149 typedef UNORDERED_MAP<uint32,CreatureData> CreatureDataMap;
150 typedef UNORDERED_MAP<uint32,GameObjectData> GameObjectDataMap;
151 typedef UNORDERED_MAP<uint32,CreatureLocale> CreatureLocaleMap;
152 typedef UNORDERED_MAP<uint32,GameObjectLocale> GameObjectLocaleMap;
153 typedef UNORDERED_MAP<uint32,ItemLocale> ItemLocaleMap;
154 typedef UNORDERED_MAP<uint32,QuestLocale> QuestLocaleMap;
155 typedef UNORDERED_MAP<uint32,NpcTextLocale> NpcTextLocaleMap;
156 typedef UNORDERED_MAP<uint32,PageTextLocale> PageTextLocaleMap;
157 typedef UNORDERED_MAP<uint32,MangosStringLocale> MangosStringLocaleMap;
158 typedef UNORDERED_MAP<uint32,NpcOptionLocale> NpcOptionLocaleMap;
159 typedef UNORDERED_MAP<uint32,PointOfInterestLocale> PointOfInterestLocaleMap;
161 typedef std::multimap<uint32,uint32> QuestRelations;
163 struct PetLevelInfo
165 PetLevelInfo() : health(0), mana(0) { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
167 uint16 stats[MAX_STATS];
168 uint16 health;
169 uint16 mana;
170 uint16 armor;
173 struct ReputationOnKillEntry
175 uint32 repfaction1;
176 uint32 repfaction2;
177 bool is_teamaward1;
178 uint32 reputation_max_cap1;
179 int32 repvalue1;
180 bool is_teamaward2;
181 uint32 reputation_max_cap2;
182 int32 repvalue2;
183 bool team_dependent;
186 struct PointOfInterest
188 uint32 entry;
189 float x;
190 float y;
191 uint32 icon;
192 uint32 flags;
193 uint32 data;
194 std::string icon_name;
197 struct PetCreateSpellEntry
199 uint32 spellid[4];
202 #define WEATHER_SEASONS 4
203 struct WeatherSeasonChances
205 uint32 rainChance;
206 uint32 snowChance;
207 uint32 stormChance;
210 struct WeatherZoneChances
212 WeatherSeasonChances data[WEATHER_SEASONS];
215 struct GraveYardData
217 uint32 safeLocId;
218 uint32 team;
220 typedef std::multimap<uint32,GraveYardData> GraveYardMap;
222 enum ConditionType
223 { // value1 value2 for the Condition enumed
224 CONDITION_NONE = 0, // 0 0
225 CONDITION_AURA = 1, // spell_id effindex
226 CONDITION_ITEM = 2, // item_id count
227 CONDITION_ITEM_EQUIPPED = 3, // item_id 0
228 CONDITION_ZONEID = 4, // zone_id 0
229 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank
230 CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde)
231 CONDITION_SKILL = 7, // skill_id skill_value
232 CONDITION_QUESTREWARDED = 8, // quest_id 0
233 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active.
234 CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD ñommission aura active
235 CONDITION_NO_AURA = 11, // spell_id effindex
236 CONDITION_ACTIVE_EVENT = 12, // event_id
239 #define MAX_CONDITION 13 // maximum value in ConditionType enum
241 struct PlayerCondition
243 ConditionType condition; // additional condition type
244 uint32 value1; // data for the condition - see ConditionType definition
245 uint32 value2;
247 PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
248 : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
250 static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
251 // Checks correctness of values
252 bool Meets(Player const * APlayer) const; // Checks if the player meets the condition
253 bool operator == (PlayerCondition const& lc) const
255 return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
259 // NPC gossip text id
260 typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
261 typedef std::list<GossipOption> CacheNpcOptionList;
263 typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
264 typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
266 enum SkillRangeType
268 SKILL_RANGE_LANGUAGE, // 300..300
269 SKILL_RANGE_LEVEL, // 1..max skill for level
270 SKILL_RANGE_MONO, // 1..1, grey monolite bar
271 SKILL_RANGE_RANK, // 1..skill for known rank
272 SKILL_RANGE_NONE, // 0..0 always
275 SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
277 #define MAX_PLAYER_NAME 12 // max allowed by client name length
278 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
280 bool normalizePlayerName(std::string& name);
282 struct MANGOS_DLL_SPEC LanguageDesc
284 Language lang_id;
285 uint32 spell_id;
286 uint32 skill_id;
289 extern LanguageDesc lang_description[LANGUAGES_COUNT];
290 MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
292 class PlayerDumpReader;
294 class ObjectMgr
296 friend class PlayerDumpReader;
298 public:
299 ObjectMgr();
300 ~ObjectMgr();
302 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
304 typedef std::set< Group * > GroupSet;
306 typedef UNORDERED_MAP<uint32, Guild *> GuildMap;
308 typedef UNORDERED_MAP<uint32, ArenaTeam*> ArenaTeamMap;
310 typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
312 typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
314 typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
316 typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
317 typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap;
319 typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
321 typedef UNORDERED_MAP<uint32, PetCreateSpellEntry> PetCreateSpellMap;
323 typedef std::vector<std::string> ScriptNameMap;
325 Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);}
326 Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
328 static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
330 void LoadGameobjectInfo();
331 void AddGameobjectInfo(GameObjectInfo *goinfo);
333 Group * GetGroupByLeader(const uint64 &guid) const;
334 void AddGroup(Group* group) { mGroupSet.insert( group ); }
335 void RemoveGroup(Group* group) { mGroupSet.erase( group ); }
337 Guild* GetGuildByLeader(uint64 const&guid) const;
338 Guild* GetGuildById(uint32 GuildId) const;
339 Guild* GetGuildByName(const std::string& guildname) const;
340 std::string GetGuildNameById(uint32 GuildId) const;
341 void AddGuild(Guild* guild);
342 void RemoveGuild(uint32 Id);
344 ArenaTeam* GetArenaTeamById(uint32 arenateamid) const;
345 ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
346 ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
347 void AddArenaTeam(ArenaTeam* arenaTeam);
348 void RemoveArenaTeam(uint32 Id);
349 ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
350 ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
352 static CreatureInfo const *GetCreatureTemplate( uint32 id );
353 CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
354 CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
355 uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
356 EquipmentInfo const *GetEquipmentInfo( uint32 entry );
357 static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
359 return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
362 static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
364 return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
367 static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
369 static InstanceTemplate const* GetInstanceTemplate(uint32 map)
371 return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
374 PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
376 PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
378 if(class_ >= MAX_CLASSES) return NULL;
379 return &playerClassInfo[class_];
381 void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
383 PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
385 if(race >= MAX_RACES) return NULL;
386 if(class_ >= MAX_CLASSES) return NULL;
387 PlayerInfo const* info = &playerInfo[race][class_];
388 if(info->displayId_m==0 || info->displayId_f==0) return NULL;
389 return info;
391 void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
393 uint64 GetPlayerGUIDByName(std::string name) const;
394 bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
395 uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
396 uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
397 uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const;
399 uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team );
400 void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
401 uint16 GetTaxiMount( uint32 id, uint32 team, bool allowed_alt_team = false);
402 void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
403 void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
405 Quest const* GetQuestTemplate(uint32 quest_id) const
407 QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
408 return itr != mQuestTemplates.end() ? itr->second : NULL;
410 QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
412 uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
414 QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
415 if(itr != mQuestAreaTriggerMap.end())
416 return itr->second;
417 return 0;
419 bool IsTavernAreaTrigger(uint32 Trigger_ID) const
421 return mTavernAreaTriggerSet.find(Trigger_ID) != mTavernAreaTriggerSet.end();
424 bool IsGameObjectForQuests(uint32 entry) const
426 return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end();
429 GossipText const* GetGossipText(uint32 Text_ID) const;
431 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
432 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
433 void LoadGraveyardZones();
434 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
436 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
438 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
439 if( itr != mAreaTriggers.end( ) )
440 return &itr->second;
441 return NULL;
444 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
445 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
447 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
449 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
451 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
452 if(itr != mRepOnKill.end())
453 return &itr->second;
454 return NULL;
457 PointOfInterest const* GetPointOfInterest(uint32 id) const
459 PointOfInterestMap::const_iterator itr = mPointsOfInterest.find(id);
460 if(itr != mPointsOfInterest.end())
461 return &itr->second;
462 return NULL;
465 PetCreateSpellEntry const* GetPetCreateSpellEntry(uint32 id) const
467 PetCreateSpellMap::const_iterator itr = mPetCreateSpell.find(id);
468 if(itr != mPetCreateSpell.end())
469 return &itr->second;
470 return NULL;
473 void LoadGuilds();
474 void LoadArenaTeams();
475 void LoadGroups();
476 void LoadQuests();
477 void LoadQuestRelations()
479 LoadGameobjectQuestRelations();
480 LoadGameobjectInvolvedRelations();
481 LoadCreatureQuestRelations();
482 LoadCreatureInvolvedRelations();
484 void LoadGameobjectQuestRelations();
485 void LoadGameobjectInvolvedRelations();
486 void LoadCreatureQuestRelations();
487 void LoadCreatureInvolvedRelations();
489 QuestRelations mGOQuestRelations;
490 QuestRelations mGOQuestInvolvedRelations;
491 QuestRelations mCreatureQuestRelations;
492 QuestRelations mCreatureQuestInvolvedRelations;
494 void LoadGameObjectScripts();
495 void LoadQuestEndScripts();
496 void LoadQuestStartScripts();
497 void LoadEventScripts();
498 void LoadSpellScripts();
500 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
501 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
502 void LoadDbScriptStrings();
503 void LoadPetCreateSpells();
504 void LoadCreatureLocales();
505 void LoadCreatureTemplates();
506 void LoadCreatures();
507 void LoadCreatureRespawnTimes();
508 void LoadCreatureAddons();
509 void LoadCreatureModelInfo();
510 void LoadEquipmentTemplates();
511 void LoadGameObjectLocales();
512 void LoadGameobjects();
513 void LoadGameobjectRespawnTimes();
514 void LoadItemPrototypes();
515 void LoadItemLocales();
516 void LoadQuestLocales();
517 void LoadNpcTextLocales();
518 void LoadPageTextLocales();
519 void LoadNpcOptionLocales();
520 void LoadPointOfInterestLocales();
521 void LoadInstanceTemplate();
523 void LoadGossipText();
525 void LoadAreaTriggerTeleports();
526 void LoadQuestAreaTriggers();
527 void LoadAreaTriggerScripts();
528 void LoadTavernAreaTriggers();
529 void LoadGameObjectForQuests();
531 void LoadItemTexts();
532 void LoadPageTexts();
534 void LoadPlayerInfo();
535 void LoadPetLevelInfo();
536 void LoadExplorationBaseXP();
537 void LoadPetNames();
538 void LoadPetNumber();
539 void LoadCorpses();
540 void LoadFishingBaseSkillLevel();
542 void LoadReputationOnKill();
543 void LoadPointsOfInterest();
545 SpellClickInfoMap mSpellClickInfoMap;
546 void LoadNPCSpellClickSpells();
548 void LoadWeatherZoneChances();
549 void LoadGameTele();
551 void LoadNpcOptions();
552 void LoadNpcTextId();
553 void LoadVendors();
554 void LoadTrainerSpell();
556 std::string GeneratePetName(uint32 entry);
557 uint32 GetBaseXP(uint32 level);
558 uint32 GetXPForLevel(uint32 level);
560 int32 GetFishingBaseSkillLevel(uint32 entry) const
562 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
563 return itr != mFishingBaseForArea.end() ? itr->second : 0;
566 void ReturnOrDeleteOldMails(bool serverUp);
568 void SetHighestGuids();
569 uint32 GenerateLowGuid(HighGuid guidhigh);
570 uint32 GenerateArenaTeamId();
571 uint32 GenerateAuctionID();
572 uint64 GenerateEquipmentSetGuid();
573 uint32 GenerateGuildId();
574 uint32 GenerateItemTextID();
575 uint32 GenerateMailID();
576 uint32 GeneratePetNumber();
578 uint32 CreateItemText(std::string text);
579 std::string GetItemText( uint32 id )
581 ItemTextMap::const_iterator itr = mItemTexts.find( id );
582 if ( itr != mItemTexts.end() )
583 return itr->second;
584 else
585 return "There is no info for this item";
588 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
589 ExclusiveQuestGroups mExclusiveQuestGroups;
591 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
593 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
594 if(itr != mWeatherZoneMap.end())
595 return &itr->second;
596 else
597 return NULL;
600 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
602 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
605 CreatureData const* GetCreatureData(uint32 guid) const
607 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
608 if(itr==mCreatureDataMap.end()) return NULL;
609 return &itr->second;
611 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
612 void DeleteCreatureData(uint32 guid);
613 CreatureLocale const* GetCreatureLocale(uint32 entry) const
615 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
616 if(itr==mCreatureLocaleMap.end()) return NULL;
617 return &itr->second;
619 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
621 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
622 if(itr==mGameObjectLocaleMap.end()) return NULL;
623 return &itr->second;
625 ItemLocale const* GetItemLocale(uint32 entry) const
627 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
628 if(itr==mItemLocaleMap.end()) return NULL;
629 return &itr->second;
631 QuestLocale const* GetQuestLocale(uint32 entry) const
633 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
634 if(itr==mQuestLocaleMap.end()) return NULL;
635 return &itr->second;
637 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
639 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
640 if(itr==mNpcTextLocaleMap.end()) return NULL;
641 return &itr->second;
643 PageTextLocale const* GetPageTextLocale(uint32 entry) const
645 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
646 if(itr==mPageTextLocaleMap.end()) return NULL;
647 return &itr->second;
649 NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const
651 NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry);
652 if(itr==mNpcOptionLocaleMap.end()) return NULL;
653 return &itr->second;
655 PointOfInterestLocale const* GetPointOfInterestLocale(uint32 poi_id) const
657 PointOfInterestLocaleMap::const_iterator itr = mPointOfInterestLocaleMap.find(poi_id);
658 if(itr==mPointOfInterestLocaleMap.end()) return NULL;
659 return &itr->second;
662 GameObjectData const* GetGOData(uint32 guid) const
664 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
665 if(itr==mGameObjectDataMap.end()) return NULL;
666 return &itr->second;
668 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
669 void DeleteGOData(uint32 guid);
671 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
673 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
674 if(itr==mMangosStringLocaleMap.end()) return NULL;
675 return &itr->second;
677 const char *GetMangosString(int32 entry, int locale_idx) const;
678 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
679 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
680 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
682 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
683 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
685 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
686 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
687 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
688 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
689 void DeleteRespawnTimeForInstance(uint32 instance);
691 // grid objects
692 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
693 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
694 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
695 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
697 // reserved names
698 void LoadReservedPlayersNames();
699 bool IsReservedName(const std::string& name) const;
701 // name with valid structure and symbols
702 static bool IsValidName( const std::string& name, bool create = false );
703 static bool IsValidCharterName( const std::string& name );
704 static bool IsValidPetName( const std::string& name );
706 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
708 int GetIndexForLocale(LocaleConstant loc);
709 LocaleConstant GetLocaleForIndex(int i);
711 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
712 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
714 if(condition_id >= mConditions.size())
715 return false;
717 return mConditions[condition_id].Meets(player);
720 GameTele const* GetGameTele(uint32 id) const
722 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
723 if(itr==m_GameTeleMap.end()) return NULL;
724 return &itr->second;
726 GameTele const* GetGameTele(const std::string& name) const;
727 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
728 bool AddGameTele(GameTele& data);
729 bool DeleteGameTele(const std::string& name);
731 CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; }
733 uint32 GetNpcGossip(uint32 entry) const
735 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
736 if(iter == m_mCacheNpcTextIdMap.end())
737 return 0;
739 return iter->second;
742 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
744 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
745 if(iter == m_mCacheTrainerSpellMap.end())
746 return NULL;
748 return &iter->second;
751 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
753 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
754 if(iter == m_mCacheVendorItemMap.end())
755 return NULL;
757 return &iter->second;
759 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
760 bool RemoveVendorItem(uint32 entry,uint32 item);
761 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
763 void LoadScriptNames();
764 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
765 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
766 uint32 GetScriptId(const char *name);
768 int GetOrNewIndexForLocale(LocaleConstant loc);
769 protected:
771 // first free id for selected id type
772 uint32 m_arenaTeamId;
773 uint32 m_auctionid;
774 uint64 m_equipmentSetGuid;
775 uint32 m_guildId;
776 uint32 m_ItemTextId;
777 uint32 m_mailid;
778 uint32 m_hiPetNumber;
780 // first free low guid for seelcted guid type
781 uint32 m_hiCharGuid;
782 uint32 m_hiCreatureGuid;
783 uint32 m_hiPetGuid;
784 uint32 m_hiVehicleGuid;
785 uint32 m_hiItemGuid;
786 uint32 m_hiGoGuid;
787 uint32 m_hiDoGuid;
788 uint32 m_hiCorpseGuid;
790 QuestMap mQuestTemplates;
792 typedef UNORDERED_MAP<uint32, GossipText> GossipTextMap;
793 typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
794 typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
795 typedef std::set<uint32> TavernAreaTriggerSet;
796 typedef std::set<uint32> GameObjectForQuestSet;
798 GroupSet mGroupSet;
799 GuildMap mGuildMap;
800 ArenaTeamMap mArenaTeamMap;
802 ItemTextMap mItemTexts;
804 QuestAreaTriggerMap mQuestAreaTriggerMap;
805 TavernAreaTriggerSet mTavernAreaTriggerSet;
806 GameObjectForQuestSet mGameObjectForQuestSet;
807 GossipTextMap mGossipText;
808 AreaTriggerMap mAreaTriggers;
809 AreaTriggerScriptMap mAreaTriggerScripts;
811 RepOnKillMap mRepOnKill;
813 PointOfInterestMap mPointsOfInterest;
815 WeatherZoneMap mWeatherZoneMap;
817 PetCreateSpellMap mPetCreateSpell;
819 //character reserved names
820 typedef std::set<std::wstring> ReservedNamesMap;
821 ReservedNamesMap m_ReservedNames;
823 GraveYardMap mGraveYardMap;
825 GameTeleMap m_GameTeleMap;
827 ScriptNameMap m_scriptNames;
829 typedef std::vector<LocaleConstant> LocalForIndex;
830 LocalForIndex m_LocalForIndex;
832 int DBCLocaleIndex;
834 private:
835 void LoadScripts(ScriptMapMap& scripts, char const* tablename);
836 void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids);
837 void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
838 void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
840 typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
841 // PetLevelInfoMap[creature_id][level]
842 PetLevelInfoMap petInfo; // [creature_id][level]
844 PlayerClassInfo playerClassInfo[MAX_CLASSES];
846 void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
847 PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
849 typedef std::vector<uint32> PlayerXPperLevel; // [level]
850 PlayerXPperLevel mPlayerXPperLevel;
852 typedef std::map<uint32,uint32> BaseXPMap; // [area level][base xp]
853 BaseXPMap mBaseXPTable;
855 typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
856 FishingBaseSkillMap mFishingBaseForArea;
858 typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
859 HalfNameMap PetHalfName0;
860 HalfNameMap PetHalfName1;
862 MapObjectGuids mMapObjectGuids;
863 CreatureDataMap mCreatureDataMap;
864 CreatureLocaleMap mCreatureLocaleMap;
865 GameObjectDataMap mGameObjectDataMap;
866 GameObjectLocaleMap mGameObjectLocaleMap;
867 ItemLocaleMap mItemLocaleMap;
868 QuestLocaleMap mQuestLocaleMap;
869 NpcTextLocaleMap mNpcTextLocaleMap;
870 PageTextLocaleMap mPageTextLocaleMap;
871 MangosStringLocaleMap mMangosStringLocaleMap;
872 NpcOptionLocaleMap mNpcOptionLocaleMap;
873 PointOfInterestLocaleMap mPointOfInterestLocaleMap;
874 RespawnTimes mCreatureRespawnTimes;
875 RespawnTimes mGORespawnTimes;
877 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
878 typedef std::vector<PlayerCondition> ConditionStore;
879 ConditionStore mConditions;
881 CacheNpcOptionList m_mCacheNpcOptionList;
882 CacheNpcTextIdMap m_mCacheNpcTextIdMap;
883 CacheVendorItemMap m_mCacheVendorItemMap;
884 CacheTrainerSpellMap m_mCacheTrainerSpellMap;
887 #define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
889 // scripting access functions
890 MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits<int32>::min());
891 MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
892 MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
893 MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
894 MANGOS_DLL_SPEC CreatureInfo const* GetCreatureTemplateStore(uint32 entry);
895 MANGOS_DLL_SPEC Quest const* GetQuestTemplateStore(uint32 entry);
897 #endif