2 * Copyright (C) 2005-2008 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 "DynamicObject.h"
28 #include "GameObject.h"
32 #include "ItemPrototype.h"
33 #include "NPCHandler.h"
34 #include "Database/DatabaseEnv.h"
35 #include "AuctionHouseObject.h"
38 #include "ObjectAccessor.h"
39 #include "ObjectDefines.h"
40 #include "Policies/Singleton.h"
41 #include "Database/SQLStorage.h"
47 extern SQLStorage sCreatureStorage
;
48 extern SQLStorage sCreatureDataAddonStorage
;
49 extern SQLStorage sCreatureInfoAddonStorage
;
50 extern SQLStorage sCreatureModelStorage
;
51 extern SQLStorage sEquipmentStorage
;
52 extern SQLStorage sGOStorage
;
53 extern SQLStorage sPageTextStore
;
54 extern SQLStorage sItemStorage
;
55 extern SQLStorage sInstanceTemplate
;
72 std::wstring wnameLow
;
75 typedef UNORDERED_MAP
<uint32
, GameTele
> GameTeleMap
;
91 typedef std::multimap
<uint32
, ScriptInfo
> ScriptMap
;
92 typedef std::map
<uint32
, ScriptMap
> ScriptMapMap
;
93 extern ScriptMapMap sQuestEndScripts
;
94 extern ScriptMapMap sQuestStartScripts
;
95 extern ScriptMapMap sSpellScripts
;
96 extern ScriptMapMap sGameObjectScripts
;
97 extern ScriptMapMap sEventScripts
;
103 uint32 requiredItem2
;
106 uint32 requiredQuest
;
107 std::string requiredFailedText
;
112 float target_Orientation
;
115 typedef std::set
<uint32
> CellGuidSet
;
116 typedef std::map
<uint32
/*player guid*/,uint32
/*instance*/> CellCorpseSet
;
117 struct CellObjectGuids
119 CellGuidSet creatures
;
120 CellGuidSet gameobjects
;
121 CellCorpseSet corpses
;
123 typedef UNORDERED_MAP
<uint32
/*cell_id*/,CellObjectGuids
> CellObjectGuidsMap
;
124 typedef UNORDERED_MAP
<uint32
/*(mapid,spawnMode) pair*/,CellObjectGuidsMap
> MapObjectGuids
;
126 typedef UNORDERED_MAP
<uint64
/*(instance,guid) pair*/,time_t> RespawnTimes
;
129 // mangos string ranges
130 #define MIN_MANGOS_STRING_ID 1
131 #define MAX_MANGOS_STRING_ID 2000000000
132 #define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID
133 #define MAX_DB_SCRIPT_STRING_ID 2000010000
135 struct MangosStringLocale
137 std::vector
<std::string
> Content
; // 0 -> default, i -> i-1 locale index
140 typedef UNORDERED_MAP
<uint32
,CreatureData
> CreatureDataMap
;
141 typedef UNORDERED_MAP
<uint32
,GameObjectData
> GameObjectDataMap
;
142 typedef UNORDERED_MAP
<uint32
,CreatureLocale
> CreatureLocaleMap
;
143 typedef UNORDERED_MAP
<uint32
,GameObjectLocale
> GameObjectLocaleMap
;
144 typedef UNORDERED_MAP
<uint32
,ItemLocale
> ItemLocaleMap
;
145 typedef UNORDERED_MAP
<uint32
,QuestLocale
> QuestLocaleMap
;
146 typedef UNORDERED_MAP
<uint32
,NpcTextLocale
> NpcTextLocaleMap
;
147 typedef UNORDERED_MAP
<uint32
,PageTextLocale
> PageTextLocaleMap
;
148 typedef UNORDERED_MAP
<uint32
,MangosStringLocale
> MangosStringLocaleMap
;
149 typedef UNORDERED_MAP
<uint32
,NpcOptionLocale
> NpcOptionLocaleMap
;
151 typedef std::multimap
<uint32
,uint32
> QuestRelations
;
155 PetLevelInfo() : health(0), mana(0) { for(int i
=0; i
< MAX_STATS
; ++i
) stats
[i
] = 0; }
157 uint16 stats
[MAX_STATS
];
163 struct ReputationOnKillEntry
168 uint32 reputation_max_cap1
;
171 uint32 reputation_max_cap2
;
176 struct PetCreateSpellEntry
181 #define WEATHER_SEASONS 4
182 struct WeatherSeasonChances
189 struct WeatherZoneChances
191 WeatherSeasonChances data
[WEATHER_SEASONS
];
199 typedef std::multimap
<uint32
,GraveYardData
> GraveYardMap
;
202 { // value1 value2 for the Condition enumed
203 CONDITION_NONE
= 0, // 0 0
204 CONDITION_AURA
= 1, // spell_id effindex
205 CONDITION_ITEM
= 2, // item_id count
206 CONDITION_ITEM_EQUIPPED
= 3, // item_id 0
207 CONDITION_ZONEID
= 4, // zone_id 0
208 CONDITION_REPUTATION_RANK
= 5, // faction_id min_rank
209 CONDITION_TEAM
= 6, // player_team 0, (469 - Alliance 67 - Horde)
210 CONDITION_SKILL
= 7, // skill_id skill_value
211 CONDITION_QUESTREWARDED
= 8, // quest_id 0
212 CONDITION_QUESTTAKEN
= 9, // quest_id 0, for condition true while quest active.
213 CONDITION_AD_COMMISSION_AURA
= 10, // 0 0, for condition true while one from AD ñommission aura active
214 CONDITION_NO_AURA
= 11, // spell_id effindex
215 CONDITION_ACTIVE_EVENT
= 12, // event_id
218 #define MAX_CONDITION 13 // maximum value in ConditionType enum
220 struct PlayerCondition
222 ConditionType condition
; // additional condition type
223 uint32 value1
; // data for the condition - see ConditionType definition
226 PlayerCondition(uint8 _condition
= 0, uint32 _value1
= 0, uint32 _value2
= 0)
227 : condition(ConditionType(_condition
)), value1(_value1
), value2(_value2
) {}
229 static bool IsValid(ConditionType condition
, uint32 value1
, uint32 value2
);
230 // Checks correctness of values
231 bool Meets(Player
const * APlayer
) const; // Checks if the player meets the condition
232 bool operator == (PlayerCondition
const& lc
) const
234 return (lc
.condition
== condition
&& lc
.value1
== value1
&& lc
.value2
== value2
);
238 // NPC gossip text id
239 typedef UNORDERED_MAP
<uint32
, uint32
> CacheNpcTextIdMap
;
240 typedef std::list
<GossipOption
> CacheNpcOptionList
;
242 typedef UNORDERED_MAP
<uint32
, VendorItemData
> CacheVendorItemMap
;
243 typedef UNORDERED_MAP
<uint32
, TrainerSpellData
> CacheTrainerSpellMap
;
245 typedef std::list
<const AchievementCriteriaEntry
*> AchievementCriteriaEntryList
;
249 SKILL_RANGE_LANGUAGE
, // 300..300
250 SKILL_RANGE_LEVEL
, // 1..max skill for level
251 SKILL_RANGE_MONO
, // 1..1, grey monolite bar
252 SKILL_RANGE_RANK
, // 1..skill for known rank
253 SKILL_RANGE_NONE
, // 0..0 always
256 SkillRangeType
GetSkillRangeType(SkillLineEntry
const *pSkill
, bool racial
);
258 #define MAX_PLAYER_NAME 12 // max allowed by client name length
259 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
261 bool normalizePlayerName(std::string
& name
);
263 struct MANGOS_DLL_SPEC LanguageDesc
270 extern LanguageDesc lang_description
[LANGUAGES_COUNT
];
271 MANGOS_DLL_SPEC LanguageDesc
const* GetLanguageDescByID(uint32 lang
);
273 class PlayerDumpReader
;
277 friend class PlayerDumpReader
;
283 typedef UNORDERED_MAP
<uint32
, Item
*> ItemMap
;
285 typedef std::set
< Group
* > GroupSet
;
286 typedef std::set
< Guild
* > GuildSet
;
287 typedef std::set
< ArenaTeam
* > ArenaTeamSet
;
289 typedef UNORDERED_MAP
<uint32
, Quest
*> QuestMap
;
292 typedef UNORDERED_MAP
<uint32
, AreaTrigger
> AreaTriggerMap
;
294 typedef UNORDERED_MAP
<uint32
, uint32
> AreaTriggerScriptMap
;
296 typedef UNORDERED_MAP
<uint32
, ReputationOnKillEntry
> RepOnKillMap
;
298 typedef UNORDERED_MAP
<uint32
, WeatherZoneChances
> WeatherZoneMap
;
300 typedef UNORDERED_MAP
<uint32
, PetCreateSpellEntry
> PetCreateSpellMap
;
302 typedef std::vector
<std::string
> ScriptNameMap
;
304 Player
* GetPlayer(const char* name
) const { return ObjectAccessor::Instance().FindPlayerByName(name
);}
305 Player
* GetPlayer(uint64 guid
) const { return ObjectAccessor::FindPlayer(guid
); }
307 static GameObjectInfo
const *GetGameObjectInfo(uint32 id
) { return sGOStorage
.LookupEntry
<GameObjectInfo
>(id
); }
309 void LoadGameobjectInfo();
310 void AddGameobjectInfo(GameObjectInfo
*goinfo
);
312 Group
* GetGroupByLeader(const uint64
&guid
) const;
313 void AddGroup(Group
* group
) { mGroupSet
.insert( group
); }
314 void RemoveGroup(Group
* group
) { mGroupSet
.erase( group
); }
316 Guild
* GetGuildByLeader(uint64
const&guid
) const;
317 Guild
* GetGuildById(const uint32 GuildId
) const;
318 Guild
* GetGuildByName(std::string guildname
) const;
319 std::string
GetGuildNameById(const uint32 GuildId
) const;
320 void AddGuild(Guild
* guild
) { mGuildSet
.insert( guild
); }
321 void RemoveGuild(Guild
* guild
) { mGuildSet
.erase( guild
); }
323 ArenaTeam
* GetArenaTeamById(const uint32 ArenaTeamId
) const;
324 ArenaTeam
* GetArenaTeamByName(std::string ArenaTeamName
) const;
325 ArenaTeam
* GetArenaTeamByCapitan(uint64
const& guid
) const;
326 void AddArenaTeam(ArenaTeam
* arenateam
) { mArenaTeamSet
.insert( arenateam
); }
327 void RemoveArenaTeam(ArenaTeam
* arenateam
) { mArenaTeamSet
.erase( arenateam
); }
329 static CreatureInfo
const *GetCreatureTemplate( uint32 id
);
330 CreatureModelInfo
const *GetCreatureModelInfo( uint32 modelid
);
331 CreatureModelInfo
const* GetCreatureModelRandomGender(uint32 display_id
);
332 uint32
ChooseDisplayId(uint32 team
, const CreatureInfo
*cinfo
, const CreatureData
*data
= NULL
);
333 EquipmentInfo
const *GetEquipmentInfo( uint32 entry
);
334 static CreatureDataAddon
const *GetCreatureAddon( uint32 lowguid
)
336 return sCreatureDataAddonStorage
.LookupEntry
<CreatureDataAddon
>(lowguid
);
339 static CreatureDataAddon
const *GetCreatureTemplateAddon( uint32 entry
)
341 return sCreatureInfoAddonStorage
.LookupEntry
<CreatureDataAddon
>(entry
);
344 static ItemPrototype
const* GetItemPrototype(uint32 id
) { return sItemStorage
.LookupEntry
<ItemPrototype
>(id
); }
346 static InstanceTemplate
const* GetInstanceTemplate(uint32 map
)
348 return sInstanceTemplate
.LookupEntry
<InstanceTemplate
>(map
);
351 Item
* GetAItem(uint32 id
)
353 ItemMap::const_iterator itr
= mAitems
.find(id
);
354 if (itr
!= mAitems
.end())
360 void AddAItem(Item
* it
)
363 ASSERT( mAitems
.find(it
->GetGUIDLow()) == mAitems
.end());
364 mAitems
[it
->GetGUIDLow()] = it
;
366 bool RemoveAItem(uint32 id
)
368 ItemMap::iterator i
= mAitems
.find(id
);
369 if (i
== mAitems
.end())
376 AuctionHouseObject
* GetAuctionsMap( uint32 location
);
379 void SendAuctionWonMail( AuctionEntry
* auction
);
380 void SendAuctionSalePendingMail( AuctionEntry
* auction
);
381 void SendAuctionSuccessfulMail( AuctionEntry
* auction
);
382 void SendAuctionExpiredMail( AuctionEntry
* auction
);
383 static uint32
GetAuctionCut( uint32 location
, uint32 highBid
);
384 static uint32
GetAuctionDeposit(uint32 location
, uint32 time
, Item
*pItem
);
385 static uint32
GetAuctionOutBid(uint32 currentBid
);
387 PetLevelInfo
const* GetPetLevelInfo(uint32 creature_id
, uint32 level
) const;
389 PlayerClassInfo
const* GetPlayerClassInfo(uint32 class_
) const
391 if(class_
>= MAX_CLASSES
) return NULL
;
392 return &playerClassInfo
[class_
];
394 void GetPlayerClassLevelInfo(uint32 class_
,uint32 level
, PlayerClassLevelInfo
* info
) const;
396 PlayerInfo
const* GetPlayerInfo(uint32 race
, uint32 class_
) const
398 if(race
>= MAX_RACES
) return NULL
;
399 if(class_
>= MAX_CLASSES
) return NULL
;
400 PlayerInfo
const* info
= &playerInfo
[race
][class_
];
401 if(info
->displayId_m
==0 || info
->displayId_f
==0) return NULL
;
404 void GetPlayerLevelInfo(uint32 race
, uint32 class_
,uint32 level
, PlayerLevelInfo
* info
) const;
406 uint64
GetPlayerGUIDByName(std::string name
) const;
407 bool GetPlayerNameByGUID(const uint64
&guid
, std::string
&name
) const;
408 uint32
GetPlayerTeamByGUID(const uint64
&guid
) const;
409 uint32
GetPlayerAccountIdByGUID(const uint64
&guid
) const;
410 uint32
GetPlayerAccountIdByPlayerName(std::string name
) const;
412 uint32
GetNearestTaxiNode( float x
, float y
, float z
, uint32 mapid
);
413 void GetTaxiPath( uint32 source
, uint32 destination
, uint32
&path
, uint32
&cost
);
414 uint16
GetTaxiMount( uint32 id
, uint32 team
);
415 void GetTaxiPathNodes( uint32 path
, Path
&pathnodes
, std::vector
<uint32
>& mapIds
);
416 void GetTransportPathNodes( uint32 path
, TransportPath
&pathnodes
);
418 Quest
const* GetQuestTemplate(uint32 quest_id
) const
420 QuestMap::const_iterator itr
= mQuestTemplates
.find(quest_id
);
421 return itr
!= mQuestTemplates
.end() ? itr
->second
: NULL
;
423 QuestMap
const& GetQuestTemplates() const { return mQuestTemplates
; }
425 uint32
GetQuestForAreaTrigger(uint32 Trigger_ID
) const
427 QuestAreaTriggerMap::const_iterator itr
= mQuestAreaTriggerMap
.find(Trigger_ID
);
428 if(itr
!= mQuestAreaTriggerMap
.end())
432 bool IsTavernAreaTrigger(uint32 Trigger_ID
) const { return mTavernAreaTriggerSet
.count(Trigger_ID
) != 0; }
433 bool IsGameObjectForQuests(uint32 entry
) const { return mGameObjectForQuestSet
.count(entry
) != 0; }
434 bool IsGuildVaultGameObject(Player
*player
, uint64 guid
) const
436 if(GameObject
*go
= ObjectAccessor::GetGameObject(*player
, guid
))
437 if(go
->GetGoType() == GAMEOBJECT_TYPE_GUILD_BANK
)
442 uint32
GetBattleMasterBG(uint32 entry
) const
444 BattleMastersMap::const_iterator itr
= mBattleMastersMap
.find(entry
);
445 if(itr
!= mBattleMastersMap
.end())
447 return 2; //BATTLEGROUND_WS - i will not add include only for constant usage!
450 void AddGossipText(GossipText
*pGText
);
451 GossipText
*GetGossipText(uint32 Text_ID
);
453 WorldSafeLocsEntry
const *GetClosestGraveYard(float x
, float y
, float z
, uint32 MapId
, uint32 team
);
454 bool AddGraveYardLink(uint32 id
, uint32 zone
, uint32 team
, bool inDB
= true);
455 void LoadGraveyardZones();
456 GraveYardData
const* FindGraveYardData(uint32 id
, uint32 zone
);
458 AreaTrigger
const* GetAreaTrigger(uint32 trigger
) const
460 AreaTriggerMap::const_iterator itr
= mAreaTriggers
.find( trigger
);
461 if( itr
!= mAreaTriggers
.end( ) )
466 AreaTrigger
const* GetGoBackTrigger(uint32 Map
) const;
468 uint32
GetAreaTriggerScriptId(uint32 trigger_id
);
470 ReputationOnKillEntry
const* GetReputationOnKilEntry(uint32 id
) const
472 RepOnKillMap::const_iterator itr
= mRepOnKill
.find(id
);
473 if(itr
!= mRepOnKill
.end())
478 PetCreateSpellEntry
const* GetPetCreateSpellEntry(uint32 id
) const
480 PetCreateSpellMap::const_iterator itr
= mPetCreateSpell
.find(id
);
481 if(itr
!= mPetCreateSpell
.end())
487 void LoadArenaTeams();
490 void LoadQuestRelations()
492 LoadGameobjectQuestRelations();
493 LoadGameobjectInvolvedRelations();
494 LoadCreatureQuestRelations();
495 LoadCreatureInvolvedRelations();
497 void LoadGameobjectQuestRelations();
498 void LoadGameobjectInvolvedRelations();
499 void LoadCreatureQuestRelations();
500 void LoadCreatureInvolvedRelations();
502 QuestRelations mGOQuestRelations
;
503 QuestRelations mGOQuestInvolvedRelations
;
504 QuestRelations mCreatureQuestRelations
;
505 QuestRelations mCreatureQuestInvolvedRelations
;
507 void LoadGameObjectScripts();
508 void LoadQuestEndScripts();
509 void LoadQuestStartScripts();
510 void LoadEventScripts();
511 void LoadSpellScripts();
513 bool LoadMangosStrings(DatabaseType
& db
, char const* table
, int32 min_value
, int32 max_value
);
514 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase
,"mangos_string",MIN_MANGOS_STRING_ID
,MAX_MANGOS_STRING_ID
); }
515 void LoadDbScriptStrings();
516 void LoadPetCreateSpells();
517 void LoadCreatureLocales();
518 void LoadCreatureTemplates();
519 void LoadCreatures();
520 void LoadCreatureRespawnTimes();
521 void LoadCreatureAddons();
522 void LoadCreatureModelInfo();
523 void LoadEquipmentTemplates();
524 void LoadGameObjectLocales();
525 void LoadGameobjects();
526 void LoadGameobjectRespawnTimes();
527 void LoadItemPrototypes();
528 void LoadItemLocales();
529 void LoadQuestLocales();
530 void LoadNpcTextLocales();
531 void LoadPageTextLocales();
532 void LoadNpcOptionLocales();
533 void LoadInstanceTemplate();
535 void LoadGossipText();
537 void LoadAreaTriggerTeleports();
538 void LoadQuestAreaTriggers();
539 void LoadAreaTriggerScripts();
540 void LoadTavernAreaTriggers();
541 void LoadBattleMastersEntry();
542 void LoadGameObjectForQuests();
544 void LoadItemTexts();
545 void LoadPageTexts();
547 //load first auction items, because of check if item exists, when loading
548 void LoadAuctionItems();
550 void LoadPlayerInfo();
551 void LoadPetLevelInfo();
552 void LoadExplorationBaseXP();
554 void LoadPetNumber();
556 void LoadFishingBaseSkillLevel();
558 void LoadReputationOnKill();
560 void LoadWeatherZoneChances();
563 void LoadNpcOptions();
564 void LoadNpcTextId();
566 void LoadTrainerSpell();
567 void LoadCompletedAchievements();
569 std::string
GeneratePetName(uint32 entry
);
570 uint32
GetBaseXP(uint32 level
);
572 int32
GetFishingBaseSkillLevel(uint32 entry
) const
574 FishingBaseSkillMap::const_iterator itr
= mFishingBaseForArea
.find(entry
);
575 return itr
!= mFishingBaseForArea
.end() ? itr
->second
: 0;
578 void ReturnOrDeleteOldMails(bool serverUp
);
580 void SetHighestGuids();
581 uint32
GenerateLowGuid(HighGuid guidhigh
);
582 uint32
GenerateAuctionID();
583 uint32
GenerateMailID();
584 uint32
GenerateItemTextID();
585 uint32
GeneratePetNumber();
586 uint32
GenerateArenaTeamId();
587 uint32
GenerateGuildId();
589 uint32
CreateItemText(std::string text
);
590 std::string
GetItemText( uint32 id
)
592 ItemTextMap::const_iterator itr
= mItemTexts
.find( id
);
593 if ( itr
!= mItemTexts
.end() )
596 return "There is no info for this item";
599 typedef std::multimap
<int32
, uint32
> ExclusiveQuestGroups
;
600 ExclusiveQuestGroups mExclusiveQuestGroups
;
602 WeatherZoneChances
const* GetWeatherChances(uint32 zone_id
) const
604 WeatherZoneMap::const_iterator itr
= mWeatherZoneMap
.find(zone_id
);
605 if(itr
!= mWeatherZoneMap
.end())
611 CellObjectGuids
const& GetCellObjectGuids(uint16 mapid
, uint8 spawnMode
, uint32 cell_id
)
613 return mMapObjectGuids
[MAKE_PAIR32(mapid
,spawnMode
)][cell_id
];
616 CreatureData
const* GetCreatureData(uint32 guid
) const
618 CreatureDataMap::const_iterator itr
= mCreatureDataMap
.find(guid
);
619 if(itr
==mCreatureDataMap
.end()) return NULL
;
622 CreatureData
& NewOrExistCreatureData(uint32 guid
) { return mCreatureDataMap
[guid
]; }
623 void DeleteCreatureData(uint32 guid
);
624 CreatureLocale
const* GetCreatureLocale(uint32 entry
) const
626 CreatureLocaleMap::const_iterator itr
= mCreatureLocaleMap
.find(entry
);
627 if(itr
==mCreatureLocaleMap
.end()) return NULL
;
630 GameObjectLocale
const* GetGameObjectLocale(uint32 entry
) const
632 GameObjectLocaleMap::const_iterator itr
= mGameObjectLocaleMap
.find(entry
);
633 if(itr
==mGameObjectLocaleMap
.end()) return NULL
;
636 ItemLocale
const* GetItemLocale(uint32 entry
) const
638 ItemLocaleMap::const_iterator itr
= mItemLocaleMap
.find(entry
);
639 if(itr
==mItemLocaleMap
.end()) return NULL
;
642 QuestLocale
const* GetQuestLocale(uint32 entry
) const
644 QuestLocaleMap::const_iterator itr
= mQuestLocaleMap
.find(entry
);
645 if(itr
==mQuestLocaleMap
.end()) return NULL
;
648 NpcTextLocale
const* GetNpcTextLocale(uint32 entry
) const
650 NpcTextLocaleMap::const_iterator itr
= mNpcTextLocaleMap
.find(entry
);
651 if(itr
==mNpcTextLocaleMap
.end()) return NULL
;
654 PageTextLocale
const* GetPageTextLocale(uint32 entry
) const
656 PageTextLocaleMap::const_iterator itr
= mPageTextLocaleMap
.find(entry
);
657 if(itr
==mPageTextLocaleMap
.end()) return NULL
;
660 NpcOptionLocale
const* GetNpcOptionLocale(uint32 entry
) const
662 NpcOptionLocaleMap::const_iterator itr
= mNpcOptionLocaleMap
.find(entry
);
663 if(itr
==mNpcOptionLocaleMap
.end()) return NULL
;
667 GameObjectData
const* GetGOData(uint32 guid
) const
669 GameObjectDataMap::const_iterator itr
= mGameObjectDataMap
.find(guid
);
670 if(itr
==mGameObjectDataMap
.end()) return NULL
;
673 GameObjectData
& NewGOData(uint32 guid
) { return mGameObjectDataMap
[guid
]; }
674 void DeleteGOData(uint32 guid
);
676 MangosStringLocale
const* GetMangosStringLocale(int32 entry
) const
678 MangosStringLocaleMap::const_iterator itr
= mMangosStringLocaleMap
.find(entry
);
679 if(itr
==mMangosStringLocaleMap
.end()) return NULL
;
682 const char *GetMangosString(int32 entry
, int locale_idx
) const;
683 const char *GetMangosStringForDBCLocale(int32 entry
) const { return GetMangosString(entry
,DBCLocaleIndex
); }
684 int32
GetDBCLocaleIndex() const { return DBCLocaleIndex
; }
685 void SetDBCLocaleIndex(uint32 lang
) { DBCLocaleIndex
= GetIndexForLocale(LocaleConstant(lang
)); }
687 void AddCorpseCellData(uint32 mapid
, uint32 cellid
, uint32 player_guid
, uint32 instance
);
688 void DeleteCorpseCellData(uint32 mapid
, uint32 cellid
, uint32 player_guid
);
690 time_t GetCreatureRespawnTime(uint32 loguid
, uint32 instance
) { return mCreatureRespawnTimes
[MAKE_PAIR64(loguid
,instance
)]; }
691 void SaveCreatureRespawnTime(uint32 loguid
, uint32 instance
, time_t t
);
692 time_t GetGORespawnTime(uint32 loguid
, uint32 instance
) { return mGORespawnTimes
[MAKE_PAIR64(loguid
,instance
)]; }
693 void SaveGORespawnTime(uint32 loguid
, uint32 instance
, time_t t
);
694 void DeleteRespawnTimeForInstance(uint32 instance
);
697 void AddCreatureToGrid(uint32 guid
, CreatureData
const* data
);
698 void RemoveCreatureFromGrid(uint32 guid
, CreatureData
const* data
);
699 void AddGameobjectToGrid(uint32 guid
, GameObjectData
const* data
);
700 void RemoveGameobjectFromGrid(uint32 guid
, GameObjectData
const* data
);
703 void LoadReservedPlayersNames();
704 bool IsReservedName(std::string name
) const
706 return m_ReservedNames
.find(name
) != m_ReservedNames
.end();
709 // name with valid structure and symbols
710 static bool IsValidName( std::string name
, bool create
= false );
711 static bool IsValidCharterName( std::string name
);
712 static bool IsValidPetName( std::string name
);
714 static bool CheckDeclinedNames(std::wstring mainpart
, DeclinedName
const& names
);
716 int GetIndexForLocale(LocaleConstant loc
);
717 LocaleConstant
GetLocaleForIndex(int i
);
719 uint32
GetGuildBankTabPrice(uint8 Index
) const { return Index
< GUILD_BANK_MAX_TABS
? mGuildBankTabPrice
[Index
] : 0; }
721 uint16
GetConditionId(ConditionType condition
, uint32 value1
, uint32 value2
);
722 bool IsPlayerMeetToCondition(Player
const* player
, uint16 condition_id
) const
724 if(condition_id
>= mConditions
.size())
727 return mConditions
[condition_id
].Meets(player
);
730 GameTele
const* GetGameTele(uint32 id
) const
732 GameTeleMap::const_iterator itr
= m_GameTeleMap
.find(id
);
733 if(itr
==m_GameTeleMap
.end()) return NULL
;
736 GameTele
const* GetGameTele(std::string name
) const;
737 GameTeleMap
const& GetGameTeleMap() const { return m_GameTeleMap
; }
738 bool AddGameTele(GameTele
& data
);
739 bool DeleteGameTele(std::string name
);
741 CacheNpcOptionList
const& GetNpcOptions() const { return m_mCacheNpcOptionList
; }
743 uint32
GetNpcGossip(uint32 entry
) const
745 CacheNpcTextIdMap::const_iterator iter
= m_mCacheNpcTextIdMap
.find(entry
);
746 if(iter
== m_mCacheNpcTextIdMap
.end())
752 TrainerSpellData
const* GetNpcTrainerSpells(uint32 entry
) const
754 CacheTrainerSpellMap::const_iterator iter
= m_mCacheTrainerSpellMap
.find(entry
);
755 if(iter
== m_mCacheTrainerSpellMap
.end())
758 return &iter
->second
;
761 VendorItemData
const* GetNpcVendorItemList(uint32 entry
) const
763 CacheVendorItemMap::const_iterator iter
= m_mCacheVendorItemMap
.find(entry
);
764 if(iter
== m_mCacheVendorItemMap
.end())
767 return &iter
->second
;
769 void AddVendorItem(uint32 entry
,uint32 item
, uint32 maxcount
, uint32 incrtime
, uint32 ExtendedCost
);
770 bool RemoveVendorItem(uint32 entry
,uint32 item
);
771 bool IsVendorItemValid( uint32 vendor_entry
, uint32 item
, uint32 maxcount
, uint32 ptime
, uint32 ExtendedCost
, Player
* pl
= NULL
, std::set
<uint32
>* skip_vendors
= NULL
) const;
772 void LoadAchievementCriteriaList();
773 AchievementCriteriaEntryList
const& GetAchievementCriteriaByType(AchievementCriteriaTypes type
);
774 std::set
<uint32
> allCompletedAchievements
;
776 void LoadScriptNames();
777 ScriptNameMap
&GetScriptNames() { return m_scriptNames
; }
778 const char * GetScriptName(uint32 id
) { return id
< m_scriptNames
.size() ? m_scriptNames
[id
].c_str() : ""; }
779 uint32
GetScriptId(const char *name
);
782 // first free id for selected id type
786 uint32 m_arenaTeamId
;
788 uint32 m_hiPetNumber
;
790 // first free low guid for seelcted guid type
792 uint32 m_hiCreatureGuid
;
794 uint32 m_hiVehicleGuid
;
798 uint32 m_hiCorpseGuid
;
800 QuestMap mQuestTemplates
;
802 typedef UNORDERED_MAP
<uint32
, GossipText
*> GossipTextMap
;
803 typedef UNORDERED_MAP
<uint32
, uint32
> QuestAreaTriggerMap
;
804 typedef UNORDERED_MAP
<uint32
, uint32
> BattleMastersMap
;
805 typedef UNORDERED_MAP
<uint32
, std::string
> ItemTextMap
;
806 typedef std::set
<uint32
> TavernAreaTriggerSet
;
807 typedef std::set
<uint32
> GameObjectForQuestSet
;
811 ArenaTeamSet mArenaTeamSet
;
816 ItemTextMap mItemTexts
;
818 AuctionHouseObject mHordeAuctions
;
819 AuctionHouseObject mAllianceAuctions
;
820 AuctionHouseObject mNeutralAuctions
;
822 QuestAreaTriggerMap mQuestAreaTriggerMap
;
823 BattleMastersMap mBattleMastersMap
;
824 TavernAreaTriggerSet mTavernAreaTriggerSet
;
825 GameObjectForQuestSet mGameObjectForQuestSet
;
826 GossipTextMap mGossipText
;
827 AreaTriggerMap mAreaTriggers
;
828 AreaTriggerScriptMap mAreaTriggerScripts
;
830 RepOnKillMap mRepOnKill
;
832 WeatherZoneMap mWeatherZoneMap
;
834 PetCreateSpellMap mPetCreateSpell
;
836 //character reserved names
837 typedef std::set
<std::string
> ReservedNamesMap
;
838 ReservedNamesMap m_ReservedNames
;
840 GraveYardMap mGraveYardMap
;
842 GameTeleMap m_GameTeleMap
;
844 ScriptNameMap m_scriptNames
;
846 typedef std::vector
<LocaleConstant
> LocalForIndex
;
847 LocalForIndex m_LocalForIndex
;
848 int GetOrNewIndexForLocale(LocaleConstant loc
);
853 void LoadScripts(ScriptMapMap
& scripts
, char const* tablename
);
854 void CheckScripts(ScriptMapMap
const& scripts
,std::set
<int32
>& ids
);
855 void ConvertCreatureAddonAuras(CreatureDataAddon
* addon
, char const* table
, char const* guidEntryStr
);
856 void LoadQuestRelationsHelper(QuestRelations
& map
,char const* table
);
858 typedef std::map
<uint32
,PetLevelInfo
*> PetLevelInfoMap
;
859 // PetLevelInfoMap[creature_id][level]
860 PetLevelInfoMap petInfo
; // [creature_id][level]
862 PlayerClassInfo playerClassInfo
[MAX_CLASSES
];
864 void BuildPlayerLevelInfo(uint8 race
, uint8 class_
, uint8 level
, PlayerLevelInfo
* plinfo
) const;
865 PlayerInfo playerInfo
[MAX_RACES
][MAX_CLASSES
];
867 typedef std::map
<uint32
,uint32
> BaseXPMap
; // [area level][base xp]
868 BaseXPMap mBaseXPTable
;
870 typedef std::map
<uint32
,int32
> FishingBaseSkillMap
; // [areaId][base skill level]
871 FishingBaseSkillMap mFishingBaseForArea
;
873 typedef std::map
<uint32
,std::vector
<std::string
> > HalfNameMap
;
874 HalfNameMap PetHalfName0
;
875 HalfNameMap PetHalfName1
;
877 MapObjectGuids mMapObjectGuids
;
878 CreatureDataMap mCreatureDataMap
;
879 CreatureLocaleMap mCreatureLocaleMap
;
880 GameObjectDataMap mGameObjectDataMap
;
881 GameObjectLocaleMap mGameObjectLocaleMap
;
882 ItemLocaleMap mItemLocaleMap
;
883 QuestLocaleMap mQuestLocaleMap
;
884 NpcTextLocaleMap mNpcTextLocaleMap
;
885 PageTextLocaleMap mPageTextLocaleMap
;
886 MangosStringLocaleMap mMangosStringLocaleMap
;
887 NpcOptionLocaleMap mNpcOptionLocaleMap
;
888 RespawnTimes mCreatureRespawnTimes
;
889 RespawnTimes mGORespawnTimes
;
891 typedef std::vector
<uint32
> GuildBankTabPriceMap
;
892 GuildBankTabPriceMap mGuildBankTabPrice
;
894 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
895 typedef std::vector
<PlayerCondition
> ConditionStore
;
896 ConditionStore mConditions
;
898 CacheNpcOptionList m_mCacheNpcOptionList
;
899 CacheNpcTextIdMap m_mCacheNpcTextIdMap
;
900 CacheVendorItemMap m_mCacheVendorItemMap
;
901 CacheTrainerSpellMap m_mCacheTrainerSpellMap
;
903 // store achievement criterias by type to speed up lookup
904 AchievementCriteriaEntryList m_AchievementCriteriasByType
[ACHIEVEMENT_CRITERIA_TYPE_TOTAL
];
907 #define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
909 // scripting access functions
910 MANGOS_DLL_SPEC
bool LoadMangosStrings(DatabaseType
& db
, char const* table
,int32 start_value
= -1, int32 end_value
= std::numeric_limits
<int32
>::min());
911 MANGOS_DLL_SPEC uint32
GetAreaTriggerScriptId(uint32 trigger_id
);
912 MANGOS_DLL_SPEC uint32
GetScriptId(const char *name
);
913 MANGOS_DLL_SPEC
ObjectMgr::ScriptNameMap
& GetScriptNames();