Chances of triggering effects (#27056)

* electrocution

* slippery

* flashibg

* Update SlipperyComponent.cs

* Update SlipperySystem.cs

(cherry picked from commit 5659edd207c36b1148ba675204c74f94821abb87)
This commit is contained in:
Ed 2024-04-18 03:08:42 +03:00 committed by NullWanderer
parent ff88c958ad
commit 2a379aae7f
No known key found for this signature in database
GPG Key ID: 212F05528FD678BE
6 changed files with 17 additions and 3 deletions

View File

@ -85,4 +85,7 @@ public sealed partial class ElectrifiedComponent : Component
[DataField("shockVolume")]
public float ShockVolume = 20;
[DataField]
public float Probability = 1f;
}

View File

@ -213,6 +213,9 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
if (!IsPowered(uid, electrified, transform))
return false;
if (!_random.Prob(electrified.Probability))
return false;
EnsureComp<ActivatedElectrifiedComponent>(uid);
_appearance.SetData(uid, ElectrifiedVisuals.IsPowered, true);

View File

@ -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;
}

View File

@ -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<TransformComponent>(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))

View File

@ -32,5 +32,8 @@ namespace Content.Shared.Flash.Components
};
public bool Flashing;
[DataField]
public float Probability = 1f;
}
}

View File

@ -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;
}