class Asset(object): """ Assets that a player can purchase, like vehicles, weapons or mission requirement items like "Mega Torch 3000" to cut through vault doors! """ def __init__(self, asset_id, name, description, category, price): self._asset_id = asset_id self._name = name self._description = description self._category = category self._price = price self._traits = TraitList() def add_trait(self, trait, value): if trait in self._traits: raise DuplicateAssetTrait self._traits.add(Trait(trait, value)) @classmethod def from_json(cls, json_data): asset = cls( asset_id=json_data['id'], name=json_data['name'], description=json_data['description'], category=json_data['category'], price=json_data['price'] ) for trait, value in json_data['traits'].items(): asset.add_trait(trait, value) return asset
class GoonGroup(object): def __init__(self): self._goons = set() self._traits = TraitList() def add(self, goon): self._traits.reset() self._goons.add(goon) def remove(self, goon): self._traits.reset() self._goons.remove(goon) @property def traits(self): if len(self._traits) == 0: for goon in self._goons: for trait in goon.traits: if trait not in self._traits: self._traits.add(trait.trait, trait.value) group_trait = self._traits.get(trait.trait) group_trait += trait return self._traits def __iter__(self): return iter(self._goons)
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
def generateTraits(self): primary_trait = self.archetypes[self.type] traits = set() traits.add(primary_trait) results = TraitList() while (random.random() < .5): traits.add(random.choice(self.goon_traits)) for t in traits: results.add(Trait(t, random.randint(1,6))) return results
def get_complications(self): complications = set() traits = TraitList() for complication in self._mission.complications: if self._id in complication.objectives: if complication.roll(): complications.add(complication) for solution in self._solutions: for trait in complication.traits: if trait in solution.traits: traits.add(trait) return complications, traits