Module: Natural20::InventoryUI
- Includes:
- Weapons
- Included in:
- CommandlineUI, CharacterBuilder
- Defined in:
- lib/natural_20/cli/inventory_ui.rb
Instance Method Summary collapse
-
#character_sheet(entity) ⇒ Object
Displays the character sheet of the specified entity.
- #how_many?(item_inventory_choice) ⇒ Boolean
- #inventory_ui(entity) ⇒ Object
Methods included from Weapons
#compute_advantages_and_disadvantages, #damage_modifier, #target_advantage_condition
Instance Method Details
#character_sheet(entity) ⇒ Object
Displays the character sheet of the specified entity
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/natural_20/cli/inventory_ui.rb', line 6 def character_sheet(entity) puts t('character_sheet.name', name: entity.name) puts t('character_sheet.level', level: entity.level) puts t('character_sheet.class', name: entity.class_properties.keys.join(',')) puts ' str dex con int wis cha' puts ' ---- ---- ---- ---- ---- ---- ' puts "|#{entity.all_ability_scores.map { |s| " #{s} " }.join('||')}|" puts "|#{entity.all_ability_mods.map { |s| " #{s.negative? ? s : "+#{s}"} " }.join('||')}|" puts ' ---- ---- ---- ---- ---- ----' puts t('character_sheet.race', race: entity.race.humanize) puts t('character_sheet.subrace', race: entity.subrace.to_s.humanize) if entity.subrace puts t('character_sheet.hp', current: entity.hp, max: entity.max_hp) puts t('character_sheet.ac', ac: entity.armor_class) puts t('character_sheet.speed', speed: entity.speed) puts t('character_sheet.proficiency_bonus', bonus: entity.proficiency_bonus) puts t('character_sheet.spell_attack', spell_attack: entity.spell_attack_modifier) if entity.has_spells? puts t('character_sheet.languages') entity.languages.each do |lang| puts " #{t("language.#{lang}")}" end puts t('character_sheet.skills') Natural20::Entity::ALL_SKILLS.each do |skill| bonus_mod = entity.send("#{skill}_mod") prefix = entity.proficient?(skill) ? '*' : ' ' puts " #{t('character_sheet.skill_mod', prefix: prefix, skill: skill.to_s.ljust(20, ' '), bonus: bonus_mod.negative? ? bonus_mod : "+#{bonus_mod}")}" end unless entity.expertise.blank? puts t('character_sheet.expertise') entity.expertise.each do |prof| puts " #{prof.humanize}" end end end |
#how_many?(item_inventory_choice) ⇒ Boolean
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/natural_20/cli/inventory_ui.rb', line 125 def how_many?(item_inventory_choice) if item_inventory_choice.qty > 1 item_count = item_inventory_choice.qty m = item_inventory_choice item_label = t("object.#{m.label}", default: m.label) count = prompt.ask(t('inventory.how_many', item_label: item_label, item_count: item_count), default: item_count) do |q| q.in "1-#{item_count}" q.[:range?] = '%{value} out of expected range %{in}' end count.to_i else 1 end end |
#inventory_ui(entity) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/natural_20/cli/inventory_ui.rb', line 42 def inventory_ui(entity) begin character_sheet(entity) item_inventory_choice = prompt.select( t('character_sheet.inventory', weight: entity.inventory_weight, carry_capacity: entity.carry_capacity), per_page: 20 ) do || entity.equipped_items.each do |m| proficient_str = '' if m.subtype == 'weapon' && !entity.proficient_with_weapon?(m) proficient_str = '(not proficient)'.colorize(:red) end proficient_str = '(not proficient)'.colorize(:red) if %w[armor shield].include?(m.type) && !entity.proficient_with_armor?(m.name) .choice "#{m.label} (equipped) #{proficient_str}", m end entity.inventory.each do |m| .choice "#{m.label} x #{m.qty}", m end .choice 'Back', :back end return nil if item_inventory_choice == :back weapon_details = session.load_weapon(item_inventory_choice.name) if weapon_details puts ' ' puts '-------' puts (weapon_details[:label] || weapon_details[:name]).colorize(:blue) puts "Damage Stats: to Hit +#{entity.attack_roll_mod(weapon_details)}. #{damage_modifier(entity, weapon_details)} #{weapon_details[:damage_type]} Damage" puts "Proficiency: #{entity.proficient_with_weapon?(weapon_details) ? t(:yes) : t(:no)}" puts 'Properties:' weapon_details[:properties]&.each do |p| puts " #{t("object.properties.#{p}")}" end puts weapon_details[:description] || '' end if item_inventory_choice.equipped choice = prompt.select(item_inventory_choice.label) do || .choice t(:unequip), :unequip .choice t(:back), :back end next if choice == :back if battle.combat? && weapon_details[:type] == 'armor' puts t('inventory.cannot_change_armor_combat') next end entity.unequip(item_inventory_choice.name) else choice = prompt.select(item_inventory_choice.label) do || reasons = entity.check_equip(item_inventory_choice.name) if reasons == :ok || reasons != :unequippable if reasons == :ok .choice 'Equip', :equip else .choice 'Equip', :equip, disabled: t("object.equip_problem.#{reasons}") end end .choice t(:drop), :drop if map.ground_at(*map.entity_or_object_pos(entity)) .choice 'Back', :back end case choice when :back next when :drop # drop item to the ground qty = how_many?(item_inventory_choice) entity.drop_items!(battle, [[item_inventory_choice, qty]]) when :equip if battle.combat? && weapon_details[:type] == 'armor' puts t('inventory.cannot_change_armor_combat') next end entity.equip(item_inventory_choice.name) end end end while true end |