From 46b829826eb7ad0eea73a762c97f5766764ff5f6 Mon Sep 17 00:00:00 2001 From: rawer470 Date: Tue, 20 Aug 2024 17:58:02 +0300 Subject: [PATCH] UpdateGotData --- ZoFo/GameCore/Client.cs | 47 ++++++++++--------- .../ServerToClient/UpdateCreatePlayer.cs | 2 + 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 5d054b3..72fdb2b 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -22,9 +22,9 @@ using System.Linq; using System.Web; using ZoFo.GameCore.GUI; using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; -using ZoFo.GameCore.GameObjects.MapObjects.StopObjects; -using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; -using ZoFo.GameCore.Graphics; +using ZoFo.GameCore.GameObjects.MapObjects.StopObjects; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; +using ZoFo.GameCore.Graphics; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using ZoFo.GameCore.GameManagers.CollisionManager; @@ -122,21 +122,21 @@ namespace ZoFo.GameCore { UpdateShaking(); for (int i = 0; i < gameObjects.Count; i++) - { + { gameObjects[i].UpdateAnimations(); } for (int i = 0; i < particles.Count; i++) - { + { particles[i].UpdateAnimations(); } networkManager.SendData();//set to ticks if (myPlayer != null) GraphicsComponent.CameraPosition = - ((GraphicsComponent.CameraPosition.ToVector2() *0.9f + + ((GraphicsComponent.CameraPosition.ToVector2() * 0.9f + (myPlayer.position + myPlayer.graphicsComponent.ObjectDrawRectangle.Size.ToVector2() / 2 - AppManager.Instance.CurentScreenResolution.ToVector2() / (2 * GraphicsComponent.scaling) ) * 0.1f - ) ) + )) .ToPoint(); } public void SendData() @@ -151,14 +151,14 @@ namespace ZoFo.GameCore } for (int i = 0; i < stopObjects.Count; i++) { - stopObjects[i].Draw(spriteBatch); + stopObjects[i].Draw(spriteBatch); } for (int i = 0; i < gameObjects.Count; i++) { gameObjects[i].Draw(spriteBatch); } for (int i = 0; i < particles.Count; i++) - { + { particles[i].Draw(spriteBatch); } @@ -201,10 +201,8 @@ namespace ZoFo.GameCore if ((update as UpdateGameObjectCreated).GameObjectType == "Player") { created_gameObject = new Player((update as UpdateGameObjectCreated).position.GetVector2()); - players.Add(created_gameObject as Player); - myPlayer = players[0]; gameObjects.Add(created_gameObject); - } + } else { Type t = Type.GetType("ZoFo.GameCore.GameObjects." + (update as UpdateGameObjectCreated).GameObjectType); @@ -212,7 +210,7 @@ namespace ZoFo.GameCore if (gameObject is Entity) (gameObject as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity); gameObjects.Add(gameObject); - } + } (gameObjects.Last() as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity); } @@ -222,7 +220,7 @@ namespace ZoFo.GameCore GameObject gameObject = Activator.CreateInstance(t, (update as UpdateGameObjectWithoutIdCreated).position.GetVector2()) as GameObject; if (gameObject is Particle) particles.Add(gameObject as Particle); - } + } else if (update is UpdatePosition) { var ent = FindEntityById(update.IdEntity); @@ -245,11 +243,11 @@ namespace ZoFo.GameCore DeleteObject(ent); } - else if (update is UpdatePlayerParametrs) + else if (update is UpdatePlayerParametrs && update.IdEntity == myPlayer.Id) //aaa { UpdatePlayerHealth(update as UpdatePlayerParametrs); } - else if (update is UpdateLoot) + else if (update is UpdateLoot && update.IdEntity == myPlayer.Id)//aaa { if ((update as UpdateLoot).quantity == 0) { @@ -259,7 +257,14 @@ namespace ZoFo.GameCore if (ent != null) (ent as Player).lootData.AddLoot_Client((update as UpdateLoot).lootName, (update as UpdateLoot).quantity); } - + else if (update is UpdateCreatePlayer) + { + Vector2 pos = (update as UpdateCreatePlayer).position.GetVector2(); + Player player = new Player(pos); + myPlayer = player; + players.Add(player); + } + } public void UpdatePlayerHealth(UpdatePlayerParametrs update) { @@ -289,16 +294,16 @@ namespace ZoFo.GameCore return; } - + var ent = FindEntityById(update.IdEntity); if (ent != null) { (ent as Player).health = (update as UpdatePlayerParametrs).health; - (ent as Player).rad = (update as UpdatePlayerParametrs).radiatoin; + (ent as Player).rad = (update as UpdatePlayerParametrs).radiatoin; } - + } @@ -328,7 +333,7 @@ namespace ZoFo.GameCore if (particles.Contains(gameObject)) particles.Remove(gameObject as Particle); } - } + } public void DeleteEntity(Entity entity) { diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateCreatePlayer.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateCreatePlayer.cs index c393dc9..db59d09 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateCreatePlayer.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateCreatePlayer.cs @@ -3,12 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { public class UpdateCreatePlayer : UpdateData { public int PlayerId { get; set; } + public SerializableVector2 position { get; set; } public UpdateCreatePlayer() { isImportant = true;