Content update for NetEntities (#18935)

This commit is contained in:
metalgearsloth
2023-09-11 09:42:41 +10:00
committed by GitHub
parent 389c8d1a2c
commit 5a0fc68be2
526 changed files with 3058 additions and 2215 deletions

View File

@@ -44,9 +44,12 @@ public sealed partial class DoAfter
/// <summary>
/// Position of the user relative to their parent when the do after was started.
/// </summary>
[NonSerialized]
[DataField("userPosition")]
public EntityCoordinates UserPosition;
public NetCoordinates NetUserPosition;
/// <summary>
/// Distance from the user to the target when the do after was started.
/// </summary>
@@ -62,9 +65,12 @@ public sealed partial class DoAfter
/// <summary>
/// If <see cref="NeedHand"/> is true, this is the entity that was in the active hand when the doafter started.
/// </summary>
[NonSerialized]
[DataField("activeItem")]
public EntityUid? InitialItem;
public NetEntity? NetInitialItem;
// cached attempt event for the sake of avoiding unnecessary reflection every time this needs to be raised.
[NonSerialized] public object? AttemptEvent;
@@ -86,7 +92,7 @@ public sealed partial class DoAfter
StartTime = startTime;
}
public DoAfter(DoAfter other)
public DoAfter(IEntityManager entManager, DoAfter other)
{
Index = other.Index;
Args = new(other.Args);
@@ -97,6 +103,9 @@ public sealed partial class DoAfter
TargetDistance = other.TargetDistance;
InitialHand = other.InitialHand;
InitialItem = other.InitialItem;
NetUserPosition = other.NetUserPosition;
NetInitialItem = other.NetInitialItem;
}
}

View File

@@ -10,9 +10,12 @@ public sealed partial class DoAfterArgs
/// <summary>
/// The entity invoking do_after
/// </summary>
[NonSerialized]
[DataField("user", required: true)]
public EntityUid User;
public NetEntity NetUser;
/// <summary>
/// How long does the do_after require to complete
/// </summary>
@@ -22,15 +25,21 @@ public sealed partial class DoAfterArgs
/// <summary>
/// Applicable target (if relevant)
/// </summary>
[NonSerialized]
[DataField("target")]
public EntityUid? Target;
public NetEntity? NetTarget;
/// <summary>
/// Entity used by the User on the Target.
/// </summary>
[NonSerialized]
[DataField("using")]
public EntityUid? Used;
public NetEntity? NetUsed;
#region Event options
/// <summary>
/// The event that will get raised when the DoAfter has finished. If null, this will simply raise a <see cref="SimpleDoAfterEvent"/>
@@ -48,9 +57,12 @@ public sealed partial class DoAfterArgs
/// <summary>
/// Entity which will receive the directed event. If null, no directed event will be raised.
/// </summary>
[NonSerialized]
[DataField("eventTarget")]
public EntityUid? EventTarget;
public NetEntity? NetEventTarget;
/// <summary>
/// Should the DoAfter event broadcast? If this is false, then <see cref="EventTarget"/> should be a valid entity.
/// </summary>
@@ -173,6 +185,7 @@ public sealed partial class DoAfterArgs
/// <param name="target">The entity being targeted by the DoAFter. Not the same as <see cref="EventTarget"/></param>.
/// <param name="used">The entity being used during the DoAfter. E.g., a tool</param>
public DoAfterArgs(
IEntityManager entManager,
EntityUid user,
TimeSpan delay,
DoAfterEvent @event,
@@ -186,6 +199,10 @@ public sealed partial class DoAfterArgs
Used = used;
EventTarget = eventTarget;
Event = @event;
NetUser = entManager.GetNetEntity(User);
NetTarget = entManager.GetNetEntity(Target);
NetUsed = entManager.GetNetEntity(Used);
}
private DoAfterArgs()
@@ -202,13 +219,14 @@ public sealed partial class DoAfterArgs
/// <param name="target">The entity being targeted by the DoAfter. Not the same as <see cref="EventTarget"/></param>.
/// <param name="used">The entity being used during the DoAfter. E.g., a tool</param>
public DoAfterArgs(
IEntityManager entManager,
EntityUid user,
float seconds,
DoAfterEvent @event,
EntityUid? eventTarget,
EntityUid? target = null,
EntityUid? used = null)
: this(user, TimeSpan.FromSeconds(seconds), @event, eventTarget, target, used)
: this(entManager, user, TimeSpan.FromSeconds(seconds), @event, eventTarget, target, used)
{
}
@@ -238,6 +256,12 @@ public sealed partial class DoAfterArgs
CancelDuplicate = other.CancelDuplicate;
DuplicateCondition = other.DuplicateCondition;
// Networked
NetUser = other.NetUser;
NetTarget = other.NetTarget;
NetUsed = other.NetUsed;
NetEventTarget = other.NetEventTarget;
Event = other.Event.Clone();
}
}

