[Add] Dice & Refactor private names
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using YachtDice.Categories;
|
||||
using YachtDice.Dice;
|
||||
|
||||
@@ -9,23 +10,23 @@ namespace YachtDice.Scoring
|
||||
[Serializable]
|
||||
public struct ScoreResult
|
||||
{
|
||||
public int BaseScore;
|
||||
public int FlatBonus;
|
||||
public float Multiplier;
|
||||
public int[] DiceValues;
|
||||
public CategoryDefinition Category;
|
||||
[FormerlySerializedAs("BaseScore")] public int baseScore;
|
||||
[FormerlySerializedAs("FlatBonus")] public int flatBonus;
|
||||
[FormerlySerializedAs("Multiplier")] public float multiplier;
|
||||
[FormerlySerializedAs("DiceValues")] public int[] diceValues;
|
||||
[FormerlySerializedAs("Category")] public CategoryDefinition category;
|
||||
|
||||
public int FinalScore => Mathf.FloorToInt((BaseScore + FlatBonus) * Multiplier);
|
||||
public int FinalScore => Mathf.FloorToInt((baseScore + flatBonus) * multiplier);
|
||||
|
||||
public static ScoreResult Create(int baseScore, IReadOnlyList<IDice> dice, CategoryDefinition category)
|
||||
{
|
||||
return new ScoreResult
|
||||
{
|
||||
BaseScore = baseScore,
|
||||
FlatBonus = 0,
|
||||
Multiplier = 1f,
|
||||
DiceValues = DiceCheckUtility.ExtractValues(dice),
|
||||
Category = category
|
||||
baseScore = baseScore,
|
||||
flatBonus = 0,
|
||||
multiplier = 1f,
|
||||
diceValues = DiceCheckUtility.ExtractValues(dice),
|
||||
category = category
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user