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
27 #include "GameObject.h"
31 #include "ItemPrototype.h"
32 #include "NPCHandler.h"
33 #include "Database/DatabaseEnv.h"
36 #include "ObjectAccessor.h"
37 #include "ObjectGuid.h"
38 #include "Policies/Singleton.h"
39 #include "Database/SQLStorage.h"
45 extern SQLStorage sCreatureStorage
;
46 extern SQLStorage sCreatureDataAddonStorage
;
47 extern SQLStorage sCreatureInfoAddonStorage
;
48 extern SQLStorage sCreatureModelStorage
;
49 extern SQLStorage sEquipmentStorage
;
50 extern SQLStorage sGOStorage
;
51 extern SQLStorage sPageTextStore
;
52 extern SQLStorage sItemStorage
;
53 extern SQLStorage sInstanceTemplate
;
70 std::wstring wnameLow
;
73 typedef UNORDERED_MAP
<uint32
, GameTele
> GameTeleMap
;
89 typedef std::multimap
<uint32
, ScriptInfo
> ScriptMap
;
90 typedef std::map
<uint32
, ScriptMap
> ScriptMapMap
;
91 extern ScriptMapMap sQuestEndScripts
;
92 extern ScriptMapMap sQuestStartScripts
;
93 extern ScriptMapMap sSpellScripts
;
94 extern ScriptMapMap sGameObjectScripts
;
95 extern ScriptMapMap sEventScripts
;
96 extern ScriptMapMap sGossipScripts
;
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)
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
;
117 uint32 requiredItem2
;
120 uint32 requiredQuest
;
121 uint32 requiredQuestHeroic
;
122 std::string requiredFailedText
;
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
;
175 PetLevelInfo() : health(0), mana(0) { for(int i
=0; i
< MAX_STATS
; ++i
) stats
[i
] = 0; }
177 uint16 stats
[MAX_STATS
];
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
) {}
189 uint32 mailTemplateId
;
193 typedef std::list
<MailLevelReward
> MailLevelRewardList
;
194 typedef UNORDERED_MAP
<uint8
,MailLevelRewardList
> MailLevelRewardMap
;
196 struct ReputationOnKillEntry
201 uint32 reputation_max_cap1
;
204 uint32 reputation_max_cap2
;
209 struct PointOfInterest
217 std::string icon_name
;
220 struct GossipMenuItems
225 std::string option_text
;
227 uint32 npc_option_npcflag
;
228 uint32 action_menu_id
;
229 uint32 action_poi_id
;
230 uint32 action_script_id
;
233 std::string box_text
;
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
;
257 QuestPOIPoint() : x(0), y(0) {}
258 QuestPOIPoint(int32 _x
, int32 _y
) : x(_x
), y(_y
) {}
263 int32 ObjectiveIndex
;
269 std::vector
<QuestPOIPoint
> points
;
271 QuestPOI() : ObjectiveIndex(0), MapId(0), Unk1(0), Unk2(0), Unk3(0), Unk4(0) {}
272 QuestPOI(int32 objIndex
, uint32 mapId
, uint32 unk1
, uint32 unk2
, uint32 unk3
, uint32 unk4
) : ObjectiveIndex(objIndex
), MapId(mapId
), Unk1(unk1
), Unk2(unk2
), Unk3(unk3
), Unk4(unk4
) {}
275 typedef std::vector
<QuestPOI
> QuestPOIVector
;
276 typedef UNORDERED_MAP
<uint32
, QuestPOIVector
> QuestPOIMap
;
278 #define WEATHER_SEASONS 4
279 struct WeatherSeasonChances
286 struct WeatherZoneChances
288 WeatherSeasonChances data
[WEATHER_SEASONS
];
296 typedef std::multimap
<uint32
,GraveYardData
> GraveYardMap
;
299 { // value1 value2 for the Condition enumed
300 CONDITION_NONE
= 0, // 0 0
301 CONDITION_AURA
= 1, // spell_id effindex
302 CONDITION_ITEM
= 2, // item_id count
303 CONDITION_ITEM_EQUIPPED
= 3, // item_id 0
304 CONDITION_ZONEID
= 4, // zone_id 0
305 CONDITION_REPUTATION_RANK
= 5, // faction_id min_rank
306 CONDITION_TEAM
= 6, // player_team 0, (469 - Alliance 67 - Horde)
307 CONDITION_SKILL
= 7, // skill_id skill_value
308 CONDITION_QUESTREWARDED
= 8, // quest_id 0
309 CONDITION_QUESTTAKEN
= 9, // quest_id 0, for condition true while quest active.
310 CONDITION_AD_COMMISSION_AURA
= 10, // 0 0, for condition true while one from AD commission aura active
311 CONDITION_NO_AURA
= 11, // spell_id effindex
312 CONDITION_ACTIVE_EVENT
= 12, // event_id 0
313 CONDITION_AREA_FLAG
= 13, // area_flag area_flag_not
314 CONDITION_RACE_CLASS
= 14, // race_mask class_mask
315 CONDITION_LEVEL
= 15, // player_level 0, 1 or 2 (0: equal to, 1: equal or higher than, 2: equal or less than)
316 CONDITION_NOITEM
= 16, // item_id count
319 #define MAX_CONDITION 17 // maximum value in ConditionType enum
321 struct PlayerCondition
323 ConditionType condition
; // additional condition type
324 uint32 value1
; // data for the condition - see ConditionType definition
327 PlayerCondition(uint8 _condition
= 0, uint32 _value1
= 0, uint32 _value2
= 0)
328 : condition(ConditionType(_condition
)), value1(_value1
), value2(_value2
) {}
330 static bool IsValid(ConditionType condition
, uint32 value1
, uint32 value2
);
331 // Checks correctness of values
332 bool Meets(Player
const * APlayer
) const; // Checks if the player meets the condition
333 bool operator == (PlayerCondition
const& lc
) const
335 return (lc
.condition
== condition
&& lc
.value1
== value1
&& lc
.value2
== value2
);
339 // NPC gossip text id
340 typedef UNORDERED_MAP
<uint32
, uint32
> CacheNpcTextIdMap
;
342 typedef UNORDERED_MAP
<uint32
, VendorItemData
> CacheVendorItemMap
;
343 typedef UNORDERED_MAP
<uint32
, TrainerSpellData
> CacheTrainerSpellMap
;
347 SKILL_RANGE_LANGUAGE
, // 300..300
348 SKILL_RANGE_LEVEL
, // 1..max skill for level
349 SKILL_RANGE_MONO
, // 1..1, grey monolite bar
350 SKILL_RANGE_RANK
, // 1..skill for known rank
351 SKILL_RANGE_NONE
, // 0..0 always
354 SkillRangeType
GetSkillRangeType(SkillLineEntry
const *pSkill
, bool racial
);
356 #define MAX_PLAYER_NAME 12 // max allowed by client name length
357 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
358 #define MAX_PET_NAME 12 // max allowed by client name length
359 #define MAX_CHARTER_NAME 24 // max allowed by client name length
361 bool normalizePlayerName(std::string
& name
);
363 struct MANGOS_DLL_SPEC LanguageDesc
370 extern LanguageDesc lang_description
[LANGUAGES_COUNT
];
371 MANGOS_DLL_SPEC LanguageDesc
const* GetLanguageDescByID(uint32 lang
);
373 class PlayerDumpReader
;
378 public: // constructors
379 explicit IdGenerator(char const* _name
) : m_name(_name
), m_nextGuid(1) {}
382 void Set(T val
) { m_nextGuid
= val
; }
386 T
GetNextAfterMaxUsed() const { return m_nextGuid
; }
395 friend class PlayerDumpReader
;
401 typedef UNORDERED_MAP
<uint32
, Item
*> ItemMap
;
403 typedef UNORDERED_MAP
<uint32
, Group
*> GroupMap
;
405 typedef UNORDERED_MAP
<uint32
, Guild
*> GuildMap
;
407 typedef UNORDERED_MAP
<uint32
, ArenaTeam
*> ArenaTeamMap
;
409 typedef UNORDERED_MAP
<uint32
, Quest
*> QuestMap
;
411 typedef UNORDERED_MAP
<uint32
, AreaTrigger
> AreaTriggerMap
;
413 typedef UNORDERED_MAP
<uint32
, uint32
> AreaTriggerScriptMap
;
415 typedef UNORDERED_MAP
<uint32
, ReputationOnKillEntry
> RepOnKillMap
;
416 typedef UNORDERED_MAP
<uint32
, PointOfInterest
> PointOfInterestMap
;
418 typedef UNORDERED_MAP
<uint32
, WeatherZoneChances
> WeatherZoneMap
;
420 typedef std::vector
<std::string
> ScriptNameMap
;
422 Player
* GetPlayer(const char* name
) const { return ObjectAccessor::FindPlayerByName(name
);}
423 Player
* GetPlayer(ObjectGuid guid
) const { return ObjectAccessor::FindPlayer(guid
); }
425 static GameObjectInfo
const *GetGameObjectInfo(uint32 id
) { return sGOStorage
.LookupEntry
<GameObjectInfo
>(id
); }
427 void LoadGameobjectInfo();
428 void AddGameobjectInfo(GameObjectInfo
*goinfo
);
431 Group
* GetGroupById(uint32 id
) const;
432 void AddGroup(Group
* group
);
433 void RemoveGroup(Group
* group
);
435 Guild
* GetGuildByLeader(uint64
const&guid
) const;
436 Guild
* GetGuildById(uint32 GuildId
) const;
437 Guild
* GetGuildByName(const std::string
& guildname
) const;
438 std::string
GetGuildNameById(uint32 GuildId
) const;
439 void AddGuild(Guild
* guild
);
440 void RemoveGuild(uint32 Id
);
442 ArenaTeam
* GetArenaTeamById(uint32 arenateamid
) const;
443 ArenaTeam
* GetArenaTeamByName(const std::string
& arenateamname
) const;
444 ArenaTeam
* GetArenaTeamByCaptain(uint64
const& guid
) const;
445 void AddArenaTeam(ArenaTeam
* arenaTeam
);
446 void RemoveArenaTeam(uint32 Id
);
447 ArenaTeamMap::iterator
GetArenaTeamMapBegin() { return mArenaTeamMap
.begin(); }
448 ArenaTeamMap::iterator
GetArenaTeamMapEnd() { return mArenaTeamMap
.end(); }
450 static CreatureInfo
const *GetCreatureTemplate( uint32 id
);
451 CreatureModelInfo
const *GetCreatureModelInfo( uint32 modelid
);
452 CreatureModelInfo
const* GetCreatureModelRandomGender(uint32 display_id
);
453 uint32
ChooseDisplayId(uint32 team
, const CreatureInfo
*cinfo
, const CreatureData
*data
= NULL
);
454 EquipmentInfo
const *GetEquipmentInfo( uint32 entry
);
455 static CreatureDataAddon
const *GetCreatureAddon( uint32 lowguid
)
457 return sCreatureDataAddonStorage
.LookupEntry
<CreatureDataAddon
>(lowguid
);
460 static CreatureDataAddon
const *GetCreatureTemplateAddon( uint32 entry
)
462 return sCreatureInfoAddonStorage
.LookupEntry
<CreatureDataAddon
>(entry
);
465 static ItemPrototype
const* GetItemPrototype(uint32 id
) { return sItemStorage
.LookupEntry
<ItemPrototype
>(id
); }
467 static InstanceTemplate
const* GetInstanceTemplate(uint32 map
)
469 return sInstanceTemplate
.LookupEntry
<InstanceTemplate
>(map
);
472 PetLevelInfo
const* GetPetLevelInfo(uint32 creature_id
, uint32 level
) const;
474 PlayerClassInfo
const* GetPlayerClassInfo(uint32 class_
) const
476 if(class_
>= MAX_CLASSES
) return NULL
;
477 return &playerClassInfo
[class_
];
479 void GetPlayerClassLevelInfo(uint32 class_
,uint32 level
, PlayerClassLevelInfo
* info
) const;
481 PlayerInfo
const* GetPlayerInfo(uint32 race
, uint32 class_
) const
483 if(race
>= MAX_RACES
) return NULL
;
484 if(class_
>= MAX_CLASSES
) return NULL
;
485 PlayerInfo
const* info
= &playerInfo
[race
][class_
];
486 if(info
->displayId_m
==0 || info
->displayId_f
==0) return NULL
;
489 void GetPlayerLevelInfo(uint32 race
, uint32 class_
,uint32 level
, PlayerLevelInfo
* info
) const;
491 uint64
GetPlayerGUIDByName(std::string name
) const;
492 bool GetPlayerNameByGUID(const uint64
&guid
, std::string
&name
) const;
493 uint32
GetPlayerTeamByGUID(const uint64
&guid
) const;
494 uint32
GetPlayerAccountIdByGUID(const uint64
&guid
) const;
495 uint32
GetPlayerAccountIdByPlayerName(const std::string
& name
) const;
497 uint32
GetNearestTaxiNode( float x
, float y
, float z
, uint32 mapid
, uint32 team
);
498 void GetTaxiPath( uint32 source
, uint32 destination
, uint32
&path
, uint32
&cost
);
499 uint32
GetTaxiMountDisplayId( uint32 id
, uint32 team
, bool allowed_alt_team
= false);
500 void GetTaxiPathNodes( uint32 path
, Path
&pathnodes
, std::vector
<uint32
>& mapIds
);
501 void GetTransportPathNodes( uint32 path
, TransportPath
&pathnodes
);
503 Quest
const* GetQuestTemplate(uint32 quest_id
) const
505 QuestMap::const_iterator itr
= mQuestTemplates
.find(quest_id
);
506 return itr
!= mQuestTemplates
.end() ? itr
->second
: NULL
;
508 QuestMap
const& GetQuestTemplates() const { return mQuestTemplates
; }
510 uint32
GetQuestForAreaTrigger(uint32 Trigger_ID
) const
512 QuestAreaTriggerMap::const_iterator itr
= mQuestAreaTriggerMap
.find(Trigger_ID
);
513 if(itr
!= mQuestAreaTriggerMap
.end())
517 bool IsTavernAreaTrigger(uint32 Trigger_ID
) const
519 return mTavernAreaTriggerSet
.find(Trigger_ID
) != mTavernAreaTriggerSet
.end();
522 bool IsGameObjectForQuests(uint32 entry
) const
524 return mGameObjectForQuestSet
.find(entry
) != mGameObjectForQuestSet
.end();
527 GossipText
const* GetGossipText(uint32 Text_ID
) const;
529 WorldSafeLocsEntry
const *GetClosestGraveYard(float x
, float y
, float z
, uint32 MapId
, uint32 team
);
530 bool AddGraveYardLink(uint32 id
, uint32 zone
, uint32 team
, bool inDB
= true);
531 void LoadGraveyardZones();
532 GraveYardData
const* FindGraveYardData(uint32 id
, uint32 zone
);
534 AreaTrigger
const* GetAreaTrigger(uint32 trigger
) const
536 AreaTriggerMap::const_iterator itr
= mAreaTriggers
.find( trigger
);
537 if( itr
!= mAreaTriggers
.end( ) )
542 AreaTrigger
const* GetGoBackTrigger(uint32 Map
) const;
543 AreaTrigger
const* GetMapEntranceTrigger(uint32 Map
) const;
545 uint32
GetAreaTriggerScriptId(uint32 trigger_id
);
547 ReputationOnKillEntry
const* GetReputationOnKilEntry(uint32 id
) const
549 RepOnKillMap::const_iterator itr
= mRepOnKill
.find(id
);
550 if(itr
!= mRepOnKill
.end())
555 PointOfInterest
const* GetPointOfInterest(uint32 id
) const
557 PointOfInterestMap::const_iterator itr
= mPointsOfInterest
.find(id
);
558 if(itr
!= mPointsOfInterest
.end())
563 QuestPOIVector
const* GetQuestPOIVector(uint32 questId
)
565 QuestPOIMap::const_iterator itr
= mQuestPOIMap
.find(questId
);
566 if(itr
!= mQuestPOIMap
.end())
572 void LoadArenaTeams();
575 void LoadQuestRelations()
577 LoadGameobjectQuestRelations();
578 LoadGameobjectInvolvedRelations();
579 LoadCreatureQuestRelations();
580 LoadCreatureInvolvedRelations();
582 void LoadGameobjectQuestRelations();
583 void LoadGameobjectInvolvedRelations();
584 void LoadCreatureQuestRelations();
585 void LoadCreatureInvolvedRelations();
587 QuestRelations mGOQuestRelations
;
588 QuestRelations mGOQuestInvolvedRelations
;
589 QuestRelations mCreatureQuestRelations
;
590 QuestRelations mCreatureQuestInvolvedRelations
;
592 void LoadGameObjectScripts();
593 void LoadQuestEndScripts();
594 void LoadQuestStartScripts();
595 void LoadEventScripts();
596 void LoadSpellScripts();
597 void LoadGossipScripts();
599 bool LoadMangosStrings(DatabaseType
& db
, char const* table
, int32 min_value
, int32 max_value
);
600 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase
,"mangos_string",MIN_MANGOS_STRING_ID
,MAX_MANGOS_STRING_ID
); }
601 void LoadDbScriptStrings();
602 void LoadCreatureLocales();
603 void LoadCreatureTemplates();
604 void LoadCreatures();
605 void LoadCreatureRespawnTimes();
606 void LoadCreatureAddons();
607 void LoadCreatureModelInfo();
608 void LoadEquipmentTemplates();
609 void LoadGameObjectLocales();
610 void LoadGameobjects();
611 void LoadGameobjectRespawnTimes();
612 void LoadItemPrototypes();
613 void LoadItemRequiredTarget();
614 void LoadItemLocales();
615 void LoadQuestLocales();
616 void LoadNpcTextLocales();
617 void LoadPageTextLocales();
618 void LoadGossipMenuItemsLocales();
619 void LoadPointOfInterestLocales();
620 void LoadInstanceTemplate();
621 void LoadMailLevelRewards();
623 void LoadGossipText();
625 void LoadAreaTriggerTeleports();
626 void LoadQuestAreaTriggers();
627 void LoadAreaTriggerScripts();
628 void LoadTavernAreaTriggers();
629 void LoadGameObjectForQuests();
631 void LoadItemTexts();
632 void LoadPageTexts();
634 void LoadPlayerInfo();
635 void LoadPetLevelInfo();
636 void LoadExplorationBaseXP();
638 void LoadPetNumber();
640 void LoadFishingBaseSkillLevel();
642 void LoadReputationOnKill();
643 void LoadPointsOfInterest();
646 void LoadNPCSpellClickSpells();
648 void LoadWeatherZoneChances();
651 void LoadNpcTextId();
653 void LoadGossipMenu();
654 void LoadGossipMenuItems();
657 void LoadTrainerSpell();
659 std::string
GeneratePetName(uint32 entry
);
660 uint32
GetBaseXP(uint32 level
) const;
661 uint32
GetXPForLevel(uint32 level
) const;
662 uint32
GetXPForPetLevel(uint32 level
) const { return GetXPForLevel(level
)/20; }
664 int32
GetFishingBaseSkillLevel(uint32 entry
) const
666 FishingBaseSkillMap::const_iterator itr
= mFishingBaseForArea
.find(entry
);
667 return itr
!= mFishingBaseForArea
.end() ? itr
->second
: 0;
670 void ReturnOrDeleteOldMails(bool serverUp
);
672 void SetHighestGuids();
673 uint32
GenerateLowGuid(HighGuid guidhigh
);
674 uint32
GenerateArenaTeamId() { return m_ArenaTeamIds
.Generate(); }
675 uint32
GenerateAuctionID() { return m_AuctionIds
.Generate(); }
676 uint64
GenerateEquipmentSetGuid() { return m_EquipmentSetIds
.Generate(); }
677 uint32
GenerateGuildId() { return m_GuildIds
.Generate(); }
678 uint32
GenerateGroupId() { return m_GroupIds
.Generate(); }
679 uint32
GenerateItemTextID() { return m_ItemGuids
.Generate(); }
680 uint32
GenerateMailID() { return m_MailIds
.Generate(); }
681 uint32
GeneratePetNumber() { return m_PetNumbers
.Generate(); }
683 uint32
CreateItemText(std::string text
);
684 void AddItemText(uint32 itemTextId
, std::string text
) { mItemTexts
[itemTextId
] = text
; }
685 std::string
GetItemText( uint32 id
)
687 ItemTextMap::const_iterator itr
= mItemTexts
.find( id
);
688 if ( itr
!= mItemTexts
.end() )
691 return "There is no info for this item";
694 typedef std::multimap
<int32
, uint32
> ExclusiveQuestGroups
;
695 ExclusiveQuestGroups mExclusiveQuestGroups
;
697 MailLevelReward
const* GetMailLevelReward(uint32 level
,uint32 raceMask
)
699 MailLevelRewardMap::const_iterator map_itr
= m_mailLevelRewardMap
.find(level
);
700 if (map_itr
== m_mailLevelRewardMap
.end())
703 for(MailLevelRewardList::const_iterator set_itr
= map_itr
->second
.begin(); set_itr
!= map_itr
->second
.end(); ++set_itr
)
704 if (set_itr
->raceMask
& raceMask
)
710 WeatherZoneChances
const* GetWeatherChances(uint32 zone_id
) const
712 WeatherZoneMap::const_iterator itr
= mWeatherZoneMap
.find(zone_id
);
713 if(itr
!= mWeatherZoneMap
.end())
719 CellObjectGuids
const& GetCellObjectGuids(uint16 mapid
, uint8 spawnMode
, uint32 cell_id
)
721 return mMapObjectGuids
[MAKE_PAIR32(mapid
,spawnMode
)][cell_id
];
724 CreatureData
const* GetCreatureData(uint32 guid
) const
726 CreatureDataMap::const_iterator itr
= mCreatureDataMap
.find(guid
);
727 if(itr
==mCreatureDataMap
.end()) return NULL
;
730 CreatureData
& NewOrExistCreatureData(uint32 guid
) { return mCreatureDataMap
[guid
]; }
731 void DeleteCreatureData(uint32 guid
);
732 CreatureLocale
const* GetCreatureLocale(uint32 entry
) const
734 CreatureLocaleMap::const_iterator itr
= mCreatureLocaleMap
.find(entry
);
735 if(itr
==mCreatureLocaleMap
.end()) return NULL
;
738 GameObjectLocale
const* GetGameObjectLocale(uint32 entry
) const
740 GameObjectLocaleMap::const_iterator itr
= mGameObjectLocaleMap
.find(entry
);
741 if(itr
==mGameObjectLocaleMap
.end()) return NULL
;
744 ItemLocale
const* GetItemLocale(uint32 entry
) const
746 ItemLocaleMap::const_iterator itr
= mItemLocaleMap
.find(entry
);
747 if(itr
==mItemLocaleMap
.end()) return NULL
;
750 QuestLocale
const* GetQuestLocale(uint32 entry
) const
752 QuestLocaleMap::const_iterator itr
= mQuestLocaleMap
.find(entry
);
753 if(itr
==mQuestLocaleMap
.end()) return NULL
;
756 NpcTextLocale
const* GetNpcTextLocale(uint32 entry
) const
758 NpcTextLocaleMap::const_iterator itr
= mNpcTextLocaleMap
.find(entry
);
759 if(itr
==mNpcTextLocaleMap
.end()) return NULL
;
762 PageTextLocale
const* GetPageTextLocale(uint32 entry
) const
764 PageTextLocaleMap::const_iterator itr
= mPageTextLocaleMap
.find(entry
);
765 if(itr
==mPageTextLocaleMap
.end()) return NULL
;
768 GossipMenuItemsLocale
const* GetGossipMenuItemsLocale(uint32 entry
) const
770 GossipMenuItemsLocaleMap::const_iterator itr
= mGossipMenuItemsLocaleMap
.find(entry
);
771 if(itr
==mGossipMenuItemsLocaleMap
.end()) return NULL
;
774 PointOfInterestLocale
const* GetPointOfInterestLocale(uint32 poi_id
) const
776 PointOfInterestLocaleMap::const_iterator itr
= mPointOfInterestLocaleMap
.find(poi_id
);
777 if(itr
==mPointOfInterestLocaleMap
.end()) return NULL
;
781 GameObjectData
const* GetGOData(uint32 guid
) const
783 GameObjectDataMap::const_iterator itr
= mGameObjectDataMap
.find(guid
);
784 if(itr
==mGameObjectDataMap
.end()) return NULL
;
787 GameObjectData
& NewGOData(uint32 guid
) { return mGameObjectDataMap
[guid
]; }
788 void DeleteGOData(uint32 guid
);
790 MangosStringLocale
const* GetMangosStringLocale(int32 entry
) const
792 MangosStringLocaleMap::const_iterator itr
= mMangosStringLocaleMap
.find(entry
);
793 if(itr
==mMangosStringLocaleMap
.end()) return NULL
;
796 const char *GetMangosString(int32 entry
, int locale_idx
) const;
797 const char *GetMangosStringForDBCLocale(int32 entry
) const { return GetMangosString(entry
,DBCLocaleIndex
); }
798 int32
GetDBCLocaleIndex() const { return DBCLocaleIndex
; }
799 void SetDBCLocaleIndex(uint32 lang
) { DBCLocaleIndex
= GetIndexForLocale(LocaleConstant(lang
)); }
801 void AddCorpseCellData(uint32 mapid
, uint32 cellid
, uint32 player_guid
, uint32 instance
);
802 void DeleteCorpseCellData(uint32 mapid
, uint32 cellid
, uint32 player_guid
);
804 time_t GetCreatureRespawnTime(uint32 loguid
, uint32 instance
) { return mCreatureRespawnTimes
[MAKE_PAIR64(loguid
,instance
)]; }
805 void SaveCreatureRespawnTime(uint32 loguid
, uint32 instance
, time_t t
);
806 time_t GetGORespawnTime(uint32 loguid
, uint32 instance
) { return mGORespawnTimes
[MAKE_PAIR64(loguid
,instance
)]; }
807 void SaveGORespawnTime(uint32 loguid
, uint32 instance
, time_t t
);
808 void DeleteRespawnTimeForInstance(uint32 instance
);
811 void AddCreatureToGrid(uint32 guid
, CreatureData
const* data
);
812 void RemoveCreatureFromGrid(uint32 guid
, CreatureData
const* data
);
813 void AddGameobjectToGrid(uint32 guid
, GameObjectData
const* data
);
814 void RemoveGameobjectFromGrid(uint32 guid
, GameObjectData
const* data
);
817 void LoadReservedPlayersNames();
818 bool IsReservedName(const std::string
& name
) const;
820 // name with valid structure and symbols
821 static uint8
CheckPlayerName( const std::string
& name
, bool create
= false );
822 static PetNameInvalidReason
CheckPetName( const std::string
& name
);
823 static bool IsValidCharterName( const std::string
& name
);
825 static bool CheckDeclinedNames(std::wstring mainpart
, DeclinedName
const& names
);
827 int GetIndexForLocale(LocaleConstant loc
);
828 LocaleConstant
GetLocaleForIndex(int i
);
830 uint16
GetConditionId(ConditionType condition
, uint32 value1
, uint32 value2
);
831 bool IsPlayerMeetToCondition(Player
const* player
, uint16 condition_id
) const
833 if(condition_id
>= mConditions
.size())
836 return mConditions
[condition_id
].Meets(player
);
839 GameTele
const* GetGameTele(uint32 id
) const
841 GameTeleMap::const_iterator itr
= m_GameTeleMap
.find(id
);
842 if(itr
==m_GameTeleMap
.end()) return NULL
;
845 GameTele
const* GetGameTele(const std::string
& name
) const;
846 GameTeleMap
const& GetGameTeleMap() const { return m_GameTeleMap
; }
847 bool AddGameTele(GameTele
& data
);
848 bool DeleteGameTele(const std::string
& name
);
850 uint32
GetNpcGossip(uint32 entry
) const
852 CacheNpcTextIdMap::const_iterator iter
= m_mCacheNpcTextIdMap
.find(entry
);
853 if(iter
== m_mCacheNpcTextIdMap
.end())
859 TrainerSpellData
const* GetNpcTrainerSpells(uint32 entry
) const
861 CacheTrainerSpellMap::const_iterator iter
= m_mCacheTrainerSpellMap
.find(entry
);
862 if(iter
== m_mCacheTrainerSpellMap
.end())
865 return &iter
->second
;
868 VendorItemData
const* GetNpcVendorItemList(uint32 entry
) const
870 CacheVendorItemMap::const_iterator iter
= m_mCacheVendorItemMap
.find(entry
);
871 if(iter
== m_mCacheVendorItemMap
.end())
874 return &iter
->second
;
876 void AddVendorItem(uint32 entry
,uint32 item
, uint32 maxcount
, uint32 incrtime
, uint32 ExtendedCost
);
877 bool RemoveVendorItem(uint32 entry
,uint32 item
);
878 bool IsVendorItemValid( uint32 vendor_entry
, uint32 item
, uint32 maxcount
, uint32 ptime
, uint32 ExtendedCost
, Player
* pl
= NULL
, std::set
<uint32
>* skip_vendors
= NULL
) const;
880 void LoadScriptNames();
881 ScriptNameMap
&GetScriptNames() { return m_scriptNames
; }
882 const char * GetScriptName(uint32 id
) { return id
< m_scriptNames
.size() ? m_scriptNames
[id
].c_str() : ""; }
883 uint32
GetScriptId(const char *name
);
885 int GetOrNewIndexForLocale(LocaleConstant loc
);
887 SpellClickInfoMapBounds
GetSpellClickInfoMapBounds(uint32 creature_id
) const
889 return SpellClickInfoMapBounds(mSpellClickInfoMap
.lower_bound(creature_id
),mSpellClickInfoMap
.upper_bound(creature_id
));
892 ItemRequiredTargetMapBounds
GetItemRequiredTargetMapBounds(uint32 uiItemEntry
) const
894 return ItemRequiredTargetMapBounds(m_ItemRequiredTarget
.lower_bound(uiItemEntry
),m_ItemRequiredTarget
.upper_bound(uiItemEntry
));
897 GossipMenusMapBounds
GetGossipMenusMapBounds(uint32 uiMenuId
) const
899 return GossipMenusMapBounds(m_mGossipMenusMap
.lower_bound(uiMenuId
),m_mGossipMenusMap
.upper_bound(uiMenuId
));
902 GossipMenuItemsMapBounds
GetGossipMenuItemsMapBounds(uint32 uiMenuId
) const
904 return GossipMenuItemsMapBounds(m_mGossipMenuItemsMap
.lower_bound(uiMenuId
),m_mGossipMenuItemsMap
.upper_bound(uiMenuId
));
909 // first free id for selected id type
910 IdGenerator
<uint32
> m_ArenaTeamIds
;
911 IdGenerator
<uint32
> m_AuctionIds
;
912 IdGenerator
<uint64
> m_EquipmentSetIds
;
913 IdGenerator
<uint32
> m_GuildIds
;
914 IdGenerator
<uint32
> m_ItemTextIds
;
915 IdGenerator
<uint32
> m_MailIds
;
916 IdGenerator
<uint32
> m_PetNumbers
;
917 IdGenerator
<uint32
> m_GroupIds
;
919 // first free low guid for selected guid type
920 ObjectGuidGenerator
<HIGHGUID_PLAYER
> m_CharGuids
;
921 ObjectGuidGenerator
<HIGHGUID_UNIT
> m_CreatureGuids
;
922 ObjectGuidGenerator
<HIGHGUID_ITEM
> m_ItemGuids
;
923 ObjectGuidGenerator
<HIGHGUID_GAMEOBJECT
> m_GameobjectGuids
;
924 ObjectGuidGenerator
<HIGHGUID_CORPSE
> m_CorpseGuids
;
926 QuestMap mQuestTemplates
;
928 typedef UNORDERED_MAP
<uint32
, GossipText
> GossipTextMap
;
929 typedef UNORDERED_MAP
<uint32
, uint32
> QuestAreaTriggerMap
;
930 typedef UNORDERED_MAP
<uint32
, std::string
> ItemTextMap
;
931 typedef std::set
<uint32
> TavernAreaTriggerSet
;
932 typedef std::set
<uint32
> GameObjectForQuestSet
;
936 ArenaTeamMap mArenaTeamMap
;
938 ItemTextMap mItemTexts
;
940 QuestAreaTriggerMap mQuestAreaTriggerMap
;
941 TavernAreaTriggerSet mTavernAreaTriggerSet
;
942 GameObjectForQuestSet mGameObjectForQuestSet
;
943 GossipTextMap mGossipText
;
944 AreaTriggerMap mAreaTriggers
;
945 AreaTriggerScriptMap mAreaTriggerScripts
;
947 RepOnKillMap mRepOnKill
;
949 GossipMenusMap m_mGossipMenusMap
;
950 GossipMenuItemsMap m_mGossipMenuItemsMap
;
951 PointOfInterestMap mPointsOfInterest
;
953 QuestPOIMap mQuestPOIMap
;
955 WeatherZoneMap mWeatherZoneMap
;
957 //character reserved names
958 typedef std::set
<std::wstring
> ReservedNamesMap
;
959 ReservedNamesMap m_ReservedNames
;
961 GraveYardMap mGraveYardMap
;
963 GameTeleMap m_GameTeleMap
;
965 ScriptNameMap m_scriptNames
;
967 SpellClickInfoMap mSpellClickInfoMap
;
969 ItemRequiredTargetMap m_ItemRequiredTarget
;
971 typedef std::vector
<LocaleConstant
> LocalForIndex
;
972 LocalForIndex m_LocalForIndex
;
977 void LoadScripts(ScriptMapMap
& scripts
, char const* tablename
);
978 void CheckScripts(ScriptMapMap
const& scripts
,std::set
<int32
>& ids
);
979 void LoadCreatureAddons(SQLStorage
& creatureaddons
, char const* entryName
, char const* comment
);
980 void ConvertCreatureAddonAuras(CreatureDataAddon
* addon
, char const* table
, char const* guidEntryStr
);
981 void LoadQuestRelationsHelper(QuestRelations
& map
,char const* table
);
983 MailLevelRewardMap m_mailLevelRewardMap
;
985 typedef std::map
<uint32
,PetLevelInfo
*> PetLevelInfoMap
;
986 // PetLevelInfoMap[creature_id][level]
987 PetLevelInfoMap petInfo
; // [creature_id][level]
989 PlayerClassInfo playerClassInfo
[MAX_CLASSES
];
991 void BuildPlayerLevelInfo(uint8 race
, uint8 class_
, uint8 level
, PlayerLevelInfo
* plinfo
) const;
992 PlayerInfo playerInfo
[MAX_RACES
][MAX_CLASSES
];
994 typedef std::vector
<uint32
> PlayerXPperLevel
; // [level]
995 PlayerXPperLevel mPlayerXPperLevel
;
997 typedef std::map
<uint32
,uint32
> BaseXPMap
; // [area level][base xp]
998 BaseXPMap mBaseXPTable
;
1000 typedef std::map
<uint32
,int32
> FishingBaseSkillMap
; // [areaId][base skill level]
1001 FishingBaseSkillMap mFishingBaseForArea
;
1003 typedef std::map
<uint32
,std::vector
<std::string
> > HalfNameMap
;
1004 HalfNameMap PetHalfName0
;
1005 HalfNameMap PetHalfName1
;
1007 MapObjectGuids mMapObjectGuids
;
1008 CreatureDataMap mCreatureDataMap
;
1009 CreatureLocaleMap mCreatureLocaleMap
;
1010 GameObjectDataMap mGameObjectDataMap
;
1011 GameObjectLocaleMap mGameObjectLocaleMap
;
1012 ItemLocaleMap mItemLocaleMap
;
1013 QuestLocaleMap mQuestLocaleMap
;
1014 NpcTextLocaleMap mNpcTextLocaleMap
;
1015 PageTextLocaleMap mPageTextLocaleMap
;
1016 MangosStringLocaleMap mMangosStringLocaleMap
;
1017 GossipMenuItemsLocaleMap mGossipMenuItemsLocaleMap
;
1018 PointOfInterestLocaleMap mPointOfInterestLocaleMap
;
1019 RespawnTimes mCreatureRespawnTimes
;
1020 RespawnTimes mGORespawnTimes
;
1022 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
1023 typedef std::vector
<PlayerCondition
> ConditionStore
;
1024 ConditionStore mConditions
;
1026 CacheNpcTextIdMap m_mCacheNpcTextIdMap
;
1027 CacheVendorItemMap m_mCacheVendorItemMap
;
1028 CacheTrainerSpellMap m_mCacheTrainerSpellMap
;
1031 #define sObjectMgr MaNGOS::Singleton<ObjectMgr>::Instance()
1033 // scripting access functions
1034 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());
1035 MANGOS_DLL_SPEC uint32
GetAreaTriggerScriptId(uint32 trigger_id
);
1036 MANGOS_DLL_SPEC uint32
GetScriptId(const char *name
);
1037 MANGOS_DLL_SPEC
ObjectMgr::ScriptNameMap
& GetScriptNames();
1038 MANGOS_DLL_SPEC CreatureInfo
const* GetCreatureTemplateStore(uint32 entry
);
1039 MANGOS_DLL_SPEC Quest
const* GetQuestTemplateStore(uint32 entry
);