using UnityEngine; using GeoSus.Client; using System; public class WindController : MonoBehaviour, ITask { [Header("settings větru")] [Tooltip("Maximální síla větru (kladná i záporná)")] public float maxWindTorque = 8f; [Tooltip("Jak rychle se větr mění směrem/sílou")] public float windChangeSpeed = 0.6f; [Tooltip("Jak často se objeví silnější vichřice (v sekundách)")] public float gustInterval = 4f; [Tooltip("Multiplier pro sílu vichřice")] public float gustMultiplier = 2.0f; public float CurrentWindTorque { get; private set; } private float targetTorque; private float gustTimer; private Action _onCompleted; private Action _onExit; public string TaskID { get; set; } public TaskType TaskType { get; set; } public string TaskName { get; set; } public (double, double) TaskLocation { get; set; } public bool IsCompleted { get; private set; } void Start() { PickNewTargetTorque(); gustTimer = gustInterval; } void Update() { CurrentWindTorque = Mathf.Lerp(CurrentWindTorque, targetTorque, Time.deltaTime * windChangeSpeed); gustTimer -= Time.deltaTime; if (gustTimer <= 0f) { float gust = UnityEngine.Random.Range(-maxWindTorque, maxWindTorque) * gustMultiplier; targetTorque = Mathf.Clamp(gust, -maxWindTorque * gustMultiplier, maxWindTorque * gustMultiplier); gustTimer = gustInterval; Invoke(nameof(PickNewTargetTorque), 0.8f); // Smoothly move wind toward target torque CurrentWindTorque = Mathf.Lerp(CurrentWindTorque, targetTorque, Time.deltaTime * windChangeSpeed); } } private void PickNewTargetTorque() { targetTorque = UnityEngine.Random.Range(-maxWindTorque, maxWindTorque); } public void Initialize(Action onCompleted) { _onCompleted = onCompleted; IsCompleted = false; } public void Complete() { if (IsCompleted) return; IsCompleted = true; _onCompleted?.Invoke(this); } public void ExitTask(Action onExit) { _onExit = onExit; _onExit?.Invoke(this); } }