Class: Omega::Client::Factory

Inherits:
Station show all
Defined in:
lib/omega/client/entities/station.rb

Overview

Omega client manufacturing station tracker

Instance Attribute Summary

Attributes included from Trackable

#entity, #event_handlers

Instance Method Summary collapse

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

#construct(args = {}) ⇒ Object

Construct the specified entity on the server

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

Raises the :constructed event on self

Parameters:

  • args (Hash) (defaults to: {})

    hash of args to be converted to array and passed to server construction operation verbatim


63
64
65
66
67
68
69
# File 'lib/omega/client/entities/station.rb', line 63

def construct(args={})
  RJR::Logger.info "Constructing #{args} with #{self.entity.id}"
  constructed = node.invoke 'manufactured::construct_entity',
                    self.entity.id, *(args.to_a.flatten)
  raise_event(:constructed, constructed)
  constructed
end

#construction_argsObject

Generate construction args from entity type


104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/omega/client/entities/station.rb', line 104

def construction_args
  case @entity_type
    when 'factory' then
      {:entity_type => 'Station',
       :type  => :manufacturing}
    when 'miner' then
      {:entity_type => 'Ship',
       :type  => :mining}
    when 'corvette' then
      {:entity_type => 'Ship',
       :type  => :corvette}
    else {}
  end
end

#entity_type(val = nil) ⇒ Object Also known as: entity_type=

Get/set the type of entity to construct using this station


72
73
74
75
# File 'lib/omega/client/entities/station.rb', line 72

def entity_type(val=nil)
  @entity_type = val unless val.nil?
  @entity_type
end

#pick_systemObject

Pick system with no stations or the fewest stations and jump to it


93
94
95
96
97
98
99
100
101
# File 'lib/omega/client/entities/station.rb', line 93

def pick_system
  # TODO optimize
  system = SolarSystem.get(system_id).
                       closest_neighbor_with_no :type => "Manufactured::Station",
                                                :owned_by => user_id
  system = SolarSystem.with_fewest :type => "Manufactured::Station",
                                   :owned_by => user_id if system.nil?
  jump_to(system) if system.id != system_id
end

#start_botObject

Start the omega client bot


79
80
81
82
83
84
# File 'lib/omega/client/entities/station.rb', line 79

def start_bot
  start_construction
  handle(:transferred_from) { |*args|
    start_construction
  }
end

#start_constructionObject

Begin construction cycle


87
88
89
90
# File 'lib/omega/client/entities/station.rb', line 87

def start_construction
  entity = construction_args.merge({ :id => gen_uuid })
  construct entity if can_construct?(entity)
end