[7847] Replace paramter unions by uniton of event ai action type structures. Add...
[getmangos.git] / src / game / ObjectMgr.h
blob0a056afefd4f3f71b46c7393d896f3e6b6658092
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 struct PetCreateSpellEntry
201 uint32 spellid[4];
204 #define WEATHER_SEASONS 4
205 struct WeatherSeasonChances
207 uint32 rainChance;
208 uint32 snowChance;
209 uint32 stormChance;
212 struct WeatherZoneChances
214 WeatherSeasonChances data[WEATHER_SEASONS];
217 struct GraveYardData
219 uint32 safeLocId;
220 uint32 team;
222 typedef std::multimap<uint32,GraveYardData> GraveYardMap;
224 enum ConditionType
225 { // value1 value2 for the Condition enumed
226 CONDITION_NONE = 0, // 0 0
227 CONDITION_AURA = 1, // spell_id effindex
228 CONDITION_ITEM = 2, // item_id count
229 CONDITION_ITEM_EQUIPPED = 3, // item_id 0
230 CONDITION_ZONEID = 4, // zone_id 0
231 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank
232 CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde)
233 CONDITION_SKILL = 7, // skill_id skill_value
234 CONDITION_QUESTREWARDED = 8, // quest_id 0
235 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active.
236 CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD ñommission aura active
237 CONDITION_NO_AURA = 11, // spell_id effindex
238 CONDITION_ACTIVE_EVENT = 12, // event_id
241 #define MAX_CONDITION 13 // maximum value in ConditionType enum
243 struct PlayerCondition
245 ConditionType condition; // additional condition type
246 uint32 value1; // data for the condition - see ConditionType definition
247 uint32 value2;
249 PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
250 : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
252 static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
253 // Checks correctness of values
254 bool Meets(Player const * APlayer) const; // Checks if the player meets the condition
255 bool operator == (PlayerCondition const& lc) const
257 return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
261 // NPC gossip text id
262 typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
263 typedef std::list<GossipOption> CacheNpcOptionList;
265 typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
266 typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
268 enum SkillRangeType
270 SKILL_RANGE_LANGUAGE, // 300..300
271 SKILL_RANGE_LEVEL, // 1..max skill for level
272 SKILL_RANGE_MONO, // 1..1, grey monolite bar
273 SKILL_RANGE_RANK, // 1..skill for known rank
274 SKILL_RANGE_NONE, // 0..0 always
277 SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
279 #define MAX_PLAYER_NAME 12 // max allowed by client name length
280 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
282 bool normalizePlayerName(std::string& name);
284 struct MANGOS_DLL_SPEC LanguageDesc
286 Language lang_id;
287 uint32 spell_id;
288 uint32 skill_id;
291 extern LanguageDesc lang_description[LANGUAGES_COUNT];
292 MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
294 class PlayerDumpReader;
296 class ObjectMgr
298 friend class PlayerDumpReader;
300 public:
301 ObjectMgr();
302 ~ObjectMgr();
304 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
306 typedef std::set< Group * > GroupSet;
308 typedef UNORDERED_MAP<uint32, Guild *> GuildMap;
310 typedef UNORDERED_MAP<uint32, ArenaTeam*> ArenaTeamMap;
312 typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
314 typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
316 typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
318 typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
319 typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap;
321 typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
323 typedef UNORDERED_MAP<uint32, PetCreateSpellEntry> PetCreateSpellMap;
325 typedef std::vector<std::string> ScriptNameMap;
327 Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);}
328 Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
330 static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
332 void LoadGameobjectInfo();
333 void AddGameobjectInfo(GameObjectInfo *goinfo);
335 Group * GetGroupByLeader(const uint64 &guid) const;
336 void AddGroup(Group* group) { mGroupSet.insert( group ); }
337 void RemoveGroup(Group* group) { mGroupSet.erase( group ); }
339 Guild* GetGuildByLeader(uint64 const&guid) const;
340 Guild* GetGuildById(uint32 GuildId) const;
341 Guild* GetGuildByName(const std::string& guildname) const;
342 std::string GetGuildNameById(uint32 GuildId) const;
343 void AddGuild(Guild* guild);
344 void RemoveGuild(uint32 Id);
346 ArenaTeam* GetArenaTeamById(uint32 arenateamid) const;
347 ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
348 ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
349 void AddArenaTeam(ArenaTeam* arenaTeam);
350 void RemoveArenaTeam(uint32 Id);
351 ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
352 ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
354 static CreatureInfo const *GetCreatureTemplate( uint32 id );
355 CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
356 CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
357 uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
358 EquipmentInfo const *GetEquipmentInfo( uint32 entry );
359 static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
361 return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
364 static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
366 return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
369 static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
371 static InstanceTemplate const* GetInstanceTemplate(uint32 map)
373 return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
376 PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
378 PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
380 if(class_ >= MAX_CLASSES) return NULL;
381 return &playerClassInfo[class_];
383 void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
385 PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
387 if(race >= MAX_RACES) return NULL;
388 if(class_ >= MAX_CLASSES) return NULL;
389 PlayerInfo const* info = &playerInfo[race][class_];
390 if(info->displayId_m==0 || info->displayId_f==0) return NULL;
391 return info;
393 void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
395 uint64 GetPlayerGUIDByName(std::string name) const;
396 bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
397 uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
398 uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
399 uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const;
401 uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team );
402 void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
403 uint16 GetTaxiMount( uint32 id, uint32 team, bool allowed_alt_team = false);
404 void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
405 void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
407 Quest const* GetQuestTemplate(uint32 quest_id) const
409 QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
410 return itr != mQuestTemplates.end() ? itr->second : NULL;
412 QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
414 uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
416 QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
417 if(itr != mQuestAreaTriggerMap.end())
418 return itr->second;
419 return 0;
421 bool IsTavernAreaTrigger(uint32 Trigger_ID) const
423 return mTavernAreaTriggerSet.find(Trigger_ID) != mTavernAreaTriggerSet.end();
426 bool IsGameObjectForQuests(uint32 entry) const
428 return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end();
431 GossipText const* GetGossipText(uint32 Text_ID) const;
433 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
434 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
435 void LoadGraveyardZones();
436 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
438 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
440 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
441 if( itr != mAreaTriggers.end( ) )
442 return &itr->second;
443 return NULL;
446 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
447 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
449 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
451 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
453 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
454 if(itr != mRepOnKill.end())
455 return &itr->second;
456 return NULL;
459 PointOfInterest const* GetPointOfInterest(uint32 id) const
461 PointOfInterestMap::const_iterator itr = mPointsOfInterest.find(id);
462 if(itr != mPointsOfInterest.end())
463 return &itr->second;
464 return NULL;
467 PetCreateSpellEntry const* GetPetCreateSpellEntry(uint32 id) const
469 PetCreateSpellMap::const_iterator itr = mPetCreateSpell.find(id);
470 if(itr != mPetCreateSpell.end())
471 return &itr->second;
472 return NULL;
475 void LoadGuilds();
476 void LoadArenaTeams();
477 void LoadGroups();
478 void LoadQuests();
479 void LoadQuestRelations()
481 LoadGameobjectQuestRelations();
482 LoadGameobjectInvolvedRelations();
483 LoadCreatureQuestRelations();
484 LoadCreatureInvolvedRelations();
486 void LoadGameobjectQuestRelations();
487 void LoadGameobjectInvolvedRelations();
488 void LoadCreatureQuestRelations();
489 void LoadCreatureInvolvedRelations();
491 QuestRelations mGOQuestRelations;
492 QuestRelations mGOQuestInvolvedRelations;
493 QuestRelations mCreatureQuestRelations;
494 QuestRelations mCreatureQuestInvolvedRelations;
496 void LoadGameObjectScripts();
497 void LoadQuestEndScripts();
498 void LoadQuestStartScripts();
499 void LoadEventScripts();
500 void LoadSpellScripts();
502 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
503 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
504 void LoadDbScriptStrings();
505 void LoadPetCreateSpells();
506 void LoadCreatureLocales();
507 void LoadCreatureTemplates();
508 void LoadCreatures();
509 void LoadCreatureRespawnTimes();
510 void LoadCreatureAddons();
511 void LoadCreatureModelInfo();
512 void LoadEquipmentTemplates();
513 void LoadGameObjectLocales();
514 void LoadGameobjects();
515 void LoadGameobjectRespawnTimes();
516 void LoadItemPrototypes();
517 void LoadItemLocales();
518 void LoadQuestLocales();
519 void LoadNpcTextLocales();
520 void LoadPageTextLocales();
521 void LoadNpcOptionLocales();
522 void LoadPointOfInterestLocales();
523 void LoadInstanceTemplate();
525 void LoadGossipText();
527 void LoadAreaTriggerTeleports();
528 void LoadQuestAreaTriggers();
529 void LoadAreaTriggerScripts();
530 void LoadTavernAreaTriggers();
531 void LoadGameObjectForQuests();
533 void LoadItemTexts();
534 void LoadPageTexts();
536 void LoadPlayerInfo();
537 void LoadPetLevelInfo();
538 void LoadExplorationBaseXP();
539 void LoadPetNames();
540 void LoadPetNumber();
541 void LoadCorpses();
542 void LoadFishingBaseSkillLevel();
544 void LoadReputationOnKill();
545 void LoadPointsOfInterest();
547 SpellClickInfoMap mSpellClickInfoMap;
548 void LoadNPCSpellClickSpells();
550 void LoadWeatherZoneChances();
551 void LoadGameTele();
553 void LoadNpcOptions();
554 void LoadNpcTextId();
555 void LoadVendors();
556 void LoadTrainerSpell();
558 std::string GeneratePetName(uint32 entry);
559 uint32 GetBaseXP(uint32 level);
560 uint32 GetXPForLevel(uint32 level);
562 int32 GetFishingBaseSkillLevel(uint32 entry) const
564 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
565 return itr != mFishingBaseForArea.end() ? itr->second : 0;
568 void ReturnOrDeleteOldMails(bool serverUp);
570 void SetHighestGuids();
571 uint32 GenerateLowGuid(HighGuid guidhigh);
572 uint32 GenerateArenaTeamId();
573 uint32 GenerateAuctionID();
574 uint32 GenerateGuildId();
575 uint32 GenerateItemTextID();
576 uint32 GenerateMailID();
577 uint32 GeneratePetNumber();
579 uint32 CreateItemText(std::string text);
580 std::string GetItemText( uint32 id )
582 ItemTextMap::const_iterator itr = mItemTexts.find( id );
583 if ( itr != mItemTexts.end() )
584 return itr->second;
585 else
586 return "There is no info for this item";
589 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
590 ExclusiveQuestGroups mExclusiveQuestGroups;
592 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
594 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
595 if(itr != mWeatherZoneMap.end())
596 return &itr->second;
597 else
598 return NULL;
601 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
603 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
606 CreatureData const* GetCreatureData(uint32 guid) const
608 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
609 if(itr==mCreatureDataMap.end()) return NULL;
610 return &itr->second;
612 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
613 void DeleteCreatureData(uint32 guid);
614 CreatureLocale const* GetCreatureLocale(uint32 entry) const
616 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
617 if(itr==mCreatureLocaleMap.end()) return NULL;
618 return &itr->second;
620 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
622 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
623 if(itr==mGameObjectLocaleMap.end()) return NULL;
624 return &itr->second;
626 ItemLocale const* GetItemLocale(uint32 entry) const
628 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
629 if(itr==mItemLocaleMap.end()) return NULL;
630 return &itr->second;
632 QuestLocale const* GetQuestLocale(uint32 entry) const
634 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
635 if(itr==mQuestLocaleMap.end()) return NULL;
636 return &itr->second;
638 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
640 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
641 if(itr==mNpcTextLocaleMap.end()) return NULL;
642 return &itr->second;
644 PageTextLocale const* GetPageTextLocale(uint32 entry) const
646 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
647 if(itr==mPageTextLocaleMap.end()) return NULL;
648 return &itr->second;
650 NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const
652 NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry);
653 if(itr==mNpcOptionLocaleMap.end()) return NULL;
654 return &itr->second;
656 PointOfInterestLocale const* GetPointOfInterestLocale(uint32 poi_id) const
658 PointOfInterestLocaleMap::const_iterator itr = mPointOfInterestLocaleMap.find(poi_id);
659 if(itr==mPointOfInterestLocaleMap.end()) return NULL;
660 return &itr->second;
663 GameObjectData const* GetGOData(uint32 guid) const
665 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
666 if(itr==mGameObjectDataMap.end()) return NULL;
667 return &itr->second;
669 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
670 void DeleteGOData(uint32 guid);
672 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
674 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
675 if(itr==mMangosStringLocaleMap.end()) return NULL;
676 return &itr->second;
678 const char *GetMangosString(int32 entry, int locale_idx) const;
679 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
680 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
681 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
683 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
684 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
686 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
687 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
688 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
689 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
690 void DeleteRespawnTimeForInstance(uint32 instance);
692 // grid objects
693 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
694 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
695 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
696 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
698 // reserved names
699 void LoadReservedPlayersNames();
700 bool IsReservedName(const std::string& name) const;
702 // name with valid structure and symbols
703 static bool IsValidName( const std::string& name, bool create = false );
704 static bool IsValidCharterName( const std::string& name );
705 static bool IsValidPetName( const std::string& name );
707 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
709 int GetIndexForLocale(LocaleConstant loc);
710 LocaleConstant GetLocaleForIndex(int i);
712 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
713 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
715 if(condition_id >= mConditions.size())
716 return false;
718 return mConditions[condition_id].Meets(player);
721 GameTele const* GetGameTele(uint32 id) const
723 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
724 if(itr==m_GameTeleMap.end()) return NULL;
725 return &itr->second;
727 GameTele const* GetGameTele(const std::string& name) const;
728 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
729 bool AddGameTele(GameTele& data);
730 bool DeleteGameTele(const std::string& name);
732 CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; }
734 uint32 GetNpcGossip(uint32 entry) const
736 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
737 if(iter == m_mCacheNpcTextIdMap.end())
738 return 0;
740 return iter->second;
743 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
745 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
746 if(iter == m_mCacheTrainerSpellMap.end())
747 return NULL;
749 return &iter->second;
752 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
754 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
755 if(iter == m_mCacheVendorItemMap.end())
756 return NULL;
758 return &iter->second;
760 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
761 bool RemoveVendorItem(uint32 entry,uint32 item);
762 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
764 void LoadScriptNames();
765 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
766 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
767 uint32 GetScriptId(const char *name);
769 int GetOrNewIndexForLocale(LocaleConstant loc);
770 protected:
772 // first free id for selected id type
773 uint32 m_arenaTeamId;
774 uint32 m_auctionid;
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 = MAX_CREATURE_AI_TEXT_STRING_ID, 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