Content update for NetEntities (#18935)
This commit is contained in:
@@ -65,20 +65,20 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
|
||||
private void OnInstantGetState(EntityUid uid, InstantActionComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new InstantActionComponentState(component);
|
||||
args.State = new InstantActionComponentState(component, EntityManager);
|
||||
}
|
||||
|
||||
private void OnEntityTargetGetState(EntityUid uid, EntityTargetActionComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new EntityTargetActionComponentState(component);
|
||||
args.State = new EntityTargetActionComponentState(component, EntityManager);
|
||||
}
|
||||
|
||||
private void OnWorldTargetGetState(EntityUid uid, WorldTargetActionComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new WorldTargetActionComponentState(component);
|
||||
args.State = new WorldTargetActionComponentState(component, EntityManager);
|
||||
}
|
||||
|
||||
private void BaseHandleState(BaseActionComponent component, BaseActionComponentState state)
|
||||
private void BaseHandleState<T>(EntityUid uid, BaseActionComponent component, BaseActionComponentState state) where T : BaseActionComponent
|
||||
{
|
||||
component.Icon = state.Icon;
|
||||
component.IconOn = state.IconOn;
|
||||
@@ -89,12 +89,12 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
component.Cooldown = state.Cooldown;
|
||||
component.UseDelay = state.UseDelay;
|
||||
component.Charges = state.Charges;
|
||||
component.Provider = state.Provider;
|
||||
component.EntityIcon = state.EntityIcon;
|
||||
component.Provider = EnsureEntity<T>(state.Provider, uid);
|
||||
component.EntityIcon = EnsureEntity<T>(state.EntityIcon, uid);
|
||||
component.CheckCanInteract = state.CheckCanInteract;
|
||||
component.ClientExclusive = state.ClientExclusive;
|
||||
component.Priority = state.Priority;
|
||||
component.AttachedEntity = state.AttachedEntity;
|
||||
component.AttachedEntity = EnsureEntity<T>(state.AttachedEntity, uid);
|
||||
component.AutoPopulate = state.AutoPopulate;
|
||||
component.AutoRemove = state.AutoRemove;
|
||||
component.Temporary = state.Temporary;
|
||||
@@ -107,7 +107,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
if (args.Current is not InstantActionComponentState state)
|
||||
return;
|
||||
|
||||
BaseHandleState(component, state);
|
||||
BaseHandleState<InstantActionComponent>(uid, component, state);
|
||||
}
|
||||
|
||||
private void OnEntityTargetHandleState(EntityUid uid, EntityTargetActionComponent component, ref ComponentHandleState args)
|
||||
@@ -115,7 +115,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
if (args.Current is not EntityTargetActionComponentState state)
|
||||
return;
|
||||
|
||||
BaseHandleState(component, state);
|
||||
BaseHandleState<EntityTargetActionComponent>(uid, component, state);
|
||||
component.Whitelist = state.Whitelist;
|
||||
component.CanTargetSelf = state.CanTargetSelf;
|
||||
}
|
||||
@@ -125,7 +125,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
if (args.Current is not WorldTargetActionComponentState state)
|
||||
return;
|
||||
|
||||
BaseHandleState(component, state);
|
||||
BaseHandleState<WorldTargetActionComponent>(uid, component, state);
|
||||
}
|
||||
|
||||
private void OnGetActionData<T>(EntityUid uid, T component, ref GetActionDataEvent args) where T : BaseActionComponent
|
||||
@@ -177,7 +177,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
|
||||
protected bool TryGetContainer(
|
||||
EntityUid holderId,
|
||||
[NotNullWhen(true)] out IContainer? container,
|
||||
[NotNullWhen(true)] out BaseContainer? container,
|
||||
ContainerManagerComponent? containerManager = null)
|
||||
{
|
||||
return _containerSystem.TryGetContainer(holderId, ActionContainerId, out container, containerManager);
|
||||
@@ -185,7 +185,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
|
||||
protected bool TryGetProvidedContainer(
|
||||
EntityUid providerId,
|
||||
[NotNullWhen(true)] out IContainer? container,
|
||||
[NotNullWhen(true)] out BaseContainer? container,
|
||||
ContainerManagerComponent? containerManager = null)
|
||||
{
|
||||
return _containerSystem.TryGetContainer(providerId, ProvidedActionContainerId, out container, containerManager);
|
||||
@@ -215,7 +215,9 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
if (action.AttachedEntity == null)
|
||||
return;
|
||||
|
||||
if (!TryComp(action.AttachedEntity, out ActionsComponent? comp))
|
||||
var ent = action.AttachedEntity;
|
||||
|
||||
if (!TryComp(ent, out ActionsComponent? comp))
|
||||
{
|
||||
action.AttachedEntity = null;
|
||||
return;
|
||||
@@ -267,7 +269,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
|
||||
private void OnActionsGetState(EntityUid uid, ActionsComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new ActionsComponentState(component.Actions);
|
||||
args.State = new ActionsComponentState(GetNetEntitySet(component.Actions));
|
||||
}
|
||||
|
||||
private void OnActionsShutdown(EntityUid uid, ActionsComponent component, ComponentShutdown args)
|
||||
@@ -291,20 +293,22 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
if (!TryComp(user, out ActionsComponent? component))
|
||||
return;
|
||||
|
||||
if (!TryComp(ev.Action, out MetaDataComponent? metaData))
|
||||
var actionEnt = GetEntity(ev.Action);
|
||||
|
||||
if (!TryComp(actionEnt, out MetaDataComponent? metaData))
|
||||
return;
|
||||
|
||||
var name = Name(ev.Action, metaData);
|
||||
var name = Name(actionEnt, metaData);
|
||||
|
||||
// Does the user actually have the requested action?
|
||||
if (!component.Actions.Contains(ev.Action))
|
||||
if (!component.Actions.Contains(actionEnt))
|
||||
{
|
||||
_adminLogger.Add(LogType.Action,
|
||||
$"{ToPrettyString(user):user} attempted to perform an action that they do not have: {name}.");
|
||||
return;
|
||||
}
|
||||
|
||||
var action = GetActionData(ev.Action);
|
||||
var action = GetActionData(actionEnt);
|
||||
if (action == null || !action.Enabled)
|
||||
return;
|
||||
|
||||
@@ -318,12 +322,14 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
switch (action)
|
||||
{
|
||||
case EntityTargetActionComponent entityAction:
|
||||
if (ev.EntityTarget is not { Valid: true } entityTarget)
|
||||
if (ev.EntityTarget is not { Valid: true } netTarget)
|
||||
{
|
||||
Log.Error($"Attempted to perform an entity-targeted action without a target! Action: {name}");
|
||||
return;
|
||||
}
|
||||
|
||||
var entityTarget = GetEntity(netTarget);
|
||||
|
||||
var targetWorldPos = _transformSystem.GetWorldPosition(entityTarget);
|
||||
_rotateToFaceSystem.TryFaceCoordinates(user, targetWorldPos);
|
||||
|
||||
@@ -344,18 +350,19 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
if (entityAction.Event != null)
|
||||
{
|
||||
entityAction.Event.Target = entityTarget;
|
||||
Dirty(ev.Action, entityAction);
|
||||
Dirty(actionEnt, entityAction);
|
||||
performEvent = entityAction.Event;
|
||||
}
|
||||
|
||||
break;
|
||||
case WorldTargetActionComponent worldAction:
|
||||
if (ev.EntityCoordinatesTarget is not { } entityCoordinatesTarget)
|
||||
if (ev.EntityCoordinatesTarget is not { } netCoordinatesTarget)
|
||||
{
|
||||
Log.Error($"Attempted to perform a world-targeted action without a target! Action: {name}");
|
||||
return;
|
||||
}
|
||||
|
||||
var entityCoordinatesTarget = GetCoordinates(netCoordinatesTarget);
|
||||
_rotateToFaceSystem.TryFaceCoordinates(user, entityCoordinatesTarget.Position);
|
||||
|
||||
if (!ValidateWorldTarget(user, entityCoordinatesTarget, worldAction))
|
||||
@@ -375,7 +382,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
if (worldAction.Event != null)
|
||||
{
|
||||
worldAction.Event.Target = entityCoordinatesTarget;
|
||||
Dirty(ev.Action, worldAction);
|
||||
Dirty(actionEnt, worldAction);
|
||||
performEvent = worldAction.Event;
|
||||
}
|
||||
|
||||
@@ -403,7 +410,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
performEvent.Performer = user;
|
||||
|
||||
// All checks passed. Perform the action!
|
||||
PerformAction(user, component, ev.Action, action, performEvent, curTime);
|
||||
PerformAction(user, component, actionEnt, action, performEvent, curTime);
|
||||
}
|
||||
|
||||
public bool ValidateEntityTarget(EntityUid user, EntityUid target, EntityTargetActionComponent action)
|
||||
@@ -477,11 +484,12 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
{
|
||||
// This here is required because of client-side prediction (RaisePredictiveEvent results in event re-use).
|
||||
actionEvent.Handled = false;
|
||||
var provider = action.Provider;
|
||||
|
||||
if (action.Provider == null)
|
||||
if (provider == null)
|
||||
RaiseLocalEvent(performer, (object) actionEvent, broadcast: true);
|
||||
else
|
||||
RaiseLocalEvent(action.Provider.Value, (object) actionEvent, broadcast: true);
|
||||
RaiseLocalEvent(provider.Value, (object) actionEvent, broadcast: true);
|
||||
|
||||
handled = actionEvent.Handled;
|
||||
}
|
||||
@@ -550,7 +558,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
/// <param name="holder">Component of <see cref="holderId"/></param>
|
||||
/// <param name="action">Component of <see cref="actionId"/></param>
|
||||
/// <param name="actionContainer">Action container of <see cref="holderId"/></param>
|
||||
public virtual void AddAction(EntityUid holderId, EntityUid actionId, EntityUid? provider, ActionsComponent? holder = null, BaseActionComponent? action = null, bool dirty = true, IContainer? actionContainer = null)
|
||||
public virtual void AddAction(EntityUid holderId, EntityUid actionId, EntityUid? provider, ActionsComponent? holder = null, BaseActionComponent? action = null, bool dirty = true, BaseContainer? actionContainer = null)
|
||||
{
|
||||
action ??= GetActionData(actionId);
|
||||
// TODO remove when action subscriptions are split up
|
||||
@@ -572,7 +580,7 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
Dirty(holderId, holder);
|
||||
}
|
||||
|
||||
protected virtual void AddActionInternal(EntityUid holderId, EntityUid actionId, IContainer container, ActionsComponent holder)
|
||||
protected virtual void AddActionInternal(EntityUid holderId, EntityUid actionId, BaseContainer container, ActionsComponent holder)
|
||||
{
|
||||
container.Insert(actionId);
|
||||
holder.Actions.Add(actionId);
|
||||
|
||||
Reference in New Issue
Block a user