Files
YachtDice/Assets/Scripts/Scoring/ScoringSystem.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

90 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
using YachtDice.Modifiers;
namespace YachtDice.Scoring
{
public sealed class ScoringSystem : MonoBehaviour
{
public event Action<YachtCategory, int> OnCategoryScored;
public event Action<int> OnAllCategoriesScored;
public event Action<YachtCategory, ScoreResult> OnCategoryConfirmed;
private readonly Dictionary<YachtCategory, int> scorecard = new();
private readonly HashSet<YachtCategory> usedCategories = new();
private List<ModifierData> activeModifierData = new();
public bool IsCategoryUsed(YachtCategory category) => usedCategories.Contains(category);
public int GetCategoryScore(YachtCategory category)
{
return scorecard.TryGetValue(category, out int score) ? score : -1;
}
public int TotalScore
{
get
{
int total = 0;
foreach (var kvp in scorecard) total += kvp.Value;
return total;
}
}
public int CategoriesFilledCount => usedCategories.Count;
public int TotalCategoryCount => Enum.GetValues(typeof(YachtCategory)).Length;
public bool IsComplete => CategoriesFilledCount >= TotalCategoryCount;
public void SetActiveModifiers(List<ModifierData> modifiers)
{
activeModifierData = modifiers ?? new List<ModifierData>();
}
public IReadOnlyList<ModifierData> ActiveModifiers => activeModifierData;
public ScoreResult PreviewScore(int[] diceValues, YachtCategory category)
{
int baseScore = CategoryScorer.Calculate(diceValues, category);
ScoreResult result = ScoreResult.Create(baseScore, diceValues, category);
ModifierPipeline.Apply(activeModifierData, ref result, ModifierScope.SelectedCategory);
return result;
}
public ScoreResult ScoreCategory(int[] diceValues, YachtCategory category)
{
if (usedCategories.Contains(category))
throw new InvalidOperationException($"Category {category} has already been scored.");
int baseScore = CategoryScorer.Calculate(diceValues, category);
ScoreResult result = ScoreResult.Create(baseScore, diceValues, category);
ModifierPipeline.Apply(activeModifierData, ref result, ModifierScope.SelectedCategory);
ModifierPipeline.Apply(activeModifierData, ref result, ModifierScope.AnyCategoryClosed);
int finalScore = result.FinalScore;
scorecard[category] = finalScore;
usedCategories.Add(category);
OnCategoryScored?.Invoke(category, finalScore);
OnCategoryConfirmed?.Invoke(category, result);
if (IsComplete)
OnAllCategoriesScored?.Invoke(TotalScore);
return result;
}
public void ResetScorecard()
{
scorecard.Clear();
usedCategories.Clear();
}
}
}