Ejemplo n.º 1
0
def genHenches(numHenches, level, classes, market, al, spells, names, profs,gear,notabs=True):
  outlist = []
  for k in range(0,numHenches):
    stats=[]
    for i in range(0,6):
      acc = 0
      for j in range(0,3):
        acc+= random.randint(1,6)
      stats.append(acc)

    prefix = ""
    if market != 10:
      prefix = "\t"
    ostring = str(stats)

    if classes != []:
      cweights = []
      for c in classes:
        weight = min([f(stats) for f in c[2]])
        cweights.append((c[5] * weight, c))
      cweights = filter((lambda t: t[0] > 0),cweights)
      poss = []
      for (w,c) in cweights:
        for i in range(0,int(math.ceil(w))):
          poss.append(c)
      if len(poss) == 0:
        # if no possibilities, we default to first thing in list
        # generally fighter
        poss.append(classes[0])
      if level == 0:
        poss = [("Normal Man", 4, [], "", 0.5, 1.0)]
      ind = random.randint(0,len(poss)-1)
      hd = int(poss[ind][1])
      hp = max(random.randint(1,hd)+mod(stats[4]),1)
      if level > 1:
        for i in range(0,level-1):
          hp += max(random.randint(1,hd)+mod(stats[4]),1) 
      ostring += ", L" + str(level) + " " + poss[ind][0] + ", HP: " + str(hp)

    if names != []:
      g = float(poss[ind][4])
      g = 'M' if random.random() >= g else 'F'
      if g == 'F': ostring = ostring.replace('Man','Woman')
      ostring = names[g][random.randint(0,len(names[g])-1)] +" (" + g +"): " + ostring
      
    ostring = prefix + ostring

    if al:
      al = alignments[random.randint(1,6)-1]
      ostring += ", AL: " + al

    if profs != []:
      # build weightmap for this stat set
      weightmap = {}
      for p in profs:
        weight = -1 * 8**2 * len(p[2])
        if len(p[2]) == 0:
          weight = 3
        for c in p[2]:
          weight += (stats[c-1]) **2
        if weight > 0:
          weightmap[(p[0], p[1])] = weight
      weightlist = []
      for p in profs:
        t = (p[0], p[1])
        if t in weightmap.keys():
          for i in range(0, weightmap[t]):
            weightlist.append(t)
      profmap = {}
      bonusprofs = max(0, mod(stats[1]))
      if level == 0:
        # L0s get 4 unique profs plus possible dupes from int
        # have to account for the possibility of some poor bastard who quals for nothing
        while len(profmap.keys()) < min(4, len(weightmap.keys())):
          p = weightlist[random.randint(0, len(weightlist)-1)]
          profmap[p] = 1
      else:
        profmap[("Adventuring", 1)] = 1
        bonusprofs += (level-1)/4 +1
      for i in range(0, bonusprofs):
        done = False
        # 50% chance that we try to increase a prof we already have
        if random.random() < 0.5:
          profshave = profmap.keys()
          random.shuffle(profshave)
          for p in profshave:
            if profmap[p] < p[1]:
              profmap[p] += 1
              done = True
              break
        if not done:
          p = weightlist[random.randint(0, len(weightlist)-1)]
          while p[1] > 0 and p in profmap.keys() and profmap[p] >= p[1]:
            p = weightlist[random.randint(0, len(weightlist)-1)]
          if not p[0] in profmap.keys():
            profmap[p] = 1
          else:
            profmap[p] += 1
      profstrs = [ (p[0], profmap[p]) for p in profmap.keys()]
      acc = []
      for p in profstrs:
        if p[1] > 1:
          acc.append(p[0] + " " + str(p[1]))
        else:
          acc.append(p[0])
          
      profstr = ', '.join(sorted(acc))
      ostring += "\n\t" + prefix + "GenProfs: " + profstr

    if spells != [] and poss[ind][0].lower() in casters:
      mult = casters[poss[ind][0].lower()]
      ecl = int(math.floor(level * mult))
      if mult == 0.67 and level == 1:
        ecl = 1
      if ecl > 0:
        slist = libspellbook.genSpells(spells, ecl, mod(stats[1]), False)
        ostring += "\n\t" + prefix+"Spells known: "
        for i in range(0,len(slist)):
          ostring += "\t" +prefix + str(i+1) + ": " + ", ".join(slist[i])

    if level > 0 and gear:
      items = []
      for t in poss[ind][3]:
        if random.randint(1,20) <= level:
          try:
            items.append(tables.evaltable(itemtable[t]))
          except KeyError:
            print "No items for you on bad key: " + itemtable[t]
            gear = False
      istr = ", ".join(items)
      if istr != "":
        ostring += "\n\t" + prefix + "Gear: " + istr
    if notabs:
      ostring = re.sub('\t*','',ostring)
      ostring += '\n'
    outlist.append(ostring)
  return outlist
