Merge remote-tracking branch 'upstream/stable' into ed-15-10-2024-upstream
# Conflicts: # Content.Server/Station/Systems/StationSpawningSystem.cs
This commit is contained in:
@@ -20,7 +20,12 @@ public sealed partial class IdCardComponent : Component
|
||||
[DataField]
|
||||
[AutoNetworkedField]
|
||||
[Access(typeof(SharedIdCardSystem), typeof(SharedPdaSystem), typeof(SharedAgentIdCardSystem), Other = AccessPermissions.ReadWrite)]
|
||||
public string? JobTitle;
|
||||
public LocId? JobTitle;
|
||||
|
||||
private string? _jobTitle;
|
||||
|
||||
[Access(typeof(SharedIdCardSystem), typeof(SharedPdaSystem), typeof(SharedAgentIdCardSystem), Other = AccessPermissions.ReadWriteExecute)]
|
||||
public string? LocalizedJobTitle { set => _jobTitle = value; get => _jobTitle ?? Loc.GetString(JobTitle ?? string.Empty); }
|
||||
|
||||
/// <summary>
|
||||
/// The state of the job icon rsi.
|
||||
|
||||
@@ -67,7 +67,7 @@ public sealed class IdExaminableSystem : EntitySystem
|
||||
|
||||
private string GetNameAndJob(IdCardComponent id)
|
||||
{
|
||||
var jobSuffix = string.IsNullOrWhiteSpace(id.JobTitle) ? string.Empty : $" ({id.JobTitle})";
|
||||
var jobSuffix = string.IsNullOrWhiteSpace(id.LocalizedJobTitle) ? string.Empty : $" ({id.LocalizedJobTitle})";
|
||||
|
||||
var val = string.IsNullOrWhiteSpace(id.FullName)
|
||||
? Loc.GetString(id.NameLocId,
|
||||
|
||||
@@ -116,6 +116,7 @@ public abstract class SharedIdCardSystem : EntitySystem
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If provided with a player's EntityUid to the player parameter, adds the change to the admin logs.
|
||||
/// Actually works with the LocalizedJobTitle DataField and not with JobTitle.
|
||||
/// </remarks>
|
||||
public bool TryChangeJobTitle(EntityUid uid, string? jobTitle, IdCardComponent? id = null, EntityUid? player = null)
|
||||
{
|
||||
@@ -134,9 +135,9 @@ public abstract class SharedIdCardSystem : EntitySystem
|
||||
jobTitle = null;
|
||||
}
|
||||
|
||||
if (id.JobTitle == jobTitle)
|
||||
if (id.LocalizedJobTitle == jobTitle)
|
||||
return true;
|
||||
id.JobTitle = jobTitle;
|
||||
id.LocalizedJobTitle = jobTitle;
|
||||
Dirty(uid, id);
|
||||
UpdateEntityName(uid, id);
|
||||
|
||||
@@ -238,7 +239,7 @@ public abstract class SharedIdCardSystem : EntitySystem
|
||||
if (!Resolve(uid, ref id))
|
||||
return;
|
||||
|
||||
var jobSuffix = string.IsNullOrWhiteSpace(id.JobTitle) ? string.Empty : $" ({id.JobTitle})";
|
||||
var jobSuffix = string.IsNullOrWhiteSpace(id.LocalizedJobTitle) ? string.Empty : $" ({id.LocalizedJobTitle})";
|
||||
|
||||
var val = string.IsNullOrWhiteSpace(id.FullName)
|
||||
? Loc.GetString(id.NameLocId,
|
||||
@@ -251,7 +252,7 @@ public abstract class SharedIdCardSystem : EntitySystem
|
||||
|
||||
private static string ExtractFullTitle(IdCardComponent idCardComponent)
|
||||
{
|
||||
return $"{idCardComponent.FullName} ({CultureInfo.CurrentCulture.TextInfo.ToTitleCase(idCardComponent.JobTitle ?? string.Empty)})"
|
||||
return $"{idCardComponent.FullName} ({CultureInfo.CurrentCulture.TextInfo.ToTitleCase(idCardComponent.LocalizedJobTitle ?? string.Empty)})"
|
||||
.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.ChangeNameInContainer;
|
||||
|
||||
/// <summary>
|
||||
/// An entity with this component will get its name and verb chaned to the container it's inside of. E.g, if your a
|
||||
/// pAI that has this component and are inside a lizard plushie, your name when talking will be "lizard plushie".
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(ChangeNameInContainerSystem))]
|
||||
public sealed partial class ChangeVoiceInContainerComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// A whitelist of containers that will change the name.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public EntityWhitelist? Whitelist;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Content.Shared.Chat;
|
||||
using Robust.Shared.Containers;
|
||||
using Content.Shared.Whitelist;
|
||||
using Content.Shared.Speech;
|
||||
|
||||
namespace Content.Shared.ChangeNameInContainer;
|
||||
|
||||
public sealed partial class ChangeNameInContainerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ChangeVoiceInContainerComponent, TransformSpeakerNameEvent>(OnTransformSpeakerName);
|
||||
}
|
||||
|
||||
private void OnTransformSpeakerName(Entity<ChangeVoiceInContainerComponent> ent, ref TransformSpeakerNameEvent args)
|
||||
{
|
||||
if (!_container.TryGetContainingContainer((ent, null, null), out var container)
|
||||
|| _whitelist.IsWhitelistFail(ent.Comp.Whitelist, container.Owner))
|
||||
return;
|
||||
|
||||
args.VoiceName = Name(container.Owner);
|
||||
if (TryComp<SpeechComponent>(container.Owner, out var speechComp))
|
||||
args.SpeechVerb = speechComp.SpeechVerb;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Numerics;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Clothing.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Defines something as causing waddling when worn.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class WaddleWhenWornComponent : Component
|
||||
{
|
||||
///<summary>
|
||||
/// How high should they hop during the waddle? Higher hop = more energy.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public Vector2 HopIntensity = new(0, 0.25f);
|
||||
|
||||
/// <summary>
|
||||
/// How far should they rock backward and forward during the waddle?
|
||||
/// Each step will alternate between this being a positive and negative rotation. More rock = more scary.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float TumbleIntensity = 20.0f;
|
||||
|
||||
/// <summary>
|
||||
/// How long should a complete step take? Less time = more chaos.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float AnimationLength = 0.66f;
|
||||
|
||||
/// <summary>
|
||||
/// How much shorter should the animation be when running?
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float RunAnimationLengthMultiplier = 0.568f;
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using Content.Shared.Clothing;
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Inventory.Events;
|
||||
|
||||
namespace Content.Shared.Clothing.EntitySystems;
|
||||
|
||||
public sealed class WaddleClothingSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<WaddleWhenWornComponent, ClothingGotEquippedEvent>(OnGotEquipped);
|
||||
SubscribeLocalEvent<WaddleWhenWornComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
|
||||
}
|
||||
|
||||
private void OnGotEquipped(EntityUid entity, WaddleWhenWornComponent comp, ClothingGotEquippedEvent args)
|
||||
{
|
||||
var waddleAnimComp = EnsureComp<WaddleAnimationComponent>(args.Wearer);
|
||||
|
||||
waddleAnimComp.AnimationLength = comp.AnimationLength;
|
||||
waddleAnimComp.HopIntensity = comp.HopIntensity;
|
||||
waddleAnimComp.RunAnimationLengthMultiplier = comp.RunAnimationLengthMultiplier;
|
||||
waddleAnimComp.TumbleIntensity = comp.TumbleIntensity;
|
||||
}
|
||||
|
||||
private void OnGotUnequipped(EntityUid entity, WaddleWhenWornComponent comp, ClothingGotUnequippedEvent args)
|
||||
{
|
||||
RemComp<WaddleAnimationComponent>(args.Wearer);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ public sealed partial class MindContainerComponent : Component
|
||||
/// The mind controlling this mob. Can be null.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
[Access(typeof(SharedMindSystem), Other = AccessPermissions.ReadWriteExecute)] // FIXME Friends
|
||||
public EntityUid? Mind { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -35,7 +34,6 @@ public sealed partial class MindContainerComponent : Component
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("ghostOnShutdown")]
|
||||
[Access(typeof(SharedMindSystem), Other = AccessPermissions.ReadWriteExecute)] // FIXME Friends
|
||||
public bool GhostOnShutdown { get; set; } = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Mind.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
@@ -87,17 +86,21 @@ public sealed partial class MindComponent : Component
|
||||
/// <summary>
|
||||
/// Prevents user from ghosting out
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("preventGhosting")]
|
||||
[DataField]
|
||||
public bool PreventGhosting { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Prevents user from suiciding
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("preventSuicide")]
|
||||
[DataField]
|
||||
public bool PreventSuicide { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Mind Role Entities belonging to this Mind
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public List<EntityUid> MindRoles = new List<EntityUid>();
|
||||
|
||||
/// <summary>
|
||||
/// The session of the player owning this mind.
|
||||
/// Can be null, in which case the player is currently not logged in.
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Movement.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Declares that an entity has started to waddle like a duck/clown.
|
||||
/// </summary>
|
||||
/// <param name="entity">The newly be-waddled.</param>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StartedWaddlingEvent(NetEntity entity) : EntityEventArgs
|
||||
{
|
||||
public NetEntity Entity = entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Declares that an entity has stopped waddling like a duck/clown.
|
||||
/// </summary>
|
||||
/// <param name="entity">The former waddle-er.</param>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StoppedWaddlingEvent(NetEntity entity) : EntityEventArgs
|
||||
{
|
||||
public NetEntity Entity = entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines something as having a waddle animation when it moves.
|
||||
/// </summary>
|
||||
[RegisterComponent, AutoGenerateComponentState]
|
||||
public sealed partial class WaddleAnimationComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// What's the name of this animation? Make sure it's unique so it can play along side other animations.
|
||||
/// This prevents someone accidentally causing two identical waddling effects to play on someone at the same time.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string KeyName = "Waddle";
|
||||
|
||||
///<summary>
|
||||
/// How high should they hop during the waddle? Higher hop = more energy.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public Vector2 HopIntensity = new(0, 0.25f);
|
||||
|
||||
/// <summary>
|
||||
/// How far should they rock backward and forward during the waddle?
|
||||
/// Each step will alternate between this being a positive and negative rotation. More rock = more scary.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float TumbleIntensity = 20.0f;
|
||||
|
||||
/// <summary>
|
||||
/// How long should a complete step take? Less time = more chaos.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float AnimationLength = 0.66f;
|
||||
|
||||
/// <summary>
|
||||
/// How much shorter should the animation be when running?
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float RunAnimationLengthMultiplier = 0.568f;
|
||||
|
||||
/// <summary>
|
||||
/// Stores which step we made last, so if someone cancels out of the animation mid-step then restarts it looks more natural.
|
||||
/// </summary>
|
||||
public bool LastStep;
|
||||
|
||||
/// <summary>
|
||||
/// Stores if we're currently waddling so we can start/stop as appropriate and can tell other systems our state.
|
||||
/// </summary>
|
||||
[AutoNetworkedField]
|
||||
public bool IsCurrentlyWaddling;
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.Gravity;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Standing;
|
||||
using Content.Shared.Stunnable;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Movement.Systems;
|
||||
|
||||
public abstract class SharedWaddleAnimationSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
// Startup
|
||||
SubscribeLocalEvent<WaddleAnimationComponent, ComponentStartup>(OnComponentStartup);
|
||||
|
||||
// Start moving possibilities
|
||||
SubscribeLocalEvent<WaddleAnimationComponent, MoveInputEvent>(OnMovementInput);
|
||||
SubscribeLocalEvent<WaddleAnimationComponent, StoodEvent>(OnStood);
|
||||
|
||||
// Stop moving possibilities
|
||||
SubscribeLocalEvent((Entity<WaddleAnimationComponent> ent, ref StunnedEvent _) => StopWaddling(ent));
|
||||
SubscribeLocalEvent((Entity<WaddleAnimationComponent> ent, ref DownedEvent _) => StopWaddling(ent));
|
||||
SubscribeLocalEvent((Entity<WaddleAnimationComponent> ent, ref BuckledEvent _) => StopWaddling(ent));
|
||||
SubscribeLocalEvent<WaddleAnimationComponent, GravityChangedEvent>(OnGravityChanged);
|
||||
}
|
||||
|
||||
private void OnGravityChanged(Entity<WaddleAnimationComponent> ent, ref GravityChangedEvent args)
|
||||
{
|
||||
if (!args.HasGravity && ent.Comp.IsCurrentlyWaddling)
|
||||
StopWaddling(ent);
|
||||
}
|
||||
|
||||
private void OnComponentStartup(Entity<WaddleAnimationComponent> entity, ref ComponentStartup args)
|
||||
{
|
||||
if (!TryComp<InputMoverComponent>(entity.Owner, out var moverComponent))
|
||||
return;
|
||||
|
||||
// If the waddler is currently moving, make them start waddling
|
||||
if ((moverComponent.HeldMoveButtons & MoveButtons.AnyDirection) == MoveButtons.AnyDirection)
|
||||
{
|
||||
RaiseNetworkEvent(new StartedWaddlingEvent(GetNetEntity(entity.Owner)));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMovementInput(Entity<WaddleAnimationComponent> entity, ref MoveInputEvent args)
|
||||
{
|
||||
// Prediction mitigation. Prediction means that MoveInputEvents are spammed repeatedly, even though you'd assume
|
||||
// they're once-only for the user actually doing something. As such do nothing if we're just repeating this FoR.
|
||||
if (!_timing.IsFirstTimePredicted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.HasDirectionalMovement && entity.Comp.IsCurrentlyWaddling)
|
||||
{
|
||||
StopWaddling(entity);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Only start waddling if we're not currently AND we're actually moving.
|
||||
if (entity.Comp.IsCurrentlyWaddling || !args.HasDirectionalMovement)
|
||||
return;
|
||||
|
||||
entity.Comp.IsCurrentlyWaddling = true;
|
||||
|
||||
RaiseNetworkEvent(new StartedWaddlingEvent(GetNetEntity(entity.Owner)));
|
||||
}
|
||||
|
||||
private void OnStood(Entity<WaddleAnimationComponent> entity, ref StoodEvent args)
|
||||
{
|
||||
// Prediction mitigation. Prediction means that MoveInputEvents are spammed repeatedly, even though you'd assume
|
||||
// they're once-only for the user actually doing something. As such do nothing if we're just repeating this FoR.
|
||||
if (!_timing.IsFirstTimePredicted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryComp<InputMoverComponent>(entity.Owner, out var mover))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((mover.HeldMoveButtons & MoveButtons.AnyDirection) == MoveButtons.None)
|
||||
return;
|
||||
|
||||
if (entity.Comp.IsCurrentlyWaddling)
|
||||
return;
|
||||
|
||||
entity.Comp.IsCurrentlyWaddling = true;
|
||||
|
||||
RaiseNetworkEvent(new StartedWaddlingEvent(GetNetEntity(entity.Owner)));
|
||||
}
|
||||
|
||||
private void StopWaddling(Entity<WaddleAnimationComponent> entity)
|
||||
{
|
||||
entity.Comp.IsCurrentlyWaddling = false;
|
||||
|
||||
RaiseNetworkEvent(new StoppedWaddlingEvent(GetNetEntity(entity.Owner)));
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.Roles;
|
||||
|
||||
public abstract partial class AntagonistRoleComponent : Component
|
||||
{
|
||||
[DataField("prototype", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<AntagPrototype>))]
|
||||
public string? PrototypeId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mark the antagonist role component as being exclusive
|
||||
/// IE by default other antagonists should refuse to select the same entity for a different antag role
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
[BaseTypeRequired(typeof(AntagonistRoleComponent))]
|
||||
public sealed partial class ExclusiveAntagonistAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Roles.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// Added to mind entities to hold the data for the player's current job.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class JobComponent : Component
|
||||
{
|
||||
[DataField(required: true), AutoNetworkedField]
|
||||
public ProtoId<JobPrototype>? Prototype;
|
||||
}
|
||||
12
Content.Shared/Roles/Jobs/JobRoleComponent.cs
Normal file
12
Content.Shared/Roles/Jobs/JobRoleComponent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Roles.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// Added to mind role entities to mark them as a job role entity.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class JobRoleComponent : BaseMindRoleComponent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -13,8 +13,10 @@ namespace Content.Shared.Roles.Jobs;
|
||||
/// </summary>
|
||||
public abstract class SharedJobSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypes = default!;
|
||||
[Dependency] private readonly SharedPlayerSystem _playerSystem = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypes = default!;
|
||||
[Dependency] private readonly SharedRoleSystem _roles = default!;
|
||||
|
||||
private readonly Dictionary<string, string> _inverseTrackerLookup = new();
|
||||
|
||||
public override void Initialize()
|
||||
@@ -100,32 +102,44 @@ public abstract class SharedJobSystem : EntitySystem
|
||||
|
||||
public bool MindHasJobWithId(EntityUid? mindId, string prototypeId)
|
||||
{
|
||||
return CompOrNull<JobComponent>(mindId)?.Prototype == prototypeId;
|
||||
|
||||
MindRoleComponent? comp = null;
|
||||
if (mindId is null)
|
||||
return false;
|
||||
|
||||
_roles.MindHasRole<JobRoleComponent>(mindId.Value, out var role);
|
||||
|
||||
if (role is null)
|
||||
return false;
|
||||
|
||||
comp = role.Value.Comp;
|
||||
|
||||
return (comp.JobPrototype == prototypeId);
|
||||
}
|
||||
|
||||
public bool MindTryGetJob(
|
||||
[NotNullWhen(true)] EntityUid? mindId,
|
||||
[NotNullWhen(true)] out JobComponent? comp,
|
||||
[NotNullWhen(true)] out JobPrototype? prototype)
|
||||
{
|
||||
comp = null;
|
||||
prototype = null;
|
||||
MindTryGetJobId(mindId, out var protoId);
|
||||
|
||||
return TryComp(mindId, out comp) &&
|
||||
comp.Prototype != null &&
|
||||
_prototypes.TryIndex(comp.Prototype, out prototype);
|
||||
return (_prototypes.TryIndex<JobPrototype>(protoId, out prototype) || prototype is not null);
|
||||
}
|
||||
|
||||
public bool MindTryGetJobId([NotNullWhen(true)] EntityUid? mindId, out ProtoId<JobPrototype>? job)
|
||||
public bool MindTryGetJobId(
|
||||
[NotNullWhen(true)] EntityUid? mindId,
|
||||
out ProtoId<JobPrototype>? job)
|
||||
{
|
||||
if (!TryComp(mindId, out JobComponent? comp))
|
||||
{
|
||||
job = null;
|
||||
return false;
|
||||
}
|
||||
job = null;
|
||||
|
||||
job = comp.Prototype;
|
||||
return true;
|
||||
if (mindId is null)
|
||||
return false;
|
||||
|
||||
if (_roles.MindHasRole<JobRoleComponent>(mindId.Value, out var role))
|
||||
job = role.Value.Comp.JobPrototype;
|
||||
|
||||
return (job is not null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -134,7 +148,7 @@ public abstract class SharedJobSystem : EntitySystem
|
||||
/// </summary>
|
||||
public bool MindTryGetJobName([NotNullWhen(true)] EntityUid? mindId, out string name)
|
||||
{
|
||||
if (MindTryGetJob(mindId, out _, out var prototype))
|
||||
if (MindTryGetJob(mindId, out var prototype))
|
||||
{
|
||||
name = prototype.LocalizedName;
|
||||
return true;
|
||||
@@ -161,7 +175,7 @@ public abstract class SharedJobSystem : EntitySystem
|
||||
if (_playerSystem.ContentData(player) is not { Mind: { } mindId })
|
||||
return true;
|
||||
|
||||
if (!MindTryGetJob(mindId, out _, out var prototype))
|
||||
if (!MindTryGetJob(mindId, out var prototype))
|
||||
return true;
|
||||
|
||||
return prototype.CanBeAntag;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Content.Shared.Roles;
|
||||
/// </summary>
|
||||
/// <param name="Roles">The list of roles on the player.</param>
|
||||
[ByRefEvent]
|
||||
public readonly record struct MindGetAllRolesEvent(List<RoleInfo> Roles);
|
||||
public readonly record struct MindGetAllRoleInfoEvent(List<RoleInfo> Roles);
|
||||
|
||||
/// <summary>
|
||||
/// Returned by <see cref="MindGetAllRolesEvent"/> to give some information about a player's role.
|
||||
@@ -17,4 +17,4 @@ public readonly record struct MindGetAllRolesEvent(List<RoleInfo> Roles);
|
||||
/// <param name="Antagonist">Whether or not this role makes this player an antagonist.</param>
|
||||
/// <param name="PlayTimeTrackerId">The <see cref="PlayTimeTrackerPrototype"/> id associated with the role.</param>
|
||||
/// <param name="Prototype">The prototype ID of the role</param>
|
||||
public readonly record struct RoleInfo(Component Component, string Name, bool Antagonist, string? PlayTimeTrackerId, string Prototype);
|
||||
public readonly record struct RoleInfo(string Name, bool Antagonist, string? PlayTimeTrackerId, string Prototype);
|
||||
48
Content.Shared/Roles/MindRoleComponent.cs
Normal file
48
Content.Shared/Roles/MindRoleComponent.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Content.Shared.Mind;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// This holds data for, and indicates, a Mind Role entity
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class MindRoleComponent : BaseMindRoleComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Marks this Mind Role as Antagonist
|
||||
/// A single antag Mind Role is enough to make the owner mind count as Antagonist.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool Antag { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// True if this mindrole is an exclusive antagonist. Antag setting is not checked if this is True.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool ExclusiveAntag { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The Mind that this role belongs to
|
||||
/// </summary>
|
||||
public Entity<MindComponent> Mind { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Antagonist prototype of this role
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<AntagPrototype>? AntagPrototype { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Job prototype of this role
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<JobPrototype>? JobPrototype { get; set; }
|
||||
}
|
||||
|
||||
public abstract partial class BaseMindRoleComponent : Component
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,34 +1,31 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Ghost.Roles;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Roles.Jobs;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Roles;
|
||||
|
||||
public abstract class SharedRoleSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypes = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedMindSystem _minds = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
// TODO please lord make role entities
|
||||
private readonly HashSet<Type> _antagTypes = new();
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly SharedGameTicker _gameTicker = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypes = default!;
|
||||
|
||||
private JobRequirementOverridePrototype? _requirementOverride;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
// TODO make roles entities
|
||||
SubscribeLocalEvent<JobComponent, MindGetAllRolesEvent>(OnJobGetAllRoles);
|
||||
Subs.CVar(_cfg, CCVars.GameRoleTimerOverride, SetRequirementOverride, true);
|
||||
}
|
||||
|
||||
@@ -44,124 +41,117 @@ public abstract class SharedRoleSystem : EntitySystem
|
||||
Log.Error($"Unknown JobRequirementOverridePrototype: {value}");
|
||||
}
|
||||
|
||||
private void OnJobGetAllRoles(EntityUid uid, JobComponent component, ref MindGetAllRolesEvent args)
|
||||
{
|
||||
var name = "game-ticker-unknown-role";
|
||||
var prototype = "";
|
||||
string? playTimeTracker = null;
|
||||
if (component.Prototype != null && _prototypes.TryIndex(component.Prototype, out JobPrototype? job))
|
||||
{
|
||||
name = job.Name;
|
||||
prototype = job.ID;
|
||||
playTimeTracker = job.PlayTimeTracker;
|
||||
}
|
||||
|
||||
name = Loc.GetString(name);
|
||||
|
||||
args.Roles.Add(new RoleInfo(component, name, false, playTimeTracker, prototype));
|
||||
}
|
||||
|
||||
protected void SubscribeAntagEvents<T>() where T : AntagonistRoleComponent
|
||||
{
|
||||
SubscribeLocalEvent((EntityUid _, T component, ref MindGetAllRolesEvent args) =>
|
||||
{
|
||||
var name = "game-ticker-unknown-role";
|
||||
var prototype = "";
|
||||
if (component.PrototypeId != null && _prototypes.TryIndex(component.PrototypeId, out AntagPrototype? antag))
|
||||
{
|
||||
name = antag.Name;
|
||||
prototype = antag.ID;
|
||||
}
|
||||
name = Loc.GetString(name);
|
||||
|
||||
args.Roles.Add(new RoleInfo(component, name, true, null, prototype));
|
||||
});
|
||||
|
||||
SubscribeLocalEvent((EntityUid _, T _, ref MindIsAntagonistEvent args) => { args.IsAntagonist = true; args.IsExclusiveAntagonist |= typeof(T).TryGetCustomAttribute<ExclusiveAntagonistAttribute>(out _); });
|
||||
_antagTypes.Add(typeof(T));
|
||||
}
|
||||
|
||||
public void MindAddRoles(EntityUid mindId, ComponentRegistry components, MindComponent? mind = null, bool silent = false)
|
||||
{
|
||||
if (!Resolve(mindId, ref mind))
|
||||
return;
|
||||
|
||||
EntityManager.AddComponents(mindId, components);
|
||||
var antagonist = false;
|
||||
foreach (var compReg in components.Values)
|
||||
{
|
||||
var compType = compReg.Component.GetType();
|
||||
|
||||
var comp = EntityManager.ComponentFactory.GetComponent(compType);
|
||||
if (IsAntagonistRole(comp.GetType()))
|
||||
{
|
||||
antagonist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var mindEv = new MindRoleAddedEvent(silent);
|
||||
RaiseLocalEvent(mindId, ref mindEv);
|
||||
|
||||
var message = new RoleAddedEvent(mindId, mind, antagonist, silent);
|
||||
if (mind.OwnedEntity != null)
|
||||
{
|
||||
RaiseLocalEvent(mind.OwnedEntity.Value, message, true);
|
||||
}
|
||||
|
||||
_adminLogger.Add(LogType.Mind, LogImpact.Low,
|
||||
$"Role components {string.Join(components.Keys.ToString(), ", ")} added to mind of {_minds.MindOwnerLoggingString(mind)}");
|
||||
}
|
||||
|
||||
public void MindAddRole(EntityUid mindId, Component component, MindComponent? mind = null, bool silent = false)
|
||||
{
|
||||
if (!Resolve(mindId, ref mind))
|
||||
return;
|
||||
|
||||
if (HasComp(mindId, component.GetType()))
|
||||
{
|
||||
throw new ArgumentException($"We already have this role: {component}");
|
||||
}
|
||||
|
||||
EntityManager.AddComponent(mindId, component);
|
||||
var antagonist = IsAntagonistRole(component.GetType());
|
||||
|
||||
var mindEv = new MindRoleAddedEvent(silent);
|
||||
RaiseLocalEvent(mindId, ref mindEv);
|
||||
|
||||
var message = new RoleAddedEvent(mindId, mind, antagonist, silent);
|
||||
if (mind.OwnedEntity != null)
|
||||
{
|
||||
RaiseLocalEvent(mind.OwnedEntity.Value, message, true);
|
||||
}
|
||||
|
||||
_adminLogger.Add(LogType.Mind, LogImpact.Low,
|
||||
$"'Role {component}' added to mind of {_minds.MindOwnerLoggingString(mind)}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives this mind a new role.
|
||||
/// Adds multiple mind roles to a mind
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind to add the role to.</param>
|
||||
/// <param name="component">The role instance to add.</param>
|
||||
/// <typeparam name="T">The role type to add.</typeparam>
|
||||
/// <param name="silent">Whether or not the role should be added silently</param>
|
||||
/// <returns>The instance of the role.</returns>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if we already have a role with this type.
|
||||
/// </exception>
|
||||
public void MindAddRole<T>(EntityUid mindId, T component, MindComponent? mind = null, bool silent = false) where T : IComponent, new()
|
||||
/// <param name="mindId">The mind entity to add the role to</param>
|
||||
/// <param name="roles">The list of mind roles to add</param>
|
||||
/// <param name="mind">If the mind component is provided, it will be checked if it belongs to the mind entity</param>
|
||||
/// <param name="silent">If true, no briefing will be generated upon receiving the mind role</param>
|
||||
public void MindAddRoles(EntityUid mindId,
|
||||
List<ProtoId<EntityPrototype>>? roles,
|
||||
MindComponent? mind = null,
|
||||
bool silent = false)
|
||||
{
|
||||
if (!Resolve(mindId, ref mind))
|
||||
if (roles is null || roles.Count == 0)
|
||||
return;
|
||||
|
||||
if (HasComp<T>(mindId))
|
||||
foreach (var proto in roles)
|
||||
{
|
||||
throw new ArgumentException($"We already have this role: {typeof(T)}");
|
||||
MindAddRole(mindId, proto, mind, silent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a mind role to a mind
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind entity to add the role to</param>
|
||||
/// <param name="protoId">The mind role to add</param>
|
||||
/// <param name="mind">If the mind component is provided, it will be checked if it belongs to the mind entity</param>
|
||||
/// <param name="silent">If true, no briefing will be generated upon receiving the mind role</param>
|
||||
public void MindAddRole(EntityUid mindId,
|
||||
ProtoId<EntityPrototype> protoId,
|
||||
MindComponent? mind = null,
|
||||
bool silent = false)
|
||||
{
|
||||
if (protoId == "MindRoleJob")
|
||||
MindAddJobRole(mindId, mind, silent, "");
|
||||
else
|
||||
MindAddRoleDo(mindId, protoId, mind, silent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Job mind role with the specified job prototype
|
||||
/// </summary>
|
||||
/// /// <param name="mindId">The mind entity to add the job role to</param>
|
||||
/// <param name="mind">If the mind component is provided, it will be checked if it belongs to the mind entity</param>
|
||||
/// <param name="silent">If true, no briefing will be generated upon receiving the mind role</param>
|
||||
/// <param name="jobPrototype">The Job prototype for the new role</param>
|
||||
public void MindAddJobRole(EntityUid mindId,
|
||||
MindComponent? mind = null,
|
||||
bool silent = false,
|
||||
string? jobPrototype = null)
|
||||
{
|
||||
// Can't have someone get paid for two jobs now, can we
|
||||
if (MindHasRole<JobRoleComponent>(mindId, out var jobRole)
|
||||
&& jobRole.Value.Comp.JobPrototype != jobPrototype)
|
||||
{
|
||||
Resolve(mindId, ref mind);
|
||||
if (mind is not null)
|
||||
{
|
||||
_adminLogger.Add(LogType.Mind,
|
||||
LogImpact.Low,
|
||||
$"Job Role of {ToPrettyString(mind.OwnedEntity)} changed from '{jobRole.Value.Comp.JobPrototype}' to '{jobPrototype}'");
|
||||
}
|
||||
|
||||
jobRole.Value.Comp.JobPrototype = jobPrototype;
|
||||
}
|
||||
else
|
||||
MindAddRoleDo(mindId, "MindRoleJob", mind, silent, jobPrototype);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Mind Role
|
||||
/// </summary>
|
||||
private void MindAddRoleDo(EntityUid mindId,
|
||||
ProtoId<EntityPrototype> protoId,
|
||||
MindComponent? mind = null,
|
||||
bool silent = false,
|
||||
string? jobPrototype = null)
|
||||
{
|
||||
if (!Resolve(mindId, ref mind))
|
||||
{
|
||||
Log.Error($"Failed to add role {protoId} to mind {mindId} : Mind does not match provided mind component");
|
||||
return;
|
||||
}
|
||||
|
||||
AddComp(mindId, component);
|
||||
var antagonist = IsAntagonistRole<T>();
|
||||
var antagonist = false;
|
||||
|
||||
if (!_prototypes.TryIndex(protoId, out var protoEnt))
|
||||
{
|
||||
Log.Error($"Failed to add role {protoId} to mind {mindId} : Role prototype does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO don't let a prototype being added a second time
|
||||
//If that was somehow to occur, a second mindrole for that comp would be created
|
||||
//Meaning any mind role checks could return wrong results, since they just return the first match they find
|
||||
|
||||
var mindRoleId = Spawn(protoId, MapCoordinates.Nullspace);
|
||||
EnsureComp<MindRoleComponent>(mindRoleId);
|
||||
var mindRoleComp = Comp<MindRoleComponent>(mindRoleId);
|
||||
|
||||
mindRoleComp.Mind = (mindId,mind);
|
||||
if (jobPrototype is not null)
|
||||
{
|
||||
mindRoleComp.JobPrototype = jobPrototype;
|
||||
EnsureComp<JobRoleComponent>(mindRoleId);
|
||||
}
|
||||
|
||||
if (mindRoleComp.Antag || mindRoleComp.ExclusiveAntag)
|
||||
antagonist = true;
|
||||
|
||||
mind.MindRoles.Add(mindRoleId);
|
||||
|
||||
var mindEv = new MindRoleAddedEvent(silent);
|
||||
RaiseLocalEvent(mindId, ref mindEv);
|
||||
@@ -172,94 +162,336 @@ public abstract class SharedRoleSystem : EntitySystem
|
||||
RaiseLocalEvent(mind.OwnedEntity.Value, message, true);
|
||||
}
|
||||
|
||||
_adminLogger.Add(LogType.Mind, LogImpact.Low,
|
||||
$"'Role {typeof(T).Name}' added to mind of {_minds.MindOwnerLoggingString(mind)}");
|
||||
var name = Loc.GetString(protoEnt.Name);
|
||||
if (mind.OwnedEntity is not null)
|
||||
{
|
||||
_adminLogger.Add(LogType.Mind,
|
||||
LogImpact.Low,
|
||||
$"{name} added to mind of {ToPrettyString(mind.OwnedEntity)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO: This is not tied to the player on the Admin Log filters.
|
||||
//Probably only happens when Job Role is added on initial spawn, before the mind entity is put in a mob
|
||||
_adminLogger.Add(LogType.Mind,
|
||||
LogImpact.Low,
|
||||
$"{name} added to {ToPrettyString(mindId)}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a role from this mind.
|
||||
/// Removes all instances of a specific role from this mind.
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind to remove the role from.</param>
|
||||
/// <typeparam name="T">The type of the role to remove.</typeparam>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if we do not have this role.
|
||||
/// </exception>
|
||||
public void MindRemoveRole<T>(EntityUid mindId) where T : IComponent
|
||||
/// <exception cref="ArgumentException">Thrown if the mind does not exist or does not have this role.</exception>
|
||||
/// <returns>Returns False if there was something wrong with the mind or the removal. True if successful</returns>>
|
||||
public bool MindRemoveRole<T>(EntityUid mindId) where T : IComponent
|
||||
{
|
||||
if (!RemComp<T>(mindId))
|
||||
if (!TryComp<MindComponent>(mindId, out var mind) )
|
||||
throw new ArgumentException($"{mindId} does not exist or does not have mind component");
|
||||
|
||||
var found = false;
|
||||
var antagonist = false;
|
||||
var delete = new List<EntityUid>();
|
||||
foreach (var role in mind.MindRoles)
|
||||
{
|
||||
throw new ArgumentException($"We do not have this role: {typeof(T)}");
|
||||
if (!HasComp<T>(role))
|
||||
continue;
|
||||
|
||||
var roleComp = Comp<MindRoleComponent>(role);
|
||||
antagonist = roleComp.Antag;
|
||||
_entityManager.DeleteEntity(role);
|
||||
|
||||
delete.Add(role);
|
||||
found = true;
|
||||
|
||||
}
|
||||
|
||||
foreach (var role in delete)
|
||||
{
|
||||
mind.MindRoles.Remove(role);
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
throw new ArgumentException($"{mindId} does not have this role: {typeof(T)}");
|
||||
}
|
||||
|
||||
var mind = Comp<MindComponent>(mindId);
|
||||
var antagonist = IsAntagonistRole<T>();
|
||||
var message = new RoleRemovedEvent(mindId, mind, antagonist);
|
||||
|
||||
if (mind.OwnedEntity != null)
|
||||
{
|
||||
RaiseLocalEvent(mind.OwnedEntity.Value, message, true);
|
||||
}
|
||||
_adminLogger.Add(LogType.Mind, LogImpact.Low,
|
||||
$"'Role {typeof(T).Name}' removed from mind of {_minds.MindOwnerLoggingString(mind)}");
|
||||
}
|
||||
|
||||
public bool MindTryRemoveRole<T>(EntityUid mindId) where T : IComponent
|
||||
{
|
||||
if (!MindHasRole<T>(mindId))
|
||||
return false;
|
||||
|
||||
MindRemoveRole<T>(mindId);
|
||||
_adminLogger.Add(LogType.Mind,
|
||||
LogImpact.Low,
|
||||
$"'Role {typeof(T).Name}' removed from mind of {ToPrettyString(mind.OwnedEntity)}");
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool MindHasRole<T>(EntityUid mindId) where T : IComponent
|
||||
/// <summary>
|
||||
/// Finds and removes all mind roles of a specific type
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind entity</param>
|
||||
/// <typeparam name="T">The type of the role to remove.</typeparam>
|
||||
/// <returns>True if the role existed and was removed</returns>
|
||||
public bool MindTryRemoveRole<T>(EntityUid mindId) where T : IComponent
|
||||
{
|
||||
DebugTools.Assert(HasComp<MindComponent>(mindId));
|
||||
return HasComp<T>(mindId);
|
||||
}
|
||||
if (!MindHasRole<T>(mindId))
|
||||
{
|
||||
Log.Warning($"Failed to remove role {typeof(T)} from {mindId} : mind does not have role ");
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<RoleInfo> MindGetAllRoles(EntityUid mindId)
|
||||
{
|
||||
DebugTools.Assert(HasComp<MindComponent>(mindId));
|
||||
var ev = new MindGetAllRolesEvent(new List<RoleInfo>());
|
||||
RaiseLocalEvent(mindId, ref ev);
|
||||
return ev.Roles;
|
||||
}
|
||||
|
||||
public bool MindIsAntagonist(EntityUid? mindId)
|
||||
{
|
||||
if (mindId == null)
|
||||
if (typeof(T) == typeof(MindRoleComponent))
|
||||
return false;
|
||||
|
||||
DebugTools.Assert(HasComp<MindComponent>(mindId));
|
||||
var ev = new MindIsAntagonistEvent();
|
||||
RaiseLocalEvent(mindId.Value, ref ev);
|
||||
return ev.IsAntagonist;
|
||||
return MindRemoveRole<T>(mindId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the first mind role of a specific T type on a mind entity.
|
||||
/// Outputs entity components for the mind role's MindRoleComponent and for T
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind entity</param>
|
||||
/// <typeparam name="T">The type of the role to find.</typeparam>
|
||||
/// <param name="role">The Mind Role entity component</param>
|
||||
/// <param name="roleT">The Mind Role's entity component for T</param>
|
||||
/// <returns>True if the role is found</returns>
|
||||
public bool MindHasRole<T>(EntityUid mindId,
|
||||
[NotNullWhen(true)] out Entity<MindRoleComponent>? role,
|
||||
[NotNullWhen(true)] out Entity<T>? roleT) where T : IComponent
|
||||
{
|
||||
role = null;
|
||||
roleT = null;
|
||||
|
||||
if (!TryComp<MindComponent>(mindId, out var mind))
|
||||
return false;
|
||||
|
||||
var found = false;
|
||||
|
||||
foreach (var roleEnt in mind.MindRoles)
|
||||
{
|
||||
if (!HasComp<T>(roleEnt))
|
||||
continue;
|
||||
|
||||
role = (roleEnt,Comp<MindRoleComponent>(roleEnt));
|
||||
roleT = (roleEnt,Comp<T>(roleEnt));
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the first mind role of a specific type on a mind entity.
|
||||
/// Outputs an entity component for the mind role's MindRoleComponent
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind entity</param>
|
||||
/// <param name="type">The Type to look for</param>
|
||||
/// <param name="role">The output role</param>
|
||||
/// <returns>True if the role is found</returns>
|
||||
public bool MindHasRole(EntityUid mindId,
|
||||
Type type,
|
||||
[NotNullWhen(true)] out Entity<MindRoleComponent>? role)
|
||||
{
|
||||
role = null;
|
||||
// All MindRoles have this component, it would just return the first one.
|
||||
// Order might not be what is expected.
|
||||
// Better to report null
|
||||
if (type == Type.GetType("MindRoleComponent"))
|
||||
{
|
||||
Log.Error($"Something attempted to query mind role 'MindRoleComponent' on mind {mindId}. This component is present on every single mind role.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryComp<MindComponent>(mindId, out var mind))
|
||||
return false;
|
||||
|
||||
var found = false;
|
||||
|
||||
foreach (var roleEnt in mind.MindRoles)
|
||||
{
|
||||
if (!HasComp(roleEnt, type))
|
||||
continue;
|
||||
|
||||
role = (roleEnt,Comp<MindRoleComponent>(roleEnt));
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the first mind role of a specific type on a mind entity.
|
||||
/// Outputs an entity component for the mind role's MindRoleComponent
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind entity</param>
|
||||
/// <param name="role">The Mind Role entity component</param>
|
||||
/// <typeparam name="T">The type of the role to find.</typeparam>
|
||||
/// <returns>True if the role is found</returns>
|
||||
public bool MindHasRole<T>(EntityUid mindId,
|
||||
[NotNullWhen(true)] out Entity<MindRoleComponent>? role) where T : IComponent
|
||||
{
|
||||
return MindHasRole<T>(mindId, out role, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the first mind role of a specific type on a mind entity.
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind entity</param>
|
||||
/// <typeparam name="T">The type of the role to find.</typeparam>
|
||||
/// <returns>True if the role is found</returns>
|
||||
public bool MindHasRole<T>(EntityUid mindId) where T : IComponent
|
||||
{
|
||||
return MindHasRole<T>(mindId, out _, out _);
|
||||
}
|
||||
|
||||
//TODO: Delete this later
|
||||
/// <summary>
|
||||
/// Returns the first mind role of a specific type
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind entity</param>
|
||||
/// <returns>Entity Component of the mind role</returns>
|
||||
[Obsolete("Use MindHasRole's output value")]
|
||||
public Entity<MindRoleComponent>? MindGetRole<T>(EntityUid mindId) where T : IComponent
|
||||
{
|
||||
Entity<MindRoleComponent>? result = null;
|
||||
|
||||
var mind = Comp<MindComponent>(mindId);
|
||||
|
||||
foreach (var uid in mind.MindRoles)
|
||||
{
|
||||
if (HasComp<T>(uid) && TryComp<MindRoleComponent>(uid, out var comp))
|
||||
result = (uid,comp);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads all Roles of a mind Entity and returns their data as RoleInfo
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind entity</param>
|
||||
/// <returns>RoleInfo list</returns>
|
||||
public List<RoleInfo> MindGetAllRoleInfo(EntityUid mindId)
|
||||
{
|
||||
var roleInfo = new List<RoleInfo>();
|
||||
|
||||
if (!TryComp<MindComponent>(mindId, out var mind))
|
||||
return roleInfo;
|
||||
|
||||
foreach (var role in mind.MindRoles)
|
||||
{
|
||||
var valid = false;
|
||||
var name = "game-ticker-unknown-role";
|
||||
var prototype = "";
|
||||
string? playTimeTracker = null;
|
||||
|
||||
var comp = Comp<MindRoleComponent>(role);
|
||||
if (comp.AntagPrototype is not null)
|
||||
{
|
||||
prototype = comp.AntagPrototype;
|
||||
}
|
||||
|
||||
if (comp.JobPrototype is not null && comp.AntagPrototype is null)
|
||||
{
|
||||
prototype = comp.JobPrototype;
|
||||
if (_prototypes.TryIndex(comp.JobPrototype, out var job))
|
||||
{
|
||||
playTimeTracker = job.PlayTimeTracker;
|
||||
name = job.Name;
|
||||
valid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($" Mind Role Prototype '{role.Id}' contains invalid Job prototype: '{comp.JobPrototype}'");
|
||||
}
|
||||
}
|
||||
else if (comp.AntagPrototype is not null && comp.JobPrototype is null)
|
||||
{
|
||||
prototype = comp.AntagPrototype;
|
||||
if (_prototypes.TryIndex(comp.AntagPrototype, out var antag))
|
||||
{
|
||||
name = antag.Name;
|
||||
valid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($" Mind Role Prototype '{role.Id}' contains invalid Antagonist prototype: '{comp.AntagPrototype}'");
|
||||
}
|
||||
}
|
||||
else if (comp.JobPrototype is not null && comp.AntagPrototype is not null)
|
||||
{
|
||||
Log.Error($" Mind Role Prototype '{role.Id}' contains both Job and Antagonist prototypes");
|
||||
}
|
||||
|
||||
if (valid)
|
||||
roleInfo.Add(new RoleInfo(name, comp.Antag || comp.ExclusiveAntag , playTimeTracker, prototype));
|
||||
}
|
||||
return roleInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Does this mind possess an antagonist role
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind entity</param>
|
||||
/// <returns>True if the mind possesses any antag roles</returns>
|
||||
public bool MindIsAntagonist(EntityUid? mindId)
|
||||
{
|
||||
if (mindId is null)
|
||||
{
|
||||
Log.Warning($"Antagonist status of mind entity {mindId} could not be determined - mind entity not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
return CheckAntagonistStatus(mindId.Value).Item1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Does this mind possess an exclusive antagonist role
|
||||
/// </summary>
|
||||
/// <param name="mindId">The mind entity</param>
|
||||
/// <returns>True if the mind possesses an exclusive antag role</returns>
|
||||
/// <returns>True if the mind possesses any exclusive antag roles</returns>
|
||||
public bool MindIsExclusiveAntagonist(EntityUid? mindId)
|
||||
{
|
||||
if (mindId == null)
|
||||
if (mindId is null)
|
||||
{
|
||||
Log.Warning($"Antagonist status of mind entity {mindId} could not be determined - mind entity not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
var ev = new MindIsAntagonistEvent();
|
||||
RaiseLocalEvent(mindId.Value, ref ev);
|
||||
return ev.IsExclusiveAntagonist;
|
||||
return CheckAntagonistStatus(mindId.Value).Item2;
|
||||
}
|
||||
|
||||
public bool IsAntagonistRole<T>()
|
||||
{
|
||||
return _antagTypes.Contains(typeof(T));
|
||||
}
|
||||
private (bool, bool) CheckAntagonistStatus(EntityUid mindId)
|
||||
{
|
||||
if (!TryComp<MindComponent>(mindId, out var mind))
|
||||
{
|
||||
Log.Warning($"Antagonist status of mind entity {mindId} could not be determined - mind component not found");
|
||||
return (false, false);
|
||||
}
|
||||
|
||||
public bool IsAntagonistRole(Type component)
|
||||
{
|
||||
return _antagTypes.Contains(component);
|
||||
var antagonist = false;
|
||||
var exclusiveAntag = false;
|
||||
foreach (var role in mind.MindRoles)
|
||||
{
|
||||
if (!TryComp<MindRoleComponent>(role, out var roleComp))
|
||||
{
|
||||
//If this ever shows up outside of an integration test, then we need to look into this further.
|
||||
Log.Warning($"Mind Role Entity {role} does not have MindRoleComponent!");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (roleComp.Antag || exclusiveAntag)
|
||||
antagonist = true;
|
||||
if (roleComp.ExclusiveAntag)
|
||||
exclusiveAntag = true;
|
||||
}
|
||||
|
||||
return (antagonist, exclusiveAntag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,6 +8,7 @@ using Robust.Shared.GameStates;
|
||||
using Content.Shared.DoAfter;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Audio;
|
||||
using Content.Shared.Whitelist;
|
||||
|
||||
namespace Content.Shared.Storage.Components
|
||||
{
|
||||
@@ -26,6 +27,12 @@ namespace Content.Shared.Storage.Components
|
||||
[DataField("maxItemSize")]
|
||||
public ProtoId<ItemSizePrototype> MaxItemSize = "Small";
|
||||
|
||||
/// <summary>
|
||||
/// Entity blacklist for secret stashes.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public EntityWhitelist? Blacklist;
|
||||
|
||||
/// <summary>
|
||||
/// This sound will be played when you try to insert an item in the stash.
|
||||
/// The sound will be played whether or not the item is actually inserted.
|
||||
|
||||
@@ -13,6 +13,7 @@ using Robust.Shared.Audio.Systems;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Tools.EntitySystems;
|
||||
using Content.Shared.Whitelist;
|
||||
|
||||
namespace Content.Shared.Storage.EntitySystems;
|
||||
|
||||
@@ -27,7 +28,7 @@ public sealed class SecretStashSystem : EntitySystem
|
||||
[Dependency] private readonly SharedItemSystem _item = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly ToolOpenableSystem _toolOpenableSystem = default!;
|
||||
|
||||
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -90,8 +91,9 @@ public sealed class SecretStashSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if item is too big to fit into secret stash
|
||||
if (_item.GetSizePrototype(itemComp.Size) > _item.GetSizePrototype(entity.Comp.MaxItemSize))
|
||||
// check if item is too big to fit into secret stash or is in the blacklist
|
||||
if (_item.GetSizePrototype(itemComp.Size) > _item.GetSizePrototype(entity.Comp.MaxItemSize) ||
|
||||
_whitelistSystem.IsBlacklistPass(entity.Comp.Blacklist, itemToHideUid))
|
||||
{
|
||||
var msg = Loc.GetString("comp-secret-stash-action-hide-item-too-big",
|
||||
("item", itemToHideUid), ("stashname", GetStashName(entity)));
|
||||
|
||||
@@ -32,6 +32,12 @@ public sealed partial class EntityWhitelist
|
||||
[DataField] public string[]? Components;
|
||||
// TODO yaml validation
|
||||
|
||||
/// <summary>
|
||||
/// Mind Role Prototype names that are allowed in the whitelist.
|
||||
/// </summary>
|
||||
[DataField] public string[]? MindRoles;
|
||||
// TODO yaml validation
|
||||
|
||||
/// <summary>
|
||||
/// Item sizes that are allowed in the whitelist.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Tag;
|
||||
|
||||
namespace Content.Shared.Whitelist;
|
||||
@@ -7,6 +8,7 @@ namespace Content.Shared.Whitelist;
|
||||
public sealed class EntityWhitelistSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IComponentFactory _factory = default!;
|
||||
[Dependency] private readonly SharedRoleSystem _roles = default!;
|
||||
[Dependency] private readonly TagSystem _tag = default!;
|
||||
|
||||
private EntityQuery<ItemComponent> _itemQuery;
|
||||
@@ -46,9 +48,30 @@ public sealed class EntityWhitelistSystem : EntitySystem
|
||||
public bool IsValid(EntityWhitelist list, EntityUid uid)
|
||||
{
|
||||
if (list.Components != null)
|
||||
EnsureRegistrations(list);
|
||||
{
|
||||
var regs = StringsToRegs(list.Components);
|
||||
|
||||
if (list.Registrations != null)
|
||||
list.Registrations ??= new List<ComponentRegistration>();
|
||||
list.Registrations.AddRange(regs);
|
||||
}
|
||||
|
||||
if (list.MindRoles != null)
|
||||
{
|
||||
var regs = StringsToRegs(list.MindRoles);
|
||||
|
||||
foreach (var role in regs)
|
||||
{
|
||||
if ( _roles.MindHasRole(uid, role.Type, out _))
|
||||
{
|
||||
if (!list.RequireAll)
|
||||
return true;
|
||||
}
|
||||
else if (list.RequireAll)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (list.Registrations != null && list.Registrations.Count > 0)
|
||||
{
|
||||
foreach (var reg in list.Registrations)
|
||||
{
|
||||
@@ -153,7 +176,7 @@ public sealed class EntityWhitelistSystem : EntitySystem
|
||||
return IsWhitelistPassOrNull(blacklist, uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Helper function to determine if Blacklist is either null or the entity is not on the list
|
||||
/// Duplicate of equivalent Whitelist function
|
||||
/// </summary>
|
||||
@@ -162,24 +185,27 @@ public sealed class EntityWhitelistSystem : EntitySystem
|
||||
return IsWhitelistFailOrNull(blacklist, uid);
|
||||
}
|
||||
|
||||
private void EnsureRegistrations(EntityWhitelist list)
|
||||
private List<ComponentRegistration> StringsToRegs(string[]? input)
|
||||
{
|
||||
if (list.Components == null)
|
||||
return;
|
||||
var list = new List<ComponentRegistration>();
|
||||
|
||||
list.Registrations = new List<ComponentRegistration>();
|
||||
foreach (var name in list.Components)
|
||||
if (input == null || input.Length == 0)
|
||||
return list;
|
||||
|
||||
foreach (var name in input)
|
||||
{
|
||||
var availability = _factory.GetComponentAvailability(name);
|
||||
if (_factory.TryGetRegistration(name, out var registration)
|
||||
&& availability == ComponentAvailability.Available)
|
||||
{
|
||||
list.Registrations.Add(registration);
|
||||
list.Add(registration);
|
||||
}
|
||||
else if (availability == ComponentAvailability.Unknown)
|
||||
{
|
||||
Log.Warning($"Unknown component name {name} passed to EntityWhitelist!");
|
||||
Log.Error($"StringsToRegs failed: Unknown component name {name} passed to EntityWhitelist!");
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user