diff --git a/DangerousD/GameCore/Network/NetworkTask.cs b/DangerousD/GameCore/Network/NetworkTask.cs new file mode 100644 index 0000000..a1fb999 --- /dev/null +++ b/DangerousD/GameCore/Network/NetworkTask.cs @@ -0,0 +1,106 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.Network +{ + [Serializable] + public class NetworkTask + { + public NetworkTaskOperationEnum operation { get; set; } + public string name { get; set; } + public int value { get; set; } + public int objId { get; set; } + public Vector2 position { get; set; } + public Vector2 velocity { get; set; } + public Type type { get; set; } + + /// + /// Нанести урон сущности + /// + /// + /// + public NetworkTask(int LivingEntityId, int Damage) + { + operation = NetworkTaskOperationEnum.TakeDamage; + objId = LivingEntityId; + value = Damage; + } + + /// + /// Проиграть звук на позиции + /// + /// + /// + public NetworkTask(Vector2 SoundPosition, string SoundName) + { + operation = NetworkTaskOperationEnum.SendSound; + position = SoundPosition; + name = SoundName; + } + + /// + /// Создать сущность на позиции с заданной скоростью и присвоить её родительской сущности + /// + /// + /// + /// + /// + public NetworkTask(Type EntityType, Vector2 EntityPosition, Vector2 EntityVelocity, int ParentId) + { + operation = NetworkTaskOperationEnum.CreateEntity; + type = EntityType; + position = EntityPosition; + velocity = EntityVelocity; + objId = ParentId; + } + + /// + /// Изменить позицию сущности со сложной логикой(игрок) + /// + /// + /// + public NetworkTask(int EntityId, Vector2 EntityPosition) + { + operation = NetworkTaskOperationEnum.SendPosition; + objId = EntityId; + position = EntityPosition; + } + /// + /// Изменяет состояние и/или скорость сущности + /// + /// + /// + /// + public NetworkTask(int EntityId, string StateName, Vector2 EntityVelocity) + { + operation = NetworkTaskOperationEnum.ChangeState; + objId = EntityId; + name = StateName; + velocity = EntityVelocity; + } + + /// + /// Подключается к хосту и передаёт своё имя + /// + /// + public NetworkTask(string PlayerName) + { + operation = NetworkTaskOperationEnum.ConnectToHost; + name = PlayerName; + } + + /// + /// Получает id игрока на клиенте от хоста + /// + /// + public NetworkTask(int PlayerId) + { + operation = NetworkTaskOperationEnum.GetClientPlayerId; + objId = PlayerId; + } + } +} diff --git a/DangerousD/GameCore/Network/NetworkTaskOperationEnum.cs b/DangerousD/GameCore/Network/NetworkTaskOperationEnum.cs new file mode 100644 index 0000000..86cb112 --- /dev/null +++ b/DangerousD/GameCore/Network/NetworkTaskOperationEnum.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.Network +{ + [Serializable] + public enum NetworkTaskOperationEnum + { + TakeDamage, SendSound, CreateEntity, SendPosition, ChangeState, ConnectToHost, GetClientPlayerId + } +}