Draco18s

AI Dungeon Random Species Replacer

Nov 13th, 2020 (edited)
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***
  2.  *
  3.  *  Author: Draco18s
  4.  *
  5.  *  call this from Output Modifier
  6.  *  const regex = /(^| )(human|el|dwar|svelk)[fve]*s*(?!\w)/gi;
  7.  *  if(modifiedText.match(regex)) {
  8.  *    modifiedText = modifiedText.replace(regex,"$1"+getRandomSpecies());
  9.  *  }
  10.  *  
  11.  *  Altering the regex to pick up additional unwanted races should be pretty straight forward.
  12.  *  Adjusting the species list is likewise "add, remove, or comment" as desired. They're grouped
  13.  *  by rough category (so you could disable all canines quickly) such that any given group has
  14.  *  same odds of appearing as any other group at the same level (so "a mammal" and "a bird" are
  15.  *  just as likely as each other, but "magpie" will be about half as common as "any rodent"
  16.  *  (15 total birds, vs 8 mammal groups).
  17.  *
  18.  *  No attempt is made to massage the sentence grammar ("a owl").
  19. ***/
  20.  
  21. const species = {
  22.   mammal: {
  23.     feline: [
  24.       "feline",
  25.       "lion",
  26.       "panther",
  27.       "tiger",
  28.       "cheetah",
  29.       "cougar",
  30.       "jaguar",
  31.     ],
  32.     canine: [
  33.       "canine",
  34.       "wolf",
  35.       "fox",
  36.       "hyena",
  37.       "jackal",
  38.       "coyote",
  39.       "african wild dog",
  40.     ],
  41.     equine: [
  42.       "horse",
  43.       "zebra",
  44.     ],
  45.     ungulate: [
  46.       "deer",
  47.       "cow",
  48.       "antelope",
  49.       "boar",
  50.       "goat",
  51.       "sheep",
  52.       "reindeer",
  53.       "giraffe",
  54.     ],
  55.     ursine: [
  56.       "brown bear",
  57.       "black bear",
  58.       "polar bear",
  59.       "sun bear",
  60.     ],
  61.     mustelide: [
  62.       "otter",
  63.       "ferret",
  64.       "marten",
  65.       "mink",
  66.       "skunk",
  67.     ],
  68.     rodent: [
  69.       "bat",
  70.       "mouse",
  71.       "rat",
  72.       "beaver",
  73.     ],
  74.     other: [
  75.       "kangaroo",
  76.       "bunny",
  77.       "red panda",
  78.       "raccoon",
  79.       "elephant",
  80.       "rhinoceros",
  81.       "civet",
  82.       "sloth",
  83.       "armadillo",
  84.       "anteater",
  85.       "pangolin",
  86.     ]
  87.   },
  88.   bird: [
  89.     "magpie",
  90.     "hoatzin",
  91.     "raven",
  92.     "jay",
  93.     "eagle",
  94.     "hawk",
  95.     "secretary bird",
  96.     "rufous kingfisher",
  97.     "plover",
  98.     "owl",
  99.     "robin",
  100.     "kingfisher",
  101.     "sunbittern",
  102.     "falcon",
  103.     "gannet",
  104.   ],
  105.   reptile: {
  106.     modern: [
  107.       "kobold",
  108.       "lizardman",
  109.       "gator",
  110.       "crocodile",
  111.       "iguanna",
  112.       "snake",
  113.       "komodo",
  114.     ],
  115.     dinosaur: [
  116.       "theropod",
  117.       "sauropod",
  118.       "genasauria",
  119.     ]
  120.   },
  121.   mythic: [
  122.     "gryphon",
  123.     "hippogriff",
  124.     "dragon",
  125.     "eastern dragon",
  126.     "wyvern",
  127.     "phoenix",
  128.   ]
  129. }
  130. function getRandomSpecies() {
  131.   var chunk = species;
  132.   var max = chunk.length;
  133.   while(!Array.isArray(chunk)) {
  134.     var subchunk = Object.getOwnPropertyNames(chunk);
  135.     max = subchunk.length;
  136.     var r = Math.floor(Math.random()*max);
  137.     chunk = chunk[subchunk[r]];
  138.   }
  139.   var max = chunk.length;
  140.   var rr = Math.floor(Math.random()*max);
  141.   chunk = chunk[rr];
  142.   return chunk;
  143. }
Add Comment
Please, Sign In to add comment