/* * Copyright (C) 2005-2009 MaNGOS * * Copyright (C) 2008-2010 Trinity * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _OBJECTMGR_H #define _OBJECTMGR_H #include "Log.h" #include "Object.h" #include "Bag.h" #include "Creature.h" #include "Player.h" #include "DynamicObject.h" #include "GameObject.h" #include "Corpse.h" #include "QuestDef.h" #include "Path.h" #include "ItemPrototype.h" #include "NPCHandler.h" #include "Database/DatabaseEnv.h" #include "Mail.h" #include "Map.h" #include "ObjectAccessor.h" #include "ObjectDefines.h" #include "Policies/Singleton.h" #include "Database/SQLStorage.h" #include "Vehicle.h" #include #include #include extern SQLStorage sCreatureStorage; extern SQLStorage sCreatureDataAddonStorage; extern SQLStorage sCreatureInfoAddonStorage; extern SQLStorage sCreatureModelStorage; extern SQLStorage sEquipmentStorage; extern SQLStorage sGOStorage; extern SQLStorage sPageTextStore; extern SQLStorage sItemStorage; extern SQLStorage sInstanceTemplate; class Group; class Guild; class ArenaTeam; class Path; class TransportPath; class Item; struct GameTele { float position_x; float position_y; float position_z; float orientation; uint32 mapId; std::string name; std::wstring wnameLow; }; typedef UNORDERED_MAP GameTeleMap; struct ScriptInfo { uint32 id; uint32 delay; uint32 command; uint32 datalong; uint32 datalong2; int32 dataint; float x; float y; float z; float o; }; typedef std::multimap ScriptMap; typedef std::map ScriptMapMap; extern ScriptMapMap sQuestEndScripts; extern ScriptMapMap sQuestStartScripts; extern ScriptMapMap sSpellScripts; extern ScriptMapMap sGameObjectScripts; extern ScriptMapMap sEventScripts; extern ScriptMapMap sGossipScripts; extern ScriptMapMap sWaypointScripts; struct SpellClickInfo { uint32 spellId; uint32 questStart; // quest start (quest must be active or rewarded for spell apply) uint32 questEnd; // quest end (quest don't must be rewarded for spell apply) bool questStartCanActive; // if true then quest start can be active (not only rewarded) uint8 castFlags; uint32 auraRequired; uint32 auraForbidden; SpellClickUserTypes userType; // helpers bool IsFitToRequirements(Player const* player, Creature const * clickNpc) const; }; typedef std::multimap SpellClickInfoMap; typedef std::pair SpellClickInfoMapBounds; struct AreaTrigger { uint32 access_id; uint32 target_mapId; float target_X; float target_Y; float target_Z; float target_Orientation; }; typedef std::set CellGuidSet; typedef std::map CellCorpseSet; struct CellObjectGuids { CellGuidSet creatures; CellGuidSet gameobjects; CellCorpseSet corpses; }; typedef UNORDERED_MAP CellObjectGuidsMap; typedef UNORDERED_MAP MapObjectGuids; typedef UNORDERED_MAP RespawnTimes; // Trinity string ranges #define MIN_TRINITY_STRING_ID 1 // 'trinity_string' #define MAX_TRINITY_STRING_ID 2000000000 #define MIN_DB_SCRIPT_STRING_ID MAX_TRINITY_STRING_ID // 'db_script_string' #define MAX_DB_SCRIPT_STRING_ID 2000010000 #define MIN_CREATURE_AI_TEXT_STRING_ID (-1) // 'creature_ai_texts' #define MAX_CREATURE_AI_TEXT_STRING_ID (-1000000) struct TrinityStringLocale { std::vector Content; // 0 -> default, i -> i-1 locale index }; typedef std::map CreatureLinkedRespawnMap; typedef UNORDERED_MAP CreatureDataMap; typedef UNORDERED_MAP GameObjectDataMap; typedef UNORDERED_MAP CreatureLocaleMap; typedef UNORDERED_MAP GameObjectLocaleMap; typedef UNORDERED_MAP ItemLocaleMap; typedef UNORDERED_MAP QuestLocaleMap; typedef UNORDERED_MAP NpcTextLocaleMap; typedef UNORDERED_MAP PageTextLocaleMap; typedef UNORDERED_MAP TrinityStringLocaleMap; typedef UNORDERED_MAP GossipMenuItemsLocaleMap; typedef UNORDERED_MAP PointOfInterestLocaleMap; typedef std::multimap QuestRelations; typedef std::multimap ItemRequiredTargetMap; typedef std::pair ItemRequiredTargetMapBounds; struct PetLevelInfo { PetLevelInfo() : health(0), mana(0) { for (uint8 i=0; i < MAX_STATS; ++i ) stats[i] = 0; } uint16 stats[MAX_STATS]; uint16 health; uint16 mana; uint16 armor; }; struct MailLevelReward { MailLevelReward() : raceMask(0), mailTemplateId(0), senderEntry(0) {} MailLevelReward(uint32 _raceMask, uint32 _mailTemplateId, uint32 _senderEntry) : raceMask(_raceMask), mailTemplateId(_mailTemplateId), senderEntry(_senderEntry) {} uint32 raceMask; uint32 mailTemplateId; uint32 senderEntry; }; typedef std::list MailLevelRewardList; typedef UNORDERED_MAP MailLevelRewardMap; struct ReputationOnKillEntry { uint32 repfaction1; uint32 repfaction2; bool is_teamaward1; uint32 reputation_max_cap1; int32 repvalue1; bool is_teamaward2; uint32 reputation_max_cap2; int32 repvalue2; bool team_dependent; }; struct PointOfInterest { uint32 entry; float x; float y; uint32 icon; uint32 flags; uint32 data; std::string icon_name; }; struct GossipMenuItems { uint32 menu_id; uint32 id; uint8 option_icon; std::string option_text; uint32 option_id; uint32 npc_option_npcflag; uint32 action_menu_id; uint32 action_poi_id; uint32 action_script_id; bool box_coded; uint32 box_money; std::string box_text; uint16 cond_1; uint16 cond_2; uint16 cond_3; }; struct GossipMenus { uint32 entry; uint32 text_id; uint16 cond_1; uint16 cond_2; }; typedef std::multimap GossipMenusMap; typedef std::pair GossipMenusMapBounds; typedef std::multimap GossipMenuItemsMap; typedef std::pair GossipMenuItemsMapBounds; struct QuestPOIPoint { int32 x; int32 y; QuestPOIPoint() : x(0), y(0) {} QuestPOIPoint(int32 _x, int32 _y) : x(_x), y(_y) {} }; struct QuestPOI { int32 ObjectiveIndex; uint32 MapId; uint32 Unk1; uint32 Unk2; uint32 Unk3; uint32 Unk4; std::vector points; QuestPOI() : ObjectiveIndex(0), MapId(0), Unk1(0), Unk2(0), Unk3(0), Unk4(0) {} QuestPOI(int32 objIndex, uint32 mapId, uint32 unk1, uint32 unk2, uint32 unk3, uint32 unk4) : ObjectiveIndex(objIndex), MapId(mapId), Unk1(unk1), Unk2(unk2), Unk3(unk3), Unk4(unk4) {} }; typedef std::vector QuestPOIVector; typedef UNORDERED_MAP QuestPOIMap; #define WEATHER_SEASONS 4 struct WeatherSeasonChances { uint32 rainChance; uint32 snowChance; uint32 stormChance; }; struct WeatherZoneChances { WeatherSeasonChances data[WEATHER_SEASONS]; }; struct GraveYardData { uint32 safeLocId; uint32 team; }; typedef std::multimap GraveYardMap; enum ConditionType { // value1 value2 for the Condition enumed CONDITION_NONE = 0, // 0 0 CONDITION_AURA = 1, // spell_id effindex CONDITION_ITEM = 2, // item_id count CONDITION_ITEM_EQUIPPED = 3, // item_id 0 CONDITION_ZONEID = 4, // zone_id 0 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde) CONDITION_SKILL = 7, // skill_id skill_value CONDITION_QUESTREWARDED = 8, // quest_id 0 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active. CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD commission aura active CONDITION_NO_AURA = 11, // spell_id effindex CONDITION_ACTIVE_EVENT = 12, // event_id CONDITION_INSTANCE_DATA = 13, // entry data CONDITION_QUEST_NONE = 14, // quest_id 0 }; #define MAX_CONDITION 15 // maximum value in ConditionType enum struct PlayerCondition { ConditionType condition; // additional condition type uint32 value1; // data for the condition - see ConditionType definition uint32 value2; PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0) : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {} static bool IsValid(ConditionType condition, uint32 value1, uint32 value2); // Checks correctness of values bool Meets(Player const * APlayer) const; // Checks if the player meets the condition bool operator == (PlayerCondition const& lc) const { return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2); } }; // NPC gossip text id typedef UNORDERED_MAP CacheNpcTextIdMap; typedef UNORDERED_MAP CacheVendorItemMap; typedef UNORDERED_MAP CacheTrainerSpellMap; enum SkillRangeType { SKILL_RANGE_LANGUAGE, // 300..300 SKILL_RANGE_LEVEL, // 1..max skill for level SKILL_RANGE_MONO, // 1..1, grey monolite bar SKILL_RANGE_RANK, // 1..skill for known rank SKILL_RANGE_NONE, // 0..0 always }; struct GM_Ticket { uint64 guid; uint64 playerGuid; std::string name; float pos_x; float pos_y; float pos_z; uint32 map; std::string message; uint64 createtime; uint64 timestamp; int64 closed; // 0 = Open, -1 = Console, playerGuid = player abandoned ticket, other = GM who closed it. uint64 assignedToGM; std::string comment; }; typedef std::list GmTicketList; SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial); #define MAX_PLAYER_NAME 12 // max allowed by client name length #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names ) #define MAX_PET_NAME 12 // max allowed by client name length #define MAX_CHARTER_NAME 24 // max allowed by client name length bool normalizePlayerName(std::string& name); struct LanguageDesc { Language lang_id; uint32 spell_id; uint32 skill_id; }; extern LanguageDesc lang_description[LANGUAGES_COUNT]; LanguageDesc const* GetLanguageDescByID(uint32 lang); class PlayerDumpReader; class ObjectMgr { friend class PlayerDumpReader; public: ObjectMgr(); ~ObjectMgr(); typedef UNORDERED_MAP ItemMap; typedef std::set< Group * > GroupSet; typedef UNORDERED_MAP GuildMap; typedef UNORDERED_MAP ArenaTeamMap; typedef UNORDERED_MAP QuestMap; typedef UNORDERED_MAP AreaTriggerMap; typedef UNORDERED_MAP AreaTriggerScriptMap; typedef UNORDERED_MAP AccessRequirementMap; typedef UNORDERED_MAP RepOnKillMap; typedef UNORDERED_MAP PointOfInterestMap; typedef UNORDERED_MAP WeatherZoneMap; typedef std::vector ScriptNameMap; UNORDERED_MAP TransportEventMap; Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);} Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); } static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry(id); } void LoadGameobjectInfo(); void AddGameobjectInfo(GameObjectInfo *goinfo); Group * GetGroupByLeader(const uint64 &guid) const; void AddGroup(Group* group) { mGroupSet.insert( group ); } void RemoveGroup(Group* group) { mGroupSet.erase( group ); } Guild* GetGuildByLeader(uint64 const&guid) const; Guild* GetGuildById(uint32 GuildId) const; Guild* GetGuildByName(const std::string& guildname) const; std::string GetGuildNameById(uint32 GuildId) const; void AddGuild(Guild* guild); void RemoveGuild(uint32 Id); ArenaTeam* GetArenaTeamById(uint32 arenateamid) const; ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const; ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const; void AddArenaTeam(ArenaTeam* arenaTeam); void RemoveArenaTeam(uint32 Id); ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); } ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); } static CreatureInfo const *GetCreatureTemplate( uint32 id ); CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid ); CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id); uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL); EquipmentInfo const *GetEquipmentInfo( uint32 entry ); static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid ) { return sCreatureDataAddonStorage.LookupEntry(lowguid); } static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry ) { return sCreatureInfoAddonStorage.LookupEntry(entry); } static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry(id); } static InstanceTemplate const* GetInstanceTemplate(uint32 map) { return sInstanceTemplate.LookupEntry(map); } PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint8 level) const; PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const { if(class_ >= MAX_CLASSES) return NULL; return &playerClassInfo[class_]; } void GetPlayerClassLevelInfo(uint32 class_,uint8 level, PlayerClassLevelInfo* info) const; PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const { if(race >= MAX_RACES) return NULL; if(class_ >= MAX_CLASSES) return NULL; PlayerInfo const* info = &playerInfo[race][class_]; if(info->displayId_m==0 || info->displayId_f==0) return NULL; return info; } void GetPlayerLevelInfo(uint32 race, uint32 class_, uint8 level, PlayerLevelInfo* info) const; uint64 GetPlayerGUIDByName(std::string name) const; bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const; uint32 GetPlayerTeamByGUID(const uint64 &guid) const; uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const; uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const; uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team ); void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost); uint32 GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_alt_team = false); void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector& mapIds ); void GetTransportPathNodes( uint32 path, TransportPath &pathnodes ); Quest const* GetQuestTemplate(uint32 quest_id) const { QuestMap::const_iterator itr = mQuestTemplates.find(quest_id); return itr != mQuestTemplates.end() ? itr->second : NULL; } QuestMap const& GetQuestTemplates() const { return mQuestTemplates; } uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const { QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID); if(itr != mQuestAreaTriggerMap.end()) return itr->second; return 0; } bool IsTavernAreaTrigger(uint32 Trigger_ID) const { return mTavernAreaTriggerSet.find(Trigger_ID) != mTavernAreaTriggerSet.end(); } bool IsGameObjectForQuests(uint32 entry) const { return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end(); } GossipText const* GetGossipText(uint32 Text_ID) const; WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team); bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true); void RemoveGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = false); void LoadGraveyardZones(); GraveYardData const* FindGraveYardData(uint32 id, uint32 zone); AreaTrigger const* GetAreaTrigger(uint32 trigger) const { AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger ); if( itr != mAreaTriggers.end( ) ) return &itr->second; return NULL; } AccessRequirement const* GetAccessRequirement(uint32 requirement) const { AccessRequirementMap::const_iterator itr = mAccessRequirements.find( requirement ); if( itr != mAccessRequirements.end( ) ) return &itr->second; return NULL; } AreaTrigger const* GetGoBackTrigger(uint32 Map) const; AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const; uint32 GetAreaTriggerScriptId(uint32 trigger_id); ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const { RepOnKillMap::const_iterator itr = mRepOnKill.find(id); if(itr != mRepOnKill.end()) return &itr->second; return NULL; } PointOfInterest const* GetPointOfInterest(uint32 id) const { PointOfInterestMap::const_iterator itr = mPointsOfInterest.find(id); if(itr != mPointsOfInterest.end()) return &itr->second; return NULL; } QuestPOIVector const* GetQuestPOIVector(uint32 questId) { QuestPOIMap::const_iterator itr = mQuestPOIMap.find(questId); if(itr != mQuestPOIMap.end()) return &itr->second; return NULL; } VehicleAccessoryList GetVehicleAccessoryList(uint32 uiEntry) { VehicleAccessoryList mVehList; VehicleAccessoryMap::const_iterator itr = m_VehicleAccessoryMap.find(uiEntry); if (itr != m_VehicleAccessoryMap.end()) mVehList = itr->second; return mVehList; } void LoadGuilds(); void LoadArenaTeams(); void LoadGroups(); void LoadQuests(); void LoadQuestRelations() { sLog.outString("Loading GO Start Quest Data..."); LoadGameobjectQuestRelations(); sLog.outString("Loading GO End Quest Data..."); LoadGameobjectInvolvedRelations(); sLog.outString("Loading Creature Start Quest Data..."); LoadCreatureQuestRelations(); sLog.outString("Loading Creature End Quest Data..."); LoadCreatureInvolvedRelations(); } void LoadGameobjectQuestRelations(); void LoadGameobjectInvolvedRelations(); void LoadCreatureQuestRelations(); void LoadCreatureInvolvedRelations(); QuestRelations mGOQuestRelations; QuestRelations mGOQuestInvolvedRelations; QuestRelations mCreatureQuestRelations; QuestRelations mCreatureQuestInvolvedRelations; void LoadGameObjectScripts(); void LoadQuestEndScripts(); void LoadQuestStartScripts(); void LoadEventScripts(); void LoadSpellScripts(); void LoadGossipScripts(); void LoadWaypointScripts(); void LoadTransportEvents(); bool LoadTrinityStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value); bool LoadTrinityStrings() { return LoadTrinityStrings(WorldDatabase,"trinity_string",MIN_TRINITY_STRING_ID,MAX_TRINITY_STRING_ID); } void LoadDbScriptStrings(); void LoadCreatureClassLevelStats(); void LoadCreatureLocales(); void LoadCreatureTemplates(); void LoadCreatures(); void LoadCreatureLinkedRespawn(); bool CheckCreatureLinkedRespawn(uint32 guid, uint32 linkedGuid) const; bool SetCreatureLinkedRespawn(uint32 guid, uint32 linkedGuid); void LoadCreatureRespawnTimes(); void LoadCreatureAddons(); void LoadCreatureModelInfo(); void LoadEquipmentTemplates(); void LoadGameObjectLocales(); void LoadGameobjects(); void LoadGameobjectRespawnTimes(); void LoadItemPrototypes(); void LoadItemRequiredTarget(); void LoadItemLocales(); void LoadQuestLocales(); void LoadNpcTextLocales(); void LoadPageTextLocales(); void LoadNpcOptionLocales(); void LoadPointOfInterestLocales(); void LoadInstanceTemplate(); void LoadMailLevelRewards(); void LoadVehicleAccessories(); void LoadGossipText(); void LoadAreaTriggerTeleports(); void LoadAccessRequirements(); void LoadQuestAreaTriggers(); void LoadAreaTriggerScripts(); void LoadTavernAreaTriggers(); void LoadGameObjectForQuests(); void LoadItemTexts(); void LoadPageTexts(); void LoadPlayerInfo(); void LoadPetLevelInfo(); void LoadExplorationBaseXP(); void LoadPetNames(); void LoadPetNumber(); void LoadCorpses(); void LoadFishingBaseSkillLevel(); void LoadReputationOnKill(); void LoadPointsOfInterest(); void LoadQuestPOI(); void LoadNPCSpellClickSpells(); void LoadWeatherZoneChances(); void LoadGameTele(); void LoadNpcTextId(); void LoadGossipMenu(); void LoadGossipMenuItems(); void LoadVendors(); void LoadTrainerSpell(); void LoadGMTickets(); std::string GeneratePetName(uint32 entry); uint32 GetBaseXP(uint8 level); uint32 GetXPForLevel(uint8 level); int32 GetFishingBaseSkillLevel(uint32 entry) const { FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry); return itr != mFishingBaseForArea.end() ? itr->second : 0; } void ReturnOrDeleteOldMails(bool serverUp); CreatureBaseStats const* GetCreatureBaseStats(uint8 level, uint8 unitClass); void SetHighestGuids(); uint32 GenerateLowGuid(HighGuid guidhigh); uint32 GenerateArenaTeamId(); uint32 GenerateAuctionID(); uint64 GenerateEquipmentSetGuid(); uint32 GenerateGuildId(); uint32 GenerateItemTextID(); uint32 GenerateMailID(); uint32 GeneratePetNumber(); uint32 CreateItemText(std::string text); void AddItemText(uint32 itemTextId, std::string text) { mItemTexts[itemTextId] = text; } std::string GetItemText( uint32 id ) { ItemTextMap::const_iterator itr = mItemTexts.find( id ); if ( itr != mItemTexts.end() ) return itr->second; else return "There is no info for this item"; } typedef std::multimap ExclusiveQuestGroups; ExclusiveQuestGroups mExclusiveQuestGroups; MailLevelReward const* GetMailLevelReward(uint32 level,uint32 raceMask) { MailLevelRewardMap::const_iterator map_itr = m_mailLevelRewardMap.find(level); if (map_itr == m_mailLevelRewardMap.end()) return NULL; for(MailLevelRewardList::const_iterator set_itr = map_itr->second.begin(); set_itr != map_itr->second.end(); ++set_itr) if (set_itr->raceMask & raceMask) return &*set_itr; return NULL; } WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const { WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id); if(itr != mWeatherZoneMap.end()) return &itr->second; else return NULL; } CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id) { return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id]; } CreatureData const* GetCreatureData(uint32 guid) const { CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid); if(itr==mCreatureDataMap.end()) return NULL; return &itr->second; } CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; } void DeleteCreatureData(uint32 guid); uint32 GetLinkedRespawnGuid(uint32 guid) const { CreatureLinkedRespawnMap::const_iterator itr = mCreatureLinkedRespawnMap.find(guid); if(itr == mCreatureLinkedRespawnMap.end()) return 0; return itr->second; } CreatureLocale const* GetCreatureLocale(uint32 entry) const { CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry); if(itr==mCreatureLocaleMap.end()) return NULL; return &itr->second; } GameObjectLocale const* GetGameObjectLocale(uint32 entry) const { GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry); if(itr==mGameObjectLocaleMap.end()) return NULL; return &itr->second; } ItemLocale const* GetItemLocale(uint32 entry) const { ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry); if(itr==mItemLocaleMap.end()) return NULL; return &itr->second; } QuestLocale const* GetQuestLocale(uint32 entry) const { QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry); if(itr==mQuestLocaleMap.end()) return NULL; return &itr->second; } NpcTextLocale const* GetNpcTextLocale(uint32 entry) const { NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry); if(itr==mNpcTextLocaleMap.end()) return NULL; return &itr->second; } PageTextLocale const* GetPageTextLocale(uint32 entry) const { PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry); if(itr==mPageTextLocaleMap.end()) return NULL; return &itr->second; } GossipMenuItemsLocale const* GetGossipMenuItemsLocale(uint32 entry) const { GossipMenuItemsLocaleMap::const_iterator itr = mGossipMenuItemsLocaleMap.find(entry); if(itr==mGossipMenuItemsLocaleMap.end()) return NULL; return &itr->second; } PointOfInterestLocale const* GetPointOfInterestLocale(uint32 poi_id) const { PointOfInterestLocaleMap::const_iterator itr = mPointOfInterestLocaleMap.find(poi_id); if(itr==mPointOfInterestLocaleMap.end()) return NULL; return &itr->second; } bool IsGoOfSpecificEntrySpawned(uint32 entry) const { for (GameObjectDataMap::const_iterator it = mGameObjectDataMap.begin(); it != mGameObjectDataMap.end(); ++it) if (it->second.id == entry) return true; return false; } GameObjectData const* GetGOData(uint32 guid) const { GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid); if(itr==mGameObjectDataMap.end()) return NULL; return &itr->second; } GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; } void DeleteGOData(uint32 guid); TrinityStringLocale const* GetTrinityStringLocale(int32 entry) const { TrinityStringLocaleMap::const_iterator itr = mTrinityStringLocaleMap.find(entry); if(itr==mTrinityStringLocaleMap.end()) return NULL; return &itr->second; } const char *GetTrinityString(int32 entry, int locale_idx) const; const char *GetTrinityStringForDBCLocale(int32 entry) const { return GetTrinityString(entry,DBCLocaleIndex); } int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; } void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); } void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance); void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid); time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; } void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t); time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; } void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t); void DeleteRespawnTimeForInstance(uint32 instance); // grid objects void AddCreatureToGrid(uint32 guid, CreatureData const* data); void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data); void AddGameobjectToGrid(uint32 guid, GameObjectData const* data); void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data); uint32 AddGOData(uint32 entry, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay = 0, float rotation0 = 0, float rotation1 = 0, float rotation2 = 0, float rotation3 = 0); uint32 AddCreData(uint32 entry, uint32 team, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay = 0); bool MoveCreData(uint32 guid, uint32 map, Position pos); // reserved names void LoadReservedPlayersNames(); bool IsReservedName(const std::string& name) const; // name with valid structure and symbols static uint8 CheckPlayerName( const std::string& name, bool create = false ); static PetNameInvalidReason CheckPetName( const std::string& name ); static bool IsValidCharterName( const std::string& name ); static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names); void LoadSpellDisabledEntrys(); bool IsPlayerSpellDisabled(uint32 spellid) { return (m_DisabledPlayerSpells.count(spellid) != 0); } bool IsCreatureSpellDisabled(uint32 spellid) { return (m_DisabledCreatureSpells.count(spellid) != 0); } bool IsPetSpellDisabled(uint32 spellid) { return (m_DisabledPetSpells.count(spellid) != 0); } int GetIndexForLocale(LocaleConstant loc); LocaleConstant GetLocaleForIndex(int i); uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2); bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const { if(condition_id >= mConditions.size()) return false; return mConditions[condition_id].Meets(player); } GameTele const* GetGameTele(uint32 id) const { GameTeleMap::const_iterator itr = m_GameTeleMap.find(id); if(itr==m_GameTeleMap.end()) return NULL; return &itr->second; } GameTele const* GetGameTele(const std::string& name) const; GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; } bool AddGameTele(GameTele& data); bool DeleteGameTele(const std::string& name); uint32 GetNpcGossip(uint32 entry) const { CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry); if(iter == m_mCacheNpcTextIdMap.end()) return 0; return iter->second; } TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const { CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry); if(iter == m_mCacheTrainerSpellMap.end()) return NULL; return &iter->second; } VendorItemData const* GetNpcVendorItemList(uint32 entry) const { CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry); if(iter == m_mCacheVendorItemMap.end()) return NULL; return &iter->second; } void AddVendorItem(uint32 entry,uint32 item, int32 maxcount, uint32 incrtime, uint32 ExtendedCost, bool savetodb = true); // for event bool RemoveVendorItem(uint32 entry,uint32 item, bool savetodb = true); // for event bool IsVendorItemValid( uint32 vendor_entry, uint32 item, int32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set* skip_vendors = NULL, uint32 ORnpcflag = 0 ) const; void LoadScriptNames(); ScriptNameMap &GetScriptNames() { return m_scriptNames; } const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; } uint32 GetScriptId(const char *name); int GetOrNewIndexForLocale(LocaleConstant loc); SpellClickInfoMapBounds GetSpellClickInfoMapBounds(uint32 creature_id) const { return SpellClickInfoMapBounds(mSpellClickInfoMap.lower_bound(creature_id),mSpellClickInfoMap.upper_bound(creature_id)); } ItemRequiredTargetMapBounds GetItemRequiredTargetMapBounds(uint32 uiItemEntry) const { return ItemRequiredTargetMapBounds(m_ItemRequiredTarget.lower_bound(uiItemEntry),m_ItemRequiredTarget.upper_bound(uiItemEntry)); } GM_Ticket *GetGMTicket(uint64 ticketGuid) { for (GmTicketList::const_iterator i = m_GMTicketList.begin(); i != m_GMTicketList.end(); ++i) if((*i) && (*i)->guid == ticketGuid) return (*i); return NULL; } GM_Ticket *GetGMTicketByPlayer(uint64 playerGuid) { for (GmTicketList::const_iterator i = m_GMTicketList.begin(); i != m_GMTicketList.end(); ++i) if((*i) && (*i)->playerGuid == playerGuid && (*i)->closed == 0) return (*i); return NULL; } GossipMenusMapBounds GetGossipMenusMapBounds(uint32 uiMenuId) const { return GossipMenusMapBounds(m_mGossipMenusMap.lower_bound(uiMenuId),m_mGossipMenusMap.upper_bound(uiMenuId)); } GossipMenuItemsMapBounds GetGossipMenuItemsMapBounds(uint32 uiMenuId) const { return GossipMenuItemsMapBounds(m_mGossipMenuItemsMap.lower_bound(uiMenuId),m_mGossipMenuItemsMap.upper_bound(uiMenuId)); } void AddOrUpdateGMTicket(GM_Ticket &ticket, bool create = false); void _AddOrUpdateGMTicket(GM_Ticket &ticket); void RemoveGMTicket(uint64 ticketGuid, int64 source = -1, bool permanently = false); void RemoveGMTicket(GM_Ticket *ticket, int64 source = -1, bool permanently = false); GmTicketList m_GMTicketList; uint64 GenerateGMTicketId(); // for wintergrasp only GraveYardMap mGraveYardMap; protected: // first free id for selected id type uint32 m_arenaTeamId; uint32 m_auctionid; uint64 m_equipmentSetGuid; uint32 m_guildId; uint32 m_ItemTextId; uint32 m_mailid; uint32 m_hiPetNumber; uint64 m_GMticketid; // first free low guid for seelcted guid type uint32 m_hiCharGuid; uint32 m_hiCreatureGuid; uint32 m_hiPetGuid; uint32 m_hiVehicleGuid; uint32 m_hiItemGuid; uint32 m_hiGoGuid; uint32 m_hiDoGuid; uint32 m_hiCorpseGuid; QuestMap mQuestTemplates; typedef UNORDERED_MAP GossipTextMap; typedef UNORDERED_MAP QuestAreaTriggerMap; typedef UNORDERED_MAP ItemTextMap; typedef std::set TavernAreaTriggerSet; typedef std::set GameObjectForQuestSet; GroupSet mGroupSet; GuildMap mGuildMap; ArenaTeamMap mArenaTeamMap; ItemTextMap mItemTexts; QuestAreaTriggerMap mQuestAreaTriggerMap; TavernAreaTriggerSet mTavernAreaTriggerSet; GameObjectForQuestSet mGameObjectForQuestSet; GossipTextMap mGossipText; AreaTriggerMap mAreaTriggers; AreaTriggerScriptMap mAreaTriggerScripts; AccessRequirementMap mAccessRequirements; RepOnKillMap mRepOnKill; GossipMenusMap m_mGossipMenusMap; GossipMenuItemsMap m_mGossipMenuItemsMap; PointOfInterestMap mPointsOfInterest; QuestPOIMap mQuestPOIMap; WeatherZoneMap mWeatherZoneMap; //character reserved names typedef std::set ReservedNamesMap; ReservedNamesMap m_ReservedNames; std::set m_DisabledPlayerSpells; std::set m_DisabledCreatureSpells; std::set m_DisabledPetSpells; // GraveYardMap mGraveYardMap; GameTeleMap m_GameTeleMap; ScriptNameMap m_scriptNames; SpellClickInfoMap mSpellClickInfoMap; ItemRequiredTargetMap m_ItemRequiredTarget; VehicleAccessoryMap m_VehicleAccessoryMap; typedef std::vector LocalForIndex; LocalForIndex m_LocalForIndex; int DBCLocaleIndex; private: void LoadScripts(ScriptMapMap& scripts, char const* tablename); void CheckScripts(ScriptMapMap const& scripts,std::set& ids); void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment); void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr); void LoadQuestRelationsHelper(QuestRelations& map,char const* table); MailLevelRewardMap m_mailLevelRewardMap; CreatureBaseStatsMap m_creatureBaseStatsMap; typedef std::map PetLevelInfoMap; // PetLevelInfoMap[creature_id][level] PetLevelInfoMap petInfo; // [creature_id][level] PlayerClassInfo playerClassInfo[MAX_CLASSES]; void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const; PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES]; typedef std::vector PlayerXPperLevel; // [level] PlayerXPperLevel mPlayerXPperLevel; typedef std::map BaseXPMap; // [area level][base xp] BaseXPMap mBaseXPTable; typedef std::map FishingBaseSkillMap; // [areaId][base skill level] FishingBaseSkillMap mFishingBaseForArea; typedef std::map > HalfNameMap; HalfNameMap PetHalfName0; HalfNameMap PetHalfName1; MapObjectGuids mMapObjectGuids; CreatureDataMap mCreatureDataMap; CreatureLinkedRespawnMap mCreatureLinkedRespawnMap; CreatureLocaleMap mCreatureLocaleMap; GameObjectDataMap mGameObjectDataMap; GameObjectLocaleMap mGameObjectLocaleMap; ItemLocaleMap mItemLocaleMap; QuestLocaleMap mQuestLocaleMap; NpcTextLocaleMap mNpcTextLocaleMap; PageTextLocaleMap mPageTextLocaleMap; TrinityStringLocaleMap mTrinityStringLocaleMap; GossipMenuItemsLocaleMap mGossipMenuItemsLocaleMap; PointOfInterestLocaleMap mPointOfInterestLocaleMap; RespawnTimes mCreatureRespawnTimes; RespawnTimes mGORespawnTimes; // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required) typedef std::vector ConditionStore; ConditionStore mConditions; CacheNpcTextIdMap m_mCacheNpcTextIdMap; CacheVendorItemMap m_mCacheVendorItemMap; CacheTrainerSpellMap m_mCacheTrainerSpellMap; }; #define objmgr Trinity::Singleton::Instance() // scripting access functions bool LoadTrinityStrings(DatabaseType& db, char const* table,int32 start_value = MAX_CREATURE_AI_TEXT_STRING_ID, int32 end_value = std::numeric_limits::min()); uint32 GetAreaTriggerScriptId(uint32 trigger_id); uint32 GetScriptId(const char *name); ObjectMgr::ScriptNameMap& GetScriptNames(); GameObjectInfo const *GetGameObjectInfo(uint32 id); CreatureInfo const *GetCreatureInfo(uint32 id); CreatureInfo const* GetCreatureTemplateStore(uint32 entry); Quest const* GetQuestTemplateStore(uint32 entry); #endif