-
Notifications
You must be signed in to change notification settings - Fork 1
/
dice.gd
29 lines (21 loc) · 803 Bytes
/
dice.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
extends Node
var _rng : RandomNumberGenerator = RandomNumberGenerator.new()
# use Dice.Type enum
func rollNormal(type : int, modifier : int = 0) -> int:
_rng.randomize()
return _rng.randi_range(1, type) + modifier
# use Dice.Type enum
func rollBest(type : int, modifier : int = 0) -> int:
return max(rollNormal(type, modifier), rollNormal(type, modifier)) as int
# use Dice.Type enum
func rollWorst(type : int, modifier : int = 0) -> int:
return min(rollNormal(type, modifier), rollNormal(type, modifier)) as int
# returns Dice.Outcome enum
func getOutcome(value : int, modifier : int = 0) -> int:
value += modifier
if (value >= 10):
return Enums.DiceOutcome.BEST
elif ((value >= 7) && (value <= 9)):
return Enums.DiceOutcome.WITH_CONSEQUENCE
else:
return Enums.DiceOutcome.WORST