Add Interatable class

This commit is contained in:
Mootfrost777 2024-08-16 23:12:12 +03:00
parent 2ec1b3b268
commit b0f9bbdeec
5 changed files with 42 additions and 2 deletions

View file

@ -17,7 +17,10 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
public List<CollisionComponent> CollisionComponent; public List<CollisionComponent> CollisionComponent;
public List<CollisionComponent> TriggerComponent; public List<CollisionComponent> TriggerComponent;
public void RegisterComponent()
{
}
public static bool CheckComponentCollision(List<CollisionComponent> collisionComponents, CollisionComponent component) public static bool CheckComponentCollision(List<CollisionComponent> collisionComponents, CollisionComponent component)
{ {

View file

@ -0,0 +1,7 @@
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
public class UpdateInteraction : IUpdateData // при попытке взаимодействия с объектом
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
}

View file

@ -0,0 +1,9 @@
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
public class UpdateInteractionAvailable(int idEntity, bool isReady)
: IUpdateData // при изменении возможности повзаимодействовать с объектом
{
public int IdEntity { get; set; } = idEntity;
public string UpdateType { get; set; }
public bool IsReady { get; set; } = isReady;
}

View file

@ -2,7 +2,7 @@
using System; using System;
namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables;
public class Collectable : Entity public class Collectable : Interactable
{ {
public Collectable(Vector2 position) : base(position) public Collectable(Vector2 position) : base(position)
{ {

View file

@ -0,0 +1,21 @@
using Microsoft.Xna.Framework;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.CollisionManager;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
namespace ZoFo.GameCore.GameObjects.Entities.Interactables;
public class Interactable : Entity
{
public Interactable(Vector2 position) : base(position)
{
collisionComponent.OnTriggerEnter += (sender, e) => ChangeInteraction(sender, e, true);
collisionComponent.OnTriggerExit += (sender, e) => ChangeInteraction(sender, e, false);
}
private void ChangeInteraction(object sender, CollisionComponent e, bool isReady)
{
AppManager.Instance.server.AddData(new UpdateInteractionAvailable((sender as Player).Id, isReady));
}
}