2022-01-02 19:56:55 +00:00
|
|
|
extends Node
|
|
|
|
class_name Die
|
|
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
|
|
# var a = 2
|
|
|
|
# var b = "text"
|
|
|
|
|
|
|
|
enum DieCategory{
|
2022-01-09 20:01:00 +00:00
|
|
|
D4 = 4,
|
|
|
|
D6 = 6,
|
|
|
|
D8 = 8,
|
|
|
|
D10 = 10,
|
|
|
|
D12 = 12,
|
|
|
|
D00 = 00,
|
|
|
|
D20 = 20
|
2022-01-02 19:56:55 +00:00
|
|
|
}
|
|
|
|
|
2022-01-09 20:01:00 +00:00
|
|
|
var DieType = DieCategory
|
|
|
|
var NumberOfFaces = 0
|
2022-01-02 19:56:55 +00:00
|
|
|
|
2022-01-09 20:01:00 +00:00
|
|
|
|
|
|
|
func RollDie(InputDie):
|
|
|
|
#InputDie is supposed to be DieType for example.
|
|
|
|
var DieFaceResult = 0;
|
|
|
|
var LowestPossibleNumberOnDie = 0
|
|
|
|
var rng = RandomNumberGenerator.new()
|
2022-01-16 18:45:37 +00:00
|
|
|
rng.randomize()
|
2022-01-09 20:01:00 +00:00
|
|
|
|
|
|
|
var NoOfSides = NumberOfFaces
|
|
|
|
|
|
|
|
match NoOfSides:
|
|
|
|
100:
|
2022-01-16 18:45:37 +00:00
|
|
|
LowestPossibleNumberOnDie = 1
|
|
|
|
DieFaceResult = rng.randi_range(LowestPossibleNumberOnDie, 10)
|
|
|
|
DieFaceResult *= 10
|
|
|
|
|
2022-01-09 20:01:00 +00:00
|
|
|
_:
|
|
|
|
LowestPossibleNumberOnDie = 1
|
|
|
|
DieFaceResult = rng.randi_range(LowestPossibleNumberOnDie, NumberOfFaces)
|
|
|
|
|
2022-01-16 18:45:37 +00:00
|
|
|
var DieSuccessPercentage = (float(DieFaceResult)/float(NumberOfFaces))
|
2022-01-02 19:56:55 +00:00
|
|
|
|
2022-01-09 20:01:00 +00:00
|
|
|
print("DieFace:")
|
|
|
|
print(DieFaceResult)
|
2022-01-16 18:45:37 +00:00
|
|
|
print("Die Success Rate")
|
|
|
|
print(DieSuccessPercentage)
|
2022-01-09 20:01:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
func SetNumberOfSides():
|
|
|
|
var DSides = DieType
|
|
|
|
# For 7 Die Set, testing purposes
|
|
|
|
|
|
|
|
|
|
|
|
########################################
|
|
|
|
# Need to Seed Random Number Generator #
|
|
|
|
########################################
|
2022-01-02 19:56:55 +00:00
|
|
|
|
|
|
|
match DSides:
|
2022-01-09 20:01:00 +00:00
|
|
|
4:
|
|
|
|
NumberOfFaces = 4
|
|
|
|
6:
|
|
|
|
NumberOfFaces = 6
|
|
|
|
8:
|
|
|
|
NumberOfFaces = 8
|
|
|
|
10:
|
|
|
|
NumberOfFaces = 10
|
|
|
|
12:
|
|
|
|
NumberOfFaces = 12
|
|
|
|
00:
|
|
|
|
NumberOfFaces = 100
|
|
|
|
20:
|
|
|
|
NumberOfFaces = 20
|
|
|
|
|
|
|
|
print(NumberOfFaces)
|
2022-01-02 19:56:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2022-01-16 18:45:37 +00:00
|
|
|
DieType = DieCategory.D00
|
2022-01-09 20:01:00 +00:00
|
|
|
SetNumberOfSides()
|
|
|
|
RollDie(NumberOfFaces)
|
|
|
|
# Replace with function body.
|
2022-01-02 19:56:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
#func _process(delta):
|
|
|
|
# pass
|