Files
tbd-station-14/Content.Server/Chat/Systems/EmoteOnDamageSystem.cs
Hannah Giovanna Dawson cdbe92d37d Update DamageableSystem to modern standards (#39417)
* Update DamageableSystem to modern standards

* DamageContainerId -> DamageContainerID with lint flag

* Replace strings with protoids

* Make CVar subscription declarations all consistently whitespaced

* ChangeDamage -> TryChangeDamage, cope with C# jank

* Revert event signature changes

* Restore a comment

* Re-add two queries

* Init the queries

* Use appearanceQuery in DamageChanged

* Use damageableQuery in TryChangeDamage

* Use damageableQuery in SetDamageModifierSetId

* Final cleanup, fix sandboxing

* Rectify ExplosionSystem:::ProcessEntity's call to TryChangeDamage

* Re-organize DamageableSystem

* first big fuck you breaking change.

* THATS A LOT OF DAMAGE!!!

* Fix test fails

* test fixes 2

* push it

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2025-10-27 19:53:04 +00:00

87 lines
2.9 KiB
C#

using Content.Shared.Damage.Systems;
namespace Content.Server.Chat.Systems;
using Content.Shared.Chat;
using Content.Shared.Chat.Prototypes;
using Content.Shared.Damage;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
public sealed class EmoteOnDamageSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EmoteOnDamageComponent, DamageChangedEvent>(OnDamage);
}
private void OnDamage(EntityUid uid, EmoteOnDamageComponent emoteOnDamage, DamageChangedEvent args)
{
if (!args.DamageIncreased)
return;
if (emoteOnDamage.LastEmoteTime + emoteOnDamage.EmoteCooldown > _gameTiming.CurTime)
return;
if (emoteOnDamage.Emotes.Count == 0)
return;
if (!_random.Prob(emoteOnDamage.EmoteChance))
return;
var emote = _random.Pick(emoteOnDamage.Emotes);
if (emoteOnDamage.WithChat)
{
_chatSystem.TryEmoteWithChat(uid, emote, emoteOnDamage.HiddenFromChatWindow ? ChatTransmitRange.HideChat : ChatTransmitRange.Normal);
}
else
{
_chatSystem.TryEmoteWithoutChat(uid,emote);
}
emoteOnDamage.LastEmoteTime = _gameTiming.CurTime;
}
/// <summary>
/// Try to add an emote to the entity, which will be performed at an interval.
/// </summary>
public bool AddEmote(EntityUid uid, string emotePrototypeId, EmoteOnDamageComponent? emoteOnDamage = null)
{
if (!Resolve(uid, ref emoteOnDamage, logMissing: false))
return false;
DebugTools.Assert(emoteOnDamage.LifeStage <= ComponentLifeStage.Running);
DebugTools.Assert(_prototypeManager.HasIndex<EmotePrototype>(emotePrototypeId), "Prototype not found. Did you make a typo?");
return emoteOnDamage.Emotes.Add(emotePrototypeId);
}
/// <summary>
/// Stop preforming an emote. Note that by default this will queue empty components for removal.
/// </summary>
public bool RemoveEmote(EntityUid uid, string emotePrototypeId, EmoteOnDamageComponent? emoteOnDamage = null, bool removeEmpty = true)
{
if (!Resolve(uid, ref emoteOnDamage, logMissing: false))
return false;
DebugTools.Assert(_prototypeManager.HasIndex<EmotePrototype>(emotePrototypeId), "Prototype not found. Did you make a typo?");
if (!emoteOnDamage.Emotes.Remove(emotePrototypeId))
return false;
if (removeEmpty && emoteOnDamage.Emotes.Count == 0)
RemCompDeferred(uid, emoteOnDamage);
return true;
}
}