def choose_loot_table(branch): import dungeon b = dungeon.branches[branch] if b.get('loot') is None: return None else: return main.random_choice(b['loot'])
def item_from_table_ex(loot_table, loot_level=1): if loot_table is None or loot_table not in table: log.warn("loot", "Couldn't find loot table {}", loot_table) return None loot_table = table[loot_table] chances = {k: v.get('weight', 10) for k, v in loot_table.items()} item_id = main.random_choice(chances) choice = loot_table[item_id] import items prototype = items.table()[item_id] material = choice.get('material', None) quality = choice.get('quality', None) if prototype['category'] == 'weapon': if material is None: material = choice.get('material', choose_weapon_material(loot_level)) if quality is None: quality = choice.get('quality', choose_quality(loot_level)) if prototype['category'] == 'armor': if material is None: material = choice.get('material', choose_armor_material(loot_level)) if quality is None: quality = choice.get('quality', choose_quality(loot_level)) if quality is None: quality = '' return main.create_item(item_id, material, quality)
def check_special_drop(): global elixir_life_ticker, elixir_stat_ticker, scroll_forge_ticker elixir_stat_ticker += 1 scroll_forge_ticker += 1 elixir_life_ticker += 1 if main.roll_dice('1d850') <= elixir_life_ticker: elixir_life_ticker = 0 return 'elixir_life' elif main.roll_dice('1d300') <= elixir_stat_ticker: elixir_stat_ticker = 0 return main.random_choice(table['elixirs_0']) elif main.roll_dice('1d200') <= scroll_forge_ticker: scroll_forge_ticker = 0 return 'scroll_forge' else: return None
def item_from_table(branch, loot_table=None): if loot_table is None: loot_table = choose_loot_table(branch) if loot_table is None: return None # fall back to lower level table if higher level isn't available (TODO: Removeme) if not loot_table in table: split = loot_table.split('_') i = int(split[1]) - 1 while i >= 0: lower = split[0] + '_' + str(i) if lower in table: loot_table = lower break i -= 1 if loot_table not in table: return None loot_level = int(loot_table.split('_')[1]) category = loot_table.split('_')[0] while main.roll_dice('1d20') == 20: loot_level += 1 #oh lawdy tmp = category + '_' + str(loot_level) if not tmp in table.keys(): loot_level -= 1 break loot_table = category + '_' + str(loot_level) item_id = main.random_choice(table[loot_table]) if item_id in table.keys(): return item_from_table(branch, loot_table=item_id) material = None quality = '' if category == 'weapon': material = choose_weapon_material(loot_level) quality = choose_quality(loot_level) if category == 'armor': quality = choose_quality(loot_level) material = choose_armor_material(loot_level) return main.create_item(item_id, material, quality)
def summon_demon(actor, data): choice = main.random_choice(data['summons']) actor.fighter.take_damage(100000) main.spawn_monster(choice, actor.x, actor.y)