Skip to content

Commit

Permalink
change a bit 4
Browse files Browse the repository at this point in the history
  • Loading branch information
pheenty committed Nov 20, 2024
1 parent 725183b commit b89b8f0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 79 deletions.
26 changes: 4 additions & 22 deletions Content.Server/Stories/Garrote/GarroteComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,15 @@ namespace Content.Server.Stories.Garrote;
[RegisterComponent]
public sealed partial class GarroteComponent : Component
{
/// <summary>
/// For how long a DoAfter lasts
/// </summary>
[DataField("doAfterTime")]
public TimeSpan DoAfterTime = TimeSpan.FromSeconds(5f);
public TimeSpan DoAfterTime = TimeSpan.FromSeconds(0.5f);

[DataField("damage")]
public float Damage = 5f;

/// <summary>
/// The mininum angle in degrees from face to back to use
/// </summary>
[DataField("minAngleFromFace")]
public float MinAngleFromFace = 90;

/// <summary>
/// Whether the garrote is being used at the moment
/// </summary>
[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>
[DataField]
public bool RemoveMute = false;
}
69 changes: 19 additions & 50 deletions Content.Server/Stories/Garrote/GarroteSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
using Content.Shared.Interaction;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Content.Shared.Speech.Muting;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable;
using Content.Shared.Wieldable.Components;
using Robust.Shared.Player;
Expand All @@ -28,23 +28,23 @@ public sealed class GarroteSystem : EntitySystem
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
[Dependency] private readonly RespiratorSystem _respirator = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffect = default!;
[Dependency] private readonly SharedStunSystem _stun = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GarroteComponent, AfterInteractEvent>(OnGarroteAttempt);
SubscribeLocalEvent<GarroteComponent, GarroteDoneEvent>(OnGarroteDone);
SubscribeLocalEvent<GarroteComponent, GarroteDoAfterEvent>(OnGarroteDoAfter);
}

private void OnGarroteAttempt(EntityUid uid, GarroteComponent comp, ref AfterInteractEvent args)
{
if (comp.Busy
|| args.User == args.Target
if (args.User == args.Target
|| !args.CanReach
|| !HasComp<BodyComponent>(args.Target)
|| !HasComp<DamageableComponent>(args.Target)
Expand All @@ -60,14 +60,14 @@ private void OnGarroteAttempt(EntityUid uid, GarroteComponent comp, ref AfterInt
if (!(mobstate.CurrentState == MobState.Alive && HasComp<RespiratorComponent>(args.Target)))
{
var message = Loc.GetString("garrote-component-doesnt-breath", ("target", args.Target));
_popupSystem.PopupEntity(message, uid, args.User);
_popupSystem.PopupEntity(message, args.Target.Value, args.User);
return;
}

if (!IsBehind(args.User, args.Target.Value, comp.MinAngleFromFace) && _actionBlocker.CanInteract(args.Target.Value, null))
{
var message = Loc.GetString("garrote-component-must-be-behind", ("target", args.Target));
_popupSystem.PopupEntity(message, uid, args.User);
_popupSystem.PopupEntity(message, args.Target.Value, args.User);
return;
}

Expand All @@ -77,74 +77,43 @@ 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)
var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, comp.DoAfterTime, new GarroteDoAfterEvent(), uid, target: args.Target)
{
BreakOnMove = true,
BreakOnDamage = true,
NeedHand = true
NeedHand = true,
DuplicateCondition = DuplicateConditions.SameTool
};

if (!_doAfter.TryStartDoAfter(doAfterEventArgs)) return;

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

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

if (!HasComp<MutedComponent>(args.Target))
{
comp.RemoveMute = true;
AddComp<MutedComponent>(args.Target.Value);
}

comp.Busy = true;
_stun.TryStun(args.Target.Value, 2*comp.DoAfterTime, true); // multiplying time by 2 to prevent mispredictons
_statusEffect.TryAddStatusEffect<MutedComponent>(args.Target.Value, "Muted", 2*comp.DoAfterTime, true);
}

private void OnGarroteDone(EntityUid uid, GarroteComponent comp, GarroteDoneEvent args)
private void OnGarroteDoAfter(EntityUid uid, GarroteComponent comp, GarroteDoAfterEvent args)
{
if (args.Target == null
|| !TryComp<DamageableComponent>(args.Target, out var damageable)
|| !TryComp<MobThresholdsComponent>(args.Target, out var thresholds)
|| !TryComp<RespiratorComponent>(args.Target, out var respirator)
|| !TryComp<MobStateComponent>(args.Target, out var mobstate))
{
comp.RemoveStun = false;
comp.RemoveMute = false;
comp.Busy = false;
return;
}

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

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

comp.Busy = false;

if (args.Cancelled || mobstate.CurrentState != MobState.Alive) return;

var critthreshold = _mobThresholdSystem.GetThresholdForState(args.Target.Value, MobState.Critical, thresholds);
var deadthreshold = _mobThresholdSystem.GetThresholdForState(args.Target.Value, MobState.Dead, thresholds);
var damage = critthreshold + 0.1 * (deadthreshold - critthreshold) - damageable.TotalDamage;
DamageSpecifier damageDealt = new(_prototypeManager.Index<DamageTypePrototype>("Asphyxiation"), damage);
_damageable.TryChangeDamage(args.Target, damageDealt, false, origin: args.User);
DamageSpecifier damage = new(_prototypeManager.Index<DamageTypePrototype>("Asphyxiation"), comp.Damage); // TODO: unhardcode asphyxiation?
_damageable.TryChangeDamage(args.Target, damage, false, origin: args.User);

var saturationDelta = respirator.MinSaturation - respirator.Saturation;
_respirator.UpdateSaturation(args.Target.Value, saturationDelta, respirator);

var message = Loc.GetString("garrote-component-complete", ("user", args.User), ("target", args.Target));
_popupSystem.PopupEntity(message, args.User, PopupType.LargeCaution);
_stun.TryStun(args.Target.Value, 2*comp.DoAfterTime, true);
_statusEffect.TryAddStatusEffect<MutedComponent>(args.Target.Value, "Muted", 2*comp.DoAfterTime, true);

args.Repeat = true;
}

private bool IsBehind(EntityUid user, EntityUid target, float minAngleFromFace)
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Stories/Garrote/GarroteEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Content.Shared.Stories.Garrote;

[Serializable, NetSerializable]

public sealed partial class GarroteDoneEvent : SimpleDoAfterEvent
public sealed partial class GarroteDoAfterEvent : SimpleDoAfterEvent
{
}
6 changes: 0 additions & 6 deletions Resources/Locale/ru-RU/_stories/garrote/garrote-component.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@ garrote-component-doesnt-breath = { $target } уже не дышит!
garrote-component-must-be-behind = Вы должны быть сзади { $target }.
garrote-component-started-target = { $user } начинает удушать вас!
garrote-component-started-others = { $user } начинает удушать { $target }!
garrote-component-complete = { $user } { GENDER($user) ->
[male] задушил
[female] задушила
[epicene] задушили
*[neuter] задушило
} { $target }!

0 comments on commit b89b8f0

Please sign in to comment.