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

Revision 2, 29.2 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

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