КД на повторное поднятие для фелинидов (#1936)

This commit is contained in:
pacable 2025-05-05 14:53:16 +03:00 committed by GitHub
parent 24bb124e21
commit c38aa07752
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 97 additions and 0 deletions

View file

@ -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)

View file

@ -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<HandsComponent, EntInsertedIntoContainerMessage>(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
/// <summary>
/// Проверка для <see cref="ItemRepickupCooldownComponent"/>. Остановка досрочного поднятия
/// Всю логику нельзя запихнуть в <see cref="ItemRepickupCooldownSystem"/>, потому что
/// <see cref="PickupAttemptEvent"/> вызывается на мобе, который пытается поднять, а не на цели. Создавать новый
/// ивент... Это пока не надо, мне кажется только больше конфликтов будет
/// </summary>
/// <param name="entity">Для какой сущности проверять</param>
/// <returns>Результат проверки</returns>
public bool CheckRepickupDuration(Entity<ItemRepickupCooldownComponent?> 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
/// <summary>
/// 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

View file

@ -0,0 +1,10 @@
namespace Content.Shared._Sunrise.Carrying;
/// <summary>
/// Вызывается на сущности, которую только отпустили (перестали carry)
/// </summary>
[ByRefEvent]
public readonly record struct CarryDroppedEvent
{
}

View file

@ -0,0 +1,21 @@
namespace Content.Shared._Sunrise.Item;
/// <summary>
/// Этим компонентом следует помечать предметы, которые должно быть можно поднять вновь только после какой-то задержки
/// Компонент изначально делался для фелинидов: чтоб если поставить фелинида на пол, то у фелинида было N секунд убежать
/// от атакующего
/// </summary>
[RegisterComponent]
public sealed partial class ItemRepickupCooldownComponent : Component
{
/// <summary>
/// Сколько времени ждать перед следующим поднятием
/// </summary>
[DataField("cooldown", required: true)]
public TimeSpan CooldownDuration;
/// <summary>
/// Время предыдущего выкладывания. null если еще никогда не выкладывали сущность
/// </summary>
public TimeSpan? PrevDrop;
}

View file

@ -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;
/// <summary>
/// Система для обработки логики обновления таймера у <see cref="ItemRepickupCooldownComponent"/>
/// </summary>
public sealed class ItemRepickupCooldownSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<ItemRepickupCooldownComponent, DroppedEvent>((uid, component, args) => component.PrevDrop = _timing.CurTime);
SubscribeLocalEvent<ItemRepickupCooldownComponent, ThrownEvent>((uid, component, args) => component.PrevDrop = _timing.CurTime);
SubscribeLocalEvent<ItemRepickupCooldownComponent, EscapeInventoryEvent>((uid, component, args) => component.PrevDrop = _timing.CurTime);
SubscribeLocalEvent<ItemRepickupCooldownComponent, CarryDroppedEvent>((uid, component, args) => component.PrevDrop = _timing.CurTime);
}
}

View file

@ -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

View file

@ -189,6 +189,8 @@
size: Huge
shape:
- 0,0,3,3
- type: ItemRepickupCooldown
cooldown: 5
- type: Felinid
damageBonus:
types: