From 3d89dcef665440581a34feab1f7da79975de1349 Mon Sep 17 00:00:00 2001 From: BIGZi0348 Date: Sun, 5 Jan 2025 23:35:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BB=D0=BE=D0=BC=D0=B0=D0=BB=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BB=D0=B5=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_White/_Engi/Limping/LimpingComponent.cs | 27 +++++++ .../_Engi/Limping/LimpingHelperComponent.cs | 11 +++ .../_White/_Engi/Limping/LimpingSystem.cs | 80 +++++++++++++++++++ .../Entities/Objects/Weapons/Melee/cane.yml | 1 + Resources/Prototypes/Traits/disabilities.yml | 11 +++ .../_Engi/Entities/Objects/Misc/cane.yml | 12 +-- 6 files changed, 131 insertions(+), 11 deletions(-) create mode 100644 Content.Shared/_White/_Engi/Limping/LimpingComponent.cs create mode 100644 Content.Shared/_White/_Engi/Limping/LimpingHelperComponent.cs create mode 100644 Content.Shared/_White/_Engi/Limping/LimpingSystem.cs diff --git a/Content.Shared/_White/_Engi/Limping/LimpingComponent.cs b/Content.Shared/_White/_Engi/Limping/LimpingComponent.cs new file mode 100644 index 0000000000..67188e6325 --- /dev/null +++ b/Content.Shared/_White/_Engi/Limping/LimpingComponent.cs @@ -0,0 +1,27 @@ +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; + +namespace Content.Shared._White._Engi.Limping; + +/// +/// WD. +/// This is used for the Limping trait. +/// +[RegisterComponent, NetworkedComponent] +public sealed partial class LimpingComponent : Component +{ + [DataField] + public float SpeedModifier = 0.3f; + +} + +[Serializable, NetSerializable] +public sealed class LimpingComponentState : ComponentState +{ + public float SpeedModifier; + + public LimpingComponentState(float speedModifier) + { + SpeedModifier = speedModifier; + } +} diff --git a/Content.Shared/_White/_Engi/Limping/LimpingHelperComponent.cs b/Content.Shared/_White/_Engi/Limping/LimpingHelperComponent.cs new file mode 100644 index 0000000000..403337d538 --- /dev/null +++ b/Content.Shared/_White/_Engi/Limping/LimpingHelperComponent.cs @@ -0,0 +1,11 @@ +namespace Content.Shared._White._Engi.Limping; + +/// +/// WD. +/// This is used for the Limping trait to reduce it. +/// +[RegisterComponent] +public sealed partial class LimpingHelperComponent : Component +{ + +} diff --git a/Content.Shared/_White/_Engi/Limping/LimpingSystem.cs b/Content.Shared/_White/_Engi/Limping/LimpingSystem.cs new file mode 100644 index 0000000000..c16de5cfc0 --- /dev/null +++ b/Content.Shared/_White/_Engi/Limping/LimpingSystem.cs @@ -0,0 +1,80 @@ +using Content.Shared.Hands; +using Content.Shared.Movement.Systems; +using Robust.Shared.Timing; +using Robust.Shared.GameStates; +using Robust.Shared.Containers; + +namespace Content.Shared._White._Engi.Limping; + +public sealed class LimpingSystem : EntitySystem +{ + [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!; + [Dependency] private readonly SharedContainerSystem _container = default!; + + public override void Initialize() + { + SubscribeLocalEvent(OnGotEquipped); + SubscribeLocalEvent(OnGotUnequipped); + + SubscribeLocalEvent(OnRefreshMoveSpeed); + SubscribeLocalEvent(OnShutdown); + + SubscribeLocalEvent(OnGetState); + SubscribeLocalEvent(OnHandleState); + } + + private void OnShutdown(Entity ent, ref ComponentShutdown args) + { + _movementSpeed.RefreshMovementSpeedModifiers(ent); + } + + private void OnRefreshMoveSpeed(EntityUid uid, LimpingComponent component, RefreshMovementSpeedModifiersEvent args) + { + args.ModifySpeed(component.SpeedModifier, component.SpeedModifier); + } + + private void OnGotEquipped(Entity ent, ref GotEquippedHandEvent args) + { + if (_gameTiming.ApplyingState) + return; + + if (!TryComp(args.User, out var comp)) + return; + + if (_gameTiming.IsFirstTimePredicted) + comp.SpeedModifier = 0.5f; + + _movementSpeed.RefreshMovementSpeedModifiers(args.User); + } + + private void OnGotUnequipped(Entity ent, ref GotUnequippedHandEvent args) + { + if (!TryComp(args.User, out var comp)) + return; + + if (_gameTiming.IsFirstTimePredicted) + comp.SpeedModifier = 0.3f; + + _movementSpeed.RefreshMovementSpeedModifiers(args.User); + } + + private void OnGetState(EntityUid uid, LimpingComponent component, ref ComponentGetState args) + { + args.State = new LimpingComponentState(component.SpeedModifier); + } + + private void OnHandleState(EntityUid uid, LimpingComponent component, ref ComponentHandleState args) + { + if (args.Current is not LimpingComponentState state) + return; + + var diff = !MathHelper.CloseTo(component.SpeedModifier, state.SpeedModifier); + + if (diff && _container.TryGetContainingContainer(uid, out var container)) + { + component.SpeedModifier = state.SpeedModifier; + _movementSpeed.RefreshMovementSpeedModifiers(container.Owner); + } + } +} diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Melee/cane.yml b/Resources/Prototypes/Entities/Objects/Weapons/Melee/cane.yml index 9f5c32efdc..91339686d3 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Melee/cane.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Melee/cane.yml @@ -28,6 +28,7 @@ Blunt: 3 - type: UseDelay delay: 1 + - type: LimpingHelper # WD - type: entity name: cane blade diff --git a/Resources/Prototypes/Traits/disabilities.yml b/Resources/Prototypes/Traits/disabilities.yml index be1e981549..2cd77b880e 100644 --- a/Resources/Prototypes/Traits/disabilities.yml +++ b/Resources/Prototypes/Traits/disabilities.yml @@ -79,3 +79,14 @@ description: trait-snoring-desc components: - type: Snoring + +- type: trait # WD + id: Limping + traitGear: Cane + name: Хромота + description: Слабость в ногах мешает вам нормально передвигаться, трость может немного помочь. + blacklist: + components: + - BorgChassis + components: + - type: Limping diff --git a/Resources/Prototypes/_White/_Engi/Entities/Objects/Misc/cane.yml b/Resources/Prototypes/_White/_Engi/Entities/Objects/Misc/cane.yml index 8791b624db..c73b9acaa6 100644 --- a/Resources/Prototypes/_White/_Engi/Entities/Objects/Misc/cane.yml +++ b/Resources/Prototypes/_White/_Engi/Entities/Objects/Misc/cane.yml @@ -1,19 +1,9 @@ - type: entity - parent: BaseItem + parent: Cane id: OldCane name: трость старика description: Изношенная деревянная трость. components: - - type: Sprite - sprite: Objects/Weapons/Melee/cane.rsi - state: cane - - type: Item - size: Normal - storedRotation: -44 - shape: - - 0,0,0,2 - sprite: Objects/Weapons/Melee/cane.rsi - - type: Appearance - type: MeleeWeapon wideAnimationRotation: 45 damage: