[Add] Dice & Refactor private names

This commit is contained in:
2026-03-02 11:22:01 +07:00
parent 4890fa946e
commit f65976796d
36 changed files with 883 additions and 489 deletions
+31 -31
View File
@@ -17,28 +17,28 @@ namespace YachtDice.Scoring
public event Action<int> OnAllCategoriesScored;
public event Action<CategoryDefinition, ScoreResult> OnCategoryConfirmed;
private readonly Dictionary<CategoryDefinition, int> scorecard = new();
private readonly HashSet<CategoryDefinition> usedCategories = new();
private readonly Dictionary<CategoryDefinition, int> _scorecard = new();
private readonly HashSet<CategoryDefinition> _usedCategories = new();
private GameEventBus eventBus;
private ModifierRegistry modifierRegistry;
private CategoryCatalog catalog;
private GameEventBus _eventBus;
private ModifierRegistry _modifierRegistry;
private CategoryCatalog _catalog;
[Inject]
public void Construct(GameEventBus eventBus, ModifierRegistry modifierRegistry, CategoryCatalog catalog)
{
this.eventBus = eventBus;
this.modifierRegistry = modifierRegistry;
this.catalog = catalog;
this._eventBus = eventBus;
this._modifierRegistry = modifierRegistry;
this._catalog = catalog;
}
public CategoryCatalog Catalog => catalog;
public CategoryCatalog Catalog => _catalog;
public bool IsCategoryUsed(CategoryDefinition category) => usedCategories.Contains(category);
public bool IsCategoryUsed(CategoryDefinition category) => _usedCategories.Contains(category);
public int GetCategoryScore(CategoryDefinition category)
{
return scorecard.TryGetValue(category, out int score) ? score : -1;
return _scorecard.TryGetValue(category, out int score) ? score : -1;
}
public int TotalScore
@@ -46,14 +46,14 @@ namespace YachtDice.Scoring
get
{
int total = 0;
foreach (var kvp in scorecard) total += kvp.Value;
foreach (var kvp in _scorecard) total += kvp.Value;
return total;
}
}
public int CategoriesFilledCount => usedCategories.Count;
public int CategoriesFilledCount => _usedCategories.Count;
public int TotalCategoryCount => catalog != null ? catalog.Count : 0;
public int TotalCategoryCount => _catalog != null ? _catalog.Count : 0;
public bool IsComplete => CategoriesFilledCount >= TotalCategoryCount;
@@ -62,15 +62,15 @@ namespace YachtDice.Scoring
{
int baseScore = category.Calculate(dice);
if (eventBus == null || modifierRegistry == null)
if (_eventBus == null || _modifierRegistry == null)
return ScoreResult.Create(baseScore, dice, category);
var context = ModifierContext.CreateForScoring(
baseScore, dice, category,
currentRoll, currentTurn, playerCurrency,
modifierRegistry.Active);
_modifierRegistry.Active);
eventBus.Fire(TriggerType.OnCategoryScored, context).Forget();
_eventBus.Fire(TriggerType.OnCategoryScored, context).Forget();
return context.ToScoreResult();
}
@@ -78,20 +78,20 @@ namespace YachtDice.Scoring
public async UniTask<ScoreResult> ScoreCategoryAsync(IReadOnlyList<IDice> dice, CategoryDefinition category,
int currentRoll, int currentTurn, int playerCurrency)
{
if (usedCategories.Contains(category))
if (_usedCategories.Contains(category))
throw new InvalidOperationException($"Category {category.DisplayName} has already been scored.");
int baseScore = category.Calculate(dice);
ModifierContext context;
if (eventBus != null && modifierRegistry != null)
if (_eventBus != null && _modifierRegistry != null)
{
context = ModifierContext.CreateForScoring(
baseScore, dice, category,
currentRoll, currentTurn, playerCurrency,
modifierRegistry.Active);
_modifierRegistry.Active);
await eventBus.Fire(TriggerType.OnCategoryScored, context);
await _eventBus.Fire(TriggerType.OnCategoryScored, context);
}
else
{
@@ -106,8 +106,8 @@ namespace YachtDice.Scoring
var result = context.ToScoreResult();
int finalScore = result.FinalScore;
scorecard[category] = finalScore;
usedCategories.Add(category);
_scorecard[category] = finalScore;
_usedCategories.Add(category);
OnCategoryScored?.Invoke(category, finalScore);
OnCategoryConfirmed?.Invoke(category, result);
@@ -120,20 +120,20 @@ namespace YachtDice.Scoring
public ScoreResult ScoreCategory(IReadOnlyList<IDice> dice, CategoryDefinition category)
{
if (usedCategories.Contains(category))
if (_usedCategories.Contains(category))
throw new InvalidOperationException($"Category {category.DisplayName} has already been scored.");
int baseScore = category.Calculate(dice);
ModifierContext context = null;
if (eventBus != null && modifierRegistry != null)
if (_eventBus != null && _modifierRegistry != null)
{
context = ModifierContext.CreateForScoring(
baseScore, dice, category,
0, 0, 0,
modifierRegistry.Active);
_modifierRegistry.Active);
eventBus.Fire(TriggerType.OnCategoryScored, context).Forget();
_eventBus.Fire(TriggerType.OnCategoryScored, context).Forget();
}
ScoreResult result;
@@ -143,8 +143,8 @@ namespace YachtDice.Scoring
result = ScoreResult.Create(baseScore, dice, category);
int finalScore = result.FinalScore;
scorecard[category] = finalScore;
usedCategories.Add(category);
_scorecard[category] = finalScore;
_usedCategories.Add(category);
OnCategoryScored?.Invoke(category, finalScore);
OnCategoryConfirmed?.Invoke(category, result);
@@ -157,8 +157,8 @@ namespace YachtDice.Scoring
public void ResetScorecard()
{
scorecard.Clear();
usedCategories.Clear();
_scorecard.Clear();
_usedCategories.Clear();
}
}
}