71 lines
1.9 KiB
C#
71 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace NightclubArcadia.Skills
|
|
{
|
|
/// <summary>
|
|
/// Transient state modifiers (third of three modifier sources). Pure state — no check math.
|
|
/// Use skillId "*" to apply to every skill.
|
|
/// </summary>
|
|
public sealed class SkillStateModifiers
|
|
{
|
|
readonly Dictionary<string, Dictionary<string, int>> _bySource =
|
|
new Dictionary<string, Dictionary<string, int>>(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<string, int>(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;
|
|
}
|
|
}
|
|
}
|