Skip to content

Commit

Permalink
re: LayDownSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
Fragoler committed Feb 26, 2024
1 parent 7ef9377 commit 57a38ae
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.Arcade2);
human.AddFunction(ContentKeyFunctions.Arcade3);

human.AddFunction(ContentKeyFunctions.ToggleStanding); // Exodus-crawling

// actions should be common (for ghosts, mobs, etc)
common.AddFunction(ContentKeyFunctions.OpenActionsMenu);

Expand Down
1 change: 1 addition & 0 deletions Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(EngineKeyFunctions.MoveLeft);
AddButton(EngineKeyFunctions.MoveDown);
AddButton(EngineKeyFunctions.MoveRight);
AddButton(ContentKeyFunctions.ToggleStanding); // Exodus-Crawling
AddButton(EngineKeyFunctions.Walk);
AddCheckBox("ui-options-hotkey-toggle-walk", _cfg.GetCVar(CCVars.ToggleWalk), HandleToggleWalk);
InitToggleWalk();
Expand Down
17 changes: 17 additions & 0 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Content.Server.Speech.EntitySystems;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.ActionBlocker;
using Content.Shared.CCVar;
using Content.Shared.Chat;
Expand Down Expand Up @@ -57,6 +59,8 @@ public sealed partial class ChatSystem : SharedChatSystem
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly ReplacementAccentSystem _wordreplacement = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;

public const int VoiceRange = 10; // how far voice goes in world units
public const int WhisperClearRange = 2; // how far whisper goes while still being understandable, in world units
Expand Down Expand Up @@ -269,6 +273,14 @@ public void TrySendInGameICMessage(
}
}

// Exodus-CritSpeech-Start
if (desiredType == InGameICChatType.Speak && _mobStateSystem.IsCritical(source))
{
SendEntityWhisper(source, message, range, null, nameOverride, hideLog, ignoreActionBlocker);
return;
}
// Exodus-CritSpeech-End

