diff --git a/contrib/mysql_to_pgsql/CMakeLists.txt b/contrib/mysql_to_pgsql/CMakeLists.txt new file mode 100644 index 000000000..490a023e4 --- /dev/null +++ b/contrib/mysql_to_pgsql/CMakeLists.txt @@ -0,0 +1,21 @@ +SET(CMAKE_VERBOSE_MAKEFILE ON) +cmake_minimum_required (VERSION 2.6) + +INCLUDE(cmake/FindMySQL.cmake) +INCLUDE(cmake/FindPostgreSQL.cmake) + +MESSAGE("-- Check PostgreSQL") +FIND_PGSQL() +ADD_DEFINITIONS(-DDO_POSTGRESQL) + +MESSAGE("-- Check MySQL") +FIND_MYSQL() +ADD_DEFINITIONS(-DDO_MYSQL) + +INCLUDE_DIRECTORIES(${MYSQL_INCLUDE_DIR}) +INCLUDE_DIRECTORIES(${PGSQL_INCLUDE_DIR}) + +ADD_EXECUTABLE (mysql2pgsql src/main.cpp) + +TARGET_LINK_LIBRARIES(mysql2pgsql ${PGSQL_LIBRARIES}) +TARGET_LINK_LIBRARIES(mysql2pgsql ${MYSQL_LIBRARIES}) diff --git a/contrib/mysql_to_pgsql/README b/contrib/mysql_to_pgsql/README new file mode 100644 index 000000000..bf7083fb6 --- /dev/null +++ b/contrib/mysql_to_pgsql/README @@ -0,0 +1,14 @@ +Using cmake on a Windows +------------------ + 1. install cmake (http://www.cmake.org/cmake/resources/software.html) + 2. cmake -i + 3. Project.sln + 4. {Debug/Release}/mysql2pgsql.exe + +Using cmake on a Unix/Linux +------------------ + 1. install cmake + 2. cmake -i + 3. make + 4. ./mysql2pgsql + diff --git a/contrib/mysql_to_pgsql/cmake/FindMySQL.cmake b/contrib/mysql_to_pgsql/cmake/FindMySQL.cmake new file mode 100644 index 000000000..e7d158de2 --- /dev/null +++ b/contrib/mysql_to_pgsql/cmake/FindMySQL.cmake @@ -0,0 +1,74 @@ +# - Find mysqlclient +# Find the native MySQL includes and library +# +# MYSQL_INCLUDE_DIR - where to find mysql.h, etc. +# MYSQL_LIBRARIES - List of libraries when using MySQL. +# MYSQL_FOUND - True if MySQL found. +MACRO(FIND_MYSQL) + +IF (MYSQL_INCLUDE_DIR) + # Already in cache, be silent + SET(MySQL_FIND_QUIETLY TRUE) +ENDIF (MYSQL_INCLUDE_DIR) + +FIND_PATH(MYSQL_INCLUDE_DIR mysql.h + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MySQL AB\\MySQL Server 6.0;Location]/include" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MySQL AB\\MySQL Server 5.1;Location]/include" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MySQL AB\\MySQL Server 5.0;Location]/include" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MySQL AB\\MySQL Server 4.1;Location]/include" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MySQL AB\\MySQL Server 4.0;Location]/include" + /usr/local/mysql/include + /usr/local/include/mysql + /usr/local/include + /usr/include/mysql + /usr/include + /usr/mysql/include +) + +IF(MSVC) + SET(MYSQL_NAMES libmysql) +ELSE(MSVC) + SET(MYSQL_NAMES mysqlclient mysqlclient_r) +ENDIF(MSVC) +SET(MYSQL_SEARCH_LIB_PATHS + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MySQL AB\\MySQL Server 6.0;Location]/lib/opt" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MySQL AB\\MySQL Server 5.1;Location]/lib/opt" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MySQL AB\\MySQL Server 5.0;Location]/lib/opt" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MySQL AB\\MySQL Server 4.1;Location]/lib/opt" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MySQL AB\\MySQL Server 4.0;Location]/lib/opt" + /usr/local/mysql/lib + /usr/local/lib/mysql + /usr/local/lib + /usr/lib/mysql + /usr/lib +) +FIND_LIBRARY(MYSQL_LIBRARY + NAMES ${MYSQL_NAMES} + PATHS ${MYSQL_SEARCH_LIB_PATHS} +) + +IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) + SET(MYSQL_FOUND TRUE) + SET( MYSQL_LIBRARIES ${MYSQL_LIBRARY} ) +ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) + SET(MYSQL_FOUND FALSE) + SET( MYSQL_LIBRARIES ) +ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) + +IF (MYSQL_FOUND) + IF (NOT MySQL_FIND_QUIETLY) + MESSAGE(STATUS "Found MySQL: ${MYSQL_LIBRARY}") + ENDIF (NOT MySQL_FIND_QUIETLY) +ELSE (MYSQL_FOUND) + IF (MySQL_FIND_REQUIRED) + MESSAGE(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.") + MESSAGE(FATAL_ERROR "Could NOT find MySQL library") + ENDIF (MySQL_FIND_REQUIRED) +ENDIF (MYSQL_FOUND) + +MARK_AS_ADVANCED( + MYSQL_LIBRARY + MYSQL_INCLUDE_DIR +) + +ENDMACRO(FIND_MYSQL) \ No newline at end of file diff --git a/contrib/mysql_to_pgsql/cmake/FindPostgreSQL.cmake b/contrib/mysql_to_pgsql/cmake/FindPostgreSQL.cmake new file mode 100644 index 000000000..06a1adc9e --- /dev/null +++ b/contrib/mysql_to_pgsql/cmake/FindPostgreSQL.cmake @@ -0,0 +1,82 @@ +# - Find libpq +# Find the native PostgreSQL includes and library +# +# PGSQL_INCLUDE_DIR - where to find libpq-fe.h, etc. +# PGSQL_LIBRARIES - List of libraries when using PGSQL. +# PGSQL_FOUND - True if PGSQL found. + +MACRO(FIND_PGSQL) +IF (PGSQL_INCLUDE_DIR) + # Already in cache, be silent + SET(PostgreSQL_FIND_QUIETLY TRUE) +ENDIF (PGSQL_INCLUDE_DIR) + +# the registry settings checked are in order: +# - for pgInstaller 8.2.x postgresql version +# - for pgInstaller 8.3.x postgresql version +SET(PGSQL_WIN_BASE + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\PostgreSQL\\Installations\\{B823632F-3B72-4514-8861-B961CE263224};Base Directory]" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\PostgreSQL\\Installations\\{1F701DBD-1660-4108-B10A-FB435EA63BF0};Base Directory]") + +IF(PGSQL_WIN_BASE) + IF(MSVC) + SET(PGSQL_SEARCH_LIB_PATHS "${PGSQL_WIN_BASE}/lib/ms") + ELSE(MSVC) + SET(PGSQL_SEARCH_LIB_PATHS "${PGSQL_WIN_BASE}/lib") + ENDIF(MSVC) +ENDIF(PGSQL_WIN_BASE) + +FIND_PATH(PGSQL_INCLUDE_DIR libpq-fe.h + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\PostgreSQL\\Installations\\{1F701DBD-1660-4108-B10A-FB435EA63BF0};Base Directory]/include" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\PostgreSQL\\Installations\\{B823632F-3B72-4514-8861-B961CE263224};Base Directory]/include" + /usr/local/pgsql/include + /usr/local/postgresql/include + /usr/local/include/pgsql + /usr/local/include/postgresql + /usr/local/include + /usr/include/pgsql + /usr/include/postgresql + /usr/include + /usr/pgsql/include + /usr/postgresql/include +) + +SET(PGSQL_NAMES pq libpq) +SET(PGSQL_SEARCH_LIB_PATHS + ${PGSQL_SEARCH_LIB_PATHS} + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\PostgreSQL\\Installations\\{1F701DBD-1660-4108-B10A-FB435EA63BF0};Base Directory]/lib" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\PostgreSQL\\Installations\\{B823632F-3B72-4514-8861-B961CE263224};Base Directory]/lib" + /usr/local/pgsql/lib + /usr/local/lib + /usr/lib +) +FIND_LIBRARY(PGSQL_LIBRARY + NAMES ${PGSQL_NAMES} + PATHS ${PGSQL_SEARCH_LIB_PATHS} +) + +IF (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY) + SET(PGSQL_FOUND TRUE) + SET( PGSQL_LIBRARIES ${PGSQL_LIBRARY} ) +ELSE (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY) + SET(PGSQL_FOUND FALSE) + SET( PGSQL_LIBRARIES ) +ENDIF (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY) + +IF (PGSQL_FOUND) + IF (NOT PostgreSQL_FIND_QUIETLY) + MESSAGE(STATUS "Found PostgreSQL: ${PGSQL_LIBRARY}") + ENDIF (NOT PostgreSQL_FIND_QUIETLY) +ELSE (PGSQL_FOUND) + IF (PostgreSQL_FIND_REQUIRED) + MESSAGE(STATUS "Looked for PostgreSQL libraries named ${PGSQL_NAMES}.") + MESSAGE(FATAL_ERROR "Could NOT find PostgreSQL library") + ENDIF (PostgreSQL_FIND_REQUIRED) +ENDIF (PGSQL_FOUND) + +MARK_AS_ADVANCED( + PGSQL_LIBRARY + PGSQL_INCLUDE_DIR +) +ENDMACRO(FIND_PGSQL) + diff --git a/contrib/mysql_to_pgsql/src/defines.h b/contrib/mysql_to_pgsql/src/defines.h new file mode 100644 index 000000000..662a7aab2 --- /dev/null +++ b/contrib/mysql_to_pgsql/src/defines.h @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2005-2009 MaNGOS + * + * 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 _DEFINES_ +#define _DEFINES_ + +#ifdef WIN32 +#include +#pragma warning(disable:4996) +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + + +#ifdef WIN32 +typedef unsigned __int64 uint64; +typedef unsigned int uint32; +#else +#include +#ifndef uint64_t +#include +#endif +typedef uint64_t uint64; +typedef unsigned int uint32; +#endif + +struct sField +{ + string name; // field name + string def; // field default data + string type; // field type + uint32 flags; // filed flags, see field flags; +}; +typedef vector T_Table; +typedef vector T_TableList; +typedef map< string, T_Table > TDataBase; + +static +void pg_notice(void *arg, const char *message) +{ + /// Do nothing + //printf("%s\n", message); +} + +inline +string ConvertNativeType(enum_field_types mysqlType, uint32 length) +{ + + switch (mysqlType) + { + case FIELD_TYPE_TIMESTAMP: + return "timestamp"; + case FIELD_TYPE_BIT: + return "bit(1)"; + case FIELD_TYPE_DATETIME: + return "date"; + case FIELD_TYPE_YEAR: + case FIELD_TYPE_BLOB: + case FIELD_TYPE_SET: + case FIELD_TYPE_NULL: + case FIELD_TYPE_ENUM: + return "text"; + case FIELD_TYPE_TINY: + case FIELD_TYPE_SHORT: + case FIELD_TYPE_INT24: + return "integer"; + case FIELD_TYPE_LONGLONG: + return "int8"; + case FIELD_TYPE_LONG: + return "bigint"; + case FIELD_TYPE_DECIMAL: + case FIELD_TYPE_FLOAT: + case FIELD_TYPE_DOUBLE: + return "float"; + case FIELD_TYPE_STRING: + { + string temp; + char str[10]; + temp = "char"; + if (length) + { + temp.append("("); + sprintf(str,"%d",length); + temp.append(str); + temp.append(")"); + } + return temp; + } + case FIELD_TYPE_VAR_STRING: + { + string temp; + char str[10]; + temp = "varchar"; + if (length) + { + temp.append("("); + sprintf(str,"%d",length); + temp.append(str); + temp.append(")"); + } + return temp; + } + default: + return "text"; + } + return "text"; +} + +inline +bool IsNeeedEscapeString(enum_field_types mysqlType) +{ + switch(mysqlType) + { + case FIELD_TYPE_VAR_STRING: + case FIELD_TYPE_STRING: + case FIELD_TYPE_TINY_BLOB: + case FIELD_TYPE_MEDIUM_BLOB: + case FIELD_TYPE_LONG_BLOB: + case FIELD_TYPE_BLOB: + return true; + default: + return false; + } + return false; +} + +inline +void PG_Exec_str(string sql, PGconn *mPGconn) +{ + PGresult *res = PQexec (mPGconn, sql.c_str()); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + printf( "SQL: %s", sql.c_str() ); + printf( "SQL %s", PQerrorMessage(mPGconn) ); + } +} + +void PG_Escape_Str(string& str) +{ + if(str.empty()) + return; + char* buf = new char[str.size()*2+1]; + PQescapeString(buf,str.c_str(),str.size()); + str = buf; + delete[] buf; +} + +#endif + diff --git a/contrib/mysql_to_pgsql/src/main.cpp b/contrib/mysql_to_pgsql/src/main.cpp new file mode 100644 index 000000000..8ca6772de --- /dev/null +++ b/contrib/mysql_to_pgsql/src/main.cpp @@ -0,0 +1,339 @@ +/* + * Copyright (C) 2005-2009 MaNGOS + * + * 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 + */ + +#include "defines.h" + +int main(int argc, char* argv[]) +{ + char sPGhost[26], sPGport[26], sPGdb[26], sPGuser[26], sPGpass[26]; + printf("Postgres connection settings\n Host>"); + scanf("%s",sPGhost); + printf(" Port>"); + scanf("%s",sPGport); + printf(" Base>"); + scanf("%s",sPGdb); + printf(" User>"); + scanf("%s",sPGuser); + printf(" Pass>"); + scanf("%s",sPGpass); + + /////////////////////////////// + ///////PGSQL Connect/////////// + /////////////////////////////// + PGconn *mPGconn=NULL; + mPGconn = PQsetdbLogin(sPGhost,sPGport, NULL, NULL, sPGdb, sPGuser, sPGpass); + + if (PQstatus(mPGconn) != CONNECTION_OK) + { + printf("Could not connect to Postgre database at [%s]: \n %s\n",sPGhost, PQerrorMessage(mPGconn)); + PQfinish(mPGconn); + return 1; + } + else + { + printf("Connected to Postgre database at [%s]\n", sPGhost); + printf(" PostgreSQL server ver: [%d]\n\n",PQserverVersion(mPGconn)); + } + + /// Set dummy notice processor + PQsetNoticeProcessor(mPGconn, pg_notice, mPGconn); + + /////////////////////////////// + ///////MySQL Connect/////////// + /////////////////////////////// + MYSQL *mysqlInit; + mysqlInit = mysql_init(NULL); + if (!mysqlInit) + { + printf( "Could not initialize Mysql connection\n" ); + return 1; + } + + char sMYhost[26], sMYdb[26], sMYuser[26], sMYpass[26]; + int iMYport; + printf("Mysql connection settings \n Host>"); + scanf("%s",sMYhost); + printf(" Port>"); + scanf("%d",&iMYport); + printf(" Base>"); + scanf("%s",sMYdb); + printf(" User>"); + scanf("%s",sMYuser); + printf(" Pass>"); + scanf("%s",sMYpass); + + mysql_options(mysqlInit,MYSQL_SET_CHARSET_NAME,"utf8"); + + MYSQL *mMysql; + mMysql = mysql_real_connect(mysqlInit, sMYhost, sMYuser, sMYpass, sMYdb, iMYport, NULL, 0); + + if (mMysql) + { + printf( "Connected to MySQL database at [%s] \n", sMYhost); + printf( " MySQL client library: [%s] \n", mysql_get_client_info()); + printf( " MySQL server ver: [%s] \n\n", mysql_get_server_info( mMysql)); + } + else + { + printf("Could not connect to MySQL database at [%s]:\n %s\n", sMYhost ,mysql_error(mysqlInit)); + mysql_close(mysqlInit); + return 1; + } + + ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + MYSQL_RES *result = NULL; + MYSQL_ROW row; + MYSQL_FIELD *fields = NULL; + uint64 rowCount = 0; + uint32 fieldCount =0; + result = mysql_list_tables( mMysql , NULL ); + rowCount = mysql_num_rows(result); + + /***********************/ + /* get list of tables */ + /***********************/ + T_TableList mTableList; + mTableList.reserve((size_t)rowCount); + while( (row = mysql_fetch_row(result)) !=NULL ) + { + for (uint32 i = 0;isecond->skillId != achievementCriteria->learn_skilline_spell.skillLine) + if(miscvalue1 && miscvalue1 != achievementCriteria->learn_skillline_spell.skillLine) continue; uint32 spellCount = 0; @@ -984,7 +977,7 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui skillIter != spellmgr.GetEndSkillLineAbilityMap(spellIter->first); ++skillIter) { - if(skillIter->second->skillId == achievementCriteria->learn_skilline_spell.skillLine) + if(skillIter->second->skillId == achievementCriteria->learn_skillline_spell.skillLine) spellCount++; } } @@ -1019,6 +1012,27 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui SetCriteriaProgress(achievementCriteria, 1, PROGRESS_ACCUMULATE); break; } + case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE: + { + if(miscvalue1 && miscvalue1 != achievementCriteria->learn_skill_line.skillLine) + continue; + + uint32 spellCount = 0; + for (PlayerSpellMap::const_iterator spellIter = GetPlayer()->GetSpellMap().begin(); + spellIter != GetPlayer()->GetSpellMap().end(); + ++spellIter) + { + for(SkillLineAbilityMap::const_iterator skillIter = spellmgr.GetBeginSkillLineAbilityMap(spellIter->first); + skillIter != spellmgr.GetEndSkillLineAbilityMap(spellIter->first); + ++skillIter) + { + if(skillIter->second->skillId == achievementCriteria->learn_skill_line.skillLine) + spellCount++; + } + } + SetCriteriaProgress(achievementCriteria, spellCount); + break; + } // std case: not exist in DBC, not triggered in code as result case ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALTH: case ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_SPELLPOWER: @@ -1069,7 +1083,6 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui case ACHIEVEMENT_CRITERIA_TYPE_QUEST_ABANDONED: case ACHIEVEMENT_CRITERIA_TYPE_FLIGHT_PATHS_TAKEN: case ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE: - case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE: case ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL: case ACHIEVEMENT_CRITERIA_TYPE_ACCEPTED_SUMMONINGS: case ACHIEVEMENT_CRITERIA_TYPE_TOTAL: @@ -1192,7 +1205,9 @@ bool AchievementMgr::IsCompletedCriteria(AchievementCriteriaEntry const* achieve case ACHIEVEMENT_CRITERIA_TYPE_FISH_IN_GAMEOBJECT: return progress->counter >= achievementCriteria->fish_in_gameobject.lootCount; case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS: - return progress->counter >= achievementCriteria->learn_skilline_spell.spellCount; + return progress->counter >= achievementCriteria->learn_skillline_spell.spellCount; + case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE: + return progress->counter >= achievementCriteria->learn_skill_line.spellCount; // handle all statistic-only criteria here case ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_BATTLEGROUND: diff --git a/src/game/AuctionHouseHandler.cpp b/src/game/AuctionHouseHandler.cpp index f957a7b60..d37b1b731 100644 --- a/src/game/AuctionHouseHandler.cpp +++ b/src/game/AuctionHouseHandler.cpp @@ -38,7 +38,7 @@ void WorldSession::HandleAuctionHelloOpcode( WorldPacket & recv_data ) uint64 guid; //NPC guid recv_data >> guid; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER); if (!unit) { sLog.outDebug( "WORLD: HandleAuctionHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -162,7 +162,7 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data ) if (!item || !bid || !etime) return; //check for cheaters - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER); if (!pCreature) { sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); @@ -286,7 +286,7 @@ void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data ) if (!auctionId || !price) return; //check for cheaters - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER); if (!pCreature) { sLog.outDebug( "WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); @@ -412,7 +412,7 @@ void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data ) recv_data >> auctionId; //sLog.outDebug( "Cancel AUCTION AuctionID: %u", auctionId); - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER); if (!pCreature) { sLog.outDebug( "WORLD: HandleAuctionRemoveItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); @@ -497,7 +497,7 @@ void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data ) outbiddedCount = 0; } - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER); if (!pCreature) { sLog.outDebug( "WORLD: HandleAuctionListBidderItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -546,7 +546,7 @@ void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data ) recv_data >> guid; recv_data >> listfrom; // not used in fact (this list not have page control in client) - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER); if (!pCreature) { sLog.outDebug( "WORLD: HandleAuctionListOwnerItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -593,7 +593,7 @@ void WorldSession::HandleAuctionListItems( WorldPacket & recv_data ) recv_data >> auctionSlotID >> auctionMainCategory >> auctionSubCategory; recv_data >> quality >> usable; - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER); if (!pCreature) { sLog.outDebug( "WORLD: HandleAuctionListItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp index f38d8ac09..96d145c35 100644 --- a/src/game/BattleGround.cpp +++ b/src/game/BattleGround.cpp @@ -266,9 +266,9 @@ void BattleGround::Update(uint32 diff) if (!plr) continue; - if (!sh) + if (!sh && plr->IsInWorld()) { - sh = ObjectAccessor::GetCreature(*plr, itr->first); + sh = plr->GetMap()->GetCreature(itr->first); // only for visual effect if (sh) sh->CastSpell(sh, SPELL_SPIRIT_HEAL, true); // Spirit Heal, effect 117 diff --git a/src/game/BattleGroundHandler.cpp b/src/game/BattleGroundHandler.cpp index 8a81f748e..d70dc103a 100644 --- a/src/game/BattleGroundHandler.cpp +++ b/src/game/BattleGroundHandler.cpp @@ -40,7 +40,7 @@ void WorldSession::HandleBattleGroundHelloOpcode( WorldPacket & recv_data ) recv_data >> guid; sLog.outDebug( "WORLD: Recvd CMSG_BATTLEMASTER_HELLO Message from: " I64FMT, guid); - Creature *unit = ObjectAccessor::GetCreature(*_player, guid); + Creature *unit = GetPlayer()->GetMap()->GetCreature(guid); if (!unit) return; @@ -591,7 +591,7 @@ void WorldSession::HandleAreaSpiritHealerQueryOpcode( WorldPacket & recv_data ) uint64 guid; recv_data >> guid; - Creature *unit = ObjectAccessor::GetCreature(*_player, guid); + Creature *unit = GetPlayer()->GetMap()->GetCreature(guid); if (!unit) return; @@ -614,7 +614,7 @@ void WorldSession::HandleAreaSpiritHealerQueueOpcode( WorldPacket & recv_data ) uint64 guid; recv_data >> guid; - Creature *unit = ObjectAccessor::GetCreature(*_player, guid); + Creature *unit = GetPlayer()->GetMap()->GetCreature(guid); if (!unit) return; @@ -643,7 +643,7 @@ void WorldSession::HandleBattleGroundArenaJoin( WorldPacket & recv_data ) recv_data >> guid >> arenaslot >> asGroup >> isRated; - Creature *unit = ObjectAccessor::GetCreature(*_player, guid); + Creature *unit = GetPlayer()->GetMap()->GetCreature(guid); if (!unit) return; diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp index b79094402..86d7afff9 100644 --- a/src/game/Chat.cpp +++ b/src/game/Chat.cpp @@ -1316,7 +1316,7 @@ GameObject* ChatHandler::GetObjectGlobalyWithGuidOrNearWithDbGuid(uint32 lowguid Player* pl = m_session->GetPlayer(); - GameObject* obj = ObjectAccessor::GetGameObject(*pl, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_GAMEOBJECT)); + GameObject* obj = pl->GetMap()->GetGameObject(MAKE_NEW_GUID(lowguid, entry, HIGHGUID_GAMEOBJECT)); if(!obj && objmgr.GetGOData(lowguid)) // guid is DB guid of object { diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index dc7ad3fec..a63ca1136 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -910,10 +910,11 @@ void CreatureEventAI::ProcessAction(uint16 type, uint32 param1, uint32 param2, u else { //if not available, use pActionInvoker - Unit* pTarget = GetTargetByType(param2, pActionInvoker); - - if (Player* pPlayer = pTarget->GetCharmerOrOwnerPlayerOrPlayerItself()) - pPlayer->RewardPlayerAndGroupAtEvent(param1, m_creature); + if (Unit* pTarget = GetTargetByType(param2, pActionInvoker)) + { + if (Player* pPlayer = pTarget->GetCharmerOrOwnerPlayerOrPlayerItself()) + pPlayer->RewardPlayerAndGroupAtEvent(param1, m_creature); + } } } break; diff --git a/src/game/CreatureEventAIMgr.cpp b/src/game/CreatureEventAIMgr.cpp index b0e6f1a67..af4d21594 100644 --- a/src/game/CreatureEventAIMgr.cpp +++ b/src/game/CreatureEventAIMgr.cpp @@ -25,6 +25,7 @@ #include "ProgressBar.h" #include "Policies/SingletonImp.h" #include "ObjectDefines.h" +#include "GridDefines.h" INSTANTIATE_SINGLETON_1(CreatureEventAIMgr); @@ -72,16 +73,22 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts() if (temp.SoundId) { - if (!GetSoundEntriesStore()->LookupEntry(temp.SoundId)) - sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` has soundId %u but sound does not exist.",i,temp.SoundId); + if (!sSoundEntriesStore.LookupEntry(temp.SoundId)) + sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` has Sound %u but sound does not exist.",i,temp.SoundId); } if (!GetLanguageDescByID(temp.Language)) sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` using Language %u but Language does not exist.",i,temp.Language); - if (temp.Type > CHAT_TYPE_BOSS_WHISPER) + if (temp.Type > CHAT_TYPE_ZONE_YELL) sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` has Type %u but this Chat Type does not exist.",i,temp.Type); + if (temp.Emote) + { + if (!sEmotesStore.LookupEntry(temp.Emote)) + sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` has Emote %u but emote does not exist.",i,temp.Emote); + } + m_CreatureEventAI_TextMap[i] = temp; ++count; } while (result->NextRow()); @@ -90,7 +97,8 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts() sLog.outString(); sLog.outString(">> Loaded %u additional CreatureEventAI Texts data.", count); - }else + } + else { barGoLink bar(1); bar.step(); @@ -128,6 +136,12 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Summons() temp.orientation = fields[4].GetFloat(); temp.SpawnTimeSecs = fields[5].GetUInt32(); + if(!MaNGOS::IsValidMapCoord(temp.position_x,temp.position_y,temp.position_z,temp.orientation)) + { + sLog.outErrorDb("CreatureEventAI: Summon id %u have wrong coordinates (%f,%f,%f,%f), skipping.", i,temp.position_x,temp.position_y,temp.position_z,temp.orientation); + continue; + } + //Add to map m_CreatureEventAI_Summon_Map[i] = temp; ++Count; diff --git a/src/game/DBCStructure.h b/src/game/DBCStructure.h index 22f05f330..994458e71 100644 --- a/src/game/DBCStructure.h +++ b/src/game/DBCStructure.h @@ -419,7 +419,7 @@ struct AchievementCriteriaEntry { uint32 skillLine; // 3 uint32 spellCount; // 4 - } learn_skilline_spell; + } learn_skillline_spell; // ACHIEVEMENT_CRITERIA_TYPE_WIN_DUEL = 76 struct diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index e5f3886d9..8618efbb9 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -624,11 +624,6 @@ void GameObject::DeleteFromDB() WorldDatabase.PExecuteLog("DELETE FROM game_event_gameobject WHERE guid = '%u'", m_DBTableGuid); } -GameObject* GameObject::GetGameObject(WorldObject& object, uint64 guid) -{ - return ObjectAccessor::GetGameObject(object,guid); -} - GameObjectInfo const *GameObject::GetGOInfo() const { return m_goInfo; diff --git a/src/game/GameObject.h b/src/game/GameObject.h index d729799d7..ad8c8d8ea 100644 --- a/src/game/GameObject.h +++ b/src/game/GameObject.h @@ -427,7 +427,6 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject bool Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 animprogress, uint32 go_state); void Update(uint32 p_time); - static GameObject* GetGameObject(WorldObject& object, uint64 guid); GameObjectInfo const* GetGOInfo() const; bool IsTransport() const; diff --git a/src/game/GuildHandler.cpp b/src/game/GuildHandler.cpp index 540ea9e96..934a77b70 100644 --- a/src/game/GuildHandler.cpp +++ b/src/game/GuildHandler.cpp @@ -782,7 +782,7 @@ void WorldSession::HandleGuildSaveEmblemOpcode(WorldPacket& recvPacket) recvPacket >> vendorGuid; - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, vendorGuid,UNIT_NPC_FLAG_TABARDDESIGNER); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorGuid,UNIT_NPC_FLAG_TABARDDESIGNER); if (!pCreature) { //"That's not an emblem vendor!" @@ -905,7 +905,7 @@ void WorldSession::HandleGuildBankQuery( WorldPacket & recv_data ) uint8 unk; recv_data >> GoGuid >> unk; - if (!objmgr.IsGameObjectOfTypeInRange(_player, GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) return; if (uint32 GuildId = GetPlayer()->GetGuildId()) @@ -929,7 +929,7 @@ void WorldSession::HandleGuildBankTabColon( WorldPacket & recv_data ) uint8 TabId,unk1; recv_data >> GoGuid >> TabId >> unk1; - if (!objmgr.IsGameObjectOfTypeInRange(_player, GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) return; uint32 GuildId = GetPlayer()->GetGuildId(); @@ -958,7 +958,7 @@ void WorldSession::HandleGuildBankDeposit( WorldPacket & recv_data ) if (!money) return; - if (!objmgr.IsGameObjectOfTypeInRange(_player, GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) return; uint32 GuildId = GetPlayer()->GetGuildId(); @@ -1006,7 +1006,7 @@ void WorldSession::HandleGuildBankWithdraw( WorldPacket & recv_data ) if (!money) return; - if (!objmgr.IsGameObjectOfTypeInRange(_player, GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) return; uint32 GuildId = GetPlayer()->GetGuildId(); @@ -1107,7 +1107,7 @@ void WorldSession::HandleGuildBankDepositItem( WorldPacket & recv_data ) return; } - if (!objmgr.IsGameObjectOfTypeInRange(_player, GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) return; uint32 GuildId = GetPlayer()->GetGuildId(); @@ -1562,7 +1562,7 @@ void WorldSession::HandleGuildBankBuyTab( WorldPacket & recv_data ) recv_data >> GoGuid; recv_data >> TabId; - if (!objmgr.IsGameObjectOfTypeInRange(_player, GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) return; uint32 GuildId = GetPlayer()->GetGuildId(); @@ -1619,7 +1619,7 @@ void WorldSession::HandleGuildBankModifyTab( WorldPacket & recv_data ) if(IconIndex.empty()) return; - if (!objmgr.IsGameObjectOfTypeInRange(_player, GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK)) return; uint32 GuildId = GetPlayer()->GetGuildId(); diff --git a/src/game/ItemHandler.cpp b/src/game/ItemHandler.cpp index 0dec43d54..7818e060c 100644 --- a/src/game/ItemHandler.cpp +++ b/src/game/ItemHandler.cpp @@ -517,7 +517,7 @@ void WorldSession::HandleSellItemOpcode( WorldPacket & recv_data ) if(!itemguid) return; - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, vendorguid,UNIT_NPC_FLAG_VENDOR); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorguid,UNIT_NPC_FLAG_VENDOR); if (!pCreature) { sLog.outDebug( "WORLD: HandleSellItemOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid)) ); @@ -622,7 +622,7 @@ void WorldSession::HandleBuybackItem(WorldPacket & recv_data) recv_data >> vendorguid >> slot; - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, vendorguid,UNIT_NPC_FLAG_VENDOR); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorguid,UNIT_NPC_FLAG_VENDOR); if (!pCreature) { sLog.outDebug( "WORLD: HandleBuybackItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid)) ); @@ -709,7 +709,7 @@ void WorldSession::SendListInventory( uint64 vendorguid ) { sLog.outDebug( "WORLD: Sent SMSG_LIST_INVENTORY" ); - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, vendorguid,UNIT_NPC_FLAG_VENDOR); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorguid,UNIT_NPC_FLAG_VENDOR); if (!pCreature) { sLog.outDebug( "WORLD: SendListInventory - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid)) ); @@ -836,7 +836,7 @@ void WorldSession::HandleBuyBankSlotOpcode(WorldPacket& recvPacket) recvPacket >> guid; // cheating protection - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_BANKER); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_BANKER); if(!pCreature) { sLog.outDebug( "WORLD: HandleBuyBankSlotOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); diff --git a/src/game/Level1.cpp b/src/game/Level1.cpp index d98c0fe83..75a891abd 100644 --- a/src/game/Level1.cpp +++ b/src/game/Level1.cpp @@ -103,7 +103,7 @@ bool ChatHandler::HandleNpcWhisperCommand(const char* args) char* text = strtok(NULL, ""); uint64 guid = m_session->GetPlayer()->GetSelection(); - Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid); + Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(guid); if(!pCreature || !receiver_str || !text) { diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index a5186f2c9..cc8f1c8e7 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -506,7 +506,7 @@ bool ChatHandler::HandleGameObjectTargetCommand(const char* args) return false; } - GameObject* target = ObjectAccessor::GetGameObject(*m_session->GetPlayer(),MAKE_NEW_GUID(lowguid,id,HIGHGUID_GAMEOBJECT)); + GameObject* target = m_session->GetPlayer()->GetMap()->GetGameObject(MAKE_NEW_GUID(lowguid,id,HIGHGUID_GAMEOBJECT)); PSendSysMessage(LANG_GAMEOBJECT_DETAIL, lowguid, goI->name, lowguid, id, x, y, z, mapid, o); @@ -1332,7 +1332,7 @@ bool ChatHandler::HandleNpcDeleteCommand(const char* args) return false; if (CreatureData const* cr_data = objmgr.GetCreatureData(lowguid)) - unit = ObjectAccessor::GetCreature(*m_session->GetPlayer(), MAKE_NEW_GUID(lowguid, cr_data->id, HIGHGUID_UNIT)); + unit = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid, cr_data->id, HIGHGUID_UNIT)); } else unit = getSelectedCreature(); @@ -2600,7 +2600,7 @@ bool ChatHandler::HandleWpAddCommand(const char* args) return false; } - target = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(lowguid,data->id,HIGHGUID_UNIT)); + target = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid,data->id,HIGHGUID_UNIT)); if(!target) { PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, lowguid); @@ -2634,7 +2634,7 @@ bool ChatHandler::HandleWpAddCommand(const char* args) return false; } - target = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(lowguid,data->id,HIGHGUID_UNIT)); + target = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid,data->id,HIGHGUID_UNIT)); if(!target || target->isPet()) { PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); @@ -2849,7 +2849,7 @@ bool ChatHandler::HandleWpModifyCommand(const char* args) return false; } - Creature* npcCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), MAKE_NEW_GUID(lowguid, data->id, HIGHGUID_UNIT)); + Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid, data->id, HIGHGUID_UNIT)); if( !npcCreature ) { @@ -2928,13 +2928,13 @@ bool ChatHandler::HandleWpModifyCommand(const char* args) return false; } - Creature* npcCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), MAKE_NEW_GUID(lowguid, data->id, HIGHGUID_UNIT)); + Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid, data->id, HIGHGUID_UNIT)); // wpCreature Creature* wpCreature = NULL; if( wpGuid != 0 ) { - wpCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); + wpCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); wpCreature->DeleteFromDB(); wpCreature->CleanupsBeforeDelete(); wpCreature->AddObjectToRemoveList(); @@ -2989,7 +2989,7 @@ bool ChatHandler::HandleWpModifyCommand(const char* args) return false; } - Creature* npcCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), MAKE_NEW_GUID(lowguid, data->id, HIGHGUID_UNIT)); + Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid, data->id, HIGHGUID_UNIT)); // wpCreature Creature* wpCreature = NULL; @@ -2998,7 +2998,7 @@ bool ChatHandler::HandleWpModifyCommand(const char* args) // Respawn the owner of the waypoints if( wpGuid != 0 ) { - wpCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); + wpCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); wpCreature->DeleteFromDB(); wpCreature->CleanupsBeforeDelete(); wpCreature->AddObjectToRemoveList(); @@ -3061,7 +3061,7 @@ bool ChatHandler::HandleWpModifyCommand(const char* args) WaypointMgr.SetNodeText(lowguid, point, show_str, arg_str); - Creature* npcCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), MAKE_NEW_GUID(lowguid, data->id, HIGHGUID_UNIT)); + Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid, data->id, HIGHGUID_UNIT)); if(npcCreature) { npcCreature->SetDefaultMovementType(WAYPOINT_MOTION_TYPE); @@ -3161,7 +3161,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args) return false; } - target = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(lowguid,data->id,HIGHGUID_UNIT)); + target = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid,data->id,HIGHGUID_UNIT)); if(!target) { @@ -3232,7 +3232,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args) uint32 model2 = fields[11].GetUInt32(); // Get the creature for which we read the waypoint - Creature* wpCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(creGUID,VISUAL_WAYPOINT,HIGHGUID_UNIT)); + Creature* wpCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(creGUID,VISUAL_WAYPOINT,HIGHGUID_UNIT)); PSendSysMessage(LANG_WAYPOINT_INFO_TITLE, point, (wpCreature ? wpCreature->GetName() : ""), creGUID); PSendSysMessage(LANG_WAYPOINT_INFO_WAITTIME, waittime); @@ -3269,7 +3269,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args) { Field *fields = result2->Fetch(); uint32 wpguid = fields[0].GetUInt32(); - Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(wpguid,VISUAL_WAYPOINT,HIGHGUID_UNIT)); + Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpguid,VISUAL_WAYPOINT,HIGHGUID_UNIT)); if(!pCreature) { @@ -3468,10 +3468,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args) { Field *fields = result->Fetch(); uint32 guid = fields[0].GetUInt32(); - Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(guid,VISUAL_WAYPOINT,HIGHGUID_UNIT)); - - //Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid); - + Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(guid,VISUAL_WAYPOINT,HIGHGUID_UNIT)); if(!pCreature) { PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, guid); diff --git a/src/game/LootHandler.cpp b/src/game/LootHandler.cpp index 254f1978f..6d3191a27 100644 --- a/src/game/LootHandler.cpp +++ b/src/game/LootHandler.cpp @@ -44,8 +44,7 @@ void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data ) if (IS_GAMEOBJECT_GUID(lguid)) { - GameObject *go = - ObjectAccessor::GetGameObject(*player, lguid); + GameObject *go = player->GetMap()->GetGameObject(lguid); // not check distance for GO in case owned GO (fishing bobber case, for example) or Fishing hole GO if (!go || (go->GetOwnerGUID() != _player->GetGUID() && go->GetGoType() != GAMEOBJECT_TYPE_FISHINGHOLE) && !go->IsWithinDistInMap(_player,INTERACTION_DISTANCE)) @@ -70,8 +69,7 @@ void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data ) } else { - Creature* pCreature = - ObjectAccessor::GetCreature(*player, lguid); + Creature* pCreature = GetPlayer()->GetMap()->GetCreature(lguid); bool ok_loot = pCreature && pCreature->isAlive() == (player->getClass()==CLASS_ROGUE && pCreature->lootForPickPocketed); @@ -163,7 +161,7 @@ void WorldSession::HandleLootMoneyOpcode( WorldPacket & /*recv_data*/ ) { case HIGHGUID_GAMEOBJECT: { - GameObject *pGameObject = ObjectAccessor::GetGameObject(*GetPlayer(), guid); + GameObject *pGameObject = GetPlayer()->GetMap()->GetGameObject(guid); // not check distance for GO in case owned GO (fishing bobber case, for example) if( pGameObject && (pGameObject->GetOwnerGUID()==_player->GetGUID() || pGameObject->IsWithinDistInMap(_player,INTERACTION_DISTANCE)) ) @@ -188,7 +186,7 @@ void WorldSession::HandleLootMoneyOpcode( WorldPacket & /*recv_data*/ ) } case HIGHGUID_UNIT: { - Creature* pCreature = ObjectAccessor::GetCreature(*GetPlayer(), guid); + Creature* pCreature = GetPlayer()->GetMap()->GetCreature(guid); bool ok_loot = pCreature && pCreature->isAlive() == (player->getClass()==CLASS_ROGUE && pCreature->lootForPickPocketed); @@ -276,10 +274,12 @@ void WorldSession::DoLootRelease( uint64 lguid ) player->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_LOOTING); + if(!player->IsInWorld()) + return; + if (IS_GAMEOBJECT_GUID(lguid)) { - GameObject *go = - ObjectAccessor::GetGameObject(*player, lguid); + GameObject *go = GetPlayer()->GetMap()->GetGameObject(lguid); // not check distance for GO in case owned GO (fishing bobber case, for example) or Fishing hole GO if (!go || (go->GetOwnerGUID() != _player->GetGUID() && go->GetGoType() != GAMEOBJECT_TYPE_FISHINGHOLE) && !go->IsWithinDistInMap(_player,INTERACTION_DISTANCE)) @@ -401,7 +401,7 @@ void WorldSession::DoLootRelease( uint64 lguid ) } else { - Creature* pCreature = ObjectAccessor::GetCreature(*player, lguid); + Creature* pCreature = GetPlayer()->GetMap()->GetCreature(lguid); bool ok_loot = pCreature && pCreature->isAlive() == (player->getClass()==CLASS_ROGUE && pCreature->lootForPickPocketed); if ( !ok_loot || !pCreature->IsWithinDistInMap(_player,INTERACTION_DISTANCE) ) @@ -458,7 +458,7 @@ void WorldSession::HandleLootMasterGiveOpcode( WorldPacket & recv_data ) if(IS_CREATURE_GUID(GetPlayer()->GetLootGUID())) { - Creature *pCreature = ObjectAccessor::GetCreature(*GetPlayer(), lootguid); + Creature *pCreature = GetPlayer()->GetMap()->GetCreature(lootguid); if(!pCreature) return; @@ -466,7 +466,7 @@ void WorldSession::HandleLootMasterGiveOpcode( WorldPacket & recv_data ) } else if(IS_GAMEOBJECT_GUID(GetPlayer()->GetLootGUID())) { - GameObject *pGO = ObjectAccessor::GetGameObject(*GetPlayer(), lootguid); + GameObject *pGO = GetPlayer()->GetMap()->GetGameObject(lootguid); if(!pGO) return; diff --git a/src/game/Mail.cpp b/src/game/Mail.cpp index b385043e4..d671aeb69 100644 --- a/src/game/Mail.cpp +++ b/src/game/Mail.cpp @@ -52,7 +52,7 @@ void WorldSession::HandleSendMail(WorldPacket & recv_data ) recv_data >> mailbox; recv_data >> receiver; - if (!objmgr.IsGameObjectOfTypeInRange(_player, mailbox, GAMEOBJECT_TYPE_MAILBOX)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; // recheck @@ -278,7 +278,7 @@ void WorldSession::HandleMarkAsRead(WorldPacket & recv_data ) uint32 mailId; recv_data >> mailbox; - if (!objmgr.IsGameObjectOfTypeInRange(_player, mailbox, GAMEOBJECT_TYPE_MAILBOX)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; recv_data >> mailId; @@ -305,7 +305,7 @@ void WorldSession::HandleMailDelete(WorldPacket & recv_data ) recv_data >> mailbox; recv_data >> mailId; - if (!objmgr.IsGameObjectOfTypeInRange(_player, mailbox, GAMEOBJECT_TYPE_MAILBOX)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; Player* pl = _player; @@ -324,7 +324,7 @@ void WorldSession::HandleReturnToSender(WorldPacket & recv_data ) uint32 mailId; recv_data >> mailbox; - if (!objmgr.IsGameObjectOfTypeInRange(_player, mailbox, GAMEOBJECT_TYPE_MAILBOX)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; recv_data >> mailId; @@ -425,7 +425,7 @@ void WorldSession::HandleTakeItem(WorldPacket & recv_data ) uint32 itemId; recv_data >> mailbox; - if (!objmgr.IsGameObjectOfTypeInRange(_player, mailbox, GAMEOBJECT_TYPE_MAILBOX)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; recv_data >> mailId; @@ -520,7 +520,7 @@ void WorldSession::HandleTakeMoney(WorldPacket & recv_data ) recv_data >> mailbox; recv_data >> mailId; - if (!objmgr.IsGameObjectOfTypeInRange(_player, mailbox, GAMEOBJECT_TYPE_MAILBOX)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; Player *pl = _player; @@ -554,7 +554,7 @@ void WorldSession::HandleGetMail(WorldPacket & recv_data ) uint64 mailbox; recv_data >> mailbox; - if (!objmgr.IsGameObjectOfTypeInRange(_player, mailbox, GAMEOBJECT_TYPE_MAILBOX)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; Player* pl = _player; @@ -691,7 +691,7 @@ void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data ) recv_data >> mailbox >> mailId; - if (!objmgr.IsGameObjectOfTypeInRange(_player, mailbox, GAMEOBJECT_TYPE_MAILBOX)) + if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX)) return; Player *pl = _player; diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 0db29f022..7de4dfa3f 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -2531,3 +2531,45 @@ void BattleGroundMap::UnloadAll(bool pForce) Map::UnloadAll(pForce); } + +Creature* +Map::GetCreature(uint64 guid) +{ + Creature * ret = ObjectAccessor::GetObjectInWorld(guid, (Creature*)NULL); + if(!ret) + return NULL; + + if(ret->GetMapId() != GetId()) + return NULL; + + if(ret->GetInstanceId() != GetInstanceId()) + return NULL; + + return ret; +} + +GameObject* +Map::GetGameObject(uint64 guid) +{ + GameObject * ret = ObjectAccessor::GetObjectInWorld(guid, (GameObject*)NULL); + if(!ret) + return NULL; + if(ret->GetMapId() != GetId()) + return NULL; + if(ret->GetInstanceId() != GetInstanceId()) + return NULL; + return ret; +} + +DynamicObject* +Map::GetDynamicObject(uint64 guid) +{ + DynamicObject * ret = ObjectAccessor::GetObjectInWorld(guid, (DynamicObject*)NULL); + if(!ret) + return NULL; + if(ret->GetMapId() != GetId()) + return NULL; + if(ret->GetInstanceId() != GetInstanceId()) + return NULL; + return ret; +} diff --git a/src/game/Map.h b/src/game/Map.h index 5388d3963..2b1f1c025 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -402,6 +402,10 @@ class MANGOS_DLL_SPEC Map : public GridRefManager, public MaNGOS::Obj void RemoveFromActive(T* obj) { RemoveFromActiveHelper(obj); } void RemoveFromActive(Creature* obj); + + Creature* GetCreature(uint64 guid); + GameObject* GetGameObject(uint64 guid); + DynamicObject* GetDynamicObject(uint64 guid); private: void LoadMapAndVMap(int gx, int gy); void LoadVMap(int gx, int gy); diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index 18b27b562..ad63584b1 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -43,7 +43,7 @@ void WorldSession::HandleTabardVendorActivateOpcode( WorldPacket & recv_data ) uint64 guid; recv_data >> guid; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_TABARDDESIGNER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_TABARDDESIGNER); if (!unit) { sLog.outDebug( "WORLD: HandleTabardVendorActivateOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -74,7 +74,7 @@ void WorldSession::HandleBankerActivateOpcode( WorldPacket & recv_data ) recv_data >> guid; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_BANKER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_BANKER); if (!unit) { sLog.outDebug( "WORLD: HandleBankerActivateOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -115,7 +115,7 @@ void WorldSession::SendTrainerList( uint64 guid, const std::string& strTitle ) { sLog.outDebug( "WORLD: SendTrainerList" ); - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_TRAINER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_TRAINER); if (!unit) { sLog.outDebug( "WORLD: SendTrainerList - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -200,7 +200,7 @@ void WorldSession::HandleTrainerBuySpellOpcode( WorldPacket & recv_data ) recv_data >> guid >> spellId; sLog.outDebug( "WORLD: Received CMSG_TRAINER_BUY_SPELL NpcGUID=%u, learn spell id is: %u",uint32(GUID_LOPART(guid)), spellId ); - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_TRAINER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_TRAINER); if (!unit) { sLog.outDebug( "WORLD: HandleTrainerBuySpellOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -266,7 +266,7 @@ void WorldSession::HandleGossipHelloOpcode( WorldPacket & recv_data ) uint64 guid; recv_data >> guid; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_NONE); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE); if (!unit) { sLog.outDebug( "WORLD: HandleGossipHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -324,7 +324,7 @@ void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) sLog.outBasic("string read: %s", code.c_str()); } - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_NONE); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE); if (!unit) { sLog.outDebug( "WORLD: HandleGossipSelectOptionOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -357,7 +357,7 @@ void WorldSession::HandleSpiritHealerActivateOpcode( WorldPacket & recv_data ) recv_data >> guid; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_SPIRITHEALER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_SPIRITHEALER); if (!unit) { sLog.outDebug( "WORLD: HandleSpiritHealerActivateOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -416,7 +416,7 @@ void WorldSession::HandleBinderActivateOpcode( WorldPacket & recv_data ) if(!GetPlayer()->isAlive()) return; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, npcGUID,UNIT_NPC_FLAG_INNKEEPER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID,UNIT_NPC_FLAG_INNKEEPER); if (!unit) { sLog.outDebug( "WORLD: HandleBinderActivateOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) ); @@ -484,7 +484,7 @@ void WorldSession::HandleListStabledPetsOpcode( WorldPacket & recv_data ) recv_data >> npcGUID; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, npcGUID, UNIT_NPC_FLAG_STABLEMASTER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER); if (!unit) { sLog.outDebug( "WORLD: HandleListStabledPetsOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) ); @@ -563,7 +563,7 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data ) if(!GetPlayer()->isAlive()) return; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, npcGUID, UNIT_NPC_FLAG_STABLEMASTER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER); if (!unit) { sLog.outDebug( "WORLD: HandleStablePet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) ); @@ -630,7 +630,7 @@ void WorldSession::HandleUnstablePet( WorldPacket & recv_data ) recv_data >> npcGUID >> petnumber; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, npcGUID, UNIT_NPC_FLAG_STABLEMASTER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER); if (!unit) { sLog.outDebug( "WORLD: HandleUnstablePet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) ); @@ -689,7 +689,7 @@ void WorldSession::HandleBuyStableSlot( WorldPacket & recv_data ) recv_data >> npcGUID; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, npcGUID, UNIT_NPC_FLAG_STABLEMASTER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER); if (!unit) { sLog.outDebug( "WORLD: HandleBuyStableSlot - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) ); @@ -735,7 +735,7 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data ) recv_data >> npcGUID >> pet_number; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, npcGUID, UNIT_NPC_FLAG_STABLEMASTER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER); if (!unit) { sLog.outDebug( "WORLD: HandleStableSwapPet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) ); @@ -792,7 +792,7 @@ void WorldSession::HandleRepairItemOpcode( WorldPacket & recv_data ) recv_data >> npcGUID >> itemGUID >> guildBank; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, npcGUID, UNIT_NPC_FLAG_REPAIR); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_REPAIR); if (!unit) { sLog.outDebug( "WORLD: HandleRepairItemOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) ); diff --git a/src/game/ObjectAccessor.cpp b/src/game/ObjectAccessor.cpp index 68807c6ba..da9dd61c4 100644 --- a/src/game/ObjectAccessor.cpp +++ b/src/game/ObjectAccessor.cpp @@ -46,52 +46,6 @@ INSTANTIATE_CLASS_MUTEX(ObjectAccessor, ZThread::FastMutex); ObjectAccessor::ObjectAccessor() {} ObjectAccessor::~ObjectAccessor() {} -Creature* -ObjectAccessor::GetNPCIfCanInteractWith(Player const &player, uint64 guid, uint32 npcflagmask) -{ - // unit checks - if (!guid) - return NULL; - - // exist - Creature *unit = GetCreature(player, guid); - if (!unit) - return NULL; - - // player check - if(!player.CanInteractWithNPCs(!unit->isSpiritService())) - return NULL; - - // appropriate npc type - if(npcflagmask && !unit->HasFlag( UNIT_NPC_FLAGS, npcflagmask )) - return NULL; - - // alive or spirit healer - if(!unit->isAlive() && (!unit->isSpiritService() || player.isAlive() )) - return NULL; - - // not allow interaction under control - if(unit->GetCharmerOrOwnerGUID()) - return NULL; - - // not enemy - if( unit->IsHostileTo(&player)) - return NULL; - - // not unfriendly - if(FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(unit->getFaction())) - if(factionTemplate->faction) - if(FactionEntry const* faction = sFactionStore.LookupEntry(factionTemplate->faction)) - if(faction->reputationListID >= 0 && player.GetReputationMgr().GetRank(faction) <= REP_UNFRIENDLY) - return NULL; - - // not too far - if(!unit->IsWithinDistInMap(&player,INTERACTION_DISTANCE)) - return NULL; - - return unit; -} - Creature* ObjectAccessor::GetCreatureOrPetOrVehicle(WorldObject const &u, uint64 guid) { @@ -101,23 +55,7 @@ ObjectAccessor::GetCreatureOrPetOrVehicle(WorldObject const &u, uint64 guid) if(Creature *unit = GetVehicle(guid)) return unit; - return GetCreature(u, guid); -} - -Creature* -ObjectAccessor::GetCreature(WorldObject const &u, uint64 guid) -{ - Creature * ret = GetObjectInWorld(guid, (Creature*)NULL); - if(!ret) - return NULL; - - if(ret->GetMapId() != u.GetMapId()) - return NULL; - - if(ret->GetInstanceId() != u.GetInstanceId()) - return NULL; - - return ret; + return u.GetMap()->GetCreature(guid); } Unit* @@ -163,13 +101,13 @@ Object* ObjectAccessor::GetObjectByTypeMask(WorldObject const &p, uint64 guid, u if(typemask & TYPEMASK_GAMEOBJECT) { - obj = GetGameObject(p,guid); + obj = p.GetMap()->GetGameObject(guid); if(obj) return obj; } if(typemask & TYPEMASK_DYNAMICOBJECT) { - obj = GetDynamicObject(p,guid); + obj = p.GetMap()->GetDynamicObject(guid); if(obj) return obj; } @@ -182,32 +120,6 @@ Object* ObjectAccessor::GetObjectByTypeMask(WorldObject const &p, uint64 guid, u return NULL; } -GameObject* -ObjectAccessor::GetGameObject(WorldObject const &u, uint64 guid) -{ - GameObject * ret = GetObjectInWorld(guid, (GameObject*)NULL); - if(!ret) - return NULL; - if(ret->GetMapId() != u.GetMapId()) - return NULL; - if(ret->GetInstanceId() != u.GetInstanceId()) - return NULL; - return ret; -} - -DynamicObject* -ObjectAccessor::GetDynamicObject(WorldObject const &u, uint64 guid) -{ - DynamicObject * ret = GetObjectInWorld(guid, (DynamicObject*)NULL); - if(!ret) - return NULL; - if(ret->GetMapId() != u.GetMapId()) - return NULL; - if(ret->GetInstanceId() != u.GetInstanceId()) - return NULL; - return ret; -} - Player* ObjectAccessor::FindPlayer(uint64 guid) { diff --git a/src/game/ObjectAccessor.h b/src/game/ObjectAccessor.h index 270a27e9b..f29dceb68 100644 --- a/src/game/ObjectAccessor.h +++ b/src/game/ObjectAccessor.h @@ -137,14 +137,10 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::SingletonGetGoType() == type) - { - // TODO: find out how the client calculates the maximal usage distance to spellless working - // gameobjects like guildbanks and mailboxes - 10.0 is a just an abitrary choosen number - if (go->IsWithinDistInMap(player, 10.0f)) - return true; - sLog.outError("IsGameObjectOfTypeInRange: GameObject '%s' [GUID: %u] is too far away from player %s [GUID: %u] to be used by him (distance=%f, maximal 10 is allowed)", go->GetGOInfo()->name, - go->GetGUIDLow(), player->GetName(), player->GetGUIDLow(), go->GetDistance(player)); - } - } - return false; -} - GossipText const *ObjectMgr::GetGossipText(uint32 Text_ID) const { GossipTextMap::const_iterator itr = mGossipText.find(Text_ID); diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index adf68a5c6..8bde701a1 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -417,8 +417,6 @@ class ObjectMgr return mGameObjectForQuestSet.find(entry) != mGameObjectForQuestSet.end(); } - bool IsGameObjectOfTypeInRange(Player *player, uint64 guid, GameobjectTypes type) const; - GossipText const* GetGossipText(uint32 Text_ID) const; WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team); diff --git a/src/game/PetitionsHandler.cpp b/src/game/PetitionsHandler.cpp index a3d50441f..0087253a1 100644 --- a/src/game/PetitionsHandler.cpp +++ b/src/game/PetitionsHandler.cpp @@ -80,7 +80,7 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data) sLog.outDebug("Petitioner with GUID %u tried sell petition: name %s", GUID_LOPART(guidNPC), name.c_str()); // prevent cheating - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guidNPC,UNIT_NPC_FLAG_PETITIONER); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guidNPC,UNIT_NPC_FLAG_PETITIONER); if (!pCreature) { sLog.outDebug("WORLD: HandlePetitionBuyOpcode - Unit (GUID: %u) not found or you can't interact with him.", GUID_LOPART(guidNPC)); @@ -904,7 +904,7 @@ void WorldSession::HandlePetitionShowListOpcode(WorldPacket & recv_data) void WorldSession::SendPetitionShowList(uint64 guid) { - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_PETITIONER); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_PETITIONER); if (!pCreature) { sLog.outDebug("WORLD: HandlePetitionShowListOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid))); diff --git a/src/game/Player.cpp b/src/game/Player.cpp index a4a77ba4f..2ece81aee 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -1592,7 +1592,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati // ObjectAccessor won't find the flag. if (duel && GetMapId()!=mapid) { - GameObject* obj = ObjectAccessor::GetGameObject(*this, GetUInt64Value(PLAYER_DUEL_ARBITER)); + GameObject* obj = GetMap()->GetGameObject(GetUInt64Value(PLAYER_DUEL_ARBITER)); if (obj) DuelComplete(DUEL_FLED); } @@ -1947,6 +1947,88 @@ bool Player::CanInteractWithNPCs(bool alive) const return true; } +Creature* +Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask) +{ + // unit checks + if (!guid) + return NULL; + + if(!IsInWorld()) + return NULL; + + // exist + Creature *unit = GetMap()->GetCreature(guid); + if (!unit) + return NULL; + + // player check + if(!CanInteractWithNPCs(!unit->isSpiritService())) + return NULL; + + // appropriate npc type + if(npcflagmask && !unit->HasFlag( UNIT_NPC_FLAGS, npcflagmask )) + return NULL; + + // alive or spirit healer + if(!unit->isAlive() && (!unit->isSpiritService() || isAlive() )) + return NULL; + + // not allow interaction under control + if(unit->GetCharmerOrOwnerGUID()) + return NULL; + + // not enemy + if( unit->IsHostileTo(this)) + return NULL; + + // not unfriendly + if(FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(unit->getFaction())) + if(factionTemplate->faction) + if(FactionEntry const* faction = sFactionStore.LookupEntry(factionTemplate->faction)) + if(faction->reputationListID >= 0 && GetReputationMgr().GetRank(faction) <= REP_UNFRIENDLY) + return NULL; + + // not too far + if(!unit->IsWithinDistInMap(this,INTERACTION_DISTANCE)) + return NULL; + + return unit; +} + +GameObject* Player::GetGameObjectIfCanInteractWith(uint64 guid, GameobjectTypes type) const +{ + if(GameObject *go = GetMap()->GetGameObject(guid)) + { + if(go->GetGoType() == type) + { + float maxdist; + switch(type) + { + // TODO: find out how the client calculates the maximal usage distance to spellless working + // gameobjects like guildbanks and mailboxes - 10.0 is a just an abitrary choosen number + case GAMEOBJECT_TYPE_GUILD_BANK: + case GAMEOBJECT_TYPE_MAILBOX: + maxdist = 10.0f; + break; + case GAMEOBJECT_TYPE_FISHINGHOLE: + maxdist = 20.0f+CONTACT_DISTANCE; // max spell range + break; + default: + maxdist = INTERACTION_DISTANCE; + break; + } + + if (go->IsWithinDistInMap(this, maxdist)) + return go; + + sLog.outError("IsGameObjectOfTypeInRange: GameObject '%s' [GUID: %u] is too far away from player %s [GUID: %u] to be used by him (distance=%f, maximal 10 is allowed)", go->GetGOInfo()->name, + go->GetGUIDLow(), GetName(), GetGUIDLow(), go->GetDistance(this)); + } + } + return NULL; +} + bool Player::IsUnderWater() const { return IsInWater() && @@ -2805,6 +2887,9 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen SpellLearnSkillNode const* spellLearnSkill = spellmgr.GetSpellLearnSkill(spell_id); + SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spell_id); + SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spell_id); + if(spellLearnSkill) { uint32 skill_value = GetPureSkillValue(spellLearnSkill->skill); @@ -2823,9 +2908,6 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen else { // not ranked skills - SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spell_id); - SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spell_id); - for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) { SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(_spell_idx->second->skillId); @@ -2872,10 +2954,16 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen } } - if(IsInWorld()) + if(!GetSession()->PlayerLoading()) { + // not ranked skills + for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) + { + GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE,_spell_idx->second->skillId); + GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS,_spell_idx->second->skillId); + } + GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL,spell_id); - GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS,spell_id); } // return true (for send learn packet) only if spell active (in case ranked spells) and not replace old spell @@ -6034,7 +6122,7 @@ void Player::CheckDuelDistance(time_t currTime) return; uint64 duelFlagGUID = GetUInt64Value(PLAYER_DUEL_ARBITER); - GameObject* obj = ObjectAccessor::GetGameObject(*this, duelFlagGUID); + GameObject* obj = GetMap()->GetGameObject(duelFlagGUID); if(!obj) return; @@ -6101,7 +6189,7 @@ void Player::DuelComplete(DuelCompleteType type) duel->opponent->GetSession()->SendPacket(&data);*/ //Remove Duel Flag object - GameObject* obj = ObjectAccessor::GetGameObject(*this, GetUInt64Value(PLAYER_DUEL_ARBITER)); + GameObject* obj = GetMap()->GetGameObject(GetUInt64Value(PLAYER_DUEL_ARBITER)); if(obj) duel->initiator->RemoveGameObject(obj,true); @@ -7006,8 +7094,7 @@ void Player::SendLoot(uint64 guid, LootType loot_type) if (IS_GAMEOBJECT_GUID(guid)) { sLog.outDebug(" IS_GAMEOBJECT_GUID(guid)"); - GameObject *go = - ObjectAccessor::GetGameObject(*this, guid); + GameObject *go = GetMap()->GetGameObject(guid); // not check distance for GO in case owned GO (fishing bobber case, for example) // And permit out of range GO with no owner in case fishing hole @@ -7120,7 +7207,7 @@ void Player::SendLoot(uint64 guid, LootType loot_type) } else { - Creature *creature = ObjectAccessor::GetCreature(*this, guid); + Creature *creature = GetMap()->GetCreature(guid); // must be in range and creature must be alive for pickpocket and must be dead for another loot if (!creature || creature->isAlive()!=(loot_type == LOOT_PICKPOCKETING) || !creature->IsWithinDistInMap(this,INTERACTION_DISTANCE)) @@ -11714,7 +11801,7 @@ void Player::PrepareQuestMenu( uint64 guid ) Object *pObject; QuestRelations* pObjectQR; QuestRelations* pObjectQIR; - Creature *pCreature = ObjectAccessor::GetCreature(*this, guid); + Creature *pCreature = GetMap()->GetCreature(guid); if( pCreature ) { pObject = (Object*)pCreature; @@ -11723,7 +11810,7 @@ void Player::PrepareQuestMenu( uint64 guid ) } else { - GameObject *pGameObject = ObjectAccessor::GetGameObject(*this, guid); + GameObject *pGameObject = GetMap()->GetGameObject(guid); if( pGameObject ) { pObject = (Object*)pGameObject; @@ -11800,7 +11887,7 @@ void Player::SendPreparedQuest( uint64 guid ) qe._Delay = 0; qe._Emote = 0; std::string title = ""; - Creature *pCreature = ObjectAccessor::GetCreature(*this, guid); + Creature *pCreature = GetMap()->GetCreature(guid); if( pCreature ) { uint32 textid = pCreature->GetNpcTextId(); @@ -11864,7 +11951,7 @@ Quest const * Player::GetNextQuest( uint64 guid, Quest const *pQuest ) QuestRelations* pObjectQR; QuestRelations* pObjectQIR; - Creature *pCreature = ObjectAccessor::GetCreature(*this, guid); + Creature *pCreature = GetMap()->GetCreature(guid); if( pCreature ) { pObject = (Object*)pCreature; @@ -11873,7 +11960,7 @@ Quest const * Player::GetNextQuest( uint64 guid, Quest const *pQuest ) } else { - GameObject *pGameObject = ObjectAccessor::GetGameObject(*this, guid); + GameObject *pGameObject = GetMap()->GetGameObject(guid); if( pGameObject ) { pObject = (Object*)pGameObject; @@ -16799,7 +16886,7 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint return false; } - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*this, vendorguid,UNIT_NPC_FLAG_VENDOR); + Creature *pCreature = GetNPCIfCanInteractWith(vendorguid,UNIT_NPC_FLAG_VENDOR); if (!pCreature) { sLog.outDebug( "WORLD: BuyItemFromVendor - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid)) ); diff --git a/src/game/Player.h b/src/game/Player.h index ef9ec90f6..7379c4caf 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -900,7 +900,9 @@ class MANGOS_DLL_SPEC Player : public Unit void SendTransferAborted(uint32 mapid, uint8 reason, uint8 arg = 0); void SendInstanceResetWarning(uint32 mapid, uint32 time); + Creature* GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask); bool CanInteractWithNPCs(bool alive = true) const; + GameObject* GetGameObjectIfCanInteractWith(uint64 guid, GameobjectTypes type) const; bool ToggleAFK(); bool ToggleDND(); diff --git a/src/game/PlayerDump.cpp b/src/game/PlayerDump.cpp index 8f75e6427..e43da414c 100644 --- a/src/game/PlayerDump.cpp +++ b/src/game/PlayerDump.cpp @@ -330,6 +330,36 @@ void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl std::string PlayerDumpWriter::GetDump(uint32 guid) { std::string dump; + + dump += "IMPORTANT NOTE: This sql queries not created for apply directly, use '.pdump load' command in console or client chat instead.\n"; + dump += "IMPORTANT NOTE: NOT APPLY ITS DIRECTLY to character DB or you will DAMAGE and CORRUPT character DB\n\n"; + + // revision check guard + QueryResult* result = CharacterDatabase.Query("SELECT * FROM character_db_version LIMIT 1"); + if(result) + { + QueryResult::FieldNames const& namesMap = result->GetFieldNames(); + std::string reqName; + for(QueryResult::FieldNames::const_iterator itr = namesMap.begin(); itr != namesMap.end(); ++itr) + { + if(itr->second.substr(0,9)=="required_") + { + reqName = itr->second; + break; + } + } + + if(!reqName.empty()) + { + // this will fail at wrong character DB version + dump += "UPDATE character_db_version SET "+reqName+" = 1 WHERE FALSE;\n\n"; + } + else + sLog.outError("Table 'character_db_version' not have revision guard field, revision guard query not added to pdump."); + } + else + sLog.outError("Character DB not have 'character_db_version' table, revision guard query not added to pdump."); + for(int i = 0; i < DUMP_TABLE_COUNT; i++) DumpTable(dump, guid, dumpTables[i].name, dumpTables[i].name, dumpTables[i].type); @@ -437,9 +467,23 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s std::string line; line.assign(buf); // skip empty strings - if(line.find_first_not_of(" \t\n\r\7")==std::string::npos) + size_t nw_pos = line.find_first_not_of(" \t\n\r\7"); + if(nw_pos==std::string::npos) continue; + // skip NOTE + if(line.substr(nw_pos,15)=="IMPORTANT NOTE:") + continue; + + // add required_ check + if(line.substr(nw_pos,41)=="UPDATE character_db_version SET required_") + { + if(!CharacterDatabase.Execute(line.c_str())) + ROLLBACK(DUMP_FILE_BROKEN); + + continue; + } + // determine table name and load type std::string tn = gettablename(line); if(tn.empty()) diff --git a/src/game/QuestHandler.cpp b/src/game/QuestHandler.cpp index 28787184a..430d84c0f 100644 --- a/src/game/QuestHandler.cpp +++ b/src/game/QuestHandler.cpp @@ -87,7 +87,7 @@ void WorldSession::HandleQuestgiverHelloOpcode( WorldPacket & recv_data ) sLog.outDebug ("WORLD: Received CMSG_QUESTGIVER_HELLO npc = %u", GUID_LOPART(guid)); - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_NONE); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_NONE); if (!pCreature) { sLog.outDebug ("WORLD: HandleQuestgiverHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", @@ -611,7 +611,7 @@ void WorldSession::HandleQuestgiverStatusQueryMultipleOpcode(WorldPacket& /*recv if(IS_CREATURE_GUID(*itr)) { - Creature *questgiver = ObjectAccessor::GetCreature(*_player, *itr); + Creature *questgiver = GetPlayer()->GetMap()->GetCreature(*itr); if(!questgiver || questgiver->IsHostileTo(_player)) continue; if(!questgiver->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER)) @@ -626,7 +626,7 @@ void WorldSession::HandleQuestgiverStatusQueryMultipleOpcode(WorldPacket& /*recv } else if(IS_GAMEOBJECT_GUID(*itr)) { - GameObject *questgiver = ObjectAccessor::GetGameObject(*_player, *itr); + GameObject *questgiver = GetPlayer()->GetMap()->GetGameObject(*itr); if(!questgiver) continue; if(questgiver->GetGoType() != GAMEOBJECT_TYPE_QUESTGIVER) diff --git a/src/game/SkillHandler.cpp b/src/game/SkillHandler.cpp index 6448869c4..75d2744de 100644 --- a/src/game/SkillHandler.cpp +++ b/src/game/SkillHandler.cpp @@ -68,7 +68,7 @@ void WorldSession::HandleTalentWipeOpcode( WorldPacket & recv_data ) uint64 guid; recv_data >> guid; - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_TRAINER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_TRAINER); if (!unit) { sLog.outDebug( "WORLD: HandleTalentWipeOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 5ddc41dbc..c4bfd3252 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -158,7 +158,7 @@ void SpellCastTargets::setCorpseTarget(Corpse* corpse) void SpellCastTargets::Update(Unit* caster) { - m_GOTarget = m_GOTargetGUID ? ObjectAccessor::GetGameObject(*caster,m_GOTargetGUID) : NULL; + m_GOTarget = m_GOTargetGUID ? caster->GetMap()->GetGameObject(m_GOTargetGUID) : NULL; m_unitTarget = m_unitTargetGUID ? ( m_unitTargetGUID==caster->GetGUID() ? caster : ObjectAccessor::GetUnit(*caster, m_unitTargetGUID) ) : NULL; @@ -956,7 +956,7 @@ void Spell::AddGOTarget(GameObject* pVictim, uint32 effIndex) void Spell::AddGOTarget(uint64 goGUID, uint32 effIndex) { - GameObject* go = ObjectAccessor::GetGameObject(*m_caster, goGUID); + GameObject* go = m_caster->GetMap()->GetGameObject(goGUID); if (go) AddGOTarget(go, effIndex); } @@ -1233,7 +1233,7 @@ void Spell::DoAllEffectOnTarget(GOTargetInfo *target) if(!effectMask) return; - GameObject* go = ObjectAccessor::GetGameObject(*m_caster, target->targetGUID); + GameObject* go = m_caster->GetMap()->GetGameObject(target->targetGUID); if(!go) return; @@ -1542,9 +1542,11 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap) { if (EffectChainTarget <= 1) { - Unit* pUnitTarget = SelectMagnetTarget(); - if(pUnitTarget) + if(Unit* pUnitTarget = m_caster->SelectMagnetTarget(m_targets.getUnitTarget(), m_spellInfo)) + { + m_targets.setUnitTarget(pUnitTarget); TagUnitMap.push_back(pUnitTarget); + } } else { @@ -1782,7 +1784,7 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap) // Check original caster is GO - set its coordinates as dst cast WorldObject *caster = NULL; if (IS_GAMEOBJECT_GUID(m_originalCasterGUID)) - caster = ObjectAccessor::GetGameObject(*m_caster, m_originalCasterGUID); + caster = m_caster->GetMap()->GetGameObject(m_originalCasterGUID); if (!caster) caster = m_caster; // Set dest for targets @@ -1871,9 +1873,11 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap) } else { - Unit* pUnitTarget = SelectMagnetTarget(); - if(pUnitTarget) + if(Unit* pUnitTarget = m_caster->SelectMagnetTarget(m_targets.getUnitTarget(), m_spellInfo)) + { + m_targets.setUnitTarget(pUnitTarget); TagUnitMap.push_back(pUnitTarget); + } } } }break; @@ -1905,9 +1909,11 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap) }break; case TARGET_SINGLE_ENEMY: { - Unit* pUnitTarget = SelectMagnetTarget(); - if(pUnitTarget) + if(Unit* pUnitTarget = m_caster->SelectMagnetTarget(m_targets.getUnitTarget(), m_spellInfo)) + { + m_targets.setUnitTarget(pUnitTarget); TagUnitMap.push_back(pUnitTarget); + } }break; case TARGET_AREAEFFECT_PARTY: { @@ -2710,7 +2716,7 @@ void Spell::update(uint32 difftime) { GOTargetInfo* target = &*ihit; - GameObject* go = ObjectAccessor::GetGameObject(*m_caster, target->targetGUID); + GameObject* go = m_caster->GetMap()->GetGameObject(target->targetGUID); if(!go) continue; @@ -3259,7 +3265,7 @@ void Spell::SendChannelStart(uint32 duration) { if(itr->effectMask & (1<<0) ) { - target = ObjectAccessor::GetGameObject(*m_caster, itr->targetGUID); + target = m_caster->GetMap()->GetGameObject(itr->targetGUID); break; } } @@ -5407,7 +5413,7 @@ bool Spell::CheckTarget( Unit* target, uint32 eff ) // Get GO cast coordinates if original caster -> GO WorldObject *caster = NULL; if (IS_GAMEOBJECT_GUID(m_originalCasterGUID)) - caster = ObjectAccessor::GetGameObject(*m_caster, m_originalCasterGUID); + caster = m_caster->GetMap()->GetGameObject(m_originalCasterGUID); if (!caster) caster = m_caster; if(target!=m_caster && !target->IsWithinLOSInMap(caster)) @@ -5418,30 +5424,6 @@ bool Spell::CheckTarget( Unit* target, uint32 eff ) return true; } -Unit* Spell::SelectMagnetTarget() -{ - Unit* target = m_targets.getUnitTarget(); - - if(target && target->HasAuraType(SPELL_AURA_SPELL_MAGNET) && !(m_spellInfo->Attributes & 0x10)) - { - Unit::AuraList const& magnetAuras = target->GetAurasByType(SPELL_AURA_SPELL_MAGNET); - for(Unit::AuraList::const_iterator itr = magnetAuras.begin(); itr != magnetAuras.end(); ++itr) - { - if(Unit* magnet = (*itr)->GetCaster()) - { - if(magnet->IsWithinLOSInMap(m_caster)) - { - target = magnet; - m_targets.setUnitTarget(target); - break; - } - } - } - } - - return target; -} - bool Spell::IsNeedSendToClient() const { return m_spellInfo->SpellVisual[0] || m_spellInfo->SpellVisual[1] || IsChanneledSpell(m_spellInfo) || diff --git a/src/game/Spell.h b/src/game/Spell.h index f621c2d41..5fd7e8490 100644 --- a/src/game/Spell.h +++ b/src/game/Spell.h @@ -381,7 +381,6 @@ class Spell void SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap); void FillAreaTargets( UnitList& TagUnitMap, float x, float y, float radius, SpellNotifyPushType pushType, SpellTargets spellTargets ); - Unit* SelectMagnetTarget(); bool CheckTarget( Unit* target, uint32 eff ); bool CanAutoCast(Unit* target); diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index 9ac627381..65b1c7bff 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -145,7 +145,7 @@ pAuraHandler AuraHandler[TOTAL_AURAS]= &Aura::HandleModUnattackable, // 93 SPELL_AURA_MOD_UNATTACKABLE &Aura::HandleNoImmediateEffect, // 94 SPELL_AURA_INTERRUPT_REGEN implemented in Player::RegenerateAll &Aura::HandleAuraGhost, // 95 SPELL_AURA_GHOST - &Aura::HandleNoImmediateEffect, // 96 SPELL_AURA_SPELL_MAGNET implemented in Spell::SelectMagnetTarget + &Aura::HandleNoImmediateEffect, // 96 SPELL_AURA_SPELL_MAGNET implemented in Unit::SelectMagnetTarget &Aura::HandleManaShield, // 97 SPELL_AURA_MANA_SHIELD implemented in Unit::CalcAbsorbResist &Aura::HandleAuraModSkill, // 98 SPELL_AURA_MOD_SKILL_TALENT &Aura::HandleAuraModAttackPower, // 99 SPELL_AURA_MOD_ATTACK_POWER @@ -160,7 +160,7 @@ pAuraHandler AuraHandler[TOTAL_AURAS]= &Aura::HandleAddModifier, //108 SPELL_AURA_ADD_PCT_MODIFIER &Aura::HandleAddTargetTrigger, //109 SPELL_AURA_ADD_TARGET_TRIGGER &Aura::HandleModPowerRegenPCT, //110 SPELL_AURA_MOD_POWER_REGEN_PERCENT - &Aura::HandleNULL, //111 SPELL_AURA_ADD_CASTER_HIT_TRIGGER chance redirect attack to caster + &Aura::HandleNoImmediateEffect, //111 SPELL_AURA_ADD_CASTER_HIT_TRIGGER implemented in Unit::SelectMagnetTarget &Aura::HandleNoImmediateEffect, //112 SPELL_AURA_OVERRIDE_CLASS_SCRIPTS &Aura::HandleNoImmediateEffect, //113 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus &Aura::HandleNoImmediateEffect, //114 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT implemented in Unit::MeleeDamageBonus diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index bab3ffbaf..8fbc3afc7 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -5436,7 +5436,7 @@ void Spell::EffectSummonTotem(uint32 i) uint64 guid = m_caster->m_TotemSlot[slot]; if(guid != 0) { - Creature *OldTotem = ObjectAccessor::GetCreature(*m_caster, guid); + Creature *OldTotem = m_caster->GetMap()->GetCreature(guid); if(OldTotem && OldTotem->isTotem()) ((Totem*)OldTotem)->UnSummon(); } @@ -5636,7 +5636,7 @@ void Spell::EffectSummonObject(uint32 i) { GameObject* obj = NULL; if( m_caster ) - obj = ObjectAccessor::GetGameObject(*m_caster, guid); + obj = m_caster->GetMap()->GetGameObject(guid); if(obj) obj->Delete(); m_caster->m_ObjectSlot[slot] = 0; @@ -6118,7 +6118,7 @@ void Spell::EffectDestroyAllTotems(uint32 /*i*/) if(!m_caster->m_TotemSlot[slot]) continue; - Creature* totem = ObjectAccessor::GetCreature(*m_caster,m_caster->m_TotemSlot[slot]); + Creature* totem = m_caster->GetMap()->GetCreature(m_caster->m_TotemSlot[slot]); if(totem && totem->isTotem()) { uint32 spell_id = totem->GetUInt32Value(UNIT_CREATED_BY_SPELL); diff --git a/src/game/SpellHandler.cpp b/src/game/SpellHandler.cpp index e01aaace5..2601497cb 100644 --- a/src/game/SpellHandler.cpp +++ b/src/game/SpellHandler.cpp @@ -230,7 +230,7 @@ void WorldSession::HandleGameObjectUseOpcode( WorldPacket & recv_data ) if(_player->m_mover != _player) return; - GameObject *obj = ObjectAccessor::GetGameObject(*_player, guid); + GameObject *obj = GetPlayer()->GetMap()->GetGameObject(guid); if(!obj) return; @@ -254,7 +254,7 @@ void WorldSession::HandleGameobjectReportUse(WorldPacket& recvPacket) if(_player->m_mover != _player) return; - GameObject* go = ObjectAccessor::GetGameObject(*_player,guid); + GameObject* go = GetPlayer()->GetMap()->GetGameObject(guid); if(!go) return; @@ -471,7 +471,7 @@ void WorldSession::HandleTotemDestroy( WorldPacket& recvPacket) if(!_player->m_TotemSlot[slotId]) return; - Creature* totem = ObjectAccessor::GetCreature(*_player,_player->m_TotemSlot[slotId]); + Creature* totem = GetPlayer()->GetMap()->GetCreature(_player->m_TotemSlot[slotId]); if(totem && totem->isTotem()) ((Totem*)totem)->UnSummon(); } diff --git a/src/game/TaxiHandler.cpp b/src/game/TaxiHandler.cpp index 166d833d0..4fedb5afc 100644 --- a/src/game/TaxiHandler.cpp +++ b/src/game/TaxiHandler.cpp @@ -46,7 +46,7 @@ void WorldSession::HandleTaxiNodeStatusQueryOpcode( WorldPacket & recv_data ) void WorldSession::SendTaxiStatus( uint64 guid ) { // cheating checks - Creature *unit = ObjectAccessor::GetCreature(*_player, guid); + Creature *unit = GetPlayer()->GetMap()->GetCreature(guid); if (!unit) { sLog.outDebug( "WorldSession::SendTaxiStatus - Unit (GUID: %u) not found.", uint32(GUID_LOPART(guid)) ); @@ -78,7 +78,7 @@ void WorldSession::HandleTaxiQueryAvailableNodes( WorldPacket & recv_data ) recv_data >> guid; // cheating checks - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_FLIGHTMASTER); + Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER); if (!unit) { sLog.outDebug( "WORLD: HandleTaxiQueryAvailableNodes - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); @@ -165,7 +165,7 @@ void WorldSession::HandleActivateTaxiFarOpcode ( WorldPacket & recv_data ) recv_data >> guid >> _totalcost >> node_count; - Creature *npc = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_FLIGHTMASTER); + Creature *npc = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER); if (!npc) { sLog.outDebug( "WORLD: HandleActivateTaxiFarOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid)) ); @@ -266,7 +266,7 @@ void WorldSession::HandleActivateTaxiOpcode( WorldPacket & recv_data ) recv_data >> guid >> nodes[0] >> nodes[1]; sLog.outDebug( "WORLD: Received CMSG_ACTIVATETAXI from %d to %d" ,nodes[0],nodes[1]); - Creature *npc = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_FLIGHTMASTER); + Creature *npc = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER); if (!npc) { sLog.outDebug( "WORLD: HandleActivateTaxiOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid)) ); diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 7ec8c0bab..abbe62cbe 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -1962,6 +1962,9 @@ void Unit::AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType, bool ex return; } + // attack can be redirected to another target + pVictim = SelectMagnetTarget(pVictim); + CalcDamageInfo damageInfo; CalculateMeleeDamage(pVictim, 0, &damageInfo, attType); // Send log damage message to client @@ -3982,7 +3985,7 @@ void Unit::RemoveDynObject(uint32 spellid) return; for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*i); + DynamicObject* dynObj = GetMap()->GetDynamicObject(*i); if(!dynObj) { i = m_dynObjGUIDs.erase(i); @@ -4001,7 +4004,7 @@ void Unit::RemoveAllDynObjects() { while(!m_dynObjGUIDs.empty()) { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); + DynamicObject* dynObj = GetMap()->GetDynamicObject(*m_dynObjGUIDs.begin()); if(dynObj) dynObj->Delete(); m_dynObjGUIDs.erase(m_dynObjGUIDs.begin()); @@ -4012,7 +4015,7 @@ DynamicObject * Unit::GetDynObject(uint32 spellId, uint32 effIndex) { for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*i); + DynamicObject* dynObj = GetMap()->GetDynamicObject(*i); if(!dynObj) { i = m_dynObjGUIDs.erase(i); @@ -4030,7 +4033,7 @@ DynamicObject * Unit::GetDynObject(uint32 spellId) { for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*i); + DynamicObject* dynObj = GetMap()->GetDynamicObject(*i); if(!dynObj) { i = m_dynObjGUIDs.erase(i); @@ -7257,7 +7260,7 @@ bool Unit::isAttackingPlayer() const { if(m_TotemSlot[i]) { - Creature *totem = ObjectAccessor::GetCreature(*this, m_TotemSlot[i]); + Creature *totem = GetMap()->GetCreature(m_TotemSlot[i]); if(totem && totem->isAttackingPlayer()) return true; } @@ -7415,12 +7418,40 @@ void Unit::UnsummonAllTotems() if(!m_TotemSlot[i]) continue; - Creature *OldTotem = ObjectAccessor::GetCreature(*this, m_TotemSlot[i]); + Creature *OldTotem = GetMap()->GetCreature(m_TotemSlot[i]); if (OldTotem && OldTotem->isTotem()) ((Totem*)OldTotem)->UnSummon(); } } +Unit* Unit::SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo) +{ + if(!victim) + return NULL; + + // Magic case + if(spellInfo && (spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE || spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC)) + { + Unit::AuraList const& magnetAuras = victim->GetAurasByType(SPELL_AURA_SPELL_MAGNET); + for(Unit::AuraList::const_iterator itr = magnetAuras.begin(); itr != magnetAuras.end(); ++itr) + if(Unit* magnet = (*itr)->GetCaster()) + if(magnet->IsWithinLOSInMap(this) && magnet->isAlive()) + return magnet; + } + // Melee && ranged case + else + { + AuraList const& hitTriggerAuras = victim->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER); + for(AuraList::const_iterator i = hitTriggerAuras.begin(); i != hitTriggerAuras.end(); ++i) + if(Unit* magnet = (*i)->GetCaster()) + if(magnet->isAlive() && magnet->IsWithinLOSInMap(this)) + if(roll_chance_i((*i)->GetModifier()->m_amount)) + return magnet; + } + + return victim; +} + void Unit::SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, bool critical) { // we guess size diff --git a/src/game/Unit.h b/src/game/Unit.h index e3ea874e7..69f01e527 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1339,6 +1339,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject void ModifyAuraState(AuraState flag, bool apply); bool HasAuraState(AuraState flag) const { return HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); } void UnsummonAllTotems(); + Unit* SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo = NULL); int32 SpellBaseDamageBonus(SpellSchoolMask schoolMask); int32 SpellBaseHealingBonus(SpellSchoolMask schoolMask); int32 SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim); diff --git a/src/game/WaypointManager.cpp b/src/game/WaypointManager.cpp index 5cea9ed93..043d6fc91 100644 --- a/src/game/WaypointManager.cpp +++ b/src/game/WaypointManager.cpp @@ -141,6 +141,12 @@ void WaypointManager::Load() } } + if (be.emote) + { + if (!sEmotesStore.LookupEntry(be.emote)) + sLog.outErrorDb("Waypoint path %u (Point %u) are using emote %u, but emote does not exist.",id, point, be.emote); + } + // save memory by not storing empty behaviors if(!be.isEmpty()) { diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 606ac5ebf..85c93fa98 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7685" + #define REVISION_NR "7692" #endif // __REVISION_NR_H__