Exemplo n.º 1
0
    def run(self):
        self.assert_state('new')

        self.message.BattleStart()

        sendouts = []
        exclude = []
        for side in self.sides:
            for spot in side.spots:
                monster = spot.trainer.get_first_inactive_monster(
                        exclude=exclude)
                sendouts.append((spot, monster))
                self.release_monster(spot, monster)
        self.sort_by_speed(
                sendouts,
                key=lambda x: x[1].stats.speed,
                reverse=True,
            )
        for spot, mon in sendouts:
            Effect.send_out(spot.battler)

        self.state = 'waiting'

        self.ask_for_commands()
        self.command_loop()
Exemplo n.º 2
0
    def handle_turn(self):
        self.assert_state('processing')

        commands = []
        for battler, command in self.commands.items():
            commands.append(command)

        self.message.TurnStart(turn=self.turn_number)
        Effect.begin_turn(self)

        self.turnCommands = commands = self.sort_commands(commands)

        self.turn_order = [c.request.spot for c in commands]

        move_effects = {}

        for command in commands:
            if command.command == 'move':
                command.move_effect = command.move.get_effect(
                        command.request.battler,
                        command.target)
                command.move_effect.begin_turn()

        for command in commands:
            battler = command.battler
            spot = battler.spot

            self.message.SubturnStart(battler=battler, turn=self.turn_number)
            if command.command == 'move':
                if not command.battler.fainted:
                    command.move_effect.attempt_use()
            elif command.command == 'switch':
                self.switch(command.request.spot, command.replacement)
                Effect.send_out(command.battler.spot.battler)
            else:
                raise NotImplementedError(command)
            self.message.SubturnEnd(battler=battler, turn=self.turn_number)
            if self.check_win():
                return

        Effect.end_turn(self)

        if self.state == 'finished' or self.check_win():
            return

        self.message.TurnEnd(turn=self.turn_number)

        # That's it for this turn!
        del self.turn_order

        if not self.ended:
            self.state = 'waiting'
            self.ask_for_commands()
Exemplo n.º 3
0
    def process_replacements(self):
        """Send out monsters to replace those that have fainted."""
        self.assert_state('waiting_replacements')

        commands = [command for command in self.commands.values()
                if command.command == 'switch']

        for command in commands:
            battler = command.battler
            spot = battler.spot
            self.switch(spot, command.replacement)

        trick_factor = Effect.speed_factor(self, 1)
        commands.sort(key=lambda c: -c.replacement.stats.speed * trick_factor)
        for command in commands:
            Effect.send_out(command.battler.spot.battler)

        self.ask_for_commands()