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

Soft stamina #38

Merged
merged 10 commits into from
Sep 10, 2024
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
44 changes: 36 additions & 8 deletions Content.Shared/Crawling/CrawlingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Content.Shared.Buckle.Components;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.DoAfter;
using Content.Shared.Explosion;
using Content.Shared.Input;
Expand All @@ -17,14 +19,15 @@ public sealed partial class CrawlingSystem : EntitySystem
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly StaminaSystem _stamina = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<CrawlerComponent, CrawlStandupDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<CrawlerComponent, StandAttemptEvent>(OnStandUp);
SubscribeLocalEvent<CrawlerComponent, DownAttemptEvent>(OnFall);
SubscribeLocalEvent<CrawlerComponent, StunnedEvent>(OnStunned);
SubscribeLocalEvent<CrawlerComponent, BuckledEvent>(OnBuckled);
SubscribeLocalEvent<CrawlerComponent, GetExplosionResistanceEvent>(OnGetExplosionResistance);
SubscribeLocalEvent<CrawlerComponent, CrawlingAlertEvent>(OnCrawlingAlertEvent);
Expand All @@ -39,6 +42,17 @@ public override void Initialize()
.Register<CrawlingSystem>();
}

private bool IsSoftStunned(EntityUid uid)
{
if (!TryComp<StaminaComponent>(uid, out var stamComp))
return false;

if (stamComp.State != StunnedState.None)
return true;

return false;
}

private void ToggleCrawlingKeybind(ICommonSession? session)
{
if (session?.AttachedEntity == null)
Expand All @@ -51,23 +65,43 @@ private void ToggleCrawling(EntityUid uid, CrawlerComponent component, CrawlingK
{
if (args.Cancelled)
return;

if (IsSoftStunned(uid) && _standing.IsDown(uid))
{
args.Cancelled = true;
return;
}

SetCrawling(uid, component, !_standing.IsDown(uid));
}

public void SetCrawling(EntityUid uid, CrawlerComponent component, bool state)
{
///checks players standing state, downing player if they are standding and starts doafter with standing up if they are downed
//checks players standing state, downing player if they are standing and starts doafter with standing up if they are downed
switch (state)
{
case true:
{
_standing.Down(uid, dropHeldItems: false);
break;
}
case false:
{
if (HasComp<ActiveStaminaComponent>(uid) &&
TryComp<StaminaComponent>(uid, out var staminaComponent) &&
staminaComponent.State != StunnedState.None &&
staminaComponent.StaminaDamage > staminaComponent.CritThreshold)
{
break;
}

_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, uid, component.StandUpTime, new CrawlStandupDoAfterEvent(),
uid, used: uid)
{
BreakOnDamage = true
});
break;
}
}
}
private void OnCrawlingAlertEvent(EntityUid uid, CrawlerComponent component, CrawlingAlertEvent args)
Expand Down Expand Up @@ -97,12 +131,6 @@ private void OnFall(EntityUid uid, CrawlerComponent component, DownAttemptEvent
AddComp<CrawlingComponent>(uid);
//TODO: add hiding under table
}
private void OnStunned(EntityUid uid, CrawlerComponent component, StunnedEvent args)
{
if (!HasComp<CrawlingComponent>(uid))
AddComp<CrawlingComponent>(uid);
_alerts.ShowAlert(uid, component.CtawlingAlert);
}
private void OnBuckled(EntityUid uid, CrawlerComponent component, ref BuckledEvent args)
{
RemCompDeferred<CrawlingComponent>(uid);
Expand Down
14 changes: 11 additions & 3 deletions Content.Shared/Damage/Components/StaminaComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ namespace Content.Shared.Damage.Components;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true), AutoGenerateComponentPause]
public sealed partial class StaminaComponent : Component
{

/// <summary>
/// Have we reached peak stamina damage and been paralyzed?
/// Have we reached peak stamina damage and been paralyzed or crawling?
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool Critical;
public StunnedState State;

/// <summary>
/// How much stamina reduces per second.
Expand All @@ -39,7 +40,7 @@ public sealed partial class StaminaComponent : Component
/// How much stamina damage is required to entire stam crit.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public float CritThreshold = 100f;
public float CritThreshold = 50f;

/// <summary>
/// How long will this mob be stunned for?
Expand All @@ -57,3 +58,10 @@ public sealed partial class StaminaComponent : Component
[DataField]
public ProtoId<AlertPrototype> StaminaAlert = "Stamina";
}

public enum StunnedState
{
None,
Crawling,
Critical
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ public sealed partial class StaminaDamageOnCollideComponent : Component

[DataField("sound")]
public SoundSpecifier? Sound;

[DataField]
public bool Soft = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public sealed partial class StaminaDamageOnEmbedComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public float Damage = 10f;

[DataField]
public bool Soft = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ public sealed partial class StaminaDamageOnHitComponent : Component

[DataField("sound")]
public SoundSpecifier? Sound;

[DataField]
public bool Soft = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Content.Shared.Damage.Components;

/// <summary>
/// Multiplies the entity's <see cref="StaminaComponent.StaminaDamage"/> by the <see cref="Modifier"/>.
/// Multiplies the entity's <see cref="StaminaComponent.SoftStaminaDamage"/> by the <see cref="Modifier"/>.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(StaminaSystem))]
public sealed partial class StaminaModifierComponent : Component
Expand Down
Loading
Loading