You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package main
  2. import (
  3. "fmt"
  4. "math/rand"
  5. // "sort"
  6. "strings"
  7. "time"
  8. )
  9. type Character struct {
  10. Name string
  11. TotalForces int
  12. CorporealForces int
  13. EtherealForces int
  14. CelestialForces int
  15. Strength int
  16. Agility int
  17. Intellect int
  18. Precision int
  19. Will int
  20. Perception int
  21. Skills map[string]int
  22. Songs map[string]int
  23. Attunements []string
  24. Distinctions []string
  25. Artifacts []string
  26. Vessels map[string]int
  27. Roles map[string][]int
  28. }
  29. func roll(x, y int) []int {
  30. rolls := make([]int, x)
  31. for i := 0; i < x; i++ {
  32. rolls[i] = (rand.Intn(y) + 1)
  33. }
  34. return rolls
  35. }
  36. func sum(ary []int) int {
  37. s := 0
  38. for _, v := range ary {
  39. s += v
  40. }
  41. return s
  42. }
  43. func namegen() string {
  44. vowels := make([]string, 6)
  45. copy(vowels, strings.Split("aeiouy", ""))
  46. consonants := make([]string, 20)
  47. copy(consonants, strings.Split("bcdfghjklmnpqrstvwxz", ""))
  48. ln := rand.Intn(5) + 5
  49. vorc := rand.Intn(2)
  50. i := 0
  51. nm := make([]string, ln)
  52. for i < ln {
  53. sel, c := 0, ""
  54. if i%2 == vorc {
  55. sel = rand.Intn(6)
  56. c = vowels[sel]
  57. } else {
  58. sel = rand.Intn(20)
  59. c = consonants[sel]
  60. }
  61. if i == 0 {
  62. c = strings.ToUpper(c)
  63. }
  64. nm = append(nm, c)
  65. i++
  66. }
  67. return strings.Join(nm, "")
  68. }
  69. func main() {
  70. rand.Seed(time.Now().UnixNano()) // Keep this first in main()
  71. ply := Character{}
  72. ply.Name = namegen()
  73. ply.TotalForces = 9
  74. ply.CorporealForces = 1
  75. ply.EtherealForces = 1
  76. ply.CelestialForces = 1
  77. ply.Strength = 1
  78. ply.Agility = 1
  79. ply.Intellect = 1
  80. ply.Precision = 1
  81. ply.Will = 1
  82. ply.Perception = 1
  83. i := ply.TotalForces - (ply.CorporealForces + ply.EtherealForces + ply.CelestialForces)
  84. for i > 0 {
  85. r := rand.Intn(3)
  86. if r == 0 {
  87. ply.CorporealForces = ply.CorporealForces + 1
  88. } else if r == 1 {
  89. ply.EtherealForces = ply.EtherealForces + 1
  90. } else {
  91. ply.CelestialForces = ply.CelestialForces + 1
  92. }
  93. i--
  94. }
  95. // Corporeal
  96. coratt := (ply.CorporealForces * 4) - (ply.Strength + ply.Agility)
  97. for coratt > 0 {
  98. r := rand.Intn(2)
  99. if r == 0 {
  100. if ply.Strength == 12 || (ply.Strength >= (ply.Agility*2) && rand.Intn(3) == 0) {
  101. continue
  102. }
  103. ply.Strength = ply.Strength + 1
  104. } else {
  105. if ply.Agility == 12 || (ply.Agility >= (ply.Strength*2) && rand.Intn(3) == 0) {
  106. continue
  107. }
  108. ply.Agility = ply.Agility + 1
  109. }
  110. coratt--
  111. }
  112. // Ethereal
  113. ethatt := (ply.EtherealForces * 4) - (ply.Intellect + ply.Precision)
  114. for ethatt > 0 {
  115. r := rand.Intn(2)
  116. if r == 0 {
  117. if ply.Intellect == 12 || (ply.Intellect >= (ply.Precision*2) && rand.Intn(3) == 0) {
  118. continue
  119. }
  120. ply.Intellect = ply.Intellect + 1
  121. } else {
  122. if ply.Precision == 12 || (ply.Precision >= (ply.Intellect*2) && rand.Intn(3) == 0) {
  123. continue
  124. }
  125. ply.Precision = ply.Precision + 1
  126. }
  127. ethatt--
  128. }
  129. // Corporeal
  130. celatt := (ply.CelestialForces * 4) - (ply.Will + ply.Perception)
  131. for celatt > 0 {
  132. r := rand.Intn(2)
  133. if r == 0 {
  134. if ply.Will == 12 || (ply.Will >= (ply.Perception*2) && rand.Intn(3) == 0) {
  135. continue
  136. }
  137. ply.Will = ply.Will + 1
  138. } else {
  139. if ply.Perception == 12 || (ply.Perception >= (ply.Will*2) && rand.Intn(3) == 0) {
  140. continue
  141. }
  142. ply.Perception = ply.Perception + 1
  143. }
  144. celatt--
  145. }
  146. fmt.Println("=== Generated In Nomine character ===")
  147. fmt.Println(ply.Name)
  148. fmt.Printf("Cor %d\tEth %d\tCel %d\n",
  149. ply.CorporealForces,
  150. ply.EtherealForces,
  151. ply.CelestialForces)
  152. fmt.Printf("Str %d\tInt %d\tCel %d\n",
  153. ply.Strength,
  154. ply.Intellect,
  155. ply.Will)
  156. fmt.Printf("Agi %d\tPre %d\tPer %d\n",
  157. ply.Agility,
  158. ply.Precision,
  159. ply.Perception)
  160. }