Skip to content

Commit

Permalink
EntitySystemMessage Removal & InteractionSystem directed events (#3572)
Browse files Browse the repository at this point in the history
* Removed obsolete EntitySystemMessage, now everything uses the base EntityEventArgs or the derived HandledEntityEventArgs.
Setup InteractionSystem to use new directed events.

* Update Submodule.
  • Loading branch information
Acruid authored Mar 9, 2021
1 parent 549d841 commit 6edc416
Show file tree
Hide file tree
Showing 47 changed files with 110 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void OnUpdate()
}
}

public sealed class DoorStateMessage : EntitySystemMessage
public sealed class DoorStateMessage : EntityEventArgs
{
public ClientDoorComponent Component { get; }
public SharedDoorComponent.DoorState State { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void SnapGridOnPositionChanged()
}
}

internal sealed class SubFloorHideDirtyEvent : EntitySystemMessage
internal sealed class SubFloorHideDirtyEvent : EntityEventArgs
{
public IEntity Sender { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void CalculateNewSprite(IEntity entity)
/// <summary>
/// Event raised by a <see cref="IconSmoothComponent"/> when it needs to be recalculated.
/// </summary>
public sealed class IconSmoothDirtyEvent : EntitySystemMessage
public sealed class IconSmoothDirtyEvent : EntityEventArgs
{
public IconSmoothDirtyEvent(IEntity sender, (GridId grid, Vector2i pos)? lastPosition, SnapGridOffset offset, IconSmoothingMode mode)
{
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/GameObjects/EntitySystems/WindowSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void FrameUpdate(float frameTime)
/// <summary>
/// Event raised by a <see cref="WindowComponent"/> when it needs to be recalculated.
/// </summary>
public sealed class WindowSmoothDirtyEvent : EntitySystemMessage
public sealed class WindowSmoothDirtyEvent : EntityEventArgs
{
public IEntity Sender { get; }

Expand Down
2 changes: 1 addition & 1 deletion Content.Client/State/OutlineToggleMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Content.Client.State
{
public sealed class OutlineToggleMessage : EntitySystemMessage
public sealed class OutlineToggleMessage : EntityEventArgs
{
public bool Enabled { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private void HandleMessage(SetFooMessage message, EntitySessionEventArgs args)
}
}

private sealed class SetFooMessage : EntitySystemMessage
private sealed class SetFooMessage : EntityEventArgs
{
public SetFooMessage(EntityUid uid, bool newFoo)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Content.Server.GameObjects.Components.Access
{
public sealed class AccessReaderChangeMessage : EntitySystemMessage
public sealed class AccessReaderChangeMessage : EntityEventArgs
{
public IEntity Sender { get; }

Expand Down
11 changes: 3 additions & 8 deletions Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using Content.Server.GameObjects.Components.GUI;
Expand Down Expand Up @@ -33,7 +33,7 @@ namespace Content.Server.GameObjects.Components.Buckle
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(SharedBuckleComponent))]
public class BuckleComponent : SharedBuckleComponent, IInteractHand
public class BuckleComponent : SharedBuckleComponent
{
[Dependency] private readonly IGameTiming _gameTiming = default!;

Expand Down Expand Up @@ -410,12 +410,7 @@ public override ComponentState GetComponentState(ICommonSession player)

return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide);
}

bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
return TryUnbuckle(eventArgs.User);
}


public void Update()
{
if (!DontCollide || Physics == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ public SharedHand ToShared(int index, HandLocation location)
}
}

public class HandCountChangedEvent : EntitySystemMessage
public class HandCountChangedEvent : EntityEventArgs
{
public HandCountChangedEvent(IEntity sender)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public bool DoToggleAction(ToggleItemActionEventArgs args)
}
}

internal sealed class ActivateHandheldLightMessage : EntitySystemMessage
internal sealed class ActivateHandheldLightMessage : EntityEventArgs
{
public HandheldLightComponent Component { get; }

Expand All @@ -285,7 +285,7 @@ public ActivateHandheldLightMessage(HandheldLightComponent component)
}
}

internal sealed class DeactivateHandheldLightMessage : EntitySystemMessage
internal sealed class DeactivateHandheldLightMessage : EntityEventArgs
{
public HandheldLightComponent Component { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void Examine(FormattedMessage message, bool inDetailsRange)
message.AddMarkup(Loc.GetString("Died [color=yellow]{0}[/color].", deathTimeInfo));
}

public class GhostReturnMessage : EntitySystemMessage
public class GhostReturnMessage : EntityEventArgs
{
public GhostReturnMessage(Mind sender)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public enum EmergencyLightState
};
}

public sealed class EmergencyLightMessage : EntitySystemMessage
public sealed class EmergencyLightMessage : EntityEventArgs
{
public EmergencyLightComponent Component { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{
public class PathfindingChunkUpdateMessage : EntitySystemMessage
public class PathfindingChunkUpdateMessage : EntityEventArgs
{
public PathfindingChunk Chunk { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI
/// Indicates whether an AI should be updated by the AiSystem or not.
/// Useful to sleep AI when they die or otherwise should be inactive.
/// </summary>
internal sealed class SleepAiMessage : EntitySystemMessage
internal sealed class SleepAiMessage : EntityEventArgs
{
/// <summary>
/// Sleep or awake.
Expand Down
13 changes: 11 additions & 2 deletions Content.Server/GameObjects/EntitySystems/BuckleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#nullable enable
#nullable enable
using Content.Server.GameObjects.Components.Buckle;
using Content.Server.GameObjects.Components.Strap;
using Content.Server.GameObjects.EntitySystems.Click;
using Content.Shared.Interfaces.GameObjects.Components;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
Expand All @@ -22,11 +23,18 @@ public override void Initialize()
SubscribeLocalEvent<MoveEvent>(MoveEvent);
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(ContainerModified);
SubscribeLocalEvent<EntRemovedFromContainerMessage>(ContainerModified);

SubscribeLocalEvent<BuckleComponent, AttackHandMessage>(HandleAttackHand);
}

private void HandleAttackHand(EntityUid uid, BuckleComponent component, AttackHandMessage args)
{
args.Handled = component.TryUnbuckle(args.User);
}

public override void Update(float frameTime)
{
foreach (var comp in ComponentManager.EntityQuery<BuckleComponent>(false))
foreach (var comp in ComponentManager.EntityQuery<BuckleComponent>())
{
comp.Update();
}
Expand All @@ -37,6 +45,7 @@ public override void Shutdown()
base.Shutdown();

UnsubscribeLocalEvent<MoveEvent>();
UnsubscribeLocalEvent<BuckleComponent, AttackHandMessage>(HandleAttackHand);
}

private void MoveEvent(MoveEvent ev)
Expand Down
40 changes: 20 additions & 20 deletions Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private void HandleDragDropMessage(DragDropMessage msg, EntitySessionEventArgs a
if (!interactionArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;

// trigger dragdrops on the dropped entity
RaiseLocalEvent(dropped.Uid, interactionArgs);
foreach (var dragDrop in dropped.GetAllComponents<IDraggable>())
{
if (dragDrop.CanDrop(interactionArgs) &&
Expand All @@ -83,6 +84,7 @@ private void HandleDragDropMessage(DragDropMessage msg, EntitySessionEventArgs a
}

// trigger dragdropons on the targeted entity
RaiseLocalEvent(target.Uid, interactionArgs, false);
foreach (var dragDropOn in target.GetAllComponents<IDragDropOn>())
{
if (dragDropOn.CanDragDropOn(interactionArgs) &&
Expand Down Expand Up @@ -408,7 +410,7 @@ private void ClickFace(IEntity player, EntityCoordinates coordinates)
private async void InteractAfter(IEntity user, IEntity weapon, EntityCoordinates clickLocation, bool canReach)
{
var message = new AfterInteractMessage(user, weapon, null, clickLocation, canReach);
RaiseLocalEvent(message);
RaiseLocalEvent(weapon.Uid, message);
if (message.Handled)
{
return;
Expand All @@ -425,11 +427,9 @@ private async void InteractAfter(IEntity user, IEntity weapon, EntityCoordinates
public async Task Interaction(IEntity user, IEntity weapon, IEntity attacked, EntityCoordinates clickLocation)
{
var attackMsg = new InteractUsingMessage(user, weapon, attacked, clickLocation);
RaiseLocalEvent(attackMsg);
RaiseLocalEvent(attacked.Uid, attackMsg);
if (attackMsg.Handled)
{
return;
}

var attackBys = attacked.GetAllComponents<IInteractUsing>().OrderByDescending(x => x.Priority);
var attackByEventArgs = new InteractUsingEventArgs
Expand All @@ -451,7 +451,7 @@ public async Task Interaction(IEntity user, IEntity weapon, IEntity attacked, En
}

var afterAtkMsg = new AfterInteractMessage(user, weapon, attacked, clickLocation, true);
RaiseLocalEvent(afterAtkMsg);
RaiseLocalEvent(weapon.Uid, afterAtkMsg, false);
if (afterAtkMsg.Handled)
{
return;
Expand All @@ -470,18 +470,16 @@ public async Task Interaction(IEntity user, IEntity weapon, IEntity attacked, En
public void Interaction(IEntity user, IEntity attacked)
{
var message = new AttackHandMessage(user, attacked);
RaiseLocalEvent(message);
RaiseLocalEvent(attacked.Uid, message);
if (message.Handled)
{
return;
}

var attackHands = attacked.GetAllComponents<IInteractHand>().ToList();
var attackHandEventArgs = new InteractHandEventArgs { User = user, Target = attacked };

// all attackHands should only fire when in range / unobstructed
if (attackHandEventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
{
var attackHands = attacked.GetAllComponents<IInteractHand>().ToList();
foreach (var attackHand in attackHands)
{
if (attackHand.InteractHand(attackHandEventArgs))
Expand Down Expand Up @@ -525,7 +523,7 @@ public void UseInteraction(IEntity user, IEntity used)
}

var useMsg = new UseInHandMessage(user, used);
RaiseLocalEvent(useMsg);
RaiseLocalEvent(used.Uid, useMsg);
if (useMsg.Handled)
{
return;
Expand Down Expand Up @@ -563,7 +561,7 @@ public bool TryThrowInteraction(IEntity user, IEntity item)
public void ThrownInteraction(IEntity user, IEntity thrown)
{
var throwMsg = new ThrownMessage(user, thrown);
RaiseLocalEvent(throwMsg);
RaiseLocalEvent(thrown.Uid, throwMsg);
if (throwMsg.Handled)
{
return;
Expand All @@ -586,7 +584,7 @@ public void ThrownInteraction(IEntity user, IEntity thrown)
public void EquippedInteraction(IEntity user, IEntity equipped, EquipmentSlotDefines.Slots slot)
{
var equipMsg = new EquippedMessage(user, equipped, slot);
RaiseLocalEvent(equipMsg);
RaiseLocalEvent(equipped.Uid, equipMsg);
if (equipMsg.Handled)
{
return;
Expand All @@ -608,7 +606,7 @@ public void EquippedInteraction(IEntity user, IEntity equipped, EquipmentSlotDef
public void UnequippedInteraction(IEntity user, IEntity equipped, EquipmentSlotDefines.Slots slot)
{
var unequipMsg = new UnequippedMessage(user, equipped, slot);
RaiseLocalEvent(unequipMsg);
RaiseLocalEvent(equipped.Uid, unequipMsg);
if (unequipMsg.Handled)
{
return;
Expand All @@ -630,7 +628,7 @@ public void UnequippedInteraction(IEntity user, IEntity equipped, EquipmentSlotD
public void EquippedHandInteraction(IEntity user, IEntity item, SharedHand hand)
{
var equippedHandMessage = new EquippedHandMessage(user, item, hand);
RaiseLocalEvent(equippedHandMessage);
RaiseLocalEvent(item.Uid, equippedHandMessage);
if (equippedHandMessage.Handled)
{
return;
Expand All @@ -651,7 +649,7 @@ public void EquippedHandInteraction(IEntity user, IEntity item, SharedHand hand)
public void UnequippedHandInteraction(IEntity user, IEntity item, SharedHand hand)
{
var unequippedHandMessage = new UnequippedHandMessage(user, item, hand);
RaiseLocalEvent(unequippedHandMessage);
RaiseLocalEvent(item.Uid, unequippedHandMessage);
if (unequippedHandMessage.Handled)
{
return;
Expand Down Expand Up @@ -684,7 +682,7 @@ public bool TryDroppedInteraction(IEntity user, IEntity item, bool intentional)
public void DroppedInteraction(IEntity user, IEntity item, bool intentional)
{
var dropMsg = new DroppedMessage(user, item, intentional);
RaiseLocalEvent(dropMsg);
RaiseLocalEvent(item.Uid, dropMsg);
if (dropMsg.Handled)
{
return;
Expand All @@ -706,7 +704,7 @@ public void DroppedInteraction(IEntity user, IEntity item, bool intentional)
public void HandSelectedInteraction(IEntity user, IEntity item)
{
var handSelectedMsg = new HandSelectedMessage(user, item);
RaiseLocalEvent(handSelectedMsg);
RaiseLocalEvent(item.Uid, handSelectedMsg);
if (handSelectedMsg.Handled)
{
return;
Expand All @@ -728,7 +726,7 @@ public void HandSelectedInteraction(IEntity user, IEntity item)
public void HandDeselectedInteraction(IEntity user, IEntity item)
{
var handDeselectedMsg = new HandDeselectedMessage(user, item);
RaiseLocalEvent(handDeselectedMsg);
RaiseLocalEvent(item.Uid, handDeselectedMsg);
if (handDeselectedMsg.Handled)
{
return;
Expand All @@ -750,7 +748,7 @@ public void HandDeselectedInteraction(IEntity user, IEntity item)
public async void RangedInteraction(IEntity user, IEntity weapon, IEntity attacked, EntityCoordinates clickLocation)
{
var rangedMsg = new RangedInteractMessage(user, weapon, attacked, clickLocation);
RaiseLocalEvent(rangedMsg);
RaiseLocalEvent(attacked.Uid, rangedMsg);
if (rangedMsg.Handled)
return;

Expand All @@ -771,7 +769,7 @@ public async void RangedInteraction(IEntity user, IEntity weapon, IEntity attack
}

var afterAtkMsg = new AfterInteractMessage(user, weapon, attacked, clickLocation, false);
RaiseLocalEvent(afterAtkMsg);
RaiseLocalEvent(weapon.Uid, afterAtkMsg);
if (afterAtkMsg.Handled)
return;

Expand Down Expand Up @@ -820,6 +818,7 @@ private void DoAttack(IEntity player, EntityCoordinates coordinates, bool wideAt

if (item != null)
{
RaiseLocalEvent(item.Uid, eventArgs, false);
foreach (var attackComponent in item.GetAllComponents<IAttack>())
{
if (wideAttack ? attackComponent.WideAttack(eventArgs) : attackComponent.ClickAttack(eventArgs))
Expand All @@ -840,6 +839,7 @@ private void DoAttack(IEntity player, EntityCoordinates coordinates, bool wideAt
}
}

RaiseLocalEvent(player.Uid, eventArgs);
foreach (var attackComponent in player.GetAllComponents<IAttack>())
{
if (wideAttack)
Expand Down
Loading

0 comments on commit 6edc416

Please sign in to comment.