class GroundInteractAction
typed: true
Attributes
ground_items[RW]
target[RW]
Public Class Methods
apply!(battle, item)
click to toggle source
# File lib/natural_20/actions/ground_interact_action.rb, line 62 def self.apply!(battle, item) entity = item[:source] case (item[:type]) when :pickup item[:actions].each do |g, action| g.use!(nil, action) end if item[:cost] == :action battle&.consume!(entity, :action, 1) else battle&.consume!(entity, :free_object_interaction, 1) || battle&.consume!(entity, :action, 1) end end end
build(session, source)
click to toggle source
# File lib/natural_20/actions/ground_interact_action.rb, line 9 def self.build(session, source) action = GroundInteractAction.new(session, source, :ground_interact) action.build_map end
can?(entity, battle)
click to toggle source
# File lib/natural_20/actions/ground_interact_action.rb, line 5 def self.can?(entity, battle) battle.nil? || (entity.total_actions(battle).positive? || entity.free_object_interaction?(battle)) && items_on_the_ground_count(entity, battle).positive? end
items_on_the_ground_count(entity, battle)
click to toggle source
@param entity [Natural20::Entity] @param battle [Natural20::Battle] @return [Integer]
# File lib/natural_20/actions/ground_interact_action.rb, line 17 def self.items_on_the_ground_count(entity, battle) return 0 unless battle.map battle.map.items_on_the_ground(entity).inject(0) { |total, item| total + item[1].size } end
Public Instance Methods
build_map()
click to toggle source
# File lib/natural_20/actions/ground_interact_action.rb, line 23 def build_map OpenStruct.new({ action: self, param: [ { type: :select_ground_items } ], next: lambda { |object| self.ground_items = object OpenStruct.new({ param: nil, next: lambda { self } }) } }) end
resolve(_session, map = nil, opts = {})
click to toggle source
# File lib/natural_20/actions/ground_interact_action.rb, line 44 def resolve(_session, map = nil, opts = {}) battle = opts[:battle] actions = ground_items.map do |g, items| [g, { action: :pickup, items: items, source: @source, target: g, battle: opts[:battle] }] end.to_h @result << { source: @source, actions: actions, map: map, battle: battle, type: :pickup } self end