A character/one-shot generator for KOBOLDS IN SPACE!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

koboldgen.py 39KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. import random as r
  2. import argparse
  3. import sys
  4. import adversaries
  5. import gear
  6. 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"]
  7. mid = beg + ["l","x","n","r"]
  8. def binarize(num, l=None):
  9. r = bin(num)[2:]
  10. try:
  11. l = int(l)
  12. except:
  13. l = None
  14. if l != None:
  15. while len(r) < l:
  16. r = "0" + r
  17. return r
  18. def gen_name(length=None, minimum=3):
  19. maximum = 8
  20. if length == None:
  21. lgt = r.randint(minimum,maximum)
  22. else:
  23. if length > maximum:
  24. length = maximum
  25. print("Maximum name length is 8.")
  26. lgt = length
  27. morae = []
  28. while len("".join(morae)) < lgt:
  29. if len(morae) == 0:
  30. mora = r.choice(beg)
  31. morae.append(mora[0].upper() + mora[1:])
  32. else:
  33. mora = r.choice(mid)
  34. if morae[-1] == mora:
  35. mora = r.choice(mid)
  36. morae.append(mora)
  37. fname = "".join(morae)[:lgt]
  38. return fname
  39. class Plot:
  40. loc1 = ["friendly","hostile","derelict","airless","poison-filled/covered","overgrown","looted","burning","frozen","haunted","infested"]
  41. loc2 = ["asteroid","moon","space station","spaceship","ringworld","Dyson sphere","planet","Space Whale","pocket of folded space","time vortex","Reroll"]
  42. 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"]
  43. prob = adversaries.prob
  44. 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):
  45. self.loc_desc = loc_desc if loc_desc != None else Plot.loc1[r.randint(0, len(Plot.loc1)-1)]
  46. self.locIndex = int(locIndex) if locIndex != None else r.randint(0, len(Plot.loc2)-1)
  47. self.battlefield = int(battlefield) if battlefield != None else 0
  48. self.location = location if location != None else Plot.loc2[self.locIndex]
  49. if locIndex == None and self.locIndex == len(Plot.loc2) - 2:
  50. if self.battlefield == 0:
  51. self.battlefield = 1
  52. self.locIndex = r.randint(0, len(Plot.loc2)-3)
  53. elif locIndex == None and self.locIndex != len(Plot.loc2) - 1:
  54. if self.location == "":
  55. self.location = Plot.loc2[self.locIndex]
  56. if self.location[0].lower() in ["a","e","i","o","u"]:
  57. self.locart = 1
  58. else:
  59. self.locart = 0
  60. self.missIndex = missIndex if missIndex != None else r.randint(0, len(Plot.miss)-1)
  61. self.oops = int(oops) if oops != None else r.randint(1,12)
  62. if self.oops != 1:
  63. self.oops = 0
  64. self.mission = Plot.miss[self.missIndex]
  65. self.probIndex = probIndex if probIndex != None else r.randint(0, len(Plot.prob)-1)
  66. self.problem = Plot.prob[self.probIndex]
  67. if type(self.problem["name"]) != str:
  68. self.problem["name"] = self.problem["name"]()
  69. if type(self.problem["note"]) != str:
  70. self.problem["note"] = self.problem["note"]()
  71. if self.problem["hasMinion"]:
  72. if secProblem != None:
  73. try:
  74. self.secProblem = Plot.prob[secProblem]
  75. except:
  76. self.secProblem = Plot.prob[r.choice(self.problem["potentialMinions"])]
  77. else:
  78. self.secProblem = Plot.prob[r.choice(self.problem["potentialMinions"])]
  79. if type(self.secProblem["name"]) != str:
  80. self.secProblem["name"] = self.secProblem["name"]()
  81. if type(self.secProblem["note"]) != str:
  82. self.secProblem["note"] = self.secProblem["note"]()
  83. self.fullProblem = ""
  84. if self.problem["needsName"]:
  85. self.problem["givenname"] = probName if probName != None else gen_name()
  86. self.fullProblem += self.problem["givenname"] + ", "
  87. if not self.problem["isPlural"] and self.problem["name"].split(" ")[0] != "Old":
  88. if self.problem["name"][0].lower() in ["a","e","i","o","u"]:
  89. self.fullProblem += "an "
  90. else:
  91. self.fullProblem += "a "
  92. self.fullProblem += self.problem["name"]
  93. if self.problem["hasMinion"]:
  94. self.fullProblem += " and their minion, "
  95. # if self.secProblem["name"][0].lower() in ["a","e","i","o","u"]:
  96. # self.fullProblem += "an "
  97. # else:
  98. # self.fullProblem += "a "
  99. self.fullProblem += self.secProblem["name"]
  100. class Character:
  101. # Remember to update gen_gadget() when you add gadgets
  102. GADGETS = gear.gadgets
  103. # Remember to update gen_career() when you add careers
  104. CAREERS = [ {"id": 0, "name": "Soldier/Guard"},
  105. {"id": 1, "name": "Pilot"},
  106. {"id": 2, "name": "Medic"},
  107. {"id": 3, "name": "Mechanic"},
  108. {"id": 4, "name": "Politician"},
  109. {"id": 5, "name": "Spellcaster"},
  110. {"id": 6, "name": "Performer"},
  111. {"id": 7, "name": "Historian"},
  112. {"id": 8, "name": "Spy"},
  113. {"id": 9, "name": "Cook"},
  114. {"id": 10, "name": "Cartographer"},
  115. {"id": 11, "name": "Inventor"},
  116. {"id": 12, "name": "Merchant"},
  117. {"id": 13, "name": "Bard"},
  118. {"id": 14, "name": "Sorcerer"},
  119. {"id": 15, "name": "Cleric"},
  120. {"id": 16, "name": "Rogue"},
  121. {"id": 17, "name": "Ranger"},
  122. {"id": 18, "name": "Barbarian"},
  123. {"id": 19, "name": "Artificer"},
  124. {"id": 20, "name": "Druid"},
  125. {"id": 21, "name": "Wizard"},
  126. {"id": 22, "name": "Fighter"},
  127. {"id": 23, "name": "Monk"},
  128. {"id": 24, "name": "Paladin"},
  129. {"id": 25, "name": "Warlock"},
  130. {"id": 26, "name": "Blood Hunter"}
  131. ]
  132. def __init__(self, name=None, career=None, stats=None, gadget=None):
  133. self.name = name if name != None else ""
  134. if career == None:
  135. self.career = ""
  136. elif isinstance(career, str):
  137. self.career = career
  138. elif isinstance(career, int) and career in range(27):
  139. self.career = [x for x in Character.CAREERS if x["id"] == career][0]
  140. else:
  141. self.career = ""
  142. self.stats = stats if stats != None else []
  143. if gadget == None:
  144. self.gadget = ""
  145. elif isinstance(gadget, str) or isinstance(gadget, dict):
  146. self.gadget = gadget
  147. if type(self.gadget["description"]) != str:
  148. self.gadget["description"] = self.gadget["description"]()
  149. else:
  150. self.gadget = next((x for x in Character.GADGETS if x["id"] == gadget), "")
  151. if type(self.gadget["description"]) != str:
  152. self.gadget["description"] = self.gadget["description"]()
  153. self.generate()
  154. def generate(self):
  155. if self.name == "" or self.name == None:
  156. self.gen_name()
  157. if self.stats == [] or self.stats == None:
  158. self.gen_stats()
  159. if self.career == "" or self.career == None:
  160. self.gen_career()
  161. if self.gadget == "" or self.gadget == None:
  162. self.gen_gadget()
  163. def gen_name(self):
  164. self.name = gen_name()
  165. def gen_stats(self, n=12):
  166. if n < 0:
  167. print("Too few stat points!")
  168. return [0,0,0,0]
  169. stats = [0,0,0,0]
  170. points = n
  171. slots = [0,1,2,3]
  172. for _ in range(points):
  173. tgl = False
  174. while tgl == False:
  175. slt = r.choice(slots)
  176. if slt <= 1:
  177. if stats[slt] == 6: continue
  178. if stats[slt] == 5 and r.randint(0,1) != 1: continue
  179. else:
  180. if stats[slt] == 6: continue
  181. if stats[slt] > 2 and r.randint(0,stats[slt]-2) != 1: continue
  182. stats[slt] += 1
  183. tgl = True
  184. stats[3] = stats[3] + 1
  185. if stats[3] > 6:
  186. stats[3] = 6
  187. stats[2] = stats[2] + 1
  188. if stats[2] > 6:
  189. stats[2] = 6
  190. self.stats = stats
  191. def gen_career(self):
  192. cid = r.randint(0,26)
  193. self.career = next((x for x in Character.CAREERS if x["id"] == cid), "")
  194. def gen_gadget(self):
  195. gid = r.randint(0,36)
  196. self.gadget = [x for x in Character.GADGETS if x["id"] == gid][0]
  197. if type(self.gadget["description"]) != str:
  198. self.gadget["description"] = self.gadget["description"]()
  199. def print_name(self, html=False):
  200. if isinstance(self.career, str):
  201. cname = self.career
  202. cid = next((x for x in Character.CAREERS if x["name"] == cname), "")
  203. else:
  204. cname = self.career["name"]
  205. c = dict(next((x for x in Character.CAREERS if x["name"] == cname), ""))
  206. cid = c["id"]
  207. if html:
  208. charText = f"<h4>Name: {self.name} (Kobold {cname})</h4>"
  209. else:
  210. charText = f"\nName: {self.name} (Kobold {cname} {cid})"
  211. print(charText)
  212. def print(self, html=False):
  213. if html:
  214. if isinstance(self.career, str):
  215. cname = self.career
  216. else:
  217. cname = self.career["name"]
  218. if isinstance(self.gadget, str):
  219. gdg = {"id": 127, "name": self.gadget, "description": "", "reusable": True}
  220. else:
  221. gdg = self.gadget
  222. out = (
  223. f"<div class='kobold'>\n"
  224. f" <span class='koboldid'>\n"
  225. f" <span class='koboldname'>{self.name}</span><br>\n"
  226. f" <span class='koboldcareer'>Kobold {cname}</span>\n"
  227. f" </span>\n"
  228. f" <br>\n"
  229. f" <span class='koboldstats'>\n"
  230. f" <ul>\n"
  231. f" <li>Order: {self.stats[0]}</li>\n"
  232. f" <li>Chaos: {self.stats[1]}</li>\n"
  233. f" <li>Brain: {self.stats[2]}</li>\n"
  234. f" <li>Body: {self.stats[3]}</li>\n"
  235. f" </ul>\n"
  236. f" </span>\n"
  237. f" <br>\n"
  238. f" <span class='koboldgadget'>\n"
  239. f" <span class='koboldgadgetname'>{gdg['name']}</span><br>\n"
  240. f" <span class='koboldgadgetdescription'>{gdg['description']}</span>\n"
  241. f" <span class='koboldgadgetreuse'>{'<br>Reusable' if gdg['reusable'] else ''}</span>\n"
  242. f" </span>"
  243. f"</div>\n"
  244. )
  245. print(out)
  246. else:
  247. self.print_name()
  248. print(f"Order: {self.stats[0]}")
  249. print(f"Chaos: {self.stats[1]}")
  250. print(f"Brain: {self.stats[2]}")
  251. print(f"Body: {self.stats[3]}")
  252. if isinstance(self.gadget, str):
  253. print(f"Gadget: {self.gadget}")
  254. else:
  255. print(f"Gadget: {self.gadget['name']} ({self.gadget['description']}{'- Reusable' if self.gadget['reusable'] else ''})")
  256. class Ship:
  257. NAME1 = ["Red","Orange","Yellow","Green","Blue","Violet","Dark","Light","Frenzied","Maniacal","Ancient"]
  258. NAME2 = ["Moon","Comet","Star","Saber","World-Eater","Dancer","Looter","Phlogiston","Fireball","Mecha","Raptor"]
  259. 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"]
  260. 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"]
  261. def __init__(self, name1=None, name2=None, gqual = None, bqual = None):
  262. self.name1 = name1 if name1 != None else r.choice(Ship.NAME1)
  263. self.name2 = name2 if name2 != None else r.choice(Ship.NAME2)
  264. self.gqual = gqual if gqual != None else r.choice(Ship.GQUAL)
  265. self.bqual = bqual if bqual != None else r.choice(Ship.BQUAL)
  266. self.fullname = f"{self.name1} {self.name2}"
  267. def print(self, html=False):
  268. if (html):
  269. 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"
  270. else:
  271. shipText = f"The {self.fullname} {self.gqual}, but {self.bqual}.\n"
  272. print(shipText)
  273. class Campaign:
  274. ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?- "
  275. NAMELETS = ['a', 'e', 'i', 'o', 'u', 'b', 'y', 'd', 'f', 'g', 'k', 'm', 'n', 'p', 'r', 's', 't', 'w', 'z', 'l', 'x']
  276. def __init__(self, n=None, makeChars=True, fromPW=False, pw=None):
  277. if fromPW == True:
  278. self.ship = None
  279. self.params = None
  280. self.characters = None
  281. self.art = None
  282. self.masterpassword = pw
  283. self.decode_key(pw)
  284. else:
  285. self.masterpassword = None
  286. self.create_campaign(n, makeChars)
  287. def create_campaign(self, n, makeChars):
  288. n = 6 if n == None else n
  289. self.ship = Ship()
  290. self.params = Plot()
  291. self.params.problem["fullname"] = ""
  292. if self.params.problem["id"] in [1,2]:
  293. self.params.problem["fullname"] += " led by " + self.params.problem["name"]
  294. if self.params.problem["id"] in [4,7,8,10]:
  295. self.params.problem["fullname"] += " named " + self.params.problem["name"]
  296. if makeChars:
  297. self.characters = []
  298. for _ in range(n):
  299. c = Character()
  300. c.generate()
  301. self.characters.append(c)
  302. self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a"
  303. def generate_key(self):
  304. """
  305. "PACKTA CTICS! ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- -------" should generate the Season 3 Pack Tactics crew.
  306. "JUSTIN BAILEY" and "NARPAS SWORD" should do something too.
  307. Key is analphanumeric string generated from a bitfield
  308. Bitfield is:
  309. Location 1: 7 bits
  310. Location 2: 7 bits
  311. Location Battlefield: 1 bit
  312. Mission: 7 bits
  313. Oops: 1 bit
  314. Problem 1: 7 bits
  315. Problem 1 name: 40 bits
  316. Problem 2: 7 bits
  317. Ship name 1: 7 bits
  318. Ship name 2: 7 bits
  319. Ship gqual: 7 bits
  320. Ship bqual: 7 bits
  321. Character 1 name: 40 bits
  322. Character 1 career: 7 bits
  323. Character 1 order: 3 bits
  324. Character 1 chaos: 3 bits
  325. Character 1 body: 3 bits
  326. Character 1 brain: 3 bits
  327. Character 1 gadget: 7 bits
  328. Character 2 name: 40 bits
  329. Character 2 career: 7 bits
  330. Character 2 order: 3 bits
  331. Character 2 chaos: 3 bits
  332. Character 2 body: 3 bits
  333. Character 2 brain: 3 bits
  334. Character 2 gadget: 7 bits
  335. Character 3 name: 40 bits
  336. Character 3 career: 7 bits
  337. Character 3 order: 3 bits
  338. Character 3 chaos: 3 bits
  339. Character 3 body: 3 bits
  340. Character 3 brain: 3 bits
  341. Character 3 gadget: 7 bits
  342. Character 4 name: 40 bits
  343. Character 4 career: 7 bits
  344. Character 4 order: 3 bits
  345. Character 4 chaos: 3 bits
  346. Character 4 body: 3 bits
  347. Character 4 brain: 3 bits
  348. Character 4 gadget: 7 bits
  349. Character 5 name: 40 bits
  350. Character 5 career: 7 bits
  351. Character 5 order: 3 bits
  352. Character 5 chaos: 3 bits
  353. Character 5 body: 3 bits
  354. Character 5 brain: 3 bits
  355. Character 5 gadget: 7 bits
  356. Character 6 name: 40 bits
  357. Character 6 career: 7 bits
  358. Character 6 order: 3 bits
  359. Character 6 chaos: 3 bits
  360. Character 6 body: 3 bits
  361. Character 6 brain: 3 bits
  362. Character 6 gadget: 7 bits
  363. 104 for campaign
  364. 396 for characters
  365. total 501
  366. 11 remaining
  367. """
  368. self.key = ""
  369. l1 = bin(Plot.loc1.index(self.params.loc_desc))[2:]
  370. l2 = bin(Plot.loc2.index(self.params.location))[2:]
  371. lb = bin(self.params.battlefield)[2:]
  372. op = bin(self.params.oops)[2:]
  373. ms = bin(self.params.missIndex)[2:]
  374. pb1 = bin(self.params.probIndex)[2:]
  375. if self.params.problem["hasMinion"]:
  376. pb2 = bin(self.params.secProblem["id"])[2:]
  377. else:
  378. pb2 = bin(127)[2:]
  379. if self.params.problem["needsName"]:
  380. pbname = self.encode_name(self.params.problem["givenname"])
  381. else:
  382. pbname = self.encode_name("yyyyyyyy")
  383. n1 = bin(Ship.NAME1.index(self.ship.name1))[2:]
  384. n2 = bin(Ship.NAME2.index(self.ship.name2))[2:]
  385. gq = bin(Ship.GQUAL.index(self.ship.gqual))[2:]
  386. bq = bin(Ship.BQUAL.index(self.ship.bqual))[2:]
  387. chars = {}
  388. i = 0
  389. for chct in self.characters:
  390. chars[i] = {
  391. "name": self.encode_name(chct.name),
  392. "career": bin(chct.career["id"])[2:],
  393. "order": bin(chct.stats[0])[2:],
  394. "chaos": bin(chct.stats[1])[2:],
  395. "body": bin(chct.stats[2])[2:],
  396. "brains": bin(chct.stats[3])[2:],
  397. "gadget": bin(chct.gadget["id"])[2:]
  398. }
  399. i += 1
  400. l1 = lpad(l1, 7)
  401. l2 = lpad(l2, 7)
  402. ms = lpad(ms, 7)
  403. pb1 = lpad(pb1, 7)
  404. pb2 = lpad(pb2, 7)
  405. pbname = lpad(pbname, 40, "1")
  406. n1 = lpad(n1, 7)
  407. n2 = lpad(n2, 7)
  408. gq = lpad(gq, 7)
  409. bq = lpad(bq, 7)
  410. self.key += l1 + l2 + lb + ms + op + pb1 + pbname + pb2 + n1 + n2 + gq + bq
  411. for k,chct in chars.items():
  412. chct["name"] = lpad(chct["name"], 40, "1")
  413. chct["career"] = lpad(chct["career"], 7)
  414. chct["order"] = lpad(chct["order"],3)
  415. chct["chaos"] = lpad(chct["chaos"], 3)
  416. chct["body"] = lpad(chct["body"], 3)
  417. chct["brains"] = lpad(chct["brains"], 3)
  418. chct["gadget"] = lpad(chct["gadget"], 7)
  419. self.key += chct["name"] + chct["career"] + chct["order"] + chct["chaos"] + chct["body"] + chct["brains"] + chct["gadget"]
  420. while len(self.key) < 509:
  421. self.key = self.key + "0"
  422. letters = []
  423. letter = []
  424. for bit in self.key:
  425. letter.append(bit)
  426. if len(letter) == 6:
  427. letters.append(Campaign.ALPHABET[int("".join(letter),2)])
  428. letter = []
  429. words = []
  430. word = []
  431. for lt in letters:
  432. word.append(lt)
  433. if len(word) == 6:
  434. words.append("".join(word))
  435. word = []
  436. words.append("".join(word))
  437. self.password = " ".join(words)
  438. return self.password
  439. def decode_key(self, pw):
  440. densePwd = pw.replace(" ", "")
  441. aBuiltin = densePwd[:12].upper()
  442. builtins = ["PACKTACTICS!", "JUSTINBAILEY", "NARPASSWORD", "PACKTACTICS1", "PACKTACTICS2", "PACKTACTICS3"]
  443. if len(densePwd) != 84 and (aBuiltin not in builtins):
  444. print("This password is not valid. If this is a password that this generator created, please email noelle@noelle.codes and let me know.")
  445. sys.exit(0)
  446. if aBuiltin in builtins:
  447. if aBuiltin == "PACKTACTICS!" or aBuiltin == "PACKTACTICS3":
  448. # Create a campaign featuring the Season 3 Pack Tactics crew.
  449. self.ship = Ship("Red", "Star", "is maneuverable & unarmored", "has a politician who thinks they're in charge of it")
  450. self.params = Plot()
  451. self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a"
  452. self.characters = []
  453. self.characters.append(Character("Niwri", 17, [3, 4, 4, 3], 123))
  454. self.characters.append(Character("Zax", 18, [1, 6, 2, 5], 124))
  455. self.characters.append(Character("Chroma", 19, [4, 2, 5, 3], 125))
  456. self.characters.append(Character("Zenosha", 20, [3, 4, 5, 2], 126))
  457. self.characters.append(Character("Snax", 21, [3, 4, 6, 1], 127))
  458. # self.print_params()
  459. # self.print_chars()
  460. return
  461. elif aBuiltin == "PACKTACTICS1":
  462. # Create a campaign featuring the Season 1 Pack Tactics crew.
  463. self.ship = Ship()
  464. self.params = Plot()
  465. self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a"
  466. self.characters = []
  467. self.characters.append(Character("Daldain", 13, [3, 4, 5, 2], 114))
  468. self.characters.append(Character("Gox", 18, [2, 5, 2, 5], 115))
  469. self.characters.append(Character("Zeeli", 14, [4, 2, 5, 3], 116))
  470. self.characters.append(Character("Sox", 16, [3, 3, 3, 3], 117))
  471. # self.print_params()
  472. # self.print_chars()
  473. return
  474. elif aBuiltin == "PACKTACTICS2":
  475. # Create a campaign featuring the Season 2 Pack Tactics crew.
  476. self.ship = Ship("Red", "Star", "is maneuverable & unarmored", "has a politician who thinks they're in charge of it")
  477. self.params = Plot()
  478. self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a"
  479. self.characters = []
  480. self.characters.append(Character("Daldain", 13, [4, 5, 5, 3], 118))
  481. self.characters.append(Character("Gox", 18, [2, 6, 4, 5], 119))
  482. self.characters.append(Character("Zeeli", 14, [3, 4, 6, 5], 120))
  483. self.characters.append(Character("Marwyse", 15, [4, 4, 6, 3], 121))
  484. self.characters.append(Character("Sox", 16, [5, 4, 4, 4], 122))
  485. # self.print_params()
  486. # self.print_chars()
  487. return
  488. elif aBuiltin == "JUSTINBAILEY":
  489. # Create a random campaign, but everyone's Gadget is a leotard that somehow is also an environment suit
  490. self.create_campaign(n=6, makeChars=True)
  491. for c in self.characters:
  492. 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}
  493. # self.print_params()
  494. # self.print_chars()
  495. return
  496. elif aBuiltin == "NARPASSWORD":
  497. # Create a random campaign, but all the kobolds' stats are set to 6
  498. self.create_campaign(n=6, makeChars=True)
  499. for c in self.characters:
  500. c.stats = [6,6,6,6]
  501. # self.print_params()
  502. # self.print_chars()
  503. return
  504. numPwd = []
  505. for c in densePwd:
  506. numPwd.append(Campaign.ALPHABET.index(c))
  507. bitPwd = [lpad(bin(x).replace("0b",""), 6) for x in numPwd]
  508. longBitPwd = []
  509. for word in bitPwd:
  510. longword = lpad(word,6)
  511. longBitPwd.append(longword)
  512. self.newBitfield = "".join(longBitPwd)
  513. while len(self.newBitfield) < 509:
  514. self.newBitfield += "0"
  515. outkey = {}
  516. # Location 1: 7 bits
  517. i,j = 0,7
  518. outkey["loc1"] = int(self.newBitfield[i:j], 2)
  519. # Location 2: 7 bits
  520. i,j = j,j+7
  521. outkey["loc2"] = int(self.newBitfield[i:j], 2)
  522. # Location Battlefield: 1 bit
  523. i,j = j,j+1
  524. outkey["battlefield"] = int(self.newBitfield[i:j], 2)
  525. # Mission: 7 bits
  526. i,j = j,j+7
  527. outkey["miss"] = int(self.newBitfield[i:j], 2)
  528. # Oops: 1 bit
  529. i,j = j,j+1
  530. outkey["oops"] = int(self.newBitfield[i:j], 2)
  531. # Problem 1: 7 bits
  532. i,j = j,j+7
  533. outkey["prob1"] = int(self.newBitfield[i:j], 2)
  534. # Problem 1 name: 40 bits
  535. i,j = j,j+40
  536. outkey["prob1name"] = self.newBitfield[i:j]
  537. # Problem 2: 7 bits
  538. i,j = j,j+7
  539. outkey["prob2"] = int(self.newBitfield[i:j], 2)
  540. # Ship name 1: 7 bits
  541. i,j = j,j+7
  542. outkey["sname1"] = int(self.newBitfield[i:j], 2)
  543. # Ship name 2: 7 bits
  544. i,j = j,j+7
  545. outkey["sname2"] = int(self.newBitfield[i:j], 2)
  546. # Ship gqual: 7 bits
  547. i,j = j,j+7
  548. outkey["gqual"] = int(self.newBitfield[i:j], 2)
  549. # Ship bqual: 7 bits
  550. i,j = j,j+7
  551. outkey["bqual"] = int(self.newBitfield[i:j], 2)
  552. # Character 1 name: 40 bits
  553. i,j = j,j+40
  554. outkey["char1name"] = self.newBitfield[i:j]
  555. # Character 1 career: 7 bits
  556. i,j = j,j+7
  557. outkey["char1career"] = int(self.newBitfield[i:j], 2)
  558. # Character 1 order: 3 bits
  559. i,j = j,j+3
  560. outkey["char1ord"] = int(self.newBitfield[i:j], 2)
  561. # Character 1 chaos: 3 bits
  562. i,j = j,j+3
  563. outkey["char1cha"] = int(self.newBitfield[i:j], 2)
  564. # Character 1 body: 3 bits
  565. i,j = j,j+3
  566. outkey["char1bod"] = int(self.newBitfield[i:j], 2)
  567. # Character 1 brain: 3 bits
  568. i,j = j,j+3
  569. outkey["char1bra"] = int(self.newBitfield[i:j], 2)
  570. # Character 1 gadget: 7 bits
  571. i,j = j,j+7
  572. outkey["char1gad"] = int(self.newBitfield[i:j], 2)
  573. # Character 2 name: 40 bits
  574. i,j = j,j+40
  575. outkey["char2name"] = self.newBitfield[i:j]
  576. # Character 2 career: 7 bits
  577. i,j = j,j+7
  578. outkey["char2career"] = int(self.newBitfield[i:j], 2)
  579. # Character 2 order: 3 bits
  580. i,j = j,j+3
  581. outkey["char2ord"] = int(self.newBitfield[i:j], 2)
  582. # Character 2 chaos: 3 bits
  583. i,j = j,j+3
  584. outkey["char2cha"] = int(self.newBitfield[i:j], 2)
  585. # Character 2 body: 3 bits
  586. i,j = j,j+3
  587. outkey["char2bod"] = int(self.newBitfield[i:j], 2)
  588. # Character 2 brain: 3 bits
  589. i,j = j,j+3
  590. outkey["char2bra"] = int(self.newBitfield[i:j], 2)
  591. # Character 2 gadget: 7 bits
  592. i,j = j,j+7
  593. outkey["char2gad"] = int(self.newBitfield[i:j], 2)
  594. # Character 3 name: 40 bits
  595. i,j = j,j+40
  596. outkey["char3name"] = self.newBitfield[i:j]
  597. # Character 3 career: 7 bits
  598. i,j = j,j+7
  599. outkey["char3career"] = int(self.newBitfield[i:j], 2)
  600. # Character 3 order: 3 bits
  601. i,j = j,j+3
  602. outkey["char3ord"] = int(self.newBitfield[i:j], 2)
  603. # Character 3 chaos: 3 bits
  604. i,j = j,j+3
  605. outkey["char3cha"] = int(self.newBitfield[i:j], 2)
  606. # Character 3 body: 3 bits
  607. i,j = j,j+3
  608. outkey["char3bod"] = int(self.newBitfield[i:j], 2)
  609. # Character 3 brain: 3 bits
  610. i,j = j,j+3
  611. outkey["char3bra"] = int(self.newBitfield[i:j], 2)
  612. # Character 3 gadget: 7 bits
  613. i,j = j,j+7
  614. outkey["char3gad"] = int(self.newBitfield[i:j], 2)
  615. # Character 4 name: 40 bits
  616. i,j = j,j+40
  617. outkey["char4name"] = self.newBitfield[i:j]
  618. # Character 4 career: 7 bits
  619. i,j = j,j+7
  620. outkey["char4career"] = int(self.newBitfield[i:j], 2)
  621. # Character 4 order: 3 bits
  622. i,j = j,j+3
  623. outkey["char4ord"] = int(self.newBitfield[i:j], 2)
  624. # Character 4 chaos: 3 bits
  625. i,j = j,j+3
  626. outkey["char4cha"] = int(self.newBitfield[i:j], 2)
  627. # Character 4 body: 3 bits
  628. i,j = j,j+3
  629. outkey["char4bod"] = int(self.newBitfield[i:j], 2)
  630. # Character 4 brain: 3 bits
  631. i,j = j,j+3
  632. outkey["char4bra"] = int(self.newBitfield[i:j], 2)
  633. # Character 4 gadget: 7 bits
  634. i,j = j,j+7
  635. outkey["char4gad"] = int(self.newBitfield[i:j], 2)
  636. # Character 5 name: 40 bits
  637. i,j = j,j+40
  638. outkey["char5name"] = self.newBitfield[i:j]
  639. # Character 5 career: 7 bits
  640. i,j = j,j+7
  641. outkey["char5career"] = int(self.newBitfield[i:j], 2)
  642. # Character 5 order: 3 bits
  643. i,j = j,j+3
  644. outkey["char5ord"] = int(self.newBitfield[i:j], 2)
  645. # Character 5 chaos: 3 bits
  646. i,j = j,j+3
  647. outkey["char5cha"] = int(self.newBitfield[i:j], 2)
  648. # Character 5 body: 3 bits
  649. i,j = j,j+3
  650. outkey["char5bod"] = int(self.newBitfield[i:j], 2)
  651. # Character 5 brain: 3 bits
  652. i,j = j,j+3
  653. outkey["char5bra"] = int(self.newBitfield[i:j], 2)
  654. # Character 5 gadget: 7 bits
  655. i,j = j,j+7
  656. outkey["char5gad"] = int(self.newBitfield[i:j], 2)
  657. # Character 6 name: 40 bits
  658. i,j = j,j+40
  659. outkey["char6name"] = self.newBitfield[i:j]
  660. # Character 6 career: 7 bits
  661. i,j = j,j+7
  662. outkey["char6career"] = int(self.newBitfield[i:j], 2)
  663. # Character 6 order: 3 bits
  664. i,j = j,j+3
  665. outkey["char6ord"] = int(self.newBitfield[i:j], 2)
  666. # Character 6 chaos: 3 bits
  667. i,j = j,j+3
  668. outkey["char6cha"] = int(self.newBitfield[i:j], 2)
  669. # Character 6 body: 3 bits
  670. i,j = j,j+3
  671. outkey["char6bod"] = int(self.newBitfield[i:j], 2)
  672. # Character 6 brain: 3 bits
  673. i,j = j,j+3
  674. outkey["char6bra"] = int(self.newBitfield[i:j], 2)
  675. # Character 6 gadget: 7 bits
  676. i,j = j,j+7
  677. outkey["char6gad"] = int(self.newBitfield[i:j], 2)
  678. self.ship = Ship(Ship.NAME1[outkey["sname1"]], Ship.NAME2[outkey["sname2"]], Ship.GQUAL[outkey["gqual"]], Ship.BQUAL[outkey["bqual"]])
  679. 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)
  680. self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a"
  681. self.characters = []
  682. for q in range(1,7):
  683. 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"]
  684. 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]])
  685. self.characters.append(c)
  686. #return self.newBitfield
  687. def encode_name(self, name):
  688. field = "".join([lpad(bin(Campaign.NAMELETS.index(c.lower()))[2:], 5) for c in name])
  689. return field
  690. def decode_name(self, field):
  691. i,j = 35,40
  692. name = ""
  693. for _ in range(8):
  694. k = int(field[i:j], 2)
  695. if k != 31:
  696. name = Campaign.NAMELETS[k] + name
  697. i,j = i-5, i
  698. name = name[0].upper() + name[1:]
  699. return name
  700. def print_params(self, endc=" ", html=False):
  701. st = ["Order:", "Chaos:", "Brains:", "Body:"]
  702. cst = ", ".join([" ".join(y) for y in list(zip(st, [str(x) for x in self.params.problem["stats"]]))])
  703. if self.params.oops == 1:
  704. oops = "...well, they weren't paying attention, so don't tell them, but they're supposed to "
  705. else:
  706. oops = ""
  707. mission = oops + self.params.mission
  708. # pl = "s" if self.params.problem["isPlural"] else ""
  709. note = self.params.problem["note"]
  710. secnote = ""
  711. if self.params.problem["hasMinion"]:
  712. secnote = "Their minion: " + self.params.secProblem["note"]
  713. lines = [
  714. f"The Kobolds of the {self.ship.fullname}",
  715. f"have been sent out to {self.art} {self.params.loc_desc} {self.params.location}!",
  716. f"in order to {mission}",
  717. f"but they're challenged by {self.params.fullProblem}!",
  718. f"{note} {secnote}",
  719. f"The stats of the {self.params.problem['shortname']}",
  720. f"{cst}"
  721. ]
  722. if self.params.problem["hasMinion"]:
  723. mst = ", ".join([" ".join(y) for y in list(zip(st, [str(x) for x in self.params.secProblem["stats"]]))])
  724. # spl = "s" if self.params.secProblem["isPlural"] else ""
  725. lines.append(f"The stats of the {self.params.secProblem['shortname']}")
  726. lines.append(f"{mst}")
  727. if html:
  728. secnote = ""
  729. if self.params.problem["hasMinion"]:
  730. secnote = "Their minion: " + self.params.secProblem["note"] + "<br>\n"
  731. out = (
  732. f"<div id='theship' class='firstrow'>\n"
  733. f" <span class='head'>The Ship</span>\n"
  734. f" <span id='shipname'>\n"
  735. f" The {self.ship.fullname}!\n"
  736. f" </span>\n"
  737. f" <br>\n"
  738. f" <span id='shipquality1'>\n"
  739. f" It {self.ship.gqual}...\n"
  740. f" </span><br>\n"
  741. f" <span id='shipquality2'>\n"
  742. f" But {self.ship.bqual}!\n"
  743. f" </span>\n"
  744. f"</div>\n"
  745. f"<div id='themission' class='firstrow'>\n"
  746. f" <span class='head'>The Mission</span>\n"
  747. f" <span id='missionloc'>\n"
  748. f" The kobolds have been sent to {self.art} {self.params.loc_desc} {self.params.location}\n"
  749. f" </span><br>\n"
  750. f" <span id='missiontarget'>\n"
  751. f" in order to {mission}!\n"
  752. f" </span>\n"
  753. f"</div>\n<br clear='all'>\n"
  754. f"<div id='theadversary' class='firstrow'>\n"
  755. f" <span class='head'>The Adversary</span>\n"
  756. f" They're challenged by <span id='advname'>{self.params.fullProblem}</span>!\n"
  757. f" <br>\n"
  758. f" <span id='problemnote'>\n"
  759. f" {self.params.problem['note']}<br>\n"
  760. f" {secnote}"
  761. f" </span>\n"
  762. f" <span id='problemstats'>\n"
  763. f" The stats of the {self.params.problem['shortname']}:<br>\n"
  764. f" {cst}\n"
  765. f" </span>\n"
  766. )
  767. if self.params.problem["hasMinion"]:
  768. out += (
  769. f" <br><span id='secprobstats'>\n"
  770. f" The stats of the {self.params.secProblem['shortname']}:<br>\n"
  771. f" {mst}\n"
  772. f" </span>\n"
  773. )
  774. out += f"</div>\n"
  775. print(out)
  776. print(f"<br clear='all'>\n")
  777. else:
  778. print(f"{lines[0]} {lines[1]} {lines[2]} -- {lines[3]}")
  779. print(f"{lines[4]}")
  780. print(f"{lines[5]}: {lines[6]}")
  781. if self.params.problem["hasMinion"]:
  782. print(f"- {lines[7]}: {lines[8]}")
  783. print()
  784. self.ship.print(html=html)
  785. def print_chars(self, html=False):
  786. if html:
  787. print(f"<div id='thekobolds'>\n")
  788. print(f"<span class='head'>The Kobolds</span>\n")
  789. else:
  790. print("The kobolds:")
  791. for k in self.characters:
  792. k.print(html=html)
  793. if html:
  794. print(f"</div>\n<br clear='all'>\n")
  795. def print_password(self, html=False):
  796. if self.masterpassword:
  797. pw = self.masterpassword
  798. else:
  799. pw = self.generate_key()
  800. if html:
  801. out = (
  802. f"<div id='passwordbox'>"
  803. f"<span class='passwordhead'>Permalink to this campaign:</span><br>"
  804. f"<span><a href='http://node.noelle.codes/kobold?pw={pw.replace(' ', '')}'>{pw.replace(' ', '')}</a></span><br><br>"
  805. f"<span class='passwordhead'><a href='http://node.noelle.codes/kobold'>Generate a new random campaign</a></span><br>"
  806. f"</div>"
  807. )
  808. print(out)
  809. print(f"<br clear='all'>\n")
  810. else:
  811. print(f"Password: {pw}")
  812. def decode(self, pwd):
  813. pass
  814. def lpad(s, n, c="0"):
  815. while len(s) < n:
  816. s = c + s
  817. return s
  818. if __name__ == "__main__":
  819. parser = argparse.ArgumentParser()
  820. group = parser.add_mutually_exclusive_group()
  821. group.add_argument("-c", "--campaign", help="print a full campaign block with N kobolds (default 6)", nargs="?", const=6, type=int, metavar="N")
  822. group.add_argument("-k", "--kobolds", help="print N kobolds", type=int, nargs="?", const=1, default=1, metavar="N")
  823. group.add_argument("-n", "--names", help="print N kobolds without stat blocks", nargs="?", const=1, type=int, metavar="N")
  824. group.add_argument("-p", "--params", help="print only the parameters of a campaign", action="store_true")
  825. group.add_argument("-s", "--ship", help="print only the ship name and description", action="store_true")
  826. group.add_argument("-pw", "--password", help="print the campaign defined by the submitted password", type=str, nargs="?", const=1, metavar="PW")
  827. parser.add_argument("--html", help="print in HTML instead of plain text", action="store_true")
  828. args = parser.parse_args()
  829. html = True if args.html else False
  830. if args.password:
  831. cmp = Campaign(fromPW = True, pw=args.password)
  832. cmp.print_params(html=html)
  833. cmp.print_chars(html=html)
  834. cmp.print_password(html=html)
  835. elif args.campaign:
  836. cmp = Campaign(args.campaign)
  837. cmp.print_params(html=html)
  838. cmp.print_chars(html=html)
  839. cmp.print_password(html=html)
  840. elif args.params:
  841. cmp = Campaign(makeChars=False)
  842. cmp.print_params(html=html)
  843. elif args.ship:
  844. ship = Ship()
  845. ship.print(html=html)
  846. elif args.names:
  847. for _ in range(args.names):
  848. c = Character()
  849. c.generate()
  850. c.print_name(html=html)
  851. else:
  852. for _ in range(args.kobolds):
  853. c = Character()
  854. c.generate()
  855. c.print(html=html)