mirror of
https://github.com/RPG-Research/bcirpg.git
synced 2024-04-16 14:23:01 +00:00
Change 2 for cleanup
This commit is contained in:
1
Phase2/Godot_GameCode/DiceRoller/.import/.gdignore
Normal file
1
Phase2/Godot_GameCode/DiceRoller/.import/.gdignore
Normal file
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,3 @@
|
||||
source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
|
||||
dest_md5="26ea799ea0a3da9e753b3ebe822e0570"
|
||||
|
Binary file not shown.
69
Phase2/Godot_GameCode/DiceRoller/DiceRoller.gd
Normal file
69
Phase2/Godot_GameCode/DiceRoller/DiceRoller.gd
Normal file
@ -0,0 +1,69 @@
|
||||
#This script is for the overarching node that will contain the diemanager singleton
|
||||
#It should be the only one of the die scripts that is attached onto a node.
|
||||
|
||||
extends Control
|
||||
|
||||
#desired dice types and needed percentage to pass are selected by game/user
|
||||
#desiredDice takes an int array representing the # sides on the die/dice
|
||||
#neededPercentageToPass takes a float that
|
||||
export var desiredDice: Array
|
||||
export var neededPercentageToPass: float
|
||||
|
||||
#Define dieManager variable
|
||||
var dieManager
|
||||
|
||||
func _ready():
|
||||
#create diemanager object
|
||||
dieManager = DieManager.new(desiredDice, neededPercentageToPass)
|
||||
|
||||
#function gets the result of the roll(s) and shows it in the UI
|
||||
func _on_Die_button_down():
|
||||
#rollDice function returns an array with the following elements in the following positions:
|
||||
#rollDice result: [[rolledValues], percentRolled, passResult, neededPercent, degreeOfSuccess, dice]
|
||||
var result = dieManager.rollDice()
|
||||
|
||||
|
||||
#assigning variable names to each of them for better clarity
|
||||
var rolledValues = result[0]
|
||||
var percentRolled = result[1]
|
||||
var passResult = result[2]
|
||||
var neededPercent = result[3]
|
||||
var degreeOfSuccess = result[4]
|
||||
var dice = result[5]
|
||||
|
||||
|
||||
#Check if passed or not
|
||||
if passResult:
|
||||
$Outcome.text = "Successful Roll!"
|
||||
else:
|
||||
$Outcome.text = "Failed Roll!"
|
||||
|
||||
var diceResultText = "Rolled Values:\n"
|
||||
|
||||
#Prints the integer calues of each die rolled in the form: "D(num faces): (value rolled)"
|
||||
for i in range(dice.size()):
|
||||
diceResultText += ("D" + str(dice[i]) + ": " + str(rolledValues[i]) + "\n")
|
||||
|
||||
#changing labels on screen
|
||||
$RolledValues.text = diceResultText
|
||||
$PercentNeeded.text = "Percent Needed to Pass: " + str(neededPercent * 100) + "%"
|
||||
$PercentRolled.text = "Percent Rolled: " + str(percentRolled * 100) + "%"
|
||||
$DegreeOfSuccess.text = "Degree of Success: " + str(degreeOfSuccess * 100) + "%"
|
||||
|
||||
#revealing labels to user
|
||||
$Outcome.show()
|
||||
$RolledValues.show()
|
||||
$PercentNeeded.show()
|
||||
$PercentRolled.show()
|
||||
$DegreeOfSuccess.show()
|
||||
|
||||
|
||||
#Calls the cleardata method for the diemanager and hides the text on screen
|
||||
func _on_Reset_button_down():
|
||||
$Outcome.hide()
|
||||
$PercentNeeded.hide()
|
||||
$PercentRolled.hide()
|
||||
$DegreeOfSuccess.hide()
|
||||
$RolledValues.hide()
|
||||
dieManager.clearData()
|
||||
dieManager.setDieManager(desiredDice, neededPercentageToPass)
|
97
Phase2/Godot_GameCode/DiceRoller/DiceRoller.tscn
Normal file
97
Phase2/Godot_GameCode/DiceRoller/DiceRoller.tscn
Normal file
@ -0,0 +1,97 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://DiceRoller.gd" type="Script" id=1]
|
||||
|
||||
[node name="DieManager" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
desiredDice = [ 10, 4, 6, 20 ]
|
||||
neededPercentageToPass = 0.4
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
color = Color( 0, 0, 0, 1 )
|
||||
|
||||
[node name="Die" type="Button" parent="."]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -95.0
|
||||
margin_top = 2.0
|
||||
margin_right = 92.0
|
||||
margin_bottom = 91.0
|
||||
text = "Roll Die/Dice"
|
||||
|
||||
[node name="RolledValues" type="Label" parent="."]
|
||||
visible = false
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
margin_left = -299.0
|
||||
margin_top = 6.0
|
||||
margin_right = 297.0
|
||||
margin_bottom = 86.0
|
||||
text = "Rolled Values:"
|
||||
align = 1
|
||||
autowrap = true
|
||||
|
||||
[node name="Outcome" type="Label" parent="."]
|
||||
visible = false
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
margin_left = -296.0
|
||||
margin_top = 173.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 253.0
|
||||
text = "Success!
|
||||
"
|
||||
align = 1
|
||||
autowrap = true
|
||||
|
||||
[node name="PercentNeeded" type="Label" parent="."]
|
||||
visible = false
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
margin_left = -286.0
|
||||
margin_top = 210.0
|
||||
margin_right = 310.0
|
||||
margin_bottom = 290.0
|
||||
text = "Percent Needed to Pass: 0%"
|
||||
align = 1
|
||||
autowrap = true
|
||||
|
||||
[node name="PercentRolled" type="Label" parent="."]
|
||||
visible = false
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
margin_left = -293.0
|
||||
margin_top = 241.0
|
||||
margin_right = 303.0
|
||||
margin_bottom = 321.0
|
||||
text = "Percent Rolled: 0%"
|
||||
align = 1
|
||||
autowrap = true
|
||||
|
||||
[node name="DegreeOfSuccess" type="Label" parent="."]
|
||||
visible = false
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
margin_left = -295.0
|
||||
margin_top = 272.0
|
||||
margin_right = 301.0
|
||||
margin_bottom = 352.0
|
||||
text = "Degree of Success: 0%"
|
||||
align = 1
|
||||
autowrap = true
|
||||
|
||||
[node name="Reset" type="Button" parent="."]
|
||||
margin_left = 457.0
|
||||
margin_top = 421.0
|
||||
margin_right = 567.0
|
||||
margin_bottom = 469.0
|
||||
text = "Reset"
|
||||
|
||||
[connection signal="button_down" from="Die" to="." method="_on_Die_button_down"]
|
||||
[connection signal="button_down" from="Reset" to="." method="_on_Reset_button_down"]
|
24
Phase2/Godot_GameCode/DiceRoller/Die.gd
Normal file
24
Phase2/Godot_GameCode/DiceRoller/Die.gd
Normal file
@ -0,0 +1,24 @@
|
||||
#Die class
|
||||
extends Node2D
|
||||
|
||||
class_name Die
|
||||
|
||||
#value of selected die type
|
||||
var numFaces: int
|
||||
|
||||
#Class constructor
|
||||
func _init(value):
|
||||
numFaces = value
|
||||
|
||||
#returns an integer value of the rolled result (assuming the die is a valid type)
|
||||
func rollDie():
|
||||
randomize()
|
||||
|
||||
var rolledNum
|
||||
rolledNum = randi() % numFaces + 1
|
||||
return rolledNum
|
||||
|
||||
|
||||
#Returns the number of faces on this die
|
||||
func getNumFaces():
|
||||
return numFaces
|
128
Phase2/Godot_GameCode/DiceRoller/DieManager.gd
Normal file
128
Phase2/Godot_GameCode/DiceRoller/DieManager.gd
Normal file
@ -0,0 +1,128 @@
|
||||
#This is the diemanager script that controls the rolling of the die/dice as well as calculates
|
||||
#the end result
|
||||
|
||||
class_name DieManager
|
||||
|
||||
extends Node2D
|
||||
|
||||
#Array of the desired dice values to mod god wants
|
||||
var desiredDice: Array
|
||||
|
||||
#User can select the percentage needed for a successful roll
|
||||
var neededPercentageToPass: float
|
||||
|
||||
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 = []
|
||||
|
||||
#rolledValues holds the integer value rolled from each die
|
||||
var rolledValues = []
|
||||
|
||||
#boolean based on whether the overall roll passed or not
|
||||
var passedRoll
|
||||
|
||||
#float holding the degree of success (rolledVal - neededPercentageToPass)
|
||||
var degreeOfSuccess
|
||||
|
||||
#Constructor for diemanager class
|
||||
func _init(dice, percent):
|
||||
desiredDice = dice
|
||||
neededPercentageToPass = percent
|
||||
loadData()
|
||||
|
||||
#set values of diemanager
|
||||
func setDieManager(dice, percent):
|
||||
desiredDice = dice
|
||||
neededPercentageToPass = percent
|
||||
loadData()
|
||||
|
||||
#Load the diceInPlay array
|
||||
func loadData():
|
||||
for elem in desiredDice:
|
||||
if elem in validDieTypes:
|
||||
diceUsed.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
|
||||
|
||||
#Resets the data in the script
|
||||
func clearData():
|
||||
isPercentageRoll = false
|
||||
rolledValues = []
|
||||
desiredDice = []
|
||||
diceUsed = []
|
||||
neededPercentageToPass = 0
|
||||
|
||||
#Returns the percent value of an individual die
|
||||
#Stores the rolled value in rolledValues
|
||||
func returnDiePercentage(inputedDie):
|
||||
#In case this method is being called on no dice
|
||||
if len(diceUsed) == 0:
|
||||
push_error("Cannot roll without any dice!")
|
||||
|
||||
var rolledVal = inputedDie.rollDie()
|
||||
|
||||
#add rolled integer value to array
|
||||
rolledValues.append(rolledVal)
|
||||
|
||||
#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
|
||||
return float(rolledVal % 10)
|
||||
|
||||
return float(rolledVal) / float(inputedDie.numFaces)
|
||||
|
||||
#Rolls all of the dice in diceUsed
|
||||
#returns the average of all the percentages
|
||||
func rollDice():
|
||||
#In case this method is being called on no dice
|
||||
if len(diceUsed) == 0:
|
||||
push_error("Cannot roll without any dice!")
|
||||
|
||||
#denominator will equal the total number of dice rolled
|
||||
var denominator = 0
|
||||
|
||||
#sum of floats of all rolled die percentages
|
||||
var sumOfPercentages = 0
|
||||
|
||||
if isPercentageRoll:
|
||||
sumOfPercentages += (returnDiePercentage(diceUsed[0]) / 10.0) + (returnDiePercentage(diceUsed[1]) / 100.0)
|
||||
else:
|
||||
for die in diceUsed:
|
||||
sumOfPercentages += returnDiePercentage(die)
|
||||
denominator += 1
|
||||
|
||||
var result = []
|
||||
|
||||
result.append(rolledValues)
|
||||
|
||||
if isPercentageRoll:
|
||||
#Percentage roll result remains the sum of the rolls
|
||||
result.append(sumOfPercentages)
|
||||
else:
|
||||
if denominator == 0:
|
||||
result.append(0)
|
||||
#result is average of sum of percentages otherwise rounded to 2 decimcal places
|
||||
|
||||
result.append(stepify((float(sumOfPercentages) / float(denominator)), 0.0001))
|
||||
|
||||
passedRoll = (result[1] >= neededPercentageToPass)
|
||||
#NOTE: degree of success is always calculated regardlesss of success/failure. Let me know if this should be changed
|
||||
degreeOfSuccess = result[1] - neededPercentageToPass
|
||||
result.append(passedRoll)
|
||||
result.append(neededPercentageToPass)
|
||||
result.append(degreeOfSuccess)
|
||||
result.append(desiredDice)
|
||||
|
||||
#rollDice result: [[rolledValues], percentRolled, passResult, neededPercent, degreeOfSuccess, dice]
|
||||
return result
|
||||
|
||||
|
7
Phase2/Godot_GameCode/DiceRoller/default_env.tres
Normal file
7
Phase2/Godot_GameCode/DiceRoller/default_env.tres
Normal file
@ -0,0 +1,7 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
BIN
Phase2/Godot_GameCode/DiceRoller/icon.png
Normal file
BIN
Phase2/Godot_GameCode/DiceRoller/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
35
Phase2/Godot_GameCode/DiceRoller/icon.png.import
Normal file
35
Phase2/Godot_GameCode/DiceRoller/icon.png.import
Normal file
@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.png"
|
||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
43
Phase2/Godot_GameCode/DiceRoller/project.godot
Normal file
43
Phase2/Godot_GameCode/DiceRoller/project.godot
Normal file
@ -0,0 +1,43 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=4
|
||||
|
||||
_global_script_classes=[ {
|
||||
"base": "Node2D",
|
||||
"class": "Die",
|
||||
"language": "GDScript",
|
||||
"path": "res://Die.gd"
|
||||
}, {
|
||||
"base": "Node2D",
|
||||
"class": "DieManager",
|
||||
"language": "GDScript",
|
||||
"path": "res://DieManager.gd"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"Die": "",
|
||||
"DieManager": ""
|
||||
}
|
||||
|
||||
[application]
|
||||
|
||||
config/name="GodotDiceRoller_Andrew"
|
||||
run/main_scene="res://DiceRoller.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[autoload]
|
||||
|
||||
DiceRoller="*res://DiceRoller.gd"
|
||||
|
||||
[physics]
|
||||
|
||||
common/enable_pause_aware_picking=true
|
||||
|
||||
[rendering]
|
||||
|
||||
environment/default_environment="res://default_env.tres"
|
Reference in New Issue
Block a user