Added IInteractable and Stations

This commit is contained in:
2026-04-26 09:36:55 +02:00
parent b872b52632
commit 48448a9cff
12 changed files with 291 additions and 36 deletions

View File

@@ -0,0 +1,83 @@
using GeoSus.Client;
using System;
using UnityEngine;
using System.Linq;
public class Station : IInteractable
{
public StationType Type { get; set; }
public Position Location { get; set; }
public PlayerRole? ReqRole { get; set; }
public float InteractionRange { get; set; }
protected GameObject interfaceInstance;
public GameObject Interface; // Prefab pro interakci (napø. UI pro úkol nebo sabotáže)
public virtual void Interact(PlayerRole role)
{
if (ReqRole.HasValue && role != ReqRole.Value)
{
Debug.Log("You do not have the required role to interact with this station.");
return;
}
else
{
interfaceInstance = UnityEngine.Object.Instantiate(Interface); // Zobrazí interakèní UI
}
}
public Station(Position location, float interactionRange)
{
Location = location;
InteractionRange = interactionRange;
}
}
public class TaskStation : Station
{
public string TaskID { get; set; } // Unikátní ID úkolu pro server
private GameClient _gameClient;
public TaskStation(Position pos, float interactionRange, GameClient gameClient, string taskID) : base(pos, interactionRange)
{
Type = StationType.Task;
ReqRole = PlayerRole.Crew;
_gameClient = gameClient;
}
public ITask Task { get; set; }
public override void Interact(PlayerRole role)
{
if(interfaceInstance != null)
{
ResumeTask();
return;
}
base.Interact(role);
Task = interfaceInstance.GetComponent<ITask>();
Task.TaskID = TaskID;
Task.Initialize(OnTaskCompleted);
}
private void ResumeTask()
{
interfaceInstance.SetActive(true); // Zobrazí interakèní UI
}
private void OnTaskCompleted(ITask task)
{
_gameClient.CompleteTask(task.TaskID);
task.ExitTask(OnTaskExit);
Debug.Log($"Task {task.TaskName} completed and sent to server.");
}
private void OnTaskExit(ITask task)
{
if (task.IsCompleted)
{
UnityEngine.Object.Destroy(interfaceInstance); // Znièí interakèní UI
Debug.Log($"Task {task.TaskName} completed and sent to server.");
}
else
{
interfaceInstance.SetActive(false); // Skryje interakèní UI
Debug.Log($"Task {task.TaskName} was not completed, but exited.");
}
}
}