Files
MuHua-UIElements/Assets/ModuleCore/ModuleTools/Dice.cs
T
MuHua-123 a7eb4f7bbb 1
2025-07-21 18:14:40 +08:00

33 lines
979 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
/// <summary>
/// 骰子
/// </summary>
public static class Dice {
/// <summary> 掷一次骰子 </summary>
public static int Roll(int value) {
return Random.Range(1, value + 1);
}
/// <summary> d20 + 调整值 + 加值 </summary>
public static int Roll20(int modifier = 0, int addValue = 0, DiceGrade grade = DiceGrade.) {
int d1 = Roll(20); int d2 = Roll(20);
if (grade == DiceGrade.) { d1 = d1 >= d2 ? d1 : d2; }
if (grade == DiceGrade.) { d1 = d1 <= d2 ? d1 : d2; }
return d1 + modifier + addValue;
}
/// <summary> Attribute规则:投4次d6,去掉最低值 </summary>
public static int RollAttribute() {
int[] rolls = { Roll(6), Roll(6), Roll(6), Roll(6) };
Array.Sort(rolls);
return rolls[1] + rolls[2] + rolls[3]; // 弃最低值
}
}
public enum DiceGrade {
= 0,
= 1,
= 2
}