using System;
using System.Collections.Generic;
namespace NightclubArcadia.Skills
{
///
/// Transient state modifiers (third of three modifier sources). Pure state — no check math.
/// Use skillId "*" to apply to every skill.
///
public sealed class SkillStateModifiers
{
readonly Dictionary> _bySource =
new Dictionary>(StringComparer.Ordinal);
public void Set(string sourceKey, string skillId, int delta)
{
if (string.IsNullOrEmpty(sourceKey))
{
throw new ArgumentException("Source key is required.", nameof(sourceKey));
}
if (string.IsNullOrEmpty(skillId))
{
throw new ArgumentException("Skill id is required.", nameof(skillId));
}
if (!_bySource.TryGetValue(sourceKey, out var map))
{
map = new Dictionary(StringComparer.OrdinalIgnoreCase);
_bySource[sourceKey] = map;
}
map[skillId] = delta;
}
public void Clear(string sourceKey)
{
if (string.IsNullOrEmpty(sourceKey))
{
return;
}
_bySource.Remove(sourceKey);
}
public int TotalFor(string skillId)
{
if (string.IsNullOrEmpty(skillId))
{
return 0;
}
var total = 0;
foreach (var map in _bySource.Values)
{
if (map.TryGetValue(skillId, out var specific))
{
total += specific;
}
if (map.TryGetValue("*", out var wildcard))
{
total += wildcard;
}
}
return total;
}
}
}