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

Revision 149, 33.5 kB (checked in by yumileroy, 17 years ago)

[svn] *Implement new player conditions CONDITION_NO_AURA, CONDITION_ACTIVE_EVENT
* Default behaviour of pets for creatures changed to REACT_DEFENSIVE
* Disallowed sending wrapped items as COD
* Prevent loading and saving single target auras for pet in same way as already implemented for player
* Correctly limit use some flask types to zones.
* Fixed extracting common.MPQ under *nix
* Many small xleanups and fixes.
** mangos merge rev.

TEST REV so be careful of creepy crawly bugs!

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