A character/one-shot generator for KOBOLDS IN SPACE!
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.

koboldgen.py 43KB

4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. import random as r
  2. import argparse
  3. import sys
  4. beg = ["a","e","i","o","u","ba","be","bi","bo","bu","by","y","da","de","di","do","du","dy","fa","fi","fo","fe","fu","ga","ge","gi","go","gu","ka","ke","ki","ko","ku","ky","ma","me","mi","mo","mu","na","ne","ni","no","nu","pa","pe","pi","po","pu","ra","re","ri","ro","ru","ry","sa","se","si","so","su","ta","te","ti","to","tu","ty","wa","we","wi","wo","wy","za","ze","zi","zo","zu","zy"]
  5. mid = beg + ["l","x","n","r"]
  6. def binarize(num, l=None):
  7. r = bin(num)[2:]
  8. try:
  9. l = int(l)
  10. except:
  11. l = None
  12. if l != None:
  13. while len(r) < l:
  14. r = "0" + r
  15. return r
  16. def gen_name(length=None, minimum=3):
  17. maximum = 8
  18. if length == None:
  19. lgt = r.randint(minimum,maximum)
  20. else:
  21. if length > maximum:
  22. length = maximum
  23. print("Maximum name length is 8.")
  24. lgt = length
  25. morae = []
  26. while len("".join(morae)) < lgt:
  27. if len(morae) == 0:
  28. mora = r.choice(beg)
  29. morae.append(mora[0].upper() + mora[1:])
  30. else:
  31. mora = r.choice(mid)
  32. if morae[-1] == mora:
  33. mora = r.choice(mid)
  34. morae.append(mora)
  35. fname = "".join(morae)[:lgt]
  36. return fname
  37. class Plot:
  38. loc1 = ["friendly","hostile","derelict","airless","poison-filled/covered","overgrown","looted","burning","frozen","haunted","infested"]
  39. loc2 = ["asteroid","moon","space station","spaceship","ringworld","Dyson sphere","planet","Space Whale","pocket of folded space","time vortex","Reroll"]
  40. miss = ["explore","loot everything not bolted down too securely","find the last group of kobolds who came here","find a rumored secret weapon","find a way to break someone else's secret weapon","claim this place in the name of the Kobold Empire","make friends","rediscover lost technology","find lost magical items","find and defeat a powerful enemy"]
  41. prob = [
  42. {
  43. "id": 0,
  44. "name": "an Undead Sample Pack (swarm of zombies and skeletons)",
  45. "shortname": "undead",
  46. "stats": [0,5,2,6],
  47. },
  48. {
  49. "id": 1,
  50. "name": "a rival band of kobolds",
  51. "shortname": "kobold rivals",
  52. "stats": [3,3,4,4],
  53. },
  54. {
  55. "id": 2,
  56. "name": "a detachment from the Elf Armada",
  57. "shortname": "elves",
  58. "stats": [4,3,5,4],
  59. },
  60. {
  61. "id": 3,
  62. "name": "refugees with parasites. Big parasites",
  63. "shortname": "refugees",
  64. "stats": [2,4,0,0],
  65. },
  66. {
  67. "id": 4,
  68. "name": "an artificial intelligence bent on multi-world domination",
  69. "shortname": "AI",
  70. "stats": [4,1,6,3],
  71. },
  72. {
  73. "id": 5,
  74. "name": "robot spiders",
  75. "shortname": "spiders",
  76. "stats": [3,3,2,4],
  77. },
  78. {
  79. "id": 6,
  80. "name": "semi-intelligent metal eating slime",
  81. "shortname": "slime",
  82. "stats": [0,2,1,5],
  83. },
  84. {
  85. "id": 7,
  86. "name": "a living asteroid that intends to follow the kobolds home like the largest puppy",
  87. "shortname": "asteroid",
  88. "stats": [2,3,1,6],
  89. },
  90. {
  91. "id": 8,
  92. "name": "an old lich that wants everyone to stay off of their 'lawn'",
  93. "shortname": "lich",
  94. "stats": [5,2,6,3],
  95. },
  96. {
  97. "id": 9,
  98. "name": "elder gods hailing from the dark spaces between the stars",
  99. "shortname": "gods",
  100. "stats": [0,6,6,6],
  101. },
  102. {
  103. "id": 10,
  104. "name": "a Flying Brain Monster",
  105. "shortname": "Flying Brain Monster",
  106. "stats": [2,3,6,1],
  107. },
  108. ]
  109. def __init__(self, loc_desc=None, locIndex=None, battlefield=None, location=None, missIndex=None, oops=None, mission=None, probIndex=None, problem=None, probName=None, secProblem=None, thirdProblem=None):
  110. self.loc_desc = loc_desc if loc_desc != None else Plot.loc1[r.randint(0, len(Plot.loc1)-1)]
  111. self.locIndex = int(locIndex) if locIndex != None else r.randint(0, len(Plot.loc2)-1)
  112. self.battlefield = int(battlefield) if battlefield != None else 0
  113. self.location = location if location != None else Plot.loc2[self.locIndex]
  114. if locIndex == None and self.locIndex == len(Plot.loc2) - 2:
  115. if self.battlefield == 0:
  116. self.battlefield = 1
  117. self.locIndex = r.randint(0, len(Plot.loc2)-3)
  118. elif locIndex == None and self.locIndex != len(Plot.loc2) - 1:
  119. if self.location == "":
  120. self.location = Plot.loc2[self.locIndex]
  121. if self.location[0].lower() in ["a","e","i","o","u"]:
  122. self.locart = 1
  123. else:
  124. self.locart = 0
  125. self.missIndex = missIndex if missIndex != None else r.randint(0, len(Plot.miss)-1)
  126. self.oops = int(oops) if oops != None else r.randint(1,12)
  127. if self.oops != 1:
  128. self.oops = 0
  129. self.mission = Plot.miss[self.missIndex]
  130. self.probIndex = probIndex if probIndex != None else r.randint(0, len(Plot.prob)-1)
  131. self.problem = Plot.prob[self.probIndex]
  132. if secProblem != None:
  133. try:
  134. self.secProblem = [x for x in Plot.prob if x["id"] == secProblem][0]
  135. except:
  136. self.secProblem = None
  137. else:
  138. self.secProblem = None
  139. self.thirdProblem = [x for x in Plot.prob if x["id"] == thirdProblem][0] if (thirdProblem != None and thirdProblem in list(filter(lambda x:x["id"], Plot.prob))) else None
  140. self.problem["givenname"] = probName if probName != None else gen_name()
  141. if self.problem["id"] == 3 and self.secProblem == None:
  142. self.secProblem = {"name": "Parasites", "shortname": "parasites", "stats": [3,4,2,3]}
  143. if self.problem["id"] == 10 and self.secProblem == None:
  144. self.secProbIndex = r.randint(0, len(Plot.prob)-2)
  145. self.secProblem = Plot.prob[self.secProbIndex]
  146. if self.secProbIndex == 3 and self.thirdProblem == None:
  147. self.thirdProblem = {"name": "Parasites", "shortname": "parasites", "stats": [3,4,2,3]}
  148. self.fullProblem = self.problem["givenname"] + ", " + self.problem["name"]
  149. if self.secProblem and self.secProblem["name"] != "Parasites":
  150. self.fullProblem += " and its minion, " + self.secProblem["name"]
  151. class Character:
  152. # Remember to update gen_gadget() when you add gadgets
  153. GADGETS = [ {"id": 0, "name": "Awesome Dagger of Sneak(?) Attacks", "description": "Yell 'Sneak Attack!' to count a mixed-success Body attack as a success.", "reusable": True},
  154. {"id": 1, "name": "Button of Uselessness", "description": f"This large, red button can be stuck onto any flat surface, horizontal, vertical, or otherwise. A short time after it has been placed, any character (friend or foe) nearby must succeed a Brains roll to avoid pressing the button. Pressing the button does nothing, but this action takes the place of anything that might otherwise be done during an Event if the Brains roll is failed. The button can be pressed {r.randint(1,6)} times before it breaks and no longer compels others to press it.", "reusable": False},
  155. {"id": 2, "name": "Encyclopedia of Stuff I Totally Knew", "description": "Add 2 points to the target number of any uncontested Brains roll, or 1 point to the target number of a contested Brains roll.", "reusable": True},
  156. {"id": 3, "name": "Medkit", "description": "Make a Brains/Order roll to restore 2 lost Body points, or 1 on a Mixed Success. If the character has medical training, restored Body points may be doubled.", "reusable": False},
  157. {"id": 4, "name": "Potion of Healing", "description": "Restore 1 lost Body point. Using counts as an Event but no roll is needed unless it’s contested.", "reusable": False},
  158. {"id": 5, "name": "Tinfoil Helm of Shielding", "description": "Count any Brains damage as a mixed success. If you take Body damage, roll 1d6; on a 6, the Helm is useless until you take a nap.", "reusable": True},
  159. {"id": 6, "name": "Handy Toothbrush", "description": "Scrub the Space Gunk off whatever object you're interacting with to turn a mixed Order success to make that object work into a full success.", "reusable": True},
  160. {"id": 7, "name": "Jar of ... Something", "description": "Throw it (Body/Chaos) at another character to make them spend an Event cleaning it off, or throw it at the floor to make a ten-foot circle of difficult terrain.", "reusable": False},
  161. {"id": 8, "name": "Pocket Sand!", "description": "Yell 'Pocket Sand!' to count a successful Body attack against you as a mixed success.", "reusable": False},
  162. {"id": 9, "name": "The Fabulous Grappling Hook", "description": "As an Event, instantly move 50 feet in any direction. (Make sure you have 50 feet available to move in or take 1 Body damage when you arrive short of that.)", "reusable": True},
  163. {"id": 10, "name": "Pocket Accordion", "description": "Make a Brains/Order or Brains/Chaos roll. On a success, any nearby opponent has -1 Brains during their next event. On a failure, everybody nearby, including you, has -1 Brains on their next event.", "reusable": True},
  164. {"id": 11, "name": "Cloak of Adsorption", "description": "The cloak starts out white. Whenever you are the target of a successful attack, the cloak becomes the color of whatever hit you. If your cloak is already the same color as whatever hit you, the attack becomes a mixed success and the cloak turns black and can no longer absorb colors. The cloak becomes white again after a nap.", "reusable": True},
  165. {"id": 12, "name": "Cloak of Absorption", "description": "The cloak starts out white. You can remove the cloak and lay it over difficult terrain to make it easy terrain; if the terrain is difficult because the ground is wet, the cloak becomes wet and the ground in that area becomes dry. The cloak dries out after a nap.", "reusable": True},
  166. {"id": 13, "name": "Cloak of Desorption", "description": "The cloak starts out black. As an Event, you can cause a gas to evaporate from the cloak, leaving it a dingy gray and healing 1 Body to anyone within ten feet of you. The cloak becomes black again after a nap.", "reusable": True},
  167. {"id": 14, "name": "Cloak of Food Portions", "description": "Wearing this cloak causes it to flare out at the base, making the wearer resemble a pyramid. In conversations regarding food the wearer can add +2 to Brains rolls when trying to convince others to alter their diets. This can be done once per nap. Considering how many large things tend to snack on kobolds, this has been found to actually be quite useful.", "reusable": True},
  168. {"id": 15, "name": "Huge Goggles", "description": "If you take Body damage, roll 1d6; on a 6, the lenses of the Goggles break until you take a nap.", "reusable": True},
  169. {"id": 123, "name": "Shortbow of the Watch", "description": "Choose a single target. You get +1 to Body damage against that target and +1 to Brain rolls to track that target. Activating this is not an Event.", "reusable": True},
  170. {"id": 124, "name": "Hammer of Thunderbolts", "description": "You get +1 Body damage on any successful or partially successful attack with this weapon. As an Event, you can also throw it at a target or surface, which will stun any creature within 30 feet of the impact for 1d6 Events.", "reusable": True},
  171. {"id": 125, "name": "Eldritch Cannon", "description": "You conjure a small, semi-autonomous and semi-intelligent cannon that can produce a single spell effect of your choice as an Event.", "reusable": True},
  172. {"id": 126, "name": "Staff of Lightning", "description": "As an Event, create a lightning bolt from the tip of the staff that travels 30 feet in a straight line and deals 2 Body damage to any target in its path.", "reusable": True},
  173. {"id": 127, "name": "Voyager Staff", "description": "Any spell you cast has +1 damage. In addition, as an Event, you can move up to 50 feet in any direction - even through walls and other solid surfaces.", "reusable": True}
  174. ]
  175. # Remember to update gen_career() when you add careers
  176. CAREERS = [ {"id": 0, "name": "Soldier/Guard"},
  177. {"id": 1, "name": "Pilot"},
  178. {"id": 2, "name": "Medic"},
  179. {"id": 3, "name": "Mechanic"},
  180. {"id": 4, "name": "Politician"},
  181. {"id": 5, "name": "Spellcaster"},
  182. {"id": 6, "name": "Performer"},
  183. {"id": 7, "name": "Historian"},
  184. {"id": 8, "name": "Spy"},
  185. {"id": 9, "name": "Cook"},
  186. {"id": 10, "name": "Cartographer"},
  187. {"id": 11, "name": "Inventor"},
  188. {"id": 12, "name": "Merchant"},
  189. {"id": 123, "name": "Ranger"},
  190. {"id": 124, "name": "Barbarian"},
  191. {"id": 125, "name": "Artificer"},
  192. {"id": 126, "name": "Druid"},
  193. {"id": 127, "name": "Wizard"}
  194. ]
  195. def __init__(self, name=None, career=None, stats=None, gadget=None):
  196. self.name = name if name != None else ""
  197. if career == None:
  198. self.career = ""
  199. elif isinstance(career, str):
  200. self.career = career
  201. elif isinstance(career, int) and (career in range(13) or career in range(123,128)):
  202. self.career = [x for x in Character.CAREERS if x["id"] == career][0]
  203. else:
  204. self.career = ""
  205. self.stats = stats if stats != None else []
  206. if gadget == None:
  207. self.gadget = ""
  208. elif isinstance(gadget, str) or isinstance(gadget, dict):
  209. self.gadget = gadget
  210. else:
  211. self.gadget = next((x for x in Character.GADGETS if x["id"] == gadget), "")
  212. self.generate()
  213. def generate(self):
  214. if self.name == "" or self.name == None:
  215. self.gen_name()
  216. if self.stats == [] or self.stats == None:
  217. self.gen_stats()
  218. if self.career == "" or self.career == None:
  219. self.gen_career()
  220. if self.gadget == "" or self.gadget == None:
  221. self.gen_gadget()
  222. def gen_name(self):
  223. self.name = gen_name()
  224. def gen_stats(self, n=12):
  225. if n < 0:
  226. print("Too few stat points!")
  227. return [0,0,0,0]
  228. stats = [0,0,0,0]
  229. points = n
  230. slots = [0,1,2,3]
  231. for _ in range(points):
  232. tgl = False
  233. while tgl == False:
  234. slt = r.choice(slots)
  235. if slt <= 1:
  236. if stats[slt] == 6: continue
  237. if stats[slt] == 5 and r.randint(0,1) != 1: continue
  238. else:
  239. if stats[slt] == 6: continue
  240. if stats[slt] > 2 and r.randint(0,stats[slt]-2) != 1: continue
  241. stats[slt] += 1
  242. tgl = True
  243. stats[3] = stats[3] + 1
  244. if stats[3] > 6:
  245. stats[3] = 6
  246. stats[2] = stats[2] + 1
  247. if stats[2] > 6:
  248. stats[2] = 6
  249. self.stats = stats
  250. def gen_career(self):
  251. cid = r.randint(0,12)
  252. self.career = next((x for x in Character.CAREERS if x["id"] == cid), "")
  253. def gen_gadget(self):
  254. gid = r.randint(0,15)
  255. self.gadget = [x for x in Character.GADGETS if x["id"] == gid][0]
  256. def print_name(self, html=False):
  257. if isinstance(self.career, str):
  258. cname = self.career
  259. cid = next((x for x in Character.CAREERS if x["name"] == cname), "")
  260. else:
  261. cname = self.career["name"]
  262. c = dict(next((x for x in Character.CAREERS if x["name"] == cname), ""))
  263. cid = c["id"]
  264. if html:
  265. charText = f"<h4>Name: {self.name} (Kobold {cname})</h4>"
  266. else:
  267. charText = f"\nName: {self.name} (Kobold {cname} {cid})"
  268. print(charText)
  269. def print(self, html=False):
  270. if html:
  271. if isinstance(self.career, str):
  272. cname = self.career
  273. else:
  274. cname = self.career["name"]
  275. if isinstance(self.gadget, str):
  276. gdg = {"id": 127, "name": self.gadget, "description": "", "reusable": True}
  277. else:
  278. gdg = self.gadget
  279. out = (
  280. f"<div class='kobold'>\n"
  281. f" <span class='koboldid'>\n"
  282. f" <span class='koboldname'>{self.name}</span><br>\n"
  283. f" <span class='koboldcareer'>Kobold {cname}</span>\n"
  284. f" </span>\n"
  285. f" <br>\n"
  286. f" <span class='koboldstats'>\n"
  287. f" <ul>\n"
  288. f" <li>Order: {self.stats[0]}</li>\n"
  289. f" <li>Chaos: {self.stats[1]}</li>\n"
  290. f" <li>Brain: {self.stats[2]}</li>\n"
  291. f" <li>Body: {self.stats[3]}</li>\n"
  292. f" </ul>\n"
  293. f" </span>\n"
  294. f" <br>\n"
  295. f" <span class='koboldgadget'>\n"
  296. f" <span class='koboldgadgetname'>{gdg['name']}</span><br>\n"
  297. f" <span class='koboldgadgetdescription'>{gdg['description']}</span>\n"
  298. f" <span class='koboldgadgetreuse'>{'<br>Reusable' if gdg['reusable'] else ''}</span>\n"
  299. f" </span>"
  300. f"</div>\n"
  301. )
  302. print(out)
  303. else:
  304. self.print_name()
  305. print(f"Order: {self.stats[0]}")
  306. print(f"Chaos: {self.stats[1]}")
  307. print(f"Brain: {self.stats[2]}")
  308. print(f"Body: {self.stats[3]}")
  309. if isinstance(self.gadget, str):
  310. print(f"Gadget: {self.gadget}")
  311. else:
  312. print(f"Gadget: {self.gadget['name']} ({self.gadget['description']}{'- Reusable' if self.gadget['reusable'] else ''})")
  313. class Ship:
  314. NAME1 = ["Red","Orange","Yellow","Green","Blue","Violet","Dark","Light","Frenzied","Maniacal","Ancient"]
  315. NAME2 = ["Moon","Comet","Star","Saber","World-Eater","Dancer","Looter","Phlogiston","Fireball","Mecha","Raptor"]
  316. GQUAL = ["is stealthy & unarmored","is speedy & unarmored","is maneuverable & unarmored","is always repairable","is self-repairing","is flamboyant & speedy","is slow & armored","is flamboyant & armored","is hard to maneuver & armored","has Too Many Weapons!","has a prototype hyperdrive"]
  317. BQUAL = ["has an annoying AI","has inconveniently crossed circuits","has an unpredictable power source","drifts to the right","is haunted","was recently 'found' so the kobolds are unused to it","is too cold","has a constant odd smell","its interior design... changes","its water pressure shifts between slow drip and power wash","it leaves a visible smoke trail"]
  318. def __init__(self, name1=None, name2=None, gqual = None, bqual = None):
  319. self.name1 = name1 if name1 != None else r.choice(Ship.NAME1)
  320. self.name2 = name2 if name2 != None else r.choice(Ship.NAME2)
  321. self.gqual = gqual if gqual != None else r.choice(Ship.GQUAL)
  322. self.bqual = bqual if bqual != None else r.choice(Ship.BQUAL)
  323. self.fullname = f"{self.name1} {self.name2}"
  324. def print(self, html=False):
  325. if (html):
  326. shipText = f"<p>The <strong>{self.fullname}</strong> <span style='color: blue;'>{self.gqual}</span>, but <span style='color: red;'>{self.bqual}</span>.</p>\n"
  327. else:
  328. shipText = f"The {self.fullname} {self.gqual}, but {self.bqual}.\n"
  329. print(shipText)
  330. class Campaign:
  331. ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?- "
  332. NAMELETS = ['a', 'e', 'i', 'o', 'u', 'b', 'y', 'd', 'f', 'g', 'k', 'm', 'n', 'p', 'r', 's', 't', 'w', 'z', 'l', 'x']
  333. def __init__(self, n=None, makeChars=True, fromPW=False, pw=None):
  334. if fromPW == True:
  335. self.ship = None
  336. self.params = None
  337. self.characters = None
  338. self.art = None
  339. self.masterpassword = pw
  340. self.decode_key(pw)
  341. else:
  342. self.masterpassword = None
  343. self.create_campaign(n, makeChars)
  344. def create_campaign(self, n, makeChars):
  345. n = 6 if n == None else n
  346. self.ship = Ship()
  347. self.params = Plot()
  348. self.params.problem["fullname"] = ""
  349. if self.params.problem["id"] in [1,2]:
  350. self.params.problem["fullname"] += " led by " + self.params.problem["name"]
  351. if self.params.problem["id"] in [4,7,8,10]:
  352. self.params.problem["fullname"] += " named " + self.params.problem["name"]
  353. if makeChars:
  354. self.characters = []
  355. for _ in range(n):
  356. c = Character()
  357. c.generate()
  358. self.characters.append(c)
  359. self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a"
  360. def generate_key(self):
  361. """
  362. "PACKTA CTICS! ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- -------" should generate the Season 3 Pack Tactics crew.
  363. "JUSTIN BAILEY" and "NARPAS SWORD" should do something too.
  364. Key is analphanumeric string generated from a bitfield
  365. Bitfield is:
  366. Location 1: 7 bits
  367. Location 2: 7 bits
  368. Location Battlefield: 1 bit
  369. Mission: 7 bits
  370. Oops: 1 bit
  371. Problem 1: 7 bits
  372. Problem 1 name: 40 bits
  373. Problem 2: 7 bits
  374. Ship name 1: 7 bits
  375. Ship name 2: 7 bits
  376. Ship gqual: 7 bits
  377. Ship bqual: 7 bits
  378. Character 1 name: 40 bits
  379. Character 1 career: 7 bits
  380. Character 1 order: 3 bits
  381. Character 1 chaos: 3 bits
  382. Character 1 body: 3 bits
  383. Character 1 brain: 3 bits
  384. Character 1 gadget: 7 bits
  385. Character 2 name: 40 bits
  386. Character 2 career: 7 bits
  387. Character 2 order: 3 bits
  388. Character 2 chaos: 3 bits
  389. Character 2 body: 3 bits
  390. Character 2 brain: 3 bits
  391. Character 2 gadget: 7 bits
  392. Character 3 name: 40 bits
  393. Character 3 career: 7 bits
  394. Character 3 order: 3 bits
  395. Character 3 chaos: 3 bits
  396. Character 3 body: 3 bits
  397. Character 3 brain: 3 bits
  398. Character 3 gadget: 7 bits
  399. Character 4 name: 40 bits
  400. Character 4 career: 7 bits
  401. Character 4 order: 3 bits
  402. Character 4 chaos: 3 bits
  403. Character 4 body: 3 bits
  404. Character 4 brain: 3 bits
  405. Character 4 gadget: 7 bits
  406. Character 5 name: 40 bits
  407. Character 5 career: 7 bits
  408. Character 5 order: 3 bits
  409. Character 5 chaos: 3 bits
  410. Character 5 body: 3 bits
  411. Character 5 brain: 3 bits
  412. Character 5 gadget: 7 bits
  413. Character 6 name: 40 bits
  414. Character 6 career: 7 bits
  415. Character 6 order: 3 bits
  416. Character 6 chaos: 3 bits
  417. Character 6 body: 3 bits
  418. Character 6 brain: 3 bits
  419. Character 6 gadget: 7 bits
  420. 104 for campaign
  421. 396 for characters
  422. total 501
  423. 11 remaining
  424. """
  425. self.key = ""
  426. l1 = bin(Plot.loc1.index(self.params.loc_desc))[2:]
  427. l2 = bin(Plot.loc2.index(self.params.location))[2:]
  428. lb = bin(self.params.battlefield)[2:]
  429. op = bin(self.params.oops)[2:]
  430. ms = bin(self.params.missIndex)[2:]
  431. pb1 = bin(self.params.probIndex)[2:]
  432. if self.params.probIndex == 10:
  433. pb2 = bin(self.params.secProbIndex)[2:]
  434. else:
  435. pb2 = bin(127)[2:]
  436. pbname = self.encode_name(self.params.problem["givenname"])
  437. n1 = bin(Ship.NAME1.index(self.ship.name1))[2:]
  438. n2 = bin(Ship.NAME2.index(self.ship.name2))[2:]
  439. gq = bin(Ship.GQUAL.index(self.ship.gqual))[2:]
  440. bq = bin(Ship.BQUAL.index(self.ship.bqual))[2:]
  441. chars = {}
  442. i = 0
  443. for chct in self.characters:
  444. chars[i] = {
  445. "name": self.encode_name(chct.name),
  446. "career": bin(chct.career["id"])[2:],
  447. "order": bin(chct.stats[0])[2:],
  448. "chaos": bin(chct.stats[1])[2:],
  449. "body": bin(chct.stats[2])[2:],
  450. "brains": bin(chct.stats[3])[2:],
  451. "gadget": bin(chct.gadget["id"])[2:]
  452. }
  453. i += 1
  454. l1 = lpad(l1, 7)
  455. l2 = lpad(l2, 7)
  456. ms = lpad(ms, 7)
  457. pb1 = lpad(pb1, 7)
  458. pb2 = lpad(pb2, 7)
  459. pbname = lpad(pbname, 40, "1")
  460. n1 = lpad(n1, 7)
  461. n2 = lpad(n2, 7)
  462. gq = lpad(gq, 7)
  463. bq = lpad(bq, 7)
  464. self.key += l1 + l2 + lb + ms + op + pb1 + pbname + pb2 + n1 + n2 + gq + bq
  465. for k,chct in chars.items():
  466. chct["name"] = lpad(chct["name"], 40, "1")
  467. chct["career"] = lpad(chct["career"], 7)
  468. chct["order"] = lpad(chct["order"],3)
  469. chct["chaos"] = lpad(chct["chaos"], 3)
  470. chct["body"] = lpad(chct["body"], 3)
  471. chct["brains"] = lpad(chct["brains"], 3)
  472. chct["gadget"] = lpad(chct["gadget"], 7)
  473. self.key += chct["name"] + chct["career"] + chct["order"] + chct["chaos"] + chct["body"] + chct["brains"] + chct["gadget"]
  474. while len(self.key) < 509:
  475. self.key = self.key + "0"
  476. letters = []
  477. letter = []
  478. for bit in self.key:
  479. letter.append(bit)
  480. if len(letter) == 6:
  481. letters.append(Campaign.ALPHABET[int("".join(letter),2)])
  482. letter = []
  483. words = []
  484. word = []
  485. for lt in letters:
  486. word.append(lt)
  487. if len(word) == 6:
  488. words.append("".join(word))
  489. word = []
  490. words.append("".join(word))
  491. self.password = " ".join(words)
  492. return self.password
  493. def decode_key(self, pw):
  494. densePwd = pw.replace(" ", "")
  495. if len(densePwd) != 84 and (densePwd not in ["PACKTACTICS!", "JUSTINBAILEY", "NARPASSWORD"]):
  496. print("This password is not valid. If this is a password that this generator created, please email noelle@noelle.codes and let me know.")
  497. sys.exit(0)
  498. if densePwd[:12] == "PACKTACTICS!":
  499. # Create a campaign featuring the Season 3 Pack Tactics crew.
  500. self.ship = Ship("Red", "Star", "is maneuverable & unarmored", "has a politician who thinks they're in charge of it")
  501. self.params = Plot()
  502. self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a"
  503. self.characters = []
  504. self.characters.append(Character("Niwri", 123, [3, 4, 4, 3], 123))
  505. self.characters.append(Character("Zax", 124, [1, 6, 2, 5], 124))
  506. self.characters.append(Character("Chroma", 125, [4, 2, 5, 3], 125))
  507. self.characters.append(Character("Zenosha", 126, [2, 3, 5, 2], 126))
  508. self.characters.append(Character("Snax", 127, [3, 4, 6, 1], 127))
  509. # self.print_params()
  510. # self.print_chars()
  511. return
  512. elif densePwd[:12] == "JUSTINBAILEY":
  513. # Create a random campaign, but everyone's Gadget is a leotard that somehow is also an environment suit
  514. self.create_campaign(n=6, makeChars=True)
  515. for c in self.characters:
  516. c.gadget = {"id":127, "name": "The Bailey", "description": "A form-fitting leotard that somehow protects the wearer from all environmental effects except extreme heat - including vacuum and poison.", "reusable": True}
  517. # self.print_params()
  518. # self.print_chars()
  519. return
  520. elif densePwd[:12] == "NARPASSWORD":
  521. # Create a random campaign, but all the kobolds' stats are set to 6
  522. self.create_campaign(n=6, makeChars=True)
  523. for c in self.characters:
  524. c.stats = [6,6,6,6]
  525. # self.print_params()
  526. # self.print_chars()
  527. return
  528. numPwd = []
  529. for c in densePwd:
  530. numPwd.append(Campaign.ALPHABET.index(c))
  531. bitPwd = [lpad(bin(x).replace("0b",""), 6) for x in numPwd]
  532. longBitPwd = []
  533. for word in bitPwd:
  534. longword = lpad(word,6)
  535. longBitPwd.append(longword)
  536. self.newBitfield = "".join(longBitPwd)
  537. while len(self.newBitfield) < 509:
  538. self.newBitfield += "0"
  539. outkey = {}
  540. # Location 1: 7 bits
  541. i,j = 0,7
  542. outkey["loc1"] = int(self.newBitfield[i:j], 2)
  543. # Location 2: 7 bits
  544. i,j = j,j+7
  545. outkey["loc2"] = int(self.newBitfield[i:j], 2)
  546. # Location Battlefield: 1 bit
  547. i,j = j,j+1
  548. outkey["battlefield"] = int(self.newBitfield[i:j], 2)
  549. # Mission: 7 bits
  550. i,j = j,j+7
  551. outkey["miss"] = int(self.newBitfield[i:j], 2)
  552. # Oops: 1 bit
  553. i,j = j,j+1
  554. outkey["oops"] = int(self.newBitfield[i:j], 2)
  555. # Problem 1: 7 bits
  556. i,j = j,j+7
  557. outkey["prob1"] = int(self.newBitfield[i:j], 2)
  558. # Problem 1 name: 40 bits
  559. i,j = j,j+40
  560. outkey["prob1name"] = self.newBitfield[i:j]
  561. # Problem 2: 7 bits
  562. i,j = j,j+7
  563. outkey["prob2"] = int(self.newBitfield[i:j], 2)
  564. # Ship name 1: 7 bits
  565. i,j = j,j+7
  566. outkey["sname1"] = int(self.newBitfield[i:j], 2)
  567. # Ship name 2: 7 bits
  568. i,j = j,j+7
  569. outkey["sname2"] = int(self.newBitfield[i:j], 2)
  570. # Ship gqual: 7 bits
  571. i,j = j,j+7
  572. outkey["gqual"] = int(self.newBitfield[i:j], 2)
  573. # Ship bqual: 7 bits
  574. i,j = j,j+7
  575. outkey["bqual"] = int(self.newBitfield[i:j], 2)
  576. # Character 1 name: 40 bits
  577. i,j = j,j+40
  578. outkey["char1name"] = self.newBitfield[i:j]
  579. # Character 1 career: 7 bits
  580. i,j = j,j+7
  581. outkey["char1career"] = int(self.newBitfield[i:j], 2)
  582. # Character 1 order: 3 bits
  583. i,j = j,j+3
  584. outkey["char1ord"] = int(self.newBitfield[i:j], 2)
  585. # Character 1 chaos: 3 bits
  586. i,j = j,j+3
  587. outkey["char1cha"] = int(self.newBitfield[i:j], 2)
  588. # Character 1 body: 3 bits
  589. i,j = j,j+3
  590. outkey["char1bod"] = int(self.newBitfield[i:j], 2)
  591. # Character 1 brain: 3 bits
  592. i,j = j,j+3
  593. outkey["char1bra"] = int(self.newBitfield[i:j], 2)
  594. # Character 1 gadget: 7 bits
  595. i,j = j,j+7
  596. outkey["char1gad"] = int(self.newBitfield[i:j], 2)
  597. # Character 2 name: 40 bits
  598. i,j = j,j+40
  599. outkey["char2name"] = self.newBitfield[i:j]
  600. # Character 2 career: 7 bits
  601. i,j = j,j+7
  602. outkey["char2career"] = int(self.newBitfield[i:j], 2)
  603. # Character 2 order: 3 bits
  604. i,j = j,j+3
  605. outkey["char2ord"] = int(self.newBitfield[i:j], 2)
  606. # Character 2 chaos: 3 bits
  607. i,j = j,j+3
  608. outkey["char2cha"] = int(self.newBitfield[i:j], 2)
  609. # Character 2 body: 3 bits
  610. i,j = j,j+3
  611. outkey["char2bod"] = int(self.newBitfield[i:j], 2)
  612. # Character 2 brain: 3 bits
  613. i,j = j,j+3
  614. outkey["char2bra"] = int(self.newBitfield[i:j], 2)
  615. # Character 2 gadget: 7 bits
  616. i,j = j,j+7
  617. outkey["char2gad"] = int(self.newBitfield[i:j], 2)
  618. # Character 3 name: 40 bits
  619. i,j = j,j+40
  620. outkey["char3name"] = self.newBitfield[i:j]
  621. # Character 3 career: 7 bits
  622. i,j = j,j+7
  623. outkey["char3career"] = int(self.newBitfield[i:j], 2)
  624. # Character 3 order: 3 bits
  625. i,j = j,j+3
  626. outkey["char3ord"] = int(self.newBitfield[i:j], 2)
  627. # Character 3 chaos: 3 bits
  628. i,j = j,j+3
  629. outkey["char3cha"] = int(self.newBitfield[i:j], 2)
  630. # Character 3 body: 3 bits
  631. i,j = j,j+3
  632. outkey["char3bod"] = int(self.newBitfield[i:j], 2)
  633. # Character 3 brain: 3 bits
  634. i,j = j,j+3
  635. outkey["char3bra"] = int(self.newBitfield[i:j], 2)
  636. # Character 3 gadget: 7 bits
  637. i,j = j,j+7
  638. outkey["char3gad"] = int(self.newBitfield[i:j], 2)
  639. # Character 4 name: 40 bits
  640. i,j = j,j+40
  641. outkey["char4name"] = self.newBitfield[i:j]
  642. # Character 4 career: 7 bits
  643. i,j = j,j+7
  644. outkey["char4career"] = int(self.newBitfield[i:j], 2)
  645. # Character 4 order: 3 bits
  646. i,j = j,j+3
  647. outkey["char4ord"] = int(self.newBitfield[i:j], 2)
  648. # Character 4 chaos: 3 bits
  649. i,j = j,j+3
  650. outkey["char4cha"] = int(self.newBitfield[i:j], 2)
  651. # Character 4 body: 3 bits
  652. i,j = j,j+3
  653. outkey["char4bod"] = int(self.newBitfield[i:j], 2)
  654. # Character 4 brain: 3 bits
  655. i,j = j,j+3
  656. outkey["char4bra"] = int(self.newBitfield[i:j], 2)
  657. # Character 4 gadget: 7 bits
  658. i,j = j,j+7
  659. outkey["char4gad"] = int(self.newBitfield[i:j], 2)
  660. # Character 5 name: 40 bits
  661. i,j = j,j+40
  662. outkey["char5name"] = self.newBitfield[i:j]
  663. # Character 5 career: 7 bits
  664. i,j = j,j+7
  665. outkey["char5career"] = int(self.newBitfield[i:j], 2)
  666. # Character 5 order: 3 bits
  667. i,j = j,j+3
  668. outkey["char5ord"] = int(self.newBitfield[i:j], 2)
  669. # Character 5 chaos: 3 bits
  670. i,j = j,j+3
  671. outkey["char5cha"] = int(self.newBitfield[i:j], 2)
  672. # Character 5 body: 3 bits
  673. i,j = j,j+3
  674. outkey["char5bod"] = int(self.newBitfield[i:j], 2)
  675. # Character 5 brain: 3 bits
  676. i,j = j,j+3
  677. outkey["char5bra"] = int(self.newBitfield[i:j], 2)
  678. # Character 5 gadget: 7 bits
  679. i,j = j,j+7
  680. outkey["char5gad"] = int(self.newBitfield[i:j], 2)
  681. # Character 6 name: 40 bits
  682. i,j = j,j+40
  683. outkey["char6name"] = self.newBitfield[i:j]
  684. # Character 6 career: 7 bits
  685. i,j = j,j+7
  686. outkey["char6career"] = int(self.newBitfield[i:j], 2)
  687. # Character 6 order: 3 bits
  688. i,j = j,j+3
  689. outkey["char6ord"] = int(self.newBitfield[i:j], 2)
  690. # Character 6 chaos: 3 bits
  691. i,j = j,j+3
  692. outkey["char6cha"] = int(self.newBitfield[i:j], 2)
  693. # Character 6 body: 3 bits
  694. i,j = j,j+3
  695. outkey["char6bod"] = int(self.newBitfield[i:j], 2)
  696. # Character 6 brain: 3 bits
  697. i,j = j,j+3
  698. outkey["char6bra"] = int(self.newBitfield[i:j], 2)
  699. # Character 6 gadget: 7 bits
  700. i,j = j,j+7
  701. outkey["char6gad"] = int(self.newBitfield[i:j], 2)
  702. self.ship = Ship(Ship.NAME1[outkey["sname1"]], Ship.NAME2[outkey["sname2"]], Ship.GQUAL[outkey["gqual"]], Ship.BQUAL[outkey["bqual"]])
  703. self.params = Plot(loc_desc=Plot.loc1[outkey["loc1"]], locIndex=outkey["loc2"], battlefield=outkey["battlefield"], location=None, missIndex=outkey["miss"], oops=outkey["oops"], mission=None, probIndex=outkey["prob1"], problem=None, probName=self.decode_name(outkey["prob1name"]), secProblem=outkey["prob2"], thirdProblem=None)
  704. self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a"
  705. self.characters = []
  706. for q in range(1,7):
  707. keys = [f"char{q}name", f"char{q}career", f"char{q}ord", f"char{q}cha", f"char{q}bod", f"char{q}bra", f"char{q}gad"]
  708. c = Character(name=self.decode_name(outkey[keys[0]]), career=outkey[keys[1]], stats=[outkey[keys[2]], outkey[keys[3]], outkey[keys[4]], outkey[keys[5]]], gadget=outkey[keys[6]])
  709. self.characters.append(c)
  710. #return self.newBitfield
  711. def encode_name(self, name):
  712. field = "".join([lpad(bin(Campaign.NAMELETS.index(c.lower()))[2:], 5) for c in name])
  713. return field
  714. def decode_name(self, field):
  715. i,j = 35,40
  716. name = ""
  717. for _ in range(8):
  718. k = int(field[i:j], 2)
  719. if k != 31:
  720. name = Campaign.NAMELETS[k] + name
  721. i,j = i-5, i
  722. name = name[0].upper() + name[1:]
  723. return name
  724. def print_params(self, endc=" ", html=False):
  725. st = ["Order:", "Chaos:", "Brains:", "Body:"]
  726. cst = ", ".join([" ".join(y) for y in list(zip(st, [str(x) for x in self.params.problem["stats"]]))])
  727. if self.params.oops == 1:
  728. oops = "...well, they weren't paying attention, so don't tell them, but they're supposed to "
  729. else:
  730. oops = ""
  731. mission = oops + self.params.mission
  732. lines = [
  733. f"The Kobolds of the {self.ship.fullname}",
  734. f"have been sent out to {self.art} {self.params.loc_desc} {self.params.location}!",
  735. f"in order to {mission}",
  736. f"but they're challenged by {self.params.fullProblem}!",
  737. f"The stats of the {self.params.problem['shortname']}",
  738. f"{cst}"
  739. ]
  740. if self.params.secProblem:
  741. mst = ", ".join([" ".join(y) for y in list(zip(st, [str(x) for x in self.params.secProblem["stats"]]))])
  742. lines.append(f"The stats of the {self.params.secProblem['shortname']}")
  743. lines.append(f"{mst}")
  744. if self.params.thirdProblem:
  745. pst = ", ".join([" ".join(y) for y in list(zip(st, [str(x) for x in self.params.thirdProblem["stats"]]))])
  746. lines.append(f"The stats of the {self.params.thirdProblem['shortname']}")
  747. lines.append("{pst}")
  748. if html:
  749. out = (
  750. f"<div id='theship' class='firstrow'>\n"
  751. f" <span class='head'>The Ship</span>\n"
  752. f" <span id='shipname'>\n"
  753. f" The {self.ship.fullname}!\n"
  754. f" </span>\n"
  755. f" <br>\n"
  756. f" <span id='shipquality1'>\n"
  757. f" It {self.ship.gqual}...\n"
  758. f" </span><br>\n"
  759. f" <span id='shipquality2'>\n"
  760. f" But {self.ship.bqual}!\n"
  761. f" </span>\n"
  762. f"</div>\n"
  763. f"<div id='themission' class='firstrow'>\n"
  764. f" <span class='head'>The Mission</span>\n"
  765. f" <span id='missionloc'>\n"
  766. f" The kobolds have been sent to {self.art} {self.params.loc_desc} {self.params.location}\n"
  767. f" </span><br>\n"
  768. f" <span id='missiontarget'>\n"
  769. f" in order to {mission}!\n"
  770. f" </span>\n"
  771. f"</div>\n<br clear='all'>\n"
  772. f"<div id='theadversary' class='firstrow'>\n"
  773. f" <span class='head'>The Adversary</span>\n"
  774. f" They're challenged by <span id='advname'>{self.params.fullProblem}</span>!\n"
  775. f" <br>\n"
  776. f" <span id='problemstats'>\n"
  777. f" The stats of the {self.params.problem['shortname']}:<br>\n"
  778. f" {cst}\n"
  779. f" </span>\n"
  780. )
  781. if self.params.secProblem:
  782. out += (
  783. f" <br><span id='secprobstats'>\n"
  784. f" The stats of the {self.params.secProblem['shortname']}:<br>\n"
  785. f" {mst}\n"
  786. f" </span>\n"
  787. )
  788. if self.params.thirdProblem:
  789. out += (
  790. f" <br><span id='thirdprobstats'>\n"
  791. f" The stats of the {self.params.thirdProblem['shortname']}:<br>\n"
  792. f" {pst}\n"
  793. f" </span>\n"
  794. )
  795. out += f"</div>\n"
  796. print(out)
  797. print(f"<br clear='all'>\n")
  798. else:
  799. print(f"{lines[0]} {lines[1]} {lines[2]} -- {lines[3]}")
  800. print(f"{lines[4]}: {lines[5]}")
  801. if self.params.secProblem:
  802. print(f"- {lines[6]}: {lines[7]}")
  803. if self.params.thirdProblem:
  804. print(f"- - {lines[8]}: {lines[9]}")
  805. print()
  806. self.ship.print(html=html)
  807. def print_chars(self, html=False):
  808. if html:
  809. print(f"<div id='thekobolds'>\n")
  810. print(f"<span class='head'>The Kobolds</span>\n")
  811. else:
  812. print("The kobolds:")
  813. for k in self.characters:
  814. k.print(html=html)
  815. if html:
  816. print(f"</div>\n<br clear='all'>\n")
  817. def print_password(self, html=False):
  818. if self.masterpassword:
  819. pw = self.masterpassword
  820. else:
  821. pw = self.generate_key()
  822. if html:
  823. out = (
  824. f"<div id='passwordbox'>"
  825. f"<span class='passwordhead'>Permalink to this campaign:</span><br>"
  826. f"<span><a href='http://node.noelle.codes/kobold?pw={pw.replace(' ', '')}'>{pw.replace(' ', '')}</a></span><br><br>"
  827. f"<span class='passwordhead'><a href='http://node.noelle.codes/kobold'>Generate a new random campaign</a></span><br>"
  828. f"</div>"
  829. )
  830. print(out)
  831. print(f"<br clear='all'>\n")
  832. else:
  833. print(f"Password: {pw}")
  834. def decode(self, pwd):
  835. pass
  836. def lpad(s, n, c="0"):
  837. while len(s) < n:
  838. s = c + s
  839. return s
  840. if __name__ == "__main__":
  841. parser = argparse.ArgumentParser()
  842. group = parser.add_mutually_exclusive_group()
  843. group.add_argument("-c", "--campaign", help="print a full campaign block with N kobolds (default 6)", nargs="?", const=6, type=int, metavar="N")
  844. group.add_argument("-k", "--kobolds", help="print N kobolds", type=int, nargs="?", const=1, default=1, metavar="N")
  845. group.add_argument("-n", "--names", help="print N kobolds without stat blocks", nargs="?", const=1, type=int, metavar="N")
  846. group.add_argument("-p", "--params", help="print only the parameters of a campaign", action="store_true")
  847. group.add_argument("-s", "--ship", help="print only the ship name and description", action="store_true")
  848. group.add_argument("-pw", "--password", help="print the campaign defined by the submitted password", type=str, nargs="?", const=1, metavar="PW")
  849. parser.add_argument("--html", help="print in HTML instead of plain text", action="store_true")
  850. args = parser.parse_args()
  851. html = True if args.html else False
  852. if args.password:
  853. cmp = Campaign(fromPW = True, pw=args.password)
  854. cmp.print_params(html=html)
  855. cmp.print_chars(html=html)
  856. cmp.print_password(html=html)
  857. elif args.campaign:
  858. cmp = Campaign(args.campaign)
  859. cmp.print_params(html=html)
  860. cmp.print_chars(html=html)
  861. cmp.print_password(html=html)
  862. elif args.params:
  863. cmp = Campaign(makeChars=False)
  864. cmp.print_params(html=html)
  865. elif args.ship:
  866. ship = Ship()
  867. ship.print(html=html)
  868. elif args.names:
  869. for _ in range(args.names):
  870. c = Character()
  871. c.generate()
  872. c.print_name(html=html)
  873. else:
  874. for _ in range(args.kobolds):
  875. c = Character()
  876. c.generate()
  877. c.print(html=html)