Ejemplo n.º 2
0
                    help="Generate full lair/encounter descriptions")
parser.add_argument("-n",
                    "--encounter",
                    action='store_true',
                    help="Generate single encounter per hex rather than lairs")
args = parser.parse_args()

# load the monster file
tables.loadtables(args.monsters)
# load the terrain description
tables.loadtables(args.terrainfile)
# load the treasure files
tables.loadtables(args.treasure)

encTypeSuffix = "Enc" if args.encounter else "Lair"

# and now we generate the lairs in the hexes
for r in range(0, args.rows):
    for c in range(0, args.cols):
        if not args.encounter: print "Hex (" + str(r) + ", " + str(c) + "):"
        numlairs = 1 if args.encounter else dice.roll(lairdice[args.terrain])
        for i in range(0, numlairs):
            monster = tables.evaltable(args.terrain + "Enc")
            print monster
            monstertable = ''.join(
                monster.rstrip().lstrip().split(" ")) + encTypeSuffix
            if args.full and monstertable in tables.tabledice.keys():
                lairout = tables.evaltable(monstertable)
                print "\t" + lairout + "\n"
        print ""
Ejemplo n.º 3
0
#!/usr/bin/python2

import re
import random
import argparse
import tables

parser = argparse.ArgumentParser(description="Generate treasure")
parser.add_argument("-t","--tables",default="./treasuretables",help=\
  "File containing list of treasure tables")
parser.add_argument("-n", "--num",type=int, default=1,help=\
  "Number to generate")
parser.add_argument("typelist",metavar='H',nargs='+',help=\
  "List of hoard types and tables to roll")
args = parser.parse_args()

tables.loadtables(args.tables)
for t in args.typelist:
  for i in range(0,args.num):
    print t + ": " + tables.evaltable(t)
Ejemplo n.º 4
0
parser.add_argument("-t","--terrain", default="Swamp",help="Terrain type to stock for")
parser.add_argument("-f","--terrainfile",default="./enctables",help="Name of terrainfile to stock from")
parser.add_argument("-m","--monsters",default="./monstertables",help="File of monsters to reference")
parser.add_argument("-e","--treasure", default="./treasuretables",help="File of treasure type tables")
parser.add_argument("-u","--full", action='store_true', help="Generate full lair/encounter descriptions")
parser.add_argument("-n","--encounter", action='store_true', help="Generate single encounter per hex rather than lairs")
args = parser.parse_args()

# load the monster file
tables.loadtables(args.monsters)
# load the terrain description
tables.loadtables(args.terrainfile)
# load the treasure files
tables.loadtables(args.treasure)

encTypeSuffix = "Enc" if args.encounter else "Lair"

# and now we generate the lairs in the hexes
for r in range(0,args.rows):
  for c in range(0,args.cols):
    if not args.encounter: print "Hex (" + str(r) + ", " + str(c) + "):"
    numlairs = 1 if args.encounter else dice.roll(lairdice[args.terrain])
    for i in range(0, numlairs):
      monster = tables.evaltable(args.terrain + "Enc")
      print monster
      monstertable = ''.join(monster.rstrip().lstrip().split(" ")) + encTypeSuffix
      if args.full and monstertable in tables.tabledice.keys():
        lairout = tables.evaltable(monstertable)
        print "\t" + lairout+"\n"
    print ""
Ejemplo n.º 5
0
#!/usr/bin/python2

import re
import random
import argparse
import tables

parser = argparse.ArgumentParser(description="Generate treasure")
parser.add_argument("-t","--tables",default="./treasuretables",help=\
  "File containing list of treasure tables")
parser.add_argument("-n", "--num",type=int, default=1,help=\
  "Number to generate")
parser.add_argument("typelist",metavar='H',nargs='+',help=\
  "List of hoard types and tables to roll")
args = parser.parse_args()

tables.loadtables(args.tables)
for t in args.typelist:
    for i in range(0, args.num):
        print t + ": " + tables.evaltable(t)
