Microwaved pais get scrambled name + randomly bricked (#19982)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-09-16 07:07:36 +01:00
committed by GitHub
parent 8aba52d796
commit e8c58d1574
4 changed files with 166 additions and 75 deletions

View File

@@ -124,6 +124,7 @@ public sealed class ToggleableGhostRoleSystem : EntitySystem
{ {
if (component.Deleted || !HasComp<GhostTakeoverAvailableComponent>(uid)) if (component.Deleted || !HasComp<GhostTakeoverAvailableComponent>(uid))
return; return;
RemCompDeferred<GhostTakeoverAvailableComponent>(uid); RemCompDeferred<GhostTakeoverAvailableComponent>(uid);
RemCompDeferred<GhostRoleComponent>(uid); RemCompDeferred<GhostRoleComponent>(uid);
_popup.PopupEntity(Loc.GetString(component.StopSearchVerbPopup), uid, args.User); _popup.PopupEntity(Loc.GetString(component.StopSearchVerbPopup), uid, args.User);
@@ -133,4 +134,26 @@ public sealed class ToggleableGhostRoleSystem : EntitySystem
args.Verbs.Add(verb); args.Verbs.Add(verb);
} }
} }
/// <summary>
/// If there is a player present, kicks it out.
/// If not, prevents future ghosts taking it.
/// No popups are made, but appearance is updated.
/// </summary>
public void Wipe(EntityUid uid)
{
if (TryComp<MindContainerComponent>(uid, out var mindContainer) &&
mindContainer.HasMind &&
_mind.TryGetMind(uid, out var mindId, out var mind))
{
_mind.TransferTo(mindId, null, mind: mind);
}
if (!HasComp<GhostTakeoverAvailableComponent>(uid))
return;
RemCompDeferred<GhostTakeoverAvailableComponent>(uid);
RemCompDeferred<GhostRoleComponent>(uid);
UpdateAppearance(uid, ToggleableGhostRoleStatus.Off);
}
} }

View File

@@ -1,15 +1,29 @@
using Content.Server.Ghost.Roles;
using Content.Server.Ghost.Roles.Components;
using Content.Server.Instruments; using Content.Server.Instruments;
using Content.Server.Kitchen.Components;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
using Content.Shared.Mind.Components; using Content.Shared.Mind.Components;
using Content.Shared.PAI; using Content.Shared.PAI;
using Content.Shared.Popups;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Random;
using System.Text;
namespace Content.Server.PAI namespace Content.Server.PAI;
public sealed class PAISystem : SharedPAISystem
{ {
public sealed class PAISystem : SharedPAISystem
{
[Dependency] private readonly InstrumentSystem _instrumentSystem = default!; [Dependency] private readonly InstrumentSystem _instrumentSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!; [Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly ToggleableGhostRoleSystem _toggleableGhostRole = default!;
/// <summary>
/// Possible symbols that can be part of a scrambled pai's name.
/// </summary>
private static readonly char[] SYMBOLS = new[] { '#', '~', '-', '@', '&', '^', '%', '$', '*', ' '};
public override void Initialize() public override void Initialize()
{ {
@@ -18,6 +32,7 @@ namespace Content.Server.PAI
SubscribeLocalEvent<PAIComponent, UseInHandEvent>(OnUseInHand); SubscribeLocalEvent<PAIComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<PAIComponent, MindAddedMessage>(OnMindAdded); SubscribeLocalEvent<PAIComponent, MindAddedMessage>(OnMindAdded);
SubscribeLocalEvent<PAIComponent, MindRemovedMessage>(OnMindRemoved); SubscribeLocalEvent<PAIComponent, MindRemovedMessage>(OnMindRemoved);
SubscribeLocalEvent<PAIComponent, BeingMicrowavedEvent>(OnMicrowaved);
} }
private void OnUseInHand(EntityUid uid, PAIComponent component, UseInHandEvent args) private void OnUseInHand(EntityUid uid, PAIComponent component, UseInHandEvent args)
@@ -48,6 +63,41 @@ namespace Content.Server.PAI
PAITurningOff(uid); PAITurningOff(uid);
} }
private void OnMicrowaved(EntityUid uid, PAIComponent comp, BeingMicrowavedEvent args)
{
// name will always be scrambled whether it gets bricked or not, this is the reward
ScrambleName(uid, comp);
// randomly brick it
if (_random.Prob(comp.BrickChance))
{
_popup.PopupEntity(Loc.GetString(comp.BrickPopup), uid, PopupType.LargeCaution);
_toggleableGhostRole.Wipe(uid);
RemComp<PAIComponent>(uid);
RemComp<ToggleableGhostRoleComponent>(uid);
}
else
{
// you are lucky...
_popup.PopupEntity(Loc.GetString(comp.ScramblePopup), uid, PopupType.Large);
}
}
private void ScrambleName(EntityUid uid, PAIComponent comp)
{
// create a new random name
var len = _random.Next(6, 18);
var name = new StringBuilder(len);
for (int i = 0; i < len; i++)
{
name.Append(_random.Pick(SYMBOLS));
}
// add 's pAI to the scrambled name
var val = Loc.GetString("pai-system-pai-name-raw", ("name", name.ToString()));
_metaData.SetEntityName(uid, val);
}
public void PAITurningOff(EntityUid uid) public void PAITurningOff(EntityUid uid)
{ {
// Close the instrument interface if it was open // Close the instrument interface if it was open
@@ -66,5 +116,4 @@ namespace Content.Server.PAI
_metaData.SetEntityName(uid, proto.Name); _metaData.SetEntityName(uid, proto.Name);
} }
} }
}
} }

View File

@@ -2,26 +2,26 @@ using Robust.Shared.GameStates;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.PAI namespace Content.Shared.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, NetworkedComponent]
public sealed partial class PAIComponent : Component
{ {
/// <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, NetworkedComponent]
public sealed partial class PAIComponent : Component
{
/// <summary> /// <summary>
/// The last person who activated this PAI. /// The last person who activated this PAI.
/// Used for assigning the name. /// Used for assigning the name.
/// </summary> /// </summary>
[DataField("lastUSer"), ViewVariables(VVAccess.ReadWrite)] [DataField("lastUser"), ViewVariables(VVAccess.ReadWrite)]
public EntityUid? LastUser; public EntityUid? LastUser;
[DataField("midiActionId", serverOnly: true, [DataField("midiActionId", serverOnly: true,
@@ -30,6 +30,22 @@ namespace Content.Shared.PAI
[DataField("midiAction", serverOnly: true)] // server only, as it uses a server-BUI event !type [DataField("midiAction", serverOnly: true)] // server only, as it uses a server-BUI event !type
public EntityUid? MidiAction; public EntityUid? MidiAction;
}
}
/// <summary>
/// When microwaved there is this chance to brick the pai, kicking out its player and preventing it from being used again.
/// </summary>
[DataField("brickChance")]
public float BrickChance = 0.5f;
/// <summary>
/// Locale id for the popup shown when the pai gets bricked.
/// </summary>
[DataField("brickPopup")]
public string BrickPopup = "pai-system-brick-popup";
/// <summary>
/// Locale id for the popup shown when the pai is microwaved but does not get bricked.
/// </summary>
[DataField("scramblePopup")]
public string ScramblePopup = "pai-system-scramble-popup";
}

View File

@@ -17,4 +17,7 @@ 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 pai-system-pai-name = { CAPITALIZE(THE($owner)) }'s pAI
pai-system-pai-name-raw = {$name}'s pAI
pai-system-brick-popup = The pAI's circuits loudly pop and fizzle out!
pai-system-scramble-popup = The pAI's circuits are overloaded with electricity!