Esempio 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
Esempio n. 2
0
#!/usr/bin/python2
import libspellbook
import argparse

parser = argparse.ArgumentParser(description="Generate spellbooks for ACKS wizards")
parser.add_argument("-n","--num",type=int,default=1,help="Number of spellbooks to generate")
parser.add_argument("-l","--level",type=int,default=1,help="Level of mage to generate for")
parser.add_argument("-s","--spells",default="./spells",help="File to draw spells from")
parser.add_argument("-i","--intel", type=int,default=1,help="Intelligence bonus of mage")
parser.add_argument("-e","--excess",action="store_true",help="Allow mages to know spells\
  beyond the limits of their repertoire, as PC mages are wont to do")
args = parser.parse_args()

spells = libspellbook.parseSpells(args.spells)

for i in range(0,args.num):
  known = libspellbook.genSpells(spells, args.level, args.intel, args.excess)
  libspellbook.printSpells(known)
Esempio n. 3
0
                    "--num",
                    type=int,
                    default=1,
                    help="Number of spellbooks to generate")
parser.add_argument("-l",
                    "--level",
                    type=int,
                    default=1,
                    help="Level of mage to generate for")
parser.add_argument("-s",
                    "--spells",
                    default="./spells",
                    help="File to draw spells from")
parser.add_argument("-i",
                    "--intel",
                    type=int,
                    default=1,
                    help="Intelligence bonus of mage")
parser.add_argument("-e",
                    "--excess",
                    action="store_true",
                    help="Allow mages to know spells\
  beyond the limits of their repertoire, as PC mages are wont to do")
args = parser.parse_args()

spells = libspellbook.parseSpells(args.spells)

for i in range(0, args.num):
    known = libspellbook.genSpells(spells, args.level, args.intel, args.excess)
    libspellbook.printSpells(known)
Esempio n. 4
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