Created
December 10, 2018 21:29
-
-
Save Pome-ro/2efe1938e99fa3b6a26ab9621a5846d8 to your computer and use it in GitHub Desktop.
Test the Difficulty Class of a given trap/event/skill in D&D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-DC { | |
param ( | |
# Parameter help description | |
[Parameter()] | |
[int] | |
$DC, | |
[Parameter()] | |
[int] | |
$Bonus, | |
[Parameter()] | |
[int] | |
$probonus = 0, | |
[Parameter()] | |
[int] | |
$tests = 500 | |
) | |
$results = New-Object System.Collections.Generic.List[System.Object] | |
for ($i = 0; $i -lt $tests ; $i++) { | |
$Dice = Get-Random -Minimum 1 -Maximum 20 | |
$Result = $Dice + $Bonus + $probonus | |
if ($Result -ge $DC) { | |
$results.add($True) | |
} else { | |
$results.add($False) | |
} | |
} | |
$Results = $Results.ToArray() | |
$TotalSuccess = $($Results | Where-Object {$_ -eq $True}).Count | |
$SuccesRate = ($TotalSuccess / $tests) * 100 | |
Write-Output $SuccesRate"% Success Rate" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment