UpdateGotData

This commit is contained in:
rawer470 2024-08-20 17:58:02 +03:00
parent 784ae57519
commit 46b829826e
2 changed files with 28 additions and 21 deletions

View file

@ -22,9 +22,9 @@ using System.Linq;
using System.Web; using System.Web;
using ZoFo.GameCore.GUI; using ZoFo.GameCore.GUI;
using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables;
using ZoFo.GameCore.GameObjects.MapObjects.StopObjects; using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO;
using ZoFo.GameCore.Graphics; using ZoFo.GameCore.Graphics;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.CollisionManager;
@ -122,21 +122,21 @@ namespace ZoFo.GameCore
{ {
UpdateShaking(); UpdateShaking();
for (int i = 0; i < gameObjects.Count; i++) for (int i = 0; i < gameObjects.Count; i++)
{ {
gameObjects[i].UpdateAnimations(); gameObjects[i].UpdateAnimations();
} }
for (int i = 0; i < particles.Count; i++) for (int i = 0; i < particles.Count; i++)
{ {
particles[i].UpdateAnimations(); particles[i].UpdateAnimations();
} }
networkManager.SendData();//set to ticks networkManager.SendData();//set to ticks
if (myPlayer != null) if (myPlayer != null)
GraphicsComponent.CameraPosition = 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) (myPlayer.position + myPlayer.graphicsComponent.ObjectDrawRectangle.Size.ToVector2() / 2 - AppManager.Instance.CurentScreenResolution.ToVector2() / (2 * GraphicsComponent.scaling)
) * 0.1f ) * 0.1f
) ) ))
.ToPoint(); .ToPoint();
} }
public void SendData() public void SendData()
@ -151,14 +151,14 @@ namespace ZoFo.GameCore
} }
for (int i = 0; i < stopObjects.Count; i++) for (int i = 0; i < stopObjects.Count; i++)
{ {
stopObjects[i].Draw(spriteBatch); stopObjects[i].Draw(spriteBatch);
} }
for (int i = 0; i < gameObjects.Count; i++) for (int i = 0; i < gameObjects.Count; i++)
{ {
gameObjects[i].Draw(spriteBatch); gameObjects[i].Draw(spriteBatch);
} }
for (int i = 0; i < particles.Count; i++) for (int i = 0; i < particles.Count; i++)
{ {
particles[i].Draw(spriteBatch); particles[i].Draw(spriteBatch);
} }
@ -201,10 +201,8 @@ namespace ZoFo.GameCore
if ((update as UpdateGameObjectCreated).GameObjectType == "Player") if ((update as UpdateGameObjectCreated).GameObjectType == "Player")
{ {
created_gameObject = new Player((update as UpdateGameObjectCreated).position.GetVector2()); created_gameObject = new Player((update as UpdateGameObjectCreated).position.GetVector2());
players.Add(created_gameObject as Player);
myPlayer = players[0];
gameObjects.Add(created_gameObject); gameObjects.Add(created_gameObject);
} }
else else
{ {
Type t = Type.GetType("ZoFo.GameCore.GameObjects." + (update as UpdateGameObjectCreated).GameObjectType); Type t = Type.GetType("ZoFo.GameCore.GameObjects." + (update as UpdateGameObjectCreated).GameObjectType);
@ -212,7 +210,7 @@ namespace ZoFo.GameCore
if (gameObject is Entity) if (gameObject is Entity)
(gameObject as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity); (gameObject as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity);
gameObjects.Add(gameObject); gameObjects.Add(gameObject);
} }
(gameObjects.Last() as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity); (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; GameObject gameObject = Activator.CreateInstance(t, (update as UpdateGameObjectWithoutIdCreated).position.GetVector2()) as GameObject;
if (gameObject is Particle) if (gameObject is Particle)
particles.Add(gameObject as Particle); particles.Add(gameObject as Particle);
} }
else if (update is UpdatePosition) else if (update is UpdatePosition)
{ {
var ent = FindEntityById(update.IdEntity); var ent = FindEntityById(update.IdEntity);
@ -245,11 +243,11 @@ namespace ZoFo.GameCore
DeleteObject(ent); DeleteObject(ent);
} }
else if (update is UpdatePlayerParametrs) else if (update is UpdatePlayerParametrs && update.IdEntity == myPlayer.Id) //aaa
{ {
UpdatePlayerHealth(update as UpdatePlayerParametrs); 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) if ((update as UpdateLoot).quantity == 0)
{ {
@ -259,7 +257,14 @@ namespace ZoFo.GameCore
if (ent != null) if (ent != null)
(ent as Player).lootData.AddLoot_Client((update as UpdateLoot).lootName, (update as UpdateLoot).quantity); (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) public void UpdatePlayerHealth(UpdatePlayerParametrs update)
{ {
@ -289,16 +294,16 @@ namespace ZoFo.GameCore
return; return;
} }
var ent = FindEntityById(update.IdEntity); var ent = FindEntityById(update.IdEntity);
if (ent != null) if (ent != null)
{ {
(ent as Player).health = (update as UpdatePlayerParametrs).health; (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)) if (particles.Contains(gameObject))
particles.Remove(gameObject as Particle); particles.Remove(gameObject as Particle);
} }
} }
public void DeleteEntity(Entity entity) public void DeleteEntity(Entity entity)
{ {

View file

@ -3,12 +3,14 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{ {
public class UpdateCreatePlayer : UpdateData public class UpdateCreatePlayer : UpdateData
{ {
public int PlayerId { get; set; } public int PlayerId { get; set; }
public SerializableVector2 position { get; set; }
public UpdateCreatePlayer() public UpdateCreatePlayer()
{ {
isImportant = true; isImportant = true;