[7915] Implement more stricted checks and limitations at loading creature addon data.
[getmangos.git] / src / game / ObjectMgr.h
blobbb58b723b22fe27d75d8c9dcdb8a97c8964c0f70
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;
165 struct PetLevelInfo
167 PetLevelInfo() : health(0), mana(0) { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
169 uint16 stats[MAX_STATS];
170 uint16 health;
171 uint16 mana;
172 uint16 armor;
175 struct ReputationOnKillEntry
177 uint32 repfaction1;
178 uint32 repfaction2;
179 bool is_teamaward1;
180 uint32 reputation_max_cap1;
181 int32 repvalue1;
182 bool is_teamaward2;
183 uint32 reputation_max_cap2;
184 int32 repvalue2;
185 bool team_dependent;
188 struct PointOfInterest
190 uint32 entry;
191 float x;
192 float y;
193 uint32 icon;
194 uint32 flags;
195 uint32 data;
196 std::string icon_name;
199 #define WEATHER_SEASONS 4
200 struct WeatherSeasonChances
202 uint32 rainChance;
203 uint32 snowChance;
204 uint32 stormChance;
207 struct WeatherZoneChances
209 WeatherSeasonChances data[WEATHER_SEASONS];
212 struct GraveYardData
214 uint32 safeLocId;
215 uint32 team;
217 typedef std::multimap<uint32,GraveYardData> GraveYardMap;
219 enum ConditionType
220 { // value1 value2 for the Condition enumed
221 CONDITION_NONE = 0, // 0 0
222 CONDITION_AURA = 1, // spell_id effindex
223 CONDITION_ITEM = 2, // item_id count
224 CONDITION_ITEM_EQUIPPED = 3, // item_id 0
225 CONDITION_ZONEID = 4, // zone_id 0
226 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank
227 CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde)
228 CONDITION_SKILL = 7, // skill_id skill_value
229 CONDITION_QUESTREWARDED = 8, // quest_id 0
230 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active.
231 CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD ñommission aura active
232 CONDITION_NO_AURA = 11, // spell_id effindex
233 CONDITION_ACTIVE_EVENT = 12, // event_id
236 #define MAX_CONDITION 13 // maximum value in ConditionType enum
238 struct PlayerCondition
240 ConditionType condition; // additional condition type
241 uint32 value1; // data for the condition - see ConditionType definition
242 uint32 value2;
244 PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
245 : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
247 static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
248 // Checks correctness of values
249 bool Meets(Player const * APlayer) const; // Checks if the player meets the condition
250 bool operator == (PlayerCondition const& lc) const
252 return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
256 // NPC gossip text id
257 typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
258 typedef std::list<GossipOption> CacheNpcOptionList;
260 typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
261 typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
263 enum SkillRangeType
265 SKILL_RANGE_LANGUAGE, // 300..300
266 SKILL_RANGE_LEVEL, // 1..max skill for level
267 SKILL_RANGE_MONO, // 1..1, grey monolite bar
268 SKILL_RANGE_RANK, // 1..skill for known rank
269 SKILL_RANGE_NONE, // 0..0 always
272 SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
274 #define MAX_PLAYER_NAME 12 // max allowed by client name length
275 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
277 bool normalizePlayerName(std::string& name);
279 struct MANGOS_DLL_SPEC LanguageDesc
281 Language lang_id;
282 uint32 spell_id;
283 uint32 skill_id;
286 extern LanguageDesc lang_description[LANGUAGES_COUNT];
287 MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
289 class PlayerDumpReader;
291 class ObjectMgr
293 friend class PlayerDumpReader;
295 public:
296 ObjectMgr();
297 ~ObjectMgr();
299 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
301 typedef std::set< Group * > GroupSet;
303 typedef UNORDERED_MAP<uint32, Guild *> GuildMap;
305 typedef UNORDERED_MAP<uint32, ArenaTeam*> ArenaTeamMap;
307 typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
309 typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
311 typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
313 typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
314 typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap;
316 typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
318 typedef std::vector<std::string> ScriptNameMap;
320 Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);}
321 Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
323 static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
325 void LoadGameobjectInfo();
326 void AddGameobjectInfo(GameObjectInfo *goinfo);
328 Group * GetGroupByLeader(const uint64 &guid) const;
329 void AddGroup(Group* group) { mGroupSet.insert( group ); }
330 void RemoveGroup(Group* group) { mGroupSet.erase( group ); }
332 Guild* GetGuildByLeader(uint64 const&guid) const;
333 Guild* GetGuildById(uint32 GuildId) const;
334 Guild* GetGuildByName(const std::string& guildname) const;
335 std::string GetGuildNameById(uint32 GuildId) const;
336 void AddGuild(Guild* guild);
337 void RemoveGuild(uint32 Id);
339 ArenaTeam* GetArenaTeamById(uint32 arenateamid) const;
340 ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
341 ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
342 void AddArenaTeam(ArenaTeam* arenaTeam);
343 void RemoveArenaTeam(uint32 Id);
344 ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
345 ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
347 static CreatureInfo const *GetCreatureTemplate( uint32 id );
348 CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
349 CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
350 uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
351 EquipmentInfo const *GetEquipmentInfo( uint32 entry );
352 static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
354 return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
357 static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
359 return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
362 static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
364 static InstanceTemplate const* GetInstanceTemplate(uint32 map)
366 return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
369 PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
371 PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
373 if(class_ >= MAX_CLASSES) return NULL;
374 return &playerClassInfo[class_];
376 void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
378 PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
380 if(race >= MAX_RACES) return NULL;
381 if(class_ >= MAX_CLASSES) return NULL;
382 PlayerInfo const* info = &playerInfo[race][class_];
383 if(info->displayId_m==0 || info->displayId_f==0) return NULL;
384 return info;
386 void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
388 uint64 GetPlayerGUIDByName(std::string name) const;
389 bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
390 uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
391 uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
392 uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const;
394 uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team );
395 void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
396 uint16 GetTaxiMount( uint32 id, uint32 team, bool allowed_alt_team = false);
397 void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
398 void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
400 Quest const* GetQuestTemplate(uint32 quest_id) const
402 QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
403 return itr != mQuestTemplates.end() ? itr->second : NULL;
405 QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
407 uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
409 QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
410 if(itr != mQuestAreaTriggerMap.end())
411 return itr->second;
412 return 0;
414 bool IsTavernAreaTrigger(uint32 Trigger_ID) const
416 return mTavernAreaTriggerSet.find(Trigger_ID) != mTavernAreaTriggerSet.end();
419 bool IsGameObjectForQuests(uint32 entry) const
421 return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end();
424 GossipText const* GetGossipText(uint32 Text_ID) const;
426 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
427 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
428 void LoadGraveyardZones();
429 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
431 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
433 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
434 if( itr != mAreaTriggers.end( ) )
435 return &itr->second;
436 return NULL;
439 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
440 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
442 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
444 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
446 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
447 if(itr != mRepOnKill.end())
448 return &itr->second;
449 return NULL;
452 PointOfInterest const* GetPointOfInterest(uint32 id) const
454 PointOfInterestMap::const_iterator itr = mPointsOfInterest.find(id);
455 if(itr != mPointsOfInterest.end())
456 return &itr->second;
457 return NULL;
460 void LoadGuilds();
461 void LoadArenaTeams();
462 void LoadGroups();
463 void LoadQuests();
464 void LoadQuestRelations()
466 LoadGameobjectQuestRelations();
467 LoadGameobjectInvolvedRelations();
468 LoadCreatureQuestRelations();
469 LoadCreatureInvolvedRelations();
471 void LoadGameobjectQuestRelations();
472 void LoadGameobjectInvolvedRelations();
473 void LoadCreatureQuestRelations();
474 void LoadCreatureInvolvedRelations();
476 QuestRelations mGOQuestRelations;
477 QuestRelations mGOQuestInvolvedRelations;
478 QuestRelations mCreatureQuestRelations;
479 QuestRelations mCreatureQuestInvolvedRelations;
481 void LoadGameObjectScripts();
482 void LoadQuestEndScripts();
483 void LoadQuestStartScripts();
484 void LoadEventScripts();
485 void LoadSpellScripts();
487 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
488 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
489 void LoadDbScriptStrings();
490 void LoadCreatureLocales();
491 void LoadCreatureTemplates();
492 void LoadCreatures();
493 void LoadCreatureRespawnTimes();
494 void LoadCreatureAddons();
495 void LoadCreatureModelInfo();
496 void LoadEquipmentTemplates();
497 void LoadGameObjectLocales();
498 void LoadGameobjects();
499 void LoadGameobjectRespawnTimes();
500 void LoadItemPrototypes();
501 void LoadItemLocales();
502 void LoadQuestLocales();
503 void LoadNpcTextLocales();
504 void LoadPageTextLocales();
505 void LoadNpcOptionLocales();
506 void LoadPointOfInterestLocales();
507 void LoadInstanceTemplate();
509 void LoadGossipText();
511 void LoadAreaTriggerTeleports();
512 void LoadQuestAreaTriggers();
513 void LoadAreaTriggerScripts();
514 void LoadTavernAreaTriggers();
515 void LoadGameObjectForQuests();
517 void LoadItemTexts();
518 void LoadPageTexts();
520 void LoadPlayerInfo();
521 void LoadPetLevelInfo();
522 void LoadExplorationBaseXP();
523 void LoadPetNames();
524 void LoadPetNumber();
525 void LoadCorpses();
526 void LoadFishingBaseSkillLevel();
528 void LoadReputationOnKill();
529 void LoadPointsOfInterest();
531 SpellClickInfoMap mSpellClickInfoMap;
532 void LoadNPCSpellClickSpells();
534 void LoadWeatherZoneChances();
535 void LoadGameTele();
537 void LoadNpcOptions();
538 void LoadNpcTextId();
539 void LoadVendors();
540 void LoadTrainerSpell();
542 std::string GeneratePetName(uint32 entry);
543 uint32 GetBaseXP(uint32 level);
544 uint32 GetXPForLevel(uint32 level);
546 int32 GetFishingBaseSkillLevel(uint32 entry) const
548 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
549 return itr != mFishingBaseForArea.end() ? itr->second : 0;
552 void ReturnOrDeleteOldMails(bool serverUp);
554 void SetHighestGuids();
555 uint32 GenerateLowGuid(HighGuid guidhigh);
556 uint32 GenerateArenaTeamId();
557 uint32 GenerateAuctionID();
558 uint32 GenerateGuildId();
559 uint32 GenerateItemTextID();
560 uint32 GenerateMailID();
561 uint32 GeneratePetNumber();
563 uint32 CreateItemText(std::string text);
564 std::string GetItemText( uint32 id )
566 ItemTextMap::const_iterator itr = mItemTexts.find( id );
567 if ( itr != mItemTexts.end() )
568 return itr->second;
569 else
570 return "There is no info for this item";
573 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
574 ExclusiveQuestGroups mExclusiveQuestGroups;
576 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
578 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
579 if(itr != mWeatherZoneMap.end())
580 return &itr->second;
581 else
582 return NULL;
585 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
587 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
590 CreatureData const* GetCreatureData(uint32 guid) const
592 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
593 if(itr==mCreatureDataMap.end()) return NULL;
594 return &itr->second;
596 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
597 void DeleteCreatureData(uint32 guid);
598 CreatureLocale const* GetCreatureLocale(uint32 entry) const
600 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
601 if(itr==mCreatureLocaleMap.end()) return NULL;
602 return &itr->second;
604 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
606 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
607 if(itr==mGameObjectLocaleMap.end()) return NULL;
608 return &itr->second;
610 ItemLocale const* GetItemLocale(uint32 entry) const
612 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
613 if(itr==mItemLocaleMap.end()) return NULL;
614 return &itr->second;
616 QuestLocale const* GetQuestLocale(uint32 entry) const
618 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
619 if(itr==mQuestLocaleMap.end()) return NULL;
620 return &itr->second;
622 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
624 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
625 if(itr==mNpcTextLocaleMap.end()) return NULL;
626 return &itr->second;
628 PageTextLocale const* GetPageTextLocale(uint32 entry) const
630 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
631 if(itr==mPageTextLocaleMap.end()) return NULL;
632 return &itr->second;
634 NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const
636 NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry);
637 if(itr==mNpcOptionLocaleMap.end()) return NULL;
638 return &itr->second;
640 PointOfInterestLocale const* GetPointOfInterestLocale(uint32 poi_id) const
642 PointOfInterestLocaleMap::const_iterator itr = mPointOfInterestLocaleMap.find(poi_id);
643 if(itr==mPointOfInterestLocaleMap.end()) return NULL;
644 return &itr->second;
647 GameObjectData const* GetGOData(uint32 guid) const
649 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
650 if(itr==mGameObjectDataMap.end()) return NULL;
651 return &itr->second;
653 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
654 void DeleteGOData(uint32 guid);
656 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
658 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
659 if(itr==mMangosStringLocaleMap.end()) return NULL;
660 return &itr->second;
662 const char *GetMangosString(int32 entry, int locale_idx) const;
663 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
664 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
665 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
667 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
668 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
670 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
671 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
672 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
673 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
674 void DeleteRespawnTimeForInstance(uint32 instance);
676 // grid objects
677 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
678 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
679 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
680 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
682 // reserved names
683 void LoadReservedPlayersNames();
684 bool IsReservedName(const std::string& name) const;
686 // name with valid structure and symbols
687 static bool IsValidName( const std::string& name, bool create = false );
688 static bool IsValidCharterName( const std::string& name );
689 static bool IsValidPetName( const std::string& name );
691 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
693 int GetIndexForLocale(LocaleConstant loc);
694 LocaleConstant GetLocaleForIndex(int i);
696 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
697 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
699 if(condition_id >= mConditions.size())
700 return false;
702 return mConditions[condition_id].Meets(player);
705 GameTele const* GetGameTele(uint32 id) const
707 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
708 if(itr==m_GameTeleMap.end()) return NULL;
709 return &itr->second;
711 GameTele const* GetGameTele(const std::string& name) const;
712 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
713 bool AddGameTele(GameTele& data);
714 bool DeleteGameTele(const std::string& name);
716 CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; }
718 uint32 GetNpcGossip(uint32 entry) const
720 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
721 if(iter == m_mCacheNpcTextIdMap.end())
722 return 0;
724 return iter->second;
727 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
729 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
730 if(iter == m_mCacheTrainerSpellMap.end())
731 return NULL;
733 return &iter->second;
736 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
738 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
739 if(iter == m_mCacheVendorItemMap.end())
740 return NULL;
742 return &iter->second;
744 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
745 bool RemoveVendorItem(uint32 entry,uint32 item);
746 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
748 void LoadScriptNames();
749 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
750 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
751 uint32 GetScriptId(const char *name);
753 int GetOrNewIndexForLocale(LocaleConstant loc);
754 protected:
756 // first free id for selected id type
757 uint32 m_arenaTeamId;
758 uint32 m_auctionid;
759 uint32 m_guildId;
760 uint32 m_ItemTextId;
761 uint32 m_mailid;
762 uint32 m_hiPetNumber;
764 // first free low guid for seelcted guid type
765 uint32 m_hiCharGuid;
766 uint32 m_hiCreatureGuid;
767 uint32 m_hiPetGuid;
768 uint32 m_hiVehicleGuid;
769 uint32 m_hiItemGuid;
770 uint32 m_hiGoGuid;
771 uint32 m_hiDoGuid;
772 uint32 m_hiCorpseGuid;
774 QuestMap mQuestTemplates;
776 typedef UNORDERED_MAP<uint32, GossipText> GossipTextMap;
777 typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
778 typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
779 typedef std::set<uint32> TavernAreaTriggerSet;
780 typedef std::set<uint32> GameObjectForQuestSet;
782 GroupSet mGroupSet;
783 GuildMap mGuildMap;
784 ArenaTeamMap mArenaTeamMap;
786 ItemTextMap mItemTexts;
788 QuestAreaTriggerMap mQuestAreaTriggerMap;
789 TavernAreaTriggerSet mTavernAreaTriggerSet;
790 GameObjectForQuestSet mGameObjectForQuestSet;
791 GossipTextMap mGossipText;
792 AreaTriggerMap mAreaTriggers;
793 AreaTriggerScriptMap mAreaTriggerScripts;
795 RepOnKillMap mRepOnKill;
797 PointOfInterestMap mPointsOfInterest;
799 WeatherZoneMap mWeatherZoneMap;
801 //character reserved names
802 typedef std::set<std::wstring> ReservedNamesMap;
803 ReservedNamesMap m_ReservedNames;
805 GraveYardMap mGraveYardMap;
807 GameTeleMap m_GameTeleMap;
809 ScriptNameMap m_scriptNames;
811 typedef std::vector<LocaleConstant> LocalForIndex;
812 LocalForIndex m_LocalForIndex;
814 int DBCLocaleIndex;
816 private:
817 void LoadScripts(ScriptMapMap& scripts, char const* tablename);
818 void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids);
819 void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
820 void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
822 typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
823 // PetLevelInfoMap[creature_id][level]
824 PetLevelInfoMap petInfo; // [creature_id][level]
826 PlayerClassInfo playerClassInfo[MAX_CLASSES];
828 void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
829 PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
831 typedef std::vector<uint32> PlayerXPperLevel; // [level]
832 PlayerXPperLevel mPlayerXPperLevel;
834 typedef std::map<uint32,uint32> BaseXPMap; // [area level][base xp]
835 BaseXPMap mBaseXPTable;
837 typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
838 FishingBaseSkillMap mFishingBaseForArea;
840 typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
841 HalfNameMap PetHalfName0;
842 HalfNameMap PetHalfName1;
844 MapObjectGuids mMapObjectGuids;
845 CreatureDataMap mCreatureDataMap;
846 CreatureLocaleMap mCreatureLocaleMap;
847 GameObjectDataMap mGameObjectDataMap;
848 GameObjectLocaleMap mGameObjectLocaleMap;
849 ItemLocaleMap mItemLocaleMap;
850 QuestLocaleMap mQuestLocaleMap;
851 NpcTextLocaleMap mNpcTextLocaleMap;
852 PageTextLocaleMap mPageTextLocaleMap;
853 MangosStringLocaleMap mMangosStringLocaleMap;
854 NpcOptionLocaleMap mNpcOptionLocaleMap;
855 PointOfInterestLocaleMap mPointOfInterestLocaleMap;
856 RespawnTimes mCreatureRespawnTimes;
857 RespawnTimes mGORespawnTimes;
859 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
860 typedef std::vector<PlayerCondition> ConditionStore;
861 ConditionStore mConditions;
863 CacheNpcOptionList m_mCacheNpcOptionList;
864 CacheNpcTextIdMap m_mCacheNpcTextIdMap;
865 CacheVendorItemMap m_mCacheVendorItemMap;
866 CacheTrainerSpellMap m_mCacheTrainerSpellMap;
869 #define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
871 // scripting access functions
872 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());
873 MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
874 MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
875 MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
876 MANGOS_DLL_SPEC CreatureInfo const* GetCreatureTemplateStore(uint32 entry);
877 MANGOS_DLL_SPEC Quest const* GetQuestTemplateStore(uint32 entry);
879 #endif