From 78fa747973e76368c7036720f7775b2fd7232b58 Mon Sep 17 00:00:00 2001 From: clusterfack Date: Tue, 1 May 2018 02:52:37 -0500 Subject: [PATCH] Adds click parsing entity system (#64) * Adds click parsing entity system Instead of every entity system receiving the message and deciding if it individually wants the message, and verifying player information. The click parser system receives the message and parses which system to send it to based on clicktype and sends it. * Submodule update --- Content.Server/Content.Server.csproj | 6 +- .../EntitySystems/Click/ClickParser.cs | 70 +++++++++++++++++++ .../{ => Click}/InteractionSystem.cs | 39 +---------- engine | 2 +- 4 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 Content.Server/GameObjects/EntitySystems/Click/ClickParser.cs rename Content.Server/GameObjects/EntitySystems/{ => Click}/InteractionSystem.cs (91%) diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index b8333212f9..1b6a6f545d 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -91,7 +91,8 @@ - + + @@ -137,4 +138,5 @@ - + + \ No newline at end of file diff --git a/Content.Server/GameObjects/EntitySystems/Click/ClickParser.cs b/Content.Server/GameObjects/EntitySystems/Click/ClickParser.cs new file mode 100644 index 0000000000..055af9eaa2 --- /dev/null +++ b/Content.Server/GameObjects/EntitySystems/Click/ClickParser.cs @@ -0,0 +1,70 @@ +using System; +using SS14.Server.Interfaces.Player; +using SS14.Shared.GameObjects; +using SS14.Shared.GameObjects.System; +using SS14.Shared.Input; +using SS14.Shared.Interfaces.GameObjects; +using SS14.Shared.Interfaces.Network; +using SS14.Shared.IoC; + +namespace Content.Server.GameObjects.EntitySystems +{ + /// + /// Catches clicks from the client and parses them to relevant entity systems + /// + public class ClickParserSystem : EntitySystem + { + /// + public override void RegisterMessageTypes() + { + base.RegisterMessageTypes(); + + RegisterMessageType(); + } + + /// + /// Grab click events sent from the client input system + /// + /// + /// + public override void HandleNetMessage(INetChannel channel, EntitySystemMessage message) + { + base.HandleNetMessage(channel, message); + + var playerMan = IoCManager.Resolve(); + var session = playerMan.GetSessionByChannel(channel); + var playerentity = session.AttachedEntity; + + if (playerentity == null) + return; + + switch (message) + { + case ClickEventMessage msg: + ParseClickMessage(msg, playerentity); + break; + } + } + + /// + /// Parse click to the relevant entity system + /// + /// + /// + private void ParseClickMessage(ClickEventMessage message, IEntity player) + { + switch (message.Click) + { + case ClickType.Left: + EntitySystemManager.GetEntitySystem().UserInteraction(message, player); + break; + case (ClickType.Left | ClickType.Shift): + //Examine system + break; + case ClickType.Right: + //Verb System + break; + } + } + } +} diff --git a/Content.Server/GameObjects/EntitySystems/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs similarity index 91% rename from Content.Server/GameObjects/EntitySystems/InteractionSystem.cs rename to Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs index 625bf8d307..7a0fa8b417 100644 --- a/Content.Server/GameObjects/EntitySystems/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs @@ -6,9 +6,6 @@ using SS14.Shared.Interfaces.GameObjects; using System.Collections.Generic; using System.Linq; using SS14.Shared.Input; -using SS14.Shared.Interfaces.Network; -using SS14.Shared.IoC; -using SS14.Server.Interfaces.Player; using SS14.Shared.Log; using SS14.Shared.Map; using SS14.Server.GameObjects; @@ -92,40 +89,8 @@ namespace Content.Server.GameObjects.EntitySystems private const float INTERACTION_RANGE = 2; private const float INTERACTION_RANGE_SQUARED = INTERACTION_RANGE * INTERACTION_RANGE; - /// - public override void RegisterMessageTypes() + public void UserInteraction(ClickEventMessage msg, IEntity player) { - base.RegisterMessageTypes(); - - RegisterMessageType(); - } - - //Grab click events sent from the client input system - public override void HandleNetMessage(INetChannel channel, EntitySystemMessage message) - { - base.HandleNetMessage(channel, message); - - var playerMan = IoCManager.Resolve(); - var session = playerMan.GetSessionByChannel(channel); - var playerentity = session.AttachedEntity; - - if (playerentity == null) - return; - - switch (message) - { - case ClickEventMessage msg: - UserInteraction(msg, playerentity); - break; - } - } - - private void UserInteraction(ClickEventMessage msg, IEntity player) - { - //Verify click type - if (msg.Click != ClickType.Left) - return; - //Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null IEntity attacked = null; if (msg.Uid.IsValid()) @@ -227,7 +192,7 @@ namespace Content.Server.GameObjects.EntitySystems /// /// /// - private void InteractAfterattack(IEntity user, IEntity weapon, LocalCoordinates clicklocation) + public static void InteractAfterattack(IEntity user, IEntity weapon, LocalCoordinates clicklocation) { List afterattacks = weapon.GetComponents().ToList(); diff --git a/engine b/engine index 3a78a26652..9aed85b4c7 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit 3a78a26652de2aa5dde5b59f56ba1a78d23e2cd4 +Subproject commit 9aed85b4c7f91a1c72adf91a7f4928fe4b91e367