def generate_people(pc, npc, town_name, dump_json=False, to_file=True): global characters, positions full_town = {} if dump_json: full_town = json.load(open(town_name + '.town.json', 'r')) for k in range(len(characters)): write_npc(characters[k], positions[k]) full_town[positions[k]] = characters[k] for p in pc: person = create_person(create_variance()) write_people(person, p) full_town[p] = person for p in npc: person = PC.PC() write_npc(person, p) full_town[p] = person if dump_json: try: json.dump(full_town, open(town_name + ".town.json", 'w'), indent=4, sort_keys=True, default=lambda x: x.__dict__) except Exception as e: raise e print("Writing the town ", town_name) if to_file: write_html(town_name) return bs(townHTML, 'html5lib').prettify()
def create_person(pop): if pop is None: pop = create_variance() race = choice(list(pop.keys()), 1, p=list(pop.values()))[0] gender = choice(['Male', 'Female'], p=[0.5, 0.5]) orientation = choice( ['Male', 'Female'], p=[0.042, 0.958] if gender == 'male' else [0.958, 0.042]) name = ng.name_parser(race, gender) age = int(randint(ages[race][0], ages[race][1])) face = appearance['Face'][randint(len(appearance['Face']))] hair = appearance['Hair'][randint(len(appearance['Hair']))] eyes = appearance['Eyes'][randint(len(appearance['Eyes']))] body = appearance['Body'][randint(len(appearance['Body']))] appear = body + ' and looks ' + face.lower() + ' with ' + hair.lower( ) + ' hair and ' + eyes.lower() + ' eyes. ' back = 'I\'m a ' + gender + ' ' + race + ', from ' back += back_location[randint(len(back_location))] + ' who ' back += back_story[randint(len(back_story))] trait = [] demenor = randint(3) if demenor == 2: trait.append(positive_traits[randint(len(positive_traits))]) trait.append(positive_traits[randint(len(positive_traits))]) elif demenor == 1: trait.append(neutral_traits[randint(len(neutral_traits))]) trait.append(neutral_traits[randint(len(neutral_traits))]) else: trait.append(negative_traits[randint(len(negative_traits))]) trait.append(negative_traits[randint(len(negative_traits))]) story = [ back, ] return Character(name, race, gender, age, appear, trait, story, orientation)
def generate_shops(w, a, p, e, en, b, t, j, f, g, br, gu, v, qu, name='', dump_json=False): """ [# of Stores, Rarity Low, Rarity High, Quan High, Quan Low] """ global characters, positions, townHTML from names import TownNamer town_name = str(TownNamer()) if name == '' else name townHTML += "<h1>" + town_name + "</h1><p>Description</p>" if sum([ w[0], a[0], p[0], e[0], en[0], b[0], t[0], j[0], f[0], g[0], br[0], gu[0] ]) > 0: townHTML += """<h2 class="text-lg bold center">Shops</h2>""" full_town = {} i = 0 for _ in range(w[0]): store = create_weapon_shop(create_person(create_variance()), [w[1], w[2]], randint(w[3], w[4]), inflate=w[6]) write_store(store, additional=w[5]) full_town[i] = store.to_dict() i += 1 for _ in range(a[0]): store = create_armor_shop(create_person(create_variance()), [a[1], a[2]], randint(a[3], a[4]), inflate=a[6]) write_store(store, additional=a[5]) full_town[i] = store.to_dict() i += 1 for _ in range(p[0]): store = create_potion_shop(create_person(create_variance()), [p[1], p[2]], randint(p[3], p[4]), inflate=p[5]) write_store(store) full_town[i] = store.to_dict() i += 1 for _ in range(e[0]): store = create_enchantment_shop(create_person(create_variance()), [e[1], e[2]], randint(e[3], e[4]), inflate=e[5]) write_store(store) full_town[i] = store.to_dict() i += 1 for _ in range(en[0]): store = create_enchanter_shop(create_person(create_variance()), [en[1], en[2]], randint(en[3], en[4]), inflate=en[5]) write_store(store) full_town[i] = store.to_dict() i += 1 for _ in range(b[0]): store = create_book_shop(create_person(create_variance()), choice(Books.Genres, randint(len(Books.Genres)), replace=False), randint(b[1], b[2]), inflate=b[3]) write_store(store, False) full_town[i] = store.to_dict() i += 1 for _ in range(t[0]): store = create_tavern(create_person(create_variance()), t[1], randint(t[2], t[3]), inflate=t[4]) write_store(store, False) full_town[i] = store.__dict__ i += 1 for _ in range(j[0]): store = create_jewel_shop(create_person(create_variance()), [j[1], j[2]], randint(j[3], j[4]), inflate=j[5]) write_store(store) full_town[i] = store.to_dict() i += 1 for _ in range(f[0]): store = create_restaurant(create_person(create_variance()), randint(f[1], f[2]), inflate=f[3]) write_store(store) full_town[i] = store.__dict__ i += 1 for _ in range(g[0]): store = create_general_store(create_person(create_variance()), [g[1], g[2]], randint(g[3], g[4]), g[5], inflate=g[6]) write_store(store) full_town[i] = store.to_dict() i += 1 for _ in range(br[0]): store = create_brothel(create_person(create_variance()), randint(br[1], br[2]), inflate=br[3]) write_store(store) full_town[i] = store.to_dict() i += 1 for _ in range(gu[0]): store = create_gunsmith(create_person(create_variance()), [gu[1], gu[2]], randint(gu[3], gu[4]), inflate=gu[6]) write_store(store, additional=gu[5]) full_town[i] = store.to_dict() i += 1 for _ in range(v[0]): store = create_variety_shop(create_person(create_variance()), randint(v[1], v[2]), inflate=v[3]) write_store(store) full_town[i] = store.to_dict() i += 1 for _ in range(qu[0]): q = quests.QuestBoard(qu[1], qu[2], qu[3], town_name) characters = q.Members positions = q.Positions townHTML += str(q) full_town[i] = q.__dict__ i += 1 # Dump the class information into a json file if dump_json: json.dump(full_town, open(town_name + ".town.json", 'w'), indent=4, sort_keys=True, default=lambda x: x.__dict__) return town_name
sort_keys=True, default=lambda x: x.__dict__) except Exception as e: raise e print("Writing the town ", town_name) if to_file: write_html(town_name) return bs(townHTML, 'html5lib').prettify() if __name__ == '__main__': townHTML += """<h2 class="text-lg bold center">Shops</h2>""" for _ in range(4): write_store( create_weapon_shop(create_person(create_variance()), [0, 2], randint(5, 15), inflate=4)) write_store( create_armor_shop(create_person(create_variance()), [0, 2], randint(5, 15), inflate=4)) write_store( create_potion_shop(create_person(create_variance()), [0, 9], randint(5, 15), inflate=4)) write_store( create_enchantment_shop(create_person(create_variance()), [0, 9],