Action container rejig (#20260)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2023-09-23 04:49:39 -04:00
committed by GitHub
parent c80c90ed65
commit 684b334806
50 changed files with 889 additions and 740 deletions

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Content.Server.Actions;
using Content.Server.Humanoid;
using Content.Server.Inventory;
@@ -29,6 +30,7 @@ namespace Content.Server.Polymorph.Systems
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly ActionsSystem _actions = default!;
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly SharedBuckleSystem _buckle = default!;
[Dependency] private readonly ContainerSystem _container = default!;
@@ -53,7 +55,7 @@ namespace Content.Server.Polymorph.Systems
SubscribeLocalEvent<PolymorphableComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<PolymorphableComponent, PolymorphActionEvent>(OnPolymorphActionEvent);
SubscribeLocalEvent<PolymorphedEntityComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<PolymorphedEntityComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullyEatenEvent>(OnBeforeFullyEaten);
SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullySlicedEvent>(OnBeforeFullySliced);
SubscribeLocalEvent<PolymorphedEntityComponent, RevertPolymorphActionEvent>(OnRevertPolymorphActionEvent);
@@ -85,7 +87,7 @@ namespace Content.Server.Polymorph.Systems
Revert(uid, component);
}
public void OnStartup(EntityUid uid, PolymorphedEntityComponent component, ComponentStartup args)
private void OnMapInit(EntityUid uid, PolymorphedEntityComponent component, MapInitEvent args)
{
if (!_proto.TryIndex(component.Prototype, out PolymorphPrototype? proto))
{
@@ -98,14 +100,11 @@ namespace Content.Server.Polymorph.Systems
if (proto.Forced)
return;
var actionId = Spawn(RevertPolymorphId);
if (_actions.TryGetActionData(actionId, out var action))
if (_actions.AddAction(uid, ref component.Action, out var action, RevertPolymorphId))
{
action.EntityIcon = component.Parent;
action.UseDelay = TimeSpan.FromSeconds(proto.Delay);
}
_actions.AddAction(uid, actionId, null, null, action);
}
private void OnBeforeFullyEaten(EntityUid uid, PolymorphedEntityComponent comp, BeforeFullyEatenEvent args)
@@ -332,20 +331,26 @@ namespace Content.Server.Polymorph.Systems
if (!TryComp<PolymorphableComponent>(target, out var polycomp))
return;
var entproto = _proto.Index<EntityPrototype>(polyproto.Entity);
var actionId = Spawn(RevertPolymorphId);
if (_actions.TryGetActionData(actionId, out var baseAction) &&
baseAction is InstantActionComponent action)
{
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 Dictionary<string, EntityUid>();
if (polycomp.PolymorphActions.ContainsKey(id))
return;
polycomp.PolymorphActions ??= new Dictionary<string, EntityUid>();
polycomp.PolymorphActions.Add(id, actionId);
_actions.AddAction(target, actionId, target);
}
var entproto = _proto.Index<EntityPrototype>(polyproto.Entity);
EntityUid? actionId = default!;
if (!_actions.AddAction(target, ref actionId, RevertPolymorphId, target))
return;
polycomp.PolymorphActions.Add(id, actionId.Value);
_metaData.SetEntityName(actionId.Value, Loc.GetString("polymorph-self-action-name", ("target", entproto.Name)));
_metaData.SetEntityDescription(actionId.Value, Loc.GetString("polymorph-self-action-description", ("target", entproto.Name)));
if (!_actions.TryGetActionData(actionId, out var baseAction))
return;
baseAction.Icon = new SpriteSpecifier.EntityPrototype(polyproto.Entity);
if (baseAction is InstantActionComponent action)
action.Event = new PolymorphActionEvent { Prototype = polyproto };
}
[PublicAPI]