From c9d766242fd28f362a9e89e9e1c2fd44682ce05e Mon Sep 17 00:00:00 2001 From: Lev Date: Sat, 17 Aug 2024 19:42:55 +0300 Subject: [PATCH] add vectors in UpdateInput, add event ActionEvent and Subscribing to the actions of the input manager --- ZoFo/GameCore/Client.cs | 9 +++++++ ZoFo/GameCore/GameManagers/InputManager.cs | 26 +++++++++++++++---- .../Updates/ClientToServer/UpdateInput.cs | 15 +++++++---- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index f49020f..ee0355c 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -14,6 +14,8 @@ using ZoFo.GameCore.GameObjects.MapObjects.Tiles; using System.Drawing; using System.Reflection; using ZoFo.GameCore.GameObjects.Entities; +using ZoFo.GameCore.GameManagers; +using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; namespace ZoFo.GameCore { @@ -26,6 +28,13 @@ namespace ZoFo.GameCore { networkManager = new ClientNetworkManager(); networkManager.GetDataSent += OnDataSend; + + // Подписка на действия инпутменеджера. + // Отправляются данные апдейтса с обновлением инпута + AppManager.Instance.InputManager.ActionEvent += () => networkManager.AddData(new UpdateInput(){ + InputMovementDirection = AppManager.Instance.InputManager.InputMovementDirection, + InputAttackDirection = AppManager.Instance.InputManager.InputAttackDirection + }); } public void OnDataSend(string data) diff --git a/ZoFo/GameCore/GameManagers/InputManager.cs b/ZoFo/GameCore/GameManagers/InputManager.cs index 9bf702b..dd13535 100644 --- a/ZoFo/GameCore/GameManagers/InputManager.cs +++ b/ZoFo/GameCore/GameManagers/InputManager.cs @@ -17,17 +17,21 @@ namespace ZoFo.GameCore.GameManagers public class InputManager { - public delegate void Delegat(); - public event Delegat ShootEvent; // событие удара(когда нажат X, событие срабатывает) + public event Action ShootEvent; // событие удара(когда нажат X, событие срабатывает) - public event Delegat OnInteract; // событие взаимодействия с collectable(например, лутом) + public event Action OnInteract; // событие взаимодействия с collectable(например, лутом) //с помощью кнопки E. + + public event Action ActionEvent; public Vector2 InputMovementDirection; + private Vector2 prevInputMovementDirection; public Vector2 InputAttackDirection; + private Vector2 prevInputAttackDirection; - public event Delegat TalkEvent; + public event Action TalkEvent; - ScopeState currentScopeState; // Положение оружия. Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight. + public ScopeState currentScopeState; // Положение оружия. Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight. + private ScopeState prevCurrentScopeState; private bool _cheatsEnabled = false; public bool InvincibilityCheat { get; private set; } = false; public bool CollisionsCheat { get; private set; } = false; @@ -128,6 +132,7 @@ namespace ZoFo.GameCore.GameManagers lastGamePadState = gamePadState; #endregion #region Работа с KeyBoard + #region InputAttack with mouse MouseState mouseState = Mouse.GetState(); AppManager.Instance.debugHud.Set("mouse position", $"({mouseState.X}, {mouseState.Y}"); @@ -231,6 +236,17 @@ namespace ZoFo.GameCore.GameManagers lastKeyboardState = keyBoardState; #endregion + #region ActionEvent + if(InputMovementDirection != prevInputMovementDirection || + InputAttackDirection != prevInputAttackDirection || + currentScopeState != prevCurrentScopeState) + { + ActionEvent?.Invoke(); + } + prevInputMovementDirection = InputMovementDirection; + prevInputAttackDirection = InputAttackDirection; + prevCurrentScopeState = currentScopeState; + #endregion } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs index bb2ea93..350fd41 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Xna.Framework; +using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; @@ -8,10 +10,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer { public class UpdateInput :UpdateData { - // public int IdEntity { get; set; } - public UpdateInput() - { - UpdateType = "UpdateInput"; - } + // public int IdEntity { get; set; } + public Vector2 InputMovementDirection{get;set;} + public Vector2 InputAttackDirection {get;set;} + public UpdateInput() + { + UpdateType = "UpdateInput"; + } + } }