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
27 #include "GameObject.h"
31 #include "ItemPrototype.h"
32 #include "NPCHandler.h"
33 #include "Database/DatabaseEnv.h"
36 #include "ObjectAccessor.h"
37 #include "ObjectDefines.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
;
252 #define WEATHER_SEASONS 4
253 struct WeatherSeasonChances
260 struct WeatherZoneChances
262 WeatherSeasonChances data
[WEATHER_SEASONS
];
270 typedef std::multimap
<uint32
,GraveYardData
> GraveYardMap
;
273 { // value1 value2 for the Condition enumed
274 CONDITION_NONE
= 0, // 0 0
275 CONDITION_AURA
= 1, // spell_id effindex
276 CONDITION_ITEM
= 2, // item_id count
277 CONDITION_ITEM_EQUIPPED
= 3, // item_id 0
278 CONDITION_ZONEID
= 4, // zone_id 0
279 CONDITION_REPUTATION_RANK
= 5, // faction_id min_rank
280 CONDITION_TEAM
= 6, // player_team 0, (469 - Alliance 67 - Horde)
281 CONDITION_SKILL
= 7, // skill_id skill_value
282 CONDITION_QUESTREWARDED
= 8, // quest_id 0
283 CONDITION_QUESTTAKEN
= 9, // quest_id 0, for condition true while quest active.
284 CONDITION_AD_COMMISSION_AURA
= 10, // 0 0, for condition true while one from AD commission aura active
285 CONDITION_NO_AURA
= 11, // spell_id effindex
286 CONDITION_ACTIVE_EVENT
= 12, // event_id 0
287 CONDITION_AREA_FLAG
= 13, // area_flag area_flag_not
288 CONDITION_RACE_CLASS
= 14, // race_mask class_mask
291 #define MAX_CONDITION 15 // maximum value in ConditionType enum
293 struct PlayerCondition
295 ConditionType condition
; // additional condition type
296 uint32 value1
; // data for the condition - see ConditionType definition
299 PlayerCondition(uint8 _condition
= 0, uint32 _value1
= 0, uint32 _value2
= 0)
300 : condition(ConditionType(_condition
)), value1(_value1
), value2(_value2
) {}
302 static bool IsValid(ConditionType condition
, uint32 value1
, uint32 value2
);
303 // Checks correctness of values
304 bool Meets(Player
const * APlayer
) const; // Checks if the player meets the condition
305 bool operator == (PlayerCondition
const& lc
) const
307 return (lc
.condition
== condition
&& lc
.value1
== value1
&& lc
.value2
== value2
);
311 // NPC gossip text id
312 typedef UNORDERED_MAP
<uint32
, uint32
> CacheNpcTextIdMap
;
314 typedef UNORDERED_MAP
<uint32
, VendorItemData
> CacheVendorItemMap
;
315 typedef UNORDERED_MAP
<uint32
, TrainerSpellData
> CacheTrainerSpellMap
;
319 SKILL_RANGE_LANGUAGE
, // 300..300
320 SKILL_RANGE_LEVEL
, // 1..max skill for level
321 SKILL_RANGE_MONO
, // 1..1, grey monolite bar
322 SKILL_RANGE_RANK
, // 1..skill for known rank
323 SKILL_RANGE_NONE
, // 0..0 always
326 SkillRangeType
GetSkillRangeType(SkillLineEntry
const *pSkill
, bool racial
);
328 #define MAX_PLAYER_NAME 12 // max allowed by client name length
329 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
330 #define MAX_PET_NAME 12 // max allowed by client name length
331 #define MAX_CHARTER_NAME 24 // max allowed by client name length
333 bool normalizePlayerName(std::string
& name
);
335 struct MANGOS_DLL_SPEC LanguageDesc
342 extern LanguageDesc lang_description
[LANGUAGES_COUNT
];
343 MANGOS_DLL_SPEC LanguageDesc
const* GetLanguageDescByID(uint32 lang
);
345 class PlayerDumpReader
;
349 friend class PlayerDumpReader
;
355 typedef UNORDERED_MAP
<uint32
, Item
*> ItemMap
;
357 typedef std::set
< Group
* > GroupSet
;
359 typedef UNORDERED_MAP
<uint32
, Guild
*> GuildMap
;
361 typedef UNORDERED_MAP
<uint32
, ArenaTeam
*> ArenaTeamMap
;
363 typedef UNORDERED_MAP
<uint32
, Quest
*> QuestMap
;
365 typedef UNORDERED_MAP
<uint32
, AreaTrigger
> AreaTriggerMap
;
367 typedef UNORDERED_MAP
<uint32
, uint32
> AreaTriggerScriptMap
;
369 typedef UNORDERED_MAP
<uint32
, ReputationOnKillEntry
> RepOnKillMap
;
370 typedef UNORDERED_MAP
<uint32
, PointOfInterest
> PointOfInterestMap
;
372 typedef UNORDERED_MAP
<uint32
, WeatherZoneChances
> WeatherZoneMap
;
374 typedef std::vector
<std::string
> ScriptNameMap
;
376 Player
* GetPlayer(const char* name
) const { return ObjectAccessor::FindPlayerByName(name
);}
377 Player
* GetPlayer(uint64 guid
) const { return ObjectAccessor::FindPlayer(guid
); }
379 static GameObjectInfo
const *GetGameObjectInfo(uint32 id
) { return sGOStorage
.LookupEntry
<GameObjectInfo
>(id
); }
381 void LoadGameobjectInfo();
382 void AddGameobjectInfo(GameObjectInfo
*goinfo
);
384 Group
* GetGroupByLeader(const uint64
&guid
) const;
385 void AddGroup(Group
* group
) { mGroupSet
.insert( group
); }
386 void RemoveGroup(Group
* group
) { mGroupSet
.erase( group
); }
388 Guild
* GetGuildByLeader(uint64
const&guid
) const;
389 Guild
* GetGuildById(uint32 GuildId
) const;
390 Guild
* GetGuildByName(const std::string
& guildname
) const;
391 std::string
GetGuildNameById(uint32 GuildId
) const;
392 void AddGuild(Guild
* guild
);
393 void RemoveGuild(uint32 Id
);
395 ArenaTeam
* GetArenaTeamById(uint32 arenateamid
) const;
396 ArenaTeam
* GetArenaTeamByName(const std::string
& arenateamname
) const;
397 ArenaTeam
* GetArenaTeamByCaptain(uint64
const& guid
) const;
398 void AddArenaTeam(ArenaTeam
* arenaTeam
);
399 void RemoveArenaTeam(uint32 Id
);
400 ArenaTeamMap::iterator
GetArenaTeamMapBegin() { return mArenaTeamMap
.begin(); }
401 ArenaTeamMap::iterator
GetArenaTeamMapEnd() { return mArenaTeamMap
.end(); }
403 static CreatureInfo
const *GetCreatureTemplate( uint32 id
);
404 CreatureModelInfo
const *GetCreatureModelInfo( uint32 modelid
);
405 CreatureModelInfo
const* GetCreatureModelRandomGender(uint32 display_id
);
406 uint32
ChooseDisplayId(uint32 team
, const CreatureInfo
*cinfo
, const CreatureData
*data
= NULL
);
407 EquipmentInfo
const *GetEquipmentInfo( uint32 entry
);
408 static CreatureDataAddon
const *GetCreatureAddon( uint32 lowguid
)
410 return sCreatureDataAddonStorage
.LookupEntry
<CreatureDataAddon
>(lowguid
);
413 static CreatureDataAddon
const *GetCreatureTemplateAddon( uint32 entry
)
415 return sCreatureInfoAddonStorage
.LookupEntry
<CreatureDataAddon
>(entry
);
418 static ItemPrototype
const* GetItemPrototype(uint32 id
) { return sItemStorage
.LookupEntry
<ItemPrototype
>(id
); }
420 static InstanceTemplate
const* GetInstanceTemplate(uint32 map
)
422 return sInstanceTemplate
.LookupEntry
<InstanceTemplate
>(map
);
425 PetLevelInfo
const* GetPetLevelInfo(uint32 creature_id
, uint32 level
) const;
427 PlayerClassInfo
const* GetPlayerClassInfo(uint32 class_
) const
429 if(class_
>= MAX_CLASSES
) return NULL
;
430 return &playerClassInfo
[class_
];
432 void GetPlayerClassLevelInfo(uint32 class_
,uint32 level
, PlayerClassLevelInfo
* info
) const;
434 PlayerInfo
const* GetPlayerInfo(uint32 race
, uint32 class_
) const
436 if(race
>= MAX_RACES
) return NULL
;
437 if(class_
>= MAX_CLASSES
) return NULL
;
438 PlayerInfo
const* info
= &playerInfo
[race
][class_
];
439 if(info
->displayId_m
==0 || info
->displayId_f
==0) return NULL
;
442 void GetPlayerLevelInfo(uint32 race
, uint32 class_
,uint32 level
, PlayerLevelInfo
* info
) const;
444 uint64
GetPlayerGUIDByName(std::string name
) const;
445 bool GetPlayerNameByGUID(const uint64
&guid
, std::string
&name
) const;
446 uint32
GetPlayerTeamByGUID(const uint64
&guid
) const;
447 uint32
GetPlayerAccountIdByGUID(const uint64
&guid
) const;
448 uint32
GetPlayerAccountIdByPlayerName(const std::string
& name
) const;
450 uint32
GetNearestTaxiNode( float x
, float y
, float z
, uint32 mapid
, uint32 team
);
451 void GetTaxiPath( uint32 source
, uint32 destination
, uint32
&path
, uint32
&cost
);
452 uint32
GetTaxiMountDisplayId( uint32 id
, uint32 team
, bool allowed_alt_team
= false);
453 void GetTaxiPathNodes( uint32 path
, Path
&pathnodes
, std::vector
<uint32
>& mapIds
);
454 void GetTransportPathNodes( uint32 path
, TransportPath
&pathnodes
);
456 Quest
const* GetQuestTemplate(uint32 quest_id
) const
458 QuestMap::const_iterator itr
= mQuestTemplates
.find(quest_id
);
459 return itr
!= mQuestTemplates
.end() ? itr
->second
: NULL
;
461 QuestMap
const& GetQuestTemplates() const { return mQuestTemplates
; }
463 uint32
GetQuestForAreaTrigger(uint32 Trigger_ID
) const
465 QuestAreaTriggerMap::const_iterator itr
= mQuestAreaTriggerMap
.find(Trigger_ID
);
466 if(itr
!= mQuestAreaTriggerMap
.end())
470 bool IsTavernAreaTrigger(uint32 Trigger_ID
) const
472 return mTavernAreaTriggerSet
.find(Trigger_ID
) != mTavernAreaTriggerSet
.end();
475 bool IsGameObjectForQuests(uint32 entry
) const
477 return mGameObjectForQuestSet
.find(entry
) != mGameObjectForQuestSet
.end();
480 GossipText
const* GetGossipText(uint32 Text_ID
) const;
482 WorldSafeLocsEntry
const *GetClosestGraveYard(float x
, float y
, float z
, uint32 MapId
, uint32 team
);
483 bool AddGraveYardLink(uint32 id
, uint32 zone
, uint32 team
, bool inDB
= true);
484 void LoadGraveyardZones();
485 GraveYardData
const* FindGraveYardData(uint32 id
, uint32 zone
);
487 AreaTrigger
const* GetAreaTrigger(uint32 trigger
) const
489 AreaTriggerMap::const_iterator itr
= mAreaTriggers
.find( trigger
);
490 if( itr
!= mAreaTriggers
.end( ) )
495 AreaTrigger
const* GetGoBackTrigger(uint32 Map
) const;
496 AreaTrigger
const* GetMapEntranceTrigger(uint32 Map
) const;
498 uint32
GetAreaTriggerScriptId(uint32 trigger_id
);
500 ReputationOnKillEntry
const* GetReputationOnKilEntry(uint32 id
) const
502 RepOnKillMap::const_iterator itr
= mRepOnKill
.find(id
);
503 if(itr
!= mRepOnKill
.end())
508 PointOfInterest
const* GetPointOfInterest(uint32 id
) const
510 PointOfInterestMap::const_iterator itr
= mPointsOfInterest
.find(id
);
511 if(itr
!= mPointsOfInterest
.end())
517 void LoadArenaTeams();
520 void LoadQuestRelations()
522 LoadGameobjectQuestRelations();
523 LoadGameobjectInvolvedRelations();
524 LoadCreatureQuestRelations();
525 LoadCreatureInvolvedRelations();
527 void LoadGameobjectQuestRelations();
528 void LoadGameobjectInvolvedRelations();
529 void LoadCreatureQuestRelations();
530 void LoadCreatureInvolvedRelations();
532 QuestRelations mGOQuestRelations
;
533 QuestRelations mGOQuestInvolvedRelations
;
534 QuestRelations mCreatureQuestRelations
;
535 QuestRelations mCreatureQuestInvolvedRelations
;
537 void LoadGameObjectScripts();
538 void LoadQuestEndScripts();
539 void LoadQuestStartScripts();
540 void LoadEventScripts();
541 void LoadSpellScripts();
542 void LoadGossipScripts();
544 bool LoadMangosStrings(DatabaseType
& db
, char const* table
, int32 min_value
, int32 max_value
);
545 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase
,"mangos_string",MIN_MANGOS_STRING_ID
,MAX_MANGOS_STRING_ID
); }
546 void LoadDbScriptStrings();
547 void LoadCreatureLocales();
548 void LoadCreatureTemplates();
549 void LoadCreatures();
550 void LoadCreatureRespawnTimes();
551 void LoadCreatureAddons();
552 void LoadCreatureModelInfo();
553 void LoadEquipmentTemplates();
554 void LoadGameObjectLocales();
555 void LoadGameobjects();
556 void LoadGameobjectRespawnTimes();
557 void LoadItemPrototypes();
558 void LoadItemRequiredTarget();
559 void LoadItemLocales();
560 void LoadQuestLocales();
561 void LoadNpcTextLocales();
562 void LoadPageTextLocales();
563 void LoadGossipMenuItemsLocales();
564 void LoadPointOfInterestLocales();
565 void LoadInstanceTemplate();
566 void LoadMailLevelRewards();
568 void LoadGossipText();
570 void LoadAreaTriggerTeleports();
571 void LoadQuestAreaTriggers();
572 void LoadAreaTriggerScripts();
573 void LoadTavernAreaTriggers();
574 void LoadGameObjectForQuests();
576 void LoadItemTexts();
577 void LoadPageTexts();
579 void LoadPlayerInfo();
580 void LoadPetLevelInfo();
581 void LoadExplorationBaseXP();
583 void LoadPetNumber();
585 void LoadFishingBaseSkillLevel();
587 void LoadReputationOnKill();
588 void LoadPointsOfInterest();
590 void LoadNPCSpellClickSpells();
592 void LoadWeatherZoneChances();
595 void LoadNpcTextId();
597 void LoadGossipMenu();
598 void LoadGossipMenuItems();
601 void LoadTrainerSpell();
603 std::string
GeneratePetName(uint32 entry
);
604 uint32
GetBaseXP(uint32 level
);
605 uint32
GetXPForLevel(uint32 level
);
607 int32
GetFishingBaseSkillLevel(uint32 entry
) const
609 FishingBaseSkillMap::const_iterator itr
= mFishingBaseForArea
.find(entry
);
610 return itr
!= mFishingBaseForArea
.end() ? itr
->second
: 0;
613 void ReturnOrDeleteOldMails(bool serverUp
);
615 void SetHighestGuids();
616 uint32
GenerateLowGuid(HighGuid guidhigh
);
617 uint32
GenerateArenaTeamId();
618 uint32
GenerateAuctionID();
619 uint64
GenerateEquipmentSetGuid();
620 uint32
GenerateGuildId();
621 uint32
GenerateItemTextID();
622 uint32
GenerateMailID();
623 uint32
GeneratePetNumber();
625 uint32
CreateItemText(std::string text
);
626 void AddItemText(uint32 itemTextId
, std::string text
) { mItemTexts
[itemTextId
] = text
; }
627 std::string
GetItemText( uint32 id
)
629 ItemTextMap::const_iterator itr
= mItemTexts
.find( id
);
630 if ( itr
!= mItemTexts
.end() )
633 return "There is no info for this item";
636 typedef std::multimap
<int32
, uint32
> ExclusiveQuestGroups
;
637 ExclusiveQuestGroups mExclusiveQuestGroups
;
639 MailLevelReward
const* GetMailLevelReward(uint32 level
,uint32 raceMask
)
641 MailLevelRewardMap::const_iterator map_itr
= m_mailLevelRewardMap
.find(level
);
642 if (map_itr
== m_mailLevelRewardMap
.end())
645 for(MailLevelRewardList::const_iterator set_itr
= map_itr
->second
.begin(); set_itr
!= map_itr
->second
.end(); ++set_itr
)
646 if (set_itr
->raceMask
& raceMask
)
652 WeatherZoneChances
const* GetWeatherChances(uint32 zone_id
) const
654 WeatherZoneMap::const_iterator itr
= mWeatherZoneMap
.find(zone_id
);
655 if(itr
!= mWeatherZoneMap
.end())
661 CellObjectGuids
const& GetCellObjectGuids(uint16 mapid
, uint8 spawnMode
, uint32 cell_id
)
663 return mMapObjectGuids
[MAKE_PAIR32(mapid
,spawnMode
)][cell_id
];
666 CreatureData
const* GetCreatureData(uint32 guid
) const
668 CreatureDataMap::const_iterator itr
= mCreatureDataMap
.find(guid
);
669 if(itr
==mCreatureDataMap
.end()) return NULL
;
672 CreatureData
& NewOrExistCreatureData(uint32 guid
) { return mCreatureDataMap
[guid
]; }
673 void DeleteCreatureData(uint32 guid
);
674 CreatureLocale
const* GetCreatureLocale(uint32 entry
) const
676 CreatureLocaleMap::const_iterator itr
= mCreatureLocaleMap
.find(entry
);
677 if(itr
==mCreatureLocaleMap
.end()) return NULL
;
680 GameObjectLocale
const* GetGameObjectLocale(uint32 entry
) const
682 GameObjectLocaleMap::const_iterator itr
= mGameObjectLocaleMap
.find(entry
);
683 if(itr
==mGameObjectLocaleMap
.end()) return NULL
;
686 ItemLocale
const* GetItemLocale(uint32 entry
) const
688 ItemLocaleMap::const_iterator itr
= mItemLocaleMap
.find(entry
);
689 if(itr
==mItemLocaleMap
.end()) return NULL
;
692 QuestLocale
const* GetQuestLocale(uint32 entry
) const
694 QuestLocaleMap::const_iterator itr
= mQuestLocaleMap
.find(entry
);
695 if(itr
==mQuestLocaleMap
.end()) return NULL
;
698 NpcTextLocale
const* GetNpcTextLocale(uint32 entry
) const
700 NpcTextLocaleMap::const_iterator itr
= mNpcTextLocaleMap
.find(entry
);
701 if(itr
==mNpcTextLocaleMap
.end()) return NULL
;
704 PageTextLocale
const* GetPageTextLocale(uint32 entry
) const
706 PageTextLocaleMap::const_iterator itr
= mPageTextLocaleMap
.find(entry
);
707 if(itr
==mPageTextLocaleMap
.end()) return NULL
;
710 GossipMenuItemsLocale
const* GetGossipMenuItemsLocale(uint32 entry
) const
712 GossipMenuItemsLocaleMap::const_iterator itr
= mGossipMenuItemsLocaleMap
.find(entry
);
713 if(itr
==mGossipMenuItemsLocaleMap
.end()) return NULL
;
716 PointOfInterestLocale
const* GetPointOfInterestLocale(uint32 poi_id
) const
718 PointOfInterestLocaleMap::const_iterator itr
= mPointOfInterestLocaleMap
.find(poi_id
);
719 if(itr
==mPointOfInterestLocaleMap
.end()) return NULL
;
723 GameObjectData
const* GetGOData(uint32 guid
) const
725 GameObjectDataMap::const_iterator itr
= mGameObjectDataMap
.find(guid
);
726 if(itr
==mGameObjectDataMap
.end()) return NULL
;
729 GameObjectData
& NewGOData(uint32 guid
) { return mGameObjectDataMap
[guid
]; }
730 void DeleteGOData(uint32 guid
);
732 MangosStringLocale
const* GetMangosStringLocale(int32 entry
) const
734 MangosStringLocaleMap::const_iterator itr
= mMangosStringLocaleMap
.find(entry
);
735 if(itr
==mMangosStringLocaleMap
.end()) return NULL
;
738 const char *GetMangosString(int32 entry
, int locale_idx
) const;
739 const char *GetMangosStringForDBCLocale(int32 entry
) const { return GetMangosString(entry
,DBCLocaleIndex
); }
740 int32
GetDBCLocaleIndex() const { return DBCLocaleIndex
; }
741 void SetDBCLocaleIndex(uint32 lang
) { DBCLocaleIndex
= GetIndexForLocale(LocaleConstant(lang
)); }
743 void AddCorpseCellData(uint32 mapid
, uint32 cellid
, uint32 player_guid
, uint32 instance
);
744 void DeleteCorpseCellData(uint32 mapid
, uint32 cellid
, uint32 player_guid
);
746 time_t GetCreatureRespawnTime(uint32 loguid
, uint32 instance
) { return mCreatureRespawnTimes
[MAKE_PAIR64(loguid
,instance
)]; }
747 void SaveCreatureRespawnTime(uint32 loguid
, uint32 instance
, time_t t
);
748 time_t GetGORespawnTime(uint32 loguid
, uint32 instance
) { return mGORespawnTimes
[MAKE_PAIR64(loguid
,instance
)]; }
749 void SaveGORespawnTime(uint32 loguid
, uint32 instance
, time_t t
);
750 void DeleteRespawnTimeForInstance(uint32 instance
);
753 void AddCreatureToGrid(uint32 guid
, CreatureData
const* data
);
754 void RemoveCreatureFromGrid(uint32 guid
, CreatureData
const* data
);
755 void AddGameobjectToGrid(uint32 guid
, GameObjectData
const* data
);
756 void RemoveGameobjectFromGrid(uint32 guid
, GameObjectData
const* data
);
759 void LoadReservedPlayersNames();
760 bool IsReservedName(const std::string
& name
) const;
762 // name with valid structure and symbols
763 static uint8
CheckPlayerName( const std::string
& name
, bool create
= false );
764 static PetNameInvalidReason
CheckPetName( const std::string
& name
);
765 static bool IsValidCharterName( const std::string
& name
);
767 static bool CheckDeclinedNames(std::wstring mainpart
, DeclinedName
const& names
);
769 int GetIndexForLocale(LocaleConstant loc
);
770 LocaleConstant
GetLocaleForIndex(int i
);
772 uint16
GetConditionId(ConditionType condition
, uint32 value1
, uint32 value2
);
773 bool IsPlayerMeetToCondition(Player
const* player
, uint16 condition_id
) const
775 if(condition_id
>= mConditions
.size())
778 return mConditions
[condition_id
].Meets(player
);
781 GameTele
const* GetGameTele(uint32 id
) const
783 GameTeleMap::const_iterator itr
= m_GameTeleMap
.find(id
);
784 if(itr
==m_GameTeleMap
.end()) return NULL
;
787 GameTele
const* GetGameTele(const std::string
& name
) const;
788 GameTeleMap
const& GetGameTeleMap() const { return m_GameTeleMap
; }
789 bool AddGameTele(GameTele
& data
);
790 bool DeleteGameTele(const std::string
& name
);
792 uint32
GetNpcGossip(uint32 entry
) const
794 CacheNpcTextIdMap::const_iterator iter
= m_mCacheNpcTextIdMap
.find(entry
);
795 if(iter
== m_mCacheNpcTextIdMap
.end())
801 TrainerSpellData
const* GetNpcTrainerSpells(uint32 entry
) const
803 CacheTrainerSpellMap::const_iterator iter
= m_mCacheTrainerSpellMap
.find(entry
);
804 if(iter
== m_mCacheTrainerSpellMap
.end())
807 return &iter
->second
;
810 VendorItemData
const* GetNpcVendorItemList(uint32 entry
) const
812 CacheVendorItemMap::const_iterator iter
= m_mCacheVendorItemMap
.find(entry
);
813 if(iter
== m_mCacheVendorItemMap
.end())
816 return &iter
->second
;
818 void AddVendorItem(uint32 entry
,uint32 item
, uint32 maxcount
, uint32 incrtime
, uint32 ExtendedCost
);
819 bool RemoveVendorItem(uint32 entry
,uint32 item
);
820 bool IsVendorItemValid( uint32 vendor_entry
, uint32 item
, uint32 maxcount
, uint32 ptime
, uint32 ExtendedCost
, Player
* pl
= NULL
, std::set
<uint32
>* skip_vendors
= NULL
) const;
822 void LoadScriptNames();
823 ScriptNameMap
&GetScriptNames() { return m_scriptNames
; }
824 const char * GetScriptName(uint32 id
) { return id
< m_scriptNames
.size() ? m_scriptNames
[id
].c_str() : ""; }
825 uint32
GetScriptId(const char *name
);
827 int GetOrNewIndexForLocale(LocaleConstant loc
);
829 SpellClickInfoMapBounds
GetSpellClickInfoMapBounds(uint32 creature_id
) const
831 return SpellClickInfoMapBounds(mSpellClickInfoMap
.lower_bound(creature_id
),mSpellClickInfoMap
.upper_bound(creature_id
));
834 ItemRequiredTargetMapBounds
GetItemRequiredTargetMapBounds(uint32 uiItemEntry
) const
836 return ItemRequiredTargetMapBounds(m_ItemRequiredTarget
.lower_bound(uiItemEntry
),m_ItemRequiredTarget
.upper_bound(uiItemEntry
));
839 GossipMenusMapBounds
GetGossipMenusMapBounds(uint32 uiMenuId
) const
841 return GossipMenusMapBounds(m_mGossipMenusMap
.lower_bound(uiMenuId
),m_mGossipMenusMap
.upper_bound(uiMenuId
));
844 GossipMenuItemsMapBounds
GetGossipMenuItemsMapBounds(uint32 uiMenuId
) const
846 return GossipMenuItemsMapBounds(m_mGossipMenuItemsMap
.lower_bound(uiMenuId
),m_mGossipMenuItemsMap
.upper_bound(uiMenuId
));
851 // first free id for selected id type
852 uint32 m_arenaTeamId
;
854 uint64 m_equipmentSetGuid
;
858 uint32 m_hiPetNumber
;
860 // first free low guid for seelcted guid type
862 uint32 m_hiCreatureGuid
;
865 uint32 m_hiCorpseGuid
;
867 QuestMap mQuestTemplates
;
869 typedef UNORDERED_MAP
<uint32
, GossipText
> GossipTextMap
;
870 typedef UNORDERED_MAP
<uint32
, uint32
> QuestAreaTriggerMap
;
871 typedef UNORDERED_MAP
<uint32
, std::string
> ItemTextMap
;
872 typedef std::set
<uint32
> TavernAreaTriggerSet
;
873 typedef std::set
<uint32
> GameObjectForQuestSet
;
877 ArenaTeamMap mArenaTeamMap
;
879 ItemTextMap mItemTexts
;
881 QuestAreaTriggerMap mQuestAreaTriggerMap
;
882 TavernAreaTriggerSet mTavernAreaTriggerSet
;
883 GameObjectForQuestSet mGameObjectForQuestSet
;
884 GossipTextMap mGossipText
;
885 AreaTriggerMap mAreaTriggers
;
886 AreaTriggerScriptMap mAreaTriggerScripts
;
888 RepOnKillMap mRepOnKill
;
890 GossipMenusMap m_mGossipMenusMap
;
891 GossipMenuItemsMap m_mGossipMenuItemsMap
;
892 PointOfInterestMap mPointsOfInterest
;
894 WeatherZoneMap mWeatherZoneMap
;
896 //character reserved names
897 typedef std::set
<std::wstring
> ReservedNamesMap
;
898 ReservedNamesMap m_ReservedNames
;
900 GraveYardMap mGraveYardMap
;
902 GameTeleMap m_GameTeleMap
;
904 ScriptNameMap m_scriptNames
;
906 SpellClickInfoMap mSpellClickInfoMap
;
908 ItemRequiredTargetMap m_ItemRequiredTarget
;
910 typedef std::vector
<LocaleConstant
> LocalForIndex
;
911 LocalForIndex m_LocalForIndex
;
916 void LoadScripts(ScriptMapMap
& scripts
, char const* tablename
);
917 void CheckScripts(ScriptMapMap
const& scripts
,std::set
<int32
>& ids
);
918 void LoadCreatureAddons(SQLStorage
& creatureaddons
, char const* entryName
, char const* comment
);
919 void ConvertCreatureAddonAuras(CreatureDataAddon
* addon
, char const* table
, char const* guidEntryStr
);
920 void LoadQuestRelationsHelper(QuestRelations
& map
,char const* table
);
922 MailLevelRewardMap m_mailLevelRewardMap
;
924 typedef std::map
<uint32
,PetLevelInfo
*> PetLevelInfoMap
;
925 // PetLevelInfoMap[creature_id][level]
926 PetLevelInfoMap petInfo
; // [creature_id][level]
928 PlayerClassInfo playerClassInfo
[MAX_CLASSES
];
930 void BuildPlayerLevelInfo(uint8 race
, uint8 class_
, uint8 level
, PlayerLevelInfo
* plinfo
) const;
931 PlayerInfo playerInfo
[MAX_RACES
][MAX_CLASSES
];
933 typedef std::vector
<uint32
> PlayerXPperLevel
; // [level]
934 PlayerXPperLevel mPlayerXPperLevel
;
936 typedef std::map
<uint32
,uint32
> BaseXPMap
; // [area level][base xp]
937 BaseXPMap mBaseXPTable
;
939 typedef std::map
<uint32
,int32
> FishingBaseSkillMap
; // [areaId][base skill level]
940 FishingBaseSkillMap mFishingBaseForArea
;
942 typedef std::map
<uint32
,std::vector
<std::string
> > HalfNameMap
;
943 HalfNameMap PetHalfName0
;
944 HalfNameMap PetHalfName1
;
946 MapObjectGuids mMapObjectGuids
;
947 CreatureDataMap mCreatureDataMap
;
948 CreatureLocaleMap mCreatureLocaleMap
;
949 GameObjectDataMap mGameObjectDataMap
;
950 GameObjectLocaleMap mGameObjectLocaleMap
;
951 ItemLocaleMap mItemLocaleMap
;
952 QuestLocaleMap mQuestLocaleMap
;
953 NpcTextLocaleMap mNpcTextLocaleMap
;
954 PageTextLocaleMap mPageTextLocaleMap
;
955 MangosStringLocaleMap mMangosStringLocaleMap
;
956 GossipMenuItemsLocaleMap mGossipMenuItemsLocaleMap
;
957 PointOfInterestLocaleMap mPointOfInterestLocaleMap
;
958 RespawnTimes mCreatureRespawnTimes
;
959 RespawnTimes mGORespawnTimes
;
961 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
962 typedef std::vector
<PlayerCondition
> ConditionStore
;
963 ConditionStore mConditions
;
965 CacheNpcTextIdMap m_mCacheNpcTextIdMap
;
966 CacheVendorItemMap m_mCacheVendorItemMap
;
967 CacheTrainerSpellMap m_mCacheTrainerSpellMap
;
970 #define sObjectMgr MaNGOS::Singleton<ObjectMgr>::Instance()
972 // scripting access functions
973 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());
974 MANGOS_DLL_SPEC uint32
GetAreaTriggerScriptId(uint32 trigger_id
);
975 MANGOS_DLL_SPEC uint32
GetScriptId(const char *name
);
976 MANGOS_DLL_SPEC
ObjectMgr::ScriptNameMap
& GetScriptNames();
977 MANGOS_DLL_SPEC CreatureInfo
const* GetCreatureTemplateStore(uint32 entry
);
978 MANGOS_DLL_SPEC Quest
const* GetQuestTemplateStore(uint32 entry
);