コード例 #1
0
ファイル: combat.py プロジェクト: erya008/Tuxemon
    def start_battle(self, game, action, contexts):
        """Start a battle and switch to the combat module. The parameters must contain an NPC slug
        in the NPC database.

        :param game: The main game object that contains all the game's variables.
        :param action: The action (tuple) retrieved from the database that contains the action's
            parameters

        :type game: core.control.Control
        :type action: Tuple

        :rtype: None
        :returns: None

        Valid Parameters: npc_slug

        **Examples:**

        >>> action.__dict__
        {
            "type": "start_battle",
            "parameters": [
                "npc_hiker1"
            ]
        }

        """
        # Don't start a battle if we don't even have monsters in our party yet.
        if not self.check_battle_legal(game.player1):
            return False

        # Stop movement and keypress on the server.
        if game.isclient or game.ishost:
            game.client.update_player(game.player1.facing,
                                      event_type="CLIENT_START_BATTLE")

        # Start combat
        npc_slug = action.parameters[0]

        # TODO: This should *really* be handled in the Npc initializer
        # Create an NPC object that will be used as our opponent
        npc = player.Npc(slug=npc_slug)

        # Look up the NPC's details from our NPC database
        npcs = db.JSONDatabase()
        npcs.load("npc")
        npc_details = npcs.database['npc'][npc_slug]

        # Set the NPC object with the details fetched from the database.
        npc.name = npc_details['name']

        # Set the NPC object's AI model.
        npc.ai = ai.AI()

        # Look up the NPC's monster party
        npc_party = npc_details['monsters']

        # Look up the monster's details
        monsters = db.JSONDatabase()
        monsters.load("monster")

        # Look up each monster in the NPC's party
        for npc_monster_details in npc_party:
            results = monsters.database['monster'][
                npc_monster_details['monster']]

            # Create a monster object for each monster the NPC has in their party.
            # TODO: unify save/load of monsters
            current_monster = monster.Monster()
            current_monster.load_from_db(npc_monster_details['monster'])
            current_monster.name = npc_monster_details['name']
            current_monster.level = npc_monster_details['level']
            current_monster.hp = npc_monster_details['hp']
            current_monster.current_hp = npc_monster_details['hp']
            current_monster.attack = npc_monster_details['attack']
            current_monster.defense = npc_monster_details['defense']
            current_monster.speed = npc_monster_details['speed']
            current_monster.special_attack = npc_monster_details[
                'special_attack']
            current_monster.special_defense = npc_monster_details[
                'special_defense']
            current_monster.experience_give_modifier = npc_monster_details[
                'exp_give_mod']
            current_monster.experience_required_modifier = npc_monster_details[
                'exp_req_mod']

            current_monster.type1 = results['types'][0]

            current_monster.set_level(current_monster.level)

            if len(results['types']) > 1:
                current_monster.type2 = results['types'][1]

            current_monster.load_sprite_from_db()

            pound = technique.Technique('technique_pound')

            current_monster.learn(pound)

            # Add our monster to the NPC's party
            npc.monsters.append(current_monster)

        # Add our players and setup combat
        game.push_state("CombatState",
                        players=(game.player1, npc),
                        combat_type="trainer")

        # Start some music!
        logger.info("Playing battle music!")
        filename = "147066_pokemon.ogg"

        mixer.music.load(prepare.BASEDIR + "resources/music/" + filename)
        mixer.music.play(-1)
