[8449] Deprecate healing/damage item mods and merge internal data in to spell power.
[getmangos.git] / src / game / ObjectMgr.h
blobb36394cb1ba0c6879491415bcfad2c5d7891695b
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 questStart; // quest start (quest must be active or rewarded for spell apply)
102 uint32 questEnd; // quest end (quest don't must be rewarded for spell apply)
103 bool questStartCanActive; // if true then quest start can be active (not only rewarded)
104 uint8 castFlags;
106 // helpers
107 bool IsFitToRequirements(Player const* player) const;
110 typedef std::multimap<uint32, SpellClickInfo> SpellClickInfoMap;
111 typedef std::pair<SpellClickInfoMap::const_iterator,SpellClickInfoMap::const_iterator> SpellClickInfoMapBounds;
113 struct AreaTrigger
115 uint8 requiredLevel;
116 uint32 requiredItem;
117 uint32 requiredItem2;
118 uint32 heroicKey;
119 uint32 heroicKey2;
120 uint32 requiredQuest;
121 uint32 requiredQuestHeroic;
122 std::string requiredFailedText;
123 uint32 target_mapId;
124 float target_X;
125 float target_Y;
126 float target_Z;
127 float target_Orientation;
130 typedef std::set<uint32> CellGuidSet;
131 typedef std::map<uint32/*player guid*/,uint32/*instance*/> CellCorpseSet;
132 struct CellObjectGuids
134 CellGuidSet creatures;
135 CellGuidSet gameobjects;
136 CellCorpseSet corpses;
138 typedef UNORDERED_MAP<uint32/*cell_id*/,CellObjectGuids> CellObjectGuidsMap;
139 typedef UNORDERED_MAP<uint32/*(mapid,spawnMode) pair*/,CellObjectGuidsMap> MapObjectGuids;
141 typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
144 // mangos string ranges
145 #define MIN_MANGOS_STRING_ID 1 // 'mangos_string'
146 #define MAX_MANGOS_STRING_ID 2000000000
147 #define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID // 'db_script_string'
148 #define MAX_DB_SCRIPT_STRING_ID 2000010000
149 #define MIN_CREATURE_AI_TEXT_STRING_ID (-1) // 'creature_ai_texts'
150 #define MAX_CREATURE_AI_TEXT_STRING_ID (-1000000)
152 struct MangosStringLocale
154 std::vector<std::string> Content; // 0 -> default, i -> i-1 locale index
157 typedef UNORDERED_MAP<uint32,CreatureData> CreatureDataMap;
158 typedef UNORDERED_MAP<uint32,GameObjectData> GameObjectDataMap;
159 typedef UNORDERED_MAP<uint32,CreatureLocale> CreatureLocaleMap;
160 typedef UNORDERED_MAP<uint32,GameObjectLocale> GameObjectLocaleMap;
161 typedef UNORDERED_MAP<uint32,ItemLocale> ItemLocaleMap;
162 typedef UNORDERED_MAP<uint32,QuestLocale> QuestLocaleMap;
163 typedef UNORDERED_MAP<uint32,NpcTextLocale> NpcTextLocaleMap;
164 typedef UNORDERED_MAP<uint32,PageTextLocale> PageTextLocaleMap;
165 typedef UNORDERED_MAP<int32,MangosStringLocale> MangosStringLocaleMap;
166 typedef UNORDERED_MAP<uint32,NpcOptionLocale> NpcOptionLocaleMap;
167 typedef UNORDERED_MAP<uint32,PointOfInterestLocale> PointOfInterestLocaleMap;
169 typedef std::multimap<uint32,uint32> QuestRelations;
170 typedef std::multimap<uint32,ItemRequiredTarget> ItemRequiredTargetMap;
171 typedef std::pair<ItemRequiredTargetMap::const_iterator, ItemRequiredTargetMap::const_iterator> ItemRequiredTargetMapBounds;
173 struct PetLevelInfo
175 PetLevelInfo() : health(0), mana(0) { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
177 uint16 stats[MAX_STATS];
178 uint16 health;
179 uint16 mana;
180 uint16 armor;
183 struct ReputationOnKillEntry
185 uint32 repfaction1;
186 uint32 repfaction2;
187 bool is_teamaward1;
188 uint32 reputation_max_cap1;
189 int32 repvalue1;
190 bool is_teamaward2;
191 uint32 reputation_max_cap2;
192 int32 repvalue2;
193 bool team_dependent;
196 struct PointOfInterest
198 uint32 entry;
199 float x;
200 float y;
201 uint32 icon;
202 uint32 flags;
203 uint32 data;
204 std::string icon_name;
207 #define WEATHER_SEASONS 4
208 struct WeatherSeasonChances
210 uint32 rainChance;
211 uint32 snowChance;
212 uint32 stormChance;
215 struct WeatherZoneChances
217 WeatherSeasonChances data[WEATHER_SEASONS];
220 struct GraveYardData
222 uint32 safeLocId;
223 uint32 team;
225 typedef std::multimap<uint32,GraveYardData> GraveYardMap;
227 enum ConditionType
228 { // value1 value2 for the Condition enumed
229 CONDITION_NONE = 0, // 0 0
230 CONDITION_AURA = 1, // spell_id effindex
231 CONDITION_ITEM = 2, // item_id count
232 CONDITION_ITEM_EQUIPPED = 3, // item_id 0
233 CONDITION_ZONEID = 4, // zone_id 0
234 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank
235 CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde)
236 CONDITION_SKILL = 7, // skill_id skill_value
237 CONDITION_QUESTREWARDED = 8, // quest_id 0
238 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active.
239 CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD commission aura active
240 CONDITION_NO_AURA = 11, // spell_id effindex
241 CONDITION_ACTIVE_EVENT = 12, // event_id
244 #define MAX_CONDITION 13 // maximum value in ConditionType enum
246 struct PlayerCondition
248 ConditionType condition; // additional condition type
249 uint32 value1; // data for the condition - see ConditionType definition
250 uint32 value2;
252 PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
253 : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
255 static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
256 // Checks correctness of values
257 bool Meets(Player const * APlayer) const; // Checks if the player meets the condition
258 bool operator == (PlayerCondition const& lc) const
260 return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
264 // NPC gossip text id
265 typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
266 typedef std::list<GossipOption> CacheNpcOptionList;
268 typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
269 typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
271 enum SkillRangeType
273 SKILL_RANGE_LANGUAGE, // 300..300
274 SKILL_RANGE_LEVEL, // 1..max skill for level
275 SKILL_RANGE_MONO, // 1..1, grey monolite bar
276 SKILL_RANGE_RANK, // 1..skill for known rank
277 SKILL_RANGE_NONE, // 0..0 always
280 SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
282 #define MAX_PLAYER_NAME 12 // max allowed by client name length
283 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
284 #define MAX_PET_NAME 12 // max allowed by client name length
285 #define MAX_CHARTER_NAME 24 // max allowed by client name length
287 bool normalizePlayerName(std::string& name);
289 struct MANGOS_DLL_SPEC LanguageDesc
291 Language lang_id;
292 uint32 spell_id;
293 uint32 skill_id;
296 extern LanguageDesc lang_description[LANGUAGES_COUNT];
297 MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
299 class PlayerDumpReader;
301 class ObjectMgr
303 friend class PlayerDumpReader;
305 public:
306 ObjectMgr();
307 ~ObjectMgr();
309 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
311 typedef std::set< Group * > GroupSet;
313 typedef UNORDERED_MAP<uint32, Guild *> GuildMap;
315 typedef UNORDERED_MAP<uint32, ArenaTeam*> ArenaTeamMap;
317 typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
319 typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
321 typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
323 typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
324 typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap;
326 typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
328 typedef std::vector<std::string> ScriptNameMap;
330 Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);}
331 Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
333 static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
335 void LoadGameobjectInfo();
336 void AddGameobjectInfo(GameObjectInfo *goinfo);
338 Group * GetGroupByLeader(const uint64 &guid) const;
339 void AddGroup(Group* group) { mGroupSet.insert( group ); }
340 void RemoveGroup(Group* group) { mGroupSet.erase( group ); }
342 Guild* GetGuildByLeader(uint64 const&guid) const;
343 Guild* GetGuildById(uint32 GuildId) const;
344 Guild* GetGuildByName(const std::string& guildname) const;
345 std::string GetGuildNameById(uint32 GuildId) const;
346 void AddGuild(Guild* guild);
347 void RemoveGuild(uint32 Id);
349 ArenaTeam* GetArenaTeamById(uint32 arenateamid) const;
350 ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
351 ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
352 void AddArenaTeam(ArenaTeam* arenaTeam);
353 void RemoveArenaTeam(uint32 Id);
354 ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
355 ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
357 static CreatureInfo const *GetCreatureTemplate( uint32 id );
358 CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
359 CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
360 uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
361 EquipmentInfo const *GetEquipmentInfo( uint32 entry );
362 static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
364 return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
367 static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
369 return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
372 static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
374 static InstanceTemplate const* GetInstanceTemplate(uint32 map)
376 return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
379 PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
381 PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
383 if(class_ >= MAX_CLASSES) return NULL;
384 return &playerClassInfo[class_];
386 void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
388 PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
390 if(race >= MAX_RACES) return NULL;
391 if(class_ >= MAX_CLASSES) return NULL;
392 PlayerInfo const* info = &playerInfo[race][class_];
393 if(info->displayId_m==0 || info->displayId_f==0) return NULL;
394 return info;
396 void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
398 uint64 GetPlayerGUIDByName(std::string name) const;
399 bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
400 uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
401 uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
402 uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const;
404 uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team );
405 void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
406 uint32 GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_alt_team = false);
407 void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
408 void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
410 Quest const* GetQuestTemplate(uint32 quest_id) const
412 QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
413 return itr != mQuestTemplates.end() ? itr->second : NULL;
415 QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
417 uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
419 QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
420 if(itr != mQuestAreaTriggerMap.end())
421 return itr->second;
422 return 0;
424 bool IsTavernAreaTrigger(uint32 Trigger_ID) const
426 return mTavernAreaTriggerSet.find(Trigger_ID) != mTavernAreaTriggerSet.end();
429 bool IsGameObjectForQuests(uint32 entry) const
431 return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end();
434 GossipText const* GetGossipText(uint32 Text_ID) const;
436 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
437 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
438 void LoadGraveyardZones();
439 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
441 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
443 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
444 if( itr != mAreaTriggers.end( ) )
445 return &itr->second;
446 return NULL;
449 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
450 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
452 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
454 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
456 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
457 if(itr != mRepOnKill.end())
458 return &itr->second;
459 return NULL;
462 PointOfInterest const* GetPointOfInterest(uint32 id) const
464 PointOfInterestMap::const_iterator itr = mPointsOfInterest.find(id);
465 if(itr != mPointsOfInterest.end())
466 return &itr->second;
467 return NULL;
470 void LoadGuilds();
471 void LoadArenaTeams();
472 void LoadGroups();
473 void LoadQuests();
474 void LoadQuestRelations()
476 LoadGameobjectQuestRelations();
477 LoadGameobjectInvolvedRelations();
478 LoadCreatureQuestRelations();
479 LoadCreatureInvolvedRelations();
481 void LoadGameobjectQuestRelations();
482 void LoadGameobjectInvolvedRelations();
483 void LoadCreatureQuestRelations();
484 void LoadCreatureInvolvedRelations();
486 QuestRelations mGOQuestRelations;
487 QuestRelations mGOQuestInvolvedRelations;
488 QuestRelations mCreatureQuestRelations;
489 QuestRelations mCreatureQuestInvolvedRelations;
491 void LoadGameObjectScripts();
492 void LoadQuestEndScripts();
493 void LoadQuestStartScripts();
494 void LoadEventScripts();
495 void LoadSpellScripts();
497 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
498 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
499 void LoadDbScriptStrings();
500 void LoadCreatureLocales();
501 void LoadCreatureTemplates();
502 void LoadCreatures();
503 void LoadCreatureRespawnTimes();
504 void LoadCreatureAddons();
505 void LoadCreatureModelInfo();
506 void LoadEquipmentTemplates();
507 void LoadGameObjectLocales();
508 void LoadGameobjects();
509 void LoadGameobjectRespawnTimes();
510 void LoadItemPrototypes();
511 void LoadItemRequiredTarget();
512 void LoadItemLocales();
513 void LoadQuestLocales();
514 void LoadNpcTextLocales();
515 void LoadPageTextLocales();
516 void LoadNpcOptionLocales();
517 void LoadPointOfInterestLocales();
518 void LoadInstanceTemplate();
520 void LoadGossipText();
522 void LoadAreaTriggerTeleports();
523 void LoadQuestAreaTriggers();
524 void LoadAreaTriggerScripts();
525 void LoadTavernAreaTriggers();
526 void LoadGameObjectForQuests();
528 void LoadItemTexts();
529 void LoadPageTexts();
531 void LoadPlayerInfo();
532 void LoadPetLevelInfo();
533 void LoadExplorationBaseXP();
534 void LoadPetNames();
535 void LoadPetNumber();
536 void LoadCorpses();
537 void LoadFishingBaseSkillLevel();
539 void LoadReputationOnKill();
540 void LoadPointsOfInterest();
542 void LoadNPCSpellClickSpells();
544 void LoadWeatherZoneChances();
545 void LoadGameTele();
547 void LoadNpcOptions();
548 void LoadNpcTextId();
549 void LoadVendors();
550 void LoadTrainerSpell();
552 std::string GeneratePetName(uint32 entry);
553 uint32 GetBaseXP(uint32 level);
554 uint32 GetXPForLevel(uint32 level);
556 int32 GetFishingBaseSkillLevel(uint32 entry) const
558 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
559 return itr != mFishingBaseForArea.end() ? itr->second : 0;
562 void ReturnOrDeleteOldMails(bool serverUp);
564 void SetHighestGuids();
565 uint32 GenerateLowGuid(HighGuid guidhigh);
566 uint32 GenerateArenaTeamId();
567 uint32 GenerateAuctionID();
568 uint64 GenerateEquipmentSetGuid();
569 uint32 GenerateGuildId();
570 uint32 GenerateItemTextID();
571 uint32 GenerateMailID();
572 uint32 GeneratePetNumber();
574 uint32 CreateItemText(std::string text);
575 void AddItemText(uint32 itemTextId, std::string text) { mItemTexts[itemTextId] = text; }
576 std::string GetItemText( uint32 id )
578 ItemTextMap::const_iterator itr = mItemTexts.find( id );
579 if ( itr != mItemTexts.end() )
580 return itr->second;
581 else
582 return "There is no info for this item";
585 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
586 ExclusiveQuestGroups mExclusiveQuestGroups;
588 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
590 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
591 if(itr != mWeatherZoneMap.end())
592 return &itr->second;
593 else
594 return NULL;
597 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
599 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
602 CreatureData const* GetCreatureData(uint32 guid) const
604 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
605 if(itr==mCreatureDataMap.end()) return NULL;
606 return &itr->second;
608 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
609 void DeleteCreatureData(uint32 guid);
610 CreatureLocale const* GetCreatureLocale(uint32 entry) const
612 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
613 if(itr==mCreatureLocaleMap.end()) return NULL;
614 return &itr->second;
616 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
618 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
619 if(itr==mGameObjectLocaleMap.end()) return NULL;
620 return &itr->second;
622 ItemLocale const* GetItemLocale(uint32 entry) const
624 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
625 if(itr==mItemLocaleMap.end()) return NULL;
626 return &itr->second;
628 QuestLocale const* GetQuestLocale(uint32 entry) const
630 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
631 if(itr==mQuestLocaleMap.end()) return NULL;
632 return &itr->second;
634 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
636 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
637 if(itr==mNpcTextLocaleMap.end()) return NULL;
638 return &itr->second;
640 PageTextLocale const* GetPageTextLocale(uint32 entry) const
642 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
643 if(itr==mPageTextLocaleMap.end()) return NULL;
644 return &itr->second;
646 NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const
648 NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry);
649 if(itr==mNpcOptionLocaleMap.end()) return NULL;
650 return &itr->second;
652 PointOfInterestLocale const* GetPointOfInterestLocale(uint32 poi_id) const
654 PointOfInterestLocaleMap::const_iterator itr = mPointOfInterestLocaleMap.find(poi_id);
655 if(itr==mPointOfInterestLocaleMap.end()) return NULL;
656 return &itr->second;
659 GameObjectData const* GetGOData(uint32 guid) const
661 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
662 if(itr==mGameObjectDataMap.end()) return NULL;
663 return &itr->second;
665 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
666 void DeleteGOData(uint32 guid);
668 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
670 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
671 if(itr==mMangosStringLocaleMap.end()) return NULL;
672 return &itr->second;
674 const char *GetMangosString(int32 entry, int locale_idx) const;
675 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
676 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
677 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
679 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
680 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
682 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
683 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
684 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
685 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
686 void DeleteRespawnTimeForInstance(uint32 instance);
688 // grid objects
689 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
690 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
691 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
692 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
694 // reserved names
695 void LoadReservedPlayersNames();
696 bool IsReservedName(const std::string& name) const;
698 // name with valid structure and symbols
699 static uint8 CheckPlayerName( const std::string& name, bool create = false );
700 static PetNameInvalidReason CheckPetName( const std::string& name );
701 static bool IsValidCharterName( const std::string& name );
703 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
705 int GetIndexForLocale(LocaleConstant loc);
706 LocaleConstant GetLocaleForIndex(int i);
708 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
709 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
711 if(condition_id >= mConditions.size())
712 return false;
714 return mConditions[condition_id].Meets(player);
717 GameTele const* GetGameTele(uint32 id) const
719 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
720 if(itr==m_GameTeleMap.end()) return NULL;
721 return &itr->second;
723 GameTele const* GetGameTele(const std::string& name) const;
724 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
725 bool AddGameTele(GameTele& data);
726 bool DeleteGameTele(const std::string& name);
728 CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; }
730 uint32 GetNpcGossip(uint32 entry) const
732 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
733 if(iter == m_mCacheNpcTextIdMap.end())
734 return 0;
736 return iter->second;
739 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
741 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
742 if(iter == m_mCacheTrainerSpellMap.end())
743 return NULL;
745 return &iter->second;
748 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
750 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
751 if(iter == m_mCacheVendorItemMap.end())
752 return NULL;
754 return &iter->second;
756 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
757 bool RemoveVendorItem(uint32 entry,uint32 item);
758 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
760 void LoadScriptNames();
761 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
762 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
763 uint32 GetScriptId(const char *name);
765 int GetOrNewIndexForLocale(LocaleConstant loc);
767 SpellClickInfoMapBounds GetSpellClickInfoMapBounds(uint32 creature_id) const
769 return SpellClickInfoMapBounds(mSpellClickInfoMap.lower_bound(creature_id),mSpellClickInfoMap.upper_bound(creature_id));
772 ItemRequiredTargetMapBounds GetItemRequiredTargetMapBounds(uint32 uiItemEntry) const
774 return ItemRequiredTargetMapBounds(m_ItemRequiredTarget.lower_bound(uiItemEntry),m_ItemRequiredTarget.upper_bound(uiItemEntry));
777 protected:
779 // first free id for selected id type
780 uint32 m_arenaTeamId;
781 uint32 m_auctionid;
782 uint64 m_equipmentSetGuid;
783 uint32 m_guildId;
784 uint32 m_ItemTextId;
785 uint32 m_mailid;
786 uint32 m_hiPetNumber;
788 // first free low guid for seelcted guid type
789 uint32 m_hiCharGuid;
790 uint32 m_hiCreatureGuid;
791 uint32 m_hiPetGuid;
792 uint32 m_hiVehicleGuid;
793 uint32 m_hiItemGuid;
794 uint32 m_hiGoGuid;
795 uint32 m_hiDoGuid;
796 uint32 m_hiCorpseGuid;
798 QuestMap mQuestTemplates;
800 typedef UNORDERED_MAP<uint32, GossipText> GossipTextMap;
801 typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
802 typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
803 typedef std::set<uint32> TavernAreaTriggerSet;
804 typedef std::set<uint32> GameObjectForQuestSet;
806 GroupSet mGroupSet;
807 GuildMap mGuildMap;
808 ArenaTeamMap mArenaTeamMap;
810 ItemTextMap mItemTexts;
812 QuestAreaTriggerMap mQuestAreaTriggerMap;
813 TavernAreaTriggerSet mTavernAreaTriggerSet;
814 GameObjectForQuestSet mGameObjectForQuestSet;
815 GossipTextMap mGossipText;
816 AreaTriggerMap mAreaTriggers;
817 AreaTriggerScriptMap mAreaTriggerScripts;
819 RepOnKillMap mRepOnKill;
821 PointOfInterestMap mPointsOfInterest;
823 WeatherZoneMap mWeatherZoneMap;
825 //character reserved names
826 typedef std::set<std::wstring> ReservedNamesMap;
827 ReservedNamesMap m_ReservedNames;
829 GraveYardMap mGraveYardMap;
831 GameTeleMap m_GameTeleMap;
833 ScriptNameMap m_scriptNames;
835 SpellClickInfoMap mSpellClickInfoMap;
837 ItemRequiredTargetMap m_ItemRequiredTarget;
839 typedef std::vector<LocaleConstant> LocalForIndex;
840 LocalForIndex m_LocalForIndex;
842 int DBCLocaleIndex;
844 private:
845 void LoadScripts(ScriptMapMap& scripts, char const* tablename);
846 void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids);
847 void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment);
848 void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
849 void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
851 typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
852 // PetLevelInfoMap[creature_id][level]
853 PetLevelInfoMap petInfo; // [creature_id][level]
855 PlayerClassInfo playerClassInfo[MAX_CLASSES];
857 void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
858 PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
860 typedef std::vector<uint32> PlayerXPperLevel; // [level]
861 PlayerXPperLevel mPlayerXPperLevel;
863 typedef std::map<uint32,uint32> BaseXPMap; // [area level][base xp]
864 BaseXPMap mBaseXPTable;
866 typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
867 FishingBaseSkillMap mFishingBaseForArea;
869 typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
870 HalfNameMap PetHalfName0;
871 HalfNameMap PetHalfName1;
873 MapObjectGuids mMapObjectGuids;
874 CreatureDataMap mCreatureDataMap;
875 CreatureLocaleMap mCreatureLocaleMap;
876 GameObjectDataMap mGameObjectDataMap;
877 GameObjectLocaleMap mGameObjectLocaleMap;
878 ItemLocaleMap mItemLocaleMap;
879 QuestLocaleMap mQuestLocaleMap;
880 NpcTextLocaleMap mNpcTextLocaleMap;
881 PageTextLocaleMap mPageTextLocaleMap;
882 MangosStringLocaleMap mMangosStringLocaleMap;
883 NpcOptionLocaleMap mNpcOptionLocaleMap;
884 PointOfInterestLocaleMap mPointOfInterestLocaleMap;
885 RespawnTimes mCreatureRespawnTimes;
886 RespawnTimes mGORespawnTimes;
888 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
889 typedef std::vector<PlayerCondition> ConditionStore;
890 ConditionStore mConditions;
892 CacheNpcOptionList m_mCacheNpcOptionList;
893 CacheNpcTextIdMap m_mCacheNpcTextIdMap;
894 CacheVendorItemMap m_mCacheVendorItemMap;
895 CacheTrainerSpellMap m_mCacheTrainerSpellMap;
898 #define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
900 // scripting access functions
901 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());
902 MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
903 MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
904 MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
905 MANGOS_DLL_SPEC CreatureInfo const* GetCreatureTemplateStore(uint32 entry);
906 MANGOS_DLL_SPEC Quest const* GetQuestTemplateStore(uint32 entry);
908 #endif