Files
MuHua-123 64938f1137 1
2025-11-12 10:19:42 +08:00

47 lines
1.6 KiB
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> d6 + 调整值 + 加值 </summary>
public static int Roll6(int modifier = 0, int addValue = 0, DiceGrade grade = DiceGrade.) {
int d1 = Roll(6); int d2 = Roll(6);
if (grade == DiceGrade.) { d1 = d1 >= d2 ? d1 : d2; }
if (grade == DiceGrade.) { d1 = d1 <= d2 ? d1 : d2; }
return d1 + modifier + addValue;
}
/// <summary> d8 + 调整值 + 加值 </summary>
public static int Roll8(int modifier = 0, int addValue = 0, DiceGrade grade = DiceGrade.) {
int d1 = Roll(8); int d2 = Roll(8);
if (grade == DiceGrade.) { d1 = d1 >= d2 ? d1 : d2; }
if (grade == DiceGrade.) { d1 = d1 <= d2 ? d1 : d2; }
return d1 + modifier + addValue;
}
/// <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
}