Re-organize all projects (#4166)
This commit is contained in:
66
Content.Server/Mind/Commands/MakeSentientCommand.cs
Normal file
66
Content.Server/Mind/Commands/MakeSentientCommand.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
#nullable enable
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.AI.Components;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Emoting;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Speech;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
|
||||
namespace Content.Server.Mind.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public class MakeSentientCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "makesentient";
|
||||
public string Description => "Makes an entity sentient (able to be controlled by a player)";
|
||||
public string Help => "makesentient <entity id>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
{
|
||||
shell.WriteLine("Wrong number of arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[0], out var id))
|
||||
{
|
||||
shell.WriteLine("Invalid argument.");
|
||||
return;
|
||||
}
|
||||
|
||||
var entId = new EntityUid(id);
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (!entityManager.TryGetEntity(entId, out var entity) || entity.Deleted)
|
||||
{
|
||||
shell.WriteLine("Invalid entity specified!");
|
||||
return;
|
||||
}
|
||||
|
||||
MakeSentient(entity);
|
||||
}
|
||||
|
||||
public static void MakeSentient(IEntity entity)
|
||||
{
|
||||
if(entity.HasComponent<AiControllerComponent>())
|
||||
entity.RemoveComponent<AiControllerComponent>();
|
||||
|
||||
// Delay spawning these components to avoid race conditions with the deferred removal of AiController.
|
||||
Timer.Spawn(100, () =>
|
||||
{
|
||||
entity.EnsureComponent<MindComponent>();
|
||||
entity.EnsureComponent<SharedPlayerInputMoverComponent>();
|
||||
entity.EnsureComponent<SharedPlayerMobMoverComponent>();
|
||||
entity.EnsureComponent<SharedSpeechComponent>();
|
||||
entity.EnsureComponent<SharedEmotingComponent>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Content.Server/Mind/Commands/MindInfoCommand.cs
Normal file
53
Content.Server/Mind/Commands/MindInfoCommand.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Text;
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Mind.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public class MindInfoCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "mindinfo";
|
||||
|
||||
public string Description => "Lists info for the mind of a specific player.";
|
||||
|
||||
public string Help => "mindinfo <session ID>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
{
|
||||
shell.WriteLine("Expected exactly 1 argument.");
|
||||
return;
|
||||
}
|
||||
|
||||
var mgr = IoCManager.Resolve<IPlayerManager>();
|
||||
if (!mgr.TryGetSessionByUsername(args[0], out var data))
|
||||
{
|
||||
shell.WriteLine("Can't find that mind");
|
||||
return;
|
||||
}
|
||||
|
||||
var mind = data.ContentData()?.Mind;
|
||||
|
||||
if (mind == null)
|
||||
{
|
||||
shell.WriteLine("Can't find that mind");
|
||||
return;
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendFormat("player: {0}, mob: {1}\nroles: ", mind.UserId, mind.OwnedComponent?.Owner?.Uid);
|
||||
foreach (var role in mind.AllRoles)
|
||||
{
|
||||
builder.AppendFormat("{0} ", role.Name);
|
||||
}
|
||||
|
||||
shell.WriteLine(builder.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
162
Content.Server/Mind/Components/MindComponent.cs
Normal file
162
Content.Server/Mind/Components/MindComponent.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Ghost.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.MobState;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Mind.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores a <see cref="Server.Mind.Mind"/> on a mob.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class MindComponent : Component, IExamine
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Mind";
|
||||
|
||||
/// <summary>
|
||||
/// The mind controlling this mob. Can be null.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Mind? Mind { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if we have a mind, false otherwise.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool HasMind => Mind != null;
|
||||
|
||||
/// <summary>
|
||||
/// Whether examining should show information about the mind or not.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("showExamineInfo")]
|
||||
public bool ShowExamineInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the mind will be put on a ghost after this component is shutdown.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("ghostOnShutdown")]
|
||||
public bool GhostOnShutdown { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Don't call this unless you know what the hell you're doing.
|
||||
/// Use <see cref="Mind.TransferTo(IEntity)"/> instead.
|
||||
/// If that doesn't cover it, make something to cover it.
|
||||
/// </summary>
|
||||
public void InternalEjectMind()
|
||||
{
|
||||
if (!Deleted)
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new MindRemovedMessage());
|
||||
Mind = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Don't call this unless you know what the hell you're doing.
|
||||
/// Use <see cref="Mind.TransferTo(IEntity)"/> instead.
|
||||
/// If that doesn't cover it, make something to cover it.
|
||||
/// </summary>
|
||||
public void InternalAssignMind(Mind value)
|
||||
{
|
||||
Mind = value;
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new MindAddedMessage());
|
||||
}
|
||||
|
||||
protected override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
// Let's not create ghosts if not in the middle of the round.
|
||||
if (IoCManager.Resolve<IGameTicker>().RunLevel != GameRunLevel.InRound)
|
||||
return;
|
||||
|
||||
if (HasMind)
|
||||
{
|
||||
var visiting = Mind?.VisitingEntity;
|
||||
if (visiting != null)
|
||||
{
|
||||
if (visiting.TryGetComponent(out GhostComponent? ghost))
|
||||
{
|
||||
ghost.CanReturnToBody = false;
|
||||
}
|
||||
|
||||
Mind!.TransferTo(visiting);
|
||||
}
|
||||
else if (GhostOnShutdown)
|
||||
{
|
||||
var spawnPosition = Owner.Transform.Coordinates;
|
||||
// Use a regular timer here because the entity has probably been deleted.
|
||||
Timer.Spawn(0, () =>
|
||||
{
|
||||
// Async this so that we don't throw if the grid we're on is being deleted.
|
||||
var mapMan = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var gridId = spawnPosition.GetGridId(Owner.EntityManager);
|
||||
if (gridId == GridId.Invalid || !mapMan.GridExists(gridId))
|
||||
{
|
||||
spawnPosition = IoCManager.Resolve<IGameTicker>().GetObserverSpawnPoint();
|
||||
}
|
||||
|
||||
var ghost = Owner.EntityManager.SpawnEntity("MobObserver", spawnPosition);
|
||||
var ghostComponent = ghost.GetComponent<GhostComponent>();
|
||||
ghostComponent.CanReturnToBody = false;
|
||||
|
||||
if (Mind != null)
|
||||
{
|
||||
ghost.Name = Mind.CharacterName ?? string.Empty;
|
||||
Mind.TransferTo(ghost);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (!ShowExamineInfo || !inDetailsRange)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dead =
|
||||
Owner.TryGetComponent<IMobStateComponent>(out var state) &&
|
||||
state.IsDead();
|
||||
|
||||
if (!HasMind)
|
||||
{
|
||||
var aliveText =
|
||||
$"[color=purple]{Loc.GetString("comp-mind-examined-catatonic", ("ent", Owner))}[/color]";
|
||||
var deadText = $"[color=red]{Loc.GetString("comp-mind-examined-dead", ("ent", Owner))}[/color]";
|
||||
|
||||
message.AddMarkup(dead ? deadText : aliveText);
|
||||
}
|
||||
else if (Mind?.Session == null)
|
||||
{
|
||||
if (dead) return;
|
||||
|
||||
var text =
|
||||
$"[color=yellow]{Loc.GetString("comp-mind-examined-ssd", ("ent", Owner))}[/color]";
|
||||
|
||||
message.AddMarkup(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MindRemovedMessage : EntityEventArgs
|
||||
{
|
||||
}
|
||||
|
||||
public class MindAddedMessage : EntityEventArgs
|
||||
{
|
||||
}
|
||||
}
|
||||
25
Content.Server/Mind/Components/VisitingMindComponent.cs
Normal file
25
Content.Server/Mind/Components/VisitingMindComponent.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
#nullable enable
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Mind.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class VisitingMindComponent : Component
|
||||
{
|
||||
public override string Name => "VisitingMind";
|
||||
|
||||
[ViewVariables] public Mind Mind { get; set; } = default!;
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
Mind?.UnVisit();
|
||||
}
|
||||
}
|
||||
|
||||
public class MindUnvisitedMessage : EntityEventArgs
|
||||
{
|
||||
}
|
||||
}
|
||||
371
Content.Server/Mind/Mind.cs
Normal file
371
Content.Server/Mind/Mind.cs
Normal file
@@ -0,0 +1,371 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Ghost.Components;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Objectives;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.Roles;
|
||||
using Content.Shared.MobState;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Mind
|
||||
{
|
||||
/// <summary>
|
||||
/// A mind represents the IC "mind" of a player. Stores roles currently.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Think of it like this: if a player is supposed to have their memories,
|
||||
/// their mind follows along.
|
||||
///
|
||||
/// Things such as respawning do not follow, because you're a new character.
|
||||
/// Getting borged, cloned, turned into a catbeast, etc... will keep it following you.
|
||||
/// </remarks>
|
||||
public sealed class Mind
|
||||
{
|
||||
private readonly ISet<Role> _roles = new HashSet<Role>();
|
||||
|
||||
private readonly List<Objective> _objectives = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates the new mind attached to a specific player session.
|
||||
/// </summary>
|
||||
/// <param name="userId">The session ID of the owning player.</param>
|
||||
public Mind(NetUserId userId)
|
||||
{
|
||||
UserId = userId;
|
||||
}
|
||||
|
||||
// TODO: This session should be able to be changed, probably.
|
||||
/// <summary>
|
||||
/// The session ID of the player owning this mind.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public NetUserId? UserId { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public bool IsVisitingEntity => VisitingEntity != null;
|
||||
|
||||
[ViewVariables]
|
||||
public IEntity? VisitingEntity { get; private set; }
|
||||
|
||||
[ViewVariables] public IEntity? CurrentEntity => VisitingEntity ?? OwnedEntity;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? CharacterName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The component currently owned by this mind.
|
||||
/// Can be null.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public MindComponent? OwnedComponent { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The entity currently owned by this mind.
|
||||
/// Can be null.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public IEntity? OwnedEntity => OwnedComponent?.Owner;
|
||||
|
||||
/// <summary>
|
||||
/// An enumerable over all the roles this mind has.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public IEnumerable<Role> AllRoles => _roles;
|
||||
|
||||
/// <summary>
|
||||
/// An enumerable over all the objectives this mind has.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public IEnumerable<Objective> AllObjectives => _objectives;
|
||||
|
||||
/// <summary>
|
||||
/// The session of the player owning this mind.
|
||||
/// Can be null, in which case the player is currently not logged in.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public IPlayerSession? Session
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!UserId.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var playerMgr = IoCManager.Resolve<IPlayerManager>();
|
||||
playerMgr.TryGetSessionById(UserId.Value, out var ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True if this Mind is 'sufficiently dead' IC (objectives, endtext).
|
||||
/// Note that this is *IC logic*, it's not necessarily tied to any specific truth.
|
||||
/// "If administrators decide that zombies are dead, this returns true for zombies."
|
||||
/// (Maybe you were looking for the action blocker system?)
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool CharacterDeadIC => CharacterDeadPhysically;
|
||||
/// <summary>
|
||||
/// True if the OwnedEntity of this mind is physically dead.
|
||||
/// This specific definition, as opposed to CharacterDeadIC, is used to determine if ghosting should allow return.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool CharacterDeadPhysically
|
||||
{
|
||||
get
|
||||
{
|
||||
// This is written explicitly so that the logic can be understood.
|
||||
// But it's also weird and potentially situational.
|
||||
// Specific considerations when updating this:
|
||||
// + Does being turned into a borg (if/when implemented) count as dead?
|
||||
// *If not, add specific conditions to users of this property where applicable.*
|
||||
// + Is being transformed into a donut 'dead'?
|
||||
// TODO: Consider changing the way ghost roles work.
|
||||
// Mind is an *IC* mind, therefore ghost takeover is IC revival right now.
|
||||
// + Is it necessary to have a reference to a specific 'mind iteration' to cycle when certain events happen?
|
||||
// (If being a borg or AI counts as dead, then this is highly likely, as it's still the same Mind for practical purposes.)
|
||||
|
||||
// This can be null if they're deleted (spike / brain nom)
|
||||
if (OwnedEntity == null)
|
||||
return true;
|
||||
var targetMobState = OwnedEntity.GetComponentOrNull<IMobStateComponent>();
|
||||
// This can be null if it's a brain (this happens very often)
|
||||
// Brains are the result of gibbing so should definitely count as dead
|
||||
if (targetMobState == null)
|
||||
return true;
|
||||
// They might actually be alive.
|
||||
return targetMobState.IsDead();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives this mind a new role.
|
||||
/// </summary>
|
||||
/// <param name="role">The type of the role to give.</param>
|
||||
/// <returns>The instance of the role.</returns>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if we already have a role with this type.
|
||||
/// </exception>
|
||||
public Role AddRole(Role role)
|
||||
{
|
||||
if (_roles.Contains(role))
|
||||
{
|
||||
throw new ArgumentException($"We already have this role: {role}");
|
||||
}
|
||||
|
||||
_roles.Add(role);
|
||||
role.Greet();
|
||||
|
||||
var message = new RoleAddedMessage(role);
|
||||
OwnedEntity?.SendMessage(OwnedComponent, message);
|
||||
|
||||
return role;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a role from this mind.
|
||||
/// </summary>
|
||||
/// <param name="role">The type of the role to remove.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if we do not have this role.
|
||||
/// </exception>
|
||||
public void RemoveRole(Role role)
|
||||
{
|
||||
if (!_roles.Contains(role))
|
||||
{
|
||||
throw new ArgumentException($"We do not have this role: {role}");
|
||||
}
|
||||
|
||||
_roles.Remove(role);
|
||||
|
||||
var message = new RoleRemovedMessage(role);
|
||||
OwnedEntity?.SendMessage(OwnedComponent, message);
|
||||
}
|
||||
|
||||
public bool HasRole<T>() where T : Role
|
||||
{
|
||||
var t = typeof(T);
|
||||
|
||||
return _roles.Any(role => role.GetType() == t);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an objective to this mind.
|
||||
/// </summary>
|
||||
public bool TryAddObjective(ObjectivePrototype objectivePrototype)
|
||||
{
|
||||
if (!objectivePrototype.CanBeAssigned(this))
|
||||
return false;
|
||||
var objective = objectivePrototype.GetObjective(this);
|
||||
if (_objectives.Contains(objective))
|
||||
return false;
|
||||
_objectives.Add(objective);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an objective to this mind.
|
||||
/// </summary>
|
||||
/// <returns>Returns true if the removal succeeded.</returns>
|
||||
public bool TryRemoveObjective(int index)
|
||||
{
|
||||
if (_objectives.Count >= index) return false;
|
||||
|
||||
var objective = _objectives[index];
|
||||
_objectives.Remove(objective);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Transfer this mind's control over to a new entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">
|
||||
/// The entity to control.
|
||||
/// Can be null, in which case it will simply detach the mind from any entity.
|
||||
/// </param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if <paramref name="entity"/> is already owned by another mind.
|
||||
/// </exception>
|
||||
public void TransferTo(IEntity? entity)
|
||||
{
|
||||
MindComponent? component = null;
|
||||
var alreadyAttached = false;
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
if (!entity.TryGetComponent(out component))
|
||||
{
|
||||
component = entity.AddComponent<MindComponent>();
|
||||
}
|
||||
else if (component.HasMind)
|
||||
{
|
||||
// TODO: Kick them out, maybe?
|
||||
throw new ArgumentException("That entity already has a mind.", nameof(entity));
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out ActorComponent? 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;
|
||||
}
|
||||
}
|
||||
|
||||
OwnedComponent?.InternalEjectMind();
|
||||
|
||||
OwnedComponent = component;
|
||||
OwnedComponent?.InternalAssignMind(this);
|
||||
|
||||
if (VisitingEntity?.HasComponent<GhostComponent>() == false)
|
||||
VisitingEntity = null;
|
||||
|
||||
// Player is CURRENTLY connected.
|
||||
if (Session != null && !alreadyAttached && VisitingEntity == null)
|
||||
{
|
||||
Session.AttachToEntity(entity);
|
||||
Logger.Info($"Session {Session.Name} transferred to entity {entity}.");
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveOwningPlayer()
|
||||
{
|
||||
UserId = null;
|
||||
}
|
||||
|
||||
public void ChangeOwningPlayer(NetUserId? 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 (UserId.HasValue)
|
||||
{
|
||||
var data = playerMgr.GetPlayerData(UserId.Value).ContentData();
|
||||
DebugTools.AssertNotNull(data);
|
||||
data!.Mind = null;
|
||||
}
|
||||
|
||||
UserId = newOwner;
|
||||
if (!newOwner.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Yank new owner out of their old mind too.
|
||||
// Can I mention how much I love the word yank?
|
||||
DebugTools.AssertNotNull(newOwnerData);
|
||||
newOwnerData!.Mind?.ChangeOwningPlayer(null);
|
||||
newOwnerData.Mind = this;
|
||||
}
|
||||
|
||||
public void Visit(IEntity entity)
|
||||
{
|
||||
Session?.AttachToEntity(entity);
|
||||
VisitingEntity = entity;
|
||||
|
||||
var comp = entity.AddComponent<VisitingMindComponent>();
|
||||
comp.Mind = this;
|
||||
|
||||
Logger.Info($"Session {Session?.Name} visiting entity {entity}.");
|
||||
}
|
||||
|
||||
public void UnVisit()
|
||||
{
|
||||
if (!IsVisitingEntity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Session?.AttachToEntity(OwnedEntity);
|
||||
var oldVisitingEnt = VisitingEntity;
|
||||
// Null this before removing the component to avoid any infinite loops.
|
||||
VisitingEntity = null;
|
||||
|
||||
DebugTools.AssertNotNull(oldVisitingEnt);
|
||||
|
||||
if (oldVisitingEnt!.HasComponent<VisitingMindComponent>())
|
||||
{
|
||||
oldVisitingEnt.RemoveComponent<VisitingMindComponent>();
|
||||
}
|
||||
|
||||
oldVisitingEnt.EntityManager.EventBus.RaiseLocalEvent(oldVisitingEnt.Uid, new MindUnvisitedMessage());
|
||||
}
|
||||
|
||||
public bool TryGetSession([NotNullWhen(true)] out IPlayerSession? session)
|
||||
{
|
||||
return (session = Session) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Content.Server/Mind/MindHelpers.cs
Normal file
20
Content.Server/Mind/MindHelpers.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Players;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Mind
|
||||
{
|
||||
internal static class MindHelpers
|
||||
{
|
||||
internal static void SendToGhost(this IEntity entity, bool canReturn=false)
|
||||
{
|
||||
var mind = entity.PlayerSession()?.ContentData()?.Mind;
|
||||
|
||||
if (mind == null) return;
|
||||
|
||||
IoCManager.Resolve<IGameTicker>().OnGhostAttempt(mind, canReturn);
|
||||
}
|
||||
}
|
||||
}
|
||||
62
Content.Server/Mind/Verbs/ControlMobVerb.cs
Normal file
62
Content.Server/Mind/Verbs/ControlMobVerb.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Mind.Verbs
|
||||
{
|
||||
[GlobalVerb]
|
||||
public class ControlMobVerb : GlobalVerb
|
||||
{
|
||||
public override bool RequireInteractionRange => false;
|
||||
public override bool BlockedByContainers => false;
|
||||
|
||||
public override void GetData(IEntity user, IEntity target, VerbData data)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
|
||||
var groupController = IoCManager.Resolve<IConGroupController>();
|
||||
if (user == target)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.TryGetComponent<ActorComponent>(out var player))
|
||||
{
|
||||
if (!user.HasComponent<MindComponent>() || !target.HasComponent<MindComponent>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (groupController.CanCommand(player.PlayerSession, "controlmob"))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Visible;
|
||||
data.Text = Loc.GetString("Control Mob");
|
||||
data.CategoryData = VerbCategories.Debug;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Activate(IEntity user, IEntity target)
|
||||
{
|
||||
var groupController = IoCManager.Resolve<IConGroupController>();
|
||||
|
||||
var player = user.GetComponent<ActorComponent>().PlayerSession;
|
||||
if (!groupController.CanCommand(player, "controlmob"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var userMind = player.ContentData()?.Mind;
|
||||
|
||||
var targetMind = target.GetComponent<MindComponent>();
|
||||
|
||||
targetMind.Mind?.TransferTo(null);
|
||||
userMind?.TransferTo(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Content.Server/Mind/Verbs/MakeSentientVerb.cs
Normal file
53
Content.Server/Mind/Verbs/MakeSentientVerb.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Content.Server.Mind.Commands;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Mind.Verbs
|
||||
{
|
||||
[GlobalVerb]
|
||||
public class MakeSentientVerb : GlobalVerb
|
||||
{
|
||||
public override bool RequireInteractionRange => false;
|
||||
public override bool BlockedByContainers => false;
|
||||
|
||||
public override void GetData(IEntity user, IEntity target, VerbData data)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
|
||||
var groupController = IoCManager.Resolve<IConGroupController>();
|
||||
|
||||
if (user == target || target.HasComponent<MindComponent>())
|
||||
return;
|
||||
|
||||
var player = user.GetComponent<ActorComponent>().PlayerSession;
|
||||
if (groupController.CanCommand(player, "makesentient"))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Visible;
|
||||
data.Text = Loc.GetString("Make Sentient");
|
||||
data.CategoryData = VerbCategories.Debug;
|
||||
data.IconTexture = "/Textures/Interface/VerbIcons/sentient.svg.192dpi.png";
|
||||
}
|
||||
}
|
||||
|
||||
public override void Activate(IEntity user, IEntity target)
|
||||
{
|
||||
var groupController = IoCManager.Resolve<IConGroupController>();
|
||||
|
||||
var player = user.GetComponent<ActorComponent>().PlayerSession;
|
||||
if (!groupController.CanCommand(player, "makesentient"))
|
||||
return;
|
||||
|
||||
var host = IoCManager.Resolve<IServerConsoleHost>();
|
||||
var cmd = new MakeSentientCommand();
|
||||
var uidStr = target.Uid.ToString();
|
||||
cmd.Execute(new ConsoleShell(host, player), $"{cmd.Command} {uidStr}",
|
||||
new[] {uidStr});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user