Add summoner information to TeleportTo function and created OnBeforeTeleport hook

This commit is contained in:
Yehonal
2017-11-16 00:13:54 +00:00
parent b340ebbec9
commit bf60f8f5c6
6 changed files with 32 additions and 15 deletions

View File

@@ -2189,8 +2189,8 @@ void Player::SendTeleportAckPacket()
GetSession()->SendPacket(&data); GetSession()->SendPacket(&data);
} }
bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options) bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options /*= 0*/, Unit *target /*= nullptr*/)
{ {
if (!MapManager::IsValidMapCoord(mapid, x, y, z, orientation)) if (!MapManager::IsValidMapCoord(mapid, x, y, z, orientation))
{ {
sLog->outError("TeleportTo: invalid map (%d) or invalid coordinates (X: %f, Y: %f, Z: %f, O: %f) given when teleporting player (GUID: %u, name: %s, map: %d, X: %f, Y: %f, Z: %f, O: %f).", sLog->outError("TeleportTo: invalid map (%d) or invalid coordinates (X: %f, Y: %f, Z: %f, O: %f) given when teleporting player (GUID: %u, name: %s, map: %d, X: %f, Y: %f, Z: %f, O: %f).",
@@ -2288,6 +2288,9 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
if (duel && GetMapId() != mapid && GetMap()->GetGameObject(GetUInt64Value(PLAYER_DUEL_ARBITER))) if (duel && GetMapId() != mapid && GetMap()->GetGameObject(GetUInt64Value(PLAYER_DUEL_ARBITER)))
DuelComplete(DUEL_FLED); DuelComplete(DUEL_FLED);
if (!sScriptMgr->OnBeforePlayerTeleport(this, mapid, x, y, z, orientation, options, target))
return false;
if (GetMapId() == mapid) if (GetMapId() == mapid)
{ {
//lets reset far teleport flag if it wasn't reset during chained teleports //lets reset far teleport flag if it wasn't reset during chained teleports
@@ -23622,8 +23625,8 @@ void Player::UpdateForQuestWorldObjects()
GetSession()->SendPacket(&packet); GetSession()->SendPacket(&packet);
} }
void Player::SummonIfPossible(bool agree) void Player::SummonIfPossible(bool agree, uint32 summoner_guid)
{ {
if (!agree) if (!agree)
{ {
m_summon_expire = 0; m_summon_expire = 0;
@@ -23643,7 +23646,7 @@ void Player::SummonIfPossible(bool agree)
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_ACCEPTED_SUMMONINGS, 1); UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_ACCEPTED_SUMMONINGS, 1);
TeleportTo(m_summon_mapid, m_summon_x, m_summon_y, m_summon_z, GetOrientation()); TeleportTo(m_summon_mapid, m_summon_x, m_summon_y, m_summon_z, GetOrientation(), 0, ObjectAccessor::FindPlayer(summoner_guid));
} }
void Player::RemoveItemDurations(Item* item) void Player::RemoveItemDurations(Item* item)

View File

@@ -1096,10 +1096,10 @@ class Player : public Unit, public GridObject<Player>
SetFloatValue(UNIT_FIELD_COMBATREACH, scale * DEFAULT_COMBAT_REACH); SetFloatValue(UNIT_FIELD_COMBATREACH, scale * DEFAULT_COMBAT_REACH);
} }
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options = 0); bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options = 0, Unit *target = nullptr);
bool TeleportTo(WorldLocation const &loc, uint32 options = 0) bool TeleportTo(WorldLocation const &loc, uint32 options = 0, Unit *target = nullptr)
{ {
return TeleportTo(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation(), options); return TeleportTo(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation(), options, target);
} }
bool TeleportToEntryPoint(); bool TeleportToEntryPoint();
@@ -1114,7 +1114,7 @@ class Player : public Unit, public GridObject<Player>
} }
bool IsSummonAsSpectator() const { return m_summon_asSpectator && m_summon_expire >= time(NULL); } bool IsSummonAsSpectator() const { return m_summon_asSpectator && m_summon_expire >= time(NULL); }
void SetSummonAsSpectator(bool on) { m_summon_asSpectator = on; } void SetSummonAsSpectator(bool on) { m_summon_asSpectator = on; }
void SummonIfPossible(bool agree); void SummonIfPossible(bool agree, uint32 summoner_guid);
time_t GetSummonExpireTimer() const { return m_summon_expire; } time_t GetSummonExpireTimer() const { return m_summon_expire; }
bool Create(uint32 guidlow, CharacterCreateInfo* createInfo); bool Create(uint32 guidlow, CharacterCreateInfo* createInfo);

View File

@@ -721,5 +721,5 @@ void WorldSession::HandleSummonResponseOpcode(WorldPacket& recvData)
agree = false; agree = false;
} }
_player->SetSummonAsSpectator(false); _player->SetSummonAsSpectator(false);
_player->SummonIfPossible(agree); _player->SummonIfPossible(agree, summoner_guid);
} }

View File

