Class: Missions::Events::PopulateResource

Inherits:
Omega::Server::Event show all
Defined in:
lib/missions/events/resources.rb

Overview

An event to populate the specified cosmos entity w/ the specified resource

Constant Summary collapse

DEFAULT_QUANTITY =

Default quantity of resource that will be added if not specified

1000

Instance Attribute Summary collapse

Attributes inherited from Omega::Server::Event

#handlers, #id, #registry, #timestamp, #type

Instance Method Summary collapse

Methods inherited from Omega::Server::Event

#event_args, #handlers_json, #invoke, json_create, #json_data, #should_exec?, #time_elapsed?, #to_s

Constructor Details

#initialize(args = {}) ⇒ PopulateResource

PopulateResource Event Initializer


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/missions/events/resources.rb', line 64

def initialize(args = {})
  attr_from_args args,
                 :resource => :random,
                 :entity   => :random,
                 :quantity => :random,
                 :from_entities  => [],
                 :from_resources => []

  [:@resource, :@entity, :@quantity].each { |a|
    v = self.instance_variable_get(a)
    self.instance_variable_set(a, v.intern) if v == 'random'
  }

  super(args)
  @handlers.unshift  proc { |e| handle_event }
end

Instance Attribute Details

#entityObject

Entity which to populate or random


31
32
33
# File 'lib/missions/events/resources.rb', line 31

def entity
  @entity
end

#from_entitiesObject

List of entities which to pick random entity from


34
35
36
# File 'lib/missions/events/resources.rb', line 34

def from_entities
  @from_entities
end

#from_resourcesObject

List of resources which to pick random resource from


28
29
30
# File 'lib/missions/events/resources.rb', line 28

def from_resources
  @from_resources
end

#quantityObject

Quantity which to populate or random


37
38
39
# File 'lib/missions/events/resources.rb', line 37

def quantity
  @quantity
end

#resourceObject

Resource which to populate or random


25
26
27
# File 'lib/missions/events/resources.rb', line 25

def resource
  @resource
end

Instance Method Details

#to_json(*a) ⇒ Object

Convert event to json representation and return it


82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/missions/events/resources.rb', line 82

def to_json(*a)
  {
    'json_class' => self.class.name,
    'data'       =>
      json_data.merge({:handlers => handlers[1..-1],
                       :resource => resource,
                       :entity => entity,
                       :quantity => @quantity,
                       :from_entities => @from_entities,
                       :from_resources => @from_resources})
  }.to_json(*a)
end