root/trunk/src/game/ObjectMgr.h @ 206

Revision 206, 33.9 kB (checked in by yumileroy, 17 years ago)

[svn] * Switch from hashmap to unordered map. - cleanup source - mangos. Help - Aokromes

Original author: KingPin?
Date: 2008-11-10 06:53:00-06:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef _OBJECTMGR_H
22#define _OBJECTMGR_H
23
24#include "Log.h"
25#include "Object.h"
26#include "Bag.h"
27#include "Creature.h"
28#include "Player.h"
29#include "DynamicObject.h"
30#include "GameObject.h"
31#include "Corpse.h"
32#include "QuestDef.h"
33#include "Path.h"
34#include "ItemPrototype.h"
35#include "NPCHandler.h"
36#include "Database/DatabaseEnv.h"
37#include "AuctionHouseObject.h"
38#include "Mail.h"
39#include "Map.h"
40#include "ObjectAccessor.h"
41#include "ObjectDefines.h"
42#include "Policies/Singleton.h"
43#include "Database/SQLStorage.h"
44
45#include <string>
46#include <map>
47#include <limits>
48
49extern SQLStorage sCreatureStorage;
50extern SQLStorage sCreatureDataAddonStorage;
51extern SQLStorage sCreatureInfoAddonStorage;
52extern SQLStorage sCreatureModelStorage;
53extern SQLStorage sEquipmentStorage;
54extern SQLStorage sGOStorage;
55extern SQLStorage sPageTextStore;
56extern SQLStorage sItemStorage;
57extern SQLStorage sInstanceTemplate;
58
59class Group;
60class Guild;
61class ArenaTeam;
62class Path;
63class TransportPath;
64class Item;
65
66struct GameTele
67{
68    float  position_x;
69    float  position_y;
70    float  position_z;
71    float  orientation;
72    uint32 mapId;
73    std::string name;
74    std::wstring wnameLow;
75};
76
77typedef UNORDERED_MAP<uint32, GameTele > GameTeleMap;
78typedef std::list<GossipOption> CacheNpcOptionList;
79
80struct ScriptInfo
81{
82    uint32 id;
83    uint32 delay;
84    uint32 command;
85    uint32 datalong;
86    uint32 datalong2;
87    std::string datatext;
88    float x;
89    float y;
90    float z;
91    float o;
92};
93
94typedef std::multimap<uint32, ScriptInfo> ScriptMap;
95typedef std::map<uint32, ScriptMap > ScriptMapMap;
96extern ScriptMapMap sQuestEndScripts;
97extern ScriptMapMap sQuestStartScripts;
98extern ScriptMapMap sSpellScripts;
99extern ScriptMapMap sGameObjectScripts;
100extern ScriptMapMap sEventScripts;
101
102struct AreaTrigger
103{
104    uint8  requiredLevel;
105    uint32 requiredItem;
106    uint32 requiredItem2;
107    uint32 heroicKey;
108    uint32 heroicKey2;
109    uint32 requiredQuest;
110    std::string requiredFailedText;
111    uint32 target_mapId;
112    float  target_X;
113    float  target_Y;
114    float  target_Z;
115    float  target_Orientation;
116};
117
118typedef std::set<uint32> CellGuidSet;
119typedef std::map<uint32/*player guid*/,uint32/*instance*/> CellCorpseSet;
120struct CellObjectGuids
121{
122    CellGuidSet creatures;
123    CellGuidSet gameobjects;
124    CellCorpseSet corpses;
125};
126typedef UNORDERED_MAP<uint32/*cell_id*/,CellObjectGuids> CellObjectGuidsMap;
127typedef UNORDERED_MAP<uint32/*(mapid,spawnMode) pair*/,CellObjectGuidsMap> MapObjectGuids;
128
129typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
130
131struct TrinityStringLocale
132{
133    std::vector<std::string> Content;                       // 0 -> default, i -> i-1 locale index
134};
135
136typedef UNORDERED_MAP<uint32,CreatureData> CreatureDataMap;
137typedef UNORDERED_MAP<uint32,GameObjectData> GameObjectDataMap;
138typedef UNORDERED_MAP<uint32,CreatureLocale> CreatureLocaleMap;
139typedef UNORDERED_MAP<uint32,GameObjectLocale> GameObjectLocaleMap;
140typedef UNORDERED_MAP<uint32,ItemLocale> ItemLocaleMap;
141typedef UNORDERED_MAP<uint32,QuestLocale> QuestLocaleMap;
142typedef UNORDERED_MAP<uint32,NpcTextLocale> NpcTextLocaleMap;
143typedef UNORDERED_MAP<uint32,PageTextLocale> PageTextLocaleMap;
144typedef UNORDERED_MAP<uint32,TrinityStringLocale> TrinityStringLocaleMap;
145typedef UNORDERED_MAP<uint32,NpcOptionLocale> NpcOptionLocaleMap;
146
147typedef std::multimap<uint32,uint32> QuestRelations;
148
149struct PetLevelInfo
150{
151    PetLevelInfo() : health(0), mana(0) { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
152
153    uint16 stats[MAX_STATS];
154    uint16 health;
155    uint16 mana;
156    uint16 armor;
157};
158
159struct ReputationOnKillEntry
160{
161    uint32 repfaction1;
162    uint32 repfaction2;
163    bool is_teamaward1;
164    uint32 reputation_max_cap1;
165    int32 repvalue1;
166    bool is_teamaward2;
167    uint32 reputation_max_cap2;
168    int32 repvalue2;
169    bool team_dependent;
170};
171
172struct PetCreateSpellEntry
173{
174    uint32 spellid[4];
175};
176
177#define WEATHER_SEASONS 4
178struct WeatherSeasonChances
179{
180    uint32 rainChance;
181    uint32 snowChance;
182    uint32 stormChance;
183};
184
185struct WeatherZoneChances
186{
187    WeatherSeasonChances data[WEATHER_SEASONS];
188};
189
190struct GraveYardData
191{
192    uint32 safeLocId;
193    uint32 team;
194};
195typedef std::multimap<uint32,GraveYardData> GraveYardMap;
196
197enum ConditionType
198{                                                           // value1       value2  for the Condition enumed
199    CONDITION_NONE                  = 0,                    // 0            0
200    CONDITION_AURA                  = 1,                    // spell_id     effindex
201    CONDITION_ITEM                  = 2,                    // item_id      count
202    CONDITION_ITEM_EQUIPPED         = 3,                    // item_id      0
203    CONDITION_ZONEID                = 4,                    // zone_id      0
204    CONDITION_REPUTATION_RANK       = 5,                    // faction_id   min_rank
205    CONDITION_TEAM                  = 6,                    // player_team  0,      (469 - Alliance 67 - Horde)
206    CONDITION_SKILL                 = 7,                    // skill_id     skill_value
207    CONDITION_QUESTREWARDED         = 8,                    // quest_id     0
208    CONDITION_QUESTTAKEN            = 9,                    // quest_id     0,      for condition true while quest active.
209    CONDITION_AD_COMMISSION_AURA    = 10,                   // 0            0,      for condition true while one from AD ñommission aura active
210        CONDITION_NO_AURA               = 11,                   // spell_id     effindex
211        CONDITION_ACTIVE_EVENT          = 12,                   // event_id
212};
213
214#define MAX_CONDITION                 13                    // maximum value in ConditionType enum
215
216//Player's info
217typedef struct _tagCachePlayerInfo
218{
219    std::string sPlayerName;
220    uint32 unfield;
221    uint32 unLevel;
222    uint8 unClass;
223//Arena
224    uint32 unArenaInfoId0;
225    uint32 unArenaInfoId1;
226    uint32 unArenaInfoId2;
227    uint32 unArenaInfoSlot0;
228    uint32 unArenaInfoSlot1;
229    uint32 unArenaInfoSlot2;
230}CachePlayerInfo, *PCachePlayerInfo;
231typedef UNORDERED_MAP<uint32, PCachePlayerInfo> CachePlayerInfoMap;
232
233struct PlayerCondition
234{
235    ConditionType condition;                                // additional condition type
236    uint32  value1;                                         // data for the condition - see ConditionType definition
237    uint32  value2;
238
239    PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
240        : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
241
242    static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
243    // Checks correctness of values
244    bool Meets(Player const * APlayer) const;               // Checks if the player meets the condition
245    bool operator == (PlayerCondition const& lc) const
246    {
247        return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
248    }
249};
250
251// NPC gossip text id
252typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
253
254
255typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
256typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
257
258enum SkillRangeType
259{
260    SKILL_RANGE_LANGUAGE,                                   // 300..300
261    SKILL_RANGE_LEVEL,                                      // 1..max skill for level
262    SKILL_RANGE_MONO,                                       // 1..1, grey monolite bar
263    SKILL_RANGE_RANK,                                       // 1..skill for known rank
264    SKILL_RANGE_NONE,                                       // 0..0 always
265};
266
267SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
268
269#define MAX_PLAYER_NAME 12                                  // max allowed by client name length
270#define MAX_INTERNAL_PLAYER_NAME 15                         // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
271
272bool normalizePlayerName(std::string& name);
273
274struct TRINITY_DLL_SPEC LanguageDesc
275{
276    Language lang_id;
277    uint32   spell_id;
278    uint32   skill_id;
279};
280
281extern LanguageDesc lang_description[LANGUAGES_COUNT];
282TRINITY_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
283
284class PlayerDumpReader;
285
286class ObjectMgr
287{
288    friend class PlayerDumpReader;
289
290    public:
291        ObjectMgr();
292        ~ObjectMgr();
293
294        typedef UNORDERED_MAP<uint32, Item*> ItemMap;
295
296        typedef std::set< Group * > GroupSet;
297        typedef std::set< Guild * > GuildSet;
298        typedef std::set< ArenaTeam * > ArenaTeamSet;
299
300        typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
301
302        typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
303
304        typedef UNORDERED_MAP<uint32, std::string> AreaTriggerScriptMap;
305
306        typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
307
308        typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
309
310        typedef UNORDERED_MAP<uint32, PetCreateSpellEntry> PetCreateSpellMap;
311
312        Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);}
313        Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
314
315        static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
316
317        void LoadGameobjectInfo();
318        void AddGameobjectInfo(GameObjectInfo *goinfo);
319
320        Group * GetGroupByLeader(const uint64 &guid) const;
321        void AddGroup(Group* group) { mGroupSet.insert( group ); }
322        void RemoveGroup(Group* group) { mGroupSet.erase( group ); }
323
324        Guild* GetGuildByLeader(uint64 const&guid) const;
325        Guild* GetGuildById(const uint32 GuildId) const;
326        Guild* GetGuildByName(std::string guildname) const;
327        std::string GetGuildNameById(const uint32 GuildId) const;
328        void AddGuild(Guild* guild) { mGuildSet.insert( guild ); }
329        void RemoveGuild(Guild* guild) { mGuildSet.erase( guild ); }
330
331        ArenaTeam* GetArenaTeamById(const uint32 ArenaTeamId) const;
332        ArenaTeam* GetArenaTeamByName(std::string ArenaTeamName) const;
333        ArenaTeam* GetArenaTeamByCapitan(uint64 const& guid) const;
334        void AddArenaTeam(ArenaTeam* arenateam) { mArenaTeamSet.insert( arenateam ); }
335        void RemoveArenaTeam(ArenaTeam* arenateam) { mArenaTeamSet.erase( arenateam ); }
336        ArenaTeamSet::iterator GetArenaTeamSetBegin() { return mArenaTeamSet.begin(); }
337        ArenaTeamSet::iterator GetArenaTeamSetEnd() { return mArenaTeamSet.end(); }
338
339        static CreatureInfo const *GetCreatureTemplate( uint32 id );
340        CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
341        CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
342        uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
343        EquipmentInfo const *GetEquipmentInfo( uint32 entry );
344        static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
345        {
346            return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
347        }
348
349        static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
350        {
351            return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
352        }
353
354        static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
355
356        static InstanceTemplate const* GetInstanceTemplate(uint32 map)
357        {
358            return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
359        }
360
361        Item* GetAItem(uint32 id)
362        {
363            ItemMap::const_iterator itr = mAitems.find(id);
364            if (itr != mAitems.end())
365            {
366                return itr->second;
367            }
368            return NULL;
369        }
370        void AddAItem(Item* it)
371        {
372            ASSERT( it );
373            ASSERT( mAitems.find(it->GetGUIDLow()) == mAitems.end());
374            mAitems[it->GetGUIDLow()] = it;
375        }
376        bool RemoveAItem(uint32 id)
377        {
378            ItemMap::iterator i = mAitems.find(id);
379            if (i == mAitems.end())
380            {
381                return false;
382            }
383            mAitems.erase(i);
384            return true;
385        }
386        AuctionHouseObject * GetAuctionsMap( uint32 location );
387
388        //auction messages
389        void SendAuctionWonMail( AuctionEntry * auction );
390        void SendAuctionSalePendingMail( AuctionEntry * auction );
391        void SendAuctionSuccessfulMail( AuctionEntry * auction );
392        void SendAuctionExpiredMail( AuctionEntry * auction );
393        static uint32 GetAuctionCut( uint32 location, uint32 highBid );
394        static uint32 GetAuctionDeposit(uint32 location, uint32 time, Item *pItem);
395        static uint32 GetAuctionOutBid(uint32 currentBid);
396
397        PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
398
399        PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
400        {
401            if(class_ >= MAX_CLASSES) return NULL;
402            return &playerClassInfo[class_];
403        }
404        void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
405
406        PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
407        {
408            if(race   >= MAX_RACES)   return NULL;
409            if(class_ >= MAX_CLASSES) return NULL;
410            PlayerInfo const* info = &playerInfo[race][class_];
411            if(info->displayId_m==0 || info->displayId_f==0) return NULL;
412            return info;
413        }
414        void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
415
416        uint64 GetPlayerGUIDByName(std::string name) const;
417        bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
418        uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
419        uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
420        uint32 GetPlayerAccountIdByPlayerName(std::string name) const;
421
422        uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid );
423        void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
424        uint16 GetTaxiMount( uint32 id, uint32 team );
425        void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
426        void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
427
428        Quest const* GetQuestTemplate(uint32 quest_id) const
429        {
430            QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
431            return itr != mQuestTemplates.end() ? itr->second : NULL;
432        }
433        QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
434
435        uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
436        {
437            QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
438            if(itr != mQuestAreaTriggerMap.end())
439                return itr->second;
440            return 0;
441        }
442        bool IsTavernAreaTrigger(uint32 Trigger_ID) const { return mTavernAreaTriggerSet.count(Trigger_ID) != 0; }
443        bool IsGameObjectForQuests(uint32 entry) const { return mGameObjectForQuestSet.count(entry) != 0; }
444        bool IsGuildVaultGameObject(Player *player, uint64 guid) const
445        {
446            if(GameObject *go = ObjectAccessor::GetGameObject(*player, guid))
447                if(go->GetGoType() == GAMEOBJECT_TYPE_GUILD_BANK)
448                    return true;
449            return false;
450        }
451
452        uint32 GetBattleMasterBG(uint32 entry) const
453        {
454            BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
455            if(itr != mBattleMastersMap.end())
456                return itr->second;
457            return 2;                                       //BATTLEGROUND_WS - i will not add include only for constant usage!
458        }
459
460        void AddGossipText(GossipText *pGText);
461        GossipText *GetGossipText(uint32 Text_ID);
462
463        WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
464        bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
465        void RemoveGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = false);
466        void LoadGraveyardZones();
467        GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
468
469        AreaTrigger const* GetAreaTrigger(uint32 trigger) const
470        {
471            AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
472            if( itr != mAreaTriggers.end( ) )
473                return &itr->second;
474            return NULL;
475        }
476
477        AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
478
479        const char* GetAreaTriggerScriptName(uint32 id);
480
481        ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
482        {
483            RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
484            if(itr != mRepOnKill.end())
485                return &itr->second;
486            return NULL;
487        }
488
489        PetCreateSpellEntry const* GetPetCreateSpellEntry(uint32 id) const
490        {
491            PetCreateSpellMap::const_iterator itr = mPetCreateSpell.find(id);
492            if(itr != mPetCreateSpell.end())
493                return &itr->second;
494            return NULL;
495        }
496
497        void LoadGuilds();
498        void LoadArenaTeams();
499        void LoadGroups();
500        void LoadQuests();
501        void LoadQuestRelations()
502        {
503            LoadGameobjectQuestRelations();
504            LoadGameobjectInvolvedRelations();
505            LoadCreatureQuestRelations();
506            LoadCreatureInvolvedRelations();
507        }
508        void LoadGameobjectQuestRelations();
509        void LoadGameobjectInvolvedRelations();
510        void LoadCreatureQuestRelations();
511        void LoadCreatureInvolvedRelations();
512
513        QuestRelations mGOQuestRelations;
514        QuestRelations mGOQuestInvolvedRelations;
515        QuestRelations mCreatureQuestRelations;
516        QuestRelations mCreatureQuestInvolvedRelations;
517
518        void LoadGameObjectScripts();
519        void LoadQuestEndScripts();
520        void LoadQuestStartScripts();
521        void LoadEventScripts();
522        void LoadSpellScripts();
523
524        bool LoadTrinityStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
525        bool LoadTrinityStrings() { return LoadTrinityStrings(WorldDatabase,"trinity_string",1,std::numeric_limits<int32>::max()); }
526        void LoadPetCreateSpells();
527        void LoadCreatureLocales();
528        void LoadCreatureTemplates();
529        void LoadCreatures();
530        void LoadCreatureRespawnTimes();
531        void LoadCreatureAddons();
532        void LoadCreatureModelInfo();
533        void LoadEquipmentTemplates();
534        void LoadGameObjectLocales();
535        void LoadGameobjects();
536        void LoadGameobjectRespawnTimes();
537        void LoadItemPrototypes();
538        void LoadItemLocales();
539        void LoadQuestLocales();
540        void LoadNpcTextLocales();
541        void LoadPageTextLocales();
542        void LoadNpcOptionLocales();
543        void LoadInstanceTemplate();
544
545        void LoadGossipText();
546
547        void LoadAreaTriggerTeleports();
548        void LoadQuestAreaTriggers();
549        void LoadAreaTriggerScripts();
550        void LoadTavernAreaTriggers();
551        void LoadBattleMastersEntry();
552        void LoadGameObjectForQuests();
553
554        void LoadItemTexts();
555        void LoadPageTexts();
556
557        //load first auction items, because of check if item exists, when loading
558        void LoadAuctionItems();
559        void LoadAuctions();
560        void LoadPlayerInfo();
561        void LoadPetLevelInfo();
562        void LoadExplorationBaseXP();
563        void LoadPetNames();
564        void LoadPetNumber();
565        void LoadCorpses();
566        void LoadFishingBaseSkillLevel();
567
568        void LoadReputationOnKill();
569
570        void LoadWeatherZoneChances();
571        void LoadGameTele();
572
573        void LoadNpcOptions();
574        void LoadNpcTextId();
575        void LoadVendors();
576        void LoadTrainerSpell();
577
578        std::string GeneratePetName(uint32 entry);
579        uint32 GetBaseXP(uint32 level);
580
581        int32 GetFishingBaseSkillLevel(uint32 entry) const
582        {
583            FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
584            return itr != mFishingBaseForArea.end() ? itr->second : 0;
585        }
586
587        void ReturnOrDeleteOldMails(bool serverUp);
588
589        void SetHighestGuids();
590        uint32 GenerateLowGuid(HighGuid guidhigh);
591        uint32 GenerateAuctionID();
592        uint32 GenerateMailID();
593        uint32 GenerateItemTextID();
594        uint32 GeneratePetNumber();
595       
596        void LoadPlayerInfoInCache();
597        PCachePlayerInfo GetPlayerInfoFromCache(uint32 unPlayerGuid) const;
598        CachePlayerInfoMap m_mPlayerInfoMap;
599
600        uint32 CreateItemText(std::string text);
601        std::string GetItemText( uint32 id )
602        {
603            ItemTextMap::const_iterator itr = mItemTexts.find( id );
604            if ( itr != mItemTexts.end() )
605                return itr->second;
606            else
607                return "There is no info for this item";
608        }
609
610        typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
611        ExclusiveQuestGroups mExclusiveQuestGroups;
612
613        WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
614        {
615            WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
616            if(itr != mWeatherZoneMap.end())
617                return &itr->second;
618            else
619                return NULL;
620        }
621
622        CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
623        {
624            return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
625        }
626
627        CreatureData const* GetCreatureData(uint32 guid) const
628        {
629            CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
630            if(itr==mCreatureDataMap.end()) return NULL;
631            return &itr->second;
632        }
633        CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
634        void DeleteCreatureData(uint32 guid);
635        CreatureLocale const* GetCreatureLocale(uint32 entry) const
636        {
637            CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
638            if(itr==mCreatureLocaleMap.end()) return NULL;
639            return &itr->second;
640        }
641        GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
642        {
643            GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
644            if(itr==mGameObjectLocaleMap.end()) return NULL;
645            return &itr->second;
646        }
647        ItemLocale const* GetItemLocale(uint32 entry) const
648        {
649            ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
650            if(itr==mItemLocaleMap.end()) return NULL;
651            return &itr->second;
652        }
653        QuestLocale const* GetQuestLocale(uint32 entry) const
654        {
655            QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
656            if(itr==mQuestLocaleMap.end()) return NULL;
657            return &itr->second;
658        }
659        NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
660        {
661            NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
662            if(itr==mNpcTextLocaleMap.end()) return NULL;
663            return &itr->second;
664        }
665        PageTextLocale const* GetPageTextLocale(uint32 entry) const
666        {
667            PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
668            if(itr==mPageTextLocaleMap.end()) return NULL;
669            return &itr->second;
670        }
671       
672        NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const
673        {
674            NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry);
675            if(itr==mNpcOptionLocaleMap.end()) return NULL;
676            return &itr->second;
677        }
678
679        GameObjectData const* GetGOData(uint32 guid) const
680        {
681            GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
682            if(itr==mGameObjectDataMap.end()) return NULL;
683            return &itr->second;
684        }
685        GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
686        void DeleteGOData(uint32 guid);
687
688        TrinityStringLocale const* GetTrinityStringLocale(int32 entry) const
689        {
690            TrinityStringLocaleMap::const_iterator itr = mTrinityStringLocaleMap.find(entry);
691            if(itr==mTrinityStringLocaleMap.end()) return NULL;
692            return &itr->second;
693        }
694        const char *GetTrinityString(int32 entry, int locale_idx) const;
695        const char *GetTrinityStringForDBCLocale(int32 entry) const { return GetTrinityString(entry,DBCLocaleIndex); }
696                int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
697        void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
698
699        void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
700        void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
701
702        time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
703        void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
704        time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
705        void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
706        void DeleteRespawnTimeForInstance(uint32 instance);
707
708        // grid objects
709        void AddCreatureToGrid(uint32 guid, CreatureData const* data);
710        void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
711        void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
712        void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
713
714        // reserved names
715        void LoadReservedPlayersNames();
716        bool IsReservedName(std::string name) const
717        {
718            return m_ReservedNames.find(name) != m_ReservedNames.end();
719        }
720
721        // name with valid structure and symbols
722        static bool IsValidName( std::string name, bool create = false );
723        static bool IsValidCharterName( std::string name );
724        static bool IsValidPetName( std::string name );
725
726        static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
727
728        void LoadSpellDisabledEntrys();
729        bool IsPlayerSpellDisabled(uint32 spellid) { return (m_DisabledPlayerSpells.count(spellid) != 0); }
730        bool IsCreatureSpellDisabled(uint32 spellid) { return (m_DisabledCreatureSpells.count(spellid) != 0); }
731
732        int GetIndexForLocale(LocaleConstant loc);
733        LocaleConstant GetLocaleForIndex(int i);
734        // guild bank tabs
735        const uint32 GetGuildBankTabPrice(uint8 Index) { return Index < GUILD_BANK_MAX_TABS ? mGuildBankTabPrice[Index] : 0; }
736
737        uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
738        bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
739        {
740            if(condition_id >= mConditions.size())
741                return false;
742
743            return mConditions[condition_id].Meets(player);
744        }
745
746        GameTele const* GetGameTele(uint32 id) const
747        {
748            GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
749            if(itr==m_GameTeleMap.end()) return NULL;
750            return &itr->second;
751        }
752        GameTele const* GetGameTele(std::string name) const;
753        GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
754        bool AddGameTele(GameTele& data);
755        bool DeleteGameTele(std::string name);
756       
757        CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; }
758
759        uint32 GetNpcGossip(uint32 entry) const
760        {
761            CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
762            if(iter == m_mCacheNpcTextIdMap.end())
763                return 0;
764           
765            return iter->second;
766        }
767
768        TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
769        {
770            CacheTrainerSpellMap::const_iterator  iter = m_mCacheTrainerSpellMap.find(entry);
771            if(iter == m_mCacheTrainerSpellMap.end())
772                return NULL;
773
774            return &iter->second;
775        }
776
777        VendorItemData const* GetNpcVendorItemList(uint32 entry) const
778        {
779            CacheVendorItemMap::const_iterator  iter = m_mCacheVendorItemMap.find(entry);
780            if(iter == m_mCacheVendorItemMap.end())
781                return NULL;
782
783            return &iter->second;
784        }
785        void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost, bool savetodb = true);
786        bool RemoveVendorItem(uint32 entry,uint32 item, bool savetodb = true);
787        bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL, uint32 ORnpcflag = 0) const;
788
789    protected:
790        uint32 m_auctionid;
791        uint32 m_mailid;
792        uint32 m_ItemTextId;
793
794        uint32 m_hiCharGuid;
795        uint32 m_hiCreatureGuid;
796        uint32 m_hiPetGuid;
797        uint32 m_hiItemGuid;
798        uint32 m_hiGoGuid;
799        uint32 m_hiDoGuid;
800        uint32 m_hiCorpseGuid;
801
802        uint32 m_hiPetNumber;
803
804        QuestMap mQuestTemplates;
805
806        typedef UNORDERED_MAP<uint32, GossipText*> GossipTextMap;
807        typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
808        typedef UNORDERED_MAP<uint32, uint32> BattleMastersMap;
809        typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
810        typedef std::set<uint32> TavernAreaTriggerSet;
811        typedef std::set<uint32> GameObjectForQuestSet;
812
813        GroupSet            mGroupSet;
814        GuildSet            mGuildSet;
815        ArenaTeamSet        mArenaTeamSet;
816
817        ItemMap             mItems;
818        ItemMap             mAitems;
819
820        ItemTextMap         mItemTexts;
821
822        AuctionHouseObject  mHordeAuctions;
823        AuctionHouseObject  mAllianceAuctions;
824        AuctionHouseObject  mNeutralAuctions;
825
826        QuestAreaTriggerMap mQuestAreaTriggerMap;
827        BattleMastersMap    mBattleMastersMap;
828        TavernAreaTriggerSet mTavernAreaTriggerSet;
829        GameObjectForQuestSet mGameObjectForQuestSet;
830        GossipTextMap       mGossipText;
831        AreaTriggerMap      mAreaTriggers;
832        AreaTriggerScriptMap  mAreaTriggerScripts;
833
834        RepOnKillMap        mRepOnKill;
835
836        WeatherZoneMap      mWeatherZoneMap;
837
838        PetCreateSpellMap   mPetCreateSpell;
839
840        //character reserved names
841        typedef std::set<std::string> ReservedNamesMap;
842        ReservedNamesMap    m_ReservedNames;
843
844        std::set<uint32>    m_DisabledPlayerSpells;
845        std::set<uint32>    m_DisabledCreatureSpells;
846
847        GraveYardMap        mGraveYardMap;
848
849        GameTeleMap         m_GameTeleMap;
850
851        typedef             std::vector<LocaleConstant> LocalForIndex;
852        LocalForIndex        m_LocalForIndex;
853        int GetOrNewIndexForLocale(LocaleConstant loc);
854
855        int DBCLocaleIndex;
856    private:
857        void LoadScripts(ScriptMapMap& scripts, char const* tablename);
858        void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
859        void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
860
861        typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
862        // PetLevelInfoMap[creature_id][level]
863        PetLevelInfoMap petInfo;                            // [creature_id][level]
864
865        PlayerClassInfo playerClassInfo[MAX_CLASSES];
866
867        void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
868        PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
869
870        typedef std::map<uint32,uint32> BaseXPMap;          // [area level][base xp]
871        BaseXPMap mBaseXPTable;
872
873        typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
874        FishingBaseSkillMap mFishingBaseForArea;
875
876        typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
877        HalfNameMap PetHalfName0;
878        HalfNameMap PetHalfName1;
879
880        MapObjectGuids mMapObjectGuids;
881        CreatureDataMap mCreatureDataMap;
882        CreatureLocaleMap mCreatureLocaleMap;
883        GameObjectDataMap mGameObjectDataMap;
884        GameObjectLocaleMap mGameObjectLocaleMap;
885        ItemLocaleMap mItemLocaleMap;
886        QuestLocaleMap mQuestLocaleMap;
887        NpcTextLocaleMap mNpcTextLocaleMap;
888        PageTextLocaleMap mPageTextLocaleMap;
889        TrinityStringLocaleMap mTrinityStringLocaleMap;
890        NpcOptionLocaleMap mNpcOptionLocaleMap;
891        RespawnTimes mCreatureRespawnTimes;
892        RespawnTimes mGORespawnTimes;
893
894        typedef std::vector<uint32> GuildBankTabPriceMap;
895        GuildBankTabPriceMap mGuildBankTabPrice;
896
897        // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
898        typedef std::vector<PlayerCondition> ConditionStore;
899        ConditionStore mConditions;
900
901        CacheNpcOptionList m_mCacheNpcOptionList;
902        CacheNpcTextIdMap m_mCacheNpcTextIdMap;
903        CacheVendorItemMap m_mCacheVendorItemMap;
904        CacheTrainerSpellMap m_mCacheTrainerSpellMap;
905};
906
907#define objmgr Trinity::Singleton<ObjectMgr>::Instance()
908
909// scripting access functions
910bool TRINITY_DLL_SPEC LoadTrinityStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits<int32>::min());
911TRINITY_DLL_SPEC const char* GetAreaTriggerScriptNameById(uint32 id);
912
913#endif
Note: See TracBrowser for help on using the browser.