Merge pull request #27 from progtime-net/ServerBranch

Server branch
This commit is contained in:
SergoDobro 2024-08-16 15:42:00 +03:00 committed by GitHub
commit 37b8623b6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 56 additions and 9 deletions

View file

@ -7,6 +7,8 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using ZoFo.GameCore.GameObjects;
using ZoFo.GameCore.GameObjects.MapObjects;
namespace ZoFo.GameCore
{
@ -22,21 +24,32 @@ namespace ZoFo.GameCore
}
public void OnDataSend(string data)
{
{
List<IUpdateData> updateDatas = JsonSerializer.Deserialize<List<IUpdateData>>(data);
// тут будет switch
foreach (var item in updateDatas)
{
/* switch (item.UpdateType) Здесь нужно отлавливать и регистрировать
{
case "Tile":
MapObject map = new MapObject();
break;
}*/
}
}
public void GameEndedUnexpectedly(){ }
public void GameEndedUnexpectedly() { }
public void JoinRoom(string ip)
{
networkManager.JoinRoom(ip);
}
public void JoinYourself(){ networkManager.JoinYourself(); }
public void JoinYourself() { networkManager.JoinYourself(); }
internal void Update(GameTime gameTime)
{
}
internal void Draw(SpriteBatch spriteBatch)
{
{
}
}
}

View file

@ -65,12 +65,14 @@ public class SelectModeMenu : AbstractGUI
{
AppManager.Instance.SetGUI(new SelectingServerGUI());
// multi
Server server = new Server(); //Server Logic SinglePlayer
Server server = new Server(); //Server Logic MultiPlayer
Client client = new Client();
server.CreateRoom(1);
client.JoinYourself();
server.CreateRoom(5);
client.JoinRoom("127.0.0.1"); //указать айпишник
AppManager.Instance.SetServer(server);
AppManager.Instance.SetClient(client);
string key = client.IsConnected.ToString();
AppManager.Instance.debugHud.Set(key, "MultiPlayer");
// ваш код здесь
};
Elements.Add(optionButton);

View file

@ -17,8 +17,10 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates
[JsonDerivedType(typeof(UpdateLoot))]
[JsonDerivedType(typeof(UpdatePlayerParametrs))]
[JsonDerivedType(typeof(UpdatePosition))]
[JsonDerivedType(typeof(UpdateTileCreated))]
[JsonDerivedType(typeof(UpdateInput))]
[JsonDerivedType(typeof(UpdatePlayerExit))]
public interface IUpdateData
{
public int IdEntity { get; set; } //Id объекта

View file

@ -0,0 +1,21 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{
public class UpdateTileCreated : IUpdateData
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
public Texture2D TextureTile { get; set; }
public Vector2 Position { get; set; }
}
}

View file

@ -16,6 +16,7 @@ namespace ZoFo.GameCore
public class Server
{
private ServerNetworkManager networkManager;
private int ticks = 0;
public Server()
{
networkManager = new ServerNetworkManager();
@ -61,12 +62,20 @@ namespace ZoFo.GameCore
private List<Entity> entities; //entity
public void Update(GameTime gameTime)
{
foreach (var go in gameObjects)
if (ticks == 3) //ОБРАБАТЫВАЕТСЯ 20 РАЗ В СЕКУНДУ
{
go.UpdateLogic(gameTime);
foreach (var go in gameObjects)
{
go.UpdateLogic(gameTime);
}
ticks = 0;
networkManager.SendData();
}
ticks++;
}
/// <summary>
/// Регистрирует игровой объект
/// </summary>