Allow mind transfer to entity if said entity is also the current visit target.

This commit is contained in:
Pieter-Jan Briers
2020-04-18 00:38:43 +02:00
parent c4f147bab4
commit 4125c36e8d

View File

@@ -1,7 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.Players;
using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
@@ -142,6 +143,7 @@ namespace Content.Server.Mobs
public void TransferTo(IEntity entity)
{
MindComponent component = null;
bool alreadyAttached = false;
if (entity != null)
{
if (!entity.TryGetComponent(out component))
@@ -153,6 +155,17 @@ namespace Content.Server.Mobs
// TODO: Kick them out, maybe?
throw new ArgumentException("That entity already has a mind.", nameof(entity));
}
if (entity.TryGetComponent(out IActorComponent actor))
{
// Happens when transferring to your currently visited entity.
if (actor.playerSession != Session)
{
throw new ArgumentException("Visit target already has a session.", nameof(entity));
}
alreadyAttached = true;
}
}
OwnedMob?.InternalEjectMind();
@@ -160,7 +173,7 @@ namespace Content.Server.Mobs
OwnedMob?.InternalAssignMind(this);
// Player is CURRENTLY connected.
if (Session != null && OwnedMob != null)
if (Session != null && OwnedMob != null && !alreadyAttached)
{
Session.AttachToEntity(entity);
}