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:
@@ -65,7 +65,6 @@ namespace Content.Client.Entry
|
|||||||
"Paper",
|
"Paper",
|
||||||
"Write",
|
"Write",
|
||||||
"Bloodstream",
|
"Bloodstream",
|
||||||
"PAI",
|
|
||||||
"TransformableContainer",
|
"TransformableContainer",
|
||||||
"Mind",
|
"Mind",
|
||||||
"StorageFill",
|
"StorageFill",
|
||||||
|
|||||||
8
Content.Client/PAI/PAISystem.cs
Normal file
8
Content.Client/PAI/PAISystem.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Content.Shared.PAI;
|
||||||
|
|
||||||
|
namespace Content.Client.PAI
|
||||||
|
{
|
||||||
|
public class PAISystem : SharedPAISystem
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,16 +14,7 @@ using Robust.Shared.Player;
|
|||||||
|
|
||||||
namespace Content.Server.PAI
|
namespace Content.Server.PAI
|
||||||
{
|
{
|
||||||
/// <summary>
|
public class PAISystem : SharedPAISystem
|
||||||
/// 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
|
|
||||||
{
|
{
|
||||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||||
|
|
||||||
@@ -78,6 +69,9 @@ namespace Content.Server.PAI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ownership tag
|
||||||
|
component.Owner.Name = Loc.GetString("pai-system-pai-name", ("owner", args.User));
|
||||||
|
|
||||||
var ghostFinder = EntityManager.EnsureComponent<GhostTakeoverAvailableComponent>(uid);
|
var ghostFinder = EntityManager.EnsureComponent<GhostTakeoverAvailableComponent>(uid);
|
||||||
|
|
||||||
ghostFinder.RoleName = Loc.GetString("pai-system-role-name");
|
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)
|
private void OnMindRemoved(EntityUid uid, PAIComponent component, MindRemovedMessage args)
|
||||||
{
|
{
|
||||||
// Mind was removed, shutdown the PAI.
|
// Mind was removed, shutdown the PAI.
|
||||||
UpdatePAIAppearance(uid, PAIStatus.Off);
|
PAITurningOff(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMindAdded(EntityUid uid, PAIComponent pai, MindAddedMessage args)
|
private void OnMindAdded(EntityUid uid, PAIComponent pai, MindAddedMessage args)
|
||||||
@@ -101,6 +95,17 @@ namespace Content.Server.PAI
|
|||||||
UpdatePAIAppearance(uid, PAIStatus.On);
|
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)
|
private void UpdatePAIAppearance(EntityUid uid, PAIStatus status)
|
||||||
{
|
{
|
||||||
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
|
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
|
||||||
@@ -128,7 +133,7 @@ namespace Content.Server.PAI
|
|||||||
{
|
{
|
||||||
EntityManager.RemoveComponent<MindComponent>(uid);
|
EntityManager.RemoveComponent<MindComponent>(uid);
|
||||||
_popupSystem.PopupEntity(Loc.GetString("pai-system-wiped-device"), uid, Filter.Entities(args.User.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);
|
args.Verbs.Add(verb);
|
||||||
@@ -144,7 +149,7 @@ namespace Content.Server.PAI
|
|||||||
{
|
{
|
||||||
EntityManager.RemoveComponent<GhostTakeoverAvailableComponent>(uid);
|
EntityManager.RemoveComponent<GhostTakeoverAvailableComponent>(uid);
|
||||||
_popupSystem.PopupEntity(Loc.GetString("pai-system-stopped-searching"), uid, Filter.Entities(args.User.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);
|
args.Verbs.Add(verb);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Server.PAI
|
namespace Content.Shared.PAI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// pAIs, or Personal AIs, are essentially portable ghost role generators.
|
/// pAIs, or Personal AIs, are essentially portable ghost role generators.
|
||||||
@@ -12,7 +14,7 @@ namespace Content.Server.PAI
|
|||||||
/// and there's not always enough players and ghost roles to justify it.
|
/// and there's not always enough players and ghost roles to justify it.
|
||||||
/// All logic in PAISystem.
|
/// All logic in PAISystem.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent, NetworkedComponent]
|
||||||
public class PAIComponent : Component
|
public class PAIComponent : Component
|
||||||
{
|
{
|
||||||
public override string Name => "PAI";
|
public override string Name => "PAI";
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
|
||||||
using Robust.Shared.ViewVariables;
|
|
||||||
|
|
||||||
namespace Content.Shared.PAI
|
|
||||||
{
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public enum PAIVisuals : byte
|
|
||||||
{
|
|
||||||
Status
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public enum PAIStatus : byte
|
|
||||||
{
|
|
||||||
Off,
|
|
||||||
Searching,
|
|
||||||
On
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
74
Content.Shared/PAI/SharedPAISystem.cs
Normal file
74
Content.Shared/PAI/SharedPAISystem.cs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
using System;
|
||||||
|
using Content.Shared.DragDrop;
|
||||||
|
using Content.Shared.Emoting;
|
||||||
|
using Content.Shared.Interaction.Events;
|
||||||
|
using Content.Shared.Item;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
|
namespace Content.Shared.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 abstract class SharedPAISystem : EntitySystem
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<PAIComponent, UseAttemptEvent>(OnUseAttempt);
|
||||||
|
SubscribeLocalEvent<PAIComponent, InteractionAttemptEvent>(OnInteractAttempt);
|
||||||
|
SubscribeLocalEvent<PAIComponent, AttackAttemptEvent>(OnAttackAttempt);
|
||||||
|
SubscribeLocalEvent<PAIComponent, DropAttemptEvent>(OnDropAttempt);
|
||||||
|
SubscribeLocalEvent<PAIComponent, PickupAttemptEvent>(OnPickupAttempt);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUseAttempt(EntityUid uid, PAIComponent component, UseAttemptEvent args)
|
||||||
|
{
|
||||||
|
args.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnInteractAttempt(EntityUid uid, PAIComponent component, InteractionAttemptEvent args)
|
||||||
|
{
|
||||||
|
args.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAttackAttempt(EntityUid uid, PAIComponent component, AttackAttemptEvent args)
|
||||||
|
{
|
||||||
|
args.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDropAttempt(EntityUid uid, PAIComponent component, DropAttemptEvent args)
|
||||||
|
{
|
||||||
|
args.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPickupAttempt(EntityUid uid, PAIComponent component, PickupAttemptEvent args)
|
||||||
|
{
|
||||||
|
args.Cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public enum PAIVisuals : byte
|
||||||
|
{
|
||||||
|
Status
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public enum PAIStatus : byte
|
||||||
|
{
|
||||||
|
Off,
|
||||||
|
Searching,
|
||||||
|
On
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -13,3 +13,5 @@ pai-system-wiped-device = The pAI was wiped from the device.
|
|||||||
pai-system-stop-searching-verb-text = Stop searching
|
pai-system-stop-searching-verb-text = Stop searching
|
||||||
pai-system-stopped-searching = The device stopped searching for a pAI.
|
pai-system-stopped-searching = The device stopped searching for a pAI.
|
||||||
|
|
||||||
|
pai-system-pai-name = { CAPITALIZE(THE($owner)) }'s pAI
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user