mirror of
https://github.com/RPG-Research/bcirpg.git
synced 2024-04-16 14:23:01 +00:00
Added D10 and easier die selection
This commit is contained in:
parent
e338cf1c47
commit
c20fd85567
@ -7,6 +7,7 @@
|
|||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
desiredDice = [ 20, 7, 10 ]
|
||||||
|
|
||||||
[node name="ColorRect" type="ColorRect" parent="."]
|
[node name="ColorRect" type="ColorRect" parent="."]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
|
@ -4,15 +4,8 @@ extends Button
|
|||||||
|
|
||||||
class_name Die
|
class_name Die
|
||||||
|
|
||||||
#array of valid number of faces
|
|
||||||
var dieTypes = [4, 6, 8, 10, 12, 20]
|
|
||||||
|
|
||||||
#value of selected die type
|
#value of selected die type
|
||||||
var numFaces: int
|
var numFaces: int
|
||||||
|
|
||||||
#bool will be used to check if a valid die type was chosen
|
|
||||||
var validNumFaces = false
|
|
||||||
|
|
||||||
#Class constructor
|
#Class constructor
|
||||||
func _init(value):
|
func _init(value):
|
||||||
numFaces = value
|
numFaces = value
|
||||||
@ -21,18 +14,8 @@ func _init(value):
|
|||||||
func rollDie():
|
func rollDie():
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
#check if selected die type exists in dieTypes array
|
var rolledNum
|
||||||
for value in dieTypes:
|
rolledNum = randi() % numFaces + 1
|
||||||
if value == numFaces:
|
return rolledNum
|
||||||
validNumFaces = true
|
|
||||||
|
|
||||||
#if the selected die type exists, we can roll an integer value based on the number of sides.
|
|
||||||
if validNumFaces:
|
|
||||||
var rolledNum
|
|
||||||
rolledNum = randi() % numFaces + 1
|
|
||||||
return rolledNum
|
|
||||||
else:
|
|
||||||
print("You do not have a valid number of sides on the die!")
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,14 @@ extends Control
|
|||||||
|
|
||||||
export var desiredDice = [20, 8]
|
export var desiredDice = [20, 8]
|
||||||
|
|
||||||
|
var validDieTypes = [4, 6, 8, 10, 12, 20]
|
||||||
|
|
||||||
|
|
||||||
|
#boolean for if a percentageroll is taking place
|
||||||
|
#we need a boolean for this because the way a percentage roll is calculated
|
||||||
|
#with two D10s is different than if one were using other dice
|
||||||
|
var isPercentageRoll = false
|
||||||
|
|
||||||
#diceUsed holds the dice objects that are rolled
|
#diceUsed holds the dice objects that are rolled
|
||||||
var diceUsed = []
|
var diceUsed = []
|
||||||
|
|
||||||
@ -29,7 +37,15 @@ var degreeOfSuccess
|
|||||||
#Load the diceInPlay array
|
#Load the diceInPlay array
|
||||||
func _ready():
|
func _ready():
|
||||||
for elem in desiredDice:
|
for elem in desiredDice:
|
||||||
diceInPlay.append(Die.new(elem))
|
if elem in validDieTypes:
|
||||||
|
diceInPlay.append(Die.new(elem))
|
||||||
|
|
||||||
|
#conditional to check if two D10s are being used
|
||||||
|
#if so, we know that a percentage roll is taking place
|
||||||
|
if len(desiredDice) == 2 && desiredDice[0] == 10 && desiredDice[1] == 10:
|
||||||
|
isPercentageRoll = true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#This is the function that returns the percentage of a rolled die (rolled val / total sides)
|
#This is the function that returns the percentage of a rolled die (rolled val / total sides)
|
||||||
#The UML showed that this function only had one parameter, "inputedDie," so I assumed that
|
#The UML showed that this function only had one parameter, "inputedDie," so I assumed that
|
||||||
@ -37,12 +53,23 @@ func _ready():
|
|||||||
#As a result, I would get the total sides by ensuring that the inputedDie corresponds to the die at index 0
|
#As a result, I would get the total sides by ensuring that the inputedDie corresponds to the die at index 0
|
||||||
#of the diceInPlay array.
|
#of the diceInPlay array.
|
||||||
func returnDiePercentage(inputedDie):
|
func returnDiePercentage(inputedDie):
|
||||||
|
|
||||||
var totalSides = diceInPlay[0].numFaces
|
var totalSides = diceInPlay[0].numFaces
|
||||||
|
|
||||||
#ensuring we don't lose the die objects in memory by storing them in another array
|
#ensuring we don't lose the die objects in memory by storing them in another array
|
||||||
diceUsed.append(diceInPlay[0])
|
diceUsed.append(diceInPlay[0])
|
||||||
diceInPlay.remove(0)
|
diceInPlay.remove(0)
|
||||||
|
|
||||||
|
#Checks if a percentageroll is being done
|
||||||
|
if isPercentageRoll:
|
||||||
|
|
||||||
|
#This conditional is used to detemrine if the rolled value is
|
||||||
|
#for the tens or ones digit
|
||||||
|
if (len(diceUsed) == 1):
|
||||||
|
return float(inputedDie % 10) / 10.0
|
||||||
|
else:
|
||||||
|
return float(inputedDie % 10) / 100.0
|
||||||
|
|
||||||
var result = float(inputedDie) / float(totalSides)
|
var result = float(inputedDie) / float(totalSides)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -102,8 +129,13 @@ func _on_Die_button_down():
|
|||||||
#increment denominator
|
#increment denominator
|
||||||
denominator += 1
|
denominator += 1
|
||||||
|
|
||||||
#result is average of sum of percentages
|
var result
|
||||||
var result = sumOfPercentages / denominator
|
if isPercentageRoll:
|
||||||
|
#Percentage roll result remains the sum of the rolls
|
||||||
|
result = sumOfPercentages
|
||||||
|
else:
|
||||||
|
#result is average of sum of percentages otherwise
|
||||||
|
result = sumOfPercentages / denominator
|
||||||
|
|
||||||
passedRoll = (result >= neededPercentageToPass)
|
passedRoll = (result >= neededPercentageToPass)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user