Module: Ledmon::Monster::Interaction
- Extended by:
- ActiveSupport::Concern
- Included in:
- Executor
- Defined in:
- lib/ledmon/monster/interaction.rb
Instance Method Summary collapse
- #accept_trade_offer(id) ⇒ Object
- #attack ⇒ Object
- #cancel_trade_offer(id) ⇒ Object
- #consume_item(item) ⇒ Object
- #craft(recipe) ⇒ Object
- #create_trade_offer(remaining, inputs, outputs) ⇒ Object
- #equip_item(item, slot) ⇒ Object
- #get_health ⇒ Object
- #get_inventory ⇒ Object
- #get_recipes ⇒ Object
- #get_remaining_consumable_duration ⇒ Object
- #get_research_progress ⇒ Object
- #interact ⇒ Object
- #list_trade_offers ⇒ Object
- #look ⇒ Object
- #research(item) ⇒ Object
- #scrap(item) ⇒ Object
- #storage_list ⇒ Object
- #storage_transfer(item, take) ⇒ Object
- #unequip_item(slot) ⇒ Object
Instance Method Details
#accept_trade_offer(id) ⇒ Object
108 109 110 |
# File 'lib/ledmon/monster/interaction.rb', line 108 def accept_trade_offer(id) client.accept_trade_offer(Ledmon::TradeOfferId.new(id:)) end |
#attack ⇒ Object
84 85 86 |
# File 'lib/ledmon/monster/interaction.rb', line 84 def attack client.attack(Ledmon::Empty.new) end |
#cancel_trade_offer(id) ⇒ Object
104 105 106 |
# File 'lib/ledmon/monster/interaction.rb', line 104 def cancel_trade_offer(id) client.cancel_trade_offer(Ledmon::TradeOfferId.new(id:)) end |
#consume_item(item) ⇒ Object
112 113 114 |
# File 'lib/ledmon/monster/interaction.rb', line 112 def consume_item(item) client.consume_item(Ledmon::ItemInfo.new(item:)) end |
#craft(recipe) ⇒ Object
48 49 50 |
# File 'lib/ledmon/monster/interaction.rb', line 48 def craft(recipe) client.craft(Ledmon::CraftData.new(recipe:)) end |
#create_trade_offer(remaining, inputs, outputs) ⇒ Object
100 101 102 |
# File 'lib/ledmon/monster/interaction.rb', line 100 def create_trade_offer(remaining, inputs, outputs) client.create_trade_offer(Ledmon::TradeOffer.new(remaining:, inputs:, outputs:)).id end |
#equip_item(item, slot) ⇒ Object
68 69 70 |
# File 'lib/ledmon/monster/interaction.rb', line 68 def equip_item(item, slot) client.equip_item(Ledmon::EquipInfo.new(item:, slot:)) end |
#get_health ⇒ Object
80 81 82 |
# File 'lib/ledmon/monster/interaction.rb', line 80 def get_health client.get_health(Ledmon::Empty.new).health end |
#get_inventory ⇒ Object
76 77 78 |
# File 'lib/ledmon/monster/interaction.rb', line 76 def get_inventory client.get_inventory(Ledmon::Empty.new) end |
#get_recipes ⇒ Object
60 61 62 |
# File 'lib/ledmon/monster/interaction.rb', line 60 def get_recipes client.get_recipes(Ledmon::Empty.new) end |
#get_remaining_consumable_duration ⇒ Object
115 116 117 |
# File 'lib/ledmon/monster/interaction.rb', line 115 def get_remaining_consumable_duration client.get_remaining_consumable_duration(Ledmon::Empty.new).time end |
#get_research_progress ⇒ Object
56 57 58 |
# File 'lib/ledmon/monster/interaction.rb', line 56 def get_research_progress client.get_research_progress(Ledmon::Empty.new) end |
#interact ⇒ Object
5 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 40 41 42 43 44 45 46 |
# File 'lib/ledmon/monster/interaction.rb', line 5 def interact queue = Queue.new requests = Enumerator.new do |yielder| loop do = queue.pop yielder << end end queue << Ledmon::InteractionRequest.new( action: Ledmon::InteractionRequestAction::START, ) last_challenge_response = nil last_challenge_algo_output = nil client.interact(requests).map do |response| logger.debug("Got response: #{response}") if response.action == :CHALLENGE logger.debug("Challenge ID: #{response.challenge_id}") logger.debug("Challenge Input: #{response.challenge_input}") algo_output = algo(response.challenge_id, response.challenge_input) last_challenge_response = response last_challenge_algo_output = algo_output queue << Ledmon::InteractionRequest.new( action: Ledmon::InteractionRequestAction::SUBMIT_CHALLENGE, challenge_response: algo_output.to_s, ) elsif response.action == :SUCCESS logger.debug("Challenge succeeded!") return true, last_challenge_response.challenge_id, last_challenge_response.challenge_input, last_challenge_algo_output elsif response.action == :FAILURE logger.debug("Challenge failed!") return false, last_challenge_response&.challenge_id, last_challenge_response&.challenge_input, last_challenge_algo_output end end end |
#list_trade_offers ⇒ Object
96 97 98 |
# File 'lib/ledmon/monster/interaction.rb', line 96 def list_trade_offers client.list_trade_offers(Ledmon::Empty.new) end |
#look ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ledmon/monster/interaction.rb', line 119 def look look_data = client.look(Ledmon::Empty.new) tiles = [] for y in -look_data.distance..look_data.distance tile_col = [] for x in -look_data.distance..look_data.distance tile_col << look_data.tiles[(x+look_data.distance)+(y+look_data.distance)*(look_data.distance*2+1)] end tiles << tile_col end tiles end |
#research(item) ⇒ Object
52 53 54 |
# File 'lib/ledmon/monster/interaction.rb', line 52 def research(item) client.research(Ledmon::ItemInfo.new(item:)) end |
#scrap(item) ⇒ Object
64 65 66 |
# File 'lib/ledmon/monster/interaction.rb', line 64 def scrap(item) client.scrap(Ledmon::ItemInfo.new(item:)) end |
#storage_list ⇒ Object
92 93 94 |
# File 'lib/ledmon/monster/interaction.rb', line 92 def storage_list client.storage_list(Ledmon::Empty.new).items.to_a end |
#storage_transfer(item, take) ⇒ Object
88 89 90 |
# File 'lib/ledmon/monster/interaction.rb', line 88 def storage_transfer(item, take) client.storage_transfer(Ledmon::StorageTransferData.new(item:, mode: if take then :TAKE else :DEPOSIT end)) end |
#unequip_item(slot) ⇒ Object
72 73 74 |
# File 'lib/ledmon/monster/interaction.rb', line 72 def unequip_item(slot) client.unequip_item(Ledmon::UnequipInfo.new(slot:)) end |