Merge remote-tracking branch 'upstream/stable' into ed-30-04-2025-upstream-sync
# Conflicts: # Content.Client/Parallax/ParallaxControl.cs # Content.Client/UserInterface/Systems/Storage/Controls/ItemGridPiece.cs # Content.IntegrationTests/Tests/PostMapInitTest.cs # Content.Server/Chat/Managers/ChatManager.cs # Content.Server/Fluids/EntitySystems/PuddleSystem.Evaporation.cs # Content.Server/Labels/Label/LabelSystem.cs # Content.Shared/Actions/SharedActionsSystem.cs # Content.Shared/Fluids/Components/EvaporationComponent.cs # Content.Shared/Labels/EntitySystems/SharedLabelSystem.cs # README.md # Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml # Resources/Prototypes/Maps/Pools/deathmatch.yml # Resources/Prototypes/Maps/arenas.yml
This commit is contained in:
44
Content.Shared/Access/Components/ExpireIdCardComponent.cs
Normal file
44
Content.Shared/Access/Components/ExpireIdCardComponent.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Content.Shared.Access.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Access.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is used for an ID that expires and replaces its access after a certain period has passed.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
|
||||
[Access(typeof(SharedIdCardSystem))]
|
||||
public sealed partial class ExpireIdCardComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether this ID has expired yet and had its accesses replaced.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool Expired;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this card will expire at all.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool Permanent;
|
||||
|
||||
/// <summary>
|
||||
/// The time at which this card will expire and the access will be removed.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField, AutoNetworkedField]
|
||||
public TimeSpan ExpireTime = TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Access the replaces current access once this card expires.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public HashSet<ProtoId<AccessLevelPrototype>> ExpiredAccess = new();
|
||||
|
||||
/// <summary>
|
||||
/// Line spoken by the card when it expires.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public LocId? ExpireMessage;
|
||||
}
|
||||
@@ -36,6 +36,13 @@ public sealed partial class IdCardComponent : Component
|
||||
[AutoNetworkedField]
|
||||
public ProtoId<JobIconPrototype> JobIcon = "JobIconUnknown";
|
||||
|
||||
/// <summary>
|
||||
/// Holds the job prototype when the ID card has no associated station record
|
||||
/// </summary>
|
||||
[DataField]
|
||||
[AutoNetworkedField]
|
||||
public ProtoId<AccessLevelPrototype>? JobPrototype;
|
||||
|
||||
/// <summary>
|
||||
/// The proto IDs of the departments associated with the job
|
||||
/// </summary>
|
||||
|
||||
@@ -9,12 +9,15 @@ using Content.Shared.PDA;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.StatusIcon;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Access.Systems;
|
||||
|
||||
public abstract class SharedIdCardSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly SharedAccessSystem _access = default!;
|
||||
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
@@ -256,4 +259,49 @@ public abstract class SharedIdCardSystem : EntitySystem
|
||||
return $"{idCardComponent.FullName} ({CultureInfo.CurrentCulture.TextInfo.ToTitleCase(idCardComponent.LocalizedJobTitle ?? string.Empty)})"
|
||||
.Trim();
|
||||
}
|
||||
|
||||
public void SetExpireTime(Entity<ExpireIdCardComponent?> ent, TimeSpan time)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp))
|
||||
return;
|
||||
ent.Comp.ExpireTime = time;
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
public void SetPermanent(Entity<ExpireIdCardComponent?> ent, bool val)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp))
|
||||
return;
|
||||
ent.Comp.Permanent = val;
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks an <see cref="ExpireIdCardComponent"/> as expired, setting the accesses.
|
||||
/// </summary>
|
||||
public virtual void ExpireId(Entity<ExpireIdCardComponent> ent)
|
||||
{
|
||||
if (ent.Comp.Expired)
|
||||
return;
|
||||
|
||||
_access.TrySetTags(ent, ent.Comp.ExpiredAccess);
|
||||
ent.Comp.Expired = true;
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
var query = EntityQueryEnumerator<ExpireIdCardComponent>();
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
if (comp.Expired || comp.Permanent)
|
||||
continue;
|
||||
|
||||
if (_timing.CurTime < comp.ExpireTime)
|
||||
continue;
|
||||
|
||||
ExpireId((uid, comp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,24 +86,6 @@ public abstract partial class BaseActionComponent : Component
|
||||
/// </summary>
|
||||
[DataField("useDelay")] public TimeSpan? UseDelay;
|
||||
|
||||
/// <summary>
|
||||
/// Convenience tool for actions with limited number of charges. Automatically decremented on use, and the
|
||||
/// action is disabled when it reaches zero. Does NOT automatically remove the action from the action bar.
|
||||
/// However, charges will regenerate if <see cref="RenewCharges"/> is enabled and the action will not disable
|
||||
/// when charges reach zero.
|
||||
/// </summary>
|
||||
[DataField("charges")] public int? Charges;
|
||||
|
||||
/// <summary>
|
||||
/// The max charges this action has. If null, this is set automatically from <see cref="Charges"/> on mapinit.
|
||||
/// </summary>
|
||||
[DataField] public int? MaxCharges;
|
||||
|
||||
/// <summary>
|
||||
/// If enabled, charges will regenerate after a <see cref="Cooldown"/> is complete
|
||||
/// </summary>
|
||||
[DataField("renewCharges")]public bool RenewCharges;
|
||||
|
||||
/// <summary>
|
||||
/// The entity that contains this action. If the action is innate, this may be the user themselves.
|
||||
/// This should almost always be non-null.
|
||||
@@ -209,9 +191,6 @@ public abstract class BaseActionComponentState : ComponentState
|
||||
public bool Toggled;
|
||||
public (TimeSpan Start, TimeSpan End)? Cooldown;
|
||||
public TimeSpan? UseDelay;
|
||||
public int? Charges;
|
||||
public int? MaxCharges;
|
||||
public bool RenewCharges;
|
||||
public NetEntity? Container;
|
||||
public NetEntity? EntityIcon;
|
||||
public bool CheckCanInteract;
|
||||
@@ -243,9 +222,6 @@ public abstract class BaseActionComponentState : ComponentState
|
||||
Toggled = component.Toggled;
|
||||
Cooldown = component.Cooldown;
|
||||
UseDelay = component.UseDelay;
|
||||
Charges = component.Charges;
|
||||
MaxCharges = component.MaxCharges;
|
||||
RenewCharges = component.RenewCharges;
|
||||
CheckCanInteract = component.CheckCanInteract;
|
||||
CheckConsciousness = component.CheckConsciousness;
|
||||
ClientExclusive = component.ClientExclusive;
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
namespace Content.Shared.Actions.Events;
|
||||
|
||||
public sealed class DisarmAttemptEvent : CancellableEntityEventArgs
|
||||
/// <summary>
|
||||
/// Raised directed on the target OR their actively held entity.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct DisarmAttemptEvent
|
||||
{
|
||||
public readonly EntityUid TargetUid;
|
||||
public readonly EntityUid DisarmerUid;
|
||||
public readonly EntityUid? TargetItemInHandUid;
|
||||
|
||||
public bool Cancelled;
|
||||
|
||||
public DisarmAttemptEvent(EntityUid targetUid, EntityUid disarmerUid, EntityUid? targetItemInHandUid = null)
|
||||
{
|
||||
TargetUid = targetUid;
|
||||
DisarmerUid = disarmerUid;
|
||||
TargetItemInHandUid = targetItemInHandUid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,14 @@ namespace Content.Shared.Actions;
|
||||
public abstract class SharedActionsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly IGameTiming GameTiming = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
||||
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
|
||||
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
|
||||
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
|
||||
[Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -69,47 +69,9 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
SubscribeAllEvent<RequestPerformActionEvent>(OnActionRequest);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var worldActionQuery = EntityQueryEnumerator<WorldTargetActionComponent>();
|
||||
while (worldActionQuery.MoveNext(out var uid, out var action))
|
||||
{
|
||||
if (IsCooldownActive(action) || !ShouldResetCharges(action))
|
||||
continue;
|
||||
|
||||
ResetCharges(uid, dirty: true);
|
||||
}
|
||||
|
||||
var instantActionQuery = EntityQueryEnumerator<InstantActionComponent>();
|
||||
while (instantActionQuery.MoveNext(out var uid, out var action))
|
||||
{
|
||||
if (IsCooldownActive(action) || !ShouldResetCharges(action))
|
||||
continue;
|
||||
|
||||
ResetCharges(uid, dirty: true);
|
||||
}
|
||||
|
||||
var entityActionQuery = EntityQueryEnumerator<EntityTargetActionComponent>();
|
||||
while (entityActionQuery.MoveNext(out var uid, out var action))
|
||||
{
|
||||
if (IsCooldownActive(action) || !ShouldResetCharges(action))
|
||||
continue;
|
||||
|
||||
ResetCharges(uid, dirty: true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnActionMapInit(EntityUid uid, BaseActionComponent component, MapInitEvent args)
|
||||
{
|
||||
component.OriginalIconColor = component.IconColor;
|
||||
|
||||
if (component.Charges == null)
|
||||
return;
|
||||
|
||||
component.MaxCharges ??= component.Charges.Value;
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void OnActionShutdown(EntityUid uid, BaseActionComponent component, ComponentShutdown args)
|
||||
@@ -324,68 +286,6 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public void SetCharges(EntityUid? actionId, int? charges)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action) ||
|
||||
action.Charges == charges)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
action.Charges = charges;
|
||||
UpdateAction(actionId, action);
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public int? GetCharges(EntityUid? actionId)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action))
|
||||
return null;
|
||||
|
||||
return action.Charges;
|
||||
}
|
||||
|
||||
public void AddCharges(EntityUid? actionId, int addCharges)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action) || action.Charges == null || addCharges < 1)
|
||||
return;
|
||||
|
||||
action.Charges += addCharges;
|
||||
UpdateAction(actionId, action);
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public void RemoveCharges(EntityUid? actionId, int? removeCharges)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action) || action.Charges == null)
|
||||
return;
|
||||
|
||||
if (removeCharges == null)
|
||||
action.Charges = removeCharges;
|
||||
else
|
||||
action.Charges -= removeCharges;
|
||||
|
||||
if (action.Charges is < 0)
|
||||
action.Charges = null;
|
||||
|
||||
UpdateAction(actionId, action);
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public void ResetCharges(EntityUid? actionId, bool update = false, bool dirty = false)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action))
|
||||
return;
|
||||
|
||||
action.Charges = action.MaxCharges;
|
||||
|
||||
if (update)
|
||||
UpdateAction(actionId, action);
|
||||
|
||||
if (dirty)
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
private void OnActionsGetState(EntityUid uid, ActionsComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new ActionsComponentState(GetNetEntitySet(component.Actions));
|
||||
@@ -428,6 +328,10 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
if (!action.Enabled)
|
||||
return;
|
||||
|
||||
var curTime = GameTiming.CurTime;
|
||||
if (IsCooldownActive(action, curTime))
|
||||
return;
|
||||
|
||||
// check for action use prevention
|
||||
// TODO: make code below use this event with a dedicated component
|
||||
var attemptEv = new ActionAttemptEvent(user);
|
||||
@@ -435,14 +339,6 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
if (attemptEv.Cancelled)
|
||||
return;
|
||||
|
||||
var curTime = GameTiming.CurTime;
|
||||
if (IsCooldownActive(action, curTime))
|
||||
return;
|
||||
|
||||
// TODO: Replace with individual charge recovery when we have the visuals to aid it
|
||||
if (action is { Charges: < 1, RenewCharges: true })
|
||||
ResetCharges(actionEnt, true, true);
|
||||
|
||||
BaseActionEvent? performEvent = null;
|
||||
|
||||
if (action.CheckConsciousness && !_actionBlockerSystem.CanConsciouslyPerformAction(user))
|
||||
@@ -633,13 +529,12 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
// even if we don't check for obstructions, we may still need to check the range.
|
||||
var xform = Transform(user);
|
||||
|
||||
if (xform.MapID != coords.GetMapId(EntityManager))
|
||||
if (xform.MapID != _transformSystem.GetMapId(coords))
|
||||
return false;
|
||||
|
||||
if (range <= 0)
|
||||
return true;
|
||||
|
||||
return coords.InRange(EntityManager, _transformSystem, Transform(user).Coordinates, range);
|
||||
return _transformSystem.InRange(coords, xform.Coordinates, range);
|
||||
}
|
||||
|
||||
return _interactionSystem.InRangeUnobstructed(user, coords, range: range);
|
||||
@@ -717,16 +612,8 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
|
||||
var dirty = toggledBefore != action.Toggled;
|
||||
|
||||
if (action.Charges != null)
|
||||
{
|
||||
dirty = true;
|
||||
action.Charges--;
|
||||
if (action is { Charges: 0, RenewCharges: false })
|
||||
action.Enabled = false;
|
||||
}
|
||||
|
||||
//action.Cooldown = null; //CP14 - disabling auto cooldown after using
|
||||
if (action is { UseDelay: not null, Charges: null or < 1 })
|
||||
if (action is { UseDelay: not null})
|
||||
{
|
||||
dirty = true;
|
||||
action.Cooldown = (curTime, curTime + action.UseDelay.Value);
|
||||
@@ -1026,8 +913,6 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
if (!action.Enabled)
|
||||
return false;
|
||||
|
||||
if (action.Charges.HasValue && action.Charges <= 0)
|
||||
return false;
|
||||
|
||||
var curTime = GameTiming.CurTime;
|
||||
if (action.Cooldown.HasValue && action.Cooldown.Value.End > curTime)
|
||||
@@ -1137,15 +1022,9 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Checks if the action has a cooldown and if it's still active
|
||||
/// </summary>
|
||||
protected bool IsCooldownActive(BaseActionComponent action, TimeSpan? curTime = null)
|
||||
public bool IsCooldownActive(BaseActionComponent action, TimeSpan? curTime = null)
|
||||
{
|
||||
curTime ??= GameTiming.CurTime;
|
||||
// TODO: Check for charge recovery timer
|
||||
return action.Cooldown.HasValue && action.Cooldown.Value.End > curTime;
|
||||
}
|
||||
|
||||
protected bool ShouldResetCharges(BaseActionComponent action)
|
||||
{
|
||||
return action is { Charges: < 1, RenewCharges: true };
|
||||
}
|
||||
}
|
||||
|
||||
19
Content.Shared/Administration/Components/MarkerComponent.cs
Normal file
19
Content.Shared/Administration/Components/MarkerComponent.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Content.Shared.Administration.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This component does nothing. It exists for admin and testing purposes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// As an example, this component can be added to an entity and then used as
|
||||
/// the target component for a pinpointer.
|
||||
/// </remarks>
|
||||
[RegisterComponent]
|
||||
public sealed partial class MarkerOneComponent : Component;
|
||||
|
||||
/// <inheritdoc cref="MarkerOneComponent"/>
|
||||
[RegisterComponent]
|
||||
public sealed partial class MarkerTwoComponent : Component;
|
||||
|
||||
/// <inheritdoc cref="MarkerOneComponent"/>
|
||||
[RegisterComponent]
|
||||
public sealed partial class MarkerThreeComponent : Component;
|
||||
@@ -12,6 +12,7 @@ public sealed record PlayerInfo(
|
||||
string StartingJob,
|
||||
bool Antag,
|
||||
RoleTypePrototype RoleProto,
|
||||
LocId? Subtype,
|
||||
int SortWeight,
|
||||
NetEntity? NetEntity,
|
||||
NetUserId SessionId,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using Content.Shared.Eui;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Serialization;
|
||||
using YamlDotNet.Serialization.Callbacks;
|
||||
|
||||
namespace Content.Shared.Administration;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PlayerPanelEuiState(NetUserId guid,
|
||||
public sealed class PlayerPanelEuiState(
|
||||
NetUserId guid,
|
||||
string username,
|
||||
TimeSpan playtime,
|
||||
int? totalNotes,
|
||||
@@ -52,3 +52,6 @@ public sealed class PlayerPanelDeleteMessage : EuiMessageBase;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PlayerPanelRejuvenationMessage: EuiMessageBase;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PlayerPanelFollowMessage: EuiMessageBase;
|
||||
|
||||
@@ -153,10 +153,11 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
if (!Timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
Audio.PlayPvs(component.SupercriticalSound, Transform(uid).Coordinates);
|
||||
|
||||
if (_net.IsServer)
|
||||
{
|
||||
Audio.PlayPvs(component.SupercriticalSound, Transform(uid).Coordinates);
|
||||
Log.Info($"Raising supercritical event. Entity: {ToPrettyString(uid)}");
|
||||
}
|
||||
|
||||
var powerMod = 1f;
|
||||
if (component.CurrentBehavior != null)
|
||||
@@ -355,7 +356,7 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
if (Timing.CurTime <= super.EndTime)
|
||||
continue;
|
||||
DoAnomalySupercriticalEvent(ent, anom);
|
||||
RemComp(ent, super);
|
||||
// Removal of the supercritical component is handled by DoAnomalySupercriticalEvent
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Atmos.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Makes entities with extinguishing behavior automatically enable/disable <see cref="CollisionWakeComponent"/>,
|
||||
/// so they can be extinguished with fire extinguishers.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent]
|
||||
public sealed partial class ExtinguishableSetCollisionWakeComponent : Component;
|
||||
@@ -27,5 +27,11 @@ public sealed partial class MovedByPressureComponent : Component
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int LastHighPressureMovementAirCycle { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Used to remember which fixtures we have to remove the table mask from and give it back accordingly
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public HashSet<string> TableLayerRemoved = new();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using Content.Shared.Atmos.Components;
|
||||
|
||||
namespace Content.Shared.Atmos.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// Implements <see cref="ExtinguishableSetCollisionWakeComponent"/>.
|
||||
/// </summary>
|
||||
public sealed class ExtinguishableSetCollisionWakeSystem : EntitySystem
|
||||
{
|
||||
[Dependency]
|
||||
private readonly CollisionWakeSystem _collisionWake = null!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ExtinguishableSetCollisionWakeComponent, ExtinguishedEvent>(HandleExtinguished);
|
||||
SubscribeLocalEvent<ExtinguishableSetCollisionWakeComponent, IgnitedEvent>(HandleIgnited);
|
||||
}
|
||||
|
||||
private void HandleExtinguished(Entity<ExtinguishableSetCollisionWakeComponent> ent, ref ExtinguishedEvent args)
|
||||
{
|
||||
_collisionWake.SetEnabled(ent, true);
|
||||
}
|
||||
|
||||
private void HandleIgnited(Entity<ExtinguishableSetCollisionWakeComponent> ent, ref IgnitedEvent args)
|
||||
{
|
||||
_collisionWake.SetEnabled(ent, false);
|
||||
}
|
||||
}
|
||||
42
Content.Shared/Atmos/FireEvents.cs
Normal file
42
Content.Shared/Atmos/FireEvents.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
|
||||
namespace Content.Shared.Atmos;
|
||||
|
||||
// NOTE: These components are currently not raised on the client, only on the server.
|
||||
|
||||
/// <summary>
|
||||
/// An entity has had an existing effect applied to it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This does not necessarily mean the effect is strong enough to fully extinguish the entity in one go.
|
||||
/// </remarks>
|
||||
[ByRefEvent]
|
||||
public struct ExtinguishEvent : IInventoryRelayEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Amount of firestacks changed. Should be a negative number.
|
||||
/// </summary>
|
||||
public float FireStacksAdjustment;
|
||||
|
||||
SlotFlags IInventoryRelayEvent.TargetSlots => SlotFlags.WITHOUT_POCKET;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A flammable entity has been extinguished.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can occur on both <c>Flammable</c> entities as well as <see cref="SmokableComponent"/>.
|
||||
/// </remarks>
|
||||
/// <seealso cref="ExtinguishEvent"/>
|
||||
[ByRefEvent]
|
||||
public struct ExtinguishedEvent;
|
||||
|
||||
/// <summary>
|
||||
/// A flammable entity has been ignited.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can occur on both <c>Flammable</c> entities as well as <see cref="SmokableComponent"/>.
|
||||
/// </remarks>
|
||||
[ByRefEvent]
|
||||
public struct IgnitedEvent;
|
||||
@@ -0,0 +1,45 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Atmos.Piping.Binary.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
public sealed partial class GasVolumePumpComponent : Component
|
||||
{
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool Enabled = true;
|
||||
|
||||
[DataField]
|
||||
public bool Blocked = false;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Overclocked = false;
|
||||
|
||||
[DataField("inlet")]
|
||||
public string InletName = "inlet";
|
||||
|
||||
[DataField("outlet")]
|
||||
public string OutletName = "outlet";
|
||||
|
||||
[DataField, AutoNetworkedField]
|
||||
public float TransferRate = Atmospherics.MaxTransferRate;
|
||||
|
||||
[DataField]
|
||||
public float MaxTransferRate = Atmospherics.MaxTransferRate;
|
||||
|
||||
[DataField]
|
||||
public float LeakRatio = 0.1f;
|
||||
|
||||
[DataField]
|
||||
public float LowerThreshold = 0.01f;
|
||||
|
||||
[DataField]
|
||||
public float HigherThreshold = DefaultHigherThreshold;
|
||||
|
||||
public static readonly float DefaultHigherThreshold = 2 * Atmospherics.MaxOutputPressure;
|
||||
|
||||
[DataField]
|
||||
public float OverclockThreshold = 1000;
|
||||
|
||||
[DataField]
|
||||
public float LastMolesTransferred;
|
||||
}
|
||||
@@ -5,26 +5,11 @@ namespace Content.Shared.Atmos.Piping.Binary.Components
|
||||
public sealed record GasVolumePumpData(float LastMolesTransferred);
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum GasVolumePumpUiKey
|
||||
public enum GasVolumePumpUiKey : byte
|
||||
{
|
||||
Key,
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class GasVolumePumpBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public string PumpLabel { get; }
|
||||
public float TransferRate { get; }
|
||||
public bool Enabled { get; }
|
||||
|
||||
public GasVolumePumpBoundUserInterfaceState(string pumpLabel, float transferRate, bool enabled)
|
||||
{
|
||||
PumpLabel = pumpLabel;
|
||||
TransferRate = transferRate;
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class GasVolumePumpToggleStatusMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Atmos.Piping.Binary.Components;
|
||||
using Content.Shared.Atmos.Visuals;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Power;
|
||||
using Content.Shared.Power.EntitySystems;
|
||||
|
||||
namespace Content.Shared.Atmos.Piping.Binary.Systems;
|
||||
|
||||
public abstract class SharedGasVolumePumpSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly SharedPowerReceiverSystem _receiver = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<GasVolumePumpComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<GasVolumePumpComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
|
||||
SubscribeLocalEvent<GasVolumePumpComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpToggleStatusMessage>(OnToggleStatusMessage);
|
||||
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpChangeTransferRateMessage>(OnTransferRateChangeMessage);
|
||||
}
|
||||
|
||||
private void OnInit(Entity<GasVolumePumpComponent> ent, ref ComponentInit args)
|
||||
{
|
||||
UpdateAppearance(ent.Owner, ent.Comp);
|
||||
}
|
||||
|
||||
private void OnPowerChanged(Entity<GasVolumePumpComponent> ent, ref PowerChangedEvent args)
|
||||
{
|
||||
UpdateAppearance(ent.Owner, ent.Comp);
|
||||
}
|
||||
|
||||
protected virtual void UpdateUi(Entity<GasVolumePumpComponent> entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnToggleStatusMessage(EntityUid uid, GasVolumePumpComponent pump, GasVolumePumpToggleStatusMessage args)
|
||||
{
|
||||
pump.Enabled = args.Enabled;
|
||||
_adminLogger.Add(LogType.AtmosPowerChanged, LogImpact.Medium,
|
||||
$"{ToPrettyString(args.Actor):player} set the power on {ToPrettyString(uid):device} to {args.Enabled}");
|
||||
|
||||
Dirty(uid, pump);
|
||||
UpdateUi((uid, pump));
|
||||
UpdateAppearance(uid, pump);
|
||||
}
|
||||
|
||||
private void OnTransferRateChangeMessage(EntityUid uid, GasVolumePumpComponent pump, GasVolumePumpChangeTransferRateMessage args)
|
||||
{
|
||||
pump.TransferRate = Math.Clamp(args.TransferRate, 0f, pump.MaxTransferRate);
|
||||
Dirty(uid, pump);
|
||||
UpdateUi((uid, pump));
|
||||
_adminLogger.Add(LogType.AtmosVolumeChanged, LogImpact.Medium,
|
||||
$"{ToPrettyString(args.Actor):player} set the transfer rate on {ToPrettyString(uid):device} to {args.TransferRate}");
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, GasVolumePumpComponent pump, ExaminedEvent args)
|
||||
{
|
||||
if (!Transform(uid).Anchored)
|
||||
return;
|
||||
|
||||
if (Loc.TryGetString("gas-volume-pump-system-examined",
|
||||
out var str,
|
||||
("statusColor", "lightblue"), // TODO: change with volume?
|
||||
("rate", pump.TransferRate)
|
||||
))
|
||||
{
|
||||
args.PushMarkup(str);
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateAppearance(EntityUid uid, GasVolumePumpComponent? pump = null, AppearanceComponent? appearance = null)
|
||||
{
|
||||
if (!Resolve(uid, ref pump, ref appearance, false))
|
||||
return;
|
||||
|
||||
bool pumpOn = pump.Enabled && _receiver.IsPowered(uid);
|
||||
if (!pumpOn)
|
||||
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.Off, appearance);
|
||||
else if (pump.Blocked)
|
||||
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.Blocked, appearance);
|
||||
else
|
||||
_appearance.SetData(uid, GasVolumePumpVisuals.State, GasVolumePumpState.On, appearance);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using Content.Shared.Mobs.Systems;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Bed.Cryostorage;
|
||||
@@ -17,13 +18,15 @@ namespace Content.Shared.Bed.Cryostorage;
|
||||
/// </summary>
|
||||
public abstract class SharedCryostorageSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly ISharedAdminLogManager AdminLog = default!;
|
||||
[Dependency] private readonly IConfigurationManager _configuration = default!;
|
||||
[Dependency] private readonly IConfigurationManager _configuration = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly ISharedPlayerManager _player = default!;
|
||||
[Dependency] private readonly SharedMapSystem _map = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] protected readonly IGameTiming Timing = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] protected readonly ISharedAdminLogManager AdminLog = default!;
|
||||
[Dependency] protected readonly SharedMindSystem Mind = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||
|
||||
protected EntityUid? PausedMap { get; private set; }
|
||||
|
||||
@@ -123,7 +126,8 @@ public abstract class SharedCryostorageSystem : EntitySystem
|
||||
if (args.Dragged == args.User)
|
||||
return;
|
||||
|
||||
if (!Mind.TryGetMind(args.Dragged, out _, out var mindComp) || mindComp.Session?.AttachedEntity != args.Dragged)
|
||||
if (!_player.TryGetSessionByEntity(args.Dragged, out var session) ||
|
||||
session.AttachedEntity != args.Dragged)
|
||||
return;
|
||||
|
||||
args.CanDrop = false;
|
||||
@@ -165,9 +169,8 @@ public abstract class SharedCryostorageSystem : EntitySystem
|
||||
if (PausedMap != null && Exists(PausedMap))
|
||||
return;
|
||||
|
||||
var map = _mapManager.CreateMap();
|
||||
_mapManager.SetMapPaused(map, true);
|
||||
PausedMap = _mapManager.GetMapEntityId(map);
|
||||
PausedMap = _map.CreateMap();
|
||||
_map.SetPaused(PausedMap.Value, true);
|
||||
}
|
||||
|
||||
public bool IsInPausedMap(Entity<TransformComponent?> entity)
|
||||
|
||||
@@ -13,13 +13,9 @@ using Content.Shared.Physics;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Toggleable;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Blocking;
|
||||
@@ -35,8 +31,6 @@ public sealed partial class BlockingSystem : EntitySystem
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly ExamineSystemShared _examine = default!;
|
||||
[Dependency] private readonly INetManager _net = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -156,61 +150,53 @@ public sealed partial class BlockingSystem : EntitySystem
|
||||
var msgUser = Loc.GetString("action-popup-blocking-user", ("shield", shieldName));
|
||||
var msgOther = Loc.GetString("action-popup-blocking-other", ("blockerName", blockerName), ("shield", shieldName));
|
||||
|
||||
if (component.BlockingToggleAction != null)
|
||||
//Don't allow someone to block if they're not parented to a grid
|
||||
if (xform.GridUid != xform.ParentUid)
|
||||
{
|
||||
//Don't allow someone to block if they're not parented to a grid
|
||||
if (xform.GridUid != xform.ParentUid)
|
||||
{
|
||||
CantBlockError(user);
|
||||
return false;
|
||||
}
|
||||
CantBlockError(user);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't allow someone to block if they're not holding the shield
|
||||
if(!_handsSystem.IsHolding(user, item, out _))
|
||||
{
|
||||
CantBlockError(user);
|
||||
return false;
|
||||
}
|
||||
// Don't allow someone to block if they're not holding the shield
|
||||
if (!_handsSystem.IsHolding(user, item, out _))
|
||||
{
|
||||
CantBlockError(user);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Don't allow someone to block if someone else is on the same tile
|
||||
var playerTileRef = xform.Coordinates.GetTileRef();
|
||||
if (playerTileRef != null)
|
||||
//Don't allow someone to block if someone else is on the same tile
|
||||
var playerTileRef = xform.Coordinates.GetTileRef();
|
||||
if (playerTileRef != null)
|
||||
{
|
||||
var intersecting = _lookup.GetLocalEntitiesIntersecting(playerTileRef.Value, 0f);
|
||||
var mobQuery = GetEntityQuery<MobStateComponent>();
|
||||
foreach (var uid in intersecting)
|
||||
{
|
||||
var intersecting = _lookup.GetLocalEntitiesIntersecting(playerTileRef.Value, 0f);
|
||||
var mobQuery = GetEntityQuery<MobStateComponent>();
|
||||
foreach (var uid in intersecting)
|
||||
if (uid != user && mobQuery.HasComponent(uid))
|
||||
{
|
||||
if (uid != user && mobQuery.HasComponent(uid))
|
||||
{
|
||||
TooCloseError(user);
|
||||
return false;
|
||||
}
|
||||
TooCloseError(user);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Don't allow someone to block if they're somehow not anchored.
|
||||
_transformSystem.AnchorEntity(user, xform);
|
||||
if (!xform.Anchored)
|
||||
{
|
||||
CantBlockError(user);
|
||||
return false;
|
||||
}
|
||||
_actionsSystem.SetToggled(component.BlockingToggleActionEntity, true);
|
||||
if (_gameTiming.IsFirstTimePredicted)
|
||||
{
|
||||
_popupSystem.PopupEntity(msgOther, user, Filter.PvsExcept(user), true);
|
||||
if(_gameTiming.InPrediction)
|
||||
_popupSystem.PopupEntity(msgUser, user, user);
|
||||
}
|
||||
}
|
||||
|
||||
//Don't allow someone to block if they're somehow not anchored.
|
||||
_transformSystem.AnchorEntity(user, xform);
|
||||
if (!xform.Anchored)
|
||||
{
|
||||
CantBlockError(user);
|
||||
return false;
|
||||
}
|
||||
_actionsSystem.SetToggled(component.BlockingToggleActionEntity, true);
|
||||
_popupSystem.PopupPredicted(msgUser, msgOther, user, user);
|
||||
|
||||
if (TryComp<PhysicsComponent>(user, out var physicsComponent))
|
||||
{
|
||||
_fixtureSystem.TryCreateFixture(user,
|
||||
component.Shape,
|
||||
BlockingComponent.BlockFixtureID,
|
||||
hard: true,
|
||||
collisionLayer: (int) CollisionGroup.WallLayer,
|
||||
collisionLayer: (int)CollisionGroup.WallLayer,
|
||||
body: physicsComponent);
|
||||
}
|
||||
|
||||
@@ -223,13 +209,13 @@ public sealed partial class BlockingSystem : EntitySystem
|
||||
private void CantBlockError(EntityUid user)
|
||||
{
|
||||
var msgError = Loc.GetString("action-popup-blocking-user-cant-block");
|
||||
_popupSystem.PopupEntity(msgError, user, user);
|
||||
_popupSystem.PopupClient(msgError, user, user);
|
||||
}
|
||||
|
||||
private void TooCloseError(EntityUid user)
|
||||
{
|
||||
var msgError = Loc.GetString("action-popup-blocking-user-too-close");
|
||||
_popupSystem.PopupEntity(msgError, user, user);
|
||||
_popupSystem.PopupClient(msgError, user, user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -255,8 +241,7 @@ public sealed partial class BlockingSystem : EntitySystem
|
||||
//If the component blocking toggle isn't null, grab the users SharedBlockingUserComponent and PhysicsComponent
|
||||
//then toggle the action to false, unanchor the user, remove the hard fixture
|
||||
//and set the users bodytype back to their original type
|
||||
if (component.BlockingToggleAction != null && TryComp<BlockingUserComponent>(user, out var blockingUserComponent)
|
||||
&& TryComp<PhysicsComponent>(user, out var physicsComponent))
|
||||
if (TryComp<BlockingUserComponent>(user, out var blockingUserComponent) && TryComp<PhysicsComponent>(user, out var physicsComponent))
|
||||
{
|
||||
if (xform.Anchored)
|
||||
_transformSystem.Unanchor(user, xform);
|
||||
@@ -264,12 +249,7 @@ public sealed partial class BlockingSystem : EntitySystem
|
||||
_actionsSystem.SetToggled(component.BlockingToggleActionEntity, false);
|
||||
_fixtureSystem.DestroyFixture(user, BlockingComponent.BlockFixtureID, body: physicsComponent);
|
||||
_physics.SetBodyType(user, blockingUserComponent.OriginalBodyType, body: physicsComponent);
|
||||
if (_gameTiming.IsFirstTimePredicted)
|
||||
{
|
||||
_popupSystem.PopupEntity(msgOther, user, Filter.PvsExcept(user), true);
|
||||
if(_gameTiming.InPrediction)
|
||||
_popupSystem.PopupEntity(msgUser, user, user);
|
||||
}
|
||||
_popupSystem.PopupPredicted(msgUser, msgOther, user, user);
|
||||
}
|
||||
|
||||
component.IsBlocking = false;
|
||||
@@ -313,7 +293,7 @@ public sealed partial class BlockingSystem : EntitySystem
|
||||
|
||||
private void OnVerbExamine(EntityUid uid, BlockingComponent component, GetVerbsEvent<ExamineVerb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess || !_net.IsServer)
|
||||
if (!args.CanInteract || !args.CanAccess)
|
||||
return;
|
||||
|
||||
var fraction = component.IsBlocking ? component.ActiveBlockFraction : component.PassiveBlockFraction;
|
||||
|
||||
@@ -16,13 +16,13 @@ public sealed partial class BlockingComponent : Component
|
||||
/// <summary>
|
||||
/// The entity that's blocking
|
||||
/// </summary>
|
||||
[ViewVariables, AutoNetworkedField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public EntityUid? User;
|
||||
|
||||
/// <summary>
|
||||
/// Is it currently blocking?
|
||||
/// </summary>
|
||||
[ViewVariables, AutoNetworkedField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool IsBlocking;
|
||||
|
||||
/// <summary>
|
||||
@@ -33,7 +33,7 @@ public sealed partial class BlockingComponent : Component
|
||||
/// <summary>
|
||||
/// The shape of the blocking fixture that will be dynamically spawned
|
||||
/// </summary>
|
||||
[DataField("shape"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public IPhysShape Shape = new PhysShapeCircle(0.5f);
|
||||
|
||||
/// <summary>
|
||||
@@ -48,8 +48,8 @@ public sealed partial class BlockingComponent : Component
|
||||
[DataField("activeBlockModifier", required: true)]
|
||||
public DamageModifierSet ActiveBlockDamageModifier = default!;
|
||||
|
||||
[DataField("blockingToggleAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string BlockingToggleAction = "ActionToggleBlock";
|
||||
[DataField]
|
||||
public EntProtoId BlockingToggleAction = "ActionToggleBlock";
|
||||
|
||||
[DataField, AutoNetworkedField]
|
||||
public EntityUid? BlockingToggleActionEntity;
|
||||
@@ -57,7 +57,7 @@ public sealed partial class BlockingComponent : Component
|
||||
/// <summary>
|
||||
/// The sound to be played when you get hit while actively blocking
|
||||
/// </summary>
|
||||
[DataField("blockSound")] public SoundSpecifier BlockSound =
|
||||
[DataField] public SoundSpecifier BlockSound =
|
||||
new SoundPathSpecifier("/Audio/Weapons/block_metal1.ogg")
|
||||
{
|
||||
Params = AudioParams.Default.WithVariation(0.25f)
|
||||
@@ -67,13 +67,13 @@ public sealed partial class BlockingComponent : Component
|
||||
/// Fraction of original damage shield will take instead of user
|
||||
/// when not blocking
|
||||
/// </summary>
|
||||
[DataField("passiveBlockFraction"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public float PassiveBlockFraction = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Fraction of original damage shield will take instead of user
|
||||
/// when blocking
|
||||
/// </summary>
|
||||
[DataField("activeBlockFraction"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public float ActiveBlockFraction = 1.0f;
|
||||
}
|
||||
|
||||
@@ -40,12 +40,6 @@ public sealed class BodyPrototypeSerializer : ITypeReader<BodyPrototype, Mapping
|
||||
{
|
||||
foreach (var (key, value) in organsNode)
|
||||
{
|
||||
if (key is not ValueDataNode)
|
||||
{
|
||||
nodes.Add(new ErrorNode(key, $"Key is not a value data node"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value is not ValueDataNode organ)
|
||||
{
|
||||
nodes.Add(new ErrorNode(value, $"Value is not a value data node"));
|
||||
@@ -91,12 +85,6 @@ public sealed class BodyPrototypeSerializer : ITypeReader<BodyPrototype, Mapping
|
||||
|
||||
foreach (var (key, value) in slots)
|
||||
{
|
||||
if (key is not ValueDataNode)
|
||||
{
|
||||
nodes.Add(new ErrorNode(key, $"Key is not a value data node"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value is not MappingDataNode slot)
|
||||
{
|
||||
nodes.Add(new ErrorNode(value, $"Slot is not a mapping data node"));
|
||||
@@ -128,10 +116,9 @@ public sealed class BodyPrototypeSerializer : ITypeReader<BodyPrototype, Mapping
|
||||
var slotNodes = node.Get<MappingDataNode>("slots");
|
||||
var allConnections = new Dictionary<string, (string? Part, HashSet<string>? Connections, Dictionary<string, string>? Organs)>();
|
||||
|
||||
foreach (var (keyNode, valueNode) in slotNodes)
|
||||
foreach (var (slotId, valueNode) in slotNodes)
|
||||
{
|
||||
var slotId = ((ValueDataNode) keyNode).Value;
|
||||
var slot = ((MappingDataNode) valueNode);
|
||||
var slot = (MappingDataNode) valueNode;
|
||||
|
||||
string? part = null;
|
||||
if (slot.TryGet<ValueDataNode>("part", out var value))
|
||||
@@ -155,9 +142,9 @@ public sealed class BodyPrototypeSerializer : ITypeReader<BodyPrototype, Mapping
|
||||
{
|
||||
organs = new Dictionary<string, string>();
|
||||
|
||||
foreach (var (organKeyNode, organValueNode) in slotOrgansNode)
|
||||
foreach (var (organKey, organValueNode) in slotOrgansNode)
|
||||
{
|
||||
organs.Add(((ValueDataNode) organKeyNode).Value, ((ValueDataNode) organValueNode).Value);
|
||||
organs.Add(organKey, ((ValueDataNode) organValueNode).Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
26
Content.Shared/CCVar/CCVars.Cargo.cs
Normal file
26
Content.Shared/CCVar/CCVars.Cargo.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Robust.Shared.Configuration;
|
||||
|
||||
namespace Content.Shared.CCVar;
|
||||
|
||||
public sealed partial class CCVars
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether or not the primary account of a bank should be listed
|
||||
/// in the funding allocation console
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> AllowPrimaryAccountAllocation =
|
||||
CVarDef.Create("cargo.allow_primary_account_allocation", false, CVar.REPLICATED);
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the primary cut of a bank should be manipulable
|
||||
/// in the funding allocation console
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> AllowPrimaryCutAdjustment =
|
||||
CVarDef.Create("cargo.allow_primary_cut_adjustment", true, CVar.REPLICATED);
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the separate lockbox cut is enabled
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> LockboxCutEnabled =
|
||||
CVarDef.Create("cargo.enable_lockbox_cut", true, CVar.REPLICATED);
|
||||
}
|
||||
@@ -38,10 +38,13 @@ public sealed partial class CCVars
|
||||
CVarDef.Create("outline.enabled", true, CVar.CLIENTONLY);
|
||||
|
||||
/// <summary>
|
||||
/// If true, the admin overlay will be displayed in the old style (showing only "ANTAG")
|
||||
/// Determines how antagonist status/roletype is displayed. Based on AdminOverlayAntagFormats enum
|
||||
/// Binary: Roletypes of interest get an "ANTAG" label
|
||||
/// Roletype: Roletypes of interest will have their roletype name displayed in their specific color
|
||||
/// Subtype: Roletypes of interest will have their subtype displayed. if subtype is not set, roletype will be shown.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> AdminOverlayClassic =
|
||||
CVarDef.Create("ui.admin_overlay_classic", false, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
public static readonly CVarDef<string> AdminOverlayAntagFormat =
|
||||
CVarDef.Create("ui.admin_overlay_antag_format", "Subtype", CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// If true, the admin overlay will display the total time of the players
|
||||
@@ -50,34 +53,48 @@ public sealed partial class CCVars
|
||||
CVarDef.Create("ui.admin_overlay_playtime", true, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// If true, the admin overlay will display the players starting position.
|
||||
/// If true, the admin overlay will display the player's starting role.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> AdminOverlayStartingJob =
|
||||
CVarDef.Create("ui.admin_overlay_starting_job", true, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// If true, the admin window player tab will show different antag symbols for each role type
|
||||
/// Determines how antagonist status/roletype is displayed Before character names on the Player Tab
|
||||
/// Off: No symbol is shown.
|
||||
/// Basic: The same antag symbol is shown for anyone marked as antag.
|
||||
/// Specific: The roletype-specific symbol is shown for anyone marked as antag.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> AdminPlayerlistSeparateSymbols =
|
||||
CVarDef.Create("ui.admin_playerlist_separate_symbols", false, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
public static readonly CVarDef<string> AdminPlayerTabSymbolSetting =
|
||||
CVarDef.Create("ui.admin_player_tab_symbols", "Specific", CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// If true, characters with antag role types will have their names colored by their role type
|
||||
/// Determines what columns are colorized
|
||||
/// Off: None.
|
||||
/// Character: The character names of "roletypes-of-interest" have their role type's color.
|
||||
/// Roletype: Role types are shown in their respective colors.
|
||||
/// Both: Both characters and role types are colorized.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> AdminPlayerlistHighlightedCharacterColor =
|
||||
CVarDef.Create("ui.admin_playerlist_highlighted_character_color", true, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
public static readonly CVarDef<string> AdminPlayerTabColorSetting =
|
||||
CVarDef.Create("ui.admin_player_tab_color", "Both", CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// If true, the Role Types column will be colored
|
||||
/// Determines what's displayed in the Role column - role type, subtype, or both.
|
||||
/// RoleType
|
||||
/// SubType
|
||||
/// RoleTypeSubtype
|
||||
/// SubtypeRoleType
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> AdminPlayerlistRoleTypeColor =
|
||||
CVarDef.Create("ui.admin_playerlist_role_type_color", true, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
public static readonly CVarDef<string> AdminPlayerTabRoleSetting =
|
||||
CVarDef.Create("ui.admin_player_tab_role", "Subtype", CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// If true, the admin overlay will show antag symbols
|
||||
/// Determines how antagonist status/roletype is displayed. Based on AdminOverlayAntagSymbolStyles enum
|
||||
/// Off: No symbol is shown.
|
||||
/// Basic: The same antag symbol is shown for anyone marked as antag.
|
||||
/// Specific: The roletype-specific symbol is shown for anyone marked as antag.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> AdminOverlaySymbols =
|
||||
CVarDef.Create("ui.admin_overlay_symbols", true, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
public static readonly CVarDef<string> AdminOverlaySymbolStyle =
|
||||
CVarDef.Create("ui.admin_overlay_symbol_style", "Specific", CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// The range (in tiles) around the cursor within which the admin overlays of ghosts start to fade out
|
||||
|
||||
@@ -182,4 +182,16 @@ public sealed partial class CCVars
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> EmergencyShuttleAutoCallExtensionTime =
|
||||
CVarDef.Create("shuttle.auto_call_extension_time", 45, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Impulse multiplier for player interactions that move grids (other than shuttle thrusters, gyroscopes and grid collisons).
|
||||
/// At the moment this only affects the pushback in SpraySystem.
|
||||
/// A higher value means grids have a lower effective mass and therefore will get pushed stronger.
|
||||
/// A value of 0 will disable pushback.
|
||||
/// The default has been chosen such that a one tile grid roughly equals 2/3 Urist masses.
|
||||
/// TODO: Make grid mass a sane number so we can get rid of this.
|
||||
/// At the moment they have a very low mass of roughly 0.48 kg per tile independent of any walls or anchored objects on them.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> GridImpulseMultiplier =
|
||||
CVarDef.Create("shuttle.grid_impulse_multiplier", 0.01f, CVar.SERVERONLY);
|
||||
}
|
||||
|
||||
@@ -8,15 +8,15 @@ public sealed class CargoConsoleInterfaceState : BoundUserInterfaceState
|
||||
public string Name;
|
||||
public int Count;
|
||||
public int Capacity;
|
||||
public int Balance;
|
||||
public NetEntity Station;
|
||||
public List<CargoOrderData> Orders;
|
||||
|
||||
public CargoConsoleInterfaceState(string name, int count, int capacity, int balance, List<CargoOrderData> orders)
|
||||
public CargoConsoleInterfaceState(string name, int count, int capacity, NetEntity station, List<CargoOrderData> orders)
|
||||
{
|
||||
Name = name;
|
||||
Count = count;
|
||||
Capacity = capacity;
|
||||
Balance = balance;
|
||||
Station = station;
|
||||
Orders = orders;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Cargo.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Makes an entity a client of the station's bank account.
|
||||
/// When its balance changes it will have <see cref="BankBalanceUpdatedEvent"/> raised on it.
|
||||
/// Other systems can then use this for logic or to update ui states.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(SharedCargoSystem))]
|
||||
[AutoGenerateComponentState]
|
||||
public sealed partial class BankClientComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The balance updated for the last station this entity was a part of.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public int Balance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised on an entity with <see cref="BankClientComponent"/> when the bank's balance is updated.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct BankBalanceUpdatedEvent(EntityUid Station, int Balance);
|
||||
@@ -1,33 +1,121 @@
|
||||
using Content.Shared.Access;
|
||||
using Content.Shared.Cargo.Prototypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Content.Shared.Radio;
|
||||
using Content.Shared.Stacks;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Cargo.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Handles sending order requests to cargo. Doesn't handle orders themselves via shuttle or telepads.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
|
||||
[Access(typeof(SharedCargoSystem))]
|
||||
public sealed partial class CargoOrderConsoleComponent : Component
|
||||
{
|
||||
[DataField("soundError")] public SoundSpecifier ErrorSound =
|
||||
new SoundPathSpecifier("/Audio/Effects/Cargo/buzz_sigh.ogg");
|
||||
/// <summary>
|
||||
/// The account that this console pulls from for ordering.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<CargoAccountPrototype> Account = "Cargo";
|
||||
|
||||
[DataField("soundConfirm")]
|
||||
public SoundSpecifier ConfirmSound = new SoundPathSpecifier("/Audio/Effects/Cargo/ping.ogg");
|
||||
[DataField]
|
||||
public SoundSpecifier ErrorSound = new SoundCollectionSpecifier("CargoError");
|
||||
|
||||
/// <summary>
|
||||
/// Sound made when <see cref="TransferUnbounded"/> is toggled.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier ToggleLimitSound = new SoundCollectionSpecifier("CargoToggleLimit");
|
||||
|
||||
/// <summary>
|
||||
/// If true, account transfers have no limit and a lower cooldown.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool TransferUnbounded;
|
||||
|
||||
[ViewVariables]
|
||||
public float TransferLimit => TransferUnbounded ? 1 : BaseTransferLimit;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum percent of total funds that can be transferred or withdrawn in one action.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float BaseTransferLimit = 0.20f;
|
||||
|
||||
/// <summary>
|
||||
/// The time at which account actions can be performed again.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField, AutoPausedField]
|
||||
public TimeSpan NextAccountActionTime;
|
||||
|
||||
[ViewVariables]
|
||||
public TimeSpan AccountActionDelay => TransferUnbounded ? UnboundedAccountActionDelay : BaseAccountActionDelay;
|
||||
|
||||
/// <summary>
|
||||
/// The minimum time between account actions when <see cref="TransferUnbounded"/> is false
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan BaseAccountActionDelay = TimeSpan.FromMinutes(1);
|
||||
|
||||
/// <summary>
|
||||
/// The minimum time between account actions when <see cref="TransferUnbounded"/> is true
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan UnboundedAccountActionDelay = TimeSpan.FromSeconds(10);
|
||||
|
||||
/// <summary>
|
||||
/// The stack representing cash dispensed on withdrawals.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<StackPrototype> CashType = "Credit";
|
||||
|
||||
/// <summary>
|
||||
/// All of the <see cref="CargoProductPrototype.Group"/>s that are supported.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField, AutoNetworkedField]
|
||||
public List<string> AllowedGroups = new() { "market" };
|
||||
|
||||
/// <summary>
|
||||
/// Access needed to toggle the limit on this console.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public HashSet<ProtoId<AccessLevelPrototype>> RemoveLimitAccess = new();
|
||||
|
||||
/// <summary>
|
||||
/// Radio channel on which order approval announcements are transmitted
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<RadioChannelPrototype> AnnouncementChannel = "Supply";
|
||||
|
||||
/// <summary>
|
||||
/// Secondary radio channel which always receives order announcements.
|
||||
/// </summary>
|
||||
public static readonly ProtoId<RadioChannelPrototype> BaseAnnouncementChannel = "Supply";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Withdraw funds from an account
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class CargoConsoleWithdrawFundsMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public ProtoId<CargoAccountPrototype>? Account;
|
||||
public int Amount;
|
||||
|
||||
public CargoConsoleWithdrawFundsMessage(ProtoId<CargoAccountPrototype>? account, int amount)
|
||||
{
|
||||
Account = account;
|
||||
Amount = amount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggle the limit on withdrawals and transfers.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class CargoConsoleToggleLimitMessage : BoundUserInterfaceMessage;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using Content.Shared.Cargo.Prototypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Cargo.Components;
|
||||
|
||||
/// <summary>
|
||||
/// A console that manipulates the distribution of revenue on the station.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SharedCargoSystem))]
|
||||
public sealed partial class FundingAllocationConsoleComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Sound played when the budget distribution is set.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier SetDistributionSound = new SoundCollectionSpecifier("CargoPing");
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class SetFundingAllocationBuiMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public Dictionary<ProtoId<CargoAccountPrototype>, int> Percents;
|
||||
public double PrimaryCut;
|
||||
public double LockboxCut;
|
||||
|
||||
public SetFundingAllocationBuiMessage(Dictionary<ProtoId<CargoAccountPrototype>, int> percents, double primaryCut, double lockboxCut)
|
||||
{
|
||||
Percents = percents;
|
||||
PrimaryCut = primaryCut;
|
||||
LockboxCut = lockboxCut;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class FundingAllocationConsoleBuiState : BoundUserInterfaceState
|
||||
{
|
||||
public NetEntity Station;
|
||||
|
||||
public FundingAllocationConsoleBuiState(NetEntity station)
|
||||
{
|
||||
Station = station;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum FundingAllocationConsoleUiKey : byte
|
||||
{
|
||||
Key
|
||||
}
|
||||
17
Content.Shared/Cargo/Components/OverrideSellComponent.cs
Normal file
17
Content.Shared/Cargo/Components/OverrideSellComponent.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Content.Shared.Cargo.Prototypes;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Cargo.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Makes a sellable object portion out its value to a specified department rather than the station default
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class OverrideSellComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The account that will receive the primary funds from this being sold.
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public ProtoId<CargoAccountPrototype> OverrideAccount;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Content.Shared.Cargo.Prototypes;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Cargo.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Added to the abstract representation of a station to track its money.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(SharedCargoSystem)), AutoGenerateComponentPause, AutoGenerateComponentState]
|
||||
public sealed partial class StationBankAccountComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The account that receives funds by default
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public ProtoId<CargoAccountPrototype> PrimaryAccount = "Cargo";
|
||||
|
||||
/// <summary>
|
||||
/// When giving funds to a particular account, the proportion of funds they should receive compared to remaining accounts.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public double PrimaryCut = 0.50;
|
||||
|
||||
/// <summary>
|
||||
/// When giving funds to a particular account from an override sell, the proportion of funds they should receive compared to remaining accounts.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public double LockboxCut = 0.75;
|
||||
|
||||
/// <summary>
|
||||
/// A dictionary corresponding to the money held by each cargo account.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public Dictionary<ProtoId<CargoAccountPrototype>, int> Accounts = new()
|
||||
{
|
||||
{ "Cargo", 2000 },
|
||||
{ "Engineering", 1000 },
|
||||
{ "Medical", 1000 },
|
||||
{ "Science", 1000 },
|
||||
{ "Security", 1000 },
|
||||
{ "Service", 1000 },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// A baseline distribution used for income and dispersing leftovers after sale.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public Dictionary<ProtoId<CargoAccountPrototype>, double> RevenueDistribution = new()
|
||||
{
|
||||
{ "Cargo", 0.00 },
|
||||
{ "Engineering", 0.20 },
|
||||
{ "Medical", 0.20 },
|
||||
{ "Science", 0.20 },
|
||||
{ "Security", 0.20 },
|
||||
{ "Service", 0.20 },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// How much the bank balance goes up per second, every Delay period. Rounded down when multiplied.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public int IncreasePerSecond = 2;
|
||||
|
||||
/// <summary>
|
||||
/// The time at which the station will receive its next deposit of passive income
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField]
|
||||
public TimeSpan NextIncomeTime;
|
||||
|
||||
/// <summary>
|
||||
/// How much time to wait (in seconds) before increasing bank accounts balance.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan IncomeDelay = TimeSpan.FromSeconds(50);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast and raised on station ent whenever its balance is updated.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct BankBalanceUpdatedEvent(EntityUid Station, Dictionary<ProtoId<CargoAccountPrototype>, int> Balance);
|
||||
39
Content.Shared/Cargo/Prototypes/CargoAccountPrototype.cs
Normal file
39
Content.Shared/Cargo/Prototypes/CargoAccountPrototype.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Cargo.Prototypes;
|
||||
|
||||
/// <summary>
|
||||
/// This is a prototype for a single account that stores money on StationBankAccountComponent
|
||||
/// </summary>
|
||||
[Prototype]
|
||||
public sealed partial class CargoAccountPrototype : IPrototype
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[IdDataField]
|
||||
public string ID { get; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Full IC name of the account.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public LocId Name;
|
||||
|
||||
/// <summary>
|
||||
/// A shortened code used to refer to the account in UIs
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public LocId Code;
|
||||
|
||||
/// <summary>
|
||||
/// Color corresponding to the account.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public Color Color;
|
||||
|
||||
/// <summary>
|
||||
/// Channel used for announcing transactions.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<RadioChannelPrototype> RadioChannel;
|
||||
}
|
||||
@@ -1,7 +1,62 @@
|
||||
using Content.Shared.Cargo.Components;
|
||||
using Content.Shared.Cargo.Prototypes;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Cargo;
|
||||
|
||||
public abstract class SharedCargoSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly IGameTiming Timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<StationBankAccountComponent, MapInitEvent>(OnMapInit);
|
||||
}
|
||||
|
||||
private void OnMapInit(Entity<StationBankAccountComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
ent.Comp.NextIncomeTime = Timing.CurTime + ent.Comp.IncomeDelay;
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For a given station, retrieves the balance in a specific account.
|
||||
/// </summary>
|
||||
public int GetBalanceFromAccount(Entity<StationBankAccountComponent?> station, ProtoId<CargoAccountPrototype> account)
|
||||
{
|
||||
if (!Resolve(station, ref station.Comp))
|
||||
return 0;
|
||||
|
||||
return station.Comp.Accounts.GetValueOrDefault(account);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For a station, creates a distribution between one the bank's account and the other accounts.
|
||||
/// The primary account receives the majority percentage listed on the bank account, with the remaining
|
||||
/// funds distributed to all accounts based on <see cref="StationBankAccountComponent.RevenueDistribution"/>
|
||||
/// </summary>
|
||||
public Dictionary<ProtoId<CargoAccountPrototype>, double> CreateAccountDistribution(Entity<StationBankAccountComponent> stationBank)
|
||||
{
|
||||
var distribution = new Dictionary<ProtoId<CargoAccountPrototype>, double>
|
||||
{
|
||||
{ stationBank.Comp.PrimaryAccount, stationBank.Comp.PrimaryCut }
|
||||
};
|
||||
var remaining = 1.0 - stationBank.Comp.PrimaryCut;
|
||||
|
||||
foreach (var (account, percentage) in stationBank.Comp.RevenueDistribution)
|
||||
{
|
||||
var existing = distribution.GetOrNew(account);
|
||||
distribution[account] = existing + remaining * percentage;
|
||||
}
|
||||
return distribution;
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public enum CargoConsoleUiKey : byte
|
||||
{
|
||||
@@ -17,8 +72,6 @@ public enum CargoPalletConsoleUiKey : byte
|
||||
Sale
|
||||
}
|
||||
|
||||
public abstract class SharedCargoSystem : EntitySystem {}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum CargoTelepadState : byte
|
||||
{
|
||||
|
||||
19
Content.Shared/Charges/Components/AutoRechargeComponent.cs
Normal file
19
Content.Shared/Charges/Components/AutoRechargeComponent.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Content.Shared.Charges.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Charges.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Something with limited charges that can be recharged automatically.
|
||||
/// Requires LimitedChargesComponent to function.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
[Access(typeof(SharedChargesSystem))]
|
||||
public sealed partial class AutoRechargeComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The time it takes to regain a single charge
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public TimeSpan RechargeDuration = TimeSpan.FromSeconds(90);
|
||||
}
|
||||
@@ -1,24 +1,27 @@
|
||||
using Content.Shared.Charges.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Charges.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SharedChargesSystem))]
|
||||
[AutoGenerateComponentState]
|
||||
/// <summary>
|
||||
/// Specifies the attached action has discrete charges, separate to a cooldown.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedChargesSystem))]
|
||||
public sealed partial class LimitedChargesComponent : Component
|
||||
{
|
||||
[DataField, AutoNetworkedField]
|
||||
public int LastCharges;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of charges
|
||||
/// The max charges this action has.
|
||||
/// </summary>
|
||||
[DataField("maxCharges"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[AutoNetworkedField]
|
||||
[DataField, AutoNetworkedField, Access(Other = AccessPermissions.Read)]
|
||||
public int MaxCharges = 3;
|
||||
|
||||
/// <summary>
|
||||
/// The current number of charges
|
||||
/// Last time charges was changed. Used to derive current charges.
|
||||
/// </summary>
|
||||
[DataField("charges"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[AutoNetworkedField]
|
||||
public int Charges = 3;
|
||||
[DataField(customTypeSerializer:typeof(TimeOffsetSerializer)), AutoNetworkedField]
|
||||
public TimeSpan LastUpdate;
|
||||
}
|
||||
|
||||
@@ -1,103 +1,238 @@
|
||||
using Content.Shared.Actions.Events;
|
||||
using Content.Shared.Charges.Components;
|
||||
using Content.Shared.Examine;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Charges.Systems;
|
||||
|
||||
public abstract class SharedChargesSystem : EntitySystem
|
||||
{
|
||||
protected EntityQuery<LimitedChargesComponent> Query;
|
||||
[Dependency] protected readonly IGameTiming _timing = default!;
|
||||
|
||||
/*
|
||||
* Despite what a bunch of systems do you don't need to continuously tick linear number updates and can just derive it easily.
|
||||
*/
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Query = GetEntityQuery<LimitedChargesComponent>();
|
||||
|
||||
SubscribeLocalEvent<LimitedChargesComponent, ExaminedEvent>(OnExamine);
|
||||
|
||||
SubscribeLocalEvent<LimitedChargesComponent, ActionAttemptEvent>(OnChargesAttempt);
|
||||
SubscribeLocalEvent<LimitedChargesComponent, MapInitEvent>(OnChargesMapInit);
|
||||
SubscribeLocalEvent<LimitedChargesComponent, ActionPerformedEvent>(OnChargesPerformed);
|
||||
}
|
||||
|
||||
protected virtual void OnExamine(EntityUid uid, LimitedChargesComponent comp, ExaminedEvent args)
|
||||
private void OnExamine(EntityUid uid, LimitedChargesComponent comp, ExaminedEvent args)
|
||||
{
|
||||
if (!args.IsInDetailsRange)
|
||||
return;
|
||||
|
||||
using (args.PushGroup(nameof(LimitedChargesComponent)))
|
||||
var rechargeEnt = new Entity<LimitedChargesComponent?, AutoRechargeComponent?>(uid, comp, null);
|
||||
var charges = GetCurrentCharges(rechargeEnt);
|
||||
using var _ = args.PushGroup(nameof(LimitedChargesComponent));
|
||||
|
||||
args.PushMarkup(Loc.GetString("limited-charges-charges-remaining", ("charges", charges)));
|
||||
if (charges == comp.MaxCharges)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("limited-charges-charges-remaining", ("charges", comp.Charges)));
|
||||
if (comp.Charges == comp.MaxCharges)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("limited-charges-max-charges"));
|
||||
}
|
||||
args.PushMarkup(Loc.GetString("limited-charges-max-charges"));
|
||||
}
|
||||
|
||||
// only show the recharging info if it's not full
|
||||
if (charges == comp.MaxCharges || !Resolve(uid, ref rechargeEnt.Comp2, false))
|
||||
return;
|
||||
|
||||
var timeRemaining = GetNextRechargeTime(rechargeEnt);
|
||||
args.PushMarkup(Loc.GetString("limited-charges-recharging", ("seconds", timeRemaining.TotalSeconds.ToString("F1"))));
|
||||
}
|
||||
|
||||
private void OnChargesAttempt(Entity<LimitedChargesComponent> ent, ref ActionAttemptEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
|
||||
var charges = GetCurrentCharges((ent.Owner, ent.Comp, null));
|
||||
|
||||
if (charges <= 0)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to add a number of charges. If it over or underflows it will be clamped, wasting the extra charges.
|
||||
/// </summary>
|
||||
public virtual void AddCharges(EntityUid uid, int change, LimitedChargesComponent? comp = null)
|
||||
private void OnChargesPerformed(Entity<LimitedChargesComponent> ent, ref ActionPerformedEvent args)
|
||||
{
|
||||
if (!Query.Resolve(uid, ref comp, false))
|
||||
AddCharges((ent.Owner, ent.Comp), -1);
|
||||
}
|
||||
|
||||
private void OnChargesMapInit(Entity<LimitedChargesComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
// If nothing specified use max.
|
||||
if (ent.Comp.LastCharges == 0)
|
||||
{
|
||||
ent.Comp.LastCharges = ent.Comp.MaxCharges;
|
||||
}
|
||||
// If -1 used then we don't want any.
|
||||
else if (ent.Comp.LastCharges < 0)
|
||||
{
|
||||
ent.Comp.LastCharges = 0;
|
||||
}
|
||||
|
||||
ent.Comp.LastUpdate = _timing.CurTime;
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public bool HasCharges(Entity<LimitedChargesComponent?> action, int charges)
|
||||
{
|
||||
var current = GetCurrentCharges(action);
|
||||
|
||||
return current >= charges;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified charges. Does not reset the accumulator.
|
||||
/// </summary>
|
||||
public void AddCharges(Entity<LimitedChargesComponent?, AutoRechargeComponent?> action, int addCharges)
|
||||
{
|
||||
if (addCharges == 0)
|
||||
return;
|
||||
|
||||
var old = comp.Charges;
|
||||
comp.Charges = Math.Clamp(comp.Charges + change, 0, comp.MaxCharges);
|
||||
if (comp.Charges != old)
|
||||
Dirty(uid, comp);
|
||||
action.Comp1 ??= EnsureComp<LimitedChargesComponent>(action.Owner);
|
||||
|
||||
var lastCharges = GetCurrentCharges(action);
|
||||
var charges = lastCharges + addCharges;
|
||||
|
||||
if (lastCharges == charges)
|
||||
return;
|
||||
|
||||
// If we were at max then need to reset the timer.
|
||||
if (charges == action.Comp1.MaxCharges || lastCharges == action.Comp1.MaxCharges)
|
||||
{
|
||||
action.Comp1.LastUpdate = _timing.CurTime;
|
||||
action.Comp1.LastCharges = action.Comp1.MaxCharges;
|
||||
}
|
||||
// If it has auto-recharge then make up the difference.
|
||||
else if (Resolve(action.Owner, ref action.Comp2, false))
|
||||
{
|
||||
var duration = action.Comp2.RechargeDuration;
|
||||
var diff = (_timing.CurTime - action.Comp1.LastUpdate);
|
||||
var remainder = (int) (diff / duration);
|
||||
|
||||
action.Comp1.LastCharges += remainder;
|
||||
action.Comp1.LastUpdate += (remainder * duration);
|
||||
}
|
||||
|
||||
action.Comp1.LastCharges = Math.Clamp(action.Comp1.LastCharges + addCharges, 0, action.Comp1.MaxCharges);
|
||||
Dirty(action.Owner, action.Comp1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the limited charges component and returns true if there are no charges. Will return false if there is no limited charges component.
|
||||
/// </summary>
|
||||
public bool IsEmpty(EntityUid uid, LimitedChargesComponent? comp = null)
|
||||
public bool TryUseCharge(Entity<LimitedChargesComponent?> entity)
|
||||
{
|
||||
// can't be empty if there are no limited charges
|
||||
if (!Query.Resolve(uid, ref comp, false))
|
||||
return TryUseCharges(entity, 1);
|
||||
}
|
||||
|
||||
public bool TryUseCharges(Entity<LimitedChargesComponent?> entity, int amount)
|
||||
{
|
||||
var current = GetCurrentCharges(entity);
|
||||
|
||||
if (current < amount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return comp.Charges <= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses a single charge. Must check IsEmpty beforehand to prevent using with 0 charge.
|
||||
/// </summary>
|
||||
public void UseCharge(EntityUid uid, LimitedChargesComponent? comp = null)
|
||||
{
|
||||
AddCharges(uid, -1, comp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks IsEmpty and uses a charge if it isn't empty.
|
||||
/// </summary>
|
||||
public bool TryUseCharge(Entity<LimitedChargesComponent?> ent)
|
||||
{
|
||||
if (!Query.Resolve(ent, ref ent.Comp, false))
|
||||
return true;
|
||||
|
||||
if (IsEmpty(ent, ent.Comp))
|
||||
return false;
|
||||
|
||||
UseCharge(ent, ent.Comp);
|
||||
AddCharges(entity, -amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the limited charges component and returns true if the number of charges remaining is less than the specified value.
|
||||
/// Will return false if there is no limited charges component.
|
||||
/// </summary>
|
||||
public bool HasInsufficientCharges(EntityUid uid, int requiredCharges, LimitedChargesComponent? comp = null)
|
||||
[Pure]
|
||||
public bool IsEmpty(Entity<LimitedChargesComponent?> entity)
|
||||
{
|
||||
// can't be empty if there are no limited charges
|
||||
if (!Resolve(uid, ref comp, false))
|
||||
return false;
|
||||
|
||||
return comp.Charges < requiredCharges;
|
||||
return GetCurrentCharges(entity) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses up a specified number of charges. Must check HasInsufficentCharges beforehand to prevent using with insufficient remaining charges.
|
||||
/// Resets action charges to MaxCharges.
|
||||
/// </summary>
|
||||
public virtual void UseCharges(EntityUid uid, int chargesUsed, LimitedChargesComponent? comp = null)
|
||||
public void ResetCharges(Entity<LimitedChargesComponent?> action)
|
||||
{
|
||||
AddCharges(uid, -chargesUsed, comp);
|
||||
if (!Resolve(action.Owner, ref action.Comp, false))
|
||||
return;
|
||||
|
||||
var charges = GetCurrentCharges((action.Owner, action.Comp, null));
|
||||
|
||||
if (charges == action.Comp.MaxCharges)
|
||||
return;
|
||||
|
||||
action.Comp.LastCharges = action.Comp.MaxCharges;
|
||||
action.Comp.LastUpdate = _timing.CurTime;
|
||||
Dirty(action);
|
||||
}
|
||||
|
||||
public void SetCharges(Entity<LimitedChargesComponent?> action, int value)
|
||||
{
|
||||
action.Comp ??= EnsureComp<LimitedChargesComponent>(action.Owner);
|
||||
|
||||
var adjusted = Math.Clamp(value, 0, action.Comp.MaxCharges);
|
||||
|
||||
if (action.Comp.LastCharges == adjusted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
action.Comp.LastCharges = adjusted;
|
||||
action.Comp.LastUpdate = _timing.CurTime;
|
||||
Dirty(action);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The next time a charge will be considered to be filled.
|
||||
/// </summary>
|
||||
/// <returns>0 timespan if invalid or no charges to generate.</returns>
|
||||
[Pure]
|
||||
public TimeSpan GetNextRechargeTime(Entity<LimitedChargesComponent?, AutoRechargeComponent?> entity)
|
||||
{
|
||||
if (!Resolve(entity.Owner, ref entity.Comp1, ref entity.Comp2, false))
|
||||
{
|
||||
return TimeSpan.Zero;
|
||||
}
|
||||
|
||||
// Okay so essentially we need to get recharge time to full, then modulus that by the recharge timer which should be the next tick.
|
||||
var fullTime = ((entity.Comp1.MaxCharges - entity.Comp1.LastCharges) * entity.Comp2.RechargeDuration) + entity.Comp1.LastUpdate;
|
||||
var timeRemaining = fullTime - _timing.CurTime;
|
||||
|
||||
if (timeRemaining < TimeSpan.Zero)
|
||||
{
|
||||
return TimeSpan.Zero;
|
||||
}
|
||||
|
||||
var nextChargeTime = timeRemaining.TotalSeconds % entity.Comp2.RechargeDuration.TotalSeconds;
|
||||
return TimeSpan.FromSeconds(nextChargeTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Derives the current charges of an entity.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
public int GetCurrentCharges(Entity<LimitedChargesComponent?, AutoRechargeComponent?> entity)
|
||||
{
|
||||
if (!Resolve(entity.Owner, ref entity.Comp1, false))
|
||||
{
|
||||
// I'm all in favor of nullable ints however null-checking return args against comp nullability is dodgy
|
||||
// so we get this.
|
||||
return -1;
|
||||
}
|
||||
|
||||
var calculated = 0;
|
||||
|
||||
if (Resolve(entity.Owner, ref entity.Comp2, false) && entity.Comp2.RechargeDuration.TotalSeconds != 0.0)
|
||||
{
|
||||
calculated = (int)((_timing.CurTime - entity.Comp1.LastUpdate).TotalSeconds / entity.Comp2.RechargeDuration.TotalSeconds);
|
||||
}
|
||||
|
||||
return Math.Clamp(entity.Comp1.LastCharges + calculated,
|
||||
0,
|
||||
entity.Comp1.MaxCharges);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
{
|
||||
public sealed class ChemicalReactionSystem : EntitySystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Foam reaction protoId.
|
||||
/// </summary>
|
||||
public static readonly ProtoId<ReactionPrototype> FoamReaction = "Foam";
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of reactions that may occur when a solution is changed.
|
||||
/// </summary>
|
||||
|
||||
@@ -38,6 +38,10 @@ public sealed class ReactiveSystem : EntitySystem
|
||||
if (!TryComp(uid, out ReactiveComponent? reactive))
|
||||
return;
|
||||
|
||||
// custom event for bypassing reactivecomponent stuff
|
||||
var ev = new ReactionEntityEvent(method, proto, reagentQuantity, source);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
|
||||
// If we have a source solution, use the reagent quantity we have left. Otherwise, use the reaction volume specified.
|
||||
var args = new EntityEffectReagentArgs(uid, EntityManager, null, source, source?.GetReagentQuantity(reagentQuantity.Reagent) ?? reagentQuantity.Quantity, proto, method, 1f);
|
||||
|
||||
@@ -107,3 +111,11 @@ Touch,
|
||||
Injection,
|
||||
Ingestion,
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public readonly record struct ReactionEntityEvent(
|
||||
ReactionMethod Method,
|
||||
ReagentPrototype Reagent,
|
||||
ReagentQuantity ReagentQuantity,
|
||||
Solution? Source
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Frozen;
|
||||
using System.Linq;
|
||||
using Content.Shared.FixedPoint;
|
||||
using System.Text.Json.Serialization;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Body.Prototypes;
|
||||
@@ -7,14 +8,14 @@ using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.EntityEffects;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Nutrition;
|
||||
using Content.Shared.Prototypes;
|
||||
using Content.Shared.Slippery;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -99,11 +100,24 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
[DataField]
|
||||
public bool MetamorphicChangeColor { get; private set; } = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// If this reagent is part of a puddle is it slippery.
|
||||
/// If not null, makes something slippery. Also defines slippery interactions like stun time and launch mult.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool Slippery;
|
||||
public SlipperyEffectEntry? SlipData;
|
||||
|
||||
/// <summary>
|
||||
/// The speed at which the reagent evaporates over time.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public FixedPoint2 EvaporationSpeed = FixedPoint2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// If this reagent can be used to mop up other reagents.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool Absorbent = false;
|
||||
|
||||
/// <summary>
|
||||
/// How easily this reagent becomes fizzy when aggitated.
|
||||
@@ -119,6 +133,13 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
[DataField]
|
||||
public float Viscosity;
|
||||
|
||||
/// <summary>
|
||||
/// Linear Friction Multiplier for a reagent
|
||||
/// 0 - frictionless, 1 - no effect on friction
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float Friction = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Should this reagent work on the dead?
|
||||
/// </summary>
|
||||
@@ -206,7 +227,7 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
.ToDictionary(x => x.Key, x => x.Item2);
|
||||
if (proto.PlantMetabolisms.Count > 0)
|
||||
{
|
||||
PlantMetabolisms = new List<string> (proto.PlantMetabolisms
|
||||
PlantMetabolisms = new List<string>(proto.PlantMetabolisms
|
||||
.Select(x => x.GuidebookEffectDescription(prototype, entSys))
|
||||
.Where(x => x is not null)
|
||||
.Select(x => x!)
|
||||
|
||||
@@ -13,7 +13,13 @@ namespace Content.Shared.Climbing.Components
|
||||
/// <summary>
|
||||
/// The range from which this entity can be climbed.
|
||||
/// </summary>
|
||||
[DataField("range")] public float Range = SharedInteractionSystem.InteractionRange / 1.4f;
|
||||
[DataField] public float Range = SharedInteractionSystem.InteractionRange;
|
||||
|
||||
/// <summary>
|
||||
/// Can drag-drop / verb vaulting be done? Set to false if climbing is being handled manually.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool Vaultable = true;
|
||||
|
||||
/// <summary>
|
||||
/// The time it takes to climb onto the entity.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Shared.DoAfter;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
@@ -25,6 +26,12 @@ public sealed partial class ClimbingComponent : Component
|
||||
[AutoNetworkedField, DataField]
|
||||
public bool IsClimbing;
|
||||
|
||||
/// <summary>
|
||||
/// The Climbing DoAfter.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public DoAfterId? DoAfter;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the owner is being moved onto the climbed entity.
|
||||
/// </summary>
|
||||
|
||||
@@ -62,6 +62,7 @@ public sealed partial class ClimbSystem : VirtualController
|
||||
SubscribeLocalEvent<ClimbingComponent, ClimbDoAfterEvent>(OnDoAfter);
|
||||
SubscribeLocalEvent<ClimbingComponent, EndCollideEvent>(OnClimbEndCollide);
|
||||
SubscribeLocalEvent<ClimbingComponent, BuckledEvent>(OnBuckled);
|
||||
SubscribeLocalEvent<ClimbingComponent, EntGotInsertedIntoContainerMessage>(OnStored);
|
||||
|
||||
SubscribeLocalEvent<ClimbableComponent, CanDropTargetEvent>(OnCanDragDropOn);
|
||||
SubscribeLocalEvent<ClimbableComponent, GetVerbsEvent<AlternativeVerb>>(AddClimbableVerb);
|
||||
@@ -148,7 +149,7 @@ public sealed partial class ClimbSystem : VirtualController
|
||||
|
||||
private void OnCanDragDropOn(EntityUid uid, ClimbableComponent component, ref CanDropTargetEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
if (args.Handled || !component.Vaultable)
|
||||
return;
|
||||
|
||||
// If already climbing then don't show outlines.
|
||||
@@ -234,19 +235,33 @@ public sealed partial class ClimbSystem : VirtualController
|
||||
};
|
||||
|
||||
_audio.PlayPredicted(comp.StartClimbSound, climbable, user);
|
||||
return _doAfterSystem.TryStartDoAfter(args, out id);
|
||||
var success = _doAfterSystem.TryStartDoAfter(args, out id);
|
||||
|
||||
if (success)
|
||||
climbing.DoAfter = id;
|
||||
|
||||
return success;
|
||||
|
||||
}
|
||||
|
||||
private void OnDoAfter(EntityUid uid, ClimbingComponent component, ClimbDoAfterEvent args)
|
||||
{
|
||||
component.DoAfter = null;
|
||||
|
||||
if (args.Handled || args.Cancelled || args.Args.Target == null || args.Args.Used == null)
|
||||
return;
|
||||
|
||||
if (_containers.IsEntityInContainer(uid))
|
||||
{
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Climb(uid, args.Args.User, args.Args.Target.Value, climbing: component);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void Climb(EntityUid uid, EntityUid user, EntityUid climbable, bool silent = false, ClimbingComponent? climbing = null,
|
||||
public void Climb(EntityUid uid, EntityUid user, EntityUid climbable, bool silent = false, ClimbingComponent? climbing = null,
|
||||
PhysicsComponent? physics = null, FixturesComponent? fixtures = null, ClimbableComponent? comp = null)
|
||||
{
|
||||
if (!Resolve(uid, ref climbing, ref physics, ref fixtures, false))
|
||||
@@ -441,6 +456,12 @@ public sealed partial class ClimbSystem : VirtualController
|
||||
/// <param name="reason">The reason why it cant be dropped</param>
|
||||
public bool CanVault(ClimbableComponent component, EntityUid user, EntityUid target, out string reason)
|
||||
{
|
||||
if (!component.Vaultable)
|
||||
{
|
||||
reason = string.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_actionBlockerSystem.CanInteract(user, target))
|
||||
{
|
||||
reason = Loc.GetString("comp-climbable-cant-interact");
|
||||
@@ -520,7 +541,27 @@ public sealed partial class ClimbSystem : VirtualController
|
||||
|
||||
private void OnBuckled(EntityUid uid, ClimbingComponent component, ref BuckledEvent args)
|
||||
{
|
||||
StopClimb(uid, component);
|
||||
StopOrCancelClimb(uid, component);
|
||||
}
|
||||
|
||||
private void OnStored(EntityUid uid, ClimbingComponent component, ref EntGotInsertedIntoContainerMessage args)
|
||||
{
|
||||
StopOrCancelClimb(uid, component);
|
||||
}
|
||||
|
||||
private void StopOrCancelClimb(EntityUid uid, ClimbingComponent component)
|
||||
{
|
||||
if (component.IsClimbing)
|
||||
{
|
||||
StopClimb(uid, component);
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.DoAfter != null)
|
||||
{
|
||||
_doAfterSystem.Cancel(component.DoAfter);
|
||||
component.DoAfter = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGlassClimbed(EntityUid uid, GlassTableComponent component, ref ClimbedOnEvent args)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Clothing.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the changes to ClothingComponent.EquippedPrefix when toggled.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class ToggleClothingPrefixComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Clothing's EquippedPrefix when activated.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string? PrefixOn = "on";
|
||||
|
||||
/// <summary>
|
||||
/// Clothing's EquippedPrefix when deactivated.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string? PrefixOff;
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Strip.Components;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Clothing.EntitySystems;
|
||||
@@ -15,10 +13,8 @@ namespace Content.Shared.Clothing.EntitySystems;
|
||||
public abstract class ClothingSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedItemSystem _itemSys = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containerSys = default!;
|
||||
[Dependency] private readonly InventorySystem _invSystem = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
[Dependency] private readonly HideLayerClothingSystem _hideLayer = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -69,14 +65,14 @@ public abstract class ClothingSystem : EntitySystem
|
||||
if (!_invSystem.TryUnequip(userEnt, slotDef.Name, true, inventory: userEnt, checkDoafter: true))
|
||||
continue;
|
||||
|
||||
if (!_invSystem.TryEquip(userEnt, toEquipEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt, checkDoafter: true))
|
||||
if (!_invSystem.TryEquip(userEnt, toEquipEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt, checkDoafter: true, triggerHandContact: true))
|
||||
continue;
|
||||
|
||||
_handsSystem.PickupOrDrop(userEnt, slotEntity.Value, handsComp: userEnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_invSystem.TryEquip(userEnt, toEquipEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt, checkDoafter: true))
|
||||
if (!_invSystem.TryEquip(userEnt, toEquipEnt, slotDef.Name, true, inventory: userEnt, clothing: toEquipEnt, checkDoafter: true, triggerHandContact: true))
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -138,7 +134,7 @@ public abstract class ClothingSystem : EntitySystem
|
||||
{
|
||||
if (args.Handled || args.Cancelled || args.Target is not { } target)
|
||||
return;
|
||||
args.Handled = _invSystem.TryUnequip(args.User, target, args.Slot, clothing: ent.Comp, predicted: true, checkDoafter: false);
|
||||
args.Handled = _invSystem.TryUnequip(args.User, target, args.Slot, clothing: ent.Comp, predicted: true, checkDoafter: false, triggerHandContact: true);
|
||||
if (args.Handled)
|
||||
_handsSystem.TryPickup(args.User, ent);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ public sealed class HideLayerClothingSystem : EntitySystem
|
||||
if (!Resolve(clothing.Owner, ref clothing.Comp1, ref clothing.Comp2))
|
||||
return;
|
||||
|
||||
if (!Resolve(user.Owner, ref user.Comp))
|
||||
// logMissing: false, as this clothing might be getting equipped by a non-human.
|
||||
if (!Resolve(user.Owner, ref user.Comp, false))
|
||||
return;
|
||||
|
||||
hideLayers &= IsEnabled(clothing!);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Item.ItemToggle.Components;
|
||||
|
||||
namespace Content.Shared.Clothing.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// On toggle handles the changes to ItemComponent.HeldPrefix. <see cref="ToggleClothingPrefixComponent"/>.
|
||||
/// </summary>
|
||||
public sealed class ToggleClothingPrefixSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ClothingSystem _clothing = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ToggleClothingPrefixComponent, ItemToggledEvent>(OnToggled);
|
||||
}
|
||||
|
||||
private void OnToggled(Entity<ToggleClothingPrefixComponent> ent, ref ItemToggledEvent args)
|
||||
{
|
||||
_clothing.SetEquippedPrefix(ent, args.Activated ? ent.Comp.PrefixOn : ent.Comp.PrefixOff);
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public sealed class ToggleableClothingSystem : EntitySystem
|
||||
// This should maybe double check that the entity currently in the slot is actually the attached clothing, but
|
||||
// if its not, then something else has gone wrong already...
|
||||
if (component.Container != null && component.Container.ContainedEntity == null && component.ClothingUid != null)
|
||||
_inventorySystem.TryUnequip(args.Equipee, component.Slot, force: true);
|
||||
_inventorySystem.TryUnequip(args.Equipee, component.Slot, force: true, triggerHandContact: true);
|
||||
}
|
||||
|
||||
private void OnRemoveToggleable(EntityUid uid, ToggleableClothingComponent component, ComponentRemove args)
|
||||
@@ -248,7 +248,7 @@ public sealed class ToggleableClothingSystem : EntitySystem
|
||||
user, user);
|
||||
}
|
||||
else
|
||||
_inventorySystem.TryEquip(user, parent, component.ClothingUid.Value, component.Slot);
|
||||
_inventorySystem.TryEquip(user, parent, component.ClothingUid.Value, component.Slot, triggerHandContact: true);
|
||||
}
|
||||
|
||||
private void OnGetActions(EntityUid uid, ToggleableClothingComponent component, GetItemActionsEvent args)
|
||||
|
||||
@@ -14,12 +14,10 @@ namespace Content.Shared.Clothing;
|
||||
public sealed class SharedMagbootsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly AlertsSystem _alerts = default!;
|
||||
[Dependency] private readonly ClothingSystem _clothing = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
[Dependency] private readonly ItemToggleSystem _toggle = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
[Dependency] private readonly SharedGravitySystem _gravity = default!;
|
||||
[Dependency] private readonly SharedItemSystem _item = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -42,10 +40,6 @@ public sealed class SharedMagbootsSystem : EntitySystem
|
||||
{
|
||||
UpdateMagbootEffects(container.Owner, ent, args.Activated);
|
||||
}
|
||||
|
||||
var prefix = args.Activated ? "on" : null;
|
||||
_item.SetHeldPrefix(ent, prefix);
|
||||
_clothing.SetEquippedPrefix(ent, prefix);
|
||||
}
|
||||
|
||||
private void OnGotUnequipped(Entity<MagbootsComponent> ent, ref ClothingGotUnequippedEvent args)
|
||||
|
||||
@@ -38,7 +38,7 @@ public sealed class ClumsySystem : EntitySystem
|
||||
private void BeforeHyposprayEvent(Entity<ClumsyComponent> ent, ref SelfBeforeHyposprayInjectsEvent args)
|
||||
{
|
||||
// Clumsy people sometimes inject themselves! Apparently syringes are clumsy proof...
|
||||
|
||||
|
||||
// checks if ClumsyHypo is false, if so, skips.
|
||||
if (!ent.Comp.ClumsyHypo)
|
||||
return;
|
||||
@@ -54,7 +54,7 @@ public sealed class ClumsySystem : EntitySystem
|
||||
private void BeforeDefibrillatorZapsEvent(Entity<ClumsyComponent> ent, ref SelfBeforeDefibrillatorZapsEvent args)
|
||||
{
|
||||
// Clumsy people sometimes defib themselves!
|
||||
|
||||
|
||||
// checks if ClumsyDefib is false, if so, skips.
|
||||
if (!ent.Comp.ClumsyDefib)
|
||||
return;
|
||||
@@ -103,8 +103,7 @@ public sealed class ClumsySystem : EntitySystem
|
||||
// This event is called in shared, thats why it has all the extra prediction stuff.
|
||||
var rand = new System.Random((int)_timing.CurTick.Value);
|
||||
|
||||
// If someone is putting you on the table, always get past the guard.
|
||||
if (!_cfg.GetCVar(CCVars.GameTableBonk) && args.PuttingOnTable == ent.Owner && !rand.Prob(ent.Comp.ClumsyDefaultCheck))
|
||||
if (!_cfg.GetCVar(CCVars.GameTableBonk) && !rand.Prob(ent.Comp.ClumsyDefaultCheck))
|
||||
return;
|
||||
|
||||
HitHeadClumsy(ent, args.BeingClimbedOn);
|
||||
|
||||
17
Content.Shared/CombatMode/DisarmMalusComponent.cs
Normal file
17
Content.Shared/CombatMode/DisarmMalusComponent.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.CombatMode;
|
||||
|
||||
/// <summary>
|
||||
/// Applies a malus to disarm attempts against this item.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class DisarmMalusComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// So, disarm chances are a % chance represented as a value between 0 and 1.
|
||||
/// This default would be a 30% penalty to that.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float Malus = 0.3f;
|
||||
}
|
||||
@@ -1,31 +1,33 @@
|
||||
namespace Content.Shared.CombatMode
|
||||
namespace Content.Shared.CombatMode;
|
||||
|
||||
[ByRefEvent]
|
||||
public record struct DisarmedEvent(EntityUid Target, EntityUid Source, float PushProb)
|
||||
{
|
||||
public sealed class DisarmedEvent : HandledEntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The entity being disarmed.
|
||||
/// </summary>
|
||||
public EntityUid Target { get; init; }
|
||||
/// <summary>
|
||||
/// The entity being disarmed.
|
||||
/// </summary>
|
||||
public readonly EntityUid Target = Target;
|
||||
|
||||
/// <summary>
|
||||
/// The entity performing the disarm.
|
||||
/// </summary>
|
||||
public EntityUid Source { get; init; }
|
||||
/// <summary>
|
||||
/// The entity performing the disarm.
|
||||
/// </summary>
|
||||
public readonly EntityUid Source = Source;
|
||||
|
||||
/// <summary>
|
||||
/// Probability for push/knockdown.
|
||||
/// </summary>
|
||||
public float PushProbability { get; init; }
|
||||
/// <summary>
|
||||
/// Probability for push/knockdown.
|
||||
/// </summary>
|
||||
public readonly float PushProbability = PushProb;
|
||||
|
||||
/// <summary>
|
||||
/// Prefix for the popup message that will be displayed on a successful push.
|
||||
/// Should be set before returning.
|
||||
/// </summary>
|
||||
public string PopupPrefix { get; set; } = "";
|
||||
/// <summary>
|
||||
/// Prefix for the popup message that will be displayed on a successful push.
|
||||
/// Should be set before returning.
|
||||
/// </summary>
|
||||
public string PopupPrefix = "";
|
||||
|
||||
/// <summary>
|
||||
/// Whether the entity was successfully stunned from a shove.
|
||||
/// </summary>
|
||||
public bool IsStunned { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether the entity was successfully stunned from a shove.
|
||||
/// </summary>
|
||||
public bool IsStunned;
|
||||
|
||||
public bool Handled;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace Content.Shared.CombatMode;
|
||||
public abstract class SharedCombatModeSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly IGameTiming Timing = default!;
|
||||
[Dependency] private readonly INetManager _netMan = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly SharedMindSystem _mind = default!;
|
||||
@@ -46,14 +45,8 @@ public abstract class SharedCombatModeSystem : EntitySystem
|
||||
args.Handled = true;
|
||||
SetInCombatMode(uid, !component.IsInCombatMode, component);
|
||||
|
||||
// TODO better handling of predicted pop-ups.
|
||||
// This probably breaks if the client has prediction disabled.
|
||||
|
||||
if (!_netMan.IsClient || !Timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
var msg = component.IsInCombatMode ? "action-popup-combat-enabled" : "action-popup-combat-disabled";
|
||||
_popup.PopupEntity(Loc.GetString(msg), args.Performer, args.Performer);
|
||||
_popup.PopupClient(Loc.GetString(msg), args.Performer, args.Performer);
|
||||
}
|
||||
|
||||
public void SetCanDisarm(EntityUid entity, bool canDisarm, CombatModeComponent? component = null)
|
||||
|
||||
@@ -2,34 +2,38 @@ using System.Text.RegularExpressions;
|
||||
using Content.Shared.Tools;
|
||||
using Content.Shared.Tools.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.Configurable
|
||||
{
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
/// <summary>
|
||||
/// Configuration for mailing units.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If you want a more detailed description ask the original coder.
|
||||
/// </remarks>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class ConfigurationComponent : Component
|
||||
{
|
||||
[DataField("config")]
|
||||
/// <summary>
|
||||
/// Tags for mail unit routing.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public Dictionary<string, string?> Config = new();
|
||||
|
||||
[DataField("qualityNeeded", customTypeSerializer: typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
public string QualityNeeded = SharedToolSystem.PulseQuality;
|
||||
/// <summary>
|
||||
/// Quality to open up the configuration UI.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<ToolQualityPrototype> QualityNeeded = SharedToolSystem.PulseQuality;
|
||||
|
||||
[DataField("validation")]
|
||||
/// <summary>
|
||||
/// Validate tags in <see cref="Config"/>.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public Regex Validation = new("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled);
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ConfigurationBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public Dictionary<string, string?> Config { get; }
|
||||
|
||||
public ConfigurationBoundUserInterfaceState(Dictionary<string, string?> config)
|
||||
{
|
||||
Config = config;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Message data sent from client to server when the device configuration is updated.
|
||||
/// </summary>
|
||||
|
||||
77
Content.Shared/Configurable/SharedConfigurationSystem.cs
Normal file
77
Content.Shared/Configurable/SharedConfigurationSystem.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Tools.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using static Content.Shared.Configurable.ConfigurationComponent;
|
||||
|
||||
namespace Content.Shared.Configurable;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="ConfigurationComponent"/>
|
||||
/// </summary>
|
||||
public abstract class SharedConfigurationSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ConfigurationComponent, ConfigurationUpdatedMessage>(OnUpdate);
|
||||
SubscribeLocalEvent<ConfigurationComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<ConfigurationComponent, ContainerIsInsertingAttemptEvent>(OnInsert);
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, ConfigurationComponent component, InteractUsingEvent args)
|
||||
{
|
||||
// TODO use activatable ui system
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!_toolSystem.HasQuality(args.Used, component.QualityNeeded))
|
||||
return;
|
||||
|
||||
args.Handled = _uiSystem.TryOpenUi(uid, ConfigurationUiKey.Key, args.User);
|
||||
}
|
||||
|
||||
private void OnUpdate(EntityUid uid, ConfigurationComponent component, ConfigurationUpdatedMessage args)
|
||||
{
|
||||
foreach (var key in component.Config.Keys)
|
||||
{
|
||||
var value = args.Config.GetValueOrDefault(key);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(value) || component.Validation != null && !component.Validation.IsMatch(value))
|
||||
continue;
|
||||
|
||||
component.Config[key] = value;
|
||||
}
|
||||
|
||||
Dirty(uid, component);
|
||||
var updatedEvent = new ConfigurationUpdatedEvent(component);
|
||||
RaiseLocalEvent(uid, updatedEvent);
|
||||
|
||||
// TODO support float (spinbox) and enum (drop-down) configurations
|
||||
// TODO support verbs.
|
||||
}
|
||||
|
||||
private void OnInsert(EntityUid uid, ConfigurationComponent component, ContainerIsInsertingAttemptEvent args)
|
||||
{
|
||||
if (!_toolSystem.HasQuality(args.EntityUid, component.QualityNeeded))
|
||||
return;
|
||||
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sent when configuration values got changes
|
||||
/// </summary>
|
||||
public sealed class ConfigurationUpdatedEvent : EntityEventArgs
|
||||
{
|
||||
public ConfigurationComponent Configuration;
|
||||
|
||||
public ConfigurationUpdatedEvent(ConfigurationComponent configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,13 @@ namespace Content.Shared.Construction.Conditions
|
||||
|
||||
public bool Condition(EntityUid user, EntityCoordinates location, Direction direction)
|
||||
{
|
||||
var entManager = IoCManager.Resolve<IEntityManager>();
|
||||
var lookupSys = entManager.System<EntityLookupSystem>();
|
||||
|
||||
var result = false;
|
||||
|
||||
foreach (var entity in location.GetEntitiesInTile(LookupFlags.Approximate | LookupFlags.Static))
|
||||
|
||||
foreach (var entity in lookupSys.GetEntitiesIntersecting(location, LookupFlags.Approximate | LookupFlags.Static))
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().HasComponent<SharedCanBuildWindowOnTopComponent>(entity))
|
||||
result = true;
|
||||
|
||||
@@ -17,8 +17,9 @@ namespace Content.Shared.Construction.Conditions
|
||||
var entManager = IoCManager.Resolve<IEntityManager>();
|
||||
var sysMan = entManager.EntitySysManager;
|
||||
var tagSystem = sysMan.GetEntitySystem<TagSystem>();
|
||||
var lookupSys = sysMan.GetEntitySystem<EntityLookupSystem>();
|
||||
|
||||
foreach (var entity in location.GetEntitiesInTile(LookupFlags.Static))
|
||||
foreach (var entity in lookupSys.GetEntitiesIntersecting(location, LookupFlags.Static))
|
||||
{
|
||||
if (tagSystem.HasTag(entity, WindowTag))
|
||||
return false;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Content.Shared.Construction.Conditions
|
||||
// get blueprint and user position
|
||||
var transformSystem = entManager.System<SharedTransformSystem>();
|
||||
var userWorldPosition = transformSystem.GetWorldPosition(user);
|
||||
var objWorldPosition = location.ToMap(entManager, transformSystem).Position;
|
||||
var objWorldPosition = transformSystem.ToMapCoordinates(location).Position;
|
||||
|
||||
// find direction from user to blueprint
|
||||
var userToObject = (objWorldPosition - userWorldPosition);
|
||||
|
||||
@@ -277,10 +277,13 @@ public sealed partial class AnchorableSystem : EntitySystem
|
||||
return !attempt.Cancelled;
|
||||
}
|
||||
|
||||
private bool TileFree(EntityCoordinates coordinates, PhysicsComponent anchorBody)
|
||||
/// <summary>
|
||||
/// Returns true if no hard anchored entities exist on the coordinate tile that would collide with the provided physics body.
|
||||
/// </summary>
|
||||
public bool TileFree(EntityCoordinates coordinates, PhysicsComponent anchorBody)
|
||||
{
|
||||
// Probably ignore CanCollide on the anchoring body?
|
||||
var gridUid = coordinates.GetGridUid(EntityManager);
|
||||
var gridUid = _transformSystem.GetGrid(coordinates);
|
||||
|
||||
if (!TryComp<MapGridComponent>(gridUid, out var grid))
|
||||
return false;
|
||||
@@ -329,7 +332,7 @@ public sealed partial class AnchorableSystem : EntitySystem
|
||||
|
||||
public bool AnyUnstackablesAnchoredAt(EntityCoordinates location)
|
||||
{
|
||||
var gridUid = location.GetGridUid(EntityManager);
|
||||
var gridUid = _transformSystem.GetGrid(location);
|
||||
|
||||
if (!TryComp<MapGridComponent>(gridUid, out var grid))
|
||||
return false;
|
||||
|
||||
@@ -49,13 +49,11 @@ public sealed class ContainerFillSerializer : ITypeValidator<Dictionary<string,
|
||||
|
||||
foreach (var (key, val) in node.Children)
|
||||
{
|
||||
var keyVal = serializationManager.ValidateNode<string>(key, context);
|
||||
|
||||
var listVal = (val is SequenceDataNode seq)
|
||||
? ListSerializer.Validate(serializationManager, seq, dependencies, context)
|
||||
: new ErrorNode(val, "ContainerFillComponent prototypes must be a sequence/list");
|
||||
|
||||
mapping.Add(keyVal, listVal);
|
||||
mapping.Add(new ValidatedValueNode(node.GetKeyNode(key)), listVal);
|
||||
}
|
||||
|
||||
return new ValidatedMappingNode(mapping);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Content.Shared.Containers;
|
||||
|
||||
/// <summary>
|
||||
/// Sent before the insertion is made.
|
||||
/// Allows preventing the insertion if any system on the entity should need to.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct BeforeThrowInsertEvent(EntityUid ThrownEntity, bool Cancelled = false);
|
||||
@@ -84,26 +84,21 @@ public sealed class ContrabandSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
String carryingMessage;
|
||||
// either its fully restricted, you have no departments, or your departments dont intersect with the restricted departments
|
||||
// if it is fully restricted, you're department-less, or your department isn't in the allowed list, you cannot carry it. Otherwise, you can.
|
||||
var carryingMessage = Loc.GetString("contraband-examine-text-avoid-carrying-around");
|
||||
var iconTexture = "/Textures/Interface/VerbIcons/lock-red.svg.192dpi.png";
|
||||
if (departments.Intersect(component.AllowedDepartments).Any()
|
||||
|| jobs.Contains(jobId))
|
||||
{
|
||||
carryingMessage = Loc.GetString("contraband-examine-text-in-the-clear");
|
||||
iconTexture = "/Textures/Interface/VerbIcons/unlock-green.svg.192dpi.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise fine to use :tm:
|
||||
carryingMessage = Loc.GetString("contraband-examine-text-avoid-carrying-around");
|
||||
}
|
||||
|
||||
var examineMarkup = GetContrabandExamine(departmentExamineMessage, carryingMessage);
|
||||
_examine.AddDetailedExamineVerb(args,
|
||||
_examine.AddHoverExamineVerb(args,
|
||||
component,
|
||||
examineMarkup,
|
||||
Loc.GetString("contraband-examinable-verb-text"),
|
||||
"/Textures/Interface/VerbIcons/lock.svg.192dpi.png",
|
||||
Loc.GetString("contraband-examinable-verb-message"));
|
||||
examineMarkup.ToMarkup(),
|
||||
iconTexture);
|
||||
}
|
||||
|
||||
private FormattedMessage GetContrabandExamine(String deptMessage, String carryMessage)
|
||||
|
||||
@@ -381,7 +381,8 @@ namespace Content.Shared.Cuffs
|
||||
_popup.PopupClient(Loc.GetString("handcuff-component-cuff-interrupt-message",
|
||||
("targetName", Identity.Name(target, EntityManager, user))), user, user);
|
||||
_popup.PopupClient(Loc.GetString("handcuff-component-cuff-interrupt-other-message",
|
||||
("otherName", Identity.Name(user, EntityManager, target))), target, target);
|
||||
("otherName", Identity.Name(user, EntityManager, target)),
|
||||
("otherEnt", user)), target, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -723,8 +724,8 @@ namespace Content.Shared.Cuffs
|
||||
// if combat mode is on, shove the person.
|
||||
if (_combatMode.IsInCombatMode(user) && target != user && user != null)
|
||||
{
|
||||
var eventArgs = new DisarmedEvent { Target = target, Source = user.Value, PushProbability = 1};
|
||||
RaiseLocalEvent(target, eventArgs);
|
||||
var eventArgs = new DisarmedEvent(target, user.Value, 1f);
|
||||
RaiseLocalEvent(target, ref eventArgs);
|
||||
shoved = true;
|
||||
}
|
||||
|
||||
|
||||
33
Content.Shared/Damage/Components/DamagePopupComponent.cs
Normal file
33
Content.Shared/Damage/Components/DamagePopupComponent.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Content.Shared.Damage.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Damage.Components;
|
||||
|
||||
/// <summary>
|
||||
/// An entity with this component will show a popup indicating the amount of damage taken.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(DamagePopupSystem))]
|
||||
public sealed partial class DamagePopupComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Bool that will be used to determine if the popup type can be changed with a left click.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool AllowTypeChange;
|
||||
|
||||
/// <summary>
|
||||
/// Enum that will be used to determine the type of damage popup displayed.
|
||||
/// </summary>
|
||||
[DataField("damagePopupType"), AutoNetworkedField]
|
||||
public DamagePopupType Type = DamagePopupType.Combined;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DamagePopupType : byte
|
||||
{
|
||||
Combined,
|
||||
Total,
|
||||
Delta,
|
||||
Hit,
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
using Content.Shared.Damage.Systems;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Damage.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Component that provides entities with stamina resistance.
|
||||
/// By default this is applied when worn, but to solely protect the entity itself and
|
||||
/// not the wearer use <c>worn: false</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is desirable over just using damage modifier sets, given that equipment like bomb-suits need to
|
||||
/// significantly reduce the damage, but shouldn't be silly overpowered in regular combat.
|
||||
/// </remarks>
|
||||
[NetworkedComponent, RegisterComponent, AutoGenerateComponentState]
|
||||
public sealed partial class StaminaResistanceComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The stamina resistance coefficient, This fraction is multiplied into the total resistance.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float DamageCoefficient = 1;
|
||||
|
||||
/// <summary>
|
||||
/// When true, resistances will be applied to the entity wearing this item.
|
||||
/// When false, only this entity will get the resistance.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool Worn = true;
|
||||
|
||||
/// <summary>
|
||||
/// Examine string for stamina resistance.
|
||||
/// Passed <c>value</c> from 0 to 100.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public LocId Examine = "stamina-resistance-coefficient-value";
|
||||
}
|
||||
12
Content.Shared/Damage/Events/BeforeStaminaDamageEvent.cs
Normal file
12
Content.Shared/Damage/Events/BeforeStaminaDamageEvent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Content.Shared.Inventory;
|
||||
|
||||
namespace Content.Shared.Damage.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised before stamina damage is dealt to allow other systems to cancel or modify it.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct BeforeStaminaDamageEvent(float Value, bool Cancelled = false) : IInventoryRelayEvent
|
||||
{
|
||||
SlotFlags IInventoryRelayEvent.TargetSlots => ~SlotFlags.POCKET;
|
||||
}
|
||||
48
Content.Shared/Damage/Systems/DamagePopupSystem.cs
Normal file
48
Content.Shared/Damage/Systems/DamagePopupSystem.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
|
||||
namespace Content.Shared.Damage.Systems;
|
||||
|
||||
public sealed class DamagePopupSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<DamagePopupComponent, DamageChangedEvent>(OnDamageChange);
|
||||
SubscribeLocalEvent<DamagePopupComponent, InteractHandEvent>(OnInteractHand);
|
||||
}
|
||||
|
||||
private void OnDamageChange(Entity<DamagePopupComponent> ent, ref DamageChangedEvent args)
|
||||
{
|
||||
if (args.DamageDelta != null)
|
||||
{
|
||||
var damageTotal = args.Damageable.TotalDamage;
|
||||
var damageDelta = args.DamageDelta.GetTotal();
|
||||
|
||||
var msg = ent.Comp.Type switch
|
||||
{
|
||||
DamagePopupType.Delta => damageDelta.ToString(),
|
||||
DamagePopupType.Total => damageTotal.ToString(),
|
||||
DamagePopupType.Combined => damageDelta + " | " + damageTotal,
|
||||
DamagePopupType.Hit => "!",
|
||||
_ => "Invalid type",
|
||||
};
|
||||
|
||||
_popupSystem.PopupPredicted(msg, ent.Owner, args.Origin);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractHand(Entity<DamagePopupComponent> ent, ref InteractHandEvent args)
|
||||
{
|
||||
if (ent.Comp.AllowTypeChange)
|
||||
{
|
||||
var next = (DamagePopupType)(((int)ent.Comp.Type + 1) % Enum.GetValues<DamagePopupType>().Length);
|
||||
ent.Comp.Type = next;
|
||||
Dirty(ent);
|
||||
_popupSystem.PopupPredicted(Loc.GetString("damage-popup-component-switched", ("setting", ent.Comp.Type)), ent.Owner, args.User);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -329,7 +329,7 @@ namespace Content.Shared.Damage
|
||||
damage.DamageDict.Add(typeId, damageValue);
|
||||
}
|
||||
|
||||
TryChangeDamage(uid, damage, interruptsDoAfters: false);
|
||||
TryChangeDamage(uid, damage, interruptsDoAfters: false, origin: args.Origin);
|
||||
}
|
||||
|
||||
private void OnRejuvenate(EntityUid uid, DamageableComponent component, RejuvenateEvent args)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Damage.Events;
|
||||
using Content.Shared.Rejuvenate;
|
||||
using Content.Shared.Slippery;
|
||||
using Content.Shared.StatusEffect;
|
||||
|
||||
38
Content.Shared/Damage/Systems/StaminaSystem.Resistance.cs
Normal file
38
Content.Shared/Damage/Systems/StaminaSystem.Resistance.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Content.Shared.Armor;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Damage.Events;
|
||||
using Content.Shared.Inventory;
|
||||
|
||||
namespace Content.Shared.Damage.Systems;
|
||||
|
||||
public sealed partial class StaminaSystem
|
||||
{
|
||||
private void InitializeResistance()
|
||||
{
|
||||
SubscribeLocalEvent<StaminaResistanceComponent, BeforeStaminaDamageEvent>(OnGetResistance);
|
||||
SubscribeLocalEvent<StaminaResistanceComponent, InventoryRelayedEvent<BeforeStaminaDamageEvent>>(RelayedResistance);
|
||||
SubscribeLocalEvent<StaminaResistanceComponent, ArmorExamineEvent>(OnArmorExamine);
|
||||
}
|
||||
|
||||
private void OnGetResistance(Entity<StaminaResistanceComponent> ent, ref BeforeStaminaDamageEvent args)
|
||||
{
|
||||
args.Value *= ent.Comp.DamageCoefficient;
|
||||
}
|
||||
|
||||
private void RelayedResistance(Entity<StaminaResistanceComponent> ent, ref InventoryRelayedEvent<BeforeStaminaDamageEvent> args)
|
||||
{
|
||||
if (ent.Comp.Worn)
|
||||
OnGetResistance(ent, ref args.Args);
|
||||
}
|
||||
|
||||
private void OnArmorExamine(Entity<StaminaResistanceComponent> ent, ref ArmorExamineEvent args)
|
||||
{
|
||||
var value = MathF.Round((1f - ent.Comp.DamageCoefficient) * 100, 1);
|
||||
|
||||
if (value == 0)
|
||||
return;
|
||||
|
||||
args.Msg.PushNewline();
|
||||
args.Msg.AddMarkupOrThrow(Loc.GetString(ent.Comp.Examine, ("value", value)));
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ public sealed partial class StaminaSystem : EntitySystem
|
||||
base.Initialize();
|
||||
|
||||
InitializeModifier();
|
||||
InitializeResistance();
|
||||
|
||||
SubscribeLocalEvent<StaminaComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<StaminaComponent, ComponentShutdown>(OnShutdown);
|
||||
@@ -118,7 +119,7 @@ public sealed partial class StaminaSystem : EntitySystem
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void OnDisarmed(EntityUid uid, StaminaComponent component, DisarmedEvent args)
|
||||
private void OnDisarmed(EntityUid uid, StaminaComponent component, ref DisarmedEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
@@ -240,7 +241,7 @@ public sealed partial class StaminaSystem : EntitySystem
|
||||
}
|
||||
|
||||
public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? component = null,
|
||||
EntityUid? source = null, EntityUid? with = null, bool visual = true, SoundSpecifier? sound = null)
|
||||
EntityUid? source = null, EntityUid? with = null, bool visual = true, SoundSpecifier? sound = null, bool ignoreResist = false)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false))
|
||||
return;
|
||||
@@ -250,6 +251,12 @@ public sealed partial class StaminaSystem : EntitySystem
|
||||
if (ev.Cancelled)
|
||||
return;
|
||||
|
||||
// Allow stamina resistance to be applied.
|
||||
if (!ignoreResist)
|
||||
{
|
||||
value = ev.Value;
|
||||
}
|
||||
|
||||
value = UniversalStaminaDamageModifier * value;
|
||||
|
||||
// Have we already reached the point of max stamina damage?
|
||||
@@ -402,9 +409,3 @@ public sealed partial class StaminaSystem : EntitySystem
|
||||
_adminLogger.Add(LogType.Stamina, LogImpact.Low, $"{ToPrettyString(uid):user} recovered from stamina crit");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised before stamina damage is dealt to allow other systems to cancel it.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct BeforeStaminaDamageEvent(float Value, bool Cancelled = false);
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Content.Shared.Decals
|
||||
IDependencyCollection dependencies, SerializationHookContext hookCtx, ISerializationContext? context = null,
|
||||
ISerializationManager.InstantiationDelegate<DecalGridChunkCollection>? _ = default)
|
||||
{
|
||||
node.TryGetValue(new ValueDataNode("version"), out var versionNode);
|
||||
node.TryGetValue("version", out var versionNode);
|
||||
var version = ((ValueDataNode?) versionNode)?.AsInt() ?? 1;
|
||||
Dictionary<Vector2i, DecalChunk> dictionary;
|
||||
uint nextIndex = 0;
|
||||
@@ -49,7 +49,7 @@ namespace Content.Shared.Decals
|
||||
|
||||
foreach (var (decalUidNode, decalData) in deckNodes)
|
||||
{
|
||||
var dUid = serializationManager.Read<uint>(decalUidNode, hookCtx, context);
|
||||
var dUid = uint.Parse(decalUidNode, CultureInfo.InvariantCulture);
|
||||
var coords = serializationManager.Read<Vector2>(decalData, hookCtx, context);
|
||||
|
||||
var chunkOrigin = SharedMapSystem.GetChunkIndices(coords, SharedDecalSystem.ChunkSize);
|
||||
@@ -132,7 +132,7 @@ namespace Content.Shared.Decals
|
||||
{
|
||||
var decal = decalLookup[uid];
|
||||
// Inline coordinates
|
||||
decks.Add(serializationManager.WriteValue(uid, alwaysWrite, context), serializationManager.WriteValue(decal.Coordinates, alwaysWrite, context));
|
||||
decks.Add(uid.ToString(), serializationManager.WriteValue(decal.Coordinates, alwaysWrite, context));
|
||||
}
|
||||
|
||||
lookupNode.Add("decals", decks);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Content.Shared.Cargo.Prototypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Delivery;
|
||||
|
||||
@@ -23,10 +25,16 @@ public sealed partial class DeliveryComponent : Component
|
||||
public bool IsLocked = true;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of spesos that gets added to the station bank account on unlock.
|
||||
/// The base amount of spesos that gets added to the station bank account on unlock.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public int SpesoReward = 500;
|
||||
public int BaseSpesoReward = 500;
|
||||
|
||||
/// <summary>
|
||||
/// The base amount of spesos that will be removed from the station bank account on a penalized delivery
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public int BaseSpesoPenalty = 250;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the recipient of this delivery.
|
||||
@@ -48,6 +56,19 @@ public sealed partial class DeliveryComponent : Component
|
||||
[DataField, AutoNetworkedField]
|
||||
public EntityUid? RecipientStation;
|
||||
|
||||
/// <summary>
|
||||
/// The bank account ID of the account to subtract funds from in case of penalization
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public ProtoId<CargoAccountPrototype> PenaltyBankAccount = "Cargo";
|
||||
|
||||
/// <summary>
|
||||
/// Whether this delivery has already received a penalty.
|
||||
/// Used to avoid getting penalized several times.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool WasPenalized;
|
||||
|
||||
/// <summary>
|
||||
/// The sound to play when the delivery is unlocked.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
using Content.Shared.EntityTable.EntitySelectors;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Delivery;
|
||||
|
||||
/// <summary>
|
||||
/// Used to mark entities that are valid for spawning deliveries on.
|
||||
/// If this requires power, it needs to be powered to count as a valid spawner.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class DeliverySpawnerComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
@@ -18,9 +16,28 @@ public sealed partial class DeliverySpawnerComponent : Component
|
||||
[DataField(required: true)]
|
||||
public EntityTableSelector Table = default!;
|
||||
|
||||
/// <summary>
|
||||
/// The max amount of deliveries this spawner can hold at a time.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public int MaxContainedDeliveryAmount = 20;
|
||||
|
||||
/// <summary>
|
||||
/// The currently held amount of deliveries.
|
||||
/// They are stored as an int and only spawned on use, as to not create additional entities without the need to.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public int ContainedDeliveryAmount;
|
||||
|
||||
/// <summary>
|
||||
/// The sound to play when the spawner spawns a delivery.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier? SpawnSound = new SoundCollectionSpecifier("DeliverySpawnSounds", AudioParams.Default.WithVolume(-7));
|
||||
|
||||
/// <summary>
|
||||
/// The sound to play when a spawner is opened, and spills all the deliveries out.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier? OpenSound = new SoundCollectionSpecifier("storageRustle");
|
||||
}
|
||||
|
||||
@@ -13,3 +13,9 @@ public enum DeliveryVisuals : byte
|
||||
IsPriorityInactive,
|
||||
JobIcon,
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DeliverySpawnerVisuals : byte
|
||||
{
|
||||
Contents,
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.NameModifier.EntitySystems;
|
||||
using Content.Shared.Objectives.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Content.Shared.Tag;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
@@ -38,12 +39,17 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<DeliveryComponent, ExaminedEvent>(OnExamine);
|
||||
SubscribeLocalEvent<DeliveryComponent, ExaminedEvent>(OnDeliveryExamine);
|
||||
SubscribeLocalEvent<DeliveryComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<DeliveryComponent, GetVerbsEvent<AlternativeVerb>>(OnGetVerbs);
|
||||
SubscribeLocalEvent<DeliveryComponent, GetVerbsEvent<AlternativeVerb>>(OnGetDeliveryVerbs);
|
||||
SubscribeLocalEvent<DeliveryComponent, AttemptSimpleToolUseEvent>(OnAttemptSimpleToolUse);
|
||||
SubscribeLocalEvent<DeliveryComponent, SimpleToolDoAfterEvent>(OnSimpleToolUse);
|
||||
|
||||
SubscribeLocalEvent<DeliverySpawnerComponent, ExaminedEvent>(OnSpawnerExamine);
|
||||
SubscribeLocalEvent<DeliverySpawnerComponent, GetVerbsEvent<AlternativeVerb>>(OnGetSpawnerVerbs);
|
||||
}
|
||||
|
||||
private void OnExamine(Entity<DeliveryComponent> ent, ref ExaminedEvent args)
|
||||
private void OnDeliveryExamine(Entity<DeliveryComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
var jobTitle = ent.Comp.RecipientJobTitle ?? Loc.GetString("delivery-recipient-no-job");
|
||||
var recipientName = ent.Comp.RecipientName ?? Loc.GetString("delivery-recipient-no-name");
|
||||
@@ -56,6 +62,11 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
args.PushText(Loc.GetString("delivery-recipient-examine", ("recipient", recipientName), ("job", jobTitle)));
|
||||
}
|
||||
|
||||
private void OnSpawnerExamine(Entity<DeliverySpawnerComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("delivery-teleporter-amount-examine", ("amount", ent.Comp.ContainedDeliveryAmount)), 50);
|
||||
}
|
||||
|
||||
private void OnUseInHand(Entity<DeliveryComponent> ent, ref UseInHandEvent args)
|
||||
{
|
||||
args.Handled = true;
|
||||
@@ -69,7 +80,7 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
OpenDelivery(ent, args.User);
|
||||
}
|
||||
|
||||
private void OnGetVerbs(Entity<DeliveryComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
|
||||
private void OnGetDeliveryVerbs(Entity<DeliveryComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null || ent.Comp.IsOpened)
|
||||
return;
|
||||
@@ -92,33 +103,83 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
});
|
||||
}
|
||||
|
||||
private bool TryUnlockDelivery(Entity<DeliveryComponent> ent, EntityUid user, bool rewardMoney = true)
|
||||
|
||||
private void OnAttemptSimpleToolUse(Entity<DeliveryComponent> ent, ref AttemptSimpleToolUseEvent args)
|
||||
{
|
||||
if (ent.Comp.IsOpened || !ent.Comp.IsLocked)
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnSimpleToolUse(Entity<DeliveryComponent> ent, ref SimpleToolDoAfterEvent args)
|
||||
{
|
||||
if (ent.Comp.IsOpened || args.Cancelled)
|
||||
return;
|
||||
|
||||
HandlePenalty(ent);
|
||||
|
||||
TryUnlockDelivery(ent, args.User, false, true);
|
||||
OpenDelivery(ent, args.User, false, true);
|
||||
}
|
||||
|
||||
private void OnGetSpawnerVerbs(Entity<DeliverySpawnerComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
|
||||
return;
|
||||
|
||||
var user = args.User;
|
||||
|
||||
args.Verbs.Add(new AlternativeVerb()
|
||||
{
|
||||
Act = () =>
|
||||
{
|
||||
_audio.PlayPredicted(ent.Comp.OpenSound, ent.Owner, user);
|
||||
|
||||
if(ent.Comp.ContainedDeliveryAmount == 0)
|
||||
{
|
||||
_popup.PopupPredicted(Loc.GetString("delivery-teleporter-empty", ("entity", ent)), null, ent, user);
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnDeliveries(ent.Owner);
|
||||
|
||||
UpdateDeliverySpawnerVisuals(ent, ent.Comp.ContainedDeliveryAmount);
|
||||
},
|
||||
Text = Loc.GetString("delivery-teleporter-empty-verb"),
|
||||
});
|
||||
}
|
||||
|
||||
private bool TryUnlockDelivery(Entity<DeliveryComponent> ent, EntityUid user, bool rewardMoney = true, bool force = false)
|
||||
{
|
||||
// Check fingerprint access if there is a reader on the mail
|
||||
if (TryComp<FingerprintReaderComponent>(ent, out var reader) && !_fingerprintReader.IsAllowed((ent, reader), user))
|
||||
if (!force && TryComp<FingerprintReaderComponent>(ent, out var reader) && !_fingerprintReader.IsAllowed((ent, reader), user))
|
||||
return false;
|
||||
|
||||
var deliveryName = _nameModifier.GetBaseName(ent.Owner);
|
||||
|
||||
_audio.PlayPredicted(ent.Comp.UnlockSound, user, user);
|
||||
if (!force)
|
||||
_audio.PlayPredicted(ent.Comp.UnlockSound, user, user);
|
||||
|
||||
ent.Comp.IsLocked = false;
|
||||
UpdateAntiTamperVisuals(ent, ent.Comp.IsLocked);
|
||||
|
||||
DirtyField(ent, ent.Comp, nameof(DeliveryComponent.IsLocked));
|
||||
|
||||
RemCompDeferred<SimpleToolUsageComponent>(ent); // we don't want unlocked mail to still be cuttable
|
||||
|
||||
var ev = new DeliveryUnlockedEvent(user);
|
||||
RaiseLocalEvent(ent, ref ev);
|
||||
|
||||
if (rewardMoney)
|
||||
GrantSpesoReward(ent.AsNullable());
|
||||
|
||||
_popup.PopupPredicted(Loc.GetString("delivery-unlocked-self", ("delivery", deliveryName)),
|
||||
Loc.GetString("delivery-unlocked-others", ("delivery", deliveryName), ("recipient", Identity.Name(user, EntityManager)), ("possadj", user)), user, user);
|
||||
if (!force)
|
||||
_popup.PopupPredicted(Loc.GetString("delivery-unlocked-self", ("delivery", deliveryName)),
|
||||
Loc.GetString("delivery-unlocked-others", ("delivery", deliveryName), ("recipient", Identity.Name(user, EntityManager)), ("possadj", user)), user, user);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OpenDelivery(Entity<DeliveryComponent> ent, EntityUid user, bool attemptPickup = true)
|
||||
private void OpenDelivery(Entity<DeliveryComponent> ent, EntityUid user, bool attemptPickup = true, bool force = false)
|
||||
{
|
||||
var deliveryName = _nameModifier.GetBaseName(ent.Owner);
|
||||
|
||||
@@ -135,12 +196,13 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
|
||||
_tag.AddTags(ent, TrashTag, RecyclableTag);
|
||||
EnsureComp<SpaceGarbageComponent>(ent);
|
||||
RemComp<StealTargetComponent>(ent); // opened mail should not count for the objective
|
||||
RemCompDeferred<StealTargetComponent>(ent); // opened mail should not count for the objective
|
||||
|
||||
DirtyField(ent.Owner, ent.Comp, nameof(DeliveryComponent.IsOpened));
|
||||
|
||||
_popup.PopupPredicted(Loc.GetString("delivery-opened-self", ("delivery", deliveryName)),
|
||||
Loc.GetString("delivery-opened-others", ("delivery", deliveryName), ("recipient", Identity.Name(user, EntityManager)), ("possadj", user)), user, user);
|
||||
if (!force)
|
||||
_popup.PopupPredicted(Loc.GetString("delivery-opened-self", ("delivery", deliveryName)),
|
||||
Loc.GetString("delivery-opened-others", ("delivery", deliveryName), ("recipient", Identity.Name(user, EntityManager)), ("possadj", user)), user, user);
|
||||
|
||||
if (!_container.TryGetContainer(ent, ent.Comp.Container, out var container))
|
||||
return;
|
||||
@@ -154,7 +216,7 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
}
|
||||
else
|
||||
{
|
||||
_container.EmptyContainer(container, true, Transform(ent.Owner).Coordinates);
|
||||
_container.EmptyContainer(container, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +230,26 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
_appearance.SetData(uid, DeliveryVisuals.IsPriority, false);
|
||||
}
|
||||
|
||||
protected void UpdateDeliverySpawnerVisuals(EntityUid uid, int contents)
|
||||
{
|
||||
_appearance.SetData(uid, DeliverySpawnerVisuals.Contents, contents > 0);
|
||||
}
|
||||
|
||||
protected virtual void GrantSpesoReward(Entity<DeliveryComponent?> ent) { }
|
||||
|
||||
protected virtual void HandlePenalty(Entity<DeliveryComponent> ent, string? reason = null) { }
|
||||
|
||||
protected virtual void SpawnDeliveries(Entity<DeliverySpawnerComponent?> ent) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to gather the multiplier from all different delivery components.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct GetDeliveryMultiplierEvent(float Multiplier)
|
||||
{
|
||||
// we can't use an optional parameter because the default parameterless constructor defaults everything
|
||||
public GetDeliveryMultiplierEvent() : this(1.0f) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
using Content.Shared.DeviceNetwork.Systems;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.DeviceNetwork.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[Access(typeof(SharedDeviceNetworkSystem), typeof(DeviceNet))]
|
||||
public sealed partial class DeviceNetworkComponent : Component
|
||||
{
|
||||
public enum DeviceNetIdDefaults
|
||||
{
|
||||
Private,
|
||||
Wired,
|
||||
Wireless,
|
||||
Apc,
|
||||
AtmosDevices,
|
||||
Reserved = 100,
|
||||
// Ids outside this enum may exist
|
||||
// This exists to let yml use nice names instead of numbers
|
||||
}
|
||||
|
||||
[DataField("deviceNetId")]
|
||||
public DeviceNetIdDefaults NetIdEnum { get; set; }
|
||||
|
||||
public int DeviceNetId => (int) NetIdEnum;
|
||||
|
||||
/// <summary>
|
||||
/// The frequency that this device is listening on.
|
||||
/// </summary>
|
||||
[DataField("receiveFrequency")]
|
||||
public uint? ReceiveFrequency;
|
||||
|
||||
/// <summary>
|
||||
/// frequency prototype. Used to select a default frequency to listen to on. Used when the map is
|
||||
/// initialized.
|
||||
/// </summary>
|
||||
[DataField("receiveFrequencyId", customTypeSerializer: typeof(PrototypeIdSerializer<DeviceFrequencyPrototype>))]
|
||||
public string? ReceiveFrequencyId;
|
||||
|
||||
/// <summary>
|
||||
/// The frequency that this device going to try transmit on.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("transmitFrequency")]
|
||||
public uint? TransmitFrequency;
|
||||
|
||||
/// <summary>
|
||||
/// frequency prototype. Used to select a default frequency to transmit on. Used when the map is
|
||||
/// initialized.
|
||||
/// </summary>
|
||||
[DataField("transmitFrequencyId", customTypeSerializer: typeof(PrototypeIdSerializer<DeviceFrequencyPrototype>))]
|
||||
public string? TransmitFrequencyId;
|
||||
|
||||
/// <summary>
|
||||
/// The address of the device, either on the network it is currently connected to or whatever address it
|
||||
/// most recently used.
|
||||
/// </summary>
|
||||
[DataField("address")]
|
||||
public string Address = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the address was customized and should be preserved across networks. If false, a randomly
|
||||
/// generated address will be created whenever this device connects to a network.
|
||||
/// </summary>
|
||||
[DataField("customAddress")]
|
||||
public bool CustomAddress = false;
|
||||
|
||||
/// <summary>
|
||||
/// Prefix to prepend to any automatically generated addresses. Helps players to identify devices. This gets
|
||||
/// localized.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("prefix")]
|
||||
public string? Prefix;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the device should listen for all device messages, regardless of the intended recipient.
|
||||
/// </summary>
|
||||
[DataField("receiveAll")]
|
||||
public bool ReceiveAll;
|
||||
|
||||
/// <summary>
|
||||
/// If the device should show its address upon an examine. Useful for devices
|
||||
/// that do not have a visible UI.
|
||||
/// </summary>
|
||||
[DataField("examinableAddress")]
|
||||
public bool ExaminableAddress;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the device should attempt to join the network on map init.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("autoConnect")]
|
||||
public bool AutoConnect = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to send the broadcast recipients list to the sender so it can be filtered.
|
||||
/// <see cref="DeviceListSystem"/>
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("sendBroadcastAttemptEvent")]
|
||||
public bool SendBroadcastAttemptEvent = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this device's address can be saved to device-lists
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("savableAddress")]
|
||||
public bool SavableAddress = true;
|
||||
|
||||
/// <summary>
|
||||
/// A list of device-lists that this device is on.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
[Access(typeof(SharedDeviceListSystem))]
|
||||
public HashSet<EntityUid> DeviceLists = new();
|
||||
|
||||
/// <summary>
|
||||
/// A list of configurators that this device is on.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
[Access(typeof(SharedNetworkConfiguratorSystem))]
|
||||
public HashSet<EntityUid> Configurators = new();
|
||||
}
|
||||
}
|
||||
238
Content.Shared/DeviceNetwork/DeviceNet.cs
Normal file
238
Content.Shared/DeviceNetwork/DeviceNet.cs
Normal file
@@ -0,0 +1,238 @@
|
||||
using Robust.Shared.Random;
|
||||
using Content.Shared.DeviceNetwork.Components;
|
||||
|
||||
namespace Content.Shared.DeviceNetwork;
|
||||
|
||||
/// <summary>
|
||||
/// Data class for storing and retrieving information about devices connected to a device network.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This basically just makes <see cref="DeviceNetworkComponent"/> accessible via their addresses and frequencies on
|
||||
/// some network.
|
||||
/// </remarks>
|
||||
public sealed class DeviceNet
|
||||
{
|
||||
/// <summary>
|
||||
/// Devices, mapped by their "Address", which is just an int that gets converted to Hex for displaying to users.
|
||||
/// This dictionary contains all devices connected to this network, though they may not be listening to any
|
||||
/// specific frequency.
|
||||
/// </summary>
|
||||
public readonly Dictionary<string, DeviceNetworkComponent> Devices = new();
|
||||
|
||||
/// <summary>
|
||||
/// Devices listening on a given frequency.
|
||||
/// </summary>
|
||||
public readonly Dictionary<uint, HashSet<DeviceNetworkComponent>> ListeningDevices = new();
|
||||
|
||||
/// <summary>
|
||||
/// Devices listening to all packets on a given frequency, regardless of the intended recipient.
|
||||
/// </summary>
|
||||
public readonly Dictionary<uint, HashSet<DeviceNetworkComponent>> ReceiveAllDevices = new();
|
||||
|
||||
private readonly IRobustRandom _random;
|
||||
public readonly int NetId;
|
||||
|
||||
public DeviceNet(int netId, IRobustRandom random)
|
||||
{
|
||||
_random = random;
|
||||
NetId = netId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a device to the network.
|
||||
/// </summary>
|
||||
public bool Add(DeviceNetworkComponent device)
|
||||
{
|
||||
if (device.CustomAddress)
|
||||
{
|
||||
// Only add if the device's existing address is available.
|
||||
if (!Devices.TryAdd(device.Address, device))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Randomly generate a new address if the existing random one is invalid. Otherwise, keep the existing address
|
||||
if (string.IsNullOrWhiteSpace(device.Address) || Devices.ContainsKey(device.Address))
|
||||
device.Address = GenerateValidAddress(device.Prefix);
|
||||
|
||||
Devices[device.Address] = device;
|
||||
}
|
||||
|
||||
if (device.ReceiveFrequency is not uint freq)
|
||||
return true;
|
||||
|
||||
if (!ListeningDevices.TryGetValue(freq, out var devices))
|
||||
ListeningDevices[freq] = devices = new();
|
||||
|
||||
devices.Add(device);
|
||||
|
||||
if (!device.ReceiveAll)
|
||||
return true;
|
||||
|
||||
if (!ReceiveAllDevices.TryGetValue(freq, out var receiveAlldevices))
|
||||
ReceiveAllDevices[freq] = receiveAlldevices = new();
|
||||
|
||||
receiveAlldevices.Add(device);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a device from the network.
|
||||
/// </summary>
|
||||
public bool Remove(DeviceNetworkComponent device)
|
||||
{
|
||||
if (device.Address == null || !Devices.Remove(device.Address))
|
||||
return false;
|
||||
|
||||
if (device.ReceiveFrequency is not uint freq)
|
||||
return true;
|
||||
|
||||
if (ListeningDevices.TryGetValue(freq, out var listening))
|
||||
{
|
||||
listening.Remove(device);
|
||||
if (listening.Count == 0)
|
||||
ListeningDevices.Remove(freq);
|
||||
}
|
||||
|
||||
if (device.ReceiveAll && ReceiveAllDevices.TryGetValue(freq, out var receiveAll))
|
||||
{
|
||||
receiveAll.Remove(device);
|
||||
if (receiveAll.Count == 0)
|
||||
ListeningDevices.Remove(freq);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Give an existing device a new randomly generated address. Useful if the device's address prefix was updated
|
||||
/// and they want a new address to reflect that, or something like that.
|
||||
/// </summary>
|
||||
public bool RandomizeAddress(string oldAddress, string? prefix = null)
|
||||
{
|
||||
if (!Devices.Remove(oldAddress, out var device))
|
||||
return false;
|
||||
|
||||
device.Address = GenerateValidAddress(prefix ?? device.Prefix);
|
||||
device.CustomAddress = false;
|
||||
Devices[device.Address] = device;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the address of an existing device.
|
||||
/// </summary>
|
||||
public bool UpdateAddress(string oldAddress, string newAddress)
|
||||
{
|
||||
if (Devices.ContainsKey(newAddress))
|
||||
return false;
|
||||
|
||||
if (!Devices.Remove(oldAddress, out var device))
|
||||
return false;
|
||||
|
||||
device.Address = newAddress;
|
||||
device.CustomAddress = true;
|
||||
Devices[newAddress] = device;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make an existing network device listen to a new frequency.
|
||||
/// </summary>
|
||||
public bool UpdateReceiveFrequency(string address, uint? newFrequency)
|
||||
{
|
||||
if (!Devices.TryGetValue(address, out var device))
|
||||
return false;
|
||||
|
||||
if (device.ReceiveFrequency == newFrequency)
|
||||
return true;
|
||||
|
||||
if (device.ReceiveFrequency is uint freq)
|
||||
{
|
||||
if (ListeningDevices.TryGetValue(freq, out var listening))
|
||||
{
|
||||
listening.Remove(device);
|
||||
if (listening.Count == 0)
|
||||
ListeningDevices.Remove(freq);
|
||||
}
|
||||
|
||||
if (device.ReceiveAll && ReceiveAllDevices.TryGetValue(freq, out var receiveAll))
|
||||
{
|
||||
receiveAll.Remove(device);
|
||||
if (receiveAll.Count == 0)
|
||||
ListeningDevices.Remove(freq);
|
||||
}
|
||||
}
|
||||
|
||||
device.ReceiveFrequency = newFrequency;
|
||||
|
||||
if (newFrequency == null)
|
||||
return true;
|
||||
|
||||
if (!ListeningDevices.TryGetValue(newFrequency.Value, out var devices))
|
||||
ListeningDevices[newFrequency.Value] = devices = new();
|
||||
|
||||
devices.Add(device);
|
||||
|
||||
if (!device.ReceiveAll)
|
||||
return true;
|
||||
|
||||
if (!ReceiveAllDevices.TryGetValue(newFrequency.Value, out var receiveAlldevices))
|
||||
ReceiveAllDevices[newFrequency.Value] = receiveAlldevices = new();
|
||||
|
||||
receiveAlldevices.Add(device);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make an existing network device listen to a new frequency.
|
||||
/// </summary>
|
||||
public bool UpdateReceiveAll(string address, bool receiveAll)
|
||||
{
|
||||
if (!Devices.TryGetValue(address, out var device))
|
||||
return false;
|
||||
|
||||
if (device.ReceiveAll == receiveAll)
|
||||
return true;
|
||||
|
||||
device.ReceiveAll = receiveAll;
|
||||
|
||||
if (device.ReceiveFrequency is not uint freq)
|
||||
return true;
|
||||
|
||||
// remove or add to set of listening devices
|
||||
|
||||
HashSet<DeviceNetworkComponent>? devices;
|
||||
if (receiveAll)
|
||||
{
|
||||
if (!ReceiveAllDevices.TryGetValue(freq, out devices))
|
||||
ReceiveAllDevices[freq] = devices = new();
|
||||
devices.Add(device);
|
||||
}
|
||||
else if (ReceiveAllDevices.TryGetValue(freq, out devices))
|
||||
{
|
||||
devices.Remove(device);
|
||||
if (devices.Count == 0)
|
||||
ReceiveAllDevices.Remove(freq);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a valid address by randomly generating one and checking if it already exists on the network.
|
||||
/// </summary>
|
||||
private string GenerateValidAddress(string? prefix)
|
||||
{
|
||||
prefix = string.IsNullOrWhiteSpace(prefix) ? null : Loc.GetString(prefix);
|
||||
string address;
|
||||
do
|
||||
{
|
||||
var num = _random.Next();
|
||||
address = $"{prefix}{num >> 16:X4}-{num & 0xFFFF:X4}";
|
||||
}
|
||||
while (Devices.ContainsKey(address));
|
||||
|
||||
return address;
|
||||
}
|
||||
}
|
||||
79
Content.Shared/DeviceNetwork/DeviceNetworkConstants.cs
Normal file
79
Content.Shared/DeviceNetwork/DeviceNetworkConstants.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Robust.Shared.Utility;
|
||||
using Content.Shared.DeviceNetwork.Components;
|
||||
|
||||
namespace Content.Shared.DeviceNetwork
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of constants to help with using device networks
|
||||
/// </summary>
|
||||
public static class DeviceNetworkConstants
|
||||
{
|
||||
/// <summary>
|
||||
/// Used by logic gates to transmit the state of their ports
|
||||
/// </summary>
|
||||
public const string LogicState = "logic_state";
|
||||
|
||||
#region Commands
|
||||
|
||||
/// <summary>
|
||||
/// The key for command names
|
||||
/// E.g. [DeviceNetworkConstants.Command] = "ping"
|
||||
/// </summary>
|
||||
public const string Command = "command";
|
||||
|
||||
/// <summary>
|
||||
/// The command for setting a devices state
|
||||
/// E.g. to turn a light on or off
|
||||
/// </summary>
|
||||
public const string CmdSetState = "set_state";
|
||||
|
||||
/// <summary>
|
||||
/// The command for a device that just updated its state
|
||||
/// E.g. suit sensors broadcasting owners vitals state
|
||||
/// </summary>
|
||||
public const string CmdUpdatedState = "updated_state";
|
||||
|
||||
#endregion
|
||||
|
||||
#region SetState
|
||||
|
||||
/// <summary>
|
||||
/// Used with the <see cref="CmdSetState"/> command to turn a device on or off
|
||||
/// </summary>
|
||||
public const string StateEnabled = "state_enabled";
|
||||
|
||||
#endregion
|
||||
|
||||
#region DisplayHelpers
|
||||
|
||||
/// <summary>
|
||||
/// Converts the unsigned int to string and inserts a number before the last digit
|
||||
/// </summary>
|
||||
public static string FrequencyToString(this uint frequency)
|
||||
{
|
||||
var result = frequency.ToString();
|
||||
if (result.Length <= 2)
|
||||
return result + ".0";
|
||||
|
||||
return result.Insert(result.Length - 1, ".");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Either returns the localized name representation of the corresponding <see cref="DeviceNetworkComponent.DeviceNetIdDefaults"/>
|
||||
/// or converts the id to string
|
||||
/// </summary>
|
||||
public static string DeviceNetIdToLocalizedName(this int id)
|
||||
{
|
||||
|
||||
if (!Enum.IsDefined(typeof(DeviceNetworkComponent.DeviceNetIdDefaults), id))
|
||||
return id.ToString();
|
||||
|
||||
var result = ((DeviceNetworkComponent.DeviceNetIdDefaults) id).ToString();
|
||||
var resultKebab = "device-net-id-" + CaseConversion.PascalToKebab(result);
|
||||
|
||||
return !Loc.TryGetString(resultKebab, out var name) ? result : name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Content.Shared.DeviceNetwork.Components;
|
||||
|
||||
namespace Content.Shared.DeviceNetwork.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Sent to the sending entity before broadcasting network packets to recipients
|
||||
/// </summary>
|
||||
public sealed class BeforeBroadcastAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
public readonly IReadOnlySet<DeviceNetworkComponent> Recipients;
|
||||
public HashSet<DeviceNetworkComponent>? ModifiedRecipients;
|
||||
|
||||
public BeforeBroadcastAttemptEvent(IReadOnlySet<DeviceNetworkComponent> recipients)
|
||||
{
|
||||
Recipients = recipients;
|
||||
}
|
||||
}
|
||||
35
Content.Shared/DeviceNetwork/Events/BeforePacketSentEvent.cs
Normal file
35
Content.Shared/DeviceNetwork/Events/BeforePacketSentEvent.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace Content.Shared.DeviceNetwork.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Event raised before a device network packet is send.
|
||||
/// Subscribed to by other systems to prevent the packet from being sent.
|
||||
/// </summary>
|
||||
public sealed class BeforePacketSentEvent : CancellableEntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The EntityUid of the entity the packet was sent from.
|
||||
/// </summary>
|
||||
public readonly EntityUid Sender;
|
||||
|
||||
public readonly TransformComponent SenderTransform;
|
||||
|
||||
/// <summary>
|
||||
/// The senders current position in world coordinates.
|
||||
/// </summary>
|
||||
public readonly Vector2 SenderPosition;
|
||||
|
||||
/// <summary>
|
||||
/// The network the packet will be sent to.
|
||||
/// </summary>
|
||||
public readonly string NetworkId;
|
||||
|
||||
public BeforePacketSentEvent(EntityUid sender, TransformComponent xform, Vector2 senderPosition, string networkId)
|
||||
{
|
||||
Sender = sender;
|
||||
SenderTransform = xform;
|
||||
SenderPosition = senderPosition;
|
||||
NetworkId = networkId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace Content.Shared.DeviceNetwork.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a device network packet gets sent.
|
||||
/// </summary>
|
||||
public sealed class DeviceNetworkPacketEvent : EntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The id of the network that this packet is being sent on.
|
||||
/// </summary>
|
||||
public int NetId;
|
||||
|
||||
/// <summary>
|
||||
/// The frequency the packet is sent on.
|
||||
/// </summary>
|
||||
public readonly uint Frequency;
|
||||
|
||||
/// <summary>
|
||||
/// Address of the intended recipient. Null if the message was broadcast.
|
||||
/// </summary>
|
||||
public string? Address;
|
||||
|
||||
/// <summary>
|
||||
/// The device network address of the sending entity.
|
||||
/// </summary>
|
||||
public readonly string SenderAddress;
|
||||
|
||||
/// <summary>
|
||||
/// The entity that sent the packet.
|
||||
/// </summary>
|
||||
public EntityUid Sender;
|
||||
|
||||
/// <summary>
|
||||
/// The data that is being sent.
|
||||
/// </summary>
|
||||
public readonly NetworkPayload Data;
|
||||
|
||||
public DeviceNetworkPacketEvent(int netId, string? address, uint frequency, string senderAddress, EntityUid sender, NetworkPayload data)
|
||||
{
|
||||
NetId = netId;
|
||||
Address = address;
|
||||
Frequency = frequency;
|
||||
SenderAddress = senderAddress;
|
||||
Sender = sender;
|
||||
Data = data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Content.Shared.DeviceNetwork.Components;
|
||||
|
||||
namespace Content.Shared.DeviceNetwork.Systems;
|
||||
|
||||
public abstract class SharedDeviceNetworkSystem : EntitySystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends the given payload as a device network packet to the entity with the given address and frequency.
|
||||
/// Addresses are given to the DeviceNetworkComponent of an entity when connecting.
|
||||
/// </summary>
|
||||
/// <param name="uid">The EntityUid of the sending entity</param>
|
||||
/// <param name="address">The address of the entity that the packet gets sent to. If null, the message is broadcast to all devices on that frequency (except the sender)</param>
|
||||
/// <param name="frequency">The frequency to send on</param>
|
||||
/// <param name="data">The data to be sent</param>
|
||||
/// <returns>Returns true when the packet was successfully enqueued.</returns>
|
||||
public virtual bool QueuePacket(EntityUid uid,
|
||||
string? address,
|
||||
NetworkPayload data,
|
||||
uint? frequency = null,
|
||||
int? network = null,
|
||||
DeviceNetworkComponent? device = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
28
Content.Shared/Disposal/Mailing/MailingUnitComponent.cs
Normal file
28
Content.Shared/Disposal/Mailing/MailingUnitComponent.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Content.Shared.Disposal.Mailing;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Disposal.Components;
|
||||
|
||||
[Access(typeof(SharedMailingUnitSystem))]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
public sealed partial class MailingUnitComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// List of targets the mailing unit can send to.
|
||||
/// Each target is just a disposal routing tag
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public List<string> TargetList = new();
|
||||
|
||||
/// <summary>
|
||||
/// The target that gets attached to the disposal holders tag list on flush
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public string? Target;
|
||||
|
||||
/// <summary>
|
||||
/// The tag for this mailing unit
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public string? Tag;
|
||||
}
|
||||
174
Content.Shared/Disposal/Mailing/SharedMailingUnitSystem.cs
Normal file
174
Content.Shared/Disposal/Mailing/SharedMailingUnitSystem.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
using Content.Shared.Configurable;
|
||||
using Content.Shared.DeviceNetwork;
|
||||
using Content.Shared.DeviceNetwork.Components;
|
||||
using Content.Shared.DeviceNetwork.Events;
|
||||
using Content.Shared.DeviceNetwork.Systems;
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Content.Shared.Disposal.Unit;
|
||||
using Content.Shared.Disposal.Unit.Events;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Power.EntitySystems;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Shared.Disposal.Mailing;
|
||||
|
||||
public abstract class SharedMailingUnitSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedDeviceNetworkSystem _deviceNetworkSystem = default!;
|
||||
[Dependency] private readonly SharedPowerReceiverSystem _power = default!;
|
||||
[Dependency] protected readonly SharedUserInterfaceSystem UserInterfaceSystem = default!;
|
||||
|
||||
private const string MailTag = "mail";
|
||||
|
||||
private const string TagConfigurationKey = "tag";
|
||||
|
||||
private const string NetTag = "tag";
|
||||
private const string NetSrc = "src";
|
||||
private const string NetTarget = "target";
|
||||
private const string NetCmdSent = "mail_sent";
|
||||
private const string NetCmdRequest = "get_mailer_tag";
|
||||
private const string NetCmdResponse = "mailer_tag";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<MailingUnitComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<MailingUnitComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
|
||||
SubscribeLocalEvent<MailingUnitComponent, BeforeDisposalFlushEvent>(OnBeforeFlush);
|
||||
SubscribeLocalEvent<MailingUnitComponent, ConfigurationUpdatedEvent>(OnConfigurationUpdated);
|
||||
SubscribeLocalEvent<MailingUnitComponent, ActivateInWorldEvent>(HandleActivate, before: new[] { typeof(SharedDisposalUnitSystem) });
|
||||
SubscribeLocalEvent<MailingUnitComponent, TargetSelectedMessage>(OnTargetSelected);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, MailingUnitComponent component, ComponentInit args)
|
||||
{
|
||||
UpdateTargetList(uid, component);
|
||||
}
|
||||
|
||||
private void OnPacketReceived(EntityUid uid, MailingUnitComponent component, DeviceNetworkPacketEvent args)
|
||||
{
|
||||
if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? command) || !_power.IsPowered(uid))
|
||||
return;
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case NetCmdRequest:
|
||||
SendTagRequestResponse(uid, args, component.Tag);
|
||||
break;
|
||||
case NetCmdResponse when args.Data.TryGetValue(NetTag, out string? tag):
|
||||
//Add the received tag request response to the list of targets
|
||||
component.TargetList.Add(tag);
|
||||
Dirty(uid, component);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the given tag as a response to a <see cref="NetCmdRequest"/> if it's not null
|
||||
/// </summary>
|
||||
private void SendTagRequestResponse(EntityUid uid, DeviceNetworkPacketEvent args, string? tag)
|
||||
{
|
||||
if (tag == null)
|
||||
return;
|
||||
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = NetCmdResponse,
|
||||
[NetTag] = tag
|
||||
};
|
||||
|
||||
_deviceNetworkSystem.QueuePacket(uid, args.Address, payload, args.Frequency);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prevents the unit from flushing if no target is selected
|
||||
/// </summary>
|
||||
private void OnBeforeFlush(EntityUid uid, MailingUnitComponent component, BeforeDisposalFlushEvent args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(component.Target))
|
||||
{
|
||||
args.Cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
Dirty(uid, component);
|
||||
args.Tags.Add(MailTag);
|
||||
args.Tags.Add(component.Target);
|
||||
|
||||
BroadcastSentMessage(uid, component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast that a mail was sent including the src and target tags
|
||||
/// </summary>
|
||||
private void BroadcastSentMessage(EntityUid uid, MailingUnitComponent component, DeviceNetworkComponent? device = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(component.Tag) || string.IsNullOrEmpty(component.Target) || !Resolve(uid, ref device))
|
||||
return;
|
||||
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = NetCmdSent,
|
||||
[NetSrc] = component.Tag,
|
||||
[NetTarget] = component.Target
|
||||
};
|
||||
|
||||
_deviceNetworkSystem.QueuePacket(uid, null, payload, null, null, device);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the units target list and broadcasts a <see cref="NetCmdRequest"/>.
|
||||
/// The target list will then get populated with <see cref="NetCmdResponse"/> responses from all active mailing units on the same grid
|
||||
/// </summary>
|
||||
private void UpdateTargetList(EntityUid uid, MailingUnitComponent component, DeviceNetworkComponent? device = null)
|
||||
{
|
||||
if (!Resolve(uid, ref device, false))
|
||||
return;
|
||||
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = NetCmdRequest
|
||||
};
|
||||
|
||||
component.TargetList.Clear();
|
||||
_deviceNetworkSystem.QueuePacket(uid, null, payload, null, null, device);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets called when the units tag got updated
|
||||
/// </summary>
|
||||
private void OnConfigurationUpdated(EntityUid uid, MailingUnitComponent component, ConfigurationUpdatedEvent args)
|
||||
{
|
||||
var configuration = args.Configuration.Config;
|
||||
if (!configuration.ContainsKey(TagConfigurationKey) || configuration[TagConfigurationKey] == string.Empty)
|
||||
{
|
||||
component.Tag = null;
|
||||
return;
|
||||
}
|
||||
|
||||
component.Tag = configuration[TagConfigurationKey];
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void HandleActivate(EntityUid uid, MailingUnitComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled || !args.Complex)
|
||||
return;
|
||||
|
||||
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
UpdateTargetList(uid, component);
|
||||
UserInterfaceSystem.OpenUi(uid, MailingUnitUiKey.Key, actor.PlayerSession);
|
||||
}
|
||||
|
||||
private void OnTargetSelected(EntityUid uid, MailingUnitComponent component, TargetSelectedMessage args)
|
||||
{
|
||||
component.Target = args.Target;
|
||||
Dirty(uid, component);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Disposal;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class MailingUnitBoundUserInterfaceState : BoundUserInterfaceState, IEquatable<MailingUnitBoundUserInterfaceState>
|
||||
{
|
||||
public string? Target;
|
||||
public List<string> TargetList;
|
||||
public string? Tag;
|
||||
public SharedDisposalUnitComponent.DisposalUnitBoundUserInterfaceState DisposalState;
|
||||
|
||||
public MailingUnitBoundUserInterfaceState(SharedDisposalUnitComponent.DisposalUnitBoundUserInterfaceState disposalState, string? target, List<string> targetList, string? tag)
|
||||
{
|
||||
DisposalState = disposalState;
|
||||
Target = target;
|
||||
TargetList = targetList;
|
||||
Tag = tag;
|
||||
}
|
||||
|
||||
public bool Equals(MailingUnitBoundUserInterfaceState? other)
|
||||
{
|
||||
if (other is null)
|
||||
return false;
|
||||
if (ReferenceEquals(this, other))
|
||||
return true;
|
||||
return DisposalState.Equals(other.DisposalState)
|
||||
&& Target == other.Target
|
||||
&& TargetList.Equals(other.TargetList)
|
||||
&& Tag == other.Tag;
|
||||
}
|
||||
|
||||
public override bool Equals(object? other)
|
||||
{
|
||||
if (other is MailingUnitBoundUserInterfaceState otherState)
|
||||
return Equals(otherState);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Throwing;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Disposal;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class DisposalDoAfterEvent : SimpleDoAfterEvent
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class SharedDisposalUnitSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly IGameTiming GameTiming = default!;
|
||||
[Dependency] protected readonly EmagSystem _emag = default!;
|
||||
[Dependency] protected readonly MetaDataSystem Metadata = default!;
|
||||
[Dependency] protected readonly SharedJointSystem Joints = default!;
|
||||
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
|
||||
|
||||
protected static TimeSpan ExitAttemptDelay = TimeSpan.FromSeconds(0.5);
|
||||
|
||||
// Percentage
|
||||
public const float PressurePerSecond = 0.05f;
|
||||
|
||||
public abstract bool HasDisposals([NotNullWhen(true)] EntityUid? uid);
|
||||
|
||||
public abstract bool ResolveDisposals(EntityUid uid, [NotNullWhen(true)] ref SharedDisposalUnitComponent? component);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current pressure state of a disposals unit.
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <param name="component"></param>
|
||||
/// <param name="metadata"></param>
|
||||
/// <returns></returns>
|
||||
public DisposalsPressureState GetState(EntityUid uid, SharedDisposalUnitComponent component, MetaDataComponent? metadata = null)
|
||||
{
|
||||
var nextPressure = Metadata.GetPauseTime(uid, metadata) + component.NextPressurized - GameTiming.CurTime;
|
||||
var pressurizeTime = 1f / PressurePerSecond;
|
||||
var pressurizeDuration = pressurizeTime - component.FlushDelay.TotalSeconds;
|
||||
|
||||
if (nextPressure.TotalSeconds > pressurizeDuration)
|
||||
{
|
||||
return DisposalsPressureState.Flushed;
|
||||
}
|
||||
|
||||
if (nextPressure > TimeSpan.Zero)
|
||||
{
|
||||
return DisposalsPressureState.Pressurizing;
|
||||
}
|
||||
|
||||
return DisposalsPressureState.Ready;
|
||||
}
|
||||
|
||||
public float GetPressure(EntityUid uid, SharedDisposalUnitComponent component, MetaDataComponent? metadata = null)
|
||||
{
|
||||
if (!Resolve(uid, ref metadata))
|
||||
return 0f;
|
||||
|
||||
var pauseTime = Metadata.GetPauseTime(uid, metadata);
|
||||
return MathF.Min(1f,
|
||||
(float) (GameTiming.CurTime - pauseTime - component.NextPressurized).TotalSeconds / PressurePerSecond);
|
||||
}
|
||||
|
||||
protected void OnPreventCollide(EntityUid uid, SharedDisposalUnitComponent component,
|
||||
ref PreventCollideEvent args)
|
||||
{
|
||||
var otherBody = args.OtherEntity;
|
||||
|
||||
// Items dropped shouldn't collide but items thrown should
|
||||
if (HasComp<ItemComponent>(otherBody) && !HasComp<ThrownItemComponent>(otherBody))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.RecentlyEjected.Contains(otherBody))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnCanDragDropOn(EntityUid uid, SharedDisposalUnitComponent component, ref CanDropTargetEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.CanDrop = CanInsert(uid, component, args.Dragged);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
protected void OnEmagged(EntityUid uid, SharedDisposalUnitComponent component, ref GotEmaggedEvent args)
|
||||
{
|
||||
if (!_emag.CompareFlag(args.Type, EmagType.Interaction))
|
||||
return;
|
||||
|
||||
if (component.DisablePressure == true)
|
||||
return;
|
||||
|
||||
component.DisablePressure = true;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
public virtual bool CanInsert(EntityUid uid, SharedDisposalUnitComponent component, EntityUid entity)
|
||||
{
|
||||
if (!Transform(uid).Anchored)
|
||||
return false;
|
||||
|
||||
var storable = HasComp<ItemComponent>(entity);
|
||||
if (!storable && !HasComp<BodyComponent>(entity))
|
||||
return false;
|
||||
|
||||
if (_whitelistSystem.IsBlacklistPass(component.Blacklist, entity) ||
|
||||
_whitelistSystem.IsWhitelistFail(component.Whitelist, entity))
|
||||
return false;
|
||||
|
||||
if (TryComp<PhysicsComponent>(entity, out var physics) && (physics.CanCollide) || storable)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public abstract void DoInsertDisposalUnit(EntityUid uid, EntityUid toInsert, EntityUid user, SharedDisposalUnitComponent? disposal = null);
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class DisposalUnitComponentState : ComponentState
|
||||
{
|
||||
public SoundSpecifier? FlushSound;
|
||||
public DisposalsPressureState State;
|
||||
public TimeSpan NextPressurized;
|
||||
public TimeSpan AutomaticEngageTime;
|
||||
public TimeSpan? NextFlush;
|
||||
public bool Powered;
|
||||
public bool Engaged;
|
||||
public List<NetEntity> RecentlyEjected;
|
||||
|
||||
public DisposalUnitComponentState(SoundSpecifier? flushSound, DisposalsPressureState state, TimeSpan nextPressurized, TimeSpan automaticEngageTime, TimeSpan? nextFlush, bool powered, bool engaged, List<NetEntity> recentlyEjected)
|
||||
{
|
||||
FlushSound = flushSound;
|
||||
State = state;
|
||||
NextPressurized = nextPressurized;
|
||||
AutomaticEngageTime = automaticEngageTime;
|
||||
NextFlush = nextFlush;
|
||||
Powered = powered;
|
||||
Engaged = engaged;
|
||||
RecentlyEjected = recentlyEjected;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Content.Shared/Disposal/Tube/DisposalEntryComponent.cs
Normal file
12
Content.Shared/Disposal/Tube/DisposalEntryComponent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Content.Shared.Disposal.Unit;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Disposal.Tube;
|
||||
|
||||
[RegisterComponent]
|
||||
[Access(typeof(SharedDisposalTubeSystem), typeof(SharedDisposalUnitSystem))]
|
||||
public sealed partial class DisposalEntryComponent : Component
|
||||
{
|
||||
[DataField]
|
||||
public EntProtoId HolderPrototypeId = "DisposalHolder";
|
||||
}
|
||||
10
Content.Shared/Disposal/Unit/BeforeDisposalFlushEvent.cs
Normal file
10
Content.Shared/Disposal/Unit/BeforeDisposalFlushEvent.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Content.Shared.Disposal.Unit.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Sent before the disposal unit flushes it's contents.
|
||||
/// Allows adding tags for sorting and preventing the disposal unit from flushing.
|
||||
/// </summary>
|
||||
public sealed class BeforeDisposalFlushEvent : CancellableEntityEventArgs
|
||||
{
|
||||
public readonly List<string> Tags = new();
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Shared.Atmos;
|
||||
using Robust.Shared.Audio;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -7,15 +8,24 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Disposal.Components;
|
||||
|
||||
[NetworkedComponent]
|
||||
public abstract partial class SharedDisposalUnitComponent : Component
|
||||
/// <summary>
|
||||
/// Takes in entities and flushes them out to attached disposals tubes after a timer.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
public sealed partial class DisposalUnitComponent : Component
|
||||
{
|
||||
public const string ContainerId = "disposals";
|
||||
|
||||
/// <summary>
|
||||
/// Air contained in the disposal unit.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public GasMixture Air = new(Atmospherics.CellVolume);
|
||||
|
||||
/// <summary>
|
||||
/// Sounds played upon the unit flushing.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("soundFlush")]
|
||||
[DataField("soundFlush"), AutoNetworkedField]
|
||||
public SoundSpecifier? FlushSound = new SoundPathSpecifier("/Audio/Machines/disposalflush.ogg");
|
||||
|
||||
/// <summary>
|
||||
@@ -39,20 +49,13 @@ public abstract partial class SharedDisposalUnitComponent : Component
|
||||
/// <summary>
|
||||
/// State for this disposals unit.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public DisposalsPressureState State;
|
||||
|
||||
// TODO: Just make this use vaulting.
|
||||
/// <summary>
|
||||
/// We'll track whatever just left disposals so we know what collision we need to ignore until they stop intersecting our BB.
|
||||
/// </summary>
|
||||
[ViewVariables, DataField]
|
||||
public List<EntityUid> RecentlyEjected = new();
|
||||
|
||||
/// <summary>
|
||||
/// Next time the disposal unit will be pressurized.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField]
|
||||
public TimeSpan NextPressurized = TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
@@ -70,26 +73,24 @@ public abstract partial class SharedDisposalUnitComponent : Component
|
||||
/// <summary>
|
||||
/// Removes the pressure requirement for flushing.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public bool DisablePressure;
|
||||
|
||||
/// <summary>
|
||||
/// Last time that an entity tried to exit this disposal unit.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField, AutoNetworkedField]
|
||||
public TimeSpan LastExitAttempt;
|
||||
|
||||
[DataField]
|
||||
public bool AutomaticEngage = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public TimeSpan AutomaticEngageTime = TimeSpan.FromSeconds(30);
|
||||
|
||||
/// <summary>
|
||||
/// Delay from trying to enter disposals ourselves.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public float EntryDelay = 0.5f;
|
||||
|
||||
@@ -104,20 +105,16 @@ public abstract partial class SharedDisposalUnitComponent : Component
|
||||
/// </summary>
|
||||
[ViewVariables] public Container Container = default!;
|
||||
|
||||
// TODO: Network power shit instead fam.
|
||||
[ViewVariables, DataField]
|
||||
public bool Powered;
|
||||
|
||||
/// <summary>
|
||||
/// Was the disposals unit engaged for a manual flush.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool Engaged;
|
||||
|
||||
/// <summary>
|
||||
/// Next time this unit will flush. Is the lesser of <see cref="FlushDelay"/> and <see cref="AutomaticEngageTime"/>
|
||||
/// </summary>
|
||||
[ViewVariables, DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField]
|
||||
public TimeSpan? NextFlush;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
@@ -162,37 +159,6 @@ public abstract partial class SharedDisposalUnitComponent : Component
|
||||
Power
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class DisposalUnitBoundUserInterfaceState : BoundUserInterfaceState, IEquatable<DisposalUnitBoundUserInterfaceState>
|
||||
{
|
||||
public readonly string UnitName;
|
||||
public readonly string UnitState;
|
||||
public readonly TimeSpan FullPressureTime;
|
||||
public readonly bool Powered;
|
||||
public readonly bool Engaged;
|
||||
|
||||
public DisposalUnitBoundUserInterfaceState(string unitName, string unitState, TimeSpan fullPressureTime, bool powered,
|
||||
bool engaged)
|
||||
{
|
||||
UnitName = unitName;
|
||||
UnitState = unitState;
|
||||
FullPressureTime = fullPressureTime;
|
||||
Powered = powered;
|
||||
Engaged = engaged;
|
||||
}
|
||||
|
||||
public bool Equals(DisposalUnitBoundUserInterfaceState? other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return UnitName == other.UnitName &&
|
||||
UnitState == other.UnitState &&
|
||||
Powered == other.Powered &&
|
||||
Engaged == other.Engaged &&
|
||||
FullPressureTime.Equals(other.FullPressureTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Message data sent from client to server when a disposal unit ui button is pressed.
|
||||
/// </summary>
|
||||
14
Content.Shared/Disposal/Unit/SharedDisposalTubeSystem.cs
Normal file
14
Content.Shared/Disposal/Unit/SharedDisposalTubeSystem.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Content.Shared.Disposal.Components;
|
||||
|
||||
namespace Content.Shared.Disposal.Unit;
|
||||
|
||||
public abstract class SharedDisposalTubeSystem : EntitySystem
|
||||
{
|
||||
public virtual bool TryInsert(EntityUid uid,
|
||||
DisposalUnitComponent from,
|
||||
IEnumerable<string>? tags = default,
|
||||
Tube.DisposalEntryComponent? entry = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
788
Content.Shared/Disposal/Unit/SharedDisposalUnitSystem.cs
Normal file
788
Content.Shared/Disposal/Unit/SharedDisposalUnitSystem.cs
Normal file
@@ -0,0 +1,788 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Climbing.Systems;
|
||||
using Content.Shared.Containers;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Content.Shared.Disposal.Unit.Events;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Power;
|
||||
using Content.Shared.Power.EntitySystems;
|
||||
using Content.Shared.Throwing;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Disposal.Unit;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class DisposalDoAfterEvent : SimpleDoAfterEvent
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class SharedDisposalUnitSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly ActionBlockerSystem ActionBlockerSystem = default!;
|
||||
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
|
||||
[Dependency] protected readonly MetaDataSystem Metadata = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] protected readonly SharedAudioSystem Audio = default!;
|
||||
[Dependency] protected readonly IGameTiming GameTiming = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLog = default!;
|
||||
[Dependency] private readonly ClimbSystem _climb = default!;
|
||||
[Dependency] protected readonly SharedContainerSystem Containers = default!;
|
||||
[Dependency] protected readonly SharedJointSystem Joints = default!;
|
||||
[Dependency] private readonly SharedPowerReceiverSystem _power = default!;
|
||||
[Dependency] private readonly SharedDisposalTubeSystem _disposalTubeSystem = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
[Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
|
||||
[Dependency] private readonly SharedUserInterfaceSystem _ui = default!;
|
||||
[Dependency] private readonly SharedMapSystem _map = default!;
|
||||
|
||||
protected static TimeSpan ExitAttemptDelay = TimeSpan.FromSeconds(0.5);
|
||||
|
||||
// Percentage
|
||||
public const float PressurePerSecond = 0.05f;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<DisposalUnitComponent, PreventCollideEvent>(OnPreventCollide);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, CanDropTargetEvent>(OnCanDragDropOn);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, GetVerbsEvent<InteractionVerb>>(AddInsertVerb);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, GetVerbsEvent<AlternativeVerb>>(AddDisposalAltVerbs);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, GetVerbsEvent<Verb>>(AddClimbInsideVerb);
|
||||
|
||||
SubscribeLocalEvent<DisposalUnitComponent, DisposalDoAfterEvent>(OnDoAfter);
|
||||
|
||||
SubscribeLocalEvent<DisposalUnitComponent, BeforeThrowInsertEvent>(OnThrowInsert);
|
||||
|
||||
SubscribeLocalEvent<DisposalUnitComponent, DisposalUnitComponent.UiButtonPressedMessage>(OnUiButtonPressed);
|
||||
|
||||
SubscribeLocalEvent<DisposalUnitComponent, GotEmaggedEvent>(OnEmagged);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, AnchorStateChangedEvent>(OnAnchorChanged);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, PowerChangedEvent>(OnPowerChange);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, ComponentInit>(OnDisposalInit);
|
||||
|
||||
SubscribeLocalEvent<DisposalUnitComponent, ActivateInWorldEvent>(OnActivate);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, DragDropTargetEvent>(OnDragDropOn);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, ContainerRelayMovementEntityEvent>(OnMovement);
|
||||
}
|
||||
|
||||
private void AddDisposalAltVerbs(Entity<DisposalUnitComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract)
|
||||
return;
|
||||
|
||||
var uid = ent.Owner;
|
||||
var component = ent.Comp;
|
||||
|
||||
// Behavior for if the disposals bin has items in it
|
||||
if (component.Container.ContainedEntities.Count > 0)
|
||||
{
|
||||
// Verbs to flush the unit
|
||||
AlternativeVerb flushVerb = new()
|
||||
{
|
||||
Act = () => ManualEngage(uid, component),
|
||||
Text = Loc.GetString("disposal-flush-verb-get-data-text"),
|
||||
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/delete_transparent.svg.192dpi.png")),
|
||||
Priority = 1,
|
||||
};
|
||||
args.Verbs.Add(flushVerb);
|
||||
|
||||
// Verb to eject the contents
|
||||
AlternativeVerb ejectVerb = new()
|
||||
{
|
||||
Act = () => TryEjectContents(uid, component),
|
||||
Category = VerbCategory.Eject,
|
||||
Text = Loc.GetString("disposal-eject-verb-get-data-text")
|
||||
};
|
||||
args.Verbs.Add(ejectVerb);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddInsertVerb(EntityUid uid, DisposalUnitComponent component, GetVerbsEvent<InteractionVerb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null || args.Using == null)
|
||||
return;
|
||||
|
||||
if (!ActionBlockerSystem.CanDrop(args.User))
|
||||
return;
|
||||
|
||||
if (!CanInsert(uid, component, args.Using.Value))
|
||||
return;
|
||||
|
||||
InteractionVerb insertVerb = new()
|
||||
{
|
||||
Text = Name(args.Using.Value),
|
||||
Category = VerbCategory.Insert,
|
||||
Act = () =>
|
||||
{
|
||||
_handsSystem.TryDropIntoContainer(args.User, args.Using.Value, component.Container, checkActionBlocker: false, args.Hands);
|
||||
_adminLog.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(args.User):player} inserted {ToPrettyString(args.Using.Value)} into {ToPrettyString(uid)}");
|
||||
AfterInsert(uid, component, args.Using.Value, args.User);
|
||||
}
|
||||
};
|
||||
|
||||
args.Verbs.Add(insertVerb);
|
||||
}
|
||||
|
||||
private void OnDoAfter(EntityUid uid, DisposalUnitComponent component, DoAfterEvent args)
|
||||
{
|
||||
if (args.Handled || args.Cancelled || args.Args.Target == null || args.Args.Used == null)
|
||||
return;
|
||||
|
||||
AfterInsert(uid, component, args.Args.Target.Value, args.Args.User, doInsert: true);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnThrowInsert(Entity<DisposalUnitComponent> ent, ref BeforeThrowInsertEvent args)
|
||||
{
|
||||
if (!CanInsert(ent, ent, args.ThrownEntity))
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var query = EntityQueryEnumerator<DisposalUnitComponent, MetaDataComponent>();
|
||||
while (query.MoveNext(out var uid, out var unit, out var metadata))
|
||||
{
|
||||
Update(uid, unit, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This should just use the same thing as entity storage?
|
||||
private void OnMovement(EntityUid uid, DisposalUnitComponent component, ref ContainerRelayMovementEntityEvent args)
|
||||
{
|
||||
var currentTime = GameTiming.CurTime;
|
||||
|
||||
if (!ActionBlockerSystem.CanMove(args.Entity))
|
||||
return;
|
||||
|
||||
if (!TryComp(args.Entity, out HandsComponent? hands) ||
|
||||
hands.Count == 0 ||
|
||||
currentTime < component.LastExitAttempt + ExitAttemptDelay)
|
||||
return;
|
||||
|
||||
Dirty(uid, component);
|
||||
component.LastExitAttempt = currentTime;
|
||||
Remove(uid, component, args.Entity);
|
||||
UpdateUI((uid, component));
|
||||
}
|
||||
|
||||
private void OnActivate(EntityUid uid, DisposalUnitComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled || !args.Complex)
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
_ui.TryToggleUi(uid, DisposalUnitComponent.DisposalUnitUiKey.Key, args.User);
|
||||
}
|
||||
|
||||
private void OnAfterInteractUsing(EntityUid uid, DisposalUnitComponent component, AfterInteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled || !args.CanReach)
|
||||
return;
|
||||
|
||||
if (!HasComp<HandsComponent>(args.User))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CanInsert(uid, component, args.Used) || !_handsSystem.TryDropIntoContainer(args.User, args.Used, component.Container))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_adminLog.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(args.User):player} inserted {ToPrettyString(args.Used)} into {ToPrettyString(uid)}");
|
||||
AfterInsert(uid, component, args.Used, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
protected virtual void OnDisposalInit(Entity<DisposalUnitComponent> ent, ref ComponentInit args)
|
||||
{
|
||||
ent.Comp.Container = Containers.EnsureContainer<Container>(ent, DisposalUnitComponent.ContainerId);
|
||||
}
|
||||
|
||||
private void OnPowerChange(EntityUid uid, DisposalUnitComponent component, ref PowerChangedEvent args)
|
||||
{
|
||||
if (!component.Running)
|
||||
return;
|
||||
|
||||
UpdateUI((uid, component));
|
||||
UpdateVisualState(uid, component);
|
||||
|
||||
if (!args.Powered)
|
||||
{
|
||||
component.NextFlush = null;
|
||||
Dirty(uid, component);
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.Engaged)
|
||||
{
|
||||
// Run ManualEngage to recalculate a new flush time
|
||||
ManualEngage(uid, component);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnchorChanged(EntityUid uid, DisposalUnitComponent component, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
if (Terminating(uid))
|
||||
return;
|
||||
|
||||
UpdateVisualState(uid, component);
|
||||
if (!args.Anchored)
|
||||
TryEjectContents(uid, component);
|
||||
}
|
||||
|
||||
private void OnDragDropOn(EntityUid uid, DisposalUnitComponent component, ref DragDropTargetEvent args)
|
||||
{
|
||||
args.Handled = TryInsert(uid, args.Dragged, args.User);
|
||||
}
|
||||
|
||||
protected virtual void UpdateUI(Entity<DisposalUnitComponent> entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the estimated time when the disposal unit will be back to full pressure.
|
||||
/// </summary>
|
||||
public TimeSpan EstimatedFullPressure(EntityUid uid, DisposalUnitComponent component)
|
||||
{
|
||||
if (component.NextPressurized < GameTiming.CurTime)
|
||||
return TimeSpan.Zero;
|
||||
|
||||
return component.NextPressurized;
|
||||
}
|
||||
|
||||
public bool CanFlush(EntityUid unit, DisposalUnitComponent component)
|
||||
{
|
||||
return GetState(unit, component) == DisposalsPressureState.Ready
|
||||
&& _power.IsPowered(unit)
|
||||
&& Comp<TransformComponent>(unit).Anchored;
|
||||
}
|
||||
|
||||
public void Remove(EntityUid uid, DisposalUnitComponent component, EntityUid toRemove)
|
||||
{
|
||||
if (GameTiming.ApplyingState)
|
||||
return;
|
||||
|
||||
if (!Containers.Remove(toRemove, component.Container))
|
||||
return;
|
||||
|
||||
if (component.Container.ContainedEntities.Count == 0)
|
||||
{
|
||||
// If not manually engaged then reset the flushing entirely.
|
||||
if (!component.Engaged)
|
||||
{
|
||||
component.NextFlush = null;
|
||||
Dirty(uid, component);
|
||||
UpdateUI((uid, component));
|
||||
}
|
||||
}
|
||||
|
||||
_climb.Climb(toRemove, toRemove, uid, silent: true);
|
||||
|
||||
UpdateVisualState(uid, component);
|
||||
}
|
||||
|
||||
public void UpdateVisualState(EntityUid uid, DisposalUnitComponent component, bool flush = false)
|
||||
{
|
||||
if (!TryComp(uid, out AppearanceComponent? appearance))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Transform(uid).Anchored)
|
||||
{
|
||||
_appearance.SetData(uid, DisposalUnitComponent.Visuals.VisualState, DisposalUnitComponent.VisualState.UnAnchored, appearance);
|
||||
_appearance.SetData(uid, DisposalUnitComponent.Visuals.Handle, DisposalUnitComponent.HandleState.Normal, appearance);
|
||||
_appearance.SetData(uid, DisposalUnitComponent.Visuals.Light, DisposalUnitComponent.LightStates.Off, appearance);
|
||||
return;
|
||||
}
|
||||
|
||||
var state = GetState(uid, component);
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case DisposalsPressureState.Flushed:
|
||||
_appearance.SetData(uid, DisposalUnitComponent.Visuals.VisualState, DisposalUnitComponent.VisualState.OverlayFlushing, appearance);
|
||||
break;
|
||||
case DisposalsPressureState.Pressurizing:
|
||||
_appearance.SetData(uid, DisposalUnitComponent.Visuals.VisualState, DisposalUnitComponent.VisualState.OverlayCharging, appearance);
|
||||
break;
|
||||
case DisposalsPressureState.Ready:
|
||||
_appearance.SetData(uid, DisposalUnitComponent.Visuals.VisualState, DisposalUnitComponent.VisualState.Anchored, appearance);
|
||||
break;
|
||||
}
|
||||
|
||||
_appearance.SetData(uid, DisposalUnitComponent.Visuals.Handle, component.Engaged
|
||||
? DisposalUnitComponent.HandleState.Engaged
|
||||
: DisposalUnitComponent.HandleState.Normal, appearance);
|
||||
|
||||
if (!_power.IsPowered(uid))
|
||||
{
|
||||
_appearance.SetData(uid, DisposalUnitComponent.Visuals.Light, DisposalUnitComponent.LightStates.Off, appearance);
|
||||
return;
|
||||
}
|
||||
|
||||
var lightState = DisposalUnitComponent.LightStates.Off;
|
||||
|
||||
if (component.Container.ContainedEntities.Count > 0)
|
||||
{
|
||||
lightState |= DisposalUnitComponent.LightStates.Full;
|
||||
}
|
||||
|
||||
if (state is DisposalsPressureState.Pressurizing or DisposalsPressureState.Flushed)
|
||||
{
|
||||
lightState |= DisposalUnitComponent.LightStates.Charging;
|
||||
}
|
||||
else
|
||||
{
|
||||
lightState |= DisposalUnitComponent.LightStates.Ready;
|
||||
}
|
||||
|
||||
_appearance.SetData(uid, DisposalUnitComponent.Visuals.Light, lightState, appearance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current pressure state of a disposals unit.
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <param name="component"></param>
|
||||
/// <param name="metadata"></param>
|
||||
/// <returns></returns>
|
||||
public DisposalsPressureState GetState(EntityUid uid, DisposalUnitComponent component, MetaDataComponent? metadata = null)
|
||||
{
|
||||
var nextPressure = Metadata.GetPauseTime(uid, metadata) + component.NextPressurized - GameTiming.CurTime;
|
||||
var pressurizeTime = 1f / PressurePerSecond;
|
||||
var pressurizeDuration = pressurizeTime - component.FlushDelay.TotalSeconds;
|
||||
|
||||
if (nextPressure.TotalSeconds > pressurizeDuration)
|
||||
{
|
||||
return DisposalsPressureState.Flushed;
|
||||
}
|
||||
|
||||
if (nextPressure > TimeSpan.Zero)
|
||||
{
|
||||
return DisposalsPressureState.Pressurizing;
|
||||
}
|
||||
|
||||
return DisposalsPressureState.Ready;
|
||||
}
|
||||
|
||||
public float GetPressure(EntityUid uid, DisposalUnitComponent component, MetaDataComponent? metadata = null)
|
||||
{
|
||||
if (!Resolve(uid, ref metadata))
|
||||
return 0f;
|
||||
|
||||
var pauseTime = Metadata.GetPauseTime(uid, metadata);
|
||||
return MathF.Min(1f,
|
||||
(float)(GameTiming.CurTime - pauseTime - component.NextPressurized).TotalSeconds / PressurePerSecond);
|
||||
}
|
||||
|
||||
protected void OnPreventCollide(EntityUid uid, DisposalUnitComponent component,
|
||||
ref PreventCollideEvent args)
|
||||
{
|
||||
var otherBody = args.OtherEntity;
|
||||
|
||||
// Items dropped shouldn't collide but items thrown should
|
||||
if (HasComp<ItemComponent>(otherBody) && !HasComp<ThrownItemComponent>(otherBody))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnCanDragDropOn(EntityUid uid, DisposalUnitComponent component, ref CanDropTargetEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.CanDrop = CanInsert(uid, component, args.Dragged);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
protected void OnEmagged(EntityUid uid, DisposalUnitComponent component, ref GotEmaggedEvent args)
|
||||
{
|
||||
component.DisablePressure = true;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
public virtual bool CanInsert(EntityUid uid, DisposalUnitComponent component, EntityUid entity)
|
||||
{
|
||||
// TODO: All of the below should be using the EXISTING EVENT
|
||||
if (!Containers.CanInsert(entity, component.Container))
|
||||
return false;
|
||||
|
||||
if (!Transform(uid).Anchored)
|
||||
return false;
|
||||
|
||||
var storable = HasComp<ItemComponent>(entity);
|
||||
if (!storable && !HasComp<BodyComponent>(entity))
|
||||
return false;
|
||||
|
||||
if (_whitelistSystem.IsBlacklistPass(component.Blacklist, entity) ||
|
||||
_whitelistSystem.IsWhitelistFail(component.Whitelist, entity))
|
||||
return false;
|
||||
|
||||
if (TryComp<PhysicsComponent>(entity, out var physics) && (physics.CanCollide) || storable)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public void DoInsertDisposalUnit(EntityUid uid,
|
||||
EntityUid toInsert,
|
||||
EntityUid user,
|
||||
DisposalUnitComponent? disposal = null)
|
||||
{
|
||||
if (!Resolve(uid, ref disposal))
|
||||
return;
|
||||
|
||||
if (!Containers.Insert(toInsert, disposal.Container))
|
||||
return;
|
||||
|
||||
_adminLog.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(user):player} inserted {ToPrettyString(toInsert)} into {ToPrettyString(uid)}");
|
||||
AfterInsert(uid, disposal, toInsert, user);
|
||||
}
|
||||
|
||||
public virtual void AfterInsert(EntityUid uid,
|
||||
DisposalUnitComponent component,
|
||||
EntityUid inserted,
|
||||
EntityUid? user = null,
|
||||
bool doInsert = false)
|
||||
{
|
||||
Audio.PlayPredicted(component.InsertSound, uid, user: user);
|
||||
if (doInsert && !Containers.Insert(inserted, component.Container))
|
||||
return;
|
||||
|
||||
if (user != inserted && user != null)
|
||||
_adminLog.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(user.Value):player} inserted {ToPrettyString(inserted)} into {ToPrettyString(uid)}");
|
||||
|
||||
QueueAutomaticEngage(uid, component);
|
||||
|
||||
_ui.CloseUi(uid, DisposalUnitComponent.DisposalUnitUiKey.Key, inserted);
|
||||
|
||||
// Maybe do pullable instead? Eh still fine.
|
||||
Joints.RecursiveClearJoints(inserted);
|
||||
UpdateVisualState(uid, component);
|
||||
}
|
||||
|
||||
public bool TryInsert(EntityUid unitId, EntityUid toInsertId, EntityUid? userId, DisposalUnitComponent? unit = null)
|
||||
{
|
||||
if (!Resolve(unitId, ref unit))
|
||||
return false;
|
||||
|
||||
if (userId.HasValue && !HasComp<HandsComponent>(userId) && toInsertId != userId) // Mobs like mouse can Jump inside even with no hands
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("disposal-unit-no-hands"), userId.Value, userId.Value, PopupType.SmallCaution);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CanInsert(unitId, unit, toInsertId))
|
||||
return false;
|
||||
|
||||
bool insertingSelf = userId == toInsertId;
|
||||
|
||||
var delay = insertingSelf ? unit.EntryDelay : unit.DraggedEntryDelay;
|
||||
|
||||
if (userId != null && !insertingSelf)
|
||||
_popupSystem.PopupEntity(Loc.GetString("disposal-unit-being-inserted", ("user", Identity.Entity((EntityUid)userId, EntityManager))), toInsertId, toInsertId, PopupType.Large);
|
||||
|
||||
if (delay <= 0 || userId == null)
|
||||
{
|
||||
AfterInsert(unitId, unit, toInsertId, userId, doInsert: true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Can't check if our target AND disposals moves currently so we'll just check target.
|
||||
// if you really want to check if disposals moves then add a predicate.
|
||||
var doAfterArgs = new DoAfterArgs(EntityManager, userId.Value, delay, new DisposalDoAfterEvent(), unitId, target: toInsertId, used: unitId)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
BreakOnMove = true,
|
||||
NeedHand = false,
|
||||
};
|
||||
|
||||
_doAfterSystem.TryStartDoAfter(doAfterArgs);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void UpdateState(EntityUid uid, DisposalsPressureState state, DisposalUnitComponent component, MetaDataComponent metadata)
|
||||
{
|
||||
if (component.State == state)
|
||||
return;
|
||||
|
||||
component.State = state;
|
||||
UpdateVisualState(uid, component);
|
||||
Dirty(uid, component, metadata);
|
||||
|
||||
if (state == DisposalsPressureState.Ready)
|
||||
{
|
||||
component.NextPressurized = TimeSpan.Zero;
|
||||
|
||||
// Manually engaged
|
||||
if (component.Engaged)
|
||||
{
|
||||
component.NextFlush = GameTiming.CurTime + component.ManualFlushTime;
|
||||
}
|
||||
else if (component.Container.ContainedEntities.Count > 0)
|
||||
{
|
||||
component.NextFlush = GameTiming.CurTime + component.AutomaticEngageTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
component.NextFlush = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Work out if we can stop updating this disposals component i.e. full pressure and nothing colliding.
|
||||
/// </summary>
|
||||
private void Update(EntityUid uid, DisposalUnitComponent component, MetaDataComponent metadata)
|
||||
{
|
||||
var state = GetState(uid, component, metadata);
|
||||
|
||||
// Pressurizing, just check if we need a state update.
|
||||
if (component.NextPressurized > GameTiming.CurTime)
|
||||
{
|
||||
UpdateState(uid, state, component, metadata);
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.NextFlush != null)
|
||||
{
|
||||
if (component.NextFlush.Value < GameTiming.CurTime)
|
||||
{
|
||||
TryFlush(uid, component);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateState(uid, state, component, metadata);
|
||||
}
|
||||
|
||||
public bool TryFlush(EntityUid uid, DisposalUnitComponent component)
|
||||
{
|
||||
if (!CanFlush(uid, component))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (component.NextFlush != null)
|
||||
component.NextFlush = component.NextFlush.Value + component.AutomaticEngageTime;
|
||||
|
||||
var beforeFlushArgs = new BeforeDisposalFlushEvent();
|
||||
RaiseLocalEvent(uid, beforeFlushArgs);
|
||||
|
||||
if (beforeFlushArgs.Cancelled)
|
||||
{
|
||||
Disengage(uid, component);
|
||||
return false;
|
||||
}
|
||||
|
||||
var xform = Transform(uid);
|
||||
if (!TryComp(xform.GridUid, out MapGridComponent? grid))
|
||||
return false;
|
||||
|
||||
var coords = xform.Coordinates;
|
||||
var entry = _map.GetLocal(xform.GridUid.Value, grid, coords)
|
||||
.FirstOrDefault(HasComp<Tube.DisposalEntryComponent>);
|
||||
|
||||
if (entry == default || component is not DisposalUnitComponent sDisposals)
|
||||
{
|
||||
component.Engaged = false;
|
||||
UpdateUI((uid, component));
|
||||
Dirty(uid, component);
|
||||
return false;
|
||||
}
|
||||
|
||||
HandleAir(uid, sDisposals, xform);
|
||||
|
||||
_disposalTubeSystem.TryInsert(entry, sDisposals, beforeFlushArgs.Tags);
|
||||
|
||||
component.NextPressurized = GameTiming.CurTime;
|
||||
if (!component.DisablePressure)
|
||||
component.NextPressurized += TimeSpan.FromSeconds(1f / PressurePerSecond);
|
||||
|
||||
component.Engaged = false;
|
||||
// stop queuing NOW
|
||||
component.NextFlush = null;
|
||||
|
||||
UpdateVisualState(uid, component, true);
|
||||
Dirty(uid, component);
|
||||
UpdateUI((uid, component));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void HandleAir(EntityUid uid, DisposalUnitComponent component, TransformComponent xform)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ManualEngage(EntityUid uid, DisposalUnitComponent component, MetaDataComponent? metadata = null)
|
||||
{
|
||||
component.Engaged = true;
|
||||
UpdateVisualState(uid, component);
|
||||
Dirty(uid, component);
|
||||
UpdateUI((uid, component));
|
||||
|
||||
if (!CanFlush(uid, component))
|
||||
return;
|
||||
|
||||
if (!Resolve(uid, ref metadata))
|
||||
return;
|
||||
|
||||
var pauseTime = Metadata.GetPauseTime(uid, metadata);
|
||||
var nextEngage = GameTiming.CurTime - pauseTime + component.ManualFlushTime;
|
||||
component.NextFlush = TimeSpan.FromSeconds(Math.Min((component.NextFlush ?? TimeSpan.MaxValue).TotalSeconds, nextEngage.TotalSeconds));
|
||||
}
|
||||
|
||||
public void Disengage(EntityUid uid, DisposalUnitComponent component)
|
||||
{
|
||||
component.Engaged = false;
|
||||
|
||||
if (component.Container.ContainedEntities.Count == 0)
|
||||
{
|
||||
component.NextFlush = null;
|
||||
}
|
||||
|
||||
UpdateVisualState(uid, component);
|
||||
Dirty(uid, component);
|
||||
UpdateUI((uid, component));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all entities currently in the disposal unit.
|
||||
/// </summary>
|
||||
public void TryEjectContents(EntityUid uid, DisposalUnitComponent component)
|
||||
{
|
||||
foreach (var entity in component.Container.ContainedEntities.ToArray())
|
||||
{
|
||||
Remove(uid, component, entity);
|
||||
}
|
||||
|
||||
if (!component.Engaged)
|
||||
{
|
||||
component.NextFlush = null;
|
||||
Dirty(uid, component);
|
||||
UpdateUI((uid, component));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If something is inserted (or the likes) then we'll queue up an automatic flush in the future.
|
||||
/// </summary>
|
||||
public void QueueAutomaticEngage(EntityUid uid, DisposalUnitComponent component, MetaDataComponent? metadata = null)
|
||||
{
|
||||
if (component.Deleted || !component.AutomaticEngage || !_power.IsPowered(uid) && component.Container.ContainedEntities.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var pauseTime = Metadata.GetPauseTime(uid, metadata);
|
||||
var automaticTime = GameTiming.CurTime + component.AutomaticEngageTime - pauseTime;
|
||||
var flushTime = TimeSpan.FromSeconds(Math.Min((component.NextFlush ?? TimeSpan.MaxValue).TotalSeconds, automaticTime.TotalSeconds));
|
||||
|
||||
component.NextFlush = flushTime;
|
||||
Dirty(uid, component);
|
||||
UpdateUI((uid, component));
|
||||
}
|
||||
|
||||
private void OnUiButtonPressed(EntityUid uid, DisposalUnitComponent component, DisposalUnitComponent.UiButtonPressedMessage args)
|
||||
{
|
||||
if (args.Actor is not { Valid: true } player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args.Button)
|
||||
{
|
||||
case DisposalUnitComponent.UiButton.Eject:
|
||||
TryEjectContents(uid, component);
|
||||
_adminLog.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(player):player} hit eject button on {ToPrettyString(uid)}");
|
||||
break;
|
||||
case DisposalUnitComponent.UiButton.Engage:
|
||||
ToggleEngage(uid, component);
|
||||
_adminLog.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(player):player} hit flush button on {ToPrettyString(uid)}, it's now {(component.Engaged ? "on" : "off")}");
|
||||
break;
|
||||
case DisposalUnitComponent.UiButton.Power:
|
||||
_power.TogglePower(uid, user: args.Actor);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException($"{ToPrettyString(player):player} attempted to hit a nonexistant button on {ToPrettyString(uid)}");
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleEngage(EntityUid uid, DisposalUnitComponent component)
|
||||
{
|
||||
component.Engaged ^= true;
|
||||
|
||||
if (component.Engaged)
|
||||
{
|
||||
ManualEngage(uid, component);
|
||||
}
|
||||
else
|
||||
{
|
||||
Disengage(uid, component);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddClimbInsideVerb(EntityUid uid, DisposalUnitComponent component, GetVerbsEvent<Verb> args)
|
||||
{
|
||||
// This is not an interaction, activation, or alternative verb type because unfortunately most users are
|
||||
// unwilling to accept that this is where they belong and don't want to accidentally climb inside.
|
||||
if (!args.CanAccess ||
|
||||
!args.CanInteract ||
|
||||
component.Container.ContainedEntities.Contains(args.User) ||
|
||||
!ActionBlockerSystem.CanMove(args.User))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CanInsert(uid, component, args.User))
|
||||
return;
|
||||
|
||||
// Add verb to climb inside of the unit,
|
||||
Verb verb = new()
|
||||
{
|
||||
Act = () => TryInsert(uid, args.User, args.User),
|
||||
DoContactInteraction = true,
|
||||
Text = Loc.GetString("disposal-self-insert-verb-get-data-text")
|
||||
};
|
||||
// TODO VERB ICON
|
||||
// TODO VERB CATEGORY
|
||||
// create a verb category for "enter"?
|
||||
// See also, medical scanner. Also maybe add verbs for entering lockers/body bags?
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
}
|
||||
@@ -84,5 +84,51 @@ namespace Content.Shared.Doors.Components
|
||||
public bool Powered;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Client animation
|
||||
|
||||
/// <summary>
|
||||
/// The sprite state used to animate the airlock frame when the airlock opens.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string OpeningLightSpriteState = "opening_unlit";
|
||||
|
||||
/// <summary>
|
||||
/// The sprite state used to animate the airlock frame when the airlock closes.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string ClosingLightSpriteState = "closing_unlit";
|
||||
|
||||
/// <summary>
|
||||
/// The sprite state used to animate the airlock panel when the airlock opens.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string OpeningPanelSpriteState = "panel_opening";
|
||||
|
||||
/// <summary>
|
||||
/// The sprite state used to animate the airlock panel when the airlock closes.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string ClosingPanelSpriteState = "panel_closing";
|
||||
|
||||
/// <summary>
|
||||
/// The sprite state used for the open airlock lights.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string OpenLightSpriteState = "open_unlit";
|
||||
|
||||
/// <summary>
|
||||
/// The sprite state used for the closed airlock lights.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string WarningLightSpriteState = "closed_unlit";
|
||||
|
||||
/// <summary>
|
||||
/// The sprite state used for the 'access denied' lights animation.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string DenySpriteState = "deny_unlit";
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
77
Content.Shared/Doors/Components/TurnstileComponent.cs
Normal file
77
Content.Shared/Doors/Components/TurnstileComponent.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Content.Shared.Doors.Systems;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Doors.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is used for a condition door that allows entry only through a single side.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
|
||||
[Access(typeof(SharedTurnstileSystem))]
|
||||
public sealed partial class TurnstileComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// A whitelist of the things this turnstile can choose to block or let through.
|
||||
/// Things not in this whitelist will be ignored by default.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public EntityWhitelist? ProcessWhitelist;
|
||||
|
||||
/// <summary>
|
||||
/// The next time at which the resist message can show.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField, AutoPausedField]
|
||||
public TimeSpan NextResistTime;
|
||||
|
||||
/// <summary>
|
||||
/// Maintained hashset of entities currently passing through the turnstile.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public HashSet<EntityUid> CollideExceptions = new();
|
||||
|
||||
/// <summary>
|
||||
/// default state of the turnstile sprite.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string DefaultState = "turnstile";
|
||||
|
||||
/// <summary>
|
||||
/// animation state of the turnstile spinning.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string SpinState = "operate";
|
||||
|
||||
/// <summary>
|
||||
/// animation state of the turnstile denying entry.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string DenyState = "deny";
|
||||
|
||||
/// <summary>
|
||||
/// Sound to play when the turnstile admits a mob through.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier? TurnSound = new SoundPathSpecifier("/Audio/Items/ratchet.ogg", AudioParams.Default.WithVolume(-6));
|
||||
|
||||
/// <summary>
|
||||
/// Sound to play when the turnstile denies entry
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier? DenySound = new SoundPathSpecifier("/Audio/Machines/airlock_deny.ogg")
|
||||
{
|
||||
Params = new()
|
||||
{
|
||||
Volume = -7,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum TurnstileVisualLayers : byte
|
||||
{
|
||||
Base
|
||||
}
|
||||
@@ -768,10 +768,13 @@ public abstract partial class SharedDoorSystem : EntitySystem
|
||||
var door = ent.Comp;
|
||||
door.NextStateChange = null;
|
||||
|
||||
if (door.CurrentlyCrushing.Count > 0)
|
||||
if (door.CurrentlyCrushing.Count > 0 && door.State != DoorState.Opening)
|
||||
{
|
||||
// This is a closed door that is crushing people and needs to auto-open. Note that we don't check "can open"
|
||||
// here. The door never actually finished closing and we don't want people to get stuck inside of doors.
|
||||
StartOpening(ent, door);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (door.State)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Shared.Doors.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Prying.Components;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Doors.Systems;
|
||||
@@ -27,7 +28,7 @@ public abstract class SharedFirelockSystem : EntitySystem
|
||||
|
||||
// Visuals
|
||||
SubscribeLocalEvent<FirelockComponent, MapInitEvent>(UpdateVisuals);
|
||||
SubscribeLocalEvent<FirelockComponent, ComponentStartup>(UpdateVisuals);
|
||||
SubscribeLocalEvent<FirelockComponent, ComponentStartup>(OnComponentStartup);
|
||||
|
||||
SubscribeLocalEvent<FirelockComponent, ExaminedEvent>(OnExamined);
|
||||
}
|
||||
@@ -104,6 +105,11 @@ public abstract class SharedFirelockSystem : EntitySystem
|
||||
|
||||
#region Visuals
|
||||
|
||||
protected virtual void OnComponentStartup(Entity<FirelockComponent> ent, ref ComponentStartup args)
|
||||
{
|
||||
UpdateVisuals(ent.Owner,ent.Comp, args);
|
||||
}
|
||||
|
||||
private void UpdateVisuals(EntityUid uid, FirelockComponent component, EntityEventArgs args) => UpdateVisuals(uid, component);
|
||||
|
||||
private void UpdateVisuals(EntityUid uid,
|
||||
@@ -142,3 +148,22 @@ public abstract class SharedFirelockSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum FirelockVisuals : byte
|
||||
{
|
||||
PressureWarning,
|
||||
TemperatureWarning,
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum FirelockVisualLayersPressure : byte
|
||||
{
|
||||
Base
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum FirelockVisualLayersTemperature : byte
|
||||
{
|
||||
Base
|
||||
}
|
||||
|
||||
135
Content.Shared/Doors/Systems/SharedTurnstileSystem.cs
Normal file
135
Content.Shared/Doors/Systems/SharedTurnstileSystem.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.Doors.Components;
|
||||
using Content.Shared.Movement.Pulling.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Doors.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// This handles logic and interactions related to <see cref="TurnstileComponent"/>
|
||||
/// </summary>
|
||||
public abstract partial class SharedTurnstileSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly EntityWhitelistSystem _entityWhitelist = default!;
|
||||
[Dependency] private readonly PullingSystem _pulling = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<TurnstileComponent, PreventCollideEvent>(OnPreventCollide);
|
||||
SubscribeLocalEvent<TurnstileComponent, StartCollideEvent>(OnStartCollide);
|
||||
SubscribeLocalEvent<TurnstileComponent, EndCollideEvent>(OnEndCollide);
|
||||
}
|
||||
|
||||
private void OnPreventCollide(Entity<TurnstileComponent> ent, ref PreventCollideEvent args)
|
||||
{
|
||||
if (args.Cancelled || !args.OurFixture.Hard || !args.OtherFixture.Hard)
|
||||
return;
|
||||
|
||||
if (ent.Comp.CollideExceptions.Contains(args.OtherEntity))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to add this in here too for chain pulls
|
||||
if (_pulling.GetPuller(args.OtherEntity) is { } puller && ent.Comp.CollideExceptions.Contains(puller))
|
||||
{
|
||||
ent.Comp.CollideExceptions.Add(args.OtherEntity);
|
||||
Dirty(ent);
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// unblockables go through for free.
|
||||
if (_entityWhitelist.IsWhitelistFail(ent.Comp.ProcessWhitelist, args.OtherEntity))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (CanPassDirection(ent, args.OtherEntity))
|
||||
{
|
||||
if (!_accessReader.IsAllowed(args.OtherEntity, ent))
|
||||
return;
|
||||
|
||||
ent.Comp.CollideExceptions.Add(args.OtherEntity);
|
||||
if (_pulling.GetPulling(args.OtherEntity) is { } uid)
|
||||
ent.Comp.CollideExceptions.Add(uid);
|
||||
|
||||
args.Cancelled = true;
|
||||
Dirty(ent);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_timing.CurTime >= ent.Comp.NextResistTime)
|
||||
{
|
||||
_popup.PopupClient(Loc.GetString("turnstile-component-popup-resist", ("turnstile", ent.Owner)), ent, args.OtherEntity);
|
||||
ent.Comp.NextResistTime = _timing.CurTime + TimeSpan.FromSeconds(0.1);
|
||||
Dirty(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStartCollide(Entity<TurnstileComponent> ent, ref StartCollideEvent args)
|
||||
{
|
||||
if (!ent.Comp.CollideExceptions.Contains(args.OtherEntity))
|
||||
{
|
||||
if (CanPassDirection(ent, args.OtherEntity))
|
||||
{
|
||||
if (!_accessReader.IsAllowed(args.OtherEntity, ent))
|
||||
{
|
||||
_audio.PlayPredicted(ent.Comp.DenySound, ent, args.OtherEntity);
|
||||
PlayAnimation(ent, ent.Comp.DenyState);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
// if they passed through:
|
||||
PlayAnimation(ent, ent.Comp.SpinState);
|
||||
_audio.PlayPredicted(ent.Comp.TurnSound, ent, args.OtherEntity);
|
||||
}
|
||||
|
||||
private void OnEndCollide(Entity<TurnstileComponent> ent, ref EndCollideEvent args)
|
||||
{
|
||||
if (!args.OurFixture.Hard)
|
||||
{
|
||||
ent.Comp.CollideExceptions.Remove(args.OtherEntity);
|
||||
Dirty(ent);
|
||||
}
|
||||
}
|
||||
|
||||
protected bool CanPassDirection(Entity<TurnstileComponent> ent, EntityUid other)
|
||||
{
|
||||
var xform = Transform(ent);
|
||||
var otherXform = Transform(other);
|
||||
|
||||
var (pos, rot) = _transform.GetWorldPositionRotation(xform);
|
||||
var otherPos = _transform.GetWorldPosition(otherXform);
|
||||
|
||||
var approachAngle = (pos - otherPos).ToAngle();
|
||||
var rotateAngle = rot.ToWorldVec().ToAngle();
|
||||
|
||||
var diff = Math.Abs(approachAngle - rotateAngle);
|
||||
diff %= MathHelper.TwoPi;
|
||||
if (diff > Math.PI)
|
||||
diff = MathHelper.TwoPi - diff;
|
||||
|
||||
return diff < Math.PI / 4;
|
||||
}
|
||||
|
||||
protected virtual void PlayAnimation(EntityUid uid, string stateId)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ namespace Content.Shared.Emag.Systems;
|
||||
public sealed class EmagSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly SharedChargesSystem _charges = default!;
|
||||
[Dependency] private readonly SharedChargesSystem _sharedCharges = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly TagSystem _tag = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
@@ -61,8 +61,8 @@ public sealed class EmagSystem : EntitySystem
|
||||
if (_tag.HasTag(target, ent.Comp.EmagImmuneTag))
|
||||
return false;
|
||||
|
||||
TryComp<LimitedChargesComponent>(ent, out var charges);
|
||||
if (_charges.IsEmpty(ent, charges))
|
||||
Entity<LimitedChargesComponent?> chargesEnt = ent.Owner;
|
||||
if (_sharedCharges.IsEmpty(chargesEnt))
|
||||
{
|
||||
_popup.PopupClient(Loc.GetString("emag-no-charges"), user, user);
|
||||
return false;
|
||||
@@ -80,8 +80,8 @@ public sealed class EmagSystem : EntitySystem
|
||||
|
||||
_adminLogger.Add(LogType.Emag, LogImpact.High, $"{ToPrettyString(user):player} emagged {ToPrettyString(target):target} with flag(s): {ent.Comp.EmagType}");
|
||||
|
||||
if (charges != null && emaggedEvent.Handled)
|
||||
_charges.UseCharge(ent, charges);
|
||||
if (emaggedEvent.Handled)
|
||||
_sharedCharges.TryUseCharge(chargesEnt);
|
||||
|
||||
if (!emaggedEvent.Repeatable)
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user