Class: Missions::Events::Manufactured

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

Overview

An event this is spawed by another in the manufactured subsystem

Instance Attribute Summary collapse

Attributes inherited from Omega::Server::Event

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

Class Method Summary collapse

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(*manufactured_event_args) ⇒ Manufactured

Manufactured Event intializer


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/missions/events/manufactured.rb', line 27

def initialize(*manufactured_event_args)
  if  manufactured_event_args.first.is_a?(Hash)
    if manufactured_event_args.first.has_key?('manufactured_event_args')
      manufactured_event_args =
        manufactured_event_args.first['manufactured_event_args'].flatten
    else
      super(manufactured_event_args.first)
      return
    end
  end

  @manufactured_event_args = manufactured_event_args

  # generate event id from args
  entity_id =
    case manu_event_type
    when 'attacked'            then
      manufactured_event_args[1].id

    when 'entity_destroyed'    then
      manufactured_event_args[1].id

    when 'destroyed_by'        then
      manufactured_event_args[1].id

    when 'resource_collected'  then
      manufactured_event_args[1].id

    when 'transferred_to'      then
      manufactured_event_args[1].id

    when 'collected_loot'      then
      manufactured_event_args[1].id

    end
  id = self.class.gen_id(entity_id, manu_event_type)

  super(:id => id, :timestamp => Time.now)
end

Instance Attribute Details

#manufactured_event_argsObject

Array of args received pertaining to the manufactured event


14
15
16
# File 'lib/missions/events/manufactured.rb', line 14

def manufactured_event_args
  @manufactured_event_args
end

Class Method Details

.gen_id(entity_id, event) ⇒ Object

Helper method to generate id from entity / event


22
23
24
# File 'lib/missions/events/manufactured.rb', line 22

def self.gen_id(entity_id, event)
  "#{entity_id}_#{event}"
end

Instance Method Details

#manu_event_typeObject

Return the manufactured event


17
18
19
# File 'lib/missions/events/manufactured.rb', line 17

def manu_event_type
  manufactured_event_args.first
end

#to_json(*a) ⇒ Object

Convert event to json representation and return it


68
69
70
71
72
73
74
# File 'lib/missions/events/manufactured.rb', line 68

def to_json(*a)
  {
    'json_class' => self.class.name,
    'data'       =>
      json_data.merge({:manufactured_event_args => @manufactured_event_args})
  }.to_json(*a)
end