mirror of
https://gitlab.com/Oreolek/salet-module.git
synced 2024-06-16 23:20:54 +03:00
New functions: randomElement and odds
This commit is contained in:
parent
ae90044ec1
commit
c9631b4330
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "salet",
|
||||
"version": "1.6.21",
|
||||
"version": "1.7.0",
|
||||
"description": "A general client-side framework for cybertext interactive fiction games.",
|
||||
"keywords": ["ifiction", "interactive fiction", "games", "coffee-script", "text", "menu"],
|
||||
"homepage": "https://salet.su",
|
||||
|
|
|
@ -41,6 +41,18 @@ class Random
|
|||
|
||||
randomInt: (upper) ->
|
||||
@rand(upper)
|
||||
|
||||
# return a random element from an array
|
||||
randomElement: (elements) ->
|
||||
return elements[@rand(elements.length - 1)]
|
||||
|
||||
# return odds of a (value + dN) being larger than target, rounded down
|
||||
odds: (value, target, n) ->
|
||||
chance = target - value
|
||||
if chance <= 0
|
||||
return 100
|
||||
chance = Math.floor((1 - chance / n) * 100)
|
||||
return chance
|
||||
|
||||
# Returns the result of rolling *n* dice with *dx* sides, and adding *plus*.
|
||||
dice: (n = 1, dx, plus = 0) ->
|
||||
|
|
Loading…
Reference in a new issue