EntitySystemMessage Removal & InteractionSystem directed events (#3572)

* Removed obsolete EntitySystemMessage, now everything uses the base EntityEventArgs or the derived HandledEntityEventArgs.
Setup InteractionSystem to use new directed events.

* Update Submodule.
This commit is contained in:
Acruid
2021-03-09 11:22:48 -08:00
committed by GitHub
parent 549d84174c
commit 6edc416afc
47 changed files with 110 additions and 186 deletions

View File

@@ -2,7 +2,7 @@ using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Access
{
public sealed class AccessReaderChangeMessage : EntitySystemMessage
public sealed class AccessReaderChangeMessage : EntityEventArgs
{
public IEntity Sender { get; }

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using Content.Server.GameObjects.Components.GUI;
@@ -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!;
@@ -410,12 +410,7 @@ namespace Content.Server.GameObjects.Components.Buckle
return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide);
}
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
return TryUnbuckle(eventArgs.User);
}
public void Update()
{
if (!DontCollide || Physics == null)

View File

@@ -839,7 +839,7 @@ namespace Content.Server.GameObjects.Components.GUI
}
}
public class HandCountChangedEvent : EntitySystemMessage
public class HandCountChangedEvent : EntityEventArgs
{
public HandCountChangedEvent(IEntity sender)
{

View File

@@ -275,7 +275,7 @@ namespace Content.Server.GameObjects.Components.Interactable
}
}
internal sealed class ActivateHandheldLightMessage : EntitySystemMessage
internal sealed class ActivateHandheldLightMessage : EntityEventArgs
{
public HandheldLightComponent Component { get; }
@@ -285,7 +285,7 @@ namespace Content.Server.GameObjects.Components.Interactable
}
}
internal sealed class DeactivateHandheldLightMessage : EntitySystemMessage
internal sealed class DeactivateHandheldLightMessage : EntityEventArgs
{
public HandheldLightComponent Component { get; }

View File

@@ -180,7 +180,7 @@ namespace Content.Server.GameObjects.Components.Observer
message.AddMarkup(Loc.GetString("Died [color=yellow]{0}[/color].", deathTimeInfo));
}
public class GhostReturnMessage : EntitySystemMessage
public class GhostReturnMessage : EntityEventArgs
{
public GhostReturnMessage(Mind sender)
{

View File

@@ -167,7 +167,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
};
}
public sealed class EmergencyLightMessage : EntitySystemMessage
public sealed class EmergencyLightMessage : EntityEventArgs
{
public EmergencyLightComponent Component { get; }

View File

@@ -9,7 +9,7 @@ using Robust.Shared.Timing;
namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{
public class PathfindingChunkUpdateMessage : EntitySystemMessage
public class PathfindingChunkUpdateMessage : EntityEventArgs
{
public PathfindingChunk Chunk { get; }

View File

@@ -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.

View File

@@ -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;
@@ -22,11 +23,18 @@ namespace Content.Server.GameObjects.EntitySystems
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();
}
@@ -37,6 +45,7 @@ namespace Content.Server.GameObjects.EntitySystems
base.Shutdown();
UnsubscribeLocalEvent<MoveEvent>();
UnsubscribeLocalEvent<BuckleComponent, AttackHandMessage>(HandleAttackHand);
}
private void MoveEvent(MoveEvent ev)

View File

@@ -73,6 +73,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
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) &&
@@ -83,6 +84,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
// trigger dragdropons on the targeted entity
RaiseLocalEvent(target.Uid, interactionArgs, false);
foreach (var dragDropOn in target.GetAllComponents<IDragDropOn>())
{
if (dragDropOn.CanDragDropOn(interactionArgs) &&
@@ -408,7 +410,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
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;
@@ -425,11 +427,9 @@ namespace Content.Server.GameObjects.EntitySystems.Click
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
@@ -451,7 +451,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
var afterAtkMsg = new AfterInteractMessage(user, weapon, attacked, clickLocation, true);
RaiseLocalEvent(afterAtkMsg);
RaiseLocalEvent(weapon.Uid, afterAtkMsg, false);
if (afterAtkMsg.Handled)
{
return;
@@ -470,18 +470,16 @@ namespace Content.Server.GameObjects.EntitySystems.Click
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))
@@ -525,7 +523,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
var useMsg = new UseInHandMessage(user, used);
RaiseLocalEvent(useMsg);
RaiseLocalEvent(used.Uid, useMsg);
if (useMsg.Handled)
{
return;
@@ -563,7 +561,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
public void ThrownInteraction(IEntity user, IEntity thrown)
{
var throwMsg = new ThrownMessage(user, thrown);
RaiseLocalEvent(throwMsg);
RaiseLocalEvent(thrown.Uid, throwMsg);
if (throwMsg.Handled)
{
return;
@@ -586,7 +584,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
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;
@@ -608,7 +606,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
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;
@@ -630,7 +628,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
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;
@@ -651,7 +649,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
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;
@@ -684,7 +682,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
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;
@@ -706,7 +704,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
public void HandSelectedInteraction(IEntity user, IEntity item)
{
var handSelectedMsg = new HandSelectedMessage(user, item);
RaiseLocalEvent(handSelectedMsg);
RaiseLocalEvent(item.Uid, handSelectedMsg);
if (handSelectedMsg.Handled)
{
return;
@@ -728,7 +726,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
public void HandDeselectedInteraction(IEntity user, IEntity item)
{
var handDeselectedMsg = new HandDeselectedMessage(user, item);
RaiseLocalEvent(handDeselectedMsg);
RaiseLocalEvent(item.Uid, handDeselectedMsg);
if (handDeselectedMsg.Handled)
{
return;
@@ -750,7 +748,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
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;
@@ -771,7 +769,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
var afterAtkMsg = new AfterInteractMessage(user, weapon, attacked, clickLocation, false);
RaiseLocalEvent(afterAtkMsg);
RaiseLocalEvent(weapon.Uid, afterAtkMsg);
if (afterAtkMsg.Handled)
return;
@@ -820,6 +818,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
if (item != null)
{
RaiseLocalEvent(item.Uid, eventArgs, false);
foreach (var attackComponent in item.GetAllComponents<IAttack>())
{
if (wideAttack ? attackComponent.WideAttack(eventArgs) : attackComponent.ClickAttack(eventArgs))
@@ -840,6 +839,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
}
RaiseLocalEvent(player.Uid, eventArgs);
foreach (var attackComponent in player.GetAllComponents<IAttack>())
{
if (wideAttack)