[7986] MaNGOS 0.13 release.
[getmangos.git] / src / game / ObjectMgr.h
blob72465c48aa0721e922d2e8b06f58633beb9140c4
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 // 'mangos_string'
140 #define MAX_MANGOS_STRING_ID 2000000000
141 #define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID // 'db_script_string'
142 #define MAX_DB_SCRIPT_STRING_ID 2000010000
143 #define MIN_CREATURE_AI_TEXT_STRING_ID (-1) // 'creature_ai_texts'
144 #define MAX_CREATURE_AI_TEXT_STRING_ID (-1000000)
146 struct MangosStringLocale
148 std::vector<std::string> Content; // 0 -> default, i -> i-1 locale index
151 typedef UNORDERED_MAP<uint32,CreatureData> CreatureDataMap;
152 typedef UNORDERED_MAP<uint32,GameObjectData> GameObjectDataMap;
153 typedef UNORDERED_MAP<uint32,CreatureLocale> CreatureLocaleMap;
154 typedef UNORDERED_MAP<uint32,GameObjectLocale> GameObjectLocaleMap;
155 typedef UNORDERED_MAP<uint32,ItemLocale> ItemLocaleMap;
156 typedef UNORDERED_MAP<uint32,QuestLocale> QuestLocaleMap;
157 typedef UNORDERED_MAP<uint32,NpcTextLocale> NpcTextLocaleMap;
158 typedef UNORDERED_MAP<uint32,PageTextLocale> PageTextLocaleMap;
159 typedef UNORDERED_MAP<int32,MangosStringLocale> MangosStringLocaleMap;
160 typedef UNORDERED_MAP<uint32,NpcOptionLocale> NpcOptionLocaleMap;
161 typedef UNORDERED_MAP<uint32,PointOfInterestLocale> PointOfInterestLocaleMap;
163 typedef std::multimap<uint32,uint32> QuestRelations;
164 typedef std::multimap<uint32,ItemRequiredTarget> ItemRequiredTargetMap;
165 typedef std::pair<ItemRequiredTargetMap::const_iterator, ItemRequiredTargetMap::const_iterator> ItemRequiredTargetMapBounds;
167 struct PetLevelInfo
169 PetLevelInfo() : health(0), mana(0) { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
171 uint16 stats[MAX_STATS];
172 uint16 health;
173 uint16 mana;
174 uint16 armor;
177 struct ReputationOnKillEntry
179 uint32 repfaction1;
180 uint32 repfaction2;
181 bool is_teamaward1;
182 uint32 reputation_max_cap1;
183 int32 repvalue1;
184 bool is_teamaward2;
185 uint32 reputation_max_cap2;
186 int32 repvalue2;
187 bool team_dependent;
190 struct PointOfInterest
192 uint32 entry;
193 float x;
194 float y;
195 uint32 icon;
196 uint32 flags;
197 uint32 data;
198 std::string icon_name;
201 #define WEATHER_SEASONS 4
202 struct WeatherSeasonChances
204 uint32 rainChance;
205 uint32 snowChance;
206 uint32 stormChance;
209 struct WeatherZoneChances
211 WeatherSeasonChances data[WEATHER_SEASONS];
214 struct GraveYardData
216 uint32 safeLocId;
217 uint32 team;
219 typedef std::multimap<uint32,GraveYardData> GraveYardMap;
221 enum ConditionType
222 { // value1 value2 for the Condition enumed
223 CONDITION_NONE = 0, // 0 0
224 CONDITION_AURA = 1, // spell_id effindex
225 CONDITION_ITEM = 2, // item_id count
226 CONDITION_ITEM_EQUIPPED = 3, // item_id 0
227 CONDITION_ZONEID = 4, // zone_id 0
228 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank
229 CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde)
230 CONDITION_SKILL = 7, // skill_id skill_value
231 CONDITION_QUESTREWARDED = 8, // quest_id 0
232 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active.
233 CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD ñommission aura active
234 CONDITION_NO_AURA = 11, // spell_id effindex
235 CONDITION_ACTIVE_EVENT = 12, // event_id
238 #define MAX_CONDITION 13 // maximum value in ConditionType enum
240 struct PlayerCondition
242 ConditionType condition; // additional condition type
243 uint32 value1; // data for the condition - see ConditionType definition
244 uint32 value2;
246 PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
247 : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
249 static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
250 // Checks correctness of values
251 bool Meets(Player const * APlayer) const; // Checks if the player meets the condition
252 bool operator == (PlayerCondition const& lc) const
254 return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
258 // NPC gossip text id
259 typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
260 typedef std::list<GossipOption> CacheNpcOptionList;
262 typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
263 typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
265 enum SkillRangeType
267 SKILL_RANGE_LANGUAGE, // 300..300
268 SKILL_RANGE_LEVEL, // 1..max skill for level
269 SKILL_RANGE_MONO, // 1..1, grey monolite bar
270 SKILL_RANGE_RANK, // 1..skill for known rank
271 SKILL_RANGE_NONE, // 0..0 always
274 SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
276 #define MAX_PLAYER_NAME 12 // max allowed by client name length
277 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
279 bool normalizePlayerName(std::string& name);
281 struct MANGOS_DLL_SPEC LanguageDesc
283 Language lang_id;
284 uint32 spell_id;
285 uint32 skill_id;
288 extern LanguageDesc lang_description[LANGUAGES_COUNT];
289 MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
291 class PlayerDumpReader;
293 class ObjectMgr
295 friend class PlayerDumpReader;
297 public:
298 ObjectMgr();
299 ~ObjectMgr();
301 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
303 typedef std::set< Group * > GroupSet;
305 typedef UNORDERED_MAP<uint32, Guild *> GuildMap;
307 typedef UNORDERED_MAP<uint32, ArenaTeam*> ArenaTeamMap;
309 typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
311 typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
313 typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
315 typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
316 typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap;
318 typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
320 typedef std::vector<std::string> ScriptNameMap;
322 Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);}
323 Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
325 static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
327 void LoadGameobjectInfo();
328 void AddGameobjectInfo(GameObjectInfo *goinfo);
330 Group * GetGroupByLeader(const uint64 &guid) const;
331 void AddGroup(Group* group) { mGroupSet.insert( group ); }
332 void RemoveGroup(Group* group) { mGroupSet.erase( group ); }
334 Guild* GetGuildByLeader(uint64 const&guid) const;
335 Guild* GetGuildById(uint32 GuildId) const;
336 Guild* GetGuildByName(const std::string& guildname) const;
337 std::string GetGuildNameById(uint32 GuildId) const;
338 void AddGuild(Guild* guild);
339 void RemoveGuild(uint32 Id);
341 ArenaTeam* GetArenaTeamById(uint32 arenateamid) const;
342 ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
343 ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
344 void AddArenaTeam(ArenaTeam* arenaTeam);
345 void RemoveArenaTeam(uint32 Id);
346 ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
347 ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
349 static CreatureInfo const *GetCreatureTemplate( uint32 id );
350 CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
351 CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
352 uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
353 EquipmentInfo const *GetEquipmentInfo( uint32 entry );
354 static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
356 return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
359 static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
361 return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
364 static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
366 static InstanceTemplate const* GetInstanceTemplate(uint32 map)
368 return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
371 PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
373 PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
375 if(class_ >= MAX_CLASSES) return NULL;
376 return &playerClassInfo[class_];
378 void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
380 PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
382 if(race >= MAX_RACES) return NULL;
383 if(class_ >= MAX_CLASSES) return NULL;
384 PlayerInfo const* info = &playerInfo[race][class_];
385 if(info->displayId_m==0 || info->displayId_f==0) return NULL;
386 return info;
388 void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
390 uint64 GetPlayerGUIDByName(std::string name) const;
391 bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
392 uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
393 uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
394 uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const;
396 uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team );
397 void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
398 uint16 GetTaxiMount( uint32 id, uint32 team, bool allowed_alt_team = false);
399 void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
400 void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
402 Quest const* GetQuestTemplate(uint32 quest_id) const
404 QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
405 return itr != mQuestTemplates.end() ? itr->second : NULL;
407 QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
409 uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
411 QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
412 if(itr != mQuestAreaTriggerMap.end())
413 return itr->second;
414 return 0;
416 bool IsTavernAreaTrigger(uint32 Trigger_ID) const
418 return mTavernAreaTriggerSet.find(Trigger_ID) != mTavernAreaTriggerSet.end();
421 bool IsGameObjectForQuests(uint32 entry) const
423 return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end();
426 GossipText const* GetGossipText(uint32 Text_ID) const;
428 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
429 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
430 void LoadGraveyardZones();
431 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
433 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
435 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
436 if( itr != mAreaTriggers.end( ) )
437 return &itr->second;
438 return NULL;
441 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
442 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
444 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
446 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
448 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
449 if(itr != mRepOnKill.end())
450 return &itr->second;
451 return NULL;
454 PointOfInterest const* GetPointOfInterest(uint32 id) const
456 PointOfInterestMap::const_iterator itr = mPointsOfInterest.find(id);
457 if(itr != mPointsOfInterest.end())
458 return &itr->second;
459 return NULL;
462 void LoadGuilds();
463 void LoadArenaTeams();
464 void LoadGroups();
465 void LoadQuests();
466 void LoadQuestRelations()
468 LoadGameobjectQuestRelations();
469 LoadGameobjectInvolvedRelations();
470 LoadCreatureQuestRelations();
471 LoadCreatureInvolvedRelations();
473 void LoadGameobjectQuestRelations();
474 void LoadGameobjectInvolvedRelations();
475 void LoadCreatureQuestRelations();
476 void LoadCreatureInvolvedRelations();
478 QuestRelations mGOQuestRelations;
479 QuestRelations mGOQuestInvolvedRelations;
480 QuestRelations mCreatureQuestRelations;
481 QuestRelations mCreatureQuestInvolvedRelations;
483 void LoadGameObjectScripts();
484 void LoadQuestEndScripts();
485 void LoadQuestStartScripts();
486 void LoadEventScripts();
487 void LoadSpellScripts();
489 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
490 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
491 void LoadDbScriptStrings();
492 void LoadCreatureLocales();
493 void LoadCreatureTemplates();
494 void LoadCreatures();
495 void LoadCreatureRespawnTimes();
496 void LoadCreatureAddons();
497 void LoadCreatureModelInfo();
498 void LoadEquipmentTemplates();
499 void LoadGameObjectLocales();
500 void LoadGameobjects();
501 void LoadGameobjectRespawnTimes();
502 void LoadItemPrototypes();
503 void LoadItemRequiredTarget();
504 void LoadItemLocales();
505 void LoadQuestLocales();
506 void LoadNpcTextLocales();
507 void LoadPageTextLocales();
508 void LoadNpcOptionLocales();
509 void LoadPointOfInterestLocales();
510 void LoadInstanceTemplate();
512 void LoadGossipText();
514 void LoadAreaTriggerTeleports();
515 void LoadQuestAreaTriggers();
516 void LoadAreaTriggerScripts();
517 void LoadTavernAreaTriggers();
518 void LoadGameObjectForQuests();
520 void LoadItemTexts();
521 void LoadPageTexts();
523 void LoadPlayerInfo();
524 void LoadPetLevelInfo();
525 void LoadExplorationBaseXP();
526 void LoadPetNames();
527 void LoadPetNumber();
528 void LoadCorpses();
529 void LoadFishingBaseSkillLevel();
531 void LoadReputationOnKill();
532 void LoadPointsOfInterest();
534 SpellClickInfoMap mSpellClickInfoMap;
535 void LoadNPCSpellClickSpells();
537 void LoadWeatherZoneChances();
538 void LoadGameTele();
540 void LoadNpcOptions();
541 void LoadNpcTextId();
542 void LoadVendors();
543 void LoadTrainerSpell();
545 std::string GeneratePetName(uint32 entry);
546 uint32 GetBaseXP(uint32 level);
547 uint32 GetXPForLevel(uint32 level);
549 int32 GetFishingBaseSkillLevel(uint32 entry) const
551 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
552 return itr != mFishingBaseForArea.end() ? itr->second : 0;
555 void ReturnOrDeleteOldMails(bool serverUp);
557 void SetHighestGuids();
558 uint32 GenerateLowGuid(HighGuid guidhigh);
559 uint32 GenerateArenaTeamId();
560 uint32 GenerateAuctionID();
561 uint32 GenerateGuildId();
562 uint32 GenerateItemTextID();
563 uint32 GenerateMailID();
564 uint32 GeneratePetNumber();
566 uint32 CreateItemText(std::string text);
567 std::string GetItemText( uint32 id )
569 ItemTextMap::const_iterator itr = mItemTexts.find( id );
570 if ( itr != mItemTexts.end() )
571 return itr->second;
572 else
573 return "There is no info for this item";
576 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
577 ExclusiveQuestGroups mExclusiveQuestGroups;
579 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
581 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
582 if(itr != mWeatherZoneMap.end())
583 return &itr->second;
584 else
585 return NULL;
588 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
590 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
593 CreatureData const* GetCreatureData(uint32 guid) const
595 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
596 if(itr==mCreatureDataMap.end()) return NULL;
597 return &itr->second;
599 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
600 void DeleteCreatureData(uint32 guid);
601 CreatureLocale const* GetCreatureLocale(uint32 entry) const
603 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
604 if(itr==mCreatureLocaleMap.end()) return NULL;
605 return &itr->second;
607 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
609 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
610 if(itr==mGameObjectLocaleMap.end()) return NULL;
611 return &itr->second;
613 ItemLocale const* GetItemLocale(uint32 entry) const
615 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
616 if(itr==mItemLocaleMap.end()) return NULL;
617 return &itr->second;
619 QuestLocale const* GetQuestLocale(uint32 entry) const
621 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
622 if(itr==mQuestLocaleMap.end()) return NULL;
623 return &itr->second;
625 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
627 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
628 if(itr==mNpcTextLocaleMap.end()) return NULL;
629 return &itr->second;
631 PageTextLocale const* GetPageTextLocale(uint32 entry) const
633 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
634 if(itr==mPageTextLocaleMap.end()) return NULL;
635 return &itr->second;
637 NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const
639 NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry);
640 if(itr==mNpcOptionLocaleMap.end()) return NULL;
641 return &itr->second;
643 PointOfInterestLocale const* GetPointOfInterestLocale(uint32 poi_id) const
645 PointOfInterestLocaleMap::const_iterator itr = mPointOfInterestLocaleMap.find(poi_id);
646 if(itr==mPointOfInterestLocaleMap.end()) return NULL;
647 return &itr->second;
650 GameObjectData const* GetGOData(uint32 guid) const
652 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
653 if(itr==mGameObjectDataMap.end()) return NULL;
654 return &itr->second;
656 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
657 void DeleteGOData(uint32 guid);
659 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
661 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
662 if(itr==mMangosStringLocaleMap.end()) return NULL;
663 return &itr->second;
665 const char *GetMangosString(int32 entry, int locale_idx) const;
666 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
667 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
668 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
670 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
671 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
673 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
674 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
675 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
676 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
677 void DeleteRespawnTimeForInstance(uint32 instance);
679 // grid objects
680 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
681 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
682 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
683 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
685 // reserved names
686 void LoadReservedPlayersNames();
687 bool IsReservedName(const std::string& name) const;
689 // name with valid structure and symbols
690 static bool IsValidName( const std::string& name, bool create = false );
691 static bool IsValidCharterName( const std::string& name );
692 static bool IsValidPetName( const std::string& name );
694 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
696 int GetIndexForLocale(LocaleConstant loc);
697 LocaleConstant GetLocaleForIndex(int i);
699 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
700 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
702 if(condition_id >= mConditions.size())
703 return false;
705 return mConditions[condition_id].Meets(player);
708 GameTele const* GetGameTele(uint32 id) const
710 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
711 if(itr==m_GameTeleMap.end()) return NULL;
712 return &itr->second;
714 GameTele const* GetGameTele(const std::string& name) const;
715 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
716 bool AddGameTele(GameTele& data);
717 bool DeleteGameTele(const std::string& name);
719 CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; }
721 uint32 GetNpcGossip(uint32 entry) const
723 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
724 if(iter == m_mCacheNpcTextIdMap.end())
725 return 0;
727 return iter->second;
730 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
732 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
733 if(iter == m_mCacheTrainerSpellMap.end())
734 return NULL;
736 return &iter->second;
739 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
741 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
742 if(iter == m_mCacheVendorItemMap.end())
743 return NULL;
745 return &iter->second;
747 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
748 bool RemoveVendorItem(uint32 entry,uint32 item);
749 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
751 void LoadScriptNames();
752 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
753 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
754 uint32 GetScriptId(const char *name);
756 int GetOrNewIndexForLocale(LocaleConstant loc);
758 ItemRequiredTargetMapBounds GetItemRequiredTargetMapBounds(uint32 uiItemEntry) const
760 return ItemRequiredTargetMapBounds(m_ItemRequiredTarget.lower_bound(uiItemEntry),m_ItemRequiredTarget.upper_bound(uiItemEntry));
763 protected:
765 // first free id for selected id type
766 uint32 m_arenaTeamId;
767 uint32 m_auctionid;
768 uint32 m_guildId;
769 uint32 m_ItemTextId;
770 uint32 m_mailid;
771 uint32 m_hiPetNumber;
773 // first free low guid for seelcted guid type
774 uint32 m_hiCharGuid;
775 uint32 m_hiCreatureGuid;
776 uint32 m_hiPetGuid;
777 uint32 m_hiVehicleGuid;
778 uint32 m_hiItemGuid;
779 uint32 m_hiGoGuid;
780 uint32 m_hiDoGuid;
781 uint32 m_hiCorpseGuid;
783 QuestMap mQuestTemplates;
785 typedef UNORDERED_MAP<uint32, GossipText> GossipTextMap;
786 typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
787 typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
788 typedef std::set<uint32> TavernAreaTriggerSet;
789 typedef std::set<uint32> GameObjectForQuestSet;
791 GroupSet mGroupSet;
792 GuildMap mGuildMap;
793 ArenaTeamMap mArenaTeamMap;
795 ItemTextMap mItemTexts;
797 QuestAreaTriggerMap mQuestAreaTriggerMap;
798 TavernAreaTriggerSet mTavernAreaTriggerSet;
799 GameObjectForQuestSet mGameObjectForQuestSet;
800 GossipTextMap mGossipText;
801 AreaTriggerMap mAreaTriggers;
802 AreaTriggerScriptMap mAreaTriggerScripts;
804 RepOnKillMap mRepOnKill;
806 PointOfInterestMap mPointsOfInterest;
808 WeatherZoneMap mWeatherZoneMap;
810 //character reserved names
811 typedef std::set<std::wstring> ReservedNamesMap;
812 ReservedNamesMap m_ReservedNames;
814 GraveYardMap mGraveYardMap;
816 GameTeleMap m_GameTeleMap;
818 ScriptNameMap m_scriptNames;
820 ItemRequiredTargetMap m_ItemRequiredTarget;
822 typedef std::vector<LocaleConstant> LocalForIndex;
823 LocalForIndex m_LocalForIndex;
825 int DBCLocaleIndex;
827 private:
828 void LoadScripts(ScriptMapMap& scripts, char const* tablename);
829 void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids);
830 void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
831 void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
833 typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
834 // PetLevelInfoMap[creature_id][level]
835 PetLevelInfoMap petInfo; // [creature_id][level]
837 PlayerClassInfo playerClassInfo[MAX_CLASSES];
839 void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
840 PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
842 typedef std::vector<uint32> PlayerXPperLevel; // [level]
843 PlayerXPperLevel mPlayerXPperLevel;
845 typedef std::map<uint32,uint32> BaseXPMap; // [area level][base xp]
846 BaseXPMap mBaseXPTable;
848 typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
849 FishingBaseSkillMap mFishingBaseForArea;
851 typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
852 HalfNameMap PetHalfName0;
853 HalfNameMap PetHalfName1;
855 MapObjectGuids mMapObjectGuids;
856 CreatureDataMap mCreatureDataMap;
857 CreatureLocaleMap mCreatureLocaleMap;
858 GameObjectDataMap mGameObjectDataMap;
859 GameObjectLocaleMap mGameObjectLocaleMap;
860 ItemLocaleMap mItemLocaleMap;
861 QuestLocaleMap mQuestLocaleMap;
862 NpcTextLocaleMap mNpcTextLocaleMap;
863 PageTextLocaleMap mPageTextLocaleMap;
864 MangosStringLocaleMap mMangosStringLocaleMap;
865 NpcOptionLocaleMap mNpcOptionLocaleMap;
866 PointOfInterestLocaleMap mPointOfInterestLocaleMap;
867 RespawnTimes mCreatureRespawnTimes;
868 RespawnTimes mGORespawnTimes;
870 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
871 typedef std::vector<PlayerCondition> ConditionStore;
872 ConditionStore mConditions;
874 CacheNpcOptionList m_mCacheNpcOptionList;
875 CacheNpcTextIdMap m_mCacheNpcTextIdMap;
876 CacheVendorItemMap m_mCacheVendorItemMap;
877 CacheTrainerSpellMap m_mCacheTrainerSpellMap;
880 #define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
882 // scripting access functions
883 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());
884 MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
885 MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
886 MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
887 MANGOS_DLL_SPEC CreatureInfo const* GetCreatureTemplateStore(uint32 entry);
888 MANGOS_DLL_SPEC Quest const* GetQuestTemplateStore(uint32 entry);
890 #endif