47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using YachtDice.Modifiers.Core;
|
|
using YachtDice.Modifiers.Definition;
|
|
using YachtDice.Modifiers.Runtime;
|
|
|
|
namespace YachtDice.Modifiers.Effects
|
|
{
|
|
[CreateAssetMenu(fileName = "AddPerDiceEffect", menuName = "YachtDice/Modifiers/Effects/Add Per Dice")]
|
|
public class AddPerDiceEffect : Effect
|
|
{
|
|
[Tooltip("Points to add per matching dice.")]
|
|
[SerializeField] private int valuePerDice;
|
|
|
|
[Tooltip("Dice face value to match (1-6). 0 = any/all dice.")]
|
|
[SerializeField, Range(0, 6)] private int targetDiceValue;
|
|
|
|
public override UniTask Apply(ModifierContext context, ModifierInstance instance)
|
|
{
|
|
if (context.DiceValues == null) return UniTask.CompletedTask;
|
|
|
|
var count = 0;
|
|
foreach (var t in context.DiceValues)
|
|
{
|
|
if (targetDiceValue == 0 || t == targetDiceValue)
|
|
count++;
|
|
}
|
|
|
|
context.FlatBonus += valuePerDice * count * instance.Stacks;
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
public static AddPerDiceEffect CreateForTest(int valuePerDice, int targetDiceValue = 0,
|
|
ModifierPhase phase = ModifierPhase.Additive, int priority = 0)
|
|
{
|
|
var so = CreateInstance<AddPerDiceEffect>();
|
|
so.valuePerDice = valuePerDice;
|
|
so.targetDiceValue = targetDiceValue;
|
|
so.SetPhaseForTest(phase);
|
|
so.SetPriorityForTest(priority);
|
|
return so;
|
|
}
|
|
#endif
|
|
}
|
|
}
|