Actions Rework (#6791)
* Rejig Actions * fix merge errors * lambda-b-gon * fix PAI, add innate actions * Revert "fix PAI, add innate actions" This reverts commit 4b501ac083e979e31ebd98d7b98077e0dbdd344b. * Just fix by making nullable. if only require: true actually did something somehow. * Make AddActions() ensure an actions component and misc comments * misc cleanup * Limit range even when not checking for obstructions * remove old guardian code * rename function and make EntityUid nullable * fix magboot bug * fix action search menu * make targeting toggle all equivalent actions * fix combat popups (enabling <-> disabling)
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
using Content.Shared.Actions.Components;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Robust.Shared.GameObjects;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Actions
|
||||
{
|
||||
/// <summary>
|
||||
/// Evicts action states with expired cooldowns.
|
||||
/// </summary>
|
||||
public sealed class SharedActionSystem : EntitySystem
|
||||
{
|
||||
private const float CooldownCheckIntervalSeconds = 10;
|
||||
private float _timeSinceCooldownCheck;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
UpdatesOutsidePrediction = true;
|
||||
SubscribeLocalEvent<ItemActionsComponent, GotEquippedEvent>(OnGotEquipped);
|
||||
SubscribeLocalEvent<ItemActionsComponent, EquippedHandEvent>(OnHandEquipped);
|
||||
SubscribeLocalEvent<ItemActionsComponent, UnequippedHandEvent>((uid, comp, _) => OnUnequipped(uid, comp));
|
||||
SubscribeLocalEvent<ItemActionsComponent, GotUnequippedEvent>((uid, comp, _) => OnUnequipped(uid, comp));
|
||||
}
|
||||
|
||||
private void OnGotEquipped(EntityUid uid, ItemActionsComponent component, GotEquippedEvent args)
|
||||
{
|
||||
if (!TryComp(args.Equipee, out SharedActionsComponent? actionsComponent))
|
||||
return;
|
||||
|
||||
component.Holder = args.Equipee;
|
||||
component.HolderActionsComponent = actionsComponent;
|
||||
component.IsEquipped = true;
|
||||
component.GrantOrUpdateAllToHolder();
|
||||
}
|
||||
|
||||
private void OnHandEquipped(EntityUid uid, ItemActionsComponent component, EquippedHandEvent args)
|
||||
{
|
||||
if (!TryComp(args.User, out SharedActionsComponent? actionsComponent))
|
||||
return;
|
||||
|
||||
component.Holder = args.User;
|
||||
component.HolderActionsComponent = actionsComponent;
|
||||
component.IsEquipped = true;
|
||||
component.InHand = args.Hand;
|
||||
component.GrantOrUpdateAllToHolder();
|
||||
}
|
||||
|
||||
private void OnUnequipped(EntityUid uid, ItemActionsComponent component)
|
||||
{
|
||||
component.RevokeAllFromHolder();
|
||||
component.Holder = null;
|
||||
component.HolderActionsComponent = null;
|
||||
component.IsEquipped = false;
|
||||
component.InHand = null;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
_timeSinceCooldownCheck += frameTime;
|
||||
if (_timeSinceCooldownCheck < CooldownCheckIntervalSeconds) return;
|
||||
|
||||
foreach (var comp in EntityManager.EntityQuery<SharedActionsComponent>(false))
|
||||
{
|
||||
comp.ExpireCooldowns();
|
||||
}
|
||||
_timeSinceCooldownCheck -= CooldownCheckIntervalSeconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user