Core/AreaTriggers: Teleport to current instance entrance when entering instances via areatrigger entity

Port From (https://github.com/TrinityCore/TrinityCore/commit/4e7508db7b70b2b79ee1fc77a1899d08173ffc62)
This commit is contained in:
hondacrx
2023-09-04 11:40:06 -04:00
parent 296e818f77
commit 3461b6fcaa
3 changed files with 49 additions and 34 deletions
@@ -802,7 +802,15 @@ namespace Game.Entities
{
Player player = caster.ToPlayer();
if (player != null)
{
if (player.GetMapId() != safeLoc.Loc.GetMapId())
{
WorldSafeLocsEntry instanceEntrance = player.GetInstanceEntrance(safeLoc.Loc.GetMapId());
if (instanceEntrance != null)
safeLoc = instanceEntrance;
}
player.TeleportTo(safeLoc.Loc);
}
}
break;
default:
+39
View File
@@ -466,6 +466,45 @@ namespace Game.Entities
_instanceResetTimes.Add(instanceId, enterTime + Time.Hour);
}
public WorldSafeLocsEntry GetInstanceEntrance(uint targetMapId)
{
WorldSafeLocsEntry entranceLocation = null;
MapRecord mapEntry = CliDB.MapStorage.LookupByKey(targetMapId);
if (mapEntry.Instanceable())
{
// Check if we can contact the instancescript of the instance for an updated entrance location
uint targetInstanceId = Global.MapMgr.FindInstanceIdForPlayer(targetMapId, this);
if (targetInstanceId != 0)
{
Map map = Global.MapMgr.FindMap(targetMapId, targetInstanceId);
if (map != null)
{
InstanceMap instanceMap = map.ToInstanceMap();
if (instanceMap != null)
{
InstanceScript instanceScript = instanceMap.GetInstanceScript();
if (instanceScript != null)
entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceScript.GetEntranceLocation());
}
}
}
// Finally check with the instancesave for an entrance location if we did not get a valid one from the instancescript
if (entranceLocation == null)
{
Group group = GetGroup();
Difficulty difficulty = group != null ? group.GetDifficultyID(mapEntry) : GetDifficultyID(mapEntry);
ObjectGuid instanceOwnerGuid = group ? group.GetRecentInstanceOwner(targetMapId) : GetGUID();
InstanceLock instanceLock = Global.InstanceLockMgr.FindActiveInstanceLock(instanceOwnerGuid, new MapDb2Entries(mapEntry, Global.DB2Mgr.GetDownscaledMapDifficultyData(targetMapId, ref difficulty)));
if (instanceLock != null)
entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceLock.GetData().EntranceWorldSafeLocId);
}
}
return entranceLocation;
}
public void SendDungeonDifficulty(int forcedDifficulty = -1)
{
DungeonDifficultySet dungeonDifficultySet = new();
+2 -34
View File
@@ -356,40 +356,8 @@ namespace Game
if (!teleported)
{
WorldSafeLocsEntry entranceLocation = null;
MapRecord mapEntry = CliDB.MapStorage.LookupByKey(at.target_mapId);
if (mapEntry.Instanceable())
{
// Check if we can contact the instancescript of the instance for an updated entrance location
uint targetInstanceId = Global.MapMgr.FindInstanceIdForPlayer(at.target_mapId, _player);
if (targetInstanceId != 0)
{
Map map = Global.MapMgr.FindMap(at.target_mapId, targetInstanceId);
if (map != null)
{
InstanceMap instanceMap = map.ToInstanceMap();
if (instanceMap)
{
InstanceScript instanceScript = instanceMap.GetInstanceScript();
if (instanceScript != null)
entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceScript.GetEntranceLocation());
}
}
}
// Finally check with the instancesave for an entrance location if we did not get a valid one from the instancescript
if (entranceLocation == null)
{
Group group = player.GetGroup();
Difficulty difficulty = group ? group.GetDifficultyID(mapEntry) : player.GetDifficultyID(mapEntry);
ObjectGuid instanceOwnerGuid = group ? group.GetRecentInstanceOwner(at.target_mapId) : player.GetGUID();
InstanceLock instanceLock = Global.InstanceLockMgr.FindActiveInstanceLock(instanceOwnerGuid, new MapDb2Entries(mapEntry, Global.DB2Mgr.GetDownscaledMapDifficultyData(at.target_mapId, ref difficulty)));
if (instanceLock != null)
entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceLock.GetData().EntranceWorldSafeLocId);
}
}
if (entranceLocation != null)
WorldSafeLocsEntry entranceLocation = player.GetInstanceEntrance(at.target_mapId);
if (entranceLocation != null && player.GetMapId() != at.target_mapId)
player.TeleportTo(entranceLocation.Loc, TeleportToOptions.NotLeaveTransport);
else
player.TeleportTo(at.target_mapId, at.target_X, at.target_Y, at.target_Z, at.target_Orientation, TeleportToOptions.NotLeaveTransport);