Files
YachtDice/Assets/Scripts/Modifiers/ModifierEffect.cs
T
horooko bee20fd1f8 [Refactor] Add folder-based namespaces to all C# scripts
Wrap all 39 scripts and 6 test files in namespaces matching their folder
structure (e.g. Assets/Scripts/Dice/ → YachtDice.Dice). Add cross-namespace
using directives where types are referenced across modules. Set rootNamespace
in both .asmdef files (YachtDice, YachtDice.Tests).

Namespace mapping:
- YachtDice.Dice — Dice, DiceRoller
- YachtDice.Economy — CurrencyBank
- YachtDice.Game — GameManager, DiceManager, DebugGameInput
- YachtDice.Inventory — InventoryController/Model/SlotView/View
- YachtDice.Modifiers — ModifierData/Effect/Enums/Pipeline/Runtime/Target
- YachtDice.Persistence — SaveData, SaveSystem
- YachtDice.Scoring — CategoryScorer, ScoreResult, ScoringSystem, YachtCategory
- YachtDice.Shop — ShopCatalog/Controller/ItemView/Model/View
- YachtDice.UI — CategoryRowView, DicePanelView, GameController, GameInfoView, ScoreCardView
- YachtDice.Editor — ModifierAssetCreator
- YachtDice.Tests — all test files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 19:06:57 +07:00

61 lines
1.8 KiB
C#

using System.Collections.Generic;
using YachtDice.Scoring;
namespace YachtDice.Modifiers
{
public delegate void ModifierHandler(ModifierData data, ref ScoreResult result);
public static class ModifierEffect
{
private static readonly Dictionary<ModifierEffectType, ModifierHandler> Handlers = new()
{
{ ModifierEffectType.AddPerDieValue, ApplyAddPerDieValue },
{ ModifierEffectType.AddFlatToFinalScore, ApplyAddFlat },
{ ModifierEffectType.MultiplyPerDieValue, ApplyMultiplyPerDieValue },
{ ModifierEffectType.MultiplyFinalScore, ApplyMultiplyFinal }
};
public static void Apply(ModifierData data, ref ScoreResult result)
{
if (Handlers.TryGetValue(data.EffectType, out var handler))
handler(data, ref result);
}
private static void ApplyAddPerDieValue(ModifierData data, ref ScoreResult result)
{
int targetValue = data.Target.DieValue;
int count = 0;
for (int i = 0; i < result.DiceValues.Length; i++)
{
if (targetValue == 0 || result.DiceValues[i] == targetValue)
count++;
}
result.FlatBonus += (int)(data.EffectValue * count);
}
private static void ApplyAddFlat(ModifierData data, ref ScoreResult result)
{
result.FlatBonus += (int)data.EffectValue;
}
private static void ApplyMultiplyPerDieValue(ModifierData data, ref ScoreResult result)
{
int targetValue = data.Target.DieValue;
for (int i = 0; i < result.DiceValues.Length; i++)
{
if (targetValue == 0 || result.DiceValues[i] == targetValue)
result.Multiplier *= data.EffectValue;
}
}
private static void ApplyMultiplyFinal(ModifierData data, ref ScoreResult result)
{
result.Multiplier *= data.EffectValue;
}
}
}