41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using UnityEngine;
|
|
using YachtDice.Modifiers.Core;
|
|
using YachtDice.Modifiers.Definition;
|
|
using YachtDice.Modifiers.Runtime;
|
|
|
|
namespace YachtDice.Modifiers.Conditions
|
|
{
|
|
[CreateAssetMenu(fileName = "DiceCountCondition", menuName = "YachtDice/Modifiers/Conditions/Dice Count")]
|
|
public class DiceCountCondition : Condition
|
|
{
|
|
[Tooltip("Dice face value to count (1-6). 0 = any value.")]
|
|
[SerializeField, Range(0, 6)] private int targetValue;
|
|
|
|
[Tooltip("Minimum number of dice that must match.")]
|
|
[SerializeField] private int minCount = 1;
|
|
|
|
public override bool Evaluate(ModifierContext context, ModifierInstance instance)
|
|
{
|
|
if (context.DiceValues == null) return false;
|
|
|
|
var count = 0;
|
|
foreach (var t in context.DiceValues)
|
|
{
|
|
if (targetValue == 0 || t == targetValue)
|
|
count++;
|
|
}
|
|
return count >= minCount;
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
public static DiceCountCondition CreateForTest(int targetValue, int minCount)
|
|
{
|
|
var so = CreateInstance<DiceCountCondition>();
|
|
so.targetValue = targetValue;
|
|
so.minCount = minCount;
|
|
return so;
|
|
}
|
|
#endif
|
|
}
|
|
}
|