Allow changing the owner of a mind.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
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 SS14.Server.Interfaces.Player;
|
using SS14.Server.Interfaces.Player;
|
||||||
using SS14.Shared.Interfaces.GameObjects;
|
using SS14.Shared.Interfaces.GameObjects;
|
||||||
using SS14.Shared.IoC;
|
using SS14.Shared.IoC;
|
||||||
@@ -37,7 +38,7 @@ namespace Content.Server.Mobs
|
|||||||
/// The session ID of the player owning this mind.
|
/// The session ID of the player owning this mind.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public NetSessionId SessionId { get; }
|
public NetSessionId? SessionId { get; private set; }
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public bool IsVisitingEntity => VisitingEntity != null;
|
public bool IsVisitingEntity => VisitingEntity != null;
|
||||||
@@ -76,8 +77,12 @@ namespace Content.Server.Mobs
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
if (!SessionId.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
var playerMgr = IoCManager.Resolve<IPlayerManager>();
|
var playerMgr = IoCManager.Resolve<IPlayerManager>();
|
||||||
playerMgr.TryGetSessionById(SessionId, out var ret);
|
playerMgr.TryGetSessionById(SessionId.Value, out var ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,6 +217,44 @@ namespace Content.Server.Mobs
|
|||||||
VisitingEntity = null;
|
VisitingEntity = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangeOwningPlayer(NetSessionId? newOwner)
|
||||||
|
{
|
||||||
|
var playerMgr = IoCManager.Resolve<IPlayerManager>();
|
||||||
|
PlayerData newOwnerData = null;
|
||||||
|
if (newOwner.HasValue)
|
||||||
|
{
|
||||||
|
if (!playerMgr.TryGetPlayerData(newOwner.Value, out var uncast))
|
||||||
|
{
|
||||||
|
// This restriction is because I'm too lazy to initialize the player data
|
||||||
|
// for a client that hasn't logged in yet.
|
||||||
|
// Go ahead and remove it if you need.
|
||||||
|
throw new ArgumentException("new owner must have previously logged into the server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
newOwnerData = uncast.ContentData();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure to remove control from our old owner if they're logged in.
|
||||||
|
var oldSession = Session;
|
||||||
|
oldSession?.AttachToEntity(null);
|
||||||
|
|
||||||
|
if (SessionId.HasValue)
|
||||||
|
{
|
||||||
|
playerMgr.GetPlayerData(SessionId.Value).ContentData().Mind = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
SessionId = newOwner;
|
||||||
|
if (!newOwner.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Yank new owner out of their old mind too.
|
||||||
|
// Can I mention how much I love the word yank?
|
||||||
|
newOwnerData.Mind?.ChangeOwningPlayer(null);
|
||||||
|
newOwnerData.Mind = this;
|
||||||
|
}
|
||||||
|
|
||||||
public void Visit(IEntity entity)
|
public void Visit(IEntity entity)
|
||||||
{
|
{
|
||||||
Session?.AttachToEntity(entity);
|
Session?.AttachToEntity(entity);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Content.Server.Mobs;
|
using Content.Server.Mobs;
|
||||||
using SS14.Server.Interfaces.Player;
|
using SS14.Server.Interfaces.Player;
|
||||||
|
using SS14.Shared.IoC;
|
||||||
using SS14.Shared.Network;
|
using SS14.Shared.Network;
|
||||||
using SS14.Shared.ViewVariables;
|
using SS14.Shared.ViewVariables;
|
||||||
|
|
||||||
@@ -19,10 +20,16 @@ namespace Content.Server.Players
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The currently occupied mind of the player owning this data.
|
/// The currently occupied mind of the player owning this data.
|
||||||
|
/// DO NOT DIRECTLY SET THIS UNLESS YOU KNOW WHAT YOU'RE DOING.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public Mind Mind { get; set; }
|
public Mind Mind { get; set; }
|
||||||
|
|
||||||
|
public void WipeMind()
|
||||||
|
{
|
||||||
|
Mind.ChangeOwningPlayer(null);
|
||||||
|
}
|
||||||
|
|
||||||
public PlayerData(NetSessionId sessionId)
|
public PlayerData(NetSessionId sessionId)
|
||||||
{
|
{
|
||||||
SessionId = sessionId;
|
SessionId = sessionId;
|
||||||
|
|||||||
Reference in New Issue
Block a user