Class: InteractAction
- Inherits:
-
Natural20::Action
- Object
- Natural20::Action
- InteractAction
- Defined in:
- lib/natural_20/actions/interact_action.rb
Overview
typed: true
Instance Attribute Summary collapse
-
#object_action ⇒ Object
Returns the value of attribute object_action.
-
#other_params ⇒ Object
Returns the value of attribute other_params.
-
#target ⇒ Object
Returns the value of attribute target.
Attributes inherited from Natural20::Action
#action_type, #errors, #result, #session, #source
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Natural20::Action
#initialize, #label, #name, #to_s, #validate
Constructor Details
This class inherits a constructor from Natural20::Action
Instance Attribute Details
#object_action ⇒ Object
Returns the value of attribute object_action.
3 4 5 |
# File 'lib/natural_20/actions/interact_action.rb', line 3 def object_action @object_action end |
#other_params ⇒ Object
Returns the value of attribute other_params.
3 4 5 |
# File 'lib/natural_20/actions/interact_action.rb', line 3 def other_params @other_params end |
#target ⇒ Object
Returns the value of attribute target.
3 4 5 |
# File 'lib/natural_20/actions/interact_action.rb', line 3 def target @target end |
Class Method Details
.apply!(battle, item) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/natural_20/actions/interact_action.rb', line 74 def self.apply!(battle, item) entity = item[:source] case (item[:type]) when :interact item[:target].use!(entity, item) if item[:cost] == :action battle&.consume!(entity, :action, 1) else battle&.consume!(entity, :free_object_interaction, 1) || battle&.consume!(entity, :action, 1) end Natural20::EventManager.received_event(event: :interact, source: entity, target: item[:target], object_action: item[:object_action]) end end |
.build(session, source) ⇒ Object
11 12 13 14 |
# File 'lib/natural_20/actions/interact_action.rb', line 11 def self.build(session, source) action = InteractAction.new(session, source, :attack) action.build_map end |
.can?(entity, battle) ⇒ Boolean
7 8 9 |
# File 'lib/natural_20/actions/interact_action.rb', line 7 def self.can?(entity, battle) battle.nil? || !battle.ongoing? || entity.total_actions(battle).positive? || entity.free_object_interaction?(battle) end |
Instance Method Details
#build_map ⇒ Object
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 52 53 |
# File 'lib/natural_20/actions/interact_action.rb', line 16 def build_map OpenStruct.new({ action: self, param: [ { type: :select_object } ], next: lambda { |object| self.target = object OpenStruct.new({ param: [ { type: :interact, target: object } ], next: lambda { |action| self.object_action = action custom_action = object.try(:build_map, action, self) if custom_action.nil? OpenStruct.new({ param: nil, next: lambda { self } }) else custom_action end } }) } }) end |
#resolve(_session, map = nil, opts = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/natural_20/actions/interact_action.rb', line 55 def resolve(_session, map = nil, opts = {}) battle = opts[:battle] result = target.resolve(@source, object_action, other_params, opts) return [] if result.nil? result_payload = { source: @source, target: target, object_action: object_action, map: map, battle: battle, type: :interact }.merge(result) @result = [result_payload] self end |