diff --git a/Content.Server/_Sunrise/Carrying/CarryingSystem.cs b/Content.Server/_Sunrise/Carrying/CarryingSystem.cs index d4c847cbb8..217394b638 100644 --- a/Content.Server/_Sunrise/Carrying/CarryingSystem.cs +++ b/Content.Server/_Sunrise/Carrying/CarryingSystem.cs @@ -302,6 +302,9 @@ namespace Content.Server._Sunrise.Carrying } _standingState.Stand(carried); _movementSpeed.RefreshMovementSpeedModifiers(carrier); + + var ev = new CarryDroppedEvent(); + RaiseLocalEvent(carried, ref ev); } private void ApplyCarrySlowdown(EntityUid carrier, EntityUid carried) diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs index 5c95983631..9ee028e2b4 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs @@ -6,11 +6,15 @@ using Robust.Shared.Containers; using Robust.Shared.Map; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; +using Robust.Shared.Timing; // Sunrise-add +using Content.Shared._Sunrise.Item; // Sunrise-add namespace Content.Shared.Hands.EntitySystems; public abstract partial class SharedHandsSystem : EntitySystem { + [Dependency] private readonly IGameTiming _timing = default!; // Sunrise-add + private void InitializePickup() { SubscribeLocalEvent(HandleEntityInserted); @@ -104,6 +108,11 @@ public abstract partial class SharedHandsSystem : EntitySystem if (!CanPickupToHand(uid, entity, hand, checkActionBlocker, handsComp, item)) return false; + // Sunrise-start + if (!CheckRepickupDuration(entity)) + return false; + // Sunrise-end + if (animate) { var xform = Transform(uid); @@ -124,6 +133,29 @@ public abstract partial class SharedHandsSystem : EntitySystem return true; } + // Sunrise-start + /// + /// Проверка для . Остановка досрочного поднятия + /// Всю логику нельзя запихнуть в , потому что + /// вызывается на мобе, который пытается поднять, а не на цели. Создавать новый + /// ивент... Это пока не надо, мне кажется только больше конфликтов будет + /// + /// Для какой сущности проверять + /// Результат проверки + public bool CheckRepickupDuration(Entity entity) + { + // У сущности просто нет запрашиваемого компонента + if (!Resolve(entity.Owner, ref entity.Comp, logMissing: false)) + return true; + + if (entity.Comp.PrevDrop is not null && + _timing.CurTime - entity.Comp.PrevDrop < entity.Comp.CooldownDuration) + return false; + + return true; + } + // Sunrise-end + /// /// Tries to pick up an entity into any hand, forcing to drop an item if there are no free hands /// By default it does check if it's possible to drop items diff --git a/Content.Shared/_Sunrise/Carrying/CarryDroppedEvent.cs b/Content.Shared/_Sunrise/Carrying/CarryDroppedEvent.cs new file mode 100644 index 0000000000..975f25d262 --- /dev/null +++ b/Content.Shared/_Sunrise/Carrying/CarryDroppedEvent.cs @@ -0,0 +1,10 @@ +namespace Content.Shared._Sunrise.Carrying; + +/// +/// Вызывается на сущности, которую только отпустили (перестали carry) +/// +[ByRefEvent] +public readonly record struct CarryDroppedEvent +{ + +} diff --git a/Content.Shared/_Sunrise/Item/ItemRepickupCooldownComponent.cs b/Content.Shared/_Sunrise/Item/ItemRepickupCooldownComponent.cs new file mode 100644 index 0000000000..86ee1b2db8 --- /dev/null +++ b/Content.Shared/_Sunrise/Item/ItemRepickupCooldownComponent.cs @@ -0,0 +1,21 @@ +namespace Content.Shared._Sunrise.Item; + +/// +/// Этим компонентом следует помечать предметы, которые должно быть можно поднять вновь только после какой-то задержки +/// Компонент изначально делался для фелинидов: чтоб если поставить фелинида на пол, то у фелинида было N секунд убежать +/// от атакующего +/// +[RegisterComponent] +public sealed partial class ItemRepickupCooldownComponent : Component +{ + /// + /// Сколько времени ждать перед следующим поднятием + /// + [DataField("cooldown", required: true)] + public TimeSpan CooldownDuration; + + /// + /// Время предыдущего выкладывания. null если еще никогда не выкладывали сущность + /// + public TimeSpan? PrevDrop; +} diff --git a/Content.Shared/_Sunrise/Item/ItemRepickupCooldownSystem.cs b/Content.Shared/_Sunrise/Item/ItemRepickupCooldownSystem.cs new file mode 100644 index 0000000000..2a27203096 --- /dev/null +++ b/Content.Shared/_Sunrise/Item/ItemRepickupCooldownSystem.cs @@ -0,0 +1,25 @@ +using Content.Shared._Sunrise.Carrying; +using Content.Shared.Hands; +using Content.Shared.Interaction.Events; +using Content.Shared.Resist; +using Content.Shared.Throwing; +using Robust.Shared.Timing; + +namespace Content.Shared._Sunrise.Item; + +/// +/// Система для обработки логики обновления таймера у +/// +public sealed class ItemRepickupCooldownSystem : EntitySystem +{ + [Dependency] private readonly IGameTiming _timing = default!; + + /// + public override void Initialize() + { + SubscribeLocalEvent((uid, component, args) => component.PrevDrop = _timing.CurTime); + SubscribeLocalEvent((uid, component, args) => component.PrevDrop = _timing.CurTime); + SubscribeLocalEvent((uid, component, args) => component.PrevDrop = _timing.CurTime); + SubscribeLocalEvent((uid, component, args) => component.PrevDrop = _timing.CurTime); + } +} diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml b/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml index 00491b5c21..78735abee3 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml @@ -1755,6 +1755,8 @@ - type: Item size: Tiny heldPrefix: 0 + - type: ItemRepickupCooldown # Sunrise-add + cooldown: 5 # Sunrise-add - type: Clothing quickEquip: false sprite: Mobs/Animals/mouse.rsi @@ -3489,6 +3491,8 @@ state: hamster-0 - type: Item size: Tiny + - type: ItemRepickupCooldown # Sunrise-add + cooldown: 5 # Sunrise-add - type: Physics - type: FaxableObject insertingState: inserting_hamster diff --git a/Resources/Prototypes/_Sunrise/Entities/Mobs/Species/felinid.yml b/Resources/Prototypes/_Sunrise/Entities/Mobs/Species/felinid.yml index aa0f7a98e0..52367afb94 100644 --- a/Resources/Prototypes/_Sunrise/Entities/Mobs/Species/felinid.yml +++ b/Resources/Prototypes/_Sunrise/Entities/Mobs/Species/felinid.yml @@ -189,6 +189,8 @@ size: Huge shape: - 0,0,3,3 + - type: ItemRepickupCooldown + cooldown: 5 - type: Felinid damageBonus: types: