From eb9d2da3ff035469e25c6eb7ee6afc989be92380 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Thu, 20 Jun 2024 17:04:32 -0400 Subject: [PATCH 01/12] Mass Contests Remake --- .../Weapons/Melee/MeleeWeaponSystem.cs | 4 +- .../Weapons/Ranged/Systems/GunSystem.cs | 9 +- Content.Shared/CCVar/CCVars.cs | 13 ++ .../Contests/ContestsSystem.CVars.cs | 19 +++ Content.Shared/Contests/ContestsSystem.cs | 116 ++++++++++++++++++ .../Cuffs/Components/HandcuffComponent.cs | 31 ++--- Content.Shared/Cuffs/SharedCuffableSystem.cs | 4 +- .../Entities/Objects/Misc/handcuffs.yml | 2 + 8 files changed, 179 insertions(+), 19 deletions(-) create mode 100644 Content.Shared/Contests/ContestsSystem.CVars.cs create mode 100644 Content.Shared/Contests/ContestsSystem.cs diff --git a/Content.Server/Weapons/Melee/MeleeWeaponSystem.cs b/Content.Server/Weapons/Melee/MeleeWeaponSystem.cs index 31c9b0d2b86..4749fd8b4b3 100644 --- a/Content.Server/Weapons/Melee/MeleeWeaponSystem.cs +++ b/Content.Server/Weapons/Melee/MeleeWeaponSystem.cs @@ -8,6 +8,7 @@ using Content.Shared.Actions.Events; using Content.Shared.Administration.Components; using Content.Shared.CombatMode; +using Content.Shared.Contests; using Content.Shared.Damage.Events; using Content.Shared.Damage.Systems; using Content.Shared.Database; @@ -43,6 +44,7 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem [Dependency] private readonly SharedColorFlashEffectSystem _color = default!; [Dependency] private readonly SolutionContainerSystem _solutions = default!; [Dependency] private readonly TagSystem _tag = default!; + [Dependency] private readonly ContestsSystem _contests = default!; public override void Initialize() { @@ -138,7 +140,7 @@ protected override bool DoDisarm(EntityUid user, DisarmAttackEvent ev, EntityUid if (attemptEvent.Cancelled) return false; - var chance = CalculateDisarmChance(user, target, inTargetHand, combatMode); + var chance = CalculateDisarmChance(user, target, inTargetHand, combatMode) * _contests.MassContest(user, target); if (_random.Prob(chance)) { diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs index b8f8f122111..ff3116a8fd0 100644 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs @@ -6,6 +6,7 @@ using Content.Server.Power.EntitySystems; using Content.Server.Stunnable; using Content.Server.Weapons.Ranged.Components; +using Content.Shared.Contests; using Content.Shared.Damage; using Content.Shared.Damage.Systems; using Content.Shared.Database; @@ -39,6 +40,7 @@ public sealed partial class GunSystem : SharedGunSystem [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly StaminaSystem _stamina = default!; [Dependency] private readonly StunSystem _stun = default!; + [Dependency] private readonly ContestsSystem _contests = default!; public const float DamagePitchVariation = SharedMeleeWeaponSystem.DamagePitchVariation; public const float GunClumsyChance = 0.5f; @@ -97,7 +99,7 @@ public override void Shoot(EntityUid gunUid, GunComponent gun, List<(EntityUid? var toMap = toCoordinates.ToMapPos(EntityManager, TransformSystem); var mapDirection = toMap - fromMap.Position; var mapAngle = mapDirection.ToAngle(); - var angle = GetRecoilAngle(Timing.CurTime, gun, mapDirection.ToAngle()); + var angle = GetRecoilAngle(Timing.CurTime, gun, mapDirection.ToAngle(), user); // If applicable, this ensures the projectile is parented to grid on spawn, instead of the map. var fromEnt = MapManager.TryFindGridAt(fromMap, out var gridUid, out var grid) @@ -311,7 +313,7 @@ private Angle[] LinearSpread(Angle start, Angle end, int intervals) return angles; } - private Angle GetRecoilAngle(TimeSpan curTime, GunComponent component, Angle direction) + private Angle GetRecoilAngle(TimeSpan curTime, GunComponent component, Angle direction, EntityUid? shooter) { var timeSinceLastFire = (curTime - component.LastFire).TotalSeconds; var newTheta = MathHelper.Clamp(component.CurrentAngle.Theta + component.AngleIncreaseModified.Theta - component.AngleDecayModified.Theta * timeSinceLastFire, component.MinAngleModified.Theta, component.MaxAngleModified.Theta); @@ -319,7 +321,8 @@ private Angle GetRecoilAngle(TimeSpan curTime, GunComponent component, Angle dir component.LastFire = component.NextFire; // Convert it so angle can go either side. - var random = Random.NextFloat(-0.5f, 0.5f); + + var random = Random.NextFloat(-0.5f, 0.5f) / _contests.MassContest(shooter); var spread = component.CurrentAngle.Theta * random; var angle = new Angle(direction.Theta + component.CurrentAngle.Theta * random); DebugTools.Assert(spread <= component.MaxAngleModified.Theta); diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 5aaf967dd1a..a8cd60a0e38 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -2118,5 +2118,18 @@ public static readonly CVarDef /// public static readonly CVarDef StationGoalsChance = CVarDef.Create("game.station_goals_chance", 0.1f, CVar.SERVERONLY); + + /// + /// Toggles all MassContest functions. All mass contests output 1f when false + /// + public static readonly CVarDef DoMassContests = + CVarDef.Create("contests.do_mass_contests", true, CVar.REPLICATED | CVar.SERVER); + + /// + /// The maximum amount that Mass Contests can modify a physics multiplier, given as a +/- percentage + /// Default of 0.25f outputs between * 0.75f and 1.25f + /// + public static readonly CVarDef MassContestsMaxPercentage = + CVarDef.Create("contests.max_percentage", 0.25f, CVar.REPLICATED | CVar.SERVER); } } diff --git a/Content.Shared/Contests/ContestsSystem.CVars.cs b/Content.Shared/Contests/ContestsSystem.CVars.cs new file mode 100644 index 00000000000..2775c8adb4c --- /dev/null +++ b/Content.Shared/Contests/ContestsSystem.CVars.cs @@ -0,0 +1,19 @@ +using Content.Shared.CCVar; +using Robust.Shared.Configuration; + +namespace Content.Shared.Contests +{ + public sealed partial class ContestsSystem + { + [Dependency] private readonly IConfigurationManager _cfg = default!; + + public bool DoMassContests { get; private set; } + public float MassContestsMaxPercentage { get; private set; } + + private void InitializeCVars() + { + Subs.CVar(_cfg, CCVars.DoMassContests, value => DoMassContests = value, true); + Subs.CVar(_cfg, CCVars.MassContestsMaxPercentage, value => MassContestsMaxPercentage = value, true); + } + } +} diff --git a/Content.Shared/Contests/ContestsSystem.cs b/Content.Shared/Contests/ContestsSystem.cs new file mode 100644 index 00000000000..2a105816b48 --- /dev/null +++ b/Content.Shared/Contests/ContestsSystem.cs @@ -0,0 +1,116 @@ +using Robust.Shared.Physics.Components; + +namespace Content.Shared.Contests +{ + public sealed partial class ContestsSystem : EntitySystem + { + // Defaulted to the average mass of an adult human + /// + /// The presumed average mass of a player entity + /// + private const float AverageMass = 71f; + public override void Initialize() + { + base.Initialize(); + + InitializeCVars(); + + } + // REGION + // Mass Contests + /// + /// Outputs the ratio of mass between a performer and the average human mass + /// + /// Uid of Performer + /// + public float MassContest(EntityUid performerUid, float otherMass = AverageMass) + { + if (DoMassContests + && TryComp(performerUid, out var performerPhysics) + && performerPhysics.Mass != 0) + return Math.Clamp(performerPhysics.Mass / otherMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + + return 1f; + } + + public float MassContest(EntityUid? performerUid, float otherMass = AverageMass) + { + if (DoMassContests) + { + var ratio = performerUid is { } uid ? MassContest(uid, otherMass) : 1f; + return ratio; + } + + return 1f; + } + + /// + /// Outputs the ratio of mass between a performer and the average human mass + /// If a function already has the performer's physics component, this is faster + /// + /// + /// + public float MassContest(PhysicsComponent performerPhysics, float otherMass = AverageMass) + { + if (DoMassContests + && performerPhysics.Mass != 0) + return Math.Clamp(performerPhysics.Mass / otherMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + + return 1f; + } + + /// + /// Outputs the ratio of mass between a performer and a target, accepts either EntityUids or PhysicsComponents in any combination + /// If you have physics components already in your function, use those instead + /// + /// + /// + /// + public float MassContest(EntityUid performerUid, EntityUid targetUid) + { + if (DoMassContests + && TryComp(performerUid, out var performerPhysics) + && TryComp(targetUid, out var targetPhysics) + && performerPhysics.Mass != 0 + && targetPhysics.InvMass != 0) + return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + + return 1f; + } + + /// + public float MassContest(EntityUid performerUid, PhysicsComponent targetPhysics) + { + if (DoMassContests + && TryComp(performerUid, out var performerPhysics) + && performerPhysics.Mass != 0 + && targetPhysics.InvMass != 0) + return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + + return 1f; + } + + /// + public float MassContest(PhysicsComponent performerPhysics, EntityUid targetUid) + { + if (DoMassContests + && TryComp(targetUid, out var targetPhysics) + && performerPhysics.Mass != 0 + && targetPhysics.InvMass != 0) + return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + + return 1f; + } + + /// + public float MassContest(PhysicsComponent performerPhysics, PhysicsComponent targetPhysics) + { + if (DoMassContests + && performerPhysics.Mass != 0 + && targetPhysics.InvMass != 0) + return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + + return 1f; + } + } +} diff --git a/Content.Shared/Cuffs/Components/HandcuffComponent.cs b/Content.Shared/Cuffs/Components/HandcuffComponent.cs index 77a77cf2f84..dac1f347e52 100644 --- a/Content.Shared/Cuffs/Components/HandcuffComponent.cs +++ b/Content.Shared/Cuffs/Components/HandcuffComponent.cs @@ -12,37 +12,37 @@ public sealed partial class HandcuffComponent : Component /// /// The time it takes to cuff an entity. /// - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public float CuffTime = 3.5f; /// /// The time it takes to uncuff an entity. /// - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public float UncuffTime = 3.5f; /// /// The time it takes for a cuffed entity to uncuff itself. /// - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public float BreakoutTime = 15f; /// /// If an entity being cuffed is stunned, this amount of time is subtracted from the time it takes to add/remove their cuffs. /// - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public float StunBonus = 2f; /// /// Will the cuffs break when removed? /// - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public bool BreakOnRemove; /// /// Will the cuffs break when removed? /// - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public EntProtoId? BrokenPrototype; /// @@ -55,35 +55,38 @@ public sealed partial class HandcuffComponent : Component /// /// The path of the RSI file used for the player cuffed overlay. /// - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public string? CuffedRSI = "Objects/Misc/handcuffs.rsi"; /// /// The iconstate used with the RSI file for the player cuffed overlay. /// - [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + [DataField, AutoNetworkedField] public string? BodyIconState = "body-overlay"; /// /// An opptional color specification for /// - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public Color Color = Color.White; - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public SoundSpecifier StartCuffSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_start.ogg"); - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public SoundSpecifier EndCuffSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_end.ogg"); - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public SoundSpecifier StartBreakoutSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_breakout_start.ogg"); - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public SoundSpecifier StartUncuffSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_takeoff_start.ogg"); - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public SoundSpecifier EndUncuffSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_takeoff_end.ogg"); + + [DataField] + public float UncuffMassModifier = 0f; } /// diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index fc005fd30fa..f5754641b31 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -5,6 +5,7 @@ using Content.Shared.Alert; using Content.Shared.Atmos.Piping.Unary.Components; using Content.Shared.Buckle.Components; +using Content.Shared.Contests; using Content.Shared.Cuffs.Components; using Content.Shared.Database; using Content.Shared.DoAfter; @@ -58,6 +59,7 @@ public abstract partial class SharedCuffableSystem : EntitySystem [Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly UseDelaySystem _delay = default!; + [Dependency] private readonly ContestsSystem _contests = default!; public override void Initialize() { @@ -559,7 +561,7 @@ public void TryUncuff(EntityUid target, EntityUid user, EntityUid? cuffsToRemove return; } - var uncuffTime = isOwner ? cuff.BreakoutTime : cuff.UncuffTime; + var uncuffTime = (isOwner ? cuff.BreakoutTime : cuff.UncuffTime) / (_contests.MassContest(user) * Math.Abs(cuff.UncuffMassModifier)); if (isOwner) { diff --git a/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml b/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml index 5f970da1840..32269d38888 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml @@ -52,6 +52,7 @@ path: /Audio/Items/Handcuffs/rope_breakout.ogg startBreakoutSound: path: /Audio/Items/Handcuffs/rope_takeoff.ogg + uncuffMassModifier: 1 - type: Construction graph: makeshifthandcuffs node: cuffscable @@ -93,6 +94,7 @@ path: /Audio/Items/Handcuffs/rope_breakout.ogg startBreakoutSound: path: /Audio/Items/Handcuffs/rope_takeoff.ogg + uncuffMassModifier: 1 - type: Sprite sprite: Objects/Misc/zipties.rsi state: cuff From 1701dedfa4a15c3577fa894a26969f2d21fb09b1 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Thu, 20 Jun 2024 17:20:36 -0400 Subject: [PATCH 02/12] Update SharedCuffableSystem.cs --- Content.Shared/Cuffs/SharedCuffableSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index f5754641b31..0fa77b182c4 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -561,7 +561,7 @@ public void TryUncuff(EntityUid target, EntityUid user, EntityUid? cuffsToRemove return; } - var uncuffTime = (isOwner ? cuff.BreakoutTime : cuff.UncuffTime) / (_contests.MassContest(user) * Math.Abs(cuff.UncuffMassModifier)); + var uncuffTime = (isOwner ? cuff.BreakoutTime : cuff.UncuffTime) * (_contests.MassContest(user) * Math.Abs(cuff.UncuffMassModifier)); if (isOwner) { From 1a1263f1a88e979f44068e92a88bba35102d7adb Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Thu, 20 Jun 2024 18:23:17 -0400 Subject: [PATCH 03/12] Update HandcuffComponent.cs --- Content.Shared/Cuffs/Components/HandcuffComponent.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Content.Shared/Cuffs/Components/HandcuffComponent.cs b/Content.Shared/Cuffs/Components/HandcuffComponent.cs index dac1f347e52..a5593cd2712 100644 --- a/Content.Shared/Cuffs/Components/HandcuffComponent.cs +++ b/Content.Shared/Cuffs/Components/HandcuffComponent.cs @@ -85,6 +85,10 @@ public sealed partial class HandcuffComponent : Component [DataField] public SoundSpecifier EndUncuffSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_takeoff_end.ogg"); + /// + /// Both a bool and a multiplier combined. If it is 0, handcuffs are unaffected by mass contests. The absolute value of any nonzero acts as a multiplier on how much mass affects uncuff speed. + /// A value of 1 provides the full modifier from MassContest. 0.5 is half the effect of mass contests, and so on. + /// [DataField] public float UncuffMassModifier = 0f; } From 5f4df32bb532b1f7d86750b266e12135bea6729e Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Mon, 1 Jul 2024 15:24:31 -0400 Subject: [PATCH 04/12] Fixes handcuff bug --- Content.Shared/Cuffs/Components/HandcuffComponent.cs | 6 +++--- Content.Shared/Cuffs/SharedCuffableSystem.cs | 2 +- Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Content.Shared/Cuffs/Components/HandcuffComponent.cs b/Content.Shared/Cuffs/Components/HandcuffComponent.cs index a5593cd2712..72663fd8fab 100644 --- a/Content.Shared/Cuffs/Components/HandcuffComponent.cs +++ b/Content.Shared/Cuffs/Components/HandcuffComponent.cs @@ -86,11 +86,11 @@ public sealed partial class HandcuffComponent : Component public SoundSpecifier EndUncuffSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_takeoff_end.ogg"); /// - /// Both a bool and a multiplier combined. If it is 0, handcuffs are unaffected by mass contests. The absolute value of any nonzero acts as a multiplier on how much mass affects uncuff speed. - /// A value of 1 provides the full modifier from MassContest. 0.5 is half the effect of mass contests, and so on. + /// Acts as a two-state option for handcuff speed. When true, handcuffs will be easier to get out of if you are larger than average. Representing the use of strength to break things like zipties. + /// When false, handcuffs are easier to get out of if you are smaller than average, representing the use of dexterity to slip the cuffs. /// [DataField] - public float UncuffMassModifier = 0f; + public bool UncuffMassMultiplies = false; } /// diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index 0fa77b182c4..92f4576c8b6 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -561,7 +561,7 @@ public void TryUncuff(EntityUid target, EntityUid user, EntityUid? cuffsToRemove return; } - var uncuffTime = (isOwner ? cuff.BreakoutTime : cuff.UncuffTime) * (_contests.MassContest(user) * Math.Abs(cuff.UncuffMassModifier)); + var uncuffTime = (isOwner ? cuff.BreakoutTime : cuff.UncuffTime) * (cuff.UncuffMassMultiplies ? 1 / _contests.MassContest(user) : _contests.MassContest(user)); if (isOwner) { diff --git a/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml b/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml index 32269d38888..711ddbc0c28 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml @@ -52,7 +52,7 @@ path: /Audio/Items/Handcuffs/rope_breakout.ogg startBreakoutSound: path: /Audio/Items/Handcuffs/rope_takeoff.ogg - uncuffMassModifier: 1 + uncuffMassMultiplies: true - type: Construction graph: makeshifthandcuffs node: cuffscable @@ -94,7 +94,7 @@ path: /Audio/Items/Handcuffs/rope_breakout.ogg startBreakoutSound: path: /Audio/Items/Handcuffs/rope_takeoff.ogg - uncuffMassModifier: 1 + uncuffMassMultiplies: true - type: Sprite sprite: Objects/Misc/zipties.rsi state: cuff From 193362651ed4a61742ce8b81c5fa509d89023bf3 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Fri, 12 Jul 2024 14:30:39 -0400 Subject: [PATCH 05/12] Update ContestsSystem.cs --- Content.Shared/Contests/ContestsSystem.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Content.Shared/Contests/ContestsSystem.cs b/Content.Shared/Contests/ContestsSystem.cs index 2a105816b48..02e50aeadd7 100644 --- a/Content.Shared/Contests/ContestsSystem.cs +++ b/Content.Shared/Contests/ContestsSystem.cs @@ -33,6 +33,10 @@ public float MassContest(EntityUid performerUid, float otherMass = AverageMass) return 1f; } + /// + /// + /// MaybeMassContest, for in case your EntityUid can potentially cease existing. + /// public float MassContest(EntityUid? performerUid, float otherMass = AverageMass) { if (DoMassContests) From f1f3fea92478c5917cd6c28c478e647c71350b77 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Fri, 12 Jul 2024 16:32:14 -0400 Subject: [PATCH 06/12] Apply suggestions from code review Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> Signed-off-by: VMSolidus --- Content.Shared/Contests/ContestsSystem.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Content.Shared/Contests/ContestsSystem.cs b/Content.Shared/Contests/ContestsSystem.cs index 02e50aeadd7..bf134c5be77 100644 --- a/Content.Shared/Contests/ContestsSystem.cs +++ b/Content.Shared/Contests/ContestsSystem.cs @@ -4,9 +4,9 @@ namespace Content.Shared.Contests { public sealed partial class ContestsSystem : EntitySystem { - // Defaulted to the average mass of an adult human /// /// The presumed average mass of a player entity + /// Defaulted to the average mass of an adult human /// private const float AverageMass = 71f; public override void Initialize() @@ -16,13 +16,12 @@ public override void Initialize() InitializeCVars(); } - // REGION - // Mass Contests + + #region Mass Contests /// /// Outputs the ratio of mass between a performer and the average human mass /// /// Uid of Performer - /// public float MassContest(EntityUid performerUid, float otherMass = AverageMass) { if (DoMassContests @@ -35,7 +34,7 @@ public float MassContest(EntityUid performerUid, float otherMass = AverageMass) /// /// - /// MaybeMassContest, for in case your EntityUid can potentially cease existing. + /// MaybeMassContest, in case your entity doesn't exist /// public float MassContest(EntityUid? performerUid, float otherMass = AverageMass) { @@ -53,7 +52,6 @@ public float MassContest(EntityUid? performerUid, float otherMass = AverageMass) /// If a function already has the performer's physics component, this is faster /// /// - /// public float MassContest(PhysicsComponent performerPhysics, float otherMass = AverageMass) { if (DoMassContests @@ -65,11 +63,10 @@ public float MassContest(PhysicsComponent performerPhysics, float otherMass = Av /// /// Outputs the ratio of mass between a performer and a target, accepts either EntityUids or PhysicsComponents in any combination - /// If you have physics components already in your function, use those instead + /// If you have physics components already in your function, use instead /// /// /// - /// public float MassContest(EntityUid performerUid, EntityUid targetUid) { if (DoMassContests @@ -116,5 +113,7 @@ public float MassContest(PhysicsComponent performerPhysics, PhysicsComponent tar return 1f; } + + #endregion } } From ab41b877cad432e7f161e7b881927c39d0bbde79 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Fri, 12 Jul 2024 16:38:15 -0400 Subject: [PATCH 07/12] Apply suggestions from code review Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> Signed-off-by: VMSolidus --- .../Contests/ContestsSystem.CVars.cs | 19 ------------------- Content.Shared/Contests/ContestsSystem.cs | 7 ------- 2 files changed, 26 deletions(-) diff --git a/Content.Shared/Contests/ContestsSystem.CVars.cs b/Content.Shared/Contests/ContestsSystem.CVars.cs index 2775c8adb4c..e69de29bb2d 100644 --- a/Content.Shared/Contests/ContestsSystem.CVars.cs +++ b/Content.Shared/Contests/ContestsSystem.CVars.cs @@ -1,19 +0,0 @@ -using Content.Shared.CCVar; -using Robust.Shared.Configuration; - -namespace Content.Shared.Contests -{ - public sealed partial class ContestsSystem - { - [Dependency] private readonly IConfigurationManager _cfg = default!; - - public bool DoMassContests { get; private set; } - public float MassContestsMaxPercentage { get; private set; } - - private void InitializeCVars() - { - Subs.CVar(_cfg, CCVars.DoMassContests, value => DoMassContests = value, true); - Subs.CVar(_cfg, CCVars.MassContestsMaxPercentage, value => MassContestsMaxPercentage = value, true); - } - } -} diff --git a/Content.Shared/Contests/ContestsSystem.cs b/Content.Shared/Contests/ContestsSystem.cs index bf134c5be77..ed29483241f 100644 --- a/Content.Shared/Contests/ContestsSystem.cs +++ b/Content.Shared/Contests/ContestsSystem.cs @@ -9,13 +9,6 @@ public sealed partial class ContestsSystem : EntitySystem /// Defaulted to the average mass of an adult human /// private const float AverageMass = 71f; - public override void Initialize() - { - base.Initialize(); - - InitializeCVars(); - - } #region Mass Contests /// From 54e95aa46feeacb033f1ae4720e445e735f2ff60 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Fri, 12 Jul 2024 16:42:31 -0400 Subject: [PATCH 08/12] This looks fucking terrible, why did you make me do this? --- Content.Shared/Contests/ContestsSystem.cs | 34 +++++++++++++---------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Content.Shared/Contests/ContestsSystem.cs b/Content.Shared/Contests/ContestsSystem.cs index ed29483241f..9f14b0ea8a6 100644 --- a/Content.Shared/Contests/ContestsSystem.cs +++ b/Content.Shared/Contests/ContestsSystem.cs @@ -1,15 +1,19 @@ +using Content.Shared.CCVar; +using Robust.Shared.Configuration; using Robust.Shared.Physics.Components; namespace Content.Shared.Contests { public sealed partial class ContestsSystem : EntitySystem { + [Dependency] private readonly IConfigurationManager _cfg = default!; + /// /// The presumed average mass of a player entity /// Defaulted to the average mass of an adult human /// private const float AverageMass = 71f; - + #region Mass Contests /// /// Outputs the ratio of mass between a performer and the average human mass @@ -17,10 +21,10 @@ public sealed partial class ContestsSystem : EntitySystem /// Uid of Performer public float MassContest(EntityUid performerUid, float otherMass = AverageMass) { - if (DoMassContests + if (_cfg.GetCVar(CCVars.DoMassContests) && TryComp(performerUid, out var performerPhysics) && performerPhysics.Mass != 0) - return Math.Clamp(performerPhysics.Mass / otherMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + return Math.Clamp(performerPhysics.Mass / otherMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage), 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage)); return 1f; } @@ -31,7 +35,7 @@ public float MassContest(EntityUid performerUid, float otherMass = AverageMass) /// public float MassContest(EntityUid? performerUid, float otherMass = AverageMass) { - if (DoMassContests) + if (_cfg.GetCVar(CCVars.DoMassContests)) { var ratio = performerUid is { } uid ? MassContest(uid, otherMass) : 1f; return ratio; @@ -47,9 +51,9 @@ public float MassContest(EntityUid? performerUid, float otherMass = AverageMass) /// public float MassContest(PhysicsComponent performerPhysics, float otherMass = AverageMass) { - if (DoMassContests + if (_cfg.GetCVar(CCVars.DoMassContests) && performerPhysics.Mass != 0) - return Math.Clamp(performerPhysics.Mass / otherMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + return Math.Clamp(performerPhysics.Mass / otherMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage), 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage)); return 1f; } @@ -62,12 +66,12 @@ public float MassContest(PhysicsComponent performerPhysics, float otherMass = Av /// public float MassContest(EntityUid performerUid, EntityUid targetUid) { - if (DoMassContests + if (_cfg.GetCVar(CCVars.DoMassContests) && TryComp(performerUid, out var performerPhysics) && TryComp(targetUid, out var targetPhysics) && performerPhysics.Mass != 0 && targetPhysics.InvMass != 0) - return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage), 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage)); return 1f; } @@ -75,11 +79,11 @@ public float MassContest(EntityUid performerUid, EntityUid targetUid) /// public float MassContest(EntityUid performerUid, PhysicsComponent targetPhysics) { - if (DoMassContests + if (_cfg.GetCVar(CCVars.DoMassContests) && TryComp(performerUid, out var performerPhysics) && performerPhysics.Mass != 0 && targetPhysics.InvMass != 0) - return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage), 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage)); return 1f; } @@ -87,11 +91,11 @@ public float MassContest(EntityUid performerUid, PhysicsComponent targetPhysics) /// public float MassContest(PhysicsComponent performerPhysics, EntityUid targetUid) { - if (DoMassContests + if (_cfg.GetCVar(CCVars.DoMassContests) && TryComp(targetUid, out var targetPhysics) && performerPhysics.Mass != 0 && targetPhysics.InvMass != 0) - return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage), 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage)); return 1f; } @@ -99,14 +103,14 @@ public float MassContest(PhysicsComponent performerPhysics, EntityUid targetUid) /// public float MassContest(PhysicsComponent performerPhysics, PhysicsComponent targetPhysics) { - if (DoMassContests + if (_cfg.GetCVar(CCVars.DoMassContests) && performerPhysics.Mass != 0 && targetPhysics.InvMass != 0) - return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - MassContestsMaxPercentage, 1 + MassContestsMaxPercentage); + return Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage), 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage)); return 1f; } - + #endregion } } From ddce1eeffd0d88dda7d2ee9bccad83cd89fb145d Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Fri, 12 Jul 2024 17:11:16 -0400 Subject: [PATCH 09/12] Apply suggestions from code review Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com> Signed-off-by: VMSolidus --- Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml b/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml index 711ddbc0c28..200b11b4f19 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml @@ -52,7 +52,7 @@ path: /Audio/Items/Handcuffs/rope_breakout.ogg startBreakoutSound: path: /Audio/Items/Handcuffs/rope_takeoff.ogg - uncuffMassMultiplies: true + uncuffMassMultiplies: true # Inverts the mass multiplier for handcuffs; larger has an easier time to break out while smaller struggles. - type: Construction graph: makeshifthandcuffs node: cuffscable @@ -94,7 +94,7 @@ path: /Audio/Items/Handcuffs/rope_breakout.ogg startBreakoutSound: path: /Audio/Items/Handcuffs/rope_takeoff.ogg - uncuffMassMultiplies: true + uncuffMassMultiplies: true # Inverts the mass multiplier for handcuffs; larger has an easier time to break out while smaller struggles. - type: Sprite sprite: Objects/Misc/zipties.rsi state: cuff From 1f905ff7340c3e80ef43b0cc2f2b90fdea020e59 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Fri, 12 Jul 2024 19:41:50 -0400 Subject: [PATCH 10/12] Delete ContestsSystem.CVars.cs --- Content.Shared/Contests/ContestsSystem.CVars.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Content.Shared/Contests/ContestsSystem.CVars.cs diff --git a/Content.Shared/Contests/ContestsSystem.CVars.cs b/Content.Shared/Contests/ContestsSystem.CVars.cs deleted file mode 100644 index e69de29bb2d..00000000000 From 7b9e6b0a0e3c58b8f42055efa99dfc4d7d109f0b Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Fri, 12 Jul 2024 19:44:07 -0400 Subject: [PATCH 11/12] Better variable name --- Content.Shared/Cuffs/Components/HandcuffComponent.cs | 2 +- Content.Shared/Cuffs/SharedCuffableSystem.cs | 2 +- Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Content.Shared/Cuffs/Components/HandcuffComponent.cs b/Content.Shared/Cuffs/Components/HandcuffComponent.cs index 72663fd8fab..d305f6067d0 100644 --- a/Content.Shared/Cuffs/Components/HandcuffComponent.cs +++ b/Content.Shared/Cuffs/Components/HandcuffComponent.cs @@ -90,7 +90,7 @@ public sealed partial class HandcuffComponent : Component /// When false, handcuffs are easier to get out of if you are smaller than average, representing the use of dexterity to slip the cuffs. /// [DataField] - public bool UncuffMassMultiplies = false; + public bool UncuffEasierWhenLarge = false; } /// diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index 92f4576c8b6..e4990320a59 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -561,7 +561,7 @@ public void TryUncuff(EntityUid target, EntityUid user, EntityUid? cuffsToRemove return; } - var uncuffTime = (isOwner ? cuff.BreakoutTime : cuff.UncuffTime) * (cuff.UncuffMassMultiplies ? 1 / _contests.MassContest(user) : _contests.MassContest(user)); + var uncuffTime = (isOwner ? cuff.BreakoutTime : cuff.UncuffTime) * (cuff.UncuffEasierWhenLarge ? 1 / _contests.MassContest(user) : _contests.MassContest(user)); if (isOwner) { diff --git a/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml b/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml index 200b11b4f19..527233920d5 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml @@ -52,7 +52,7 @@ path: /Audio/Items/Handcuffs/rope_breakout.ogg startBreakoutSound: path: /Audio/Items/Handcuffs/rope_takeoff.ogg - uncuffMassMultiplies: true # Inverts the mass multiplier for handcuffs; larger has an easier time to break out while smaller struggles. + uncuffEasierWhenLarge: true - type: Construction graph: makeshifthandcuffs node: cuffscable @@ -94,7 +94,7 @@ path: /Audio/Items/Handcuffs/rope_breakout.ogg startBreakoutSound: path: /Audio/Items/Handcuffs/rope_takeoff.ogg - uncuffMassMultiplies: true # Inverts the mass multiplier for handcuffs; larger has an easier time to break out while smaller struggles. + uncuffEasierWhenLarge: true - type: Sprite sprite: Objects/Misc/zipties.rsi state: cuff From 4e2bb7069aba466c537b0d50c5fede53611e07a1 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Fri, 12 Jul 2024 19:47:08 -0400 Subject: [PATCH 12/12] Update Content.Shared/Contests/ContestsSystem.cs Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> Signed-off-by: VMSolidus --- Content.Shared/Contests/ContestsSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/Contests/ContestsSystem.cs b/Content.Shared/Contests/ContestsSystem.cs index 9f14b0ea8a6..6386bfd7a23 100644 --- a/Content.Shared/Contests/ContestsSystem.cs +++ b/Content.Shared/Contests/ContestsSystem.cs @@ -10,7 +10,7 @@ public sealed partial class ContestsSystem : EntitySystem /// /// The presumed average mass of a player entity - /// Defaulted to the average mass of an adult human + /// Defaulted to the average mass of an adult human /// private const float AverageMass = 71f;