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

Revision 18, 33.0 kB (checked in by yumileroy, 17 years ago)

[svn] * Little fix in RandomMovementGenerator?
* Updated to 6731 and 680

Original author: Neo2003
Date: 2008-10-06 04:48:59-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19#ifndef _OBJECTMGR_H
20#define _OBJECTMGR_H
21
22#include "Log.h"
23#include "Object.h"
24#include "Bag.h"
25#include "Creature.h"
26#include "Player.h"
27#include "DynamicObject.h"
28#include "GameObject.h"
29#include "Corpse.h"
30#include "QuestDef.h"
31#include "Path.h"
32#include "ItemPrototype.h"
33#include "NPCHandler.h"
34#include "Database/DatabaseEnv.h"
35#include "AuctionHouseObject.h"
36#include "Mail.h"
37#include "Map.h"
38#include "ObjectAccessor.h"
39#include "ObjectDefines.h"
40#include "Policies/Singleton.h"
41#include "Database/SQLStorage.h"
42
43#include <string>
44#include <map>
45#include <limits>
46
47extern SQLStorage sCreatureStorage;
48extern SQLStorage sCreatureDataAddonStorage;
49extern SQLStorage sCreatureInfoAddonStorage;
50extern SQLStorage sCreatureModelStorage;
51extern SQLStorage sEquipmentStorage;
52extern SQLStorage sGOStorage;
53extern SQLStorage sPageTextStore;
54extern SQLStorage sItemStorage;
55extern SQLStorage sInstanceTemplate;
56
57class Group;
58class Guild;
59class ArenaTeam;
60class Path;
61class TransportPath;
62class Item;
63
64struct GameTele
65{
66    float  position_x;
67    float  position_y;
68    float  position_z;
69    float  orientation;
70    uint32 mapId;
71    std::string name;
72    std::wstring wnameLow;
73};
74
75typedef HM_NAMESPACE::hash_map<uint32, GameTele > GameTeleMap;
76
77struct ScriptInfo
78{
79    uint32 id;
80    uint32 delay;
81    uint32 command;
82    uint32 datalong;
83    uint32 datalong2;
84    std::string datatext;
85    float x;
86    float y;
87    float z;
88    float o;
89};
90
91typedef std::multimap<uint32, ScriptInfo> ScriptMap;
92typedef std::map<uint32, ScriptMap > ScriptMapMap;
93extern ScriptMapMap sQuestEndScripts;
94extern ScriptMapMap sQuestStartScripts;
95extern ScriptMapMap sSpellScripts;
96extern ScriptMapMap sGameObjectScripts;
97extern ScriptMapMap sEventScripts;
98
99struct AreaTrigger
100{
101    uint8  requiredLevel;
102    uint32 requiredItem;
103    uint32 requiredItem2;
104    uint32 heroicKey;
105    uint32 heroicKey2;
106    uint32 requiredQuest;
107    std::string requiredFailedText;
108    uint32 target_mapId;
109    float  target_X;
110    float  target_Y;
111    float  target_Z;
112    float  target_Orientation;
113};
114
115typedef std::set<uint32> CellGuidSet;
116typedef std::map<uint32/*player guid*/,uint32/*instance*/> CellCorpseSet;
117struct CellObjectGuids
118{
119    CellGuidSet creatures;
120    CellGuidSet gameobjects;
121    CellCorpseSet corpses;
122};
123typedef HM_NAMESPACE::hash_map<uint32/*cell_id*/,CellObjectGuids> CellObjectGuidsMap;
124typedef HM_NAMESPACE::hash_map<uint32/*(mapid,spawnMode) pair*/,CellObjectGuidsMap> MapObjectGuids;
125
126typedef HM_NAMESPACE::hash_map<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
127
128struct MangosStringLocale
129{
130    std::vector<std::string> Content;                       // 0 -> default, i -> i-1 locale index
131};
132
133typedef HM_NAMESPACE::hash_map<uint32,CreatureData> CreatureDataMap;
134typedef HM_NAMESPACE::hash_map<uint32,GameObjectData> GameObjectDataMap;
135typedef HM_NAMESPACE::hash_map<uint32,CreatureLocale> CreatureLocaleMap;
136typedef HM_NAMESPACE::hash_map<uint32,GameObjectLocale> GameObjectLocaleMap;
137typedef HM_NAMESPACE::hash_map<uint32,ItemLocale> ItemLocaleMap;
138typedef HM_NAMESPACE::hash_map<uint32,QuestLocale> QuestLocaleMap;
139typedef HM_NAMESPACE::hash_map<uint32,NpcTextLocale> NpcTextLocaleMap;
140typedef HM_NAMESPACE::hash_map<uint32,PageTextLocale> PageTextLocaleMap;
141typedef HM_NAMESPACE::hash_map<uint32,MangosStringLocale> MangosStringLocaleMap;
142
143typedef std::multimap<uint32,uint32> QuestRelations;
144
145struct PetLevelInfo
146{
147    PetLevelInfo() : health(0), mana(0) { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
148
149    uint16 stats[MAX_STATS];
150    uint16 health;
151    uint16 mana;
152    uint16 armor;
153};
154
155struct ReputationOnKillEntry
156{
157    uint32 repfaction1;
158    uint32 repfaction2;
159    bool is_teamaward1;
160    uint32 reputation_max_cap1;
161    int32 repvalue1;
162    bool is_teamaward2;
163    uint32 reputation_max_cap2;
164    int32 repvalue2;
165    bool team_dependent;
166};
167
168struct PetCreateSpellEntry
169{
170    uint32 spellid[4];
171};
172
173#define WEATHER_SEASONS 4
174struct WeatherSeasonChances
175{
176    uint32 rainChance;
177    uint32 snowChance;
178    uint32 stormChance;
179};
180
181struct WeatherZoneChances
182{
183    WeatherSeasonChances data[WEATHER_SEASONS];
184};
185
186struct GraveYardData
187{
188    uint32 safeLocId;
189    uint32 team;
190};
191typedef std::multimap<uint32,GraveYardData> GraveYardMap;
192
193enum ConditionType
194{                                                           // value1       value2  for the Condition enumed
195    CONDITION_NONE                  = 0,                    // 0            0
196    CONDITION_AURA                  = 1,                    // spell_id     effindex
197    CONDITION_ITEM                  = 2,                    // item_id      count
198    CONDITION_ITEM_EQUIPPED         = 3,                    // item_id      0
199    CONDITION_ZONEID                = 4,                    // zone_id      0
200    CONDITION_REPUTATION_RANK       = 5,                    // faction_id   min_rank
201    CONDITION_TEAM                  = 6,                    // player_team  0,      (469 - Alliance 67 - Horde)
202    CONDITION_SKILL                 = 7,                    // skill_id     skill_value
203    CONDITION_QUESTREWARDED         = 8,                    // quest_id     0
204    CONDITION_QUESTTAKEN            = 9,                    // quest_id     0,      for condition true while quest active.
205    CONDITION_AD_COMMISSION_AURA    = 10,                   // 0            0,      for condition true while one from AD ñommission aura active
206};
207
208#define MAX_CONDITION                 11                    // maximum value in ConditionType enum
209
210struct PlayerCondition
211{
212    ConditionType condition;                                // additional condition type
213    uint32  value1;                                         // data for the condition - see ConditionType definition
214    uint32  value2;
215
216    PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
217        : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
218
219    static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
220    // Checks correctness of values
221    bool Meets(Player const * APlayer) const;               // Checks if the player meets the condition
222    bool operator == (PlayerCondition const& lc) const
223    {
224        return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
225    }
226};
227
228// NPC gossip text id
229typedef HM_NAMESPACE::hash_map<uint32, uint32> CacheNpcTextIdMap;
230
231
232typedef HM_NAMESPACE::hash_map<uint32, VendorItemData> CacheVendorItemMap;
233typedef HM_NAMESPACE::hash_map<uint32, TrainerSpellData> CacheTrainerSpellMap;
234
235enum SkillRangeType
236{
237    SKILL_RANGE_LANGUAGE,                                   // 300..300
238    SKILL_RANGE_LEVEL,                                      // 1..max skill for level
239    SKILL_RANGE_MONO,                                       // 1..1, grey monolite bar
240    SKILL_RANGE_RANK,                                       // 1..skill for known rank
241    SKILL_RANGE_NONE,                                       // 0..0 always
242};
243
244SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
245
246#define MAX_PLAYER_NAME 12                                  // max allowed by client name length
247#define MAX_INTERNAL_PLAYER_NAME 15                         // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
248
249bool normalizePlayerName(std::string& name);
250
251struct MANGOS_DLL_SPEC LanguageDesc
252{
253    Language lang_id;
254    uint32   spell_id;
255    uint32   skill_id;
256};
257
258extern LanguageDesc lang_description[LANGUAGES_COUNT];
259MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
260
261class PlayerDumpReader;
262
263class ObjectMgr
264{
265    friend class PlayerDumpReader;
266
267    public:
268        ObjectMgr();
269        ~ObjectMgr();
270
271        typedef HM_NAMESPACE::hash_map<uint32, Item*> ItemMap;
272
273        typedef std::set< Group * > GroupSet;
274        typedef std::set< Guild * > GuildSet;
275        typedef std::set< ArenaTeam * > ArenaTeamSet;
276
277        typedef HM_NAMESPACE::hash_map<uint32, Quest*> QuestMap;
278
279        typedef HM_NAMESPACE::hash_map<uint32, AreaTrigger> AreaTriggerMap;
280
281        typedef HM_NAMESPACE::hash_map<uint32, std::string> AreaTriggerScriptMap;
282
283        typedef HM_NAMESPACE::hash_map<uint32, ReputationOnKillEntry> RepOnKillMap;
284
285        typedef HM_NAMESPACE::hash_map<uint32, WeatherZoneChances> WeatherZoneMap;
286
287        typedef HM_NAMESPACE::hash_map<uint32, PetCreateSpellEntry> PetCreateSpellMap;
288
289        Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);}
290        Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
291
292        static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
293
294        void LoadGameobjectInfo();
295        void AddGameobjectInfo(GameObjectInfo *goinfo);
296
297        Group * GetGroupByLeader(const uint64 &guid) const;
298        void AddGroup(Group* group) { mGroupSet.insert( group ); }
299        void RemoveGroup(Group* group) { mGroupSet.erase( group ); }
300
301        Guild* GetGuildByLeader(uint64 const&guid) const;
302        Guild* GetGuildById(const uint32 GuildId) const;
303        Guild* GetGuildByName(std::string guildname) const;
304        std::string GetGuildNameById(const uint32 GuildId) const;
305        void AddGuild(Guild* guild) { mGuildSet.insert( guild ); }
306        void RemoveGuild(Guild* guild) { mGuildSet.erase( guild ); }
307
308        ArenaTeam* GetArenaTeamById(const uint32 ArenaTeamId) const;
309        ArenaTeam* GetArenaTeamByName(std::string ArenaTeamName) const;
310        ArenaTeam* GetArenaTeamByCapitan(uint64 const& guid) const;
311        void AddArenaTeam(ArenaTeam* arenateam) { mArenaTeamSet.insert( arenateam ); }
312        void RemoveArenaTeam(ArenaTeam* arenateam) { mArenaTeamSet.erase( arenateam ); }
313        ArenaTeamSet::iterator GetArenaTeamSetBegin() { return mArenaTeamSet.begin(); }
314        ArenaTeamSet::iterator GetArenaTeamSetEnd() { return mArenaTeamSet.end(); }
315
316        static CreatureInfo const *GetCreatureTemplate( uint32 id );
317        CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
318        CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
319        uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
320        EquipmentInfo const *GetEquipmentInfo( uint32 entry );
321        static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
322        {
323            return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
324        }
325
326        static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
327        {
328            return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
329        }
330
331        static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
332
333        static InstanceTemplate const* GetInstanceTemplate(uint32 map)
334        {
335            return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
336        }
337
338        Item* GetAItem(uint32 id)
339        {
340            ItemMap::const_iterator itr = mAitems.find(id);
341            if (itr != mAitems.end())
342            {
343                return itr->second;
344            }
345            return NULL;
346        }
347        void AddAItem(Item* it)
348        {
349            ASSERT( it );
350            ASSERT( mAitems.find(it->GetGUIDLow()) == mAitems.end());
351            mAitems[it->GetGUIDLow()] = it;
352        }
353        bool RemoveAItem(uint32 id)
354        {
355            ItemMap::iterator i = mAitems.find(id);
356            if (i == mAitems.end())
357            {
358                return false;
359            }
360            mAitems.erase(i);
361            return true;
362        }
363        AuctionHouseObject * GetAuctionsMap( uint32 location );
364
365        //auction messages
366        void SendAuctionWonMail( AuctionEntry * auction );
367        void SendAuctionSalePendingMail( AuctionEntry * auction );
368        void SendAuctionSuccessfulMail( AuctionEntry * auction );
369        void SendAuctionExpiredMail( AuctionEntry * auction );
370        static uint32 GetAuctionCut( uint32 location, uint32 highBid );
371        static uint32 GetAuctionDeposit(uint32 location, uint32 time, Item *pItem);
372        static uint32 GetAuctionOutBid(uint32 currentBid);
373
374        PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
375
376        PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
377        {
378            if(class_ >= MAX_CLASSES) return NULL;
379            return &playerClassInfo[class_];
380        }
381        void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
382
383        PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
384        {
385            if(race   >= MAX_RACES)   return NULL;
386            if(class_ >= MAX_CLASSES) return NULL;
387            PlayerInfo const* info = &playerInfo[race][class_];
388            if(info->displayId_m==0 || info->displayId_f==0) return NULL;
389            return info;
390        }
391        void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
392
393        uint64 GetPlayerGUIDByName(std::string name) const;
394        bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
395        uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
396        uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
397        uint32 GetSecurityByAccount(uint32 acc_id) const;
398        bool GetAccountNameByAccount(uint32 acc_id, std::string &name) const;
399        uint32 GetAccountByAccountName(std::string name) const;
400
401        uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid );
402        void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
403        uint16 GetTaxiMount( uint32 id, uint32 team );
404        void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
405        void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
406
407        Quest const* GetQuestTemplate(uint32 quest_id) const
408        {
409            QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
410            return itr != mQuestTemplates.end() ? itr->second : NULL;
411        }
412        QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
413
414        uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
415        {
416            QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
417            if(itr != mQuestAreaTriggerMap.end())
418                return itr->second;
419            return 0;
420        }
421        bool IsTavernAreaTrigger(uint32 Trigger_ID) const { return mTavernAreaTriggerSet.count(Trigger_ID) != 0; }
422        bool IsGameObjectForQuests(uint32 entry) const { return mGameObjectForQuestSet.count(entry) != 0; }
423        bool IsGuildVaultGameObject(Player *player, uint64 guid) const
424        {
425            if(GameObject *go = ObjectAccessor::GetGameObject(*player, guid))
426                if(go->GetGoType() == GAMEOBJECT_TYPE_GUILD_BANK)
427                    return true;
428            return false;
429        }
430
431        uint32 GetBattleMasterBG(uint32 entry) const
432        {
433            BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
434            if(itr != mBattleMastersMap.end())
435                return itr->second;
436            return 2;                                       //BATTLEGROUND_WS - i will not add include only for constant usage!
437        }
438
439        void AddGossipText(GossipText *pGText);
440        GossipText *GetGossipText(uint32 Text_ID);
441
442        WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
443        bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
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 LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
503        bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_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        MangosStringLocale const* GetMangosStringLocale(int32 entry) const
654        {
655            MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
656            if(itr==mMangosStringLocaleMap.end()) return NULL;
657            return &itr->second;
658        }
659        const char *GetMangosString(int32 entry, int locale_idx) const;
660        const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(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        int GetIndexForLocale(LocaleConstant loc);
693        LocaleConstant GetLocaleForIndex(int i);
694        // guild bank tabs
695        const uint32 GetGuildBankTabPrice(uint8 Index) { return Index < GUILD_BANK_MAX_TABS ? mGuildBankTabPrice[Index] : 0; }
696
697        uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
698        bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
699        {
700            if(condition_id >= mConditions.size())
701                return false;
702
703            return mConditions[condition_id].Meets(player);
704        }
705
706        GameTele const* GetGameTele(uint32 id) const
707        {
708            GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
709            if(itr==m_GameTeleMap.end()) return NULL;
710            return &itr->second;
711        }
712        GameTele const* GetGameTele(std::string name) const;
713        GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
714        bool AddGameTele(GameTele& data);
715        bool DeleteGameTele(std::string name);
716
717        uint32 GetNpcGossip(uint32 entry) const
718        {
719            CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
720            if(iter == m_mCacheNpcTextIdMap.end())
721                return 0;
722           
723            return iter->second;
724        }
725
726        TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
727        {
728            CacheTrainerSpellMap::const_iterator  iter = m_mCacheTrainerSpellMap.find(entry);
729            if(iter == m_mCacheTrainerSpellMap.end())
730                return NULL;
731
732            return &iter->second;
733        }
734
735        VendorItemData const* GetNpcVendorItemList(uint32 entry) const
736        {
737            CacheVendorItemMap::const_iterator  iter = m_mCacheVendorItemMap.find(entry);
738            if(iter == m_mCacheVendorItemMap.end())
739                return NULL;
740
741            return &iter->second;
742        }
743        void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
744        bool RemoveVendorItem(uint32 entry,uint32 item);
745        bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL ) const;
746    protected:
747        uint32 m_auctionid;
748        uint32 m_mailid;
749        uint32 m_ItemTextId;
750
751        uint32 m_hiCharGuid;
752        uint32 m_hiCreatureGuid;
753        uint32 m_hiPetGuid;
754        uint32 m_hiItemGuid;
755        uint32 m_hiGoGuid;
756        uint32 m_hiDoGuid;
757        uint32 m_hiCorpseGuid;
758
759        uint32 m_hiPetNumber;
760
761        QuestMap mQuestTemplates;
762
763        typedef HM_NAMESPACE::hash_map<uint32, GossipText*> GossipTextMap;
764        typedef HM_NAMESPACE::hash_map<uint32, uint32> QuestAreaTriggerMap;
765        typedef HM_NAMESPACE::hash_map<uint32, uint32> BattleMastersMap;
766        typedef HM_NAMESPACE::hash_map<uint32, std::string> ItemTextMap;
767        typedef std::set<uint32> TavernAreaTriggerSet;
768        typedef std::set<uint32> GameObjectForQuestSet;
769
770        GroupSet            mGroupSet;
771        GuildSet            mGuildSet;
772        ArenaTeamSet        mArenaTeamSet;
773
774        ItemMap             mItems;
775        ItemMap             mAitems;
776
777        ItemTextMap         mItemTexts;
778
779        AuctionHouseObject  mHordeAuctions;
780        AuctionHouseObject  mAllianceAuctions;
781        AuctionHouseObject  mNeutralAuctions;
782
783        QuestAreaTriggerMap mQuestAreaTriggerMap;
784        BattleMastersMap    mBattleMastersMap;
785        TavernAreaTriggerSet mTavernAreaTriggerSet;
786        GameObjectForQuestSet mGameObjectForQuestSet;
787        GossipTextMap       mGossipText;
788        AreaTriggerMap      mAreaTriggers;
789        AreaTriggerScriptMap  mAreaTriggerScripts;
790
791        RepOnKillMap        mRepOnKill;
792
793        WeatherZoneMap      mWeatherZoneMap;
794
795        PetCreateSpellMap   mPetCreateSpell;
796
797        //character reserved names
798        typedef std::set<std::string> ReservedNamesMap;
799        ReservedNamesMap    m_ReservedNames;
800
801        GraveYardMap        mGraveYardMap;
802
803        GameTeleMap         m_GameTeleMap;
804
805        typedef             std::vector<LocaleConstant> LocalForIndex;
806        LocalForIndex        m_LocalForIndex;
807        int GetOrNewIndexForLocale(LocaleConstant loc);
808
809        int DBCLocaleIndex;
810    private:
811        void LoadScripts(ScriptMapMap& scripts, char const* tablename);
812        void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
813        void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
814
815        typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
816        // PetLevelInfoMap[creature_id][level]
817        PetLevelInfoMap petInfo;                            // [creature_id][level]
818
819        PlayerClassInfo playerClassInfo[MAX_CLASSES];
820
821        void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
822        PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
823
824        typedef std::map<uint32,uint32> BaseXPMap;          // [area level][base xp]
825        BaseXPMap mBaseXPTable;
826
827        typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
828        FishingBaseSkillMap mFishingBaseForArea;
829
830        typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
831        HalfNameMap PetHalfName0;
832        HalfNameMap PetHalfName1;
833
834        MapObjectGuids mMapObjectGuids;
835        CreatureDataMap mCreatureDataMap;
836        CreatureLocaleMap mCreatureLocaleMap;
837        GameObjectDataMap mGameObjectDataMap;
838        GameObjectLocaleMap mGameObjectLocaleMap;
839        ItemLocaleMap mItemLocaleMap;
840        QuestLocaleMap mQuestLocaleMap;
841        NpcTextLocaleMap mNpcTextLocaleMap;
842        PageTextLocaleMap mPageTextLocaleMap;
843        MangosStringLocaleMap mMangosStringLocaleMap;
844        RespawnTimes mCreatureRespawnTimes;
845        RespawnTimes mGORespawnTimes;
846
847        typedef std::vector<uint32> GuildBankTabPriceMap;
848        GuildBankTabPriceMap mGuildBankTabPrice;
849
850        // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
851        typedef std::vector<PlayerCondition> ConditionStore;
852        ConditionStore mConditions;
853
854        CacheNpcTextIdMap m_mCacheNpcTextIdMap;
855        CacheVendorItemMap m_mCacheVendorItemMap;
856        CacheTrainerSpellMap m_mCacheTrainerSpellMap;
857};
858
859#define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
860
861// scripting access functions
862bool MANGOS_DLL_SPEC LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits<int32>::min());
863MANGOS_DLL_SPEC const char* GetAreaTriggerScriptNameById(uint32 id);
864
865#endif
Note: See TracBrowser for help on using the browser.