Esempio n. 1
0
    def post(self):
        data = PlayerConfrontation.parse.parse_args()
        currentPlayer = PlayerModel.findByPlayerId(current_identity.id)
        enemy = PlayerModel.findByPlayerId(data['player'])
        location = LocationModel.findById(currentPlayer.locationId)

        playerList = []
        playerCount = 0
        for player in location.players:
            if (player.role == 'player'
                    and player.playerName != currentPlayer.playerName):
                playerCount = playerCount + 1
                playerList.append(player.json())

        if (playerCount == 0):
            return {'message': 'Target Selected'}
        else:
            return jsonify(playerList)
Esempio n. 2
0
    def get(self):
        """ Class method: GET
            Endpoint: /player-location

            Will return a players current location details only if that player is authorized and part of a lobby.
        """
        player = PlayerModel.findByPlayerId(current_identity.id)
        if (player.locationId == -1):
            return {'message': 'You are not currently part of a lobby!'}
        location = LocationModel.findById(player.locationId)
        return location.json()
Esempio n. 3
0
    def post(self):
        """ Class method: POST
            Endpoint: /player-location

            Will change a players location depending on the id of the location they want to go. 
            Error check must look for the following. If player is part of the lobby, 
        """
        data = PlayerLocation.parse.parse_args()
        player = PlayerModel.findByPlayerId(current_identity.id)

        if (player.locationId == data['locationId']):
            return {'message': 'Already at that location.'}

        try:

            currentLocation = LocationModel.findById(player.locationId)
            currentLocation.numOfPlayers = currentLocation.numOfPlayers - 1

            player.locationId = data['locationId']
            player.stamina = player.stamina - 10

            newLocation = LocationModel.findById(data['locationId'])
            newLocation.numOfPlayers = newLocation.numOfPlayers + 1

            player.save_to_db()

            # Save new locations
            currentLocation.save_to_db()
            newLocation.save_to_db()

            if (player.stamina == 0):
                player.status = "sleep"
                player.save_to_db()
                return {
                    'message': 'You are out of stamina and have fallen asleep!'
                }

        except:
            return {'message': 'Error saving to the DB!'}

        return {'message': 'You have succesfully changed locations.'}
Esempio n. 4
0
    def post(self):
        """ Class method: POST
            /action

        """
        data = PlayerAction.parse.parse_args()

        if (current_identity.status == 'sleep' and data['action'] != 'wakeup'):
            return {'message': 'You must be awake to take action!'}

        elif (data['action'] == 'attack'):
            player = PlayerModel.findByPlayerName(current_identity.playerName)
            target = PlayerModel.findByPlayerName(data['target'])
            location = LocationModel.findById(player.locationId)

            if (target.status == 'dead'):
                return {'message': 'target already dead'}

            # p is a player from the list of players in the current location
            for p in location.players:
                if (data['target'] == p.playerName):
                    # once target is found, call confront method from player who attacked
                    print(player.playerName)
                    winner = player.confront(p)
                    if (winner == player.playerName):
                        target.status = 'dead'
                        target.save_to_db()
                        return {'message': 'kill'}
                    else:
                        player.status = 'dead'
                        player.save_to_db()
                        return {'message': 'dead'}

            return {'message': 'target was not in the location'}

        elif (data['action'] == 'sleep'):
            player = PlayerModel.findByPlayerId(current_identity.id)
            player.stamina = player.stamina + 10
            player.status = 'sleep'
            player.save_to_db()
            return {'message': 'You decided to sleep: +10 stamina'}

        elif (data['action'] == 'wakeup'):
            player = PlayerModel.findByPlayerId(current_identity.id)
            player.status = 'none'
            player.save_to_db()
            return {'message': 'You are now awake'}

        elif (data['action'] == 'workout'):
            player = PlayerModel.findByPlayerId(current_identity.id)

            if (player.stamina == 0):
                player.status = "sleep"
                player.save_to_db()
                return {
                    'message': 'You are out of stamina and have fallen asleep!'
                }

            player.strength = player.strength + 10
            player.stamina = player.stamina - 10
            player.status = "sleep"

            player.save_to_db()
            return {
                'message': 'You decided to sleep: +10 strength -10 stamina'
            }

        else:
            return {'message': 'Action is not supported!'}