Content changes for session specific entity states (#11235)

This commit is contained in:
Leon Friedrich
2022-09-14 21:40:05 +12:00
committed by GitHub
parent 7cd0677708
commit 2908cd994c
12 changed files with 10 additions and 118 deletions

View File

@@ -12,6 +12,8 @@ public sealed class ActionsComponent : Component
[ViewVariables]
[Access(typeof(SharedActionsSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
public SortedSet<ActionType> Actions = new();
public override bool SendOnlyToOwner => true;
}
[Serializable, NetSerializable]

View File

@@ -37,7 +37,6 @@ public abstract class SharedActionsSystem : EntitySystem
SubscribeLocalEvent<ActionsComponent, DidUnequipHandEvent>(OnHandUnequipped);
SubscribeLocalEvent<ActionsComponent, ComponentGetState>(GetState);
SubscribeLocalEvent<ActionsComponent, ComponentGetStateAttemptEvent>(OnCanGetState);
SubscribeAllEvent<RequestPerformActionEvent>(OnActionRequest);
}
@@ -89,12 +88,6 @@ public abstract class SharedActionsSystem : EntitySystem
args.State = new ActionsComponentState(component.Actions.ToList());
}
private void OnCanGetState(EntityUid uid, ActionsComponent component, ref ComponentGetStateAttemptEvent args)
{
// Only send action state data to the relevant player.
if (args.Player.AttachedEntity != uid)
args.Cancelled = true;
}
#endregion
#region Execution

View File

@@ -11,4 +11,6 @@ namespace Content.Shared.Alert;
public sealed class AlertsComponent : Component
{
[ViewVariables] public Dictionary<AlertKey, AlertState> Alerts = new();
public override bool SendOnlyToOwner => true;
}

View File

@@ -158,38 +158,21 @@ public abstract class AlertsSystem : EntitySystem
SubscribeLocalEvent<AlertsComponent, ComponentStartup>(HandleComponentStartup);
SubscribeLocalEvent<AlertsComponent, ComponentShutdown>(HandleComponentShutdown);
SubscribeLocalEvent<AlertsComponent, MetaFlagRemoveAttemptEvent>(OnMetaFlagRemoval);
SubscribeLocalEvent<AlertsComponent, ComponentGetState>(ClientAlertsGetState);
SubscribeLocalEvent<AlertsComponent, ComponentGetStateAttemptEvent>(OnCanGetState);
SubscribeNetworkEvent<ClickAlertEvent>(HandleClickAlert);
LoadPrototypes();
_prototypeManager.PrototypesReloaded += HandlePrototypesReloaded;
}
private void OnMetaFlagRemoval(EntityUid uid, AlertsComponent component, ref MetaFlagRemoveAttemptEvent args)
{
if (component.LifeStage == ComponentLifeStage.Running)
args.ToRemove &= ~MetaDataFlags.EntitySpecific;
}
private void OnCanGetState(EntityUid uid, AlertsComponent component, ref ComponentGetStateAttemptEvent args)
{
// Only send alert state data to the relevant player.
if (args.Player.AttachedEntity != uid)
args.Cancelled = true;
}
protected virtual void HandleComponentShutdown(EntityUid uid, AlertsComponent component, ComponentShutdown args)
{
RaiseLocalEvent(uid, new AlertSyncEvent(uid), true);
_metaSystem.RemoveFlag(uid, MetaDataFlags.EntitySpecific);
}
private void HandleComponentStartup(EntityUid uid, AlertsComponent component, ComponentStartup args)
{
RaiseLocalEvent(uid, new AlertSyncEvent(uid), true);
_metaSystem.AddFlag(uid, MetaDataFlags.EntitySpecific);
}
public override void Shutdown()

View File

@@ -9,14 +9,6 @@ namespace Content.Shared.Flash
base.Initialize();
SubscribeLocalEvent<SharedFlashableComponent, ComponentGetState>(OnFlashableGetState);
SubscribeLocalEvent<SharedFlashableComponent, ComponentGetStateAttemptEvent>(OnGetStateAttempt);
}
private static void OnGetStateAttempt(EntityUid uid, SharedFlashableComponent component, ref ComponentGetStateAttemptEvent args)
{
// Only send state to the player attached to the entity.
if (args.Player.AttachedEntity != uid)
args.Cancelled = true;
}
private static void OnFlashableGetState(EntityUid uid, SharedFlashableComponent component, ref ComponentGetState args)

View File

@@ -8,6 +8,8 @@ namespace Content.Shared.Flash
{
public float Duration { get; set; }
public TimeSpan LastFlash { get; set; }
public override bool SendOnlyToOwner => true;
}
[Serializable, NetSerializable]

View File

@@ -29,5 +29,7 @@ namespace Content.Shared.Shuttles.Components
[ViewVariables]
public ShuttleButtons HeldButtons = ShuttleButtons.None;
public override bool SendOnlyToOwner => true;
}
}

View File

@@ -13,5 +13,7 @@ namespace Content.Shared.Vehicle.Components
/// The vehicle this rider is currently riding.
/// </summary>
[ViewVariables] public EntityUid? Vehicle;
public override bool SendOnlyToOwner => true;
}
}