Beispiel #1
0
def get_resource(event):
    resource_type = event.get("ResourceType").split("::")[-1]
    resource_class = ResourceFactory.get_resource(resource_type)
    props = event.get("ResourceProperties")
    resource = resource_class(props)
    params = resource.extract_params(event)
    if isinstance(resource, SumoResource):
        params["remove_on_delete_stack"] = props.get(
            "RemoveOnDeleteStack") == 'true'
    return resource, resource_type, params
Beispiel #2
0
    def _start_action(self):
        #Check that all reuired resources are available
        if not self.possession.has_resources(self.inputs):
            print "Not enough resources to start " + self.name + "! Go home..."
            self.time_left = 0
            return

        #create the output stuff right away also, so that resources are "reserved"
        #Don't give the results to the caller until duraton is passed
        for output_resource in self.outputs:
            created_output = ResourceFactory.create_resource(output_resource, self.possession)
            self.created_outputs.append(created_output)
Beispiel #3
0
    def _end_action(self):
        print "Finished produce unit action: ", self.unit.name(self.target_status)
        self.unit.status = self.target_status
        self.unit.in_progress = False

        #if next status is "automatic" add a shceduled action to finnish it
        if not self.unit.needs_presence(self.unit.next_status()):
            Scheduler.instance().add_action(ProductUnitAction(self.npc, self.unit))
        
        outputs = self.unit.outputs(self.target_status)
        for output in outputs:
            self.npc.possession.add_resource(ResourceFactory.create_resource_from_nothing(output))
Beispiel #4
0
 def destroy_resource(self, resource):
     #print "Removing " + str(resource)
     self._get_resource_heap(resource).remove(resource)
     ResourceFactory.on_resource_destroyed(resource)