Пример #1
0
    def on_connect(self, player: models.Player, payload: dict):
        """
        Initial connection information, providing the server
        with the identifying credentials of the player.  This
        message will not propagate data down to other players.
        To inform other players of your presence, you must
        set the floor you are are after connecting
        """
        print("connecting player data")
        player.appearance = payload['appearance']
        player.steam_id = payload['id']
        player.name = payload['name']
        player.loaded = True
        player.dead = False

        return None
Пример #2
0
    def on_dead(self, player: models.Player, payload: dict):
        """
        Handles informing other players of when and where
        and player dies on the floor
        """
        player.dead = True
        
        # don't allow stacking
        with db.transaction():
            models.DeadPlayer.delete().where(
                models.DeadPlayer.x == player.position[0],
                models.DeadPlayer.y == player.position[1],
                models.DeadPlayer.level == player.floor
            ).execute()

        # move player's tombstone if they've already died today
        with db.transaction():
            deadPlayer, created = models.DeadPlayer.get_or_create(
                steam_id=player.id,
                defaults={
                    'x': player.position[0],
                    'y': player.position[1],
                    'level': player.floor,
                    'steam_id': player.id,
                    'steam_name': player.name,
                    'dead_to': payload['dead_to'],
                }
            )
            if not created:
                deadPlayer.dead_to = payload['dead_to']
                deadPlayer.x = player.position[0]
                deadPlayer.y = player.position[1]
                deadPlayer.level = player.floor
                deadPlayer.save()
             
        # send the message to everyone so they know who died
        return self._send_message(target=player.floor, message={
            'type': 'dead',
            **dict(deadPlayer)
        }, exclude=[player])