Takumf

npc-generator.el

Jan 9th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. ;;; NPC generator for Basic d20 system.
  2.  
  3. (defun d6 ()
  4. (+ (random 6) 1))
  5.  
  6. (defun roll-stat ()
  7. (+ (d6) (d6) (d6)))
  8.  
  9. (defun mod-stat (stat)
  10. (cond ((<= stat 1) -5)
  11. ((and (>= stat 2) (<= stat 3)) -4)
  12. ((and (>= stat 4) (<= stat 5)) -3)
  13. ((and (>= stat 6) (<= stat 7)) -2)
  14. ((and (>= stat 8) (<= stat 9)) -1)
  15. ((and (>= stat 10) (<= stat 11)) 0)
  16. ((and (>= stat 12) (<= stat 13)) 1)
  17. ((and (>= stat 14) (<= stat 15)) 2)
  18. ((and (>= stat 16) (<= stat 17)) 3)
  19. ((and (>= stat 18) (<= stat 18)) 4)
  20. (5)))
  21.  
  22.  
  23. (defvar *gender* 0)
  24. (defvar *pronoun* '("His" "Her"))
  25. (defvar *stat-full-names* '("Strength" "Dexterity" "Constitution"
  26. "Intelligence" "Wisdom" "Charisma"))
  27. (defvar *stat-names* '("STR" "DEX" "CON" "INT" "WIS" "CHA"))
  28. (defvar *stat-values* '())
  29. (defvar *stat-mods* '())
  30.  
  31. (defun generate-abilities ()
  32. (dotimes (i 6)
  33. (push (roll-stat) *stat-values*)))
  34.  
  35. (defun generate-all ()
  36. (purge-all)
  37. (generate-abilities)
  38. (dolist (i *stat-values*)
  39. (push (mod-stat i) *stat-mods*))
  40. (setf *stat-mods* (reverse *stat-mods*)))
  41.  
  42. (defun validate (stat-mods)
  43. (let ((mods stat-mods))
  44. (if (or (> (apply '+ mods) 0)
  45. (> (nth 0 (sort mods '<)) 1))
  46. t
  47. nil)))
  48.  
  49. (defun purge-all ()
  50. (setf *stat-values* '())
  51. (setf *stat-mods* '()))
  52.  
  53. (defun describe-stat (modifier)
  54. (cond ((= modifier -5) "Abysymal")
  55. ((= modifier -4) "Awful")
  56. ((= modifier -3) "Bad")
  57. ((= modifier -2) "Poor")
  58. ((= modifier -1) "Medicore")
  59. ((= modifier 0) "Fair")
  60. ((= modifier 1) "Good")
  61. ((= modifier 2) "Great")
  62. ((= modifier 3) "Exceptional")
  63. ((= modifier 4) "Amazing")
  64. ("Phenomenal")))
  65.  
  66. (defun meaning-stat (modifier)
  67. (cond ((= modifier -5) "Severely Handicapted")
  68. ((= modifier -4) "Severely Impaired")
  69. ((= modifier -3) "Impaired")
  70. ((= modifier -2) "Significantly Below Average")
  71. ((= modifier -1) "Below Average")
  72. ((= modifier 0) "Average")
  73. ((= modifier 1) "Above Average")
  74. ((= modifier 2) "Significantly Above Average")
  75. ((= modifier 3) "Gifted")
  76. ((= modifier 4) "Highly Gifted")
  77. ("Excetionally Gifted")))
  78.  
  79. (defun describe-character ()
  80. (let ((index 0))
  81. (setf *gender* (random 2))
  82. (while (< index 6)
  83. (insert (nth *gender* *pronoun*) " "
  84. (nth index *stat-full-names*) " is rather "
  85. (describe-stat (nth index *stat-mods*)) " making "
  86. (nth *gender* *pronoun*) " quite "
  87. (meaning-stat (nth index *stat-mods*)) " for "
  88. (nth *gender* *pronoun*) " kind.\n")
  89. (setf index (+ index 1)))))
  90.  
  91. (defun output-character-stats ()
  92. (let ((index 0))
  93. (generate-all)
  94. (if (validate *stat-mods*)
  95. (progn
  96. (switch-to-buffer-other-window "*character*")
  97. (erase-buffer)
  98. (while (< index 6)
  99. (insert (nth index *stat-names*)
  100. "\t"
  101. (number-to-string (nth index *stat-values*))
  102. "\t"
  103. (number-to-string (nth index *stat-mods*))
  104. "\n")
  105. (setf index (+ index 1)))
  106. (insert "\n\n")
  107. (describe-character))
  108. (output-character-stats))))
Advertisement
Add Comment
Please, Sign In to add comment