示例#1
0
    def cast_spell(self, spell, source, due):
        """ Curse self with given spell from source, for due time. """
        try:
            psamount = PlayerSpellAmount.objects.get(player=source, spell=spell)
            assert psamount.amount > 0
        except (PlayerSpellAmount.DoesNotExist, AssertionError):
            return False

        # Pre-cat God actions: immunity and curse ar done by this
        # check
        if not God.can_cast(spell, source, self):
            return False

        try:
            psdue = PlayerSpellDue.objects.create(player=self, source=source, spell=spell, due=due)
        except Exception as e:
            logging.exception(e)
            return False
        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        psamount.amount -= 1
        if psamount.amount == 0:
            psamount.delete()
        else:
            psamount.save()
        return True
示例#2
0
    def cast_spell(self, spell, source, due):
        """ Curse self with given spell from source, for due time. """
        try:
            psamount = PlayerSpellAmount.objects.get(player=source, spell=spell)
            assert psamount.amount > 0
        except (PlayerSpellAmount.DoesNotExist, AssertionError):
            return False

        # Pre-cat God actions: immunity and curse ar done by this
        # check
        if not God.can_cast(spell, source, self):
            return False

        try:
            psdue = PlayerSpellDue.objects.create(player=self, source=source, spell=spell, due=due)
        except Exception as e:
            logging.exception(e)
            return False
        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        psamount.amount -= 1
        if psamount.amount == 0:
            psamount.delete()
        else:
            psamount.save()
        return True
示例#3
0
文件: manager.py 项目: AndreiRO/wouso
    def basic_cast(self, player_dest, spell, due):
        # Pre-cast God actions: immunity and curse ar done by this
        # check
        can_cast, error = God.can_cast(spell=spell, source=self.player, destination=player_dest)
        if not can_cast:
            return error

        try:
            psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
        except IntegrityError:
            if not spell.mass:
                return 'Cannot cast the same spell more than once'
            # extend the affected time by spell
            psdue = PlayerSpellDue.objects.get(player=player_dest, spell=spell)
            if psdue.due < due:
                psdue.delete()
                psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
            else:
                return None

        if psdue.source == psdue.player:
            signal_msg = _("cast a spell on himself/herself")
        else:
            signal_msg = _("cast a spell on {to} ")
        signals.addActivity.send(sender=None, user_from=psdue.source,
                                 user_to=psdue.player,
                                 message=signal_msg,
                                 arguments=dict(to=psdue.player),
                                 action='cast',
                                 game=None)

        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        signals.postCast.send(sender=None, psdue=psdue)
        return None
示例#4
0
文件: manager.py 项目: ciprianf/wouso
    def cast_spell(self, spell, source, due):
        """ Cast a spell on this player.

        Returns: error message if the spell was not cast, or None
        """
        try:
            psamount = PlayerSpellAmount.objects.get(player=source, spell=spell)
            assert psamount.amount > 0
        except (PlayerSpellAmount.DoesNotExist, AssertionError):
            return 'Spell unavailable'

        # Pre-cast God actions: immunity and curse ar done by this
        # check
        can_cast, error = God.can_cast(spell, source, self.player)
        if not can_cast:
            return error

        try:
            psdue = PlayerSpellDue.objects.create(player=self.player, source=source, spell=spell, due=due)
        except IntegrityError:
            return 'Cannot cast the same spell more than once'

        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        psamount.amount -= 1
        if not psamount.amount:
            psamount.delete()
        else:
            psamount.save()
        return None
示例#5
0
    def basic_cast(self, player_dest, spell, due):
        # Pre-cast God actions: immunity and curse ar done by this
        # check
        can_cast, error = God.can_cast(spell=spell, source=self.player, destination=player_dest)
        if not can_cast:
            return error

        try:
            psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
        except IntegrityError:
            if not spell.mass:
                return 'Cannot cast the same spell more than once'
            # extend the affected time by spell
            psdue = PlayerSpellDue.objects.get(player=player_dest, spell=spell)
            if psdue.due < due:
                psdue.delete()
                psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
            else:
                return None

        if psdue.source == psdue.player:
            signal_msg = _("cast a spell on himself/herself")
        else:
            signal_msg = _("cast a spell on {to} ")
        signals.addActivity.send(sender=None, user_from=psdue.source,
                                 user_to=psdue.player,
                                 message=signal_msg,
                                 arguments=dict(to=psdue.player),
                                 action='cast',
                                 game=None)

        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        signals.postCast.send(sender=None, psdue=psdue)
        return None
示例#6
0
文件: manager.py 项目: anaion/wouso
    def basic_cast(self, player_dest, spell, due):
        # Pre-cast God actions: immunity and curse ar done by this
        # check

        can_cast, error = God.can_cast(spell=spell,
                                       source=self.player,
                                       destination=player_dest)
        if not can_cast:
            return error
        try:
            psdue = PlayerSpellDue.objects.create(player=player_dest,
                                                  source=self.player,
                                                  spell=spell,
                                                  due=due)
        except IntegrityError:
            if not spell.mass:
                return 'Cannot cast the same spell more than once'
            #extend the affected time by spell
            psdue = PlayerSpellDue.objects.get(player=player_dest, spell=spell)
            if psdue.due < due:
                psdue.delete()
                psdue = PlayerSpellDue.objects.create(player=player_dest,
                                                      source=self.player,
                                                      spell=spell,
                                                      due=due)
            else:
                return None

        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        return None
示例#7
0
文件: manager.py 项目: TomyRO/wouso
    def basic_cast(self, player_dest, spell, due):
        # Pre-cast God actions: immunity and curse ar done by this
        # check

        can_cast, error = God.can_cast(spell=spell, source=self.player, destination=player_dest)
        if not can_cast:
            return error
        try:
            psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
        except IntegrityError:
            if not spell.mass:
                return 'Cannot cast the same spell more than once'
            #extend the affected time by spell
            psdue = PlayerSpellDue.objects.get(player=player_dest, spell=spell)
            if psdue.due < due:
                psdue.delete()
                psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
            else:
                return None

        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        return None