From 8514b946834a6c55b4e5e7179d6f3d59cf01bf79 Mon Sep 17 00:00:00 2001 From: Remuchi Date: Wed, 27 Mar 2024 16:56:45 +0700 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D1=81=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D0=B5=D0=BC=D1=8B=20=D1=82=D0=B0=D1=81=D0=BA=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Changeling/ChangelingSystem.Abilities.cs | 2 +- .../Unit/EntitySystems/DisposalUnitSystem.cs | 2 +- .../Resist/EscapeInventorySystem.cs | 22 +- .../_White/Carrying/BeingCarriedComponent.cs | 19 +- .../_White/Carrying/CarriableComponent.cs | 27 +- .../_White/Carrying/CarryingComponent.cs | 19 +- .../_White/Carrying/CarryingSystem.cs | 554 +++++++++--------- .../_White/Carrying/CarryingDoAfterEvent.cs | 10 - .../Carrying/CarryingSlowdownComponent.cs | 33 +- .../_White/Carrying/CarryingSlowdownSystem.cs | 64 +- 10 files changed, 357 insertions(+), 395 deletions(-) delete mode 100644 Content.Shared/_White/Carrying/CarryingDoAfterEvent.cs diff --git a/Content.Server/Changeling/ChangelingSystem.Abilities.cs b/Content.Server/Changeling/ChangelingSystem.Abilities.cs index 025d9d3ce1..8ca2dbfbe2 100644 --- a/Content.Server/Changeling/ChangelingSystem.Abilities.cs +++ b/Content.Server/Changeling/ChangelingSystem.Abilities.cs @@ -1,11 +1,11 @@ using System.Linq; +using Content.Server._White.Carrying; using Content.Server._White.Cult.GameRule; using Content.Server.Administration.Systems; using Content.Server.Bible.Components; using Content.Server.Body.Components; using Content.Server.Body.Systems; using Content.Server.Borer; -using Content.Server.Carrying; using Content.Server.Cuffs; using Content.Server.DoAfter; using Content.Server.Emp; diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs index 2346d5a447..48cf239417 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs @@ -1,9 +1,9 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; +using Content.Server._White.Carrying; using Content.Server.Administration.Logs; using Content.Server.Atmos.EntitySystems; using Content.Server.Disposal.Tube; -using Content.Server.Carrying; using Content.Server.Disposal.Tube.Components; using Content.Server.Disposal.Unit.Components; using Content.Server.Popups; diff --git a/Content.Server/Resist/EscapeInventorySystem.cs b/Content.Server/Resist/EscapeInventorySystem.cs index f1bbb45817..13e69adb64 100644 --- a/Content.Server/Resist/EscapeInventorySystem.cs +++ b/Content.Server/Resist/EscapeInventorySystem.cs @@ -1,6 +1,6 @@ +using Content.Server._White.Carrying; using Content.Server.Popups; using Content.Server.Storage.Components; -using Content.Server.Carrying; using Content.Shared.Storage; using Content.Shared.Inventory; using Content.Shared.Hands.EntitySystems; @@ -41,7 +41,8 @@ public sealed class EscapeInventorySystem : EntitySystem if (!args.HasDirectionalMovement) return; - if (!_containerSystem.TryGetContainingContainer(uid, out var container) || !_actionBlockerSystem.CanInteract(uid, container.Owner)) + if (!_containerSystem.TryGetContainingContainer(uid, out var container) || + !_actionBlockerSystem.CanInteract(uid, container.Owner)) return; // Make sure there's nothing stopped the removal (like being glued) @@ -59,16 +60,22 @@ public sealed class EscapeInventorySystem : EntitySystem } // Uncontested - if (HasComp(container.Owner) || HasComp(container.Owner) || HasComp(container.Owner)) + if (HasComp(container.Owner) || HasComp(container.Owner) || + HasComp(container.Owner)) AttemptEscape(uid, container.Owner, component); } - public void AttemptEscape(EntityUid user, EntityUid container, CanEscapeInventoryComponent component, float multiplier = 1f) + public void AttemptEscape( + EntityUid user, + EntityUid container, + CanEscapeInventoryComponent component, + float multiplier = 1f) { if (component.IsEscaping) return; - var doAfterEventArgs = new DoAfterArgs(EntityManager, user, component.BaseResistTime * multiplier, new EscapeInventoryEvent(), user, target: container) + var doAfterEventArgs = new DoAfterArgs(EntityManager, user, component.BaseResistTime * multiplier, + new EscapeInventoryEvent(), user, target: container) { BreakOnMove = true, BreakOnDamage = true, @@ -79,7 +86,8 @@ public sealed class EscapeInventorySystem : EntitySystem return; _popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting"), user, user); - _popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting-target"), container, container); + _popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting-target"), container, + container); } private void OnEscape(EntityUid uid, CanEscapeInventoryComponent component, EscapeInventoryEvent args) @@ -105,4 +113,4 @@ public sealed class EscapeInventorySystem : EntitySystem if (component.DoAfter != null) _doAfterSystem.Cancel(component.DoAfter); } -} +} \ No newline at end of file diff --git a/Content.Server/_White/Carrying/BeingCarriedComponent.cs b/Content.Server/_White/Carrying/BeingCarriedComponent.cs index afc78978c8..dbf98cb4e3 100644 --- a/Content.Server/_White/Carrying/BeingCarriedComponent.cs +++ b/Content.Server/_White/Carrying/BeingCarriedComponent.cs @@ -1,11 +1,10 @@ -namespace Content.Server.Carrying +namespace Content.Server._White.Carrying; + +/// +/// Stores the carrier of an entity being carried. +/// +[RegisterComponent] +public sealed partial class BeingCarriedComponent : Component { - /// - /// Stores the carrier of an entity being carried. - /// - [RegisterComponent] - public sealed partial class BeingCarriedComponent : Component - { - public EntityUid Carrier = default!; - } -} + public EntityUid Carrier = default!; +} \ No newline at end of file diff --git a/Content.Server/_White/Carrying/CarriableComponent.cs b/Content.Server/_White/Carrying/CarriableComponent.cs index f4fd1fa6d5..3ae2335d47 100644 --- a/Content.Server/_White/Carrying/CarriableComponent.cs +++ b/Content.Server/_White/Carrying/CarriableComponent.cs @@ -1,17 +1,16 @@ using System.Threading; -namespace Content.Server.Carrying -{ - [RegisterComponent] - public sealed partial class CarriableComponent : Component - { - /// - /// Number of free hands required - /// to carry the entity - /// - [DataField("freeHandsRequired")] - public int FreeHandsRequired = 2; +namespace Content.Server._White.Carrying; - public CancellationTokenSource? CancelToken; - } -} +[RegisterComponent] +public sealed partial class CarriableComponent : Component +{ + /// + /// Number of free hands required + /// to carry the entity + /// + [DataField] + public int FreeHandsRequired = 2; + + public CancellationTokenSource? CancelToken; +} \ No newline at end of file diff --git a/Content.Server/_White/Carrying/CarryingComponent.cs b/Content.Server/_White/Carrying/CarryingComponent.cs index e79460595b..337ca63b0b 100644 --- a/Content.Server/_White/Carrying/CarryingComponent.cs +++ b/Content.Server/_White/Carrying/CarryingComponent.cs @@ -1,11 +1,10 @@ -namespace Content.Server.Carrying +namespace Content.Server._White.Carrying; + +/// +/// Added to an entity when they are carrying somebody. +/// +[RegisterComponent] +public sealed partial class CarryingComponent : Component { - /// - /// Added to an entity when they are carrying somebody. - /// - [RegisterComponent] - public sealed partial class CarryingComponent : Component - { - public EntityUid Carried = default!; - } -} + public EntityUid Carried = default!; +} \ No newline at end of file diff --git a/Content.Server/_White/Carrying/CarryingSystem.cs b/Content.Server/_White/Carrying/CarryingSystem.cs index cce1465c1a..fc8a78247d 100644 --- a/Content.Server/_White/Carrying/CarryingSystem.cs +++ b/Content.Server/_White/Carrying/CarryingSystem.cs @@ -1,313 +1,307 @@ using System.Threading; using Content.Server.DoAfter; -using Content.Server.Resist; -using Content.Server.Popups; using Content.Server.Inventory; +using Content.Server.Popups; +using Content.Server.Resist; +using Content.Shared._White.Carrying; using Content.Shared._White.Crossbow; -using Content.Shared.Mobs; -using Content.Shared.DoAfter; -using Content.Shared.Buckle.Components; -using Content.Shared.Hands.Components; -using Content.Shared.Hands; -using Content.Shared.Stunnable; -using Content.Shared.Interaction.Events; -using Content.Shared.Verbs; -using Content.Shared.Carrying; -using Content.Shared.Movement.Events; -using Content.Shared.Movement.Systems; -using Content.Shared.Standing; using Content.Shared.ActionBlocker; +using Content.Shared.Buckle.Components; using Content.Shared.Climbing.Events; +using Content.Shared.DoAfter; +using Content.Shared.Hands; +using Content.Shared.Hands.Components; +using Content.Shared.Interaction.Events; using Content.Shared.Inventory.VirtualItem; -using Content.Shared.Throwing; +using Content.Shared.Mobs; using Content.Shared.Mobs.Systems; +using Content.Shared.Movement.Events; +using Content.Shared.Movement.Pulling.Components; using Content.Shared.Movement.Pulling.Events; using Content.Shared.Movement.Pulling.Systems; +using Content.Shared.Movement.Systems; +using Content.Shared.Standing; +using Content.Shared.Stunnable; +using Content.Shared.Throwing; +using Content.Shared.Verbs; +using Robust.Server.GameObjects; using Robust.Shared.Map.Components; -namespace Content.Server.Carrying +namespace Content.Server._White.Carrying; + +public sealed class CarryingSystem : EntitySystem { - public sealed class CarryingSystem : EntitySystem + [Dependency] private readonly VirtualItemSystem _virtualItemSystem = default!; + [Dependency] private readonly CarryingSlowdownSystem _slowdown = default!; + [Dependency] private readonly DoAfterSystem _doAfterSystem = default!; + [Dependency] private readonly StandingStateSystem _standingState = default!; + [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; + [Dependency] private readonly PullingSystem _pullingSystem = default!; + [Dependency] private readonly MobStateSystem _mobStateSystem = default!; + [Dependency] private readonly EscapeInventorySystem _escapeInventorySystem = default!; + [Dependency] private readonly PopupSystem _popupSystem = default!; + [Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!; + [Dependency] private readonly PenetratedSystem _penetrated = default!; + [Dependency] private readonly TransformSystem _transform = default!; + + public override void Initialize() { - [Dependency] private readonly VirtualItemSystem _virtualItemSystem = default!; - [Dependency] private readonly CarryingSlowdownSystem _slowdown = default!; - [Dependency] private readonly DoAfterSystem _doAfterSystem = default!; - [Dependency] private readonly StandingStateSystem _standingState = default!; - [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; - [Dependency] private readonly PullingSystem _pullingSystem = default!; - [Dependency] private readonly MobStateSystem _mobStateSystem = default!; - [Dependency] private readonly EscapeInventorySystem _escapeInventorySystem = default!; - [Dependency] private readonly PopupSystem _popupSystem = default!; - [Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!; - [Dependency] private readonly PenetratedSystem _penetrated = default!; + base.Initialize(); + SubscribeLocalEvent>(AddCarryVerb); + SubscribeLocalEvent(OnVirtualItemDeleted); + SubscribeLocalEvent(OnThrow); + SubscribeLocalEvent(OnParentChanged); + SubscribeLocalEvent(OnMobStateChanged); + SubscribeLocalEvent(OnInteractionAttempt); + SubscribeLocalEvent(OnMoveInput); + SubscribeLocalEvent(OnMoveAttempt); + SubscribeLocalEvent(OnStandAttempt); + SubscribeLocalEvent(OnInteractedWith); + SubscribeLocalEvent(OnPullAttempt); + SubscribeLocalEvent(OnStartClimb); + SubscribeLocalEvent(OnBuckleChange); + SubscribeLocalEvent(OnDoAfter); + } - public override void Initialize() + private void AddCarryVerb(EntityUid uid, CarriableComponent component, GetVerbsEvent args) + { + if (!args.CanInteract || !args.CanAccess) + return; + + if (!CanCarry(args.User, uid, component)) + return; + + if (HasComp(args.User)) // yeah not dealing with that + return; + + if (HasComp(args.User) || HasComp(args.Target)) + return; + + if (!_mobStateSystem.IsAlive(args.User)) + return; + + if (args.User == args.Target) + return; + + AlternativeVerb verb = new() { - base.Initialize(); - SubscribeLocalEvent>(AddCarryVerb); - SubscribeLocalEvent(OnVirtualItemDeleted); - SubscribeLocalEvent(OnThrow); - SubscribeLocalEvent(OnParentChanged); - SubscribeLocalEvent(OnMobStateChanged); - SubscribeLocalEvent(OnInteractionAttempt); - SubscribeLocalEvent(OnMoveInput); - SubscribeLocalEvent(OnMoveAttempt); - SubscribeLocalEvent(OnStandAttempt); - SubscribeLocalEvent(OnInteractedWith); - SubscribeLocalEvent(OnPullAttempt); - SubscribeLocalEvent(OnStartClimb); - SubscribeLocalEvent(OnBuckleChange); - SubscribeLocalEvent(OnDoAfter); - } - - - private void AddCarryVerb(EntityUid uid, CarriableComponent component, GetVerbsEvent args) - { - if (!args.CanInteract || !args.CanAccess) - return; - - if (!CanCarry(args.User, uid, component)) - return; - - if (HasComp(args.User)) // yeah not dealing with that - return; - - if (HasComp(args.User) || HasComp(args.Target)) - return; - - if (!_mobStateSystem.IsAlive(args.User)) - return; - - if (args.User == args.Target) - return; - - AlternativeVerb verb = new() + Act = () => { - Act = () => - { - StartCarryDoAfter(args.User, uid, component); - }, - Text = Loc.GetString("carry-verb"), - Priority = 2 - }; - args.Verbs.Add(verb); - } + StartCarryDoAfter(args.User, uid, component); + }, + Text = Loc.GetString("carry-verb"), + Priority = 2 + }; - /// - /// Since the carried entity is stored as 2 virtual items, when deleted we want to drop them. - /// - private void OnVirtualItemDeleted(EntityUid uid, CarryingComponent component, VirtualItemDeletedEvent args) - { - if (!HasComp(args.BlockingEntity)) - return; + args.Verbs.Add(verb); + } - DropCarried(uid, args.BlockingEntity); - } + /// + /// Since the carried entity is stored as 2 virtual items, when deleted we want to drop them. + /// + private void OnVirtualItemDeleted(EntityUid uid, CarryingComponent component, VirtualItemDeletedEvent args) + { + if (!HasComp(args.BlockingEntity)) + return; - /// - /// Basically using virtual item passthrough to throw the carried person. A new age! - /// Maybe other things besides throwing should use virt items like this... - /// - private void OnThrow(EntityUid uid, CarryingComponent component, ref BeforeThrowEvent args) - { - if (!TryComp(args.ItemUid, out var virtItem) || !HasComp(virtItem.BlockingEntity)) - return; + DropCarried(uid, args.BlockingEntity); + } - args.ItemUid = virtItem.BlockingEntity; + /// + /// Basically using virtual item passthrough to throw the carried person. A new age! + /// Maybe other things besides throwing should use virt items like this... + /// + private void OnThrow(EntityUid uid, CarryingComponent component, ref BeforeThrowEvent args) + { + if (!TryComp(args.ItemUid, out var virtItem) || + !HasComp(virtItem.BlockingEntity)) + return; - var multiplier = _contests.MassContest(uid, virtItem.BlockingEntity); - args.ThrowStrength = 5f * multiplier; - } + args.ItemUid = virtItem.BlockingEntity; + } - private void OnParentChanged(EntityUid uid, CarryingComponent component, ref EntParentChangedMessage args) - { - if (Transform(uid).MapID != args.OldMapId) - return; + private void OnParentChanged(EntityUid uid, CarryingComponent component, ref EntParentChangedMessage args) + { + if (Transform(uid).MapID != args.OldMapId) + return; - DropCarried(uid, component.Carried); - } + DropCarried(uid, component.Carried); + } - private void OnMobStateChanged(EntityUid uid, CarryingComponent component, MobStateChangedEvent args) - { - DropCarried(uid, component.Carried); - } + private void OnMobStateChanged(EntityUid uid, CarryingComponent component, MobStateChangedEvent args) + { + DropCarried(uid, component.Carried); + } - /// - /// Only let the person being carried interact with their carrier and things on their person. - /// - private void OnInteractionAttempt(EntityUid uid, BeingCarriedComponent component, InteractionAttemptEvent args) - { - if (args.Target == null) - return; + /// + /// Only let the person being carried interact with their carrier and things on their person. + /// + private void OnInteractionAttempt(EntityUid uid, BeingCarriedComponent component, InteractionAttemptEvent args) + { + if (args.Target == null) + return; - var targetParent = Transform(args.Target.Value).ParentUid; + var targetParent = Transform(args.Target.Value).ParentUid; - if (args.Target.Value != component.Carrier && targetParent != component.Carrier && targetParent != uid) - args.Cancel(); - } - - /// - /// Try to escape via the escape inventory system. - /// - private void OnMoveInput(EntityUid uid, BeingCarriedComponent component, ref MoveInputEvent args) - { - if (!TryComp(uid, out var escape)) - return; - - if (_actionBlockerSystem.CanInteract(uid, component.Carrier)) - { - _escapeInventorySystem.AttemptEscape(uid, component.Carrier, escape, _contests.MassContest(uid, component.Carrier)); - } - } - - private void OnMoveAttempt(EntityUid uid, BeingCarriedComponent component, UpdateCanMoveEvent args) - { + if (args.Target.Value != component.Carrier && targetParent != component.Carrier && targetParent != uid) args.Cancel(); - } + } - private void OnStandAttempt(EntityUid uid, BeingCarriedComponent component, StandAttemptEvent args) + /// + /// Try to escape via the escape inventory system. + /// + private void OnMoveInput(EntityUid uid, BeingCarriedComponent component, ref MoveInputEvent args) + { + if (!TryComp(uid, out var escape)) + return; + + if (_actionBlockerSystem.CanInteract(uid, component.Carrier)) { - args.Cancel(); - } - - private void OnInteractedWith(EntityUid uid, BeingCarriedComponent component, GettingInteractedWithAttemptEvent args) - { - if (args.Uid != component.Carrier) - args.Cancel(); - } - - private void OnPullAttempt(EntityUid uid, BeingCarriedComponent component, PullAttemptEvent args) - { - args.Cancelled = true; - } - - private void OnStartClimb(EntityUid uid, BeingCarriedComponent component, StartClimbEvent args) - { - DropCarried(component.Carrier, uid); - } - - private void OnBuckleChange(EntityUid uid, BeingCarriedComponent component, ref BuckleChangeEvent args) - { - DropCarried(component.Carrier, uid); - } - - private void OnDoAfter(EntityUid uid, CarriableComponent component, CarryDoAfterEvent args) - { - component.CancelToken = null; - if (args.Handled || args.Cancelled) - return; - - if (!CanCarry(args.Args.User, uid, component)) - return; - - Carry(args.Args.User, uid); - args.Handled = true; - } - private void StartCarryDoAfter(EntityUid carrier, EntityUid carried, CarriableComponent component) - { - TimeSpan length = TimeSpan.FromSeconds(3); - - var mod = _contests.MassContest(carrier, carried); - - if (mod != 0) - length /= mod; - - if (length >= TimeSpan.FromSeconds(9)) - { - _popupSystem.PopupEntity(Loc.GetString("carry-too-heavy"), carried, carrier, Shared.Popups.PopupType.SmallCaution); - return; - } - - if (!HasComp(carried)) - length *= 2f; - - component.CancelToken = new CancellationTokenSource(); - - var ev = new CarryDoAfterEvent(); - var args = new DoAfterArgs(EntityManager, carrier, length, ev, carried, target: carried) - { - BreakOnTargetMove = true, - BreakOnUserMove = true, - NeedHand = true - }; - - _doAfterSystem.TryStartDoAfter(args); - } - - private void Carry(EntityUid carrier, EntityUid carried) - { - if (TryComp(carried, out var pullable)) - _pullingSystem.TryStopPull(pullable); - - _penetrated.FreePenetrated(carried); - - Transform(carrier).AttachToGridOrMap(); - Transform(carried).AttachToGridOrMap(); - Transform(carried).Coordinates = Transform(carrier).Coordinates; - Transform(carried).AttachParent(Transform(carrier)); - _virtualItemSystem.TrySpawnVirtualItemInHand(carried, carrier); - _virtualItemSystem.TrySpawnVirtualItemInHand(carried, carrier); - var carryingComp = EnsureComp(carrier); - ApplyCarrySlowdown(carrier, carried); - var carriedComp = EnsureComp(carried); - EnsureComp(carried); - EnsureComp(carried); - - carryingComp.Carried = carried; - carriedComp.Carrier = carrier; - - _actionBlockerSystem.UpdateCanMove(carried); - } - - public void DropCarried(EntityUid carrier, EntityUid carried) - { - RemComp(carrier); // get rid of this first so we don't recusrively fire that event - RemComp(carrier); - RemComp(carried); - RemComp(carried); - RemComp(carried); - _actionBlockerSystem.UpdateCanMove(carried); - _virtualItemSystem.DeleteInHandsMatching(carrier, carried); - Transform(carried).AttachToGridOrMap(); - _standingState.Stand(carried); - _movementSpeed.RefreshMovementSpeedModifiers(carrier); - } - - private void ApplyCarrySlowdown(EntityUid carrier, EntityUid carried) - { - var massRatio = _contests.MassContest(carrier, carried); - - if (massRatio == 0) - massRatio = 1; - - var massRatioSq = Math.Pow(massRatio, 2); - var modifier = (1 - (0.15 / massRatioSq)); - modifier = Math.Max(0.1, modifier); - var slowdownComp = EnsureComp(carrier); - _slowdown.SetModifier(carrier, (float) modifier, (float) modifier, slowdownComp); - } - - public bool CanCarry(EntityUid carrier, EntityUid carried, CarriableComponent? carriedComp = null) - { - if (!Resolve(carried, ref carriedComp, false)) - return false; - - if (carriedComp.CancelToken != null) - return false; - - if (!HasComp(Transform(carrier).ParentUid)) - return false; - - if (HasComp(carrier) || HasComp(carried)) - return false; - - if (!TryComp(carrier, out var hands)) - return false; - - if (hands.CountFreeHands() < carriedComp.FreeHandsRequired) - return false; - - return true; + _escapeInventorySystem.AttemptEscape(uid, component.Carrier, escape); } } -} + + private void OnMoveAttempt(EntityUid uid, BeingCarriedComponent component, UpdateCanMoveEvent args) + { + args.Cancel(); + } + + private void OnStandAttempt(EntityUid uid, BeingCarriedComponent component, StandAttemptEvent args) + { + args.Cancel(); + } + + private void OnInteractedWith( + EntityUid uid, + BeingCarriedComponent component, + GettingInteractedWithAttemptEvent args) + { + if (args.Uid != component.Carrier) + args.Cancel(); + } + + private void OnPullAttempt(EntityUid uid, BeingCarriedComponent component, PullAttemptEvent args) + { + args.Cancelled = true; + } + + private void OnStartClimb(EntityUid uid, BeingCarriedComponent component, StartClimbEvent args) + { + DropCarried(component.Carrier, uid); + } + + private void OnBuckleChange(EntityUid uid, BeingCarriedComponent component, ref BuckleChangeEvent args) + { + DropCarried(component.Carrier, uid); + } + + private void OnDoAfter(EntityUid uid, CarriableComponent component, CarryDoAfterEvent args) + { + component.CancelToken = null; + if (args.Handled || args.Cancelled) + return; + + if (!CanCarry(args.Args.User, uid, component)) + return; + + Carry(args.Args.User, uid); + args.Handled = true; + } + + private void StartCarryDoAfter(EntityUid carrier, EntityUid carried, CarriableComponent component) + { + var length = TimeSpan.FromSeconds(6); // т.к. удалили систему разницы масс увеличу время с 3 до 6 + if (length >= TimeSpan.FromSeconds(9)) + { + _popupSystem.PopupEntity(Loc.GetString("carry-too-heavy"), carried, carrier, + Shared.Popups.PopupType.SmallCaution); + + return; + } + + if (!HasComp(carried)) + length *= 2f; + + component.CancelToken = new CancellationTokenSource(); + + var ev = new CarryDoAfterEvent(); + var args = new DoAfterArgs(EntityManager, carrier, length, ev, carried, target: carried) + { + BreakOnMove = true, + NeedHand = true + }; + + _doAfterSystem.TryStartDoAfter(args); + } + + private void Carry(EntityUid carrier, EntityUid carried) + { + if (TryComp(carried, out var pullable)) + _pullingSystem.TryStopPull(carried, pullable); + + _penetrated.FreePenetrated(carried); + + _transform.AttachToGridOrMap(carrier); + _transform.AttachToGridOrMap(carried); + _transform.SetCoordinates(carried, Transform(carrier).Coordinates); + _transform.SetParent(carried, carrier); + + _virtualItemSystem.TrySpawnVirtualItemInHand(carried, carrier); + _virtualItemSystem.TrySpawnVirtualItemInHand(carried, carrier); + + var carryingComp = EnsureComp(carrier); + ApplyCarrySlowdown(carrier); + var carriedComp = EnsureComp(carried); + EnsureComp(carried); + EnsureComp(carried); + + carryingComp.Carried = carried; + carriedComp.Carrier = carrier; + + _actionBlockerSystem.UpdateCanMove(carried); + } + + public void DropCarried(EntityUid carrier, EntityUid carried) + { + RemComp(carrier); // get rid of this first so we don't recusrively fire that event + RemComp(carrier); + RemComp(carried); + RemComp(carried); + RemComp(carried); + + _actionBlockerSystem.UpdateCanMove(carried); + _virtualItemSystem.DeleteInHandsMatching(carrier, carried); + _transform.AttachToGridOrMap(carried); + _standingState.Stand(carried); + _movementSpeed.RefreshMovementSpeedModifiers(carrier); + } + + private void ApplyCarrySlowdown(EntityUid carrier) + { + var slowdownComp = EnsureComp(carrier); + _slowdown.SetModifier(carrier, slowdownComp); + } + + public bool CanCarry(EntityUid carrier, EntityUid carried, CarriableComponent? carriedComp = null) + { + if (!Resolve(carried, ref carriedComp, false)) + return false; + + if (carriedComp.CancelToken != null) + return false; + + if (!HasComp(Transform(carrier).ParentUid)) + return false; + + if (HasComp(carrier) || HasComp(carried)) + return false; + + if (!TryComp(carrier, out var hands)) + return false; + + if (hands.CountFreeHands() < carriedComp.FreeHandsRequired) + return false; + + return true; + } +} \ No newline at end of file diff --git a/Content.Shared/_White/Carrying/CarryingDoAfterEvent.cs b/Content.Shared/_White/Carrying/CarryingDoAfterEvent.cs deleted file mode 100644 index 6acd6b775f..0000000000 --- a/Content.Shared/_White/Carrying/CarryingDoAfterEvent.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Robust.Shared.Serialization; -using Content.Shared.DoAfter; - -namespace Content.Shared.Carrying -{ - [Serializable, NetSerializable] - public sealed partial class CarryDoAfterEvent : SimpleDoAfterEvent - { - } -} diff --git a/Content.Shared/_White/Carrying/CarryingSlowdownComponent.cs b/Content.Shared/_White/Carrying/CarryingSlowdownComponent.cs index aabde66af0..5085a6bea0 100644 --- a/Content.Shared/_White/Carrying/CarryingSlowdownComponent.cs +++ b/Content.Shared/_White/Carrying/CarryingSlowdownComponent.cs @@ -1,28 +1,13 @@ using Robust.Shared.GameStates; -using Robust.Shared.Serialization; -namespace Content.Shared.Carrying +namespace Content.Shared._White.Carrying; + +[RegisterComponent, NetworkedComponent, Access(typeof(CarryingSlowdownSystem)), AutoGenerateComponentState] +public sealed partial class CarryingSlowdownComponent : Component { - [RegisterComponent, NetworkedComponent, Access(typeof(CarryingSlowdownSystem))] + [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + public float WalkModifier = 0.7f; - public sealed partial class CarryingSlowdownComponent : Component - { - [DataField("walkModifier", required: true)] [ViewVariables(VVAccess.ReadWrite)] - public float WalkModifier = 1.0f; - - [DataField("sprintModifier", required: true)] [ViewVariables(VVAccess.ReadWrite)] - public float SprintModifier = 1.0f; - } - - [Serializable, NetSerializable] - public sealed class CarryingSlowdownComponentState : ComponentState - { - public float WalkModifier; - public float SprintModifier; - public CarryingSlowdownComponentState(float walkModifier, float sprintModifier) - { - WalkModifier = walkModifier; - SprintModifier = sprintModifier; - } - } -} + [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + public float SprintModifier = 0.7f; +} \ No newline at end of file diff --git a/Content.Shared/_White/Carrying/CarryingSlowdownSystem.cs b/Content.Shared/_White/Carrying/CarryingSlowdownSystem.cs index 9b9c8cec10..6812ca484b 100644 --- a/Content.Shared/_White/Carrying/CarryingSlowdownSystem.cs +++ b/Content.Shared/_White/Carrying/CarryingSlowdownSystem.cs @@ -1,47 +1,35 @@ +using Content.Shared.DoAfter; using Content.Shared.Movement.Systems; -using Robust.Shared.GameStates; +using Robust.Shared.Serialization; -namespace Content.Shared.Carrying +namespace Content.Shared._White.Carrying; + +public sealed class CarryingSlowdownSystem : EntitySystem { - public sealed class CarryingSlowdownSystem : EntitySystem + [Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!; + + public override void Initialize() { - [Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!; + base.Initialize(); + SubscribeLocalEvent(OnRefreshMoveSpeed); + } - public override void Initialize() - { - base.Initialize(); - SubscribeLocalEvent(OnGetState); - SubscribeLocalEvent(OnHandleState); - SubscribeLocalEvent(OnRefreshMoveSpeed); - } + public void SetModifier(EntityUid uid, CarryingSlowdownComponent? component = null) + { + if (!Resolve(uid, ref component)) + return; - public void SetModifier(EntityUid uid, float walkSpeedModifier, float sprintSpeedModifier, CarryingSlowdownComponent? component = null) - { - if (!Resolve(uid, ref component)) - return; + _movementSpeed.RefreshMovementSpeedModifiers(uid); + } - component.WalkModifier = walkSpeedModifier; - component.SprintModifier = sprintSpeedModifier; - _movementSpeed.RefreshMovementSpeedModifiers(uid); - } - private void OnGetState(EntityUid uid, CarryingSlowdownComponent component, ref ComponentGetState args) - { - args.State = new CarryingSlowdownComponentState(component.WalkModifier, component.SprintModifier); - } - - private void OnHandleState(EntityUid uid, CarryingSlowdownComponent component, ref ComponentHandleState args) - { - if (args.Current is CarryingSlowdownComponentState state) - { - component.WalkModifier = state.WalkModifier; - component.SprintModifier = state.SprintModifier; - - _movementSpeed.RefreshMovementSpeedModifiers(uid); - } - } - private void OnRefreshMoveSpeed(EntityUid uid, CarryingSlowdownComponent component, RefreshMovementSpeedModifiersEvent args) - { - args.ModifySpeed(component.WalkModifier, component.SprintModifier); - } + private void OnRefreshMoveSpeed( + EntityUid uid, + CarryingSlowdownComponent component, + RefreshMovementSpeedModifiersEvent args) + { + args.ModifySpeed(component.WalkModifier, component.SprintModifier); } } + +[Serializable, NetSerializable] +public sealed partial class CarryDoAfterEvent : SimpleDoAfterEvent; \ No newline at end of file