Allow mind transfer to entity if said entity is also the current visit target.
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Content.Server.GameObjects.Components.Mobs;
|
using Content.Server.GameObjects.Components.Mobs;
|
||||||
using Content.Server.Players;
|
using Content.Server.Players;
|
||||||
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -142,6 +143,7 @@ namespace Content.Server.Mobs
|
|||||||
public void TransferTo(IEntity entity)
|
public void TransferTo(IEntity entity)
|
||||||
{
|
{
|
||||||
MindComponent component = null;
|
MindComponent component = null;
|
||||||
|
bool alreadyAttached = false;
|
||||||
if (entity != null)
|
if (entity != null)
|
||||||
{
|
{
|
||||||
if (!entity.TryGetComponent(out component))
|
if (!entity.TryGetComponent(out component))
|
||||||
@@ -153,6 +155,17 @@ namespace Content.Server.Mobs
|
|||||||
// TODO: Kick them out, maybe?
|
// TODO: Kick them out, maybe?
|
||||||
throw new ArgumentException("That entity already has a mind.", nameof(entity));
|
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();
|
OwnedMob?.InternalEjectMind();
|
||||||
@@ -160,7 +173,7 @@ namespace Content.Server.Mobs
|
|||||||
OwnedMob?.InternalAssignMind(this);
|
OwnedMob?.InternalAssignMind(this);
|
||||||
|
|
||||||
// Player is CURRENTLY connected.
|
// Player is CURRENTLY connected.
|
||||||
if (Session != null && OwnedMob != null)
|
if (Session != null && OwnedMob != null && !alreadyAttached)
|
||||||
{
|
{
|
||||||
Session.AttachToEntity(entity);
|
Session.AttachToEntity(entity);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user