Fix server crashing when portal is deleted (#2157)

-Fix server crashing when using the teleporter
This commit is contained in:
Exp
2020-10-01 13:48:42 +02:00
committed by GitHub
parent 155882f469
commit f0cb9f05ee
2 changed files with 5 additions and 3 deletions

View File

@@ -87,7 +87,7 @@ namespace Content.Server.GameObjects.Components.Movement
public void TryChangeState(PortalState targetState) public void TryChangeState(PortalState targetState)
{ {
if (Owner == null) if (Owner == null || Deleted)
{ {
return; return;
} }
@@ -102,6 +102,9 @@ namespace Content.Server.GameObjects.Components.Movement
private void ReleaseCooldown(IEntity entity) private void ReleaseCooldown(IEntity entity)
{ {
if (Owner == null || Deleted)
return;
if (ImmuneEntities.Contains(entity)) if (ImmuneEntities.Contains(entity))
{ {
ImmuneEntities.Remove(entity); ImmuneEntities.Remove(entity);
@@ -189,7 +192,6 @@ namespace Content.Server.GameObjects.Components.Movement
// Departure // Departure
// Do we need to rate-limit sounds to stop ear BLAST? // Do we need to rate-limit sounds to stop ear BLAST?
soundPlayer.PlayAtCoords(_departureSound, entity.Transform.Coordinates); soundPlayer.PlayAtCoords(_departureSound, entity.Transform.Coordinates);
entity.Transform.AttachToGridOrMap();
entity.Transform.Coordinates = position; entity.Transform.Coordinates = position;
soundPlayer.PlayAtCoords(_arrivalSound, entity.Transform.Coordinates); soundPlayer.PlayAtCoords(_arrivalSound, entity.Transform.Coordinates);
TryChangeState(PortalState.RecentlyTeleported); TryChangeState(PortalState.RecentlyTeleported);

View File

@@ -222,7 +222,7 @@ namespace Content.Server.GameObjects.Components.Movement
public void Teleport(IEntity user, Vector2 vector) public void Teleport(IEntity user, Vector2 vector)
{ {
// Messy maybe? // Messy maybe?
var targetGrid = user.ToCoordinates(vector); var targetGrid = user.Transform.Coordinates.WithPosition(vector);
var soundPlayer = EntitySystem.Get<AudioSystem>(); var soundPlayer = EntitySystem.Get<AudioSystem>();
// If portals use those, otherwise just move em over // If portals use those, otherwise just move em over