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

Revision 112, 33.3 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge CLI Commands with regular commands and give them level4 access. sec_console. Source mangos - thanks to ogeraisi for the amalgamated patch.
* Redid/Fixed/Added some lang strings.
* As usual remember this is a trunk rev so stability only guaranteed on northern countries of Mars and western parts of Pluto. No warranties outside the solar system, sorry :( . Check with your local government or dictator on regulations regarding export.

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