Module: Natural20::Lootable
- Includes:
- Container
- Included in:
- Npc, PlayerCharacter
- Defined in:
- lib/natural_20/concerns/lootable.rb
Instance Method Summary collapse
-
#available_interactions(entity, battle = nil) ⇒ Array
Lists default available interactions for an entity.
-
#build_map(action, action_object) ⇒ OpenStruct
Builds a custom UI map.
- #interactable? ⇒ Boolean
- #resolve(entity, action, other_params, opts = {}) ⇒ Object
- #use!(_entity, result) ⇒ Object
Methods included from Container
Instance Method Details
#available_interactions(entity, battle = nil) ⇒ Array
Lists default available interactions for an entity
57 58 59 60 61 62 63 64 |
# File 'lib/natural_20/concerns/lootable.rb', line 57 def available_interactions(entity, battle = nil) other_interactions = super entity, battle other_interactions << :give if !npc? || object? # other_interactions << :pickpocket if !unconscious && npc? other_interactions << :loot if (dead? || unconscious? || opened?) && inventory_count.positive? other_interactions end |
#build_map(action, action_object) ⇒ OpenStruct
Builds a custom UI map
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 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/natural_20/concerns/lootable.rb', line 8 def build_map(action, action_object) case action when :give OpenStruct.new({ action: action_object, param: [ { type: :select_items, label: action_object.source.items_label, items: action_object.source.inventory } ], next: lambda { |items| action_object.other_params = items OpenStruct.new({ param: nil, next: lambda { action_object } }) } }) when :loot OpenStruct.new({ action: action_object, param: [ { type: :select_items, label: items_label, items: inventory + equipped_items } ], next: lambda { |items| action_object.other_params = items OpenStruct.new({ param: nil, next: lambda { action_object } }) } }) end end |
#interactable? ⇒ Boolean
66 67 68 |
# File 'lib/natural_20/concerns/lootable.rb', line 66 def interactable? true end |
#resolve(entity, action, other_params, opts = {}) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/natural_20/concerns/lootable.rb', line 73 def resolve(entity, action, other_params, opts = {}) return if action.nil? case action when :give, :loot { action: action, items: other_params, source: entity, target: self, battle: opts[:battle] } end end |
#use!(_entity, result) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/natural_20/concerns/lootable.rb', line 86 def use!(_entity, result) case (result[:action]) when :give store(result[:battle], result[:source], result[:target], result[:items]) when :loot retrieve(result[:battle], result[:source], result[:target], result[:items]) end end |