Class: Omega::Client::Corvette

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

Overview

Omega client corvette ship tracker

Instance Attribute Summary collapse

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 Attribute Details

#visitedObject

visited systems


280
281
282
# File 'lib/omega/client/entities/ship.rb', line 280

def visited
  @visited
end

Instance Method Details

#attack(target) ⇒ Object

Attack the specified target

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


274
275
276
277
# File 'lib/omega/client/entities/ship.rb', line 274

def attack(target)
  RJR::Logger.info "Starting to attack #{target.id} with #{id}"
  node.invoke 'manufactured::attack_entity', id, target.id
end

#check_proximityObject

Internal helper, check nearby locations, if enemy ship is detected stop movement and attack it. Result patrol route when attack ceases


333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/omega/client/entities/ship.rb', line 333

def check_proximity
  solar_system.entities.each { |e|
    if e.is_a?(Manufactured::Ship) && e.user_id != user_id &&
       e.location - location <= attack_distance && e.alive?
      stop_moving
      unless @check_proximity_handler
        @check_proximity_handler = true
        handle(:attacked_stop){ |*args| patrol_route }
      end
      attack(e)
      break
    end
  } if self.alive? && !self.attacking?
end

#patrol_routeObject

Calculate an inter-system route to patrol and move through it.


289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/omega/client/entities/ship.rb', line 289

def patrol_route
  @visited  ||= []

  # add local system to visited list
  @visited << solar_system unless @visited.include?(solar_system)

  # grab jump gate of a neighboring system we haven't visited yet
  jg = solar_system.jump_gates.find { |jg|
         !@visited.collect { |v| v.id }.include?(jg.endpoint_id)
       }

  # if no items in to_visit clear lists
  if jg.nil?
    # if jg can't be found on two subsequent runs,
    # error out / stop bot
    if @patrol_err
      raise_event(:patrol_err)
      return
    end
    @patrol_err = true

    @visited  = []
    patrol_route

  else
    @patrol_err = false
    raise_event(:selected_system, jg.endpoint_id, jg)
    if jg.location - location < jg.trigger_distance
      jump_to(jg.endpoint)
      patrol_route

    else
      dst = jg.trigger_distance / 4
      nl  = jg.location + [dst,dst,dst]
      move_to(:location => nl) {
        jump_to(jg.endpoint)
        patrol_route
      }
    end
  end
end

#start_botObject

Start the omega client bot


283
284
285
286
# File 'lib/omega/client/entities/ship.rb', line 283

def start_bot
  handle(:destroyed_by)
  patrol_route
end