@@ -1308,6 +1308,16 @@ void ScriptMgr::OnPlayerUpdateArea(Player* player, uint32 oldArea, uint32 newAre
FOREACH_SCRIPT(PlayerScript)->OnUpdateArea(player, oldArea, newArea); FOREACH_SCRIPT(PlayerScript)->OnUpdateArea(player, oldArea, newArea);
} }
bool ScriptMgr::OnBeforePlayerTeleport(Player* player, uint32 mapid, float x, float y, float z, float orientation, uint32 options, Unit *target)
{
bool ret=true;
FOR_SCRIPTS_RET(PlayerScript, itr, end, ret) // return true by default if not scripts
if (!itr->second->OnBeforeTeleport(player, mapid, x, y, z, orientation, options, target))
ret=false; // we change ret value only when scripts return false
return ret;
}
void ScriptMgr::OnPlayerUpdateFaction(Player* player) void ScriptMgr::OnPlayerUpdateFaction(Player* player)
{ {
FOREACH_SCRIPT(PlayerScript)->OnUpdateFaction(player); FOREACH_SCRIPT(PlayerScript)->OnUpdateFaction(player);

View File

@@ -848,6 +848,9 @@ class PlayerScript : public ScriptObject
// Called when a player changes to a new map (after moving to new map) // Called when a player changes to a new map (after moving to new map)
virtual void OnMapChanged(Player* /*player*/) { } virtual void OnMapChanged(Player* /*player*/) { }
// Called before a player is being teleported to new coords
virtual bool OnBeforeTeleport(Player* /*player*/, uint32 /*mapid*/, float /*x*/, float /*y*/, float /*z*/, float /*orientation*/, uint32 /*options*/, Unit* /*target*/) { return true; }
// Called when team/faction is set on player // Called when team/faction is set on player
virtual void OnUpdateFaction(Player* /*player*/) { } virtual void OnUpdateFaction(Player* /*player*/) { }
@@ -1221,6 +1224,7 @@ class ScriptMgr
void OnPlayerBindToInstance(Player* player, Difficulty difficulty, uint32 mapid, bool permanent); void OnPlayerBindToInstance(Player* player, Difficulty difficulty, uint32 mapid, bool permanent);
void OnPlayerUpdateZone(Player* player, uint32 newZone, uint32 newArea); void OnPlayerUpdateZone(Player* player, uint32 newZone, uint32 newArea);
void OnPlayerUpdateArea(Player* player, uint32 oldArea, uint32 newArea); void OnPlayerUpdateArea(Player* player, uint32 oldArea, uint32 newArea);
bool OnBeforePlayerTeleport(Player* player, uint32 mapid, float x, float y, float z, float orientation, uint32 options, Unit *target);
void OnPlayerUpdateFaction(Player* player); void OnPlayerUpdateFaction(Player* player);
void OnPlayerAddToBattleground(Player* player, Battleground* bg); void OnPlayerAddToBattleground(Player* player, Battleground* bg);
void OnPlayerRemoveFromBattleground(Player* player, Battleground* bg); void OnPlayerRemoveFromBattleground(Player* player, Battleground* bg);

View File

@@ -612,8 +612,8 @@ public:
else else
_player->SaveRecallPosition(); _player->SaveRecallPosition();
_player->TeleportTo(target->GetMapId(), target->GetPositionX(), target->GetPositionY(), target->GetPositionZ()+0.25f, _player->GetOrientation(), TELE_TO_GM_MODE); if (_player->TeleportTo(target->GetMapId(), target->GetPositionX(), target->GetPositionY(), target->GetPositionZ()+0.25f, _player->GetOrientation(), TELE_TO_GM_MODE, target))
_player->SetPhaseMask(target->GetPhaseMask() | 1, false); _player->SetPhaseMask(target->GetPhaseMask() | 1, false);
} }
else else
{ {
@@ -734,8 +734,8 @@ public:
// before GM // before GM
float x, y, z; float x, y, z;
handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, target->GetObjectSize()); handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, target->GetObjectSize());
target->TeleportTo(handler->GetSession()->GetPlayer()->GetMapId(), x, y, z, target->GetOrientation()); if (target->TeleportTo(handler->GetSession()->GetPlayer()->GetMapId(), x, y, z, target->GetOrientation(), 0, handler->GetSession()->GetPlayer()))
target->SetPhaseMask(handler->GetSession()->GetPlayer()->GetPhaseMask(), false); target->SetPhaseMask(handler->GetSession()->GetPlayer()->GetPhaseMask(), false);
} }
else else
{ {
@@ -845,7 +845,7 @@ public:
// before GM // before GM
float x, y, z; float x, y, z;
handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, player->GetObjectSize()); handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, player->GetObjectSize());
player->TeleportTo(handler->GetSession()->GetPlayer()->GetMapId(), x, y, z, player->GetOrientation()); player->TeleportTo(handler->GetSession()->GetPlayer()->GetMapId(), x, y, z, player->GetOrientation(), 0, handler->GetSession()->GetPlayer());
} }
return true; return true;