// Otherwise, send whatever type.
switch (desiredType)
{
Expand Down Expand Up @@ -562,6 +574,11 @@ private void SendEntityWhisper(

_replay.RecordServerMessage(new ChatMessage(ChatChannel.Whisper, message, wrappedMessage, GetNetEntity(source), null, MessageRangeHideChatForReplay(range)));

// Exodus-CritSpeech-Start
if (_mobStateSystem.IsCritical(source) && _prototype.TryIndex<DamageTypePrototype>("Asphyxiation", out var asphyxiation))
_damageable.TryChangeDamage(source, new(asphyxiation, 20), true, false);
// Exodus-Crit-Speech-End

var ev = new EntitySpokeEvent(source, message, channel, obfuscatedMessage);
RaiseLocalEvent(source, ev, true);
if (!hideLog)
Expand Down
34 changes: 34 additions & 0 deletions Content.Server/Standing/StandingStateController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Content.Server.DoAfter;
using Content.Shared.DoAfter;
using Content.Shared.Standing;

namespace Content.Server.Standing;
public sealed class StandingStateController : SharedStandingStateController
{
[Dependency] private readonly DoAfterSystem _doAfter = default!;

public override void HandleToggleStandingInput(EntityUid uid)
{
if (!TryComp<StandingStateComponent>(uid, out var standing) || !standing.CanCrawl || !standing.CanStandUp)
return;

if (standing.Standing)
{
var doAfterArgs = new DoAfterArgs(EntityManager, uid, standing.DownDelay, new DownDoAfterEvent(), uid)
{
BlockDuplicate = true,
BreakOnDamage = true,
};
_doAfter.TryStartDoAfter(doAfterArgs);
}
else
{
var doAfterArgs = new DoAfterArgs(EntityManager, uid, standing.StandDelay, new StandDoAfterEvent(), uid)
{
BlockDuplicate = true,
BreakOnDamage = true,
};
_doAfter.TryStartDoAfter(doAfterArgs);
}
}
}
4 changes: 3 additions & 1 deletion Content.Shared/CombatMode/SharedCombatModeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Shared.MouseRotator;
using Content.Shared.Movement.Components;
using Content.Shared.Popups;
using Content.Shared.Standing; // Exodus-Crawling
using Robust.Shared.Network;
using Robust.Shared.Timing;

Expand All @@ -13,6 +14,7 @@ public abstract class SharedCombatModeSystem : EntitySystem
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly StandingStateSystem _standing = default!; // Exodus-Crawling

public override void Initialize()
{
Expand Down Expand Up @@ -85,7 +87,7 @@ public virtual void SetInCombatMode(EntityUid entity, bool value, CombatModeComp
if (!component.ToggleMouseRotator || IsNpc(entity))
return;

SetMouseRotatorComponents(entity, value);
SetMouseRotatorComponents(entity, value && !_standing.IsDown(entity)); // Exodus-Crawling
}

private void SetMouseRotatorComponents(EntityUid uid, bool value)
Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Input/ContentKeyFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static class ContentKeyFunctions
public static readonly BoundKeyFunction TakeScreenshot = "TakeScreenshot";
public static readonly BoundKeyFunction TakeScreenshotNoUI = "TakeScreenshotNoUI";
public static readonly BoundKeyFunction ToggleFullscreen = "ToggleFullscreen";
public static readonly BoundKeyFunction ToggleStanding = "ToggleStanding"; // Exodus-Crawling
public static readonly BoundKeyFunction Point = "Point";
public static readonly BoundKeyFunction ZoomOut = "ZoomOut";
public static readonly BoundKeyFunction ZoomIn = "ZoomIn";
Expand Down
50 changes: 48 additions & 2 deletions Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using Content.Shared.Bed.Sleep;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Damage;
using Content.Shared.Damage.ForceSay;
using Content.Shared.Emoting;
using Content.Shared.Hands;
using Content.Shared.Humanoid;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Movement.Systems;
using Content.Shared.Pointing;
using Content.Shared.Pulling.Events;
using Content.Shared.Speech;
Expand Down Expand Up @@ -43,6 +47,7 @@ private void SubscribeEvents()
SubscribeLocalEvent<MobStateComponent, TryingToSleepEvent>(OnSleepAttempt);
SubscribeLocalEvent<MobStateComponent, CombatModeShouldHandInteractEvent>(OnCombatModeShouldHandInteract);
SubscribeLocalEvent<MobStateComponent, AttemptPacifiedAttackEvent>(OnAttemptPacifiedAttack);
SubscribeLocalEvent<MobStateComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeedModifiers);
}

private void OnStateExitSubscribers(EntityUid target, MobStateComponent component, MobState state)
Expand Down Expand Up @@ -83,7 +88,10 @@ private void OnStateEnteredSubscribers(EntityUid target, MobStateComponent compo
switch (state)
{
case MobState.Alive:
_standing.Stand(target);
// Exodus-Crawling-Start
if (!_standing.CanCrawl(target))
_standing.Stand(target);
// Exodus-Crawling-End
_appearance.SetData(target, MobStateVisuals.State, MobState.Alive);
break;
case MobState.Critical:
Expand Down Expand Up @@ -134,17 +142,28 @@ private void OnSpeakAttempt(EntityUid uid, MobStateComponent component, SpeakAtt
return;
}

// Exodus-Crit-Speech-Start
if (component.CurrentState == MobState.Critical)
return;
// Exodus-Crit-Speech-End

CheckAct(uid, component, args);
}

private void CheckAct(EntityUid target, MobStateComponent component, CancellableEntityEventArgs args)
{
switch (component.CurrentState)
{
// Exodus-CritSpeech-Start
case MobState.Dead:
case MobState.Critical:
args.Cancel();
break;
case MobState.Critical:
if (args is not UpdateCanMoveEvent || !HasComp<HumanoidAppearanceComponent>(target))
args.Cancel();
break;
//Exodus-CritSpeech-End

}
}

Expand Down Expand Up @@ -175,5 +194,32 @@ private void OnAttemptPacifiedAttack(Entity<MobStateComponent> ent, ref AttemptP
args.Cancelled = true;
}

private void OnRefreshMovementSpeedModifiers(EntityUid uid, MobStateComponent component, ref RefreshMovementSpeedModifiersEvent ev)
{
if (!HasComp<HumanoidAppearanceComponent>(uid))
return;

switch (component.CurrentState)
{
case MobState.Critical:
if (!TryComp<DamageableComponent>(uid, out var damageable))
return;

// Exodus-Crawling-Start
if (!TryComp<MovementSpeedModifierComponent>(uid, out var speed))
return;

if (!_mobThreshold.TryGetPercentageForState(uid, MobState.Dead, damageable.TotalDamage, out var percentage))
return;

var sprintSpeedModifier = (1 - (float) percentage) * 2 * 0.15f * speed.BaseSprintSpeed;
var walkSpeedModifier = (1 - (float) percentage) * 2 * 0.15f * speed.BaseWalkSpeed;

ev.ModifySpeed(sprintSpeedModifier, walkSpeedModifier);
// Exodus-Crawling-End
break;
}
}

#endregion
}
1 change: 1 addition & 0 deletions Content.Shared/Mobs/Systems/MobStateSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class MobStateSystem : EntitySystem
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!;
private ISawmill _sawmill = default!;

public override void Initialize()
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Movement/Systems/SharedMoverController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected void HandleMobMovement(
var canMove = mover.CanMove;
if (RelayTargetQuery.TryGetComponent(uid, out var relayTarget))
{
if (_mobState.IsIncapacitated(relayTarget.Source) ||
if (_mobState.IsDead(relayTarget.Source) ||
TryComp<SleepingComponent>(relayTarget.Source, out _) ||
!MoverQuery.TryGetComponent(relayTarget.Source, out var relayedMover))
{
Expand Down
42 changes: 42 additions & 0 deletions Content.Shared/Standing/SharedStandingStateController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Content.Shared.Input;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared.Physics.Controllers;
using Robust.Shared.Player;

namespace Content.Shared.Standing
{
public abstract class SharedStandingStateController : VirtualController
{
public override void Initialize()
{
base.Initialize();

CommandBinds.Builder
.Bind(ContentKeyFunctions.ToggleStanding, new StandingInputCmdHandler(this))
.Register<SharedStandingStateController>();
}

public abstract void HandleToggleStandingInput(EntityUid uid);

private sealed class StandingInputCmdHandler : InputCmdHandler
{
private readonly SharedStandingStateController _controller;

public StandingInputCmdHandler(SharedStandingStateController controller)
{
_controller = controller;
}

public override bool HandleCmdMessage(IEntityManager entManager, ICommonSession? session, IFullInputCmdMessage message)
{
if (session?.AttachedEntity == null) return true;

if (message.State == BoundKeyState.Down)
_controller.HandleToggleStandingInput(session.AttachedEntity.Value);

return true;
}
}
}
}
33 changes: 33 additions & 0 deletions Content.Shared/Standing/StandingStateComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,38 @@ public sealed partial class StandingStateComponent : Component
/// </summary>
[DataField, AutoNetworkedField]
public List<string> ChangedFixtures = new();

// Exodus-Crawling-Start

[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool CanCrawl { get; set; } = false;

/// <summary>
/// Is entity able to stand up in it's own
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool CanStandUp { get; set; } = true;

/// <summary>
/// Delay used in do after to lie down
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public TimeSpan DownDelay = TimeSpan.FromMilliseconds(500);

// <summary>
/// Delay used in do after to get up
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public TimeSpan StandDelay = TimeSpan.FromSeconds(1);

/// <summary>
/// Speed modificator which applies while entity crawling
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float CrawlingSpeedModifier = 0.3f;

// Exodus-Crawling-End
}
}
Loading

0 comments on commit 57a38ae

Please sign in to comment.