def do_encounter(self, string): npcs = encounter.parse(string) for group in npcs: for i in range(group[1]): entity = self.load_json(group[0]) entity["key"] = self.get_next_id() entity["hp"] = roll.parse(entity["hp"]) entity["initiative"] = roll.parse(entity["DEX"]) self.active_entities["encounter"].append(entity) self.do_status("")
def generate_name(race): race = race.lower() if race == "half-elf": race = "elf" if roll.parse("d2") == 1 else "human" elif "orc" in race: race = "orc" if roll.parse("d2") == 1 else "human" elif race == "tiefling" and roll.parse("d2") == 2: race = "human" if roll.parse("d4") < 4: return names.generate_name(race) + " " + names.generate_name(race) return names.generate_name(race)
def do_treasure(self, string): num, cr = string.split() amount = 0 denom = "gp" cr = int(cr) num = int(num) if cr == 0: for i in range(num): amount += roll.parse("1d10") denom = "cp" elif cr < 5: result = roll.parse("d100") for i in range(num): if result < 31: amount += roll.parse("5d6") denom = "cp" elif result < 61: amount += roll.parse("4d6") denom = "sp" elif result < 71: amount += roll.parse("3d6")*10 denom = "sp" elif result < 96: amount += roll.parse("3d6") denom = "gp" else: amount += roll.parse("1d6")*10 denom = "gp" print "%i %s"%(amount, denom)
def parse(string): args = string.split(" and ") npcs = [] for group in args: parts = group.split(" ") name = "creatures/" + parts[-1] number = roll.parse(parts[0]) if len(parts) > 1 else 1 if name[-1] is 's': name = name[:-1] npcs.append((name, number)) return npcs
def generate_npc(string=""): npc = NPC() law = roll.parse("d3") if law == 1: npc.law_alignment = LAWFUL else: npc.law_alignment = CHAOTIC if law == 2 else NEUTRAL moral = roll.parse("d3") if moral == 1: npc.moral_alignment = GOOD else: npc.moral_alignment = EVIL if moral == 2 else NEUTRAL npc.sex = roll.parse("d2") race = roll.parse("d20") if race < 15: npc.race = "Human" elif race < 17: npc.race = "Dwarf" elif race == 17: npc.race = "Halfling" elif race == 18: npc.race = "Gnome" elif race == 19: npc.race = "Elf" else: race = roll.parse("d10") if race < 7: npc.race = "Half-Elf" elif race < 9: npc.race = "Half-Orc" elif race == 9: npc.race = "Dragonborn" else: npc.race = "Tiefling" npc.name = generate_name(npc.race) npc.trade = generate_trade() npc.notes = generate_notes(npc.moral_alignment, npc.law_alignment) return npc
def do_roll(self, string): _,_,_,_, result = roll.parse(string, value_only=False) print result