def deactivate(self, county): # noinspection PyPropertyAccess for effect in self.effects: effect.undo(county) # noinspection PyPropertyAccess notice = Notification(county, f"Lost {self.name}", self.description, category="Research") notice.save()
def mana_change(self): county = self.county growth = self._mana_change active_spells = Casting.query.filter_by(county_id=county.id).filter_by( active=True).all() loss = sum(spell.mana_sustain for spell in active_spells) difference = int(growth - loss) if difference < 0 and county.mana + difference < 0: drop_spell = choice(active_spells) drop_spell.active = False drop_spell.save() # might be unneeded notice = Notification( county, "Spell Ended", f"You did not have enough mana and {drop_spell.name} ended.", "Spell End") notice.save() # noinspection PyPropertyAccess return self.mana_change return difference
def activate(self, county): # noinspection PyPropertyAccess for effect in self.effects: try: effect.activate(self) except TypeError as ex: tech_name = self.name effect_info = repr(effect.kwargs) # noinspection PyPropertyAccess description = self.description county_name = county.name raise TypeError( f"Tech: {tech_name} of {description} was crashed " f"by {effect_info} in county {county_name}" f"\nThe original exception was\n{ex}") # noinspection PyPropertyAccess notice = Notification(county, f"Discovered {self.name}", self.description, category="Research") notice.save()