Class: Omega::Client::Miner

Inherits:
Ship show all
Defined in:
lib/omega/client/entities/ship.rb

Overview

Omega client miner ship tracker

Instance Attribute Summary

Attributes included from TrackState

#states

Attributes included from Trackable

#entity, #event_handlers

Instance Method Summary collapse

Methods inherited from Ship

#collect_loot, #dock_to, #undock

Methods included from HasCargo

#transfer, #transfer_all_to

Methods included from InSystem

#closest, #jump_to, #move_to, #solar_system, #stop_moving

Methods included from HasLocation

included, #location

Methods included from TrackState

included, #off_state, #on_state, #set_state, #unset_state

Methods included from TrackEntity

clear_entities, #entities, entities, included, track_entity

Methods included from Trackable

#clear_handlers, #clear_handlers_for, #handle, #handles?, included, #method_missing, #node, node, #raise_event, #refresh

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Omega::Client::Trackable

Instance Method Details

#mine(resource) ⇒ Object

Mine the specified resource

All server side mining restrictions apply, this method does not do any checks b4 invoking start_mining so if server raises a related error, it will be reraised here

Parameters:


136
137
138
139
# File 'lib/omega/client/entities/ship.rb', line 136

def mine(resource)
  RJR::Logger.info "Starting to mine #{resource.material_id} with #{id}"
  @entity = node.invoke 'manufactured::start_mining', id, resource.id
end

#offload_resourcesObject

Move to the closest station owned by user and transfer resources to it


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/omega/client/entities/ship.rb', line 157

def offload_resources
  st = closest(:station).first

  if st.nil?
    raise_event(:no_stations)
    return

  elsif st.location - location < transfer_distance
    begin
      transfer_all_to(st)

      # allow two errors before giving up
      @transfer_errs = 0
    rescue Exception => e
      @transfer_errs ||= 0
      @transfer_errs  += 1
      if @transfer_errs > 2
        raise_event(:transfer_err, st)
        return
      end

      # refresh stations and try again
      Omega::Client::Station.refresh
      offload_resources
      return
    end

    select_target

  else
    raise_event(:moving_to, st)
    move_to(:destination => st) { |*args|
      offload_resources
    }
  end
end

#select_targetObject

Select next resource, move to it, and commence mining


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/omega/client/entities/ship.rb', line 195

def select_target
  ast = closest(:resource).first
  if ast.nil?
    raise_event(:no_resources)
    return
  else
    raise_event(:selected_resource, ast)
  end

  rs  = ast.resources.find { |rsi| rsi.quantity > 0 }

  if ast.location - location < mining_distance
    # server resource may by depleted at any point,
    # need to catch errors, and try elsewhere
    begin
      mine(rs)
    rescue Exception => e
      select_target
    end

  else
    dst = mining_distance / 4
    nl  = ast.location + [dst,dst,dst]
    move_to(:location => nl) { |*args|
      begin
        mine(rs)
      rescue Exception => e
        select_target
      end
    }
  end
end

#start_botObject

Start the omega client bot


142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/omega/client/entities/ship.rb', line 142

def start_bot
  # start listening for events which may trigger state changes
  handle(:resource_collected)
  handle(:mining_stopped) { |m,*args|
    m.select_target if args[3] != 'ship_cargo_full'
  }

  if cargo_full?
    offload_resources
  else
    select_target
  end
end