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_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
desiredDice = [ 20, 7, 10 ]
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
|
@ -4,15 +4,8 @@ extends Button
|
||||
|
||||
class_name Die
|
||||
|
||||
#array of valid number of faces
|
||||
var dieTypes = [4, 6, 8, 10, 12, 20]
|
||||
|
||||
#value of selected die type
|
||||
var numFaces: int
|
||||
|
||||
#bool will be used to check if a valid die type was chosen
|
||||
var validNumFaces = false
|
||||
|
||||
#Class constructor
|
||||
func _init(value):
|
||||
numFaces = value
|
||||
@ -21,18 +14,8 @@ func _init(value):
|
||||
func rollDie():
|
||||
randomize()
|
||||
|
||||
#check if selected die type exists in dieTypes array
|
||||
for value in dieTypes:
|
||||
if value == numFaces:
|
||||
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]
|
||||
|
||||
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
|
||||
var diceUsed = []
|
||||
|
||||
@ -29,20 +37,39 @@ var degreeOfSuccess
|
||||
#Load the diceInPlay array
|
||||
func _ready():
|
||||
for elem in desiredDice:
|
||||
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)
|
||||
#The UML showed that this function only had one parameter, "inputedDie," so I assumed that
|
||||
#was the rolled integer value. However, in order to find the percetage we need the total sides as well
|
||||
#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.
|
||||
func returnDiePercentage(inputedDie):
|
||||
|
||||
var totalSides = diceInPlay[0].numFaces
|
||||
|
||||
#ensuring we don't lose the die objects in memory by storing them in another array
|
||||
diceUsed.append(diceInPlay[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)
|
||||
return result
|
||||
|
||||
@ -102,8 +129,13 @@ func _on_Die_button_down():
|
||||
#increment denominator
|
||||
denominator += 1
|
||||
|
||||
#result is average of sum of percentages
|
||||
var result = sumOfPercentages / denominator
|
||||
var result
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user