Files
AppleHillsProduction/Assets/Scripts/Minigames/FortFight/Data/PlayerAmmoState.cs
tschesky e60d516e7e Implement Fort Fight minigame (#75)
Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com>
Reviewed-on: #75
2025-12-04 01:18:29 +00:00

157 lines
4.4 KiB
C#

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