Files
DepthsOfGreed/Assets/Scripts/HandbookUI/ISupplyGameplay.cs
T

77 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
namespace DepthsOfGreed.HandbookUI
{
public enum SupplyKind { None = -1, Physical = 0, EnergyCells = 1, Special = 2 }
public enum SupplyTruckPhase { Idle, Loading, Driving, Unloading }
public enum SupplyStop { PhysicalTank = 0, EnergyTank = 1, SpecialTank = 2, Distributor = 3 }
public enum SupplyConsumption { PerShot, WhileFiring }
[Serializable]
public sealed class TowerSupplyDefinition
{
[Tooltip("None = kein Kelleranschluss.")]
public SupplyKind kind = SupplyKind.None;
[Min(0)] public float magazineCapacity = 60;
[Tooltip("Startfüllung pro neu gebauter Turminstanz, nicht der aktuelle Magazinstand.")]
[Min(0)] public float initialAmmo = 60;
[Tooltip("Maximale Nachfüllrate vom Verteiler ins Turmmagazin.")]
[Min(0)] public float refillPerSecond = 10;
public SupplyConsumption consumption = SupplyConsumption.PerShot;
[Tooltip("Bei PerShot: nur bei einem tatsächlich abgefeuerten Schuss verbuchen.")]
[Min(0)] public float unitsPerShot = 1;
[Tooltip("Bei WhileFiring: nur während tatsächlicher Feuerzeit verbuchen.")]
[Min(0)] public float unitsPerFiringSecond;
}
// A detached display snapshot. Gameplay retains ownership of all live state.
public sealed class SupplyState
{
public SupplyKind priority = SupplyKind.None;
public IReadOnlyList<SupplyChannelState> channels = Array.Empty<SupplyChannelState>();
public IReadOnlyList<TowerSupplyState> towers = Array.Empty<TowerSupplyState>();
public SupplyTruckState truck;
}
public sealed class SupplyChannelState
{
public SupplyKind kind;
public float storage, storageCapacity;
public float buffer, bufferCapacity;
// Optional, measured consumption; not theoretical fire rate.
public float? consumedPerSecond;
}
public sealed class TowerSupplyState
{
// Must be the same stable instance ID as BuiltObjectSnapshot.instanceId.
public long instanceId;
public HandbookTowerEntry type;
public bool connected = true;
public float magazine, magazineCapacity;
public float? consumedPerSecond;
}
public sealed class SupplyTruckState
{
public SupplyTruckPhase phase;
public SupplyKind cargoKind = SupplyKind.None;
public float cargo, cargoCapacity;
public SupplyStop from, to;
[Range(0,1)] public float progress;
}
public readonly struct SupplyCommandResult
{
public readonly bool accepted;
public readonly string message;
public SupplyCommandResult(bool accepted, string message = null) { this.accepted = accepted; this.message = message; }
}
// Implement on a MonoBehaviour. The UI polls at 4 Hz and never consumes ammunition.
public interface ISupplyGameplay
{
SupplyState ReadState();
SupplyCommandResult SetConnected(long instanceId, bool connected);
SupplyCommandResult SetPriority(SupplyKind priority);
}
}