Data refactor
This commit is contained in:
156
Assets/Scripts/Minigames/FortFight/Data/PlayerAmmoState.cs
Normal file
156
Assets/Scripts/Minigames/FortFight/Data/PlayerAmmoState.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd7545bfc92d4096b53954bab9884b15
|
||||
timeCreated: 1764797211
|
||||
Reference in New Issue
Block a user