コード例 #2
0
ファイル: player.py プロジェクト: ekureina/Tuxemon
    def add_monster(self, game, action):
        """Adds a monster to the current player's party if there is room. The action parameter 
        must contain a monster name to look up in the monster database.
    
        :param game: The main game object that contains all the game's variables.
        :param action: The action (tuple) retrieved from the database that contains the action's
            parameters
    
        :type game: core.tools.Control
        :type action: Tuple
    
        :rtype: None
        :returns: None
    
        Valid Parameters: monster_name
    
        **Example:**
    
        >>> action
        ... (u'add_monster', u'Bulbatux', 1, 9)
        ...
        >>> monster = core.components.monster.Monster()
        >>> monster.load_from_db(action[1])
        ...
        >>> pprint.pprint(monster.__dict__)
        ... {'attack': 50,
        ...  'attack_modifier': [u'1', u'1.1', u'1.2'],
        ...  'back_battle_sprite': u'resources/gfx/sprites/battle/bulbatux-back.png',
        ...  'body': <core.components.fusion.Body instance at 0x2d0b3f8>,
        ...  'defense': 7,
        ...  'defense_modifier': [u'1', u'1.1', u'1.2'],
        ...  'front_battle_sprite': u'resources/gfx/sprites/battle/bulbatux-front.png',
        ...  'hp': 30,
        ...  'hp_modifier': [u'0.9', u'1', u'1.1'],
        ...  'level': 0,
        ...  'menu_sprite': u'resources/gfx/sprites/battle/bulbatux-menu01.png',
        ...  'monster_id': 1,
        ...  'moves': [],
        ...  'name': u'Bulbatux',
        ...  'special_attack': 9,
        ...  'special_attack_modifier': [u'1', u'1.1', u'1.2'],
        ...  'special_defense': 8,
        ...  'special_defense_modifier': [u'1', u'1.1', u'1.2'],
        ...  'speed': 7,
        ...  'speed_modifier': [u'1', u'1.1', u'1.2'],
        ...  'status': 'Normal',
        ...  'type1': u'grass',
        ...  'type2': u'poison'}
        ...
        >>> game.player1.add_monster(monster)
        >>> game.player1.monsters
        ... [<core.components.monster.Monster instance at 0x2d0b3b0>]
    
        """

        parameters = action[1].split(",")
        monster_name = parameters[0]
        monster_level = parameters[1]
        current_monster = monster.Monster()
        current_monster.load_from_db(monster_name)
        current_monster.set_level(int(monster_level))

        game.player1.add_monster(current_monster)
コード例 #3
0
ファイル: combat.py プロジェクト: erya008/Tuxemon
    def random_encounter(self, game, action, contexts):
        """Randomly starts a battle with a monster defined in the "encounter" table in the
        "monster.db" database. The chance that this will start a battle depends on the
        "encounter_rate" specified in the database. The "encounter_rate" number is the chance
        walking in to this tile will trigger a battle out of 100.

        :param game: The main game object that contains all the game's variables.
        :param action: The action (tuple) retrieved from the database that contains the action's
            parameters

        :type game: core.control.Control
        :type action: Tuple

        :rtype: None
        :returns: None

        Valid Parameters: encounter_slug

        """
        player1 = game.player1

        # Don't start a battle if we don't even have monsters in our party yet.
        if not self.check_battle_legal(player1):
            return False

        # Get the parameters to determine what encounter group we'll look up in the database.
        encounter_slug = action.parameters[0]

        # Look up the encounter details
        monsters = db.JSONDatabase()
        monsters.load("encounter")
        monsters.load("monster")

        # Keep an encounter variable that will let us know if we're going to start a battle.
        encounter = None

        # Get all the monsters associated with this encounter.
        encounters = monsters.database['encounter'][encounter_slug]['monsters']

        for item in encounters:
            # Perform a roll to see if this monster is going to start a battle.
            roll = random.randrange(1, 1000)
            if roll <= int(item['encounter_rate']):
                # Set our encounter details
                encounter = item

        # If a random encounter was successfully rolled, look up the monster and start the
        # battle.
        if encounter:

            logger.info("Start battle!")

            # Stop movement and keypress on the server.
            if game.isclient or game.ishost:
                game.client.update_player(game.player1.facing,
                                          event_type="CLIENT_START_BATTLE")

            # Create a monster object
            current_monster = monster.Monster()
            current_monster.load_from_db(encounter['monster'])

            # Set the monster's level based on the specified level range
            if len(encounter['level_range']) > 1:
                level = random.randrange(encounter['level_range'][0],
                                         encounter['level_range'][1])
            else:
                level = encounter['level_range'][0]

            # Set the monster's level
            current_monster.level = 1
            current_monster.set_level(level)

            # Create an NPC object which will be this monster's "trainer"
            npc = player.Npc()
            npc.monsters.append(current_monster)

            # Set the NPC object's AI model.
            npc.ai = ai.AI()

            # Add our players and setup combat
            # "queueing" it will mean it starts after the top of the stack is popped (or replaced)
            game.queue_state("CombatState",
                             players=(player1, npc),
                             combat_type="monster")

            # flash the screen
            game.push_state("FlashTransition")

            # Start some music!
            filename = "147066_pokemon.ogg"
            mixer.music.load(prepare.BASEDIR + "resources/music/" + filename)
            mixer.music.play(-1)
            game.current_music["status"] = "playing"
            game.current_music["song"] = filename
