Module: Missions::DSL::Event

Includes:
Helpers
Defined in:
lib/missions/dsl/event.rb

Overview

Mission related events handlers

Class Method Summary collapse

Methods included from Helpers

#dsl_module_for, included, #is_dsl_category?

Class Method Details

.check_victory_conditionsObject


65
66
67
68
69
# File 'lib/missions/dsl/event.rb', line 65

def self.check_victory_conditions
  proc { |mission, evnt|
    create_victory_event.call(mission, evnt) if mission.completed?
  }
end

.collected_lootObject


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/missions/dsl/event.rb', line 52

def self.collected_loot
  proc { |mission, evnt|
    loot = evnt.manufactured_event_args[2]
    mission.mission_data['loot'] ||= []
    mission.mission_data['loot'] << loot
    update_mission mission

    if Query.check_loot.call(mission)
      Event.create_victory_event.call(mission, evnt)
    end
  }
end

.create_victory_eventObject


71
72
73
74
75
76
77
78
# File 'lib/missions/dsl/event.rb', line 71

def self.create_victory_event
  proc { |mission, evnt|
    # TODO unless mission.failed?
    victory  = Missions::Events::Victory.new :mission  => mission,
                                             :registry => registry
    registry << victory
  }
end

.entity_destroyedObject


44
45
46
47
48
49
50
# File 'lib/missions/dsl/event.rb', line 44

def self.entity_destroyed
  proc { |mission, evnt|
    mission.mission_data['destroyed'] ||= []
    mission.mission_data['destroyed'] << evnt
    update_mission mission
  }
end

.resource_collectedObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/missions/dsl/event.rb', line 15

def self.resource_collected
  proc { |mission, evnt|
    rs = evnt.manufactured_event_args[2].material_id
    q  = evnt.manufactured_event_args[3]
    mission.mission_data['resources']     ||= {}
    mission.mission_data['resources'][rs] ||= 0
    mission.mission_data['resources'][rs]  += q
    update_mission mission

    if Query.check_mining_quantity.call(mission)
      Event.create_victory_event.call(mission, evnt)
    end
  }
end

.transferred_outObject


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/missions/dsl/event.rb', line 30

def self.transferred_out
  proc { |mission, evnt|
    dst = evnt.manufactured_event_args[2]
    rs  = evnt.manufactured_event_args[3]
    mission.mission_data['last_transfer'] =
      { 'dst' => dst, 'rs' => rs.material_id, 'q' => rs.quantity }
    update_mission mission

    if Query.check_transfer.call(mission)
      Event.create_victory_event.call(mission, evnt)
    end
  }
end