Add ActionPerformedEvent, ActionsSystem.SetIfBiggerCooldown, action id to action events and BackgroundOn field (#27682)
* Add ActionPerformedEvent and ActionsSystem.SetIfBiggerCooldown * Add action id to action events and backgroundon field to action component
This commit is contained in:
@@ -144,9 +144,6 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
|
||||
public void SetCooldown(EntityUid? actionId, TimeSpan start, TimeSpan end)
|
||||
{
|
||||
if (actionId == null)
|
||||
return;
|
||||
|
||||
if (!TryGetActionData(actionId, out var action))
|
||||
return;
|
||||
|
||||
@@ -162,9 +159,6 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
|
||||
public void ClearCooldown(EntityUid? actionId)
|
||||
{
|
||||
if (actionId == null)
|
||||
return;
|
||||
|
||||
if (!TryGetActionData(actionId, out var action))
|
||||
return;
|
||||
|
||||
@@ -175,6 +169,27 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the cooldown for this action only if it is bigger than the one it already has.
|
||||
/// </summary>
|
||||
public void SetIfBiggerCooldown(EntityUid? actionId, TimeSpan? cooldown)
|
||||
{
|
||||
if (cooldown == null ||
|
||||
cooldown.Value <= TimeSpan.Zero ||
|
||||
!TryGetActionData(actionId, out var action))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var start = GameTiming.CurTime;
|
||||
var end = start + cooldown;
|
||||
if (action.Cooldown?.End > end)
|
||||
return;
|
||||
|
||||
action.Cooldown = (start, end.Value);
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public void StartUseDelay(EntityUid? actionId)
|
||||
{
|
||||
if (actionId == null)
|
||||
@@ -438,7 +453,10 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
}
|
||||
|
||||
if (performEvent != null)
|
||||
{
|
||||
performEvent.Performer = user;
|
||||
performEvent.Action = actionEnt;
|
||||
}
|
||||
|
||||
// All checks passed. Perform the action!
|
||||
PerformAction(user, component, actionEnt, action, performEvent, curTime);
|
||||
@@ -580,6 +598,9 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
|
||||
if (dirty && component != null)
|
||||
Dirty(performer, component);
|
||||
|
||||
var ev = new ActionPerformedEvent(performer);
|
||||
RaiseLocalEvent(actionId, ref ev);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user