View File

@@ -24,7 +24,7 @@ public sealed class DoAfterComponentState : ComponentState
public readonly ushort NextId;
public readonly Dictionary<ushort, DoAfter> DoAfters;
public DoAfterComponentState(DoAfterComponent component)
public DoAfterComponentState(IEntityManager entManager, DoAfterComponent component)
{
NextId = component.NextId;
@@ -36,9 +36,10 @@ public sealed class DoAfterComponentState : ComponentState
DoAfters = component.DoAfters;
#else
DoAfters = new();
foreach (var (id, doafter) in component.DoAfters)
foreach (var (id, doAfter) in component.DoAfters)
{
DoAfters.Add(id, new DoAfter(doafter));
var newDoAfter = new DoAfter(entManager, doAfter);
DoAfters.Add(id, newDoAfter);
}
#endif
}

View File

@@ -71,7 +71,7 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
}
if (dirty)
Dirty(comp);
Dirty(uid, comp);
if (comp.DoAfters.Count == 0)
RemCompDeferred(uid, active);

View File

@@ -100,7 +100,7 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
private void OnDoAfterGetState(EntityUid uid, DoAfterComponent comp, ref ComponentGetState args)
{
args.State = new DoAfterComponentState(comp);
args.State = new DoAfterComponentState(EntityManager, comp);
}
private void OnDoAfterHandleState(EntityUid uid, DoAfterComponent comp, ref ComponentHandleState args)
@@ -115,7 +115,18 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
comp.DoAfters.Clear();
foreach (var (id, doAfter) in state.DoAfters)
{
comp.DoAfters.Add(id, new(doAfter));
var newDoAfter = new DoAfter(EntityManager, doAfter);
comp.DoAfters.Add(id, newDoAfter);
// Networking yay (if you have an easier way dear god please).
newDoAfter.UserPosition = EnsureCoordinates<DoAfterComponent>(newDoAfter.NetUserPosition, uid);
newDoAfter.InitialItem = EnsureEntity<DoAfterComponent>(newDoAfter.NetInitialItem, uid);
var doAfterArgs = newDoAfter.Args;
doAfterArgs.Target = EnsureEntity<DoAfterComponent>(doAfterArgs.NetTarget, uid);
doAfterArgs.Used = EnsureEntity<DoAfterComponent>(doAfterArgs.NetUsed, uid);
doAfterArgs.User = EnsureEntity<DoAfterComponent>(doAfterArgs.NetUser, uid);
doAfterArgs.EventTarget = EnsureEntity<DoAfterComponent>(doAfterArgs.NetEventTarget, uid);
}
comp.NextId = state.NextId;
@@ -195,6 +206,16 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
id = new DoAfterId(args.User, comp.NextId++);
var doAfter = new DoAfter(id.Value.Index, args, GameTiming.CurTime);
// Networking yay
doAfter.NetUserPosition = GetNetCoordinates(doAfter.UserPosition);
doAfter.NetInitialItem = GetNetEntity(doAfter.InitialItem);
// Networking yay
args.NetTarget = GetNetEntity(args.Target);
args.NetUsed = GetNetEntity(args.Used);
args.NetUser = GetNetEntity(args.User);
args.NetEventTarget = GetNetEntity(args.EventTarget);
if (args.BreakOnUserMove || args.BreakOnTargetMove)
doAfter.UserPosition = Transform(args.User).Coordinates;
@@ -322,7 +343,7 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
}
InternalCancel(doAfter, comp);
Dirty(comp);
Dirty(entity, comp);
}
private void InternalCancel(DoAfter doAfter, DoAfterComponent component)