Placeholder pAIs, ghost role rules window (#4972)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Ghost.Roles.Components
|
||||
{
|
||||
@@ -11,6 +12,8 @@ namespace Content.Server.Ghost.Roles.Components
|
||||
|
||||
[DataField("description")] private string _roleDescription = "Unknown";
|
||||
|
||||
[DataField("rules")] private string _roleRules = "";
|
||||
|
||||
// We do this so updating RoleName and RoleDescription in VV updates the open EUIs.
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
@@ -35,6 +38,17 @@ namespace Content.Server.Ghost.Roles.Components
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string RoleRules
|
||||
{
|
||||
get => _roleRules;
|
||||
set
|
||||
{
|
||||
_roleRules = value;
|
||||
EntitySystem.Get<GhostRoleSystem>().UpdateAllEui();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public bool Taken { get; protected set; }
|
||||
|
||||
@@ -44,7 +58,8 @@ namespace Content.Server.Ghost.Roles.Components
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (_roleRules == "")
|
||||
_roleRules = Loc.GetString("ghost-role-component-default-rules");
|
||||
EntitySystem.Get<GhostRoleSystem>().RegisterGhostRole(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Content.Server.Ghost.Roles
|
||||
|
||||
foreach (var (id, role) in _ghostRoles)
|
||||
{
|
||||
roles[i] = new GhostRoleInfo(){Identifier = id, Name = role.RoleName, Description = role.RoleDescription};
|
||||
roles[i] = new GhostRoleInfo(){Identifier = id, Name = role.RoleName, Description = role.RoleDescription, Rules = role.RoleRules};
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Ghost.Roles
|
||||
{
|
||||
@@ -13,11 +14,11 @@ namespace Content.Server.Ghost.Roles
|
||||
{
|
||||
public string Command => "makeghostrole";
|
||||
public string Description => "Turns an entity into a ghost role.";
|
||||
public string Help => $"Usage: {Command} <entity uid> <name> <description>";
|
||||
public string Help => $"Usage: {Command} <entity uid> <name> <description> [<rules>]";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 3)
|
||||
if (args.Length < 3 || args.Length > 4)
|
||||
{
|
||||
shell.WriteLine($"Invalid amount of arguments.\n{Help}");
|
||||
return;
|
||||
@@ -46,6 +47,7 @@ namespace Content.Server.Ghost.Roles
|
||||
|
||||
var name = args[1];
|
||||
var description = args[2];
|
||||
var rules = args.Length >= 4 ? args[3] : Loc.GetString("ghost-role-component-default-rules");
|
||||
|
||||
if (entity.EnsureComponent(out GhostTakeoverAvailableComponent takeOver))
|
||||
{
|
||||
@@ -55,6 +57,7 @@ namespace Content.Server.Ghost.Roles
|
||||
|
||||
takeOver.RoleName = name;
|
||||
takeOver.RoleDescription = description;
|
||||
takeOver.RoleRules = rules;
|
||||
|
||||
shell.WriteLine($"Made entity {entity.Name} a ghost role.");
|
||||
}
|
||||
|
||||
21
Content.Server/PAI/PAIComponent.cs
Normal file
21
Content.Server/PAI/PAIComponent.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
154
Content.Server/PAI/PAISystem.cs
Normal file
154
Content.Server/PAI/PAISystem.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.PAI;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Ghost.Roles.Components;
|
||||
using Content.Server.Mind.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
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
|
||||
{
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<PAIComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<PAIComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<PAIComponent, MindAddedMessage>(OnMindAdded);
|
||||
SubscribeLocalEvent<PAIComponent, MindRemovedMessage>(OnMindRemoved);
|
||||
SubscribeLocalEvent<PAIComponent, GetActivationVerbsEvent>(AddWipeVerb);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, PAIComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (args.IsInDetailsRange)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<MindComponent>(uid, out var mind) && mind.HasMind)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("pai-system-pai-installed"));
|
||||
}
|
||||
else if (EntityManager.HasComponent<GhostTakeoverAvailableComponent>(uid))
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("pai-system-still-searching"));
|
||||
}
|
||||
else
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("pai-system-off"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUseInHand(EntityUid uid, PAIComponent component, UseInHandEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
// Placeholder PAIs are essentially portable ghost role generators.
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
// Check for pAI activation
|
||||
if (EntityManager.TryGetComponent<MindComponent>(uid, out var mind) && mind.HasMind)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("pai-system-pai-installed"), uid, Filter.Entities(args.User.Uid));
|
||||
return;
|
||||
}
|
||||
else if (EntityManager.HasComponent<GhostTakeoverAvailableComponent>(uid))
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("pai-system-still-searching"), uid, Filter.Entities(args.User.Uid));
|
||||
return;
|
||||
}
|
||||
|
||||
var ghostFinder = EntityManager.EnsureComponent<GhostTakeoverAvailableComponent>(uid);
|
||||
|
||||
ghostFinder.RoleName = Loc.GetString("pai-system-role-name");
|
||||
ghostFinder.RoleDescription = Loc.GetString("pai-system-role-description");
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString("pai-system-searching"), uid, Filter.Entities(args.User.Uid));
|
||||
UpdatePAIAppearance(uid, PAIStatus.Searching);
|
||||
}
|
||||
|
||||
private void OnMindRemoved(EntityUid uid, PAIComponent component, MindRemovedMessage args)
|
||||
{
|
||||
// Mind was removed, shutdown the PAI.
|
||||
UpdatePAIAppearance(uid, PAIStatus.Off);
|
||||
}
|
||||
|
||||
private void OnMindAdded(EntityUid uid, PAIComponent pai, MindAddedMessage args)
|
||||
{
|
||||
// Mind was added, shutdown the ghost role stuff so it won't get in the way
|
||||
if (EntityManager.HasComponent<GhostTakeoverAvailableComponent>(uid))
|
||||
EntityManager.RemoveComponent<GhostTakeoverAvailableComponent>(uid);
|
||||
UpdatePAIAppearance(uid, PAIStatus.On);
|
||||
}
|
||||
|
||||
private void UpdatePAIAppearance(EntityUid uid, PAIStatus status)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
|
||||
{
|
||||
appearance.SetData(PAIVisuals.Status, status);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddWipeVerb(EntityUid uid, PAIComponent pai, GetActivationVerbsEvent args)
|
||||
{
|
||||
if (args.User == null || !args.CanAccess || !args.CanInteract)
|
||||
return;
|
||||
|
||||
if (EntityManager.TryGetComponent<MindComponent>(uid, out var mind) && mind.HasMind)
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("pai-system-wipe-device-verb-text");
|
||||
verb.Act = () => {
|
||||
if (pai.Deleted)
|
||||
return;
|
||||
// Wiping device :(
|
||||
// The shutdown of the Mind should cause automatic reset of the pAI during OnMindRemoved
|
||||
// EDIT: But it doesn't!!!! Wtf? Do stuff manually
|
||||
if (EntityManager.HasComponent<MindComponent>(uid))
|
||||
{
|
||||
EntityManager.RemoveComponent<MindComponent>(uid);
|
||||
_popupSystem.PopupEntity(Loc.GetString("pai-system-wiped-device"), uid, Filter.Entities(args.User.Uid));
|
||||
UpdatePAIAppearance(uid, PAIStatus.Off);
|
||||
}
|
||||
};
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
else if (EntityManager.HasComponent<GhostTakeoverAvailableComponent>(uid))
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("pai-system-stop-searching-verb-text");
|
||||
verb.Act = () => {
|
||||
if (pai.Deleted)
|
||||
return;
|
||||
if (EntityManager.HasComponent<GhostTakeoverAvailableComponent>(uid))
|
||||
{
|
||||
EntityManager.RemoveComponent<GhostTakeoverAvailableComponent>(uid);
|
||||
_popupSystem.PopupEntity(Loc.GetString("pai-system-stopped-searching"), uid, Filter.Entities(args.User.Uid));
|
||||
UpdatePAIAppearance(uid, PAIStatus.Off);
|
||||
}
|
||||
};
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user