84 lines
2.5 KiB
C#
84 lines
2.5 KiB
C#
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 { get; set; } // 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.");
|
|
}
|
|
|
|
}
|
|
|
|
}
|