Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radiation protective armor and medicine now effect message frequency #1797

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
using Content.Shared.Radiation.Events;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Server.Radiation.Components;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;

using System.Linq;

namespace Content.Server.Radiation.Systems;
Expand All @@ -11,6 +16,7 @@ public sealed class RadiationNoticingSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

public override void Initialize()
{
Expand All @@ -20,10 +26,40 @@ public override void Initialize()

private void OnIrradiated(EntityUid uid, ActorComponent actorComponent, OnIrradiatedEvent args)
{
// Convert recieved radiation from event into actual radiation after rad damage reductions
if (!TryComp<DamageableComponent>(uid, out var damageable))
return; // If you aren't taking damage from radiation then what the messages say make no sense
var trueTotalRads = args.TotalRads;

DamageSpecifier damage = new();
foreach (var typeId in damageable.RadiationDamageTypeIDs)
{
damage.DamageDict.Add(typeId, FixedPoint2.New(args.TotalRads));
}

// Calculate entity inherent resistances
if (damageable.DamageModifierSetId != null &&
_prototypeManager.TryIndex<DamageModifierSetPrototype>(damageable.DamageModifierSetId, out var modifierSet))
{
// Hook into damage modifier calculation system
damage = DamageSpecifier.ApplyModifierSet(damage, modifierSet);
}

//Raise event to get all armor/shield/etc resistances
var ev = new DamageModifyEvent(damage, null, true);
RaiseLocalEvent(uid, ev);
damage = ev.Damage;

if (damage.Empty)
{
return;
}
trueTotalRads = (float)damage.GetTotal();

// Roll chance for popup messages
// This is per radiation update tick,
// is tuned so that when being irradiated with 1 rad/sec, see 1 message every 5-ish seconds on average
if (_random.NextFloat() <= args.RadsPerSecond / 20)
// Based on incoming rads so variable frame time does not alter message rate
// Tuned for approx 1 message every 5 seconds or so per 1 rad/second incoming
if (_random.NextFloat() <= trueTotalRads / 14)
{
SendRadiationPopup(uid);
}
Expand Down
5 changes: 3 additions & 2 deletions Content.Shared/Blocking/BlockingSystem.User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component

var blockFraction = blocking.IsBlocking ? blocking.ActiveBlockFraction : blocking.PassiveBlockFraction;
blockFraction = Math.Clamp(blockFraction, 0, 1);
_damageable.TryChangeDamage(component.BlockingItem, blockFraction * args.OriginalDamage);
if (!args.IsVirtual) //#IMP Don't damage shield if we are just seeing what damage COULD be blocked
_damageable.TryChangeDamage(component.BlockingItem, blockFraction * args.OriginalDamage);

var modify = new DamageModifierSet();
foreach (var key in dmgComp.Damage.DamageDict.Keys)
Expand All @@ -80,7 +81,7 @@ private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component

args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, modify);

if (blocking.IsBlocking && !args.Damage.Equals(args.OriginalDamage))
if (blocking.IsBlocking && !args.Damage.Equals(args.OriginalDamage) && !args.IsVirtual) //#IMP => IsVirtual
{
_audio.PlayPvs(blocking.BlockSound, uid);
}
Expand Down
5 changes: 4 additions & 1 deletion Content.Shared/Damage/Systems/DamageableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,14 @@ public sealed class DamageModifyEvent : EntityEventArgs, IInventoryRelayEvent
public DamageSpecifier Damage;
public EntityUid? Origin;

public DamageModifyEvent(DamageSpecifier damage, EntityUid? origin = null)
public bool IsVirtual; //#IMP For when you want to see what damage could be dealt, without actually dealing it

public DamageModifyEvent(DamageSpecifier damage, EntityUid? origin = null, bool isVirtual = false)
{
OriginalDamage = damage;
Damage = damage;
Origin = origin;
IsVirtual = isVirtual;// # IMP
}
}

Expand Down
Loading