45 lines
1.5 KiB
C#
45 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 = "MultiplyPerDiceEffect", menuName = "YachtDice/Modifiers/Effects/Multiply Per Dice")]
|
|
public class MultiplyPerDiceEffect : Effect
|
|
{
|
|
[Tooltip("Multiplier to apply per matching dice.")]
|
|
[SerializeField] private float multiplierPerDice = 1f;
|
|
|
|
[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;
|
|
|
|
foreach (var t in context.DiceValues)
|
|
{
|
|
if (targetDiceValue == 0 || t == targetDiceValue)
|
|
context.Multiplier *= multiplierPerDice;
|
|
}
|
|
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
public static MultiplyPerDiceEffect CreateForTest(float multiplierPerDice, int targetDiceValue = 0,
|
|
ModifierPhase phase = ModifierPhase.Multiplicative, int priority = 0)
|
|
{
|
|
var so = CreateInstance<MultiplyPerDiceEffect>();
|
|
so.multiplierPerDice = multiplierPerDice;
|
|
so.targetDiceValue = targetDiceValue;
|
|
so.SetPhaseForTest(phase);
|
|
so.SetPriorityForTest(priority);
|
|
return so;
|
|
}
|
|
#endif
|
|
}
|
|
}
|