if (action.ClientExclusive)
{
if (instantAction.Event != null)
+ {
instantAction.Event.Performer = user;
+ instantAction.Event.Action = actionId;
+ }
PerformAction(user, actions, actionId, instantAction, instantAction.Event, GameTiming.CurTime);
}
{
action.Event.Target = coords;
action.Event.Performer = user;
+ action.Event.Action = actionId;
}
_actionsSystem.PerformAction(user, actionComp, actionId, action, action.Event, _timing.CurTime);
{
action.Event.Target = entity;
action.Event.Performer = user;
+ action.Event.Action = actionId;
}
_actionsSystem.PerformAction(user, actionComp, actionId, action, action.Event, _timing.CurTime);
_controller ??= UserInterfaceManager.GetUIController<ActionUIController>();
_spriteSys ??= _entities.System<SpriteSystem>();
- if ((_controller.SelectingTargetFor == ActionId || _action.Toggled) && _action.IconOn != null)
- SetActionIcon(_spriteSys.Frame0(_action.IconOn));
+ if ((_controller.SelectingTargetFor == ActionId || _action.Toggled))
+ {
+ if (_action.IconOn != null)
+ SetActionIcon(_spriteSys.Frame0(_action.IconOn));
+
+ if (_action.BackgroundOn != null)
+ _buttonBackgroundTexture = _spriteSys.Frame0(_action.BackgroundOn);
+ }
else
+ {
SetActionIcon(_action.Icon != null ? _spriteSys.Frame0(_action.Icon) : null);
+ _buttonBackgroundTexture = Theme.ResolveTexture("SlotBackground");
+ }
}
public void UpdateBackground()
var (actId, act) = _random.Pick(options);
if (act.Event != null)
+ {
act.Event.Performer = args.User;
+ act.Event.Action = actId;
+ }
_actions.PerformAction(args.User, null, actId, act, act.Event, _timing.CurTime, false);
args.Handled = true;
if (entAct.Event != null)
{
entAct.Event.Performer = args.User;
+ entAct.Event.Action = entActId;
entAct.Event.Target = args.Target.Value;
}
if (act.Event != null)
{
act.Event.Performer = args.User;
+ act.Event.Action = actId;
act.Event.Target = args.ClickLocation;
}
/// The user performing the action.
/// </summary>
public EntityUid Performer;
+
+ /// <summary>
+ /// The action that was performed.
+ /// </summary>
+ public EntityUid Action;
}
-using Content.Shared.Mobs;
-using Robust.Shared.Audio;
+using Robust.Shared.Audio;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
/// </summary>
[DataField("iconOn")] public SpriteSpecifier? IconOn;
+ /// <summary>
+ /// For toggle actions only, background to show when toggled on.
+ /// </summary>
+ [DataField] public SpriteSpecifier? BackgroundOn;
+
/// <summary>
/// If not null, this color will modulate the action icon color.
/// </summary>
--- /dev/null
+namespace Content.Shared.Actions.Events;
+
+/// <summary>
+/// Raised on the action entity when it is used and <see cref="BaseActionEvent.Handled"/>.
+/// </summary>
+/// <param name="Performer">The entity that performed this action.</param>
+[ByRefEvent]
+public readonly record struct ActionPerformedEvent(EntityUid Performer);
public void SetCooldown(EntityUid? actionId, TimeSpan start, TimeSpan end)
{
- if (actionId == null)
- return;
-
if (!TryGetActionData(actionId, out var action))
return;
public void ClearCooldown(EntityUid? actionId)
{
- if (actionId == null)
- return;
-
if (!TryGetActionData(actionId, out var action))
return;
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)
}
if (performEvent != null)
+ {
performEvent.Performer = user;
+ performEvent.Action = actionEnt;
+ }
// All checks passed. Perform the action!
PerformAction(user, component, actionEnt, action, performEvent, curTime);
if (dirty && component != null)
Dirty(performer, component);
+
+ var ev = new ActionPerformedEvent(performer);
+ RaiseLocalEvent(actionId, ref ev);
}
#endregion