Ejemplo n.º 6
0
def genHenches(numHenches,
               level,
               classes,
               market,
               al,
               spells,
               names,
               profs,
               gear,
               notabs=True):
    outlist = []
    for k in range(0, numHenches):
        stats = []
        for i in range(0, 6):
            acc = 0
            for j in range(0, 3):
                acc += random.randint(1, 6)
            stats.append(acc)

        prefix = ""
        if market != 10:
            prefix = "\t"
        ostring = str(stats)

        if classes != []:
            cweights = []
            for c in classes:
                weight = min([f(stats) for f in c[2]])
                cweights.append((c[5] * weight, c))
            cweights = filter((lambda t: t[0] > 0), cweights)
            poss = []
            for (w, c) in cweights:
                for i in range(0, int(math.ceil(w))):
                    poss.append(c)
            if len(poss) == 0:
                # if no possibilities, we default to first thing in list
                # generally fighter
                poss.append(classes[0])
            if level == 0:
                poss = [("Normal Man", 4, [], "", 0.5, 1.0)]
            ind = random.randint(0, len(poss) - 1)
            hd = int(poss[ind][1])
            hp = max(random.randint(1, hd) + mod(stats[4]), 1)
            if level > 1:
                for i in range(0, level - 1):
                    hp += max(random.randint(1, hd) + mod(stats[4]), 1)
            ostring += ", L" + str(
                level) + " " + poss[ind][0] + ", HP: " + str(hp)

        if names != []:
            g = float(poss[ind][4])
            g = 'M' if random.random() >= g else 'F'
            if g == 'F': ostring = ostring.replace('Man', 'Woman')
            ostring = names[g][random.randint(
                0,
                len(names[g]) - 1)] + " (" + g + "): " + ostring

        ostring = prefix + ostring

        if al:
            al = alignments[random.randint(1, 6) - 1]
            ostring += ", AL: " + al

        if profs != []:
            # build weightmap for this stat set
            weightmap = {}
            for p in profs:
                weight = -1 * 8**2 * len(p[2])
                if len(p[2]) == 0:
                    weight = 3
                for c in p[2]:
                    weight += (stats[c - 1])**2
                if weight > 0:
                    weightmap[(p[0], p[1])] = weight
            weightlist = []
            for p in profs:
                t = (p[0], p[1])
                if t in weightmap.keys():
                    for i in range(0, weightmap[t]):
                        weightlist.append(t)
            profmap = {}
            bonusprofs = max(0, mod(stats[1]))
            if level == 0:
                # L0s get 4 unique profs plus possible dupes from int
                # have to account for the possibility of some poor bastard who quals for nothing
                while len(profmap.keys()) < min(4, len(weightmap.keys())):
                    p = weightlist[random.randint(0, len(weightlist) - 1)]
                    profmap[p] = 1
            else:
                profmap[("Adventuring", 1)] = 1
                bonusprofs += (level - 1) / 4 + 1
            for i in range(0, bonusprofs):
                done = False
                # 50% chance that we try to increase a prof we already have
                if random.random() < 0.5:
                    profshave = profmap.keys()
                    random.shuffle(profshave)
                    for p in profshave:
                        if profmap[p] < p[1]:
                            profmap[p] += 1
                            done = True
                            break
                if not done:
                    p = weightlist[random.randint(0, len(weightlist) - 1)]
                    while p[1] > 0 and p in profmap.keys(
                    ) and profmap[p] >= p[1]:
                        p = weightlist[random.randint(0, len(weightlist) - 1)]
                    if not p[0] in profmap.keys():
                        profmap[p] = 1
                    else:
                        profmap[p] += 1
            profstrs = [(p[0], profmap[p]) for p in profmap.keys()]
            acc = []
            for p in profstrs:
                if p[1] > 1:
                    acc.append(p[0] + " " + str(p[1]))
                else:
                    acc.append(p[0])

            profstr = ', '.join(sorted(acc))
            ostring += "\n\t" + prefix + "GenProfs: " + profstr

        if spells != [] and poss[ind][0].lower() in casters:
            mult = casters[poss[ind][0].lower()]
            ecl = int(math.floor(level * mult))
            if mult == 0.67 and level == 1:
                ecl = 1
            if ecl > 0:
                slist = libspellbook.genSpells(spells, ecl, mod(stats[1]),
                                               False)
                ostring += "\n\t" + prefix + "Spells known: "
                for i in range(0, len(slist)):
                    ostring += "\t" + prefix + str(i + 1) + ": " + ", ".join(
                        slist[i])

        if level > 0 and gear:
            items = []
            for t in poss[ind][3]:
                if random.randint(1, 20) <= level:
                    try:
                        items.append(tables.evaltable(itemtable[t]))
                    except KeyError:
                        print "No items for you on bad key: " + itemtable[t]
                        gear = False
            istr = ", ".join(items)
            if istr != "":
                ostring += "\n\t" + prefix + "Gear: " + istr
        if notabs:
            ostring = re.sub('\t*', '', ostring)
            ostring += '\n'
        outlist.append(ostring)
    return outlist