Merge remote-tracking branch 'refs/remotes/upstream/master' into ed-17-05-2024-upstream

This commit is contained in:
Ed
2024-05-17 12:57:04 +03:00
58 changed files with 3724 additions and 4985 deletions

View File

@@ -46,4 +46,7 @@ public sealed partial class IdCardComponent : Component
[DataField]
public LocId FullNameLocId = "access-id-card-component-owner-full-name-job-title-text";
[DataField]
public bool CanMicrowave = true;
}

View File

@@ -1,29 +1,85 @@
using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Rejuvenate;
using Robust.Shared.Containers;
using Robust.Shared.Timing;
namespace Content.Shared.Atmos.Rotting;
public abstract class SharedRottingSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
public const int MaxStages = 3;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PerishableComponent, MapInitEvent>(OnPerishableMapInit);
SubscribeLocalEvent<PerishableComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<PerishableComponent, ExaminedEvent>(OnPerishableExamined);
SubscribeLocalEvent<RottingComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<RottingComponent, MobStateChangedEvent>(OnRottingMobStateChanged);
SubscribeLocalEvent<RottingComponent, RejuvenateEvent>(OnRejuvenate);
SubscribeLocalEvent<RottingComponent, ExaminedEvent>(OnExamined);
}
/// <summary>
/// Return the rot stage, usually from 0 to 2 inclusive.
/// </summary>
public int RotStage(EntityUid uid, RottingComponent? comp = null, PerishableComponent? perishable = null)
private void OnPerishableMapInit(EntityUid uid, PerishableComponent component, MapInitEvent args)
{
if (!Resolve(uid, ref comp, ref perishable))
return 0;
component.RotNextUpdate = _timing.CurTime + component.PerishUpdateRate;
}
return (int) (comp.TotalRotTime.TotalSeconds / perishable.RotAfter.TotalSeconds);
private void OnMobStateChanged(EntityUid uid, PerishableComponent component, MobStateChangedEvent args)
{
if (args.NewMobState != MobState.Dead && args.OldMobState != MobState.Dead)
return;
if (HasComp<RottingComponent>(uid))
return;
component.RotAccumulator = TimeSpan.Zero;
component.RotNextUpdate = _timing.CurTime + component.PerishUpdateRate;
}
private void OnPerishableExamined(Entity<PerishableComponent> perishable, ref ExaminedEvent args)
{
int stage = PerishStage(perishable, MaxStages);
if (stage < 1 || stage > MaxStages)
{
// We dont push an examined string if it hasen't started "perishing" or it's already rotting
return;
}
var isMob = HasComp<MobStateComponent>(perishable);
var description = "perishable-" + stage + (!isMob ? "-nonmob" : string.Empty);
args.PushMarkup(Loc.GetString(description, ("target", Identity.Entity(perishable, EntityManager))));
}
private void OnShutdown(EntityUid uid, RottingComponent component, ComponentShutdown args)
{
if (TryComp<PerishableComponent>(uid, out var perishable))
{
perishable.RotNextUpdate = TimeSpan.Zero;
}
}
private void OnRottingMobStateChanged(EntityUid uid, RottingComponent component, MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead)
return;
RemCompDeferred(uid, component);
}
private void OnRejuvenate(EntityUid uid, RottingComponent component, RejuvenateEvent args)
{
RemCompDeferred<RottingComponent>(uid);
}
private void OnExamined(EntityUid uid, RottingComponent component, ExaminedEvent args)
@@ -41,4 +97,75 @@ public abstract class SharedRottingSystem : EntitySystem
args.PushMarkup(Loc.GetString(description, ("target", Identity.Entity(uid, EntityManager))));
}
/// <summary>
/// Return an integer from 0 to maxStage representing how close to rotting an entity is. Used to
/// generate examine messages for items that are starting to rot.
/// </summary>
public int PerishStage(Entity<PerishableComponent> perishable, int maxStages)
{
if (perishable.Comp.RotAfter.TotalSeconds == 0 || perishable.Comp.RotAccumulator.TotalSeconds == 0)
return 0;
return (int)(1 + maxStages * perishable.Comp.RotAccumulator.TotalSeconds / perishable.Comp.RotAfter.TotalSeconds);
}
public bool IsRotProgressing(EntityUid uid, PerishableComponent? perishable)
{
// things don't perish by default.
if (!Resolve(uid, ref perishable, false))
return false;
// only dead things or inanimate objects can rot
if (TryComp<MobStateComponent>(uid, out var mobState) && !_mobState.IsDead(uid, mobState))
return false;
if (_container.TryGetOuterContainer(uid, Transform(uid), out var container) &&
HasComp<AntiRottingContainerComponent>(container.Owner))
{
return false;
}
var ev = new IsRottingEvent();
RaiseLocalEvent(uid, ref ev);
return !ev.Handled;
}
public bool IsRotten(EntityUid uid, RottingComponent? rotting = null)
{
return Resolve(uid, ref rotting, false);
}
public void ReduceAccumulator(EntityUid uid, TimeSpan time)
{
if (!TryComp<PerishableComponent>(uid, out var perishable))
return;
if (!TryComp<RottingComponent>(uid, out var rotting))
{
perishable.RotAccumulator -= time;
return;
}
var total = (rotting.TotalRotTime + perishable.RotAccumulator) - time;
if (total < perishable.RotAfter)
{
RemCompDeferred(uid, rotting);
perishable.RotAccumulator = total;
}
else
rotting.TotalRotTime = total - perishable.RotAfter;
}
/// <summary>
/// Return the rot stage, usually from 0 to 2 inclusive.
/// </summary>
public int RotStage(EntityUid uid, RottingComponent? comp = null, PerishableComponent? perishable = null)
{
if (!Resolve(uid, ref comp, ref perishable))
return 0;
return (int) (comp.TotalRotTime.TotalSeconds / perishable.RotAfter.TotalSeconds);
}
}

