using System; using System.Collections.Generic; namespace Minigames.FortFight.Data { /// /// Encapsulates all ammunition state for a single player. /// Tracks cooldowns, selection, and usage history per player. /// [Serializable] public class PlayerAmmoState { #region Properties public int PlayerIndex { get; private set; } public ProjectileType SelectedAmmo { get; set; } #endregion #region State // Cooldowns per projectile type (turns remaining) private Dictionary cooldowns; // Optional: Track usage for statistics/analytics private Dictionary usageCount; private ProjectileType lastUsedProjectile; #endregion #region Constructor public PlayerAmmoState(int playerIndex, ProjectileType defaultAmmo) { PlayerIndex = playerIndex; SelectedAmmo = defaultAmmo; cooldowns = new Dictionary(); usageCount = new Dictionary(); lastUsedProjectile = defaultAmmo; } #endregion #region Cooldown Management /// /// Initialize cooldown for a specific projectile type. /// public void InitializeCooldown(ProjectileType type) { if (!cooldowns.ContainsKey(type)) { cooldowns[type] = 0; } } /// /// Set cooldown for a specific projectile type. /// public void SetCooldown(ProjectileType type, int turns) { cooldowns[type] = turns; } /// /// Get remaining cooldown turns for a projectile type. /// public int GetCooldown(ProjectileType type) { return cooldowns.ContainsKey(type) ? cooldowns[type] : 0; } /// /// Check if projectile type is available (not on cooldown). /// public bool IsAmmoAvailable(ProjectileType type) { return GetCooldown(type) == 0; } /// /// Decrement all cooldowns by 1 turn. /// Returns list of projectile types that completed cooldown this turn. /// public List DecrementCooldowns() { List completedCooldowns = new List(); List types = new List(cooldowns.Keys); foreach (var type in types) { if (cooldowns[type] > 0) { cooldowns[type]--; if (cooldowns[type] == 0) { completedCooldowns.Add(type); } } } return completedCooldowns; } #endregion #region Usage Tracking /// /// Record that a projectile type was used. /// public void RecordUsage(ProjectileType type) { lastUsedProjectile = type; if (!usageCount.ContainsKey(type)) { usageCount[type] = 0; } usageCount[type]++; } /// /// Get usage count for a projectile type. /// public int GetUsageCount(ProjectileType type) { return usageCount.ContainsKey(type) ? usageCount[type] : 0; } /// /// Get the last projectile type used by this player. /// public ProjectileType LastUsedProjectile => lastUsedProjectile; /// /// Get total number of projectiles used by this player. /// public int TotalUsageCount { get { int total = 0; foreach (var count in usageCount.Values) { total += count; } return total; } } #endregion } }