コード例 #4
0
ファイル: random_encounter.py プロジェクト: wgeyes/Tuxemon
    def start(self):
        player1 = self.game.player1

        # Don't start a battle if we don't even have monsters in our party yet.
        if not check_battle_legal(player1):
            return False

        # Get the parameters to determine what encounter group we'll look up in the database.
        encounter_slug = self.parameters.encounter_slug

        # Look up the encounter details
        monsters = db.JSONDatabase()
        monsters.load("encounter")
        monsters.load("monster")

        # Keep an encounter variable that will let us know if we're going to start a battle.
        encounter = None

        # Get all the monsters associated with this encounter.
        encounters = monsters.database['encounter'][encounter_slug]['monsters']

        for item in encounters:
            # Perform a roll to see if this monster is going to start a battle.
            roll = random.randrange(1, 1000)
            if roll <= int(item['encounter_rate']):
                # Set our encounter details
                encounter = item

        # If a random encounter was successfully rolled, look up the monster and start the
        # battle.
        if encounter:
            logger.info("Starting random encounter!")

            # Stop movement and keypress on the server.
            if self.game.isclient or self.game.ishost:
                self.game.client.update_player(
                    self.game.player1.facing, event_type="CLIENT_START_BATTLE")

            # Create a monster object
            current_monster = monster.Monster()
            current_monster.load_from_db(encounter['monster'])

            # Set the monster's level based on the specified level range
            if len(encounter['level_range']) > 1:
                level = random.randrange(encounter['level_range'][0],
                                         encounter['level_range'][1])
            else:
                level = encounter['level_range'][0]

            # Set the monster's level
            current_monster.level = 1
            current_monster.set_level(level)

            # Create an NPC object which will be this monster's "trainer"
            npc = player.Npc()
            npc.monsters.append(current_monster)
            npc.party_limit = 0

            # Set the NPC object's AI model.
            npc.ai = ai.AI()

            # Add our players and setup combat
            # "queueing" it will mean it starts after the top of the stack is popped (or replaced)
            self.game.queue_state("CombatState",
                                  players=(player1, npc),
                                  combat_type="monster")

            # flash the screen
            self.game.push_state("FlashTransition")

            # Start some music!
            filename = "147066_pokemon.ogg"
            mixer.music.load(prepare.BASEDIR + "resources/music/" + filename)
            mixer.music.play(-1)
            if self.game.current_music["song"]:
                self.game.current_music[
                    "previoussong"] = self.game.current_music["song"]
            self.game.current_music["status"] = "playing"
            self.game.current_music["song"] = filename
コード例 #5
0
    def start(self):
        # Don't start a battle if we don't even have monsters in our party yet.
        if not check_battle_legal(self.game.player1):
            logger.debug("battle is not legal, won't start")
            return False

        # Stop movement and keypress on the server.
        if self.game.isclient or self.game.ishost:
            self.game.client.update_player(self.game.player1.facing,
                                           event_type="CLIENT_START_BATTLE")

        # Start combat
        npc_slug = self.parameters.npc_slug

        # TODO: This should *really* be handled in the Npc initializer
        # Create an NPC object that will be used as our opponent
        npc = player.Npc(slug=npc_slug)

        # Look up the NPC's details from our NPC database
        npcs = db.JSONDatabase()
        npcs.load("npc")
        npc_details = npcs.database['npc'][npc_slug]

        # Set the NPC object's AI model.
        npc.ai = ai.AI()

        # Look up the NPC's monster party
        npc_party = npc_details['monsters']

        # Look up the monster's details
        monsters = db.JSONDatabase()
        monsters.load("monster")

        # Look up each monster in the NPC's party
        for npc_monster_details in npc_party:
            results = monsters.database['monster'][
                npc_monster_details['monster']]

            # Create a monster object for each monster the NPC has in their party.
            # TODO: unify save/load of monsters
            current_monster = monster.Monster()
            current_monster.load_from_db(npc_monster_details['monster'])
            current_monster.name = npc_monster_details['name']
            current_monster.level = npc_monster_details['level']
            current_monster.hp = npc_monster_details['hp']
            current_monster.current_hp = npc_monster_details['hp']
            current_monster.attack = npc_monster_details['attack']
            current_monster.defense = npc_monster_details['defense']
            current_monster.speed = npc_monster_details['speed']
            current_monster.special_attack = npc_monster_details[
                'special_attack']
            current_monster.special_defense = npc_monster_details[
                'special_defense']
            current_monster.experience_give_modifier = npc_monster_details[
                'exp_give_mod']
            current_monster.experience_required_modifier = npc_monster_details[
                'exp_req_mod']

            current_monster.type1 = results['types'][0]

            current_monster.set_level(current_monster.level)

            if len(results['types']) > 1:
                current_monster.type2 = results['types'][1]

            current_monster.load_sprite_from_db()

            pound = technique.Technique('technique_pound')

            current_monster.learn(pound)

            # Add our monster to the NPC's party
            npc.monsters.append(current_monster)

        # Add our players and setup combat
        logger.debug("Starting battle!")
        self.game.push_state("CombatState",
                             players=(self.game.player1, npc),
                             combat_type="trainer")

        # Start some music!
        logger.info("Playing battle music!")
        filename = "147066_pokemon.ogg"

        mixer.music.load(prepare.BASEDIR + "resources/music/" + filename)
        mixer.music.play(-1)

        if self.game.current_music["song"]:
            self.game.current_music["previoussong"] = self.game.current_music[
                "song"]
        self.game.current_music["status"] = "playing"
        self.game.current_music["song"] = filename
コード例 #6
0
    def start_battle(self, game, action):
        """Start a battle and switch to the combat module. The parameters must contain an NPC id
        in the NPC database.
            
        :param game: The main game object that contains all the game's variables.
        :param action: The action (tuple) retrieved from the database that contains the action's
            parameters
            
        :type game: core.tools.Control
        :type action: Tuple
    
        :rtype: None
        :returns: None
    
        Valid Parameters: npc_id
    
        **Examples:**
            
        >>> action
        ... (u'start_battle', u'1', 1, 9)
        
        """
    
        # Don't start a battle if we don't even have monsters in our party yet.
        if len(game.player1.monsters) < 1:
            logger.warning("Cannot start battle, player has no monsters!")
            return False
    
        # Start combat
        npc_id = int(action[1])
            
        # Create an NPC object that will be used as our opponent
        npc = player.Npc()
            
        # Look up the NPC's details from our NPC database
        npcs = db.JSONDatabase()
        npcs.load("npc")
        npc_details = npcs.database['npc'][npc_id]
    
        # Set the NPC object with the details fetched from the database.
        npc.name = npc_details['name']
    
        # Set the NPC object's AI model.
        npc.ai = ai.AI()
            
        # Look up the NPC's monster party
        npc_party = npc_details['monsters']
    
        # Look up the monster's details
        monsters = db.JSONDatabase()
        monsters.load("monster")
    
        # Look up each monster in the NPC's party
        for npc_monster_details in npc_party:
            results = monsters.database['monster'][npc_monster_details['monster_id']]
    
            # Create a monster object for each monster the NPC has in their party.
            current_monster = monster.Monster()
            current_monster.name = npc_monster_details['name']
            current_monster.monster_id = npc_monster_details['monster_id']
            current_monster.level = npc_monster_details['level']
            current_monster.hp = npc_monster_details['hp']
            current_monster.current_hp = npc_monster_details['hp']
            current_monster.attack = npc_monster_details['attack']
            current_monster.defense = npc_monster_details['defense']
            current_monster.speed = npc_monster_details['speed']
            current_monster.special_attack = npc_monster_details['special_attack']
            current_monster.special_defense = npc_monster_details['special_defense']
            current_monster.experience_give_modifier = npc_monster_details['exp_give_mod']
            current_monster.experience_required_modifier = npc_monster_details['exp_req_mod']
    
            current_monster.type1 = results['types'][0]
    
            if len(results['types']) > 1:
                current_monster.type2 = results['types'][1]
    
            current_monster.load_sprite_from_db()
    
            pound = monster.Technique('Pound')
                
            current_monster.learn(pound)
            
            # Add our monster to the NPC's party
            npc.monsters.append(current_monster)
    
        # Add our players and start combat
        game.state_dict["COMBAT"].players.append(game.player1)
        game.state_dict["COMBAT"].players.append(npc)
        game.state_dict["COMBAT"].combat_type = "trainer"
        #game.state_dict["WORLD"].combat_started = True
        game.state_dict["WORLD"].start_battle_transition = True

        # Start some music!
        logger.info("Playing battle music!")
        filename = "147066_pokemon.ogg"
        mixer.music.load("resources/music/" + filename)
        mixer.music.play(-1)
コード例 #7
0
    def random_encounter(self, game, action):
        """Randomly starts a battle with a monster defined in the "encounter" table in the
        "monster.db" database. The chance that this will start a battle depends on the
        "encounter_rate" specified in the database. The "encounter_rate" number is the chance
        walking in to this tile will trigger a battle out of 100.
    
        :param game: The main game object that contains all the game's variables.
        :param action: The action (tuple) retrieved from the database that contains the action's
            parameters
    
        :type game: core.tools.Control
        :type action: Tuple
    
        :rtype: None
        :returns: None
    
        Valid Parameters: encounter_id
    
        """
    
        player1 = game.player1
    
        # Don't start a battle if we don't even have monsters in our party yet.
        if len(player1.monsters) < 1:
            logger.warning("Cannot start battle, player has no monsters!")
            return False
        else:
            if player1.monsters[0].current_hp <= 0:
                logger.warning("Cannot start battle, player's monsters are all DEAD")
                return False
    
        # Get the parameters to determine what encounter group we'll look up in the database.
        encounter_id = int(action[1])
    
        # Look up the encounter details
        monsters = db.JSONDatabase()
        monsters.load("encounter")
        monsters.load("monster")
    
        # Keep an encounter variable that will let us know if we're going to start a battle.
        encounter = None
    
        # Get all the monsters associated with this encounter.
        encounters = monsters.database['encounter'][encounter_id]['monsters']
    
        for item in encounters:
            # Perform a roll to see if this monster is going to start a battle.
            roll = random.randrange(1,100)
            rate = range(1, int(item['encounter_rate']) + 1)
            if roll in rate:
                # Set our encounter details
                encounter = item
    
        # If a random encounter was successfully rolled, look up the monster and start the
        # battle.
        if encounter:
            logger.info("Start battle!")
                
            # Create a monster object
            current_monster = monster.Monster()
            current_monster.load_from_db(encounter['monster_id'])
    
            # Set the monster's level based on the specified level range
            if len(encounter['level_range']) > 1:
                level = random.randrange(encounter['level_range'][0], encounter['level_range'][1])
            else:
                level = encounter['level_range'][0]
    
            # Set the monster's level
            current_monster.level = level
    
            # Create an NPC object which will be this monster's "trainer"
            npc = player.Npc()
            npc.monsters.append(current_monster)
    
            # Set the NPC object's AI model.
            npc.ai = ai.AI()
    
            # Add our players and start combat
            game.state_dict["COMBAT"].players.append(player1)
            game.state_dict["COMBAT"].players.append(npc)
            game.state_dict["COMBAT"].combat_type = "monster"
            game.state_dict["WORLD"].start_battle_transition = True

            # Start some music!
            filename = "147066_pokemon.ogg"
            mixer.music.load("resources/music/" + filename)
            mixer.music.play(-1)
            game.current_music["status"] = "playing"
            game.current_music["song"] = filename

            # Stop the player's movement
            game.state_dict["WORLD"].menu_blocking = True
            player1.moving = False
            player1.direction = {'down': False, 'left': False, 'right': False, 'up': False}