Module: Missions::DSL::Query

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

Overview

Mission Queries

Class Method Summary collapse

Methods included from Helpers

#dsl_module_for, included, #is_dsl_category?

Class Method Details

.check_entity_hp(id) ⇒ Object

Return bool indicating if the ships hp == 0 (eg ship is destroyed)


16
17
18
19
20
21
22
23
# File 'lib/missions/dsl/query.rb', line 16

def self.check_entity_hp(id)
  proc { |mission|
    # check if entity is destroyed
    entity = mission.mission_data[id]
    entity = node.invoke('manufactured::get_entity', entity.id)
    entity.nil? || entity.hp == 0
  }
end

.check_lootObject

Return boolean indicating if user has collected the target loot


50
51
52
53
54
55
56
57
58
# File 'lib/missions/dsl/query.rb', line 50

def self.check_loot
  proc { |mission|
    !mission.mission_data['loot'].nil?
    !mission.mission_data['loot'].find { |rs|
      rs.material_id == mission.mission_data['check_loot']['res'] &&
      rs.quantity    >= mission.mission_data['check_loot']['q']
    }.nil?
  }
end

.check_mining_quantityObject

Return bool indicating if user has acquired target mining quantity


26
27
28
29
30
31
# File 'lib/missions/dsl/query.rb', line 26

def self.check_mining_quantity
  proc { |mission|
    q = mission.mission_data['resources'][mission.mission_data['target']]
    mission.mission_data['quantity'] <= q
  }
end

.check_transferObject

Return bool indicating if user has transfered the target resource


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/missions/dsl/query.rb', line 34

def self.check_transfer
  proc { |mission|
    mission.mission_data['last_transfer'] &&

    mission.mission_data['check_transfer']['dst'].id ==
    mission.mission_data['last_transfer']['dst'].id  &&

    mission.mission_data['check_transfer']['rs'] ==
    mission.mission_data['last_transfer']['rs']  &&

    mission.mission_data['check_transfer']['q'] >=
    mission.mission_data['last_transfer']['q']
  }
end

.entities_destroyed(filter = {}) ⇒ Object

Return bool indicating if all user entities have been destroyed


78
79
80
81
82
83
# File 'lib/missions/dsl/query.rb', line 78

def self.entities_destroyed(filter={})
  proc { |mission|
    node.invoke('manufactured::get_entity', *filter.to_a.flatten)
        .none? { |e| e.alive? }
  }
end

.user_ship(filter = {}) ⇒ Object

Return first ship returned by user_ships


71
72
73
74
75
# File 'lib/missions/dsl/query.rb', line 71

def self.user_ship(filter={})
  proc { |mission|
    user_ships(filter).call(mission).first
  }
end

.user_ships(filter = {}) ⇒ Object

Return ships the user owned that matches the speicifed properties filter


61
62
63
64
65
66
67
68
# File 'lib/missions/dsl/query.rb', line 61

def self.user_ships(filter={})
  proc { |mission|
    node.invoke('manufactured::get_entity',
                'of_type', 'Manufactured::Ship',
                'owned_by', mission.assigned_to_id).
      select { |s| filter.keys.all? { |k| s.send(k).to_s == filter[k].to_s }}
  }
end