Advertisement
Guest User

DiceLord PHP intro

a guest
Sep 30th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. /*
  2. * DiceLord (diceLord) is a roll notation and execution library for PHP. It is intended to be included or required.
  3. * a diceLord object is necessary, but the class really is only accessed for functions and each object doesn't store any data other than the functions it has.
  4. * While DiceLord was created for RollDB, it is designed to be used anywhere a RNG is needed, so by default it returns a number.
  5. *
  6. * While using DiceLord, it is a good idea to abstain from prefixing any methods with "diceLord" unless they are intended to integrate with DiceLord.
  7. * DiceLord also uses $_GLOBALS['dlText'] when dlExecute is called, which may cause issues.
  8. *
  9. * DiceLord has two means of output:
  10. * Returning the dlExecute(input) function will give you the final numerical outcome in the form of either successes or a sum of dice.
  11. * dlExecute also creates $dlText; assigning null or "null" to the second operator of the function will prevent this from happening, or you can change the variable name to $foo by putting "foo" in the second operator.
  12. *
  13. * Two of the design goals for DiceLord are to be human legible (without regular expressions), and to support an insane number of features to support basically all random number generation functions.
  14. * DiceLord is also case sensitive.
  15. *
  16. * DiceLord looks at pools of dice, with a simple notation involving commands (which can be Dice, Diemods, and pre-Operations, Operations, and post-Operations).
  17. * Pools are written separated by a semicolon, with each command in a pool separated via commas.
  18. *
  19. * Note that any time you see a # in the documentation, it is a standin for an integer; as are x, y, and z. "x"/"y"/"z" is a standin for a string.
  20. *
  21. * The following are mechanisms that DiceLord supports:
  22. *
  23. * Dice:
  24. * Dice are the individual components sent to the random number generator.
  25. * Traditional dice only require the letter in their notation and enough content to know what to roll; dy will result in 1dy, f will result in 4f+0, c will result in 1c.
  26. * Advanced "dice", which are actually stages or multiple dice referenced by a chart (such as Earthdawn's steps), cannot be used without both x and "y" input, where "y" is a string.
  27. *
  28. * xdy+z (x dice with y sides, modifying the result by z) [result of 1-y]
  29. * xf+z (x Fate dice, modifying the result by z) [result of -1, 0, or 1]
  30. * xc+z (x cointosses, modifying the result by z) [result of 0 or 1]
  31. * xs"y" (x steps/stages of "y" type) [takes from $"y" in $dlconfig.php] {special rules apply to stage/step notation}
  32. * xm"y" (x according to "y" method) [takes from result of "y"(x) in $dlmethods.php] {runs a function to calculate steps/stages/etc, diceLord is appended automatically to the front of "y"}
  33. *
  34. * Diemods:
  35. * Diemods are applied to all dice in a pool, and may impact the way that things are interpreted.
  36. * This means that in an xdy roll, the diemod would be applied x times.
  37. * Diemods all look at particular dice; once the results of a pool's rolls are completed diemods go back over the results and see if things happen.
  38. * Diemods are used before pre-Operations, and rolls can happen as a result of diemods.
  39. * Diemods are all suffixed with a diemod suffix, which is a number, and optionally a greater than or lesser than sign (all diemods) and some diemod specific suffixes (such as i/o for explosions).
  40. *
  41. * X for exploding dice. By default, an explosion increases the value of the original die. Adding "i" creates an inert outward explosion (new die is rolled that is not subject to explosion, but potentially to other diemods), while adding "o" creates an outward exploded die that is subject to exploding again. (X6 means results of 6 explode)
  42. * G for glitches; glitches are an additional result added to the $poolStr. (G<2 would mean any number below 2 glitches)
  43. * D for drop; this removes all dice with a certain result. (D1 would mean that results of 1 are removed, D<3 means all results of 3 and less are removed)
  44. * R for reroll; results of R are rerolled. This is recursive, though R is set up not to infinite loop (if R is greater than y in xdy or 1 for xf or xc it'll terminate).
  45. *
  46. * Pre-Operations:
  47. * Pre-Operations manipulate the pool prior to the Operation. You can have multiple, but they always execute in order of H-L-!, so keep that in mind.
  48. *
  49. * H# to keep highest # dice. H6 will keep the six highest individual results, so if you rolled 8d20, you'd get the six highest d20's from that result. Affix r to drop highest # dice.
  50. * L# to keep lowest # dice. L2 keeps the two lowest dice. Affix r to drop lowest # dice and keep the rest.
  51. * ! removes dice when a number is met; it will remove either the highest die (!#h), the lowest die (!#l), or a specific number when you put in something. (!1h will remove the highest die in the pool for each one that comes up).
  52. *
  53. * A complex pre-Operation would be H5, L2, !3, which would keep the lowest two of the highest five dice, and then remove any results of 3. !3, H5, L2; L2, !3, H5; or any combination of ordering will have the same result.
  54. *
  55. * Operations:
  56. * An Operation is an exclusive element; if you include multiple Operations in your DiceLord prompt, you'll only have one performed.
  57. * The default Operation is set in dlconfig.php, as are any list outcomes.
  58. *
  59. * I for individual results (each section of dice is rolled and reported independently (e.g. [d20,d6,I] results in "1-20, 1-6").
  60. * S for a sum (each section of dice is rolled indepdently, but added prior to reporting (e.g. [d20,d6,S] results in "2-26"). Note that if a cointoss or Fate roll has been done, this gets special notice.
  61. * # for success on a certain result (each section of dice has its result reported independently); >/< suffixes work as they do on diemods.
  62. *
  63. *
  64. * Post-Operations:
  65. * Post-Operations follow Operations, and are only valid if certain Operations are performed (
  66. *
  67. * ! can be a post operation when written as !# without a "h" or "l" suffix. If this is done it removes a success from the pool for each result of #. So !# would remove one success for every 1 met. You can have multiple !# of the same number (ex. !1, !1) to remove multiple successes for each result.
  68. *
  69. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement