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

Revision 6, 32.5 kB (checked in by yumileroy, 17 years ago)

[svn] * Added ACE for Linux and Windows (Thanks Derex for Linux part and partial Windows part)
* Updated to 6721 and 676
* Fixed TrinityScript? logo
* Version updated to 0.2.6721.676

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