def run_generate_settlement(conn, args): '''Runs the settlement item generator.''' # Set up the roller. if args.manual: roller = rollers.ManualDiceRoller() else: roller = rollers.PseudorandomRoller() # Generate items. settlement = (' '.join(args.settlement_type)).lower() result = settlements.generate_settlement_items(conn, settlement, roller) # Print the results. print('Magic items for a ', settlement, ':', sep='') print('-' * 78) print('Base value:', result['base_value'], 'gp') print() if len(result['minor_items']) > 0: print('Minor Magic Items') print('-' * 78) for x in result['minor_items']: item.print_item(x) print('\n') if len(result['medium_items']) > 0: print('Medium Magic Items') print('-' * 78) for x in result['medium_items']: item.print_item(x) print('\n') if len(result['major_items']) > 0: print('Major Magic Items') print('-' * 78) for x in result['major_items']: item.print_item(x)
def run_webgen_internal(params): conn = None result = "Error: unspecified program error" try: # Mode of operation: mode = params['mode'] if mode == 'echo_test': # Echo back the input. result = params elif mode == 'settlement': # Open the database. conn = sqlite.connect('data/data.db') conn.row_factory = sqlite.Row settlement_size = params['size'] result = settlements.generate_settlement_items(conn, settlement_size, rollers.PseudorandomRoller()) elif mode == 'custom': # Open the database. conn = sqlite.connect('data/freq.db') conn.row_factory = sqlite.Row base_value = default_get(params, 'base_value', 0) q_ls_min = default_get(params, 'q_ls_min', '1') q_gt_min = default_get(params, 'q_gt_min', '1') q_ls_med = default_get(params, 'q_ls_med', '1') q_gt_med = default_get(params, 'q_gt_med', '1') q_ls_maj = default_get(params, 'q_ls_maj', '1') q_gt_maj = default_get(params, 'q_gt_maj', '1') result = settlements.generate_custom(conn, base_value, q_ls_min, q_gt_min, q_ls_med, q_gt_med, q_ls_maj, q_gt_maj) elif mode == 'individual': # Open the database. conn = sqlite.connect('data/data.db') conn.row_factory = sqlite.Row strength = params['strength'] kind = params['type'] result = item.generate_item(conn, strength + ' ' + kind, rollers.PseudorandomRoller(), None) # In this case, item is an Item object. result = str(result) elif mode == 'hoard_budget': # Open the database. conn = sqlite.connect('data/data.db') conn.row_factory = sqlite.Row if params['type'] == 'custom': result = hoard.calculate_budget_custom(conn, params['custom_gp']) elif params['type'] == 'encounter': apl = params['apl'] rate = params['rate'] magnitude = params['magnitude'] result = hoard.calculate_budget_encounter(conn, apl, rate, magnitude) elif params['type'] == 'npc_gear': npc_level = params['npc_level'] is_heroic = default_get(params, 'heroic', "false") == "true" result = hoard.calculate_budget_npc_gear(conn, npc_level, is_heroic) else: result = {} elif mode == 'hoard_types': # Open the database. conn = sqlite.connect('data/data.db') conn.row_factory = sqlite.Row types = '' if default_get(params, 'type_a', 'false') == 'true': types += 'a' if default_get(params, 'type_b', 'false') == 'true': types += 'b' if default_get(params, 'type_c', 'false') == 'true': types += 'c' if default_get(params, 'type_d', 'false') == 'true': types += 'd' if default_get(params, 'type_e', 'false') == 'true': types += 'e' if default_get(params, 'type_f', 'false') == 'true': types += 'f' if default_get(params, 'type_g', 'false') == 'true': types += 'g' if default_get(params, 'type_h', 'false') == 'true': types += 'h' if default_get(params, 'type_i', 'false') == 'true': types += 'i' result = hoard.get_treasure_list(conn, types) elif mode == 'hoard_generate': # Open the database. conn = sqlite.connect('data/data.db') conn.row_factory = sqlite.Row # This one is so complex, it only operates via a map. It'll ignore # the transmission-related keys in the dict, e.g. "mode". So we # can simple pass the param dict to the function. result = hoard.generate_treasure(conn, params, rollers.PseudorandomRoller(), None) else: result = "Error: invalid mode value" except sqlite.Error as e: if DEBUG: traceback.print_exc(file=sys.stderr) except: if DEBUG: traceback.print_exc(file=sys.stderr) finally: if conn: conn.close() return result