From a2df1b746ac7b73de8be5e3e59221bbf4dfeaf33 Mon Sep 17 00:00:00 2001 From: rawer470 Date: Fri, 16 Aug 2024 22:11:10 +0300 Subject: [PATCH] ChangeHierarchyUpdateClasses --- ZoFo/GameCore/Client.cs | 2 +- .../GameManagers/NetworkManager/ClientNetworkManager.cs | 4 ++-- .../GameManagers/NetworkManager/ServerNetworkManager.cs | 6 +++--- .../NetworkManager/Updates/ClientToServer/UpdateInput.cs | 9 ++++++--- .../Updates/ClientToServer/UpdatePlayerExit.cs | 5 ++--- .../Updates/ServerToClient/UpdateAnimation.cs | 5 ++--- .../Updates/ServerToClient/UpdateEntityHealth.cs | 5 ++--- .../Updates/ServerToClient/UpdateGameEnded.cs | 5 ++--- .../Updates/ServerToClient/UpdateGameObjectCreated.cs | 5 ++--- .../NetworkManager/Updates/ServerToClient/UpdateLoot.cs | 5 ++--- .../Updates/ServerToClient/UpdatePlayerParametrs.cs | 5 ++--- .../Updates/ServerToClient/UpdatePosition.cs | 5 ++--- .../Updates/ServerToClient/UpdateTileCreated.cs | 7 +++---- .../Updates/{IUpdateData.cs => UpdateData.cs} | 6 +++--- ZoFo/GameCore/Server.cs | 4 ++-- 15 files changed, 36 insertions(+), 42 deletions(-) rename ZoFo/GameCore/GameManagers/NetworkManager/Updates/{IUpdateData.cs => UpdateData.cs} (88%) diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index bb33c14..c909e0e 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -25,7 +25,7 @@ namespace ZoFo.GameCore public void OnDataSend(string data) { - List updateDatas = JsonSerializer.Deserialize>(data); + List updateDatas = JsonSerializer.Deserialize>(data); // тут будет switch foreach (var item in updateDatas) { diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index eeb69b3..fc53cc3 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -18,7 +18,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager private int port = 7632; private EndPoint endPoint; private Socket socket; - List updates = new List(); + List updates = new List(); public delegate void OnDataSent(string Data); public event OnDataSent GetDataSent; // event public bool IsConnected { get { return socket.Connected; } } @@ -39,7 +39,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager socket.Send(bytes); } - public void AddData(IUpdateData UpdateData) + public void AddData(UpdateData UpdateData) { updates.Add(UpdateData); } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs index b4213e7..eb1673c 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs @@ -21,7 +21,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager private IPEndPoint endPoint; private Socket socket; private List clients; - private List updates; + private List updates; public delegate void OnDataSend(string data); public event OnDataSend GetDataSend; // event Dictionary managerThread; @@ -38,7 +38,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); managerThread = new Dictionary(); clients = new List(); - updates = new List(); + updates = new List(); managerThread = new Dictionary(); socket.Bind(endPoint); } @@ -60,7 +60,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager /// добавляет в лист updates новую data /// /// - public void AddData(IUpdateData data) + public void AddData(UpdateData data) { updates.Add(data); } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs index 81af1d9..bb2ea93 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs @@ -6,9 +6,12 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer { - public class UpdateInput :IUpdateData + public class UpdateInput :UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + // public int IdEntity { get; set; } + public UpdateInput() + { + UpdateType = "UpdateInput"; + } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdatePlayerExit.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdatePlayerExit.cs index ba6c6ca..7cb0b44 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdatePlayerExit.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdatePlayerExit.cs @@ -6,9 +6,8 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer { - public class UpdatePlayerExit : IUpdateData + public class UpdatePlayerExit : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdatePlayerExit() { UpdateType = "UpdatePlayerExit"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateAnimation.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateAnimation.cs index 6f07770..92fdc73 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateAnimation.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateAnimation.cs @@ -6,9 +6,8 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdateAnimation : IUpdateData //хранит новую анимации + public class UpdateAnimation : UpdateData //хранит новую анимации { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateAnimation() { UpdateType = "UpdateAnimation"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateEntityHealth.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateEntityHealth.cs index 618770e..7e1efd3 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateEntityHealth.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateEntityHealth.cs @@ -6,9 +6,8 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdateEntityHealth : IUpdateData//хранит новое хп entity + public class UpdateEntityHealth : UpdateData//хранит новое хп entity { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateEntityHealth() { UpdateType = "UpdateEntityHealth"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameEnded.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameEnded.cs index 10173b7..193f6c1 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameEnded.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameEnded.cs @@ -6,9 +6,8 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdateGameEnded : IUpdateData //хранит полученый лут и уведомляет о конце игры + public class UpdateGameEnded : UpdateData //хранит полученый лут и уведомляет о конце игры { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateGameEnded() { UpdateType = "UpdateGameEnded"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs index 4cf8a42..d3a154f 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs @@ -6,9 +6,8 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdateGameObjectCreated : IUpdateData //Хранит объект, который только отправили + public class UpdateGameObjectCreated : UpdateData //Хранит объект, который только отправили { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateGameObjectCreated() { UpdateType = "UpdateGameObjectCreated"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateLoot.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateLoot.cs index e7f8a51..19d390c 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateLoot.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateLoot.cs @@ -6,9 +6,8 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdateLoot : IUpdateData //Хранит лут + public class UpdateLoot : UpdateData //Хранит лут { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateLoot() { UpdateType = "UpdateLoot"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs index 36a2544..818dcce 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs @@ -6,9 +6,8 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdatePlayerParametrs : IUpdateData //Хранит хп, радиацию + public class UpdatePlayerParametrs : UpdateData //Хранит хп, радиацию { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdatePlayerParametrs() { UpdateType = "UpdatePlayerParametrs"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs index fda8a39..ae58334 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs @@ -6,9 +6,8 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdatePosition : IUpdateData //Хранит новую позицию + public class UpdatePosition : UpdateData //Хранит новую позицию { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdatePosition() { UpdateType = "UpdatePosition"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs index 796683d..c0f8702 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs @@ -10,11 +10,10 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - - public class UpdateTileCreated : IUpdateData + + public class UpdateTileCreated : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateTileCreated() { UpdateType = "UpdateTileCreated"; } public Texture2D TextureTile { get; set; } public Vector2 Position { get; set; } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/UpdateData.cs similarity index 88% rename from ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs rename to ZoFo/GameCore/GameManagers/NetworkManager/Updates/UpdateData.cs index 5c363d7..bb462ad 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/UpdateData.cs @@ -20,10 +20,10 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates [JsonDerivedType(typeof(UpdateTileCreated))] [JsonDerivedType(typeof(UpdateInput))] [JsonDerivedType(typeof(UpdatePlayerExit))] - - public interface IUpdateData + + public class UpdateData { public int IdEntity { get; set; } //Id объекта - public string UpdateType { get; set; } //тип обновления + public string UpdateType { get; protected set; } //тип обновления } } diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 5fcb39c..66910c8 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -24,7 +24,7 @@ namespace ZoFo.GameCore } public void OnDataSend(string data) { - List updateDatas = JsonSerializer.Deserialize>(data); + List updateDatas = JsonSerializer.Deserialize>(data); //ТУТ Switch case будет честное слово } @@ -32,7 +32,7 @@ namespace ZoFo.GameCore /// Для красоты) Отдел Серверов /// /// - public void AddData(IUpdateData data)//добавляет в лист updates новую data + public void AddData(UpdateData data)//добавляет в лист updates новую data { networkManager.AddData(data); }