Module: Omega::Client::HasCargo

Included in:
Ship, Station
Defined in:
lib/omega/client/entities/cosmos.rb

Overview

Include the HasCargo module in classes to define helper methods regarding cargo manipulation

TODO prolly should go else where

Examples:

class MiningShip
  include Trackable
  include HasCargo
  include InSystem
  include InteractsWithEnvironment
  entity_type Manufactured::Ship
  get_method "manufactured::get_entity"
  entity_validation { |e| e.type == :miner }
end

s = MiningShip.get('ship1')
s.transfer_all_to Ship.get('other_ship')

Instance Method Summary collapse

Instance Method Details

#transfer(resource, target) ⇒ Object

Transfer specified resource to target.

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

Parameters:

  • resource (Resource)

    resource to transfer

  • [Entity] (Hash)

    a customizable set of options


265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/omega/client/entities/cosmos.rb', line 265

def transfer(resource, target)
  RJR::Logger.info "Transferring #{resource} to #{target}"
  entities = node.invoke 'manufactured::transfer_resource',
                          self.id, target.id, resource
  @entity = entities.first
  self.raise_event(:transferred_to,       target, resource)

  # XXX only set target entity / raises target
  # event if client entity passed in
  if target.class.to_s =~ /Omega::Client::.*/
    target.entity = entities.last
    target.raise_event(:transferred_from,  self,   resource)
  end
end

#transfer_all_to(target) ⇒ Object

Transfer all resource sources to target.

Parameters:


251
252
253
254
255
# File 'lib/omega/client/entities/cosmos.rb', line 251

def transfer_all_to(target)
  self.resources.each { |rs|
    self.transfer rs, target
  }
end