Refactor actions to be entities with components (#19900)
This commit is contained in:
@@ -5,7 +5,6 @@ using Content.Server.Mind.Commands;
|
||||
using Content.Server.Nutrition;
|
||||
using Content.Server.Polymorph.Components;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Buckle;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
@@ -46,6 +45,8 @@ namespace Content.Server.Polymorph.Systems
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
private const string RevertPolymorphId = "ActionRevertPolymorph";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -97,23 +98,21 @@ namespace Content.Server.Polymorph.Systems
|
||||
if (proto.Forced)
|
||||
return;
|
||||
|
||||
var act = new InstantAction
|
||||
var actionId = Spawn(RevertPolymorphId);
|
||||
if (_actions.TryGetActionData(actionId, out var action))
|
||||
{
|
||||
Event = new RevertPolymorphActionEvent(),
|
||||
EntityIcon = component.Parent,
|
||||
DisplayName = Loc.GetString("polymorph-revert-action-name"),
|
||||
Description = Loc.GetString("polymorph-revert-action-description"),
|
||||
UseDelay = TimeSpan.FromSeconds(proto.Delay),
|
||||
};
|
||||
action.EntityIcon = component.Parent;
|
||||
action.UseDelay = TimeSpan.FromSeconds(proto.Delay);
|
||||
}
|
||||
|
||||
_actions.AddAction(uid, act, null);
|
||||
_actions.AddAction(uid, actionId, null, null, action);
|
||||
}
|
||||
|
||||
private void OnBeforeFullyEaten(EntityUid uid, PolymorphedEntityComponent comp, BeforeFullyEatenEvent args)
|
||||
{
|
||||
if (!_proto.TryIndex<PolymorphPrototype>(comp.Prototype, out var proto))
|
||||
{
|
||||
_sawmill.Error("Invalid polymorph prototype {comp.Prototype}");
|
||||
_sawmill.Error($"Invalid polymorph prototype {comp.Prototype}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -334,23 +333,19 @@ namespace Content.Server.Polymorph.Systems
|
||||
return;
|
||||
|
||||
var entproto = _proto.Index<EntityPrototype>(polyproto.Entity);
|
||||
|
||||
var act = new InstantAction
|
||||
var actionId = Spawn(RevertPolymorphId);
|
||||
if (_actions.TryGetActionData(actionId, out var baseAction) &&
|
||||
baseAction is InstantActionComponent action)
|
||||
{
|
||||
Event = new PolymorphActionEvent
|
||||
{
|
||||
Prototype = polyproto,
|
||||
},
|
||||
DisplayName = Loc.GetString("polymorph-self-action-name", ("target", entproto.Name)),
|
||||
Description = Loc.GetString("polymorph-self-action-description", ("target", entproto.Name)),
|
||||
Icon = new SpriteSpecifier.EntityPrototype(polyproto.Entity),
|
||||
ItemIconStyle = ItemActionIconStyle.NoItem,
|
||||
};
|
||||
action.Event = new PolymorphActionEvent { Prototype = polyproto };
|
||||
action.Icon = new SpriteSpecifier.EntityPrototype(polyproto.Entity);
|
||||
_metaData.SetEntityName(actionId, Loc.GetString("polymorph-self-action-name", ("target", entproto.Name)));
|
||||
_metaData.SetEntityDescription(actionId, Loc.GetString("polymorph-self-action-description", ("target", entproto.Name)));
|
||||
|
||||
polycomp.PolymorphActions ??= new();
|
||||
|
||||
polycomp.PolymorphActions.Add(id, act);
|
||||
_actions.AddAction(target, act, target);
|
||||
polycomp.PolymorphActions ??= new Dictionary<string, EntityUid>();
|
||||
polycomp.PolymorphActions.Add(id, actionId);
|
||||
_actions.AddAction(target, actionId, target);
|
||||
}
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
@@ -399,18 +394,4 @@ namespace Content.Server.Polymorph.Systems
|
||||
UpdateCollide();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed partial class PolymorphActionEvent : InstantActionEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// The polymorph prototype containing all the information about
|
||||
/// the specific polymorph.
|
||||
/// </summary>
|
||||
public PolymorphPrototype Prototype = default!;
|
||||
}
|
||||
|
||||
public sealed partial class RevertPolymorphActionEvent : InstantActionEvent
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user