[9957] Alow sell item for money and extanded coset without momey in same time.
[getmangos.git] / src / game / ObjectMgr.h
blob2793b770975eb1c85f631a48dec8f77ec65813f7
1 /*
2 * Copyright (C) 2005-2010 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 "GameObject.h"
28 #include "Corpse.h"
29 #include "QuestDef.h"
30 #include "ItemPrototype.h"
31 #include "NPCHandler.h"
32 #include "Database/DatabaseEnv.h"
33 #include "Map.h"
34 #include "ObjectAccessor.h"
35 #include "ObjectGuid.h"
36 #include "Policies/Singleton.h"
37 #include "Database/SQLStorage.h"
39 #include <string>
40 #include <map>
41 #include <limits>
43 extern SQLStorage sCreatureStorage;
44 extern SQLStorage sCreatureDataAddonStorage;
45 extern SQLStorage sCreatureInfoAddonStorage;
46 extern SQLStorage sCreatureModelStorage;
47 extern SQLStorage sEquipmentStorage;
48 extern SQLStorage sGOStorage;
49 extern SQLStorage sPageTextStore;
50 extern SQLStorage sItemStorage;
51 extern SQLStorage sInstanceTemplate;
53 class Group;
54 class Guild;
55 class ArenaTeam;
56 class Item;
58 struct GameTele
60 float position_x;
61 float position_y;
62 float position_z;
63 float orientation;
64 uint32 mapId;
65 std::string name;
66 std::wstring wnameLow;
69 typedef UNORDERED_MAP<uint32, GameTele > GameTeleMap;
71 struct ScriptInfo
73 uint32 id;
74 uint32 delay;
75 uint32 command;
76 uint32 datalong;
77 uint32 datalong2;
78 uint32 datalong3;
79 uint32 datalong4;
80 uint32 data_flags;
81 int32 dataint;
82 float x;
83 float y;
84 float z;
85 float o;
88 typedef std::multimap<uint32, ScriptInfo> ScriptMap;
89 typedef std::map<uint32, ScriptMap > ScriptMapMap;
90 extern ScriptMapMap sQuestEndScripts;
91 extern ScriptMapMap sQuestStartScripts;
92 extern ScriptMapMap sSpellScripts;
93 extern ScriptMapMap sGameObjectScripts;
94 extern ScriptMapMap sEventScripts;
95 extern ScriptMapMap sGossipScripts;
96 extern ScriptMapMap sCreatureMovementScripts;
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,GossipMenuItemsLocale> GossipMenuItemsLocaleMap;
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 MailLevelReward
185 MailLevelReward() : raceMask(0), mailTemplateId(0), senderEntry(0) {}
186 MailLevelReward(uint32 _raceMask, uint32 _mailTemplateId, uint32 _senderEntry) : raceMask(_raceMask), mailTemplateId(_mailTemplateId), senderEntry(_senderEntry) {}
188 uint32 raceMask;
189 uint32 mailTemplateId;
190 uint32 senderEntry;
193 typedef std::list<MailLevelReward> MailLevelRewardList;
194 typedef UNORDERED_MAP<uint8,MailLevelRewardList> MailLevelRewardMap;
196 struct ReputationOnKillEntry
198 uint32 repfaction1;
199 uint32 repfaction2;
200 bool is_teamaward1;
201 uint32 reputation_max_cap1;
202 int32 repvalue1;
203 bool is_teamaward2;
204 uint32 reputation_max_cap2;
205 int32 repvalue2;
206 bool team_dependent;
209 struct PointOfInterest
211 uint32 entry;
212 float x;
213 float y;
214 uint32 icon;
215 uint32 flags;
216 uint32 data;
217 std::string icon_name;
220 struct GossipMenuItems
222 uint32 menu_id;
223 uint32 id;
224 uint8 option_icon;
225 std::string option_text;
226 uint32 option_id;
227 uint32 npc_option_npcflag;
228 uint32 action_menu_id;
229 uint32 action_poi_id;
230 uint32 action_script_id;
231 bool box_coded;
232 uint32 box_money;
233 std::string box_text;
234 uint16 cond_1;
235 uint16 cond_2;
236 uint16 cond_3;
239 struct GossipMenus
241 uint32 entry;
242 uint32 text_id;
243 uint16 cond_1;
244 uint16 cond_2;
247 typedef std::multimap<uint32,GossipMenus> GossipMenusMap;
248 typedef std::pair<GossipMenusMap::const_iterator, GossipMenusMap::const_iterator> GossipMenusMapBounds;
249 typedef std::multimap<uint32,GossipMenuItems> GossipMenuItemsMap;
250 typedef std::pair<GossipMenuItemsMap::const_iterator, GossipMenuItemsMap::const_iterator> GossipMenuItemsMapBounds;
252 struct QuestPOIPoint
254 int32 x;
255 int32 y;
257 QuestPOIPoint() : x(0), y(0) {}
258 QuestPOIPoint(int32 _x, int32 _y) : x(_x), y(_y) {}
261 struct QuestPOI
263 uint32 PoiId;
264 int32 ObjectiveIndex;
265 uint32 MapId;
266 uint32 MapAreaId;
267 uint32 FloorId;
268 uint32 Unk3;
269 uint32 Unk4;
270 std::vector<QuestPOIPoint> points;
272 QuestPOI() : PoiId(0), ObjectiveIndex(0), MapId(0), MapAreaId(0), FloorId(0), Unk3(0), Unk4(0) {}
273 QuestPOI(uint32 poiId, int32 objIndex, uint32 mapId, uint32 mapAreaId, uint32 floorId, uint32 unk3, uint32 unk4) : PoiId(poiId), ObjectiveIndex(objIndex), MapId(mapId), MapAreaId(mapAreaId), FloorId(floorId), Unk3(unk3), Unk4(unk4) {}
276 typedef std::vector<QuestPOI> QuestPOIVector;
277 typedef UNORDERED_MAP<uint32, QuestPOIVector> QuestPOIMap;
279 #define WEATHER_SEASONS 4
280 struct WeatherSeasonChances
282 uint32 rainChance;
283 uint32 snowChance;
284 uint32 stormChance;
287 struct WeatherZoneChances
289 WeatherSeasonChances data[WEATHER_SEASONS];
292 struct GraveYardData
294 uint32 safeLocId;
295 uint32 team;
297 typedef std::multimap<uint32,GraveYardData> GraveYardMap;
299 enum ConditionType
300 { // value1 value2 for the Condition enumed
301 CONDITION_NONE = 0, // 0 0
302 CONDITION_AURA = 1, // spell_id effindex
303 CONDITION_ITEM = 2, // item_id count
304 CONDITION_ITEM_EQUIPPED = 3, // item_id 0
305 CONDITION_ZONEID = 4, // zone_id 0
306 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank
307 CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde)
308 CONDITION_SKILL = 7, // skill_id skill_value
309 CONDITION_QUESTREWARDED = 8, // quest_id 0
310 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active.
311 CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD commission aura active
312 CONDITION_NO_AURA = 11, // spell_id effindex
313 CONDITION_ACTIVE_EVENT = 12, // event_id 0
314 CONDITION_AREA_FLAG = 13, // area_flag area_flag_not
315 CONDITION_RACE_CLASS = 14, // race_mask class_mask
316 CONDITION_LEVEL = 15, // player_level 0, 1 or 2 (0: equal to, 1: equal or higher than, 2: equal or less than)
317 CONDITION_NOITEM = 16, // item_id count
318 CONDITION_SPELL = 17, // spell_id 0, 1 (0: has spell, 1: hasn't spell)
319 CONDITION_INSTANCE_SCRIPT = 18, // map_id instance_condition_id (instance script specific enum)
322 #define MAX_CONDITION 19 // maximum value in ConditionType enum
324 struct PlayerCondition
326 ConditionType condition; // additional condition type
327 uint32 value1; // data for the condition - see ConditionType definition
328 uint32 value2;
330 PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
331 : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
333 static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
334 // Checks correctness of values
335 bool Meets(Player const * APlayer) const; // Checks if the player meets the condition
336 bool operator == (PlayerCondition const& lc) const
338 return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
342 // NPC gossip text id
343 typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
345 typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
346 typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
348 enum SkillRangeType
350 SKILL_RANGE_LANGUAGE, // 300..300
351 SKILL_RANGE_LEVEL, // 1..max skill for level
352 SKILL_RANGE_MONO, // 1..1, grey monolite bar
353 SKILL_RANGE_RANK, // 1..skill for known rank
354 SKILL_RANGE_NONE, // 0..0 always
357 SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
359 #define MAX_PLAYER_NAME 12 // max allowed by client name length
360 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
361 #define MAX_PET_NAME 12 // max allowed by client name length
362 #define MAX_CHARTER_NAME 24 // max allowed by client name length
364 bool normalizePlayerName(std::string& name);
366 struct MANGOS_DLL_SPEC LanguageDesc
368 Language lang_id;
369 uint32 spell_id;
370 uint32 skill_id;
373 extern LanguageDesc lang_description[LANGUAGES_COUNT];
374 MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
376 class PlayerDumpReader;
378 template<typename T>
379 class IdGenerator
381 public: // constructors
382 explicit IdGenerator(char const* _name) : m_name(_name), m_nextGuid(1) {}
384 public: // modifiers
385 void Set(T val) { m_nextGuid = val; }
386 T Generate();
388 public: // accessors
389 T GetNextAfterMaxUsed() const { return m_nextGuid; }
391 private: // fields
392 char const* m_name;
393 T m_nextGuid;
396 class ObjectMgr
398 friend class PlayerDumpReader;
400 public:
401 ObjectMgr();
402 ~ObjectMgr();
404 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
406 typedef UNORDERED_MAP<uint32, Group*> GroupMap;
408 typedef UNORDERED_MAP<uint32, Guild*> GuildMap;
410 typedef UNORDERED_MAP<uint32, ArenaTeam*> ArenaTeamMap;
412 typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
414 typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
416 typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
418 typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
419 typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap;
421 typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
423 typedef std::vector<std::string> ScriptNameMap;
425 Player* GetPlayer(const char* name) const { return ObjectAccessor::FindPlayerByName(name);}
426 Player* GetPlayer(ObjectGuid guid) const { return ObjectAccessor::FindPlayer(guid); }
428 static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
430 void LoadGameobjectInfo();
431 void AddGameobjectInfo(GameObjectInfo *goinfo);
433 void PackGroupIds();
434 Group* GetGroupById(uint32 id) const;
435 void AddGroup(Group* group);
436 void RemoveGroup(Group* group);
438 Guild* GetGuildByLeader(uint64 const&guid) const;
439 Guild* GetGuildById(uint32 GuildId) const;
440 Guild* GetGuildByName(const std::string& guildname) const;
441 std::string GetGuildNameById(uint32 GuildId) const;
442 void AddGuild(Guild* guild);
443 void RemoveGuild(uint32 Id);
445 ArenaTeam* GetArenaTeamById(uint32 arenateamid) const;
446 ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
447 ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
448 void AddArenaTeam(ArenaTeam* arenaTeam);
449 void RemoveArenaTeam(uint32 Id);
450 ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
451 ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
453 static CreatureInfo const *GetCreatureTemplate( uint32 id );
454 CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
455 CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
456 uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
457 EquipmentInfo const *GetEquipmentInfo( uint32 entry );
458 static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
460 return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
463 static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
465 return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
468 static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
470 static InstanceTemplate const* GetInstanceTemplate(uint32 map)
472 return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
475 PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
477 PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
479 if(class_ >= MAX_CLASSES) return NULL;
480 return &playerClassInfo[class_];
482 void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
484 PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
486 if(race >= MAX_RACES) return NULL;
487 if(class_ >= MAX_CLASSES) return NULL;
488 PlayerInfo const* info = &playerInfo[race][class_];
489 if(info->displayId_m==0 || info->displayId_f==0) return NULL;
490 return info;
492 void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
494 uint64 GetPlayerGUIDByName(std::string name) const;
495 bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
496 uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
497 uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
498 uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const;
500 uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team );
501 void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
502 uint32 GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_alt_team = false);
504 Quest const* GetQuestTemplate(uint32 quest_id) const
506 QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
507 return itr != mQuestTemplates.end() ? itr->second : NULL;
509 QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
511 uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
513 QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
514 if(itr != mQuestAreaTriggerMap.end())
515 return itr->second;
516 return 0;
518 bool IsTavernAreaTrigger(uint32 Trigger_ID) const
520 return mTavernAreaTriggerSet.find(Trigger_ID) != mTavernAreaTriggerSet.end();
523 bool IsGameObjectForQuests(uint32 entry) const
525 return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end();
528 GossipText const* GetGossipText(uint32 Text_ID) const;
530 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
531 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
532 void LoadGraveyardZones();
533 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
535 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
537 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
538 if( itr != mAreaTriggers.end( ) )
539 return &itr->second;
540 return NULL;
543 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
544 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
546 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
548 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
550 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
551 if(itr != mRepOnKill.end())
552 return &itr->second;
553 return NULL;
556 PointOfInterest const* GetPointOfInterest(uint32 id) const
558 PointOfInterestMap::const_iterator itr = mPointsOfInterest.find(id);
559 if(itr != mPointsOfInterest.end())
560 return &itr->second;
561 return NULL;
564 QuestPOIVector const* GetQuestPOIVector(uint32 questId)
566 QuestPOIMap::const_iterator itr = mQuestPOIMap.find(questId);
567 if(itr != mQuestPOIMap.end())
568 return &itr->second;
569 return NULL;
572 void LoadGuilds();
573 void LoadArenaTeams();
574 void LoadGroups();
575 void LoadQuests();
576 void LoadQuestRelations()
578 LoadGameobjectQuestRelations();
579 LoadGameobjectInvolvedRelations();
580 LoadCreatureQuestRelations();
581 LoadCreatureInvolvedRelations();
583 void LoadGameobjectQuestRelations();
584 void LoadGameobjectInvolvedRelations();
585 void LoadCreatureQuestRelations();
586 void LoadCreatureInvolvedRelations();
588 QuestRelations mGOQuestRelations;
589 QuestRelations mGOQuestInvolvedRelations;
590 QuestRelations mCreatureQuestRelations;
591 QuestRelations mCreatureQuestInvolvedRelations;
593 void LoadGameObjectScripts();
594 void LoadQuestEndScripts();
595 void LoadQuestStartScripts();
596 void LoadEventScripts();
597 void LoadSpellScripts();
598 void LoadGossipScripts();
599 void LoadCreatureMovementScripts();
601 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
602 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
603 void LoadDbScriptStrings();
604 void LoadCreatureLocales();
605 void LoadCreatureTemplates();
606 void LoadCreatures();
607 void LoadCreatureRespawnTimes();
608 void LoadCreatureAddons();
609 void LoadCreatureModelInfo();
610 void LoadEquipmentTemplates();
611 void LoadGameObjectLocales();
612 void LoadGameobjects();
613 void LoadGameobjectRespawnTimes();
614 void LoadItemPrototypes();
615 void LoadItemRequiredTarget();
616 void LoadItemLocales();
617 void LoadQuestLocales();
618 void LoadNpcTextLocales();
619 void LoadPageTextLocales();
620 void LoadGossipMenuItemsLocales();
621 void LoadPointOfInterestLocales();
622 void LoadInstanceTemplate();
623 void LoadMailLevelRewards();
625 void LoadGossipText();
627 void LoadAreaTriggerTeleports();
628 void LoadQuestAreaTriggers();
629 void LoadAreaTriggerScripts();
630 void LoadTavernAreaTriggers();
631 void LoadGameObjectForQuests();
633 void LoadPageTexts();
635 void LoadPlayerInfo();
636 void LoadPetLevelInfo();
637 void LoadExplorationBaseXP();
638 void LoadPetNames();
639 void LoadPetNumber();
640 void LoadCorpses();
641 void LoadFishingBaseSkillLevel();
643 void LoadReputationOnKill();
644 void LoadPointsOfInterest();
645 void LoadQuestPOI();
647 void LoadNPCSpellClickSpells();
649 void LoadWeatherZoneChances();
650 void LoadGameTele();
652 void LoadNpcTextId();
654 void LoadGossipMenu();
655 void LoadGossipMenuItems();
657 void LoadVendors();
658 void LoadTrainerSpell();
660 std::string GeneratePetName(uint32 entry);
661 uint32 GetBaseXP(uint32 level) const;
662 uint32 GetXPForLevel(uint32 level) const;
663 uint32 GetXPForPetLevel(uint32 level) const { return GetXPForLevel(level)/20; }
665 int32 GetFishingBaseSkillLevel(uint32 entry) const
667 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
668 return itr != mFishingBaseForArea.end() ? itr->second : 0;
671 void ReturnOrDeleteOldMails(bool serverUp);
673 void SetHighestGuids();
674 uint32 GenerateLowGuid(HighGuid guidhigh);
675 uint32 GenerateArenaTeamId() { return m_ArenaTeamIds.Generate(); }
676 uint32 GenerateAuctionID() { return m_AuctionIds.Generate(); }
677 uint64 GenerateEquipmentSetGuid() { return m_EquipmentSetIds.Generate(); }
678 uint32 GenerateGuildId() { return m_GuildIds.Generate(); }
679 uint32 GenerateGroupId() { return m_GroupIds.Generate(); }
680 //uint32 GenerateItemTextID() { return m_ItemGuids.Generate(); }
681 uint32 GenerateMailID() { return m_MailIds.Generate(); }
682 uint32 GeneratePetNumber() { return m_PetNumbers.Generate(); }
684 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
685 ExclusiveQuestGroups mExclusiveQuestGroups;
687 MailLevelReward const* GetMailLevelReward(uint32 level,uint32 raceMask)
689 MailLevelRewardMap::const_iterator map_itr = m_mailLevelRewardMap.find(level);
690 if (map_itr == m_mailLevelRewardMap.end())
691 return NULL;
693 for(MailLevelRewardList::const_iterator set_itr = map_itr->second.begin(); set_itr != map_itr->second.end(); ++set_itr)
694 if (set_itr->raceMask & raceMask)
695 return &*set_itr;
697 return NULL;
700 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
702 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
703 if(itr != mWeatherZoneMap.end())
704 return &itr->second;
705 else
706 return NULL;
709 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
711 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
714 CreatureData const* GetCreatureData(uint32 guid) const
716 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
717 if(itr==mCreatureDataMap.end()) return NULL;
718 return &itr->second;
720 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
721 void DeleteCreatureData(uint32 guid);
722 CreatureLocale const* GetCreatureLocale(uint32 entry) const
724 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
725 if(itr==mCreatureLocaleMap.end()) return NULL;
726 return &itr->second;
728 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
730 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
731 if(itr==mGameObjectLocaleMap.end()) return NULL;
732 return &itr->second;
734 ItemLocale const* GetItemLocale(uint32 entry) const
736 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
737 if(itr==mItemLocaleMap.end()) return NULL;
738 return &itr->second;
740 QuestLocale const* GetQuestLocale(uint32 entry) const
742 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
743 if(itr==mQuestLocaleMap.end()) return NULL;
744 return &itr->second;
746 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
748 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
749 if(itr==mNpcTextLocaleMap.end()) return NULL;
750 return &itr->second;
752 PageTextLocale const* GetPageTextLocale(uint32 entry) const
754 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
755 if(itr==mPageTextLocaleMap.end()) return NULL;
756 return &itr->second;
758 GossipMenuItemsLocale const* GetGossipMenuItemsLocale(uint32 entry) const
760 GossipMenuItemsLocaleMap::const_iterator itr = mGossipMenuItemsLocaleMap.find(entry);
761 if(itr==mGossipMenuItemsLocaleMap.end()) return NULL;
762 return &itr->second;
764 PointOfInterestLocale const* GetPointOfInterestLocale(uint32 poi_id) const
766 PointOfInterestLocaleMap::const_iterator itr = mPointOfInterestLocaleMap.find(poi_id);
767 if(itr==mPointOfInterestLocaleMap.end()) return NULL;
768 return &itr->second;
771 GameObjectData const* GetGOData(uint32 guid) const
773 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
774 if(itr==mGameObjectDataMap.end()) return NULL;
775 return &itr->second;
777 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
778 void DeleteGOData(uint32 guid);
780 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
782 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
783 if(itr==mMangosStringLocaleMap.end()) return NULL;
784 return &itr->second;
786 const char *GetMangosString(int32 entry, int locale_idx) const;
787 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
788 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
789 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
791 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
792 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
794 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
795 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
796 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
797 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
798 void DeleteRespawnTimeForInstance(uint32 instance);
800 // grid objects
801 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
802 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
803 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
804 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
806 // reserved names
807 void LoadReservedPlayersNames();
808 bool IsReservedName(const std::string& name) const;
810 // name with valid structure and symbols
811 static uint8 CheckPlayerName( const std::string& name, bool create = false );
812 static PetNameInvalidReason CheckPetName( const std::string& name );
813 static bool IsValidCharterName( const std::string& name );
815 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
817 int GetIndexForLocale(LocaleConstant loc);
818 LocaleConstant GetLocaleForIndex(int i);
820 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
821 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
823 if(condition_id >= mConditions.size())
824 return false;
826 return mConditions[condition_id].Meets(player);
829 GameTele const* GetGameTele(uint32 id) const
831 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
832 if(itr==m_GameTeleMap.end()) return NULL;
833 return &itr->second;
835 GameTele const* GetGameTele(const std::string& name) const;
836 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
837 bool AddGameTele(GameTele& data);
838 bool DeleteGameTele(const std::string& name);
840 uint32 GetNpcGossip(uint32 entry) const
842 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
843 if(iter == m_mCacheNpcTextIdMap.end())
844 return 0;
846 return iter->second;
849 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
851 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
852 if(iter == m_mCacheTrainerSpellMap.end())
853 return NULL;
855 return &iter->second;
858 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
860 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
861 if(iter == m_mCacheVendorItemMap.end())
862 return NULL;
864 return &iter->second;
866 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, int32 ExtendedCost);
867 bool RemoveVendorItem(uint32 entry,uint32 item);
868 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, int32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
870 void LoadScriptNames();
871 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
872 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
873 uint32 GetScriptId(const char *name);
875 int GetOrNewIndexForLocale(LocaleConstant loc);
877 SpellClickInfoMapBounds GetSpellClickInfoMapBounds(uint32 creature_id) const
879 return SpellClickInfoMapBounds(mSpellClickInfoMap.lower_bound(creature_id),mSpellClickInfoMap.upper_bound(creature_id));
882 ItemRequiredTargetMapBounds GetItemRequiredTargetMapBounds(uint32 uiItemEntry) const
884 return ItemRequiredTargetMapBounds(m_ItemRequiredTarget.lower_bound(uiItemEntry),m_ItemRequiredTarget.upper_bound(uiItemEntry));
887 GossipMenusMapBounds GetGossipMenusMapBounds(uint32 uiMenuId) const
889 return GossipMenusMapBounds(m_mGossipMenusMap.lower_bound(uiMenuId),m_mGossipMenusMap.upper_bound(uiMenuId));
892 GossipMenuItemsMapBounds GetGossipMenuItemsMapBounds(uint32 uiMenuId) const
894 return GossipMenuItemsMapBounds(m_mGossipMenuItemsMap.lower_bound(uiMenuId),m_mGossipMenuItemsMap.upper_bound(uiMenuId));
897 protected:
899 // first free id for selected id type
900 IdGenerator<uint32> m_ArenaTeamIds;
901 IdGenerator<uint32> m_AuctionIds;
902 IdGenerator<uint64> m_EquipmentSetIds;
903 IdGenerator<uint32> m_GuildIds;
904 IdGenerator<uint32> m_MailIds;
905 IdGenerator<uint32> m_PetNumbers;
906 IdGenerator<uint32> m_GroupIds;
908 // first free low guid for selected guid type
909 ObjectGuidGenerator<HIGHGUID_PLAYER> m_CharGuids;
910 ObjectGuidGenerator<HIGHGUID_UNIT> m_CreatureGuids;
911 ObjectGuidGenerator<HIGHGUID_ITEM> m_ItemGuids;
912 ObjectGuidGenerator<HIGHGUID_GAMEOBJECT> m_GameobjectGuids;
913 ObjectGuidGenerator<HIGHGUID_CORPSE> m_CorpseGuids;
915 QuestMap mQuestTemplates;
917 typedef UNORDERED_MAP<uint32, GossipText> GossipTextMap;
918 typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
919 typedef std::set<uint32> TavernAreaTriggerSet;
920 typedef std::set<uint32> GameObjectForQuestSet;
922 GroupMap mGroupMap;
923 GuildMap mGuildMap;
924 ArenaTeamMap mArenaTeamMap;
926 QuestAreaTriggerMap mQuestAreaTriggerMap;
927 TavernAreaTriggerSet mTavernAreaTriggerSet;
928 GameObjectForQuestSet mGameObjectForQuestSet;
929 GossipTextMap mGossipText;
930 AreaTriggerMap mAreaTriggers;
931 AreaTriggerScriptMap mAreaTriggerScripts;
933 RepOnKillMap mRepOnKill;
935 GossipMenusMap m_mGossipMenusMap;
936 GossipMenuItemsMap m_mGossipMenuItemsMap;
937 PointOfInterestMap mPointsOfInterest;
939 QuestPOIMap mQuestPOIMap;
941 WeatherZoneMap mWeatherZoneMap;
943 //character reserved names
944 typedef std::set<std::wstring> ReservedNamesMap;
945 ReservedNamesMap m_ReservedNames;
947 GraveYardMap mGraveYardMap;
949 GameTeleMap m_GameTeleMap;
951 ScriptNameMap m_scriptNames;
953 SpellClickInfoMap mSpellClickInfoMap;
955 ItemRequiredTargetMap m_ItemRequiredTarget;
957 typedef std::vector<LocaleConstant> LocalForIndex;
958 LocalForIndex m_LocalForIndex;
960 int DBCLocaleIndex;
962 private:
963 void LoadScripts(ScriptMapMap& scripts, char const* tablename);
964 void CheckScriptTexts(ScriptMapMap const& scripts,std::set<int32>& ids);
965 void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment);
966 void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
967 void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
969 MailLevelRewardMap m_mailLevelRewardMap;
971 typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
972 // PetLevelInfoMap[creature_id][level]
973 PetLevelInfoMap petInfo; // [creature_id][level]
975 PlayerClassInfo playerClassInfo[MAX_CLASSES];
977 void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
978 PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
980 typedef std::vector<uint32> PlayerXPperLevel; // [level]
981 PlayerXPperLevel mPlayerXPperLevel;
983 typedef std::map<uint32,uint32> BaseXPMap; // [area level][base xp]
984 BaseXPMap mBaseXPTable;
986 typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
987 FishingBaseSkillMap mFishingBaseForArea;
989 typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
990 HalfNameMap PetHalfName0;
991 HalfNameMap PetHalfName1;
993 MapObjectGuids mMapObjectGuids;
994 CreatureDataMap mCreatureDataMap;
995 CreatureLocaleMap mCreatureLocaleMap;
996 GameObjectDataMap mGameObjectDataMap;
997 GameObjectLocaleMap mGameObjectLocaleMap;
998 ItemLocaleMap mItemLocaleMap;
999 QuestLocaleMap mQuestLocaleMap;
1000 NpcTextLocaleMap mNpcTextLocaleMap;
1001 PageTextLocaleMap mPageTextLocaleMap;
1002 MangosStringLocaleMap mMangosStringLocaleMap;
1003 GossipMenuItemsLocaleMap mGossipMenuItemsLocaleMap;
1004 PointOfInterestLocaleMap mPointOfInterestLocaleMap;
1005 RespawnTimes mCreatureRespawnTimes;
1006 RespawnTimes mGORespawnTimes;
1008 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
1009 typedef std::vector<PlayerCondition> ConditionStore;
1010 ConditionStore mConditions;
1012 CacheNpcTextIdMap m_mCacheNpcTextIdMap;
1013 CacheVendorItemMap m_mCacheVendorItemMap;
1014 CacheTrainerSpellMap m_mCacheTrainerSpellMap;
1017 #define sObjectMgr MaNGOS::Singleton<ObjectMgr>::Instance()
1019 // scripting access functions
1020 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());
1021 MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
1022 MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
1023 MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
1024 MANGOS_DLL_SPEC CreatureInfo const* GetCreatureTemplateStore(uint32 entry);
1025 MANGOS_DLL_SPEC Quest const* GetQuestTemplateStore(uint32 entry);
1027 #endif