Exemplo n.º 1
0
class MissionObjectiveSquad(object):
    def __init__(self, objective, narrative, mission):
        self._goons = GoonGroup()
        self._objective = objective
        self._narrative = narrative
        self._mission = mission

    @property
    def objective(self):
        return self._objective

    def add_goon(self, goon):
        self._goons.add(goon)

    def attempt_objective(self, complication_traits):
        for solution in self._objective.solutions:
            self._narrative.add('- The team has started [%s].' % solution.name)
            if self.attempt_solution(solution, complication_traits):
                self._narrative.add('-- The team succeeded [%s]!' % solution.name)
                return True
            else:
                self._narrative.add('-- The team failed [%s].' % solution.name)

        if not self._objective.can_fail:
            raise FailedCriticalObjective
        return False

    def attempt_solution(self, solution, complication_traits):
        if solution.type == 'assigned':
            goon_traits = self._goons.traits
        else:
            goon_traits = self._mission.goons.traits

        if len(complication_traits) > 0:
            traits_to_check = TraitList()
            traits_to_check.add(solution.traits)
            for trait in complication_traits:
                if trait.trait in solution.traits:
                    traits_to_check.add(trait)
        else:
            traits_to_check = solution.traits

        for trait in traits_to_check:
            squad_trait = goon_traits.get(trait.trait)
            if squad_trait is None:
                print 'Failed because goons do not have %s' % trait.trait
                return False

            roll = trait.roll()
            print '** %s check: goons have %s, need at least %s' % (trait.trait, squad_trait.value, roll)
            if squad_trait.value < roll:
                return False

        return True
Exemplo n.º 2
0
    def __init__(self, mission):
        self._mission = mission
        self._squads = []
        self._goons = GoonGroup()
        self._traits = set()
        self._narrative = Narrative()
        self._reward = mission.get_reward()
        self._objective_results = {}
        self._failed_objectives = set()

        for objective in mission.objectives:
            self._squads.append(MissionObjectiveSquad(objective, self._narrative, self))
Exemplo n.º 3
0
class MissionAttempt(object):
    def __init__(self, mission):
        self._mission = mission
        self._squads = []
        self._goons = GoonGroup()
        self._traits = set()
        self._narrative = Narrative()
        self._reward = mission.get_reward()
        self._objective_results = {}
        self._failed_objectives = set()

        for objective in mission.objectives:
            self._squads.append(MissionObjectiveSquad(objective, self._narrative, self))

    @property
    def goons(self):
        return self._goons

    @property
    def reward(self):
        return self._reward

    def get_squad_for_objective(self, objective_id, create=True):
        objective = self._mission.get_objective(objective_id)
        for squad in self._squads:
            if squad.objective == objective:
                return squad

        if create:
            return MissionObjectiveSquad(objective, self._narrative, self)

    def add_goon_to_objective(self, objective_id, goon):
        if goon not in self._goons:
            self._goons.add(goon)
        squad = self.get_squad_for_objective(objective_id)
        squad.add_goon(goon)

    def attempt(self):
        for objective_squad in self._squads:
            self._narrative.add('_____________________________________________________________________________________')
            skip = False
            for obj in objective_squad.objective.objectives_required:
                if obj in self._failed_objectives:
                    self._narrative.add('Cannot attempt objective: [%s], failed required objective(s)' % objective_squad.objective.name)
                    skip = True
                    break

            if skip:
                continue

            self._narrative.add('Attempting objective: [%s]' % objective_squad.objective.name)

            complications, complication_traits = objective_squad.objective.get_complications()
            for complication in complications:
                self._narrative.add("We've ran into a bit of a problem, %s" % complication.name)

            if objective_squad.attempt_objective(complication_traits):
                self._narrative.add('The team succeeded [%s]!' % objective_squad.objective.name)
                self._objective_results[objective_squad.objective.id] = True
                reward = objective_squad.objective.get_reward()
                if reward:
                    self._narrative.add('$%s was obtained!' % reward)
                    self._reward += reward
            else:
                self._narrative.add('The team failed [%s].' % objective_squad.objective.name)
                self._objective_results[objective_squad.objective.id] = False
                self._failed_objectives.add(objective_squad.objective.id)
Exemplo n.º 4
0
 def __init__(self, objective, narrative, mission):
     self._goons = GoonGroup()
     self._objective = objective
     self._narrative = narrative
     self._mission = mission