Module: Missions::DSL::Resolution

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

Overview

Mission Resolution

Class Method Summary collapse

Methods included from Helpers

#dsl_module_for, included, #is_dsl_category?

Class Method Details

.add_reward(rs) ⇒ Object

Add resource to a user owned entity


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

def self.add_reward(rs)
  proc { |mission|
    # TODO better way to get user ship than this
    # TODO try other ships if add_resource fails
    entity = Query.user_ships.call(mission).first

    # add resources to player's cargo
    rs.id = Motel.gen_uuid
    rs.entity = entity
    node.invoke('manufactured::add_resource', entity.id, rs)
  }
end

.cleanup_entity_events(id, *evnts) ⇒ Object

Cleanup all entity events related to the mission


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/missions/dsl/resolution.rb', line 43

def self.cleanup_entity_events(id, *evnts)
  proc { |mission|
    entities = mission.mission_data[id]
    entities = [entities] unless entities.is_a?(Array)

    entities.each { |entity|
      # remove callbacks
      node.invoke('manufactured::remove_callbacks', entity.id)

      # remove event handlers
      evnts.each { |evnt|
        eid = Missions::Events::Manufactured.gen_id(entity.id, evnt)
        registry.cleanup_event(eid)
      }
    }
  }
end

.cleanup_expiration_eventsObject

Cleanup mission expiration event


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

def self.cleanup_expiration_events
  proc { |mission|
    # remove expiration event
    eid = "mission-#{mission.id}-expired"
    registry.cleanup_event(eid)
  }
end

.fail_mission(mission_id) ⇒ Object

Mark another mission as failed


82
83
84
85
86
87
88
# File 'lib/missions/dsl/resolution.rb', line 82

def self.fail_mission(mission_id)
  proc { |mission|
    target = registry.entity { |e| e.is_a?(Mission) && e.id == mission_id }
    failed = Missions::Events::Failed.new :mission => target
    registry << failed
  }
end

.recycle_missionObject

Recycle mission, eg clone it w/ a new id, clear assignment, and add it to the registry


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

def self.recycle_mission
  proc { |mission|
    # create a new mission based on the specified one
    new_mission = mission.clone :id => Motel.gen_uuid
    new_mission.clear_assignment!
    node.invoke('missions::create_mission', new_mission)
  }
end

.update_user_attributesObject

Updates mission-related user attributes


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

def self.update_user_attributes
  proc { |mission|
    # update user attributes
    atr = mission.victorious ? Users::Attributes::MissionsCompleted.id :
                               Users::Attributes::MissionsFailed.id
    node.invoke('users::update_attribute',
                               mission.assigned_to_id,
                               atr, 1)
  }
end