From 5659edd207c36b1148ba675204c74f94821abb87 Mon Sep 17 00:00:00 2001 From: Ed <96445749+TheShuEd@users.noreply.github.com> Date: Thu, 18 Apr 2024 03:08:42 +0300 Subject: [PATCH] Chances of triggering effects (#27056) * electrocution * slippery * flashibg * Update SlipperyComponent.cs * Update SlipperySystem.cs --- .../Electrocution/Components/ElectrifiedComponent.cs | 3 +++ Content.Server/Electrocution/ElectrocutionSystem.cs | 3 +++ Content.Server/Explosion/EntitySystems/TriggerSystem.cs | 2 +- Content.Server/Flash/FlashSystem.cs | 8 ++++++-- Content.Shared/Flash/Components/FlashComponent.cs | 3 +++ .../Flash/Components/FlashOnTriggerComponent.cs | 1 + 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Content.Server/Electrocution/Components/ElectrifiedComponent.cs b/Content.Server/Electrocution/Components/ElectrifiedComponent.cs index 65a539eb08..4ef07a0cca 100644 --- a/Content.Server/Electrocution/Components/ElectrifiedComponent.cs +++ b/Content.Server/Electrocution/Components/ElectrifiedComponent.cs @@ -85,4 +85,7 @@ public sealed partial class ElectrifiedComponent : Component [DataField("shockVolume")] public float ShockVolume = 20; + + [DataField] + public float Probability = 1f; } diff --git a/Content.Server/Electrocution/ElectrocutionSystem.cs b/Content.Server/Electrocution/ElectrocutionSystem.cs index 1163306282..8291e97efe 100644 --- a/Content.Server/Electrocution/ElectrocutionSystem.cs +++ b/Content.Server/Electrocution/ElectrocutionSystem.cs @@ -213,6 +213,9 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem if (!IsPowered(uid, electrified, transform)) return false; + if (!_random.Prob(electrified.Probability)) + return false; + EnsureComp(uid); _appearance.SetData(uid, ElectrifiedVisuals.IsPowered, true); diff --git a/Content.Server/Explosion/EntitySystems/TriggerSystem.cs b/Content.Server/Explosion/EntitySystems/TriggerSystem.cs index 94f5585536..3675c214b1 100644 --- a/Content.Server/Explosion/EntitySystems/TriggerSystem.cs +++ b/Content.Server/Explosion/EntitySystems/TriggerSystem.cs @@ -153,7 +153,7 @@ namespace Content.Server.Explosion.EntitySystems private void HandleFlashTrigger(EntityUid uid, FlashOnTriggerComponent component, TriggerEvent args) { // TODO Make flash durations sane ffs. - _flashSystem.FlashArea(uid, args.User, component.Range, component.Duration * 1000f); + _flashSystem.FlashArea(uid, args.User, component.Range, component.Duration * 1000f, probability: component.Probability); args.Handled = true; } diff --git a/Content.Server/Flash/FlashSystem.cs b/Content.Server/Flash/FlashSystem.cs index fe7eb81d1e..b096e2c93f 100644 --- a/Content.Server/Flash/FlashSystem.cs +++ b/Content.Server/Flash/FlashSystem.cs @@ -19,6 +19,7 @@ using Content.Shared.Weapons.Melee.Events; using Robust.Server.Audio; using Robust.Server.GameObjects; using Robust.Shared.Audio; +using Robust.Shared.Random; using Robust.Shared.Timing; using InventoryComponent = Content.Shared.Inventory.InventoryComponent; @@ -37,6 +38,7 @@ namespace Content.Server.Flash [Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly StunSystem _stun = default!; [Dependency] private readonly TagSystem _tag = default!; + [Dependency] private readonly IRobustRandom _random = default!; public override void Initialize() { @@ -73,7 +75,7 @@ namespace Content.Server.Flash return; args.Handled = true; - FlashArea(uid, args.User, comp.Range, comp.AoeFlashDuration, comp.SlowTo, true); + FlashArea(uid, args.User, comp.Range, comp.AoeFlashDuration, comp.SlowTo, true, comp.Probability); } private bool UseFlash(EntityUid uid, FlashComponent comp, EntityUid user) @@ -148,7 +150,7 @@ namespace Content.Server.Flash } - public void FlashArea(EntityUid source, EntityUid? user, float range, float duration, float slowTo = 0.8f, bool displayPopup = false, SoundSpecifier? sound = null) + public void FlashArea(EntityUid source, EntityUid? user, float range, float duration, float slowTo = 0.8f, bool displayPopup = false, float probability = 1f, SoundSpecifier? sound = null) { var transform = EntityManager.GetComponent(source); var mapPosition = _transform.GetMapCoordinates(transform); @@ -159,6 +161,8 @@ namespace Content.Server.Flash if (!flashableQuery.TryGetComponent(entity, out var flashable)) continue; + if (!_random.Prob(probability)) + continue; // Check for unobstructed entities while ignoring the mobs with flashable components. if (!_interaction.InRangeUnobstructed(entity, mapPosition, range, flashable.CollisionGroup, (e) => e == source)) diff --git a/Content.Shared/Flash/Components/FlashComponent.cs b/Content.Shared/Flash/Components/FlashComponent.cs index a26e32cb70..6522db3b69 100644 --- a/Content.Shared/Flash/Components/FlashComponent.cs +++ b/Content.Shared/Flash/Components/FlashComponent.cs @@ -32,5 +32,8 @@ namespace Content.Shared.Flash.Components }; public bool Flashing; + + [DataField] + public float Probability = 1f; } } diff --git a/Content.Shared/Flash/Components/FlashOnTriggerComponent.cs b/Content.Shared/Flash/Components/FlashOnTriggerComponent.cs index d1270e9db7..7658ca0ae5 100644 --- a/Content.Shared/Flash/Components/FlashOnTriggerComponent.cs +++ b/Content.Shared/Flash/Components/FlashOnTriggerComponent.cs @@ -9,4 +9,5 @@ public sealed partial class FlashOnTriggerComponent : Component { [DataField] public float Range = 1.0f; [DataField] public float Duration = 8.0f; + [DataField] public float Probability = 1.0f; } -- 2.52.0