def _get_loot_details(lootable: LootableOnGround) -> List[str]: if isinstance(lootable, ConsumableOnGround): return [CONSUMABLES[lootable.consumable_type].description] if isinstance(lootable, ItemOnGround): # TODO Render suffix lines differently? return [ line.text for line in create_item_description(lootable.item_id) ]
def buy_item_option(item_id: ItemId, cost: int): item_type = item_id.item_type data = get_item_data_by_type(item_type) name_formatter = "{:<25}" buy_prompt = "> " cost_formatter = "[{} gold]" item_name = build_item_name(item_id) icon_sprite = data.icon_sprite description_lines = create_item_description(item_id) return DialogOptionData( buy_prompt + name_formatter.format(item_name) + cost_formatter.format(cost), "buy", SellItemNpcAction(cost, item_id, item_name.lower()), icon_sprite, item_name, ", ".join([line.text for line in description_lines]))
def print_loot(): for level in range(1, 10): consumable_types = get_consumables_with_level(level) item_types = get_items_with_level(level) if not consumable_types and not item_types: continue print("LEVEL " + str(level)) print("- - - - -") for c_type in consumable_types: print("{:<25}".format(c_type.name) + str(CONSUMABLES[c_type].description)) for i_type in item_types: data = get_item_data_by_type(i_type) description_lines = [line.text for line in create_item_description(randomized_item_id(i_type))] print("{:<25}".format(data.base_name) + ", ".join(description_lines)) print("")
def on_inventory_updated(self, item_slots: List[ItemInventorySlot]): for i in range(len(item_slots)): icon = self.inventory_icons[i] slot = item_slots[i] item_id = slot.get_item_id() if not slot.is_empty() else None slot_equipment_category = slot.enforced_equipment_category image = None tooltip = None if item_id: item_type = item_id.item_type data = get_item_data_by_type(item_type) image = self.images_by_ui_sprite[data.icon_sprite] category_name = None if data.item_equipment_category: category_name = ITEM_EQUIPMENT_CATEGORY_NAMES[ data.item_equipment_category] description_lines = create_item_description(item_id) item_name = item_id.name is_rare = bool(item_id.affix_stats) is_unique = data.is_unique tooltip = TooltipGraphics.create_for_item(self.ui_render, item_name, category_name, icon.rect.topleft, description_lines, is_rare=is_rare, is_unique=is_unique) elif slot_equipment_category: image = self.images_by_item_category[slot_equipment_category] category_name = ITEM_EQUIPMENT_CATEGORY_NAMES[ slot_equipment_category] tooltip_details = [ DetailLine("[" + category_name + "]"), DetailLine( "You have nothing equipped. Drag an item here to equip it!" ) ] tooltip = TooltipGraphics(self.ui_render, COLOR_WHITE, "...", tooltip_details, bottom_left=icon.rect.topleft) icon.image = image icon.tooltip = tooltip icon.slot_equipment_category = slot_equipment_category icon.item_id = item_id
def _setup_ui_components(self): icon_space = 5 x_1 = 165 y_2 = 40 self.button_delete_entities = self._create_map_editor_icon( Rect(20, y_2, MAP_EDITOR_UI_ICON_SIZE[0], MAP_EDITOR_UI_ICON_SIZE[1]), 'Q', None, UiIconSprite.MAP_EDITOR_TRASHCAN, 0, None) self.button_delete_decorations = self._create_map_editor_icon( Rect(20 + MAP_EDITOR_UI_ICON_SIZE[0] + icon_space, y_2, MAP_EDITOR_UI_ICON_SIZE[0], MAP_EDITOR_UI_ICON_SIZE[1]), 'Z', None, UiIconSprite.MAP_EDITOR_RECYCLING, 0, None) self.entity_icons_by_type = {} num_icons_per_row = 23 for entity_type in EntityTab: self.entity_icons_by_type[entity_type] = [] for i, entity in enumerate(self._entities_by_type[entity_type]): x = x_1 + (i % num_icons_per_row) * (MAP_EDITOR_UI_ICON_SIZE[0] + icon_space) row_index = (i // num_icons_per_row) y = y_2 + row_index * (MAP_EDITOR_UI_ICON_SIZE[1] + icon_space) if entity.item_id is not None: data = get_item_data(entity.item_id) category_name = None if data.item_equipment_category: category_name = ITEM_EQUIPMENT_CATEGORY_NAMES[data.item_equipment_category] description_lines = create_item_description(entity.item_id) item_name = build_item_name(entity.item_id) is_rare = entity.item_id.suffix_id is not None is_unique = data.is_unique tooltip = TooltipGraphics.create_for_item(self._ui_render, item_name, category_name, (x, y), description_lines, is_rare=is_rare, is_unique=is_unique) elif entity.consumable_type is not None: data = CONSUMABLES[entity.consumable_type] tooltip = TooltipGraphics.create_for_consumable(self._ui_render, data, (x, y)) elif entity.npc_type is not None: data = NON_PLAYER_CHARACTERS[entity.npc_type] tooltip = TooltipGraphics.create_for_npc(self._ui_render, entity.npc_type, data, (x, y)) elif entity.portal_id is not None: tooltip = TooltipGraphics.create_for_portal(self._ui_render, entity.portal_id, (x, y)) elif entity.is_smart_floor_tile: tooltip = TooltipGraphics.create_for_smart_floor_tile(self._ui_render, entity.entity_size, (x, y)) else: tooltip = None icon = self._create_map_editor_icon( Rect(x, y, MAP_EDITOR_UI_ICON_SIZE[0], MAP_EDITOR_UI_ICON_SIZE[1]), '', entity.sprite, None, entity.map_editor_entity_id, tooltip) self.entity_icons_by_type[entity_type].append(icon)
def print_items(): for category in [c for c in ItemEquipmentCategory] + [None]: if category: print(category.name + ":") else: print("PASSIVE:") print("- - - - -") entries: List[Tuple[ItemType, ItemData, Optional[int]]] = [ (i_type, i_data, get_optional_item_level(i_type)) for (i_type, i_data) in get_items_with_category(category) ] entries.sort(key=lambda entry: entry[2] if entry[2] else 9999) for item_type, item_data, item_level in entries: level_text = "level {:<10}".format( item_level) if item_level else " " * 16 item_id = randomized_item_id(item_type) item_name = build_item_name(item_id) print("{:<25}".format(item_name) + level_text + str(create_item_description(item_id))) print("")