Stop pAIs from being able to wipe each other/do other odd things, pAIs name themselves after their owners (#5160)

* Stop pAIs from being able to wipe each other/do other odd things they shouldn't

* pAI: device changes name to indicate owner

* Make PAIComponent networked (just in case)

It'll be needed in future anyway
This commit is contained in:
20kdc
2021-11-04 22:29:16 +00:00
committed by GitHub
parent c0954ce08d
commit d9cc7ef7d4
7 changed files with 106 additions and 39 deletions

View File

@@ -1,21 +0,0 @@
using Robust.Shared.GameObjects;
namespace Content.Server.PAI
{
/// <summary>
/// pAIs, or Personal AIs, are essentially portable ghost role generators.
/// In their current implementation in SS14, they create a ghost role anyone can access,
/// and that a player can also "wipe" (reset/kick out player).
/// Theoretically speaking pAIs are supposed to use a dedicated "offer and select" system,
/// with the player holding the pAI being able to choose one of the ghosts in the round.
/// This seems too complicated for an initial implementation, though,
/// and there's not always enough players and ghost roles to justify it.
/// All logic in PAISystem.
/// </summary>
[RegisterComponent]
public class PAIComponent : Component
{
public override string Name => "PAI";
}
}

View File

@@ -14,16 +14,7 @@ using Robust.Shared.Player;
namespace Content.Server.PAI
{
/// <summary>
/// pAIs, or Personal AIs, are essentially portable ghost role generators.
/// In their current implementation, they create a ghost role anyone can access,
/// and that a player can also "wipe" (reset/kick out player).
/// Theoretically speaking pAIs are supposed to use a dedicated "offer and select" system,
/// with the player holding the pAI being able to choose one of the ghosts in the round.
/// This seems too complicated for an initial implementation, though,
/// and there's not always enough players and ghost roles to justify it.
/// </summary>
public class PAISystem : EntitySystem
public class PAISystem : SharedPAISystem
{
[Dependency] private readonly PopupSystem _popupSystem = default!;
@@ -78,6 +69,9 @@ namespace Content.Server.PAI
return;
}
// Ownership tag
component.Owner.Name = Loc.GetString("pai-system-pai-name", ("owner", args.User));
var ghostFinder = EntityManager.EnsureComponent<GhostTakeoverAvailableComponent>(uid);
ghostFinder.RoleName = Loc.GetString("pai-system-role-name");
@@ -90,7 +84,7 @@ namespace Content.Server.PAI
private void OnMindRemoved(EntityUid uid, PAIComponent component, MindRemovedMessage args)
{
// Mind was removed, shutdown the PAI.
UpdatePAIAppearance(uid, PAIStatus.Off);
PAITurningOff(uid);
}
private void OnMindAdded(EntityUid uid, PAIComponent pai, MindAddedMessage args)
@@ -101,6 +95,17 @@ namespace Content.Server.PAI
UpdatePAIAppearance(uid, PAIStatus.On);
}
private void PAITurningOff(EntityUid uid)
{
UpdatePAIAppearance(uid, PAIStatus.Off);
if (EntityManager.TryGetComponent<MetaDataComponent>(uid, out var metadata))
{
var proto = metadata.EntityPrototype;
if (proto != null)
metadata.EntityName = proto.Name;
}
}
private void UpdatePAIAppearance(EntityUid uid, PAIStatus status)
{
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
@@ -128,7 +133,7 @@ namespace Content.Server.PAI
{
EntityManager.RemoveComponent<MindComponent>(uid);
_popupSystem.PopupEntity(Loc.GetString("pai-system-wiped-device"), uid, Filter.Entities(args.User.Uid));
UpdatePAIAppearance(uid, PAIStatus.Off);
PAITurningOff(uid);
}
};
args.Verbs.Add(verb);
@@ -144,7 +149,7 @@ namespace Content.Server.PAI
{
EntityManager.RemoveComponent<GhostTakeoverAvailableComponent>(uid);
_popupSystem.PopupEntity(Loc.GetString("pai-system-stopped-searching"), uid, Filter.Entities(args.User.Uid));
UpdatePAIAppearance(uid, PAIStatus.Off);
PAITurningOff(uid);
}
};
args.Verbs.Add(verb);