View File

@@ -573,13 +573,13 @@ namespace Content.Shared.CCVar
/// When a mob is walking should its X / Y movement be relative to its parent (true) or the map (false).
/// </summary>
public static readonly CVarDef<bool> RelativeMovement =
CVarDef.Create("physics.relative_movement", true, CVar.ARCHIVE | CVar.REPLICATED);
CVarDef.Create("physics.relative_movement", true, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
public static readonly CVarDef<float> TileFrictionModifier =
CVarDef.Create("physics.tile_friction", 40.0f, CVar.ARCHIVE | CVar.REPLICATED);
CVarDef.Create("physics.tile_friction", 40.0f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
public static readonly CVarDef<float> StopSpeed =
CVarDef.Create("physics.stop_speed", 0.1f, CVar.ARCHIVE | CVar.REPLICATED);
CVarDef.Create("physics.stop_speed", 0.1f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// Whether mobs can push objects like lockers.
@@ -588,7 +588,7 @@ namespace Content.Shared.CCVar
/// Technically client doesn't need to know about it but this may prevent a bug in the distant future so it stays.
/// </remarks>
public static readonly CVarDef<bool> MobPushing =
CVarDef.Create("physics.mob_pushing", false, CVar.REPLICATED);
CVarDef.Create("physics.mob_pushing", false, CVar.REPLICATED | CVar.SERVER);
/*
* Music
@@ -1547,10 +1547,10 @@ namespace Content.Shared.CCVar
CVarDef.Create("viewport.scale_render", true, CVar.CLIENTONLY | CVar.ARCHIVE);
public static readonly CVarDef<int> ViewportMinimumWidth =
CVarDef.Create("viewport.minimum_width", 15, CVar.REPLICATED);
CVarDef.Create("viewport.minimum_width", 15, CVar.REPLICATED | CVar.SERVER);
public static readonly CVarDef<int> ViewportMaximumWidth =
CVarDef.Create("viewport.maximum_width", 21, CVar.REPLICATED);
CVarDef.Create("viewport.maximum_width", 21, CVar.REPLICATED | CVar.SERVER);
public static readonly CVarDef<int> ViewportWidth =
CVarDef.Create("viewport.width", 21, CVar.CLIENTONLY | CVar.ARCHIVE);
@@ -1655,7 +1655,7 @@ namespace Content.Shared.CCVar
CVarDef.Create("chat.chat_sanitizer_enabled", true, CVar.SERVERONLY);
public static readonly CVarDef<bool> ChatShowTypingIndicator =
CVarDef.Create("chat.show_typing_indicator", true, CVar.CLIENTONLY);
CVarDef.Create("chat.show_typing_indicator", true, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
public static readonly CVarDef<bool> ChatEnableFancyBubbles =
CVarDef.Create("chat.enable_fancy_bubbles", true, CVar.CLIENTONLY | CVar.ARCHIVE, "Toggles displaying fancy speech bubbles, which display the speaking character's name.");

View File

@@ -152,10 +152,16 @@ public abstract class SharedChatSystem : EntitySystem
if (string.IsNullOrEmpty(message))
return message;
// Capitalize first letter
message = char.ToUpper(message[0]) + message.Remove(0, 1);
message = OopsConcat(char.ToUpper(message[0]).ToString(), message.Remove(0, 1));
return message;
}
private static string OopsConcat(string a, string b)
{
// This exists to prevent Roslyn being clever and compiling something that fails sandbox checks.
return a + b;
}
public string SanitizeMessageCapitalizeTheWordI(string message, string theWordI = "i")
{
if (string.IsNullOrEmpty(message))

View File

@@ -1,4 +1,5 @@
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.Serialization;
namespace Content.Shared.Chemistry
@@ -93,11 +94,11 @@ namespace Content.Shared.Chemistry
}
[Serializable, NetSerializable]
public sealed class ReagentInventoryItem(string storageSlotId, string reagentLabel, string storedAmount, Color reagentColor)
public sealed class ReagentInventoryItem(string storageSlotId, string reagentLabel, FixedPoint2 quantity, Color reagentColor)
{
public string StorageSlotId = storageSlotId;
public string ReagentLabel = reagentLabel;
public string StoredAmount = storedAmount;
public FixedPoint2 Quantity = quantity;
public Color ReagentColor = reagentColor;
}

View File

@@ -1,52 +1,6 @@
using Content.Shared.IdentityManagement;
using Content.Shared.IdentityManagement.Components;
using Content.Shared.Security;
using Content.Shared.Security.Components;
namespace Content.Shared.CriminalRecords.Systems;
public abstract class SharedCriminalRecordsConsoleSystem : EntitySystem
{
/// <summary>
/// Any entity that has a the name of the record that was just changed as their visible name will get their icon
/// updated with the new status, if the record got removed their icon will be removed too.
/// </summary>
public void UpdateCriminalIdentity(string name, SecurityStatus status)
{
var query = EntityQueryEnumerator<IdentityComponent>();
while (query.MoveNext(out var uid, out var identity))
{
if (!Identity.Name(uid, EntityManager).Equals(name))
continue;
if (status == SecurityStatus.None)
RemComp<CriminalRecordComponent>(uid);
else
SetCriminalIcon(name, status, uid);
}
}
/// <summary>
/// Decides the icon that should be displayed on the entity based on the security status
/// </summary>
public void SetCriminalIcon(string name, SecurityStatus status, EntityUid characterUid)
{
EnsureComp<CriminalRecordComponent>(characterUid, out var record);
var previousIcon = record.StatusIcon;
record.StatusIcon = status switch
{
SecurityStatus.Paroled => "SecurityIconParoled",
SecurityStatus.Wanted => "SecurityIconWanted",
SecurityStatus.Detained => "SecurityIconIncarcerated",
SecurityStatus.Discharged => "SecurityIconDischarged",
SecurityStatus.Suspected => "SecurityIconSuspected",
_ => record.StatusIcon
};
if(previousIcon != record.StatusIcon)
Dirty(characterUid, record);
}
}
/// <summary>
/// Station records aren't predicted, just exists for access.
/// </summary>
public abstract class SharedCriminalRecordsConsoleSystem : EntitySystem;

View File

@@ -0,0 +1,52 @@
using Content.Shared.IdentityManagement;
using Content.Shared.IdentityManagement.Components;
using Content.Shared.Security;
using Content.Shared.Security.Components;
namespace Content.Shared.CriminalRecords.Systems;
public abstract class SharedCriminalRecordsSystem : EntitySystem
{
/// <summary>
/// Any entity that has a the name of the record that was just changed as their visible name will get their icon
/// updated with the new status, if the record got removed their icon will be removed too.
/// </summary>
public void UpdateCriminalIdentity(string name, SecurityStatus status)
{
var query = EntityQueryEnumerator<IdentityComponent>();
while (query.MoveNext(out var uid, out var identity))
{
if (!Identity.Name(uid, EntityManager).Equals(name))
continue;
if (status == SecurityStatus.None)
RemComp<CriminalRecordComponent>(uid);
else
SetCriminalIcon(name, status, uid);
}
}
/// <summary>
/// Decides the icon that should be displayed on the entity based on the security status
/// </summary>
public void SetCriminalIcon(string name, SecurityStatus status, EntityUid characterUid)
{
EnsureComp<CriminalRecordComponent>(characterUid, out var record);
var previousIcon = record.StatusIcon;
record.StatusIcon = status switch
{
SecurityStatus.Paroled => "SecurityIconParoled",
SecurityStatus.Wanted => "SecurityIconWanted",
SecurityStatus.Detained => "SecurityIconIncarcerated",
SecurityStatus.Discharged => "SecurityIconDischarged",
SecurityStatus.Suspected => "SecurityIconSuspected",
_ => record.StatusIcon
};
if (previousIcon != record.StatusIcon)
Dirty(characterUid, record);
}
}

View File

@@ -30,14 +30,13 @@ public sealed partial class BiomeComponent : Component
public List<IBiomeLayer> Layers = new();
/// <summary>
/// Templates to use for <see cref="Layers"/>. Optional as this can be set elsewhere.
/// Templates to use for <see cref="Layers"/>.
/// If this is set on mapinit, it will fill out layers automatically.
/// If not set, use <c>BiomeSystem</c> to do it.
/// Prototype reloading will also use this.
/// </summary>
/// <remarks>
/// This is really just here for prototype reload support.
/// </remarks>
[ViewVariables(VVAccess.ReadWrite),
DataField("template", customTypeSerializer: typeof(PrototypeIdSerializer<BiomeTemplatePrototype>))]
public string? Template;
[DataField]
public ProtoId<BiomeTemplatePrototype>? Template;
/// <summary>
/// If we've already generated a tile and couldn't deload it then we won't ever reload it in future.

View File

@@ -6,8 +6,13 @@ namespace Content.Shared.Weapons.Ranged.Components;
/// <summary>
/// Indicates that this gun requires wielding to be useable.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(WieldableSystem))]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(WieldableSystem))]
public sealed partial class GunRequiresWieldComponent : Component
{
[DataField, AutoNetworkedField]
public TimeSpan LastPopup;
[DataField, AutoNetworkedField]
public TimeSpan PopupCooldown = TimeSpan.FromSeconds(1);
}

View File

@@ -1,3 +1,5 @@
using Content.Shared.Weapons.Ranged.Components;
namespace Content.Shared.Weapons.Ranged.Events;
/// <summary>
@@ -15,7 +17,7 @@ public record struct ShotAttemptedEvent
/// <summary>
/// The gun being shot.
/// </summary>
public EntityUid Used;
public Entity<GunComponent> Used;
public bool Cancelled { get; private set; }

View File

@@ -239,7 +239,7 @@ public abstract partial class SharedGunSystem : EntitySystem
var prevention = new ShotAttemptedEvent
{
User = user,
Used = gunUid
Used = (gunUid, gun)
};
RaiseLocalEvent(gunUid, ref prevention);
if (prevention.Cancelled)

View File

@@ -16,7 +16,7 @@ using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Weapons.Ranged.Systems;
using Content.Shared.Wieldable.Components;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
using Robust.Shared.Timing;
namespace Content.Shared.Wieldable;
@@ -30,6 +30,7 @@ public sealed class WieldableSystem : EntitySystem
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly UseDelaySystem _delay = default!;
[Dependency] private readonly SharedGunSystem _gun = default!;
[Dependency] private readonly IGameTiming _timing = default!;
public override void Initialize()
{
@@ -42,7 +43,7 @@ public sealed class WieldableSystem : EntitySystem
SubscribeLocalEvent<WieldableComponent, GetVerbsEvent<InteractionVerb>>(AddToggleWieldVerb);
SubscribeLocalEvent<MeleeRequiresWieldComponent, AttemptMeleeEvent>(OnMeleeAttempt);
SubscribeLocalEvent<GunRequiresWieldComponent, AttemptShootEvent>(OnShootAttempt);
SubscribeLocalEvent<GunRequiresWieldComponent, ShotAttemptedEvent>(OnShootAttempt);
SubscribeLocalEvent<GunWieldBonusComponent, ItemWieldedEvent>(OnGunWielded);
SubscribeLocalEvent<GunWieldBonusComponent, ItemUnwieldedEvent>(OnGunUnwielded);
SubscribeLocalEvent<GunWieldBonusComponent, GunRefreshModifiersEvent>(OnGunRefreshModifiers);
@@ -61,16 +62,21 @@ public sealed class WieldableSystem : EntitySystem
}
}
private void OnShootAttempt(EntityUid uid, GunRequiresWieldComponent component, ref AttemptShootEvent args)
private void OnShootAttempt(EntityUid uid, GunRequiresWieldComponent component, ref ShotAttemptedEvent args)
{
if (TryComp<WieldableComponent>(uid, out var wieldable) &&
!wieldable.Wielded)
{
args.Cancelled = true;
args.Cancel();
if (!HasComp<MeleeWeaponComponent>(uid) && !HasComp<MeleeRequiresWieldComponent>(uid))
var time = _timing.CurTime;
if (time > component.LastPopup + component.PopupCooldown &&
!HasComp<MeleeWeaponComponent>(uid) &&
!HasComp<MeleeRequiresWieldComponent>(uid))
{
args.Message = Loc.GetString("wieldable-component-requires", ("item", uid));
component.LastPopup = time;
var message = Loc.GetString("wieldable-component-requires", ("item", uid));
_popupSystem.PopupClient(message, args.Used, args.User);
}
}
}