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

Revision 85, 32.6 kB (checked in by yumileroy, 17 years ago)

[svn] Implement a new table (spell_disabled) to allow disabling some spells for players and / or creatures. To disable a spell for a players and pets, set 20 in the disable_mask, to disable for creatures, set 21. The comment field is optional. Original patch provided by Craker.

Original author: w12x
Date: 2008-10-21 03:58:38-05:00

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