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

Revision 44, 32.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge Temp dev SVN with Assembla.
* Changes include:

  • Implementation of w12x's Outdoor PvP and Game Event Systems.
  • Temporary removal of IRC Chat Bot (until infinite loop when disabled is fixed).
  • All mangos -> trinity (to convert your mangos_string table, please run mangos_string_to_trinity_string.sql).
  • Improved Config cleanup.
  • And many more changes.

Original author: Seline
Date: 2008-10-14 11:57:03-05:00

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