Skip to content

Commit

Permalink
change a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
pheenty committed Nov 16, 2024
1 parent 17e3efc commit b2bd377
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
8 changes: 7 additions & 1 deletion Content.Server/Stories/Garrote/GarroteComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public sealed partial class GarroteComponent : Component
/// For how long a DoAfter lasts
/// </summary>
[DataField("doAfterTime")]
public TimeSpan DoAfterTime = TimeSpan.FromSeconds(7f);
public TimeSpan DoAfterTime = TimeSpan.FromSeconds(5f);

/// <summary>
/// The mininum angle in degrees from face to back to use
Expand All @@ -21,6 +21,12 @@ public sealed partial class GarroteComponent : Component
[DataField]
public bool Busy = false;

/// <summary>
/// Whether the stun should be removed on DoAfter cancel, so we don't unstun stunned entities
/// </summary>
[DataField]
public bool RemoveStun = false;

/// <summary>
/// Whether the mute should be removed on DoAfter cancel, so we don't unmute mimes and alike
/// </summary>
Expand Down
42 changes: 24 additions & 18 deletions Content.Server/Stories/Garrote/GarroteSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Content.Server.Body.Components;
using Content.Server.Chat.Systems;
using Content.Server.Mobs;
using Content.Server.Popups;
using Content.Shared.ActionBlocker;
using Content.Shared.Body.Components;
Expand All @@ -27,7 +26,6 @@ public sealed class GarroteSystem : EntitySystem
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly DeathgaspSystem _deathgasp = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
Expand Down Expand Up @@ -77,7 +75,7 @@ private void OnGarroteAttempt(EntityUid uid, GarroteComponent comp, ref AfterInt
var messageothers = Loc.GetString("garrote-component-started-others", ("user", args.User), ("target", args.Target));
_popupSystem.PopupEntity(messageothers, args.User, Filter.PvsExcept(args.Target.Value), true, PopupType.MediumCaution);

var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, comp.DoAfterTime, new GarroteDoneEvent(), uid, target: args.Target, used: uid)
var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, comp.DoAfterTime, new GarroteDoneEvent(), uid)
{
BreakOnMove = true,
BreakOnDamage = true,
Expand All @@ -87,9 +85,13 @@ private void OnGarroteAttempt(EntityUid uid, GarroteComponent comp, ref AfterInt
if (!_doAfter.TryStartDoAfter(doAfterEventArgs)) return;

ProtoId<EmotePrototype> emote = "Cough";
_chatSystem.TryEmoteWithChat(uid, emote, ChatTransmitRange.HideChat, ignoreActionBlocker: true);
_chatSystem.TryEmoteWithChat(args.Target.Value, emote, ChatTransmitRange.HideChat, ignoreActionBlocker: true);

EnsureComp<StunnedComponent>(args.Target.Value);
if (!HasComp<StunnedComponent>(args.Target))
{
comp.RemoveStun = true;
AddComp<StunnedComponent>(args.Target.Value);
}

if (!HasComp<MutedComponent>(args.Target))
{
Expand All @@ -106,6 +108,7 @@ private void OnGarroteDone(EntityUid uid, GarroteComponent comp, GarroteDoneEven
|| !TryComp<DamageableComponent>(args.Target, out var damageable)
|| !TryComp<MobThresholdsComponent>(args.Target, out var thresholds))
{
comp.RemoveStun = false;
comp.RemoveMute = false;
comp.Busy = false;
return;
Expand All @@ -114,36 +117,39 @@ private void OnGarroteDone(EntityUid uid, GarroteComponent comp, GarroteDoneEven
if (!DoesBreathe(args.Target.Value) || args.Cancelled)
args.Handled = true;

if (!args.Handled)
if (comp.RemoveStun)
{
var damage = _mobThresholdSystem.GetThresholdForState(args.Target.Value, MobState.Dead, thresholds) - damageable.TotalDamage;
DamageSpecifier damageDealt = new(_prototypeManager.Index<DamageTypePrototype>("Asphyxiation"), damage);
_damageable.TryChangeDamage(args.Target, damageDealt, false, origin: args.User);
_deathgasp.Deathgasp(args.Target.Value);
var message = Loc.GetString("garrote-component-complete", ("user", args.User), ("target", args.Target));
_popupSystem.PopupEntity(message, args.User, PopupType.LargeCaution);
RemComp<StunnedComponent>(args.Target.Value);
comp.RemoveStun = false;
}

comp.Busy = false;

RemComp<StunnedComponent>(args.Target.Value);

if (comp.RemoveMute)
{
RemComp<MutedComponent>(args.Target.Value);
comp.RemoveMute = false;
}

comp.Busy = false;

if (args.Handled) return;

var damage = _mobThresholdSystem.GetThresholdForState(args.Target.Value, MobState.Critical, thresholds) - damageable.TotalDamage + 5;
DamageSpecifier damageDealt = new(_prototypeManager.Index<DamageTypePrototype>("Asphyxiation"), damage);
_damageable.TryChangeDamage(args.Target, damageDealt, false, origin: args.User);

var message = Loc.GetString("garrote-component-complete", ("user", args.User), ("target", args.Target));
_popupSystem.PopupEntity(message, args.User, PopupType.LargeCaution);

args.Handled = true;
}

private bool DoesBreathe(EntityUid target)
{
if (!TryComp<MobStateComponent>(target, out var mobstate)) return false;
return (HasComp<RespiratorComponent>(target) && mobstate.CurrentState != MobState.Dead);
return (HasComp<RespiratorComponent>(target) && mobstate.CurrentState == MobState.Alive);
}

public bool IsBehind(EntityUid user, EntityUid target, float minAngleFromFace)
private bool IsBehind(EntityUid user, EntityUid target, float minAngleFromFace)
{
if (!TryComp(target, out TransformComponent? targetTransform)) return false;
var targetLocalCardinal = targetTransform.LocalRotation.GetCardinalDir().ToAngle();
Expand Down

0 comments on commit b2bd377

Please sign in to comment.