Exemple #1
0
    def handle_wiact_message(self, data):
        if self.get_gs() != GameState.PLAY:
            # TODO: Send response back to the client
            return

        item_id = data['iid']

        msg = MessageBuf()
        msg.add_uint8(RelMessageType.RMSG_WDGMSG)
        msg.add_uint16(item_id)
        msg.add_string('take')
        msg.add_list([Coords.Z, Coords.Z])
        self.queue_rmsg(msg)

        wound_id = int(data['wid'])

        msg = MessageBuf()
        msg.add_uint8(RelMessageType.RMSG_WDGMSG)
        msg.add_uint16(self.chr_wdg_id)
        msg.add_string('wiact')
        msg.add_list([
            wound_id,
            0  # modflags
        ])
        self.queue_rmsg(msg)
Exemple #2
0
    def handle_play_message(self, data):
        if self.charlist_wdg_id == -1:
            return

        char_name = data['char_name']

        msg = MessageBuf()
        msg.add_uint8(RelMessageType.RMSG_WDGMSG)
        msg.add_uint16(self.charlist_wdg_id)
        msg.add_string('play')
        msg.add_list([char_name])
        self.queue_rmsg(msg)
Exemple #3
0
    def handle_pmchat_message(self, data):
        if self.get_gs() != GameState.PLAY or self.buddy_wdg_id == -1:
            # TODO: Send response back to the client
            return

        kin_id = data['id']

        msg = MessageBuf()
        msg.add_uint8(RelMessageType.RMSG_WDGMSG)
        msg.add_uint16(self.buddy_wdg_id)
        msg.add_string('chat')
        msg.add_list([kin_id])
        self.queue_rmsg(msg)
Exemple #4
0
    def handle_drop_message(self, data):
        if self.get_gs() != GameState.PLAY:
            # TODO: Send response back to the client
            return

        coords = data['coords']

        msg = MessageBuf()
        msg.add_uint8(RelMessageType.RMSG_WDGMSG)
        msg.add_uint16(self.inv_wdg_id)
        msg.add_string('drop')
        msg.add_list([Coord(coords['x'], coords['y'])])
        self.queue_rmsg(msg)
Exemple #5
0
    def handle_transfer_message(self, data):
        if self.get_gs() != GameState.PLAY:
            # TODO: Send response back to the client
            return

        item_id = data['id']

        msg = MessageBuf()
        msg.add_uint8(RelMessageType.RMSG_WDGMSG)
        msg.add_uint16(item_id)
        msg.add_string('transfer')
        msg.add_list([Coords.Z])  # Ignored
        self.queue_rmsg(msg)
Exemple #6
0
    def handle_msg_message(self, data):
        if self.get_gs() != GameState.PLAY:
            # TODO: Send response back to the client
            return

        chat_id = data['id']
        chat_msg = data['msg']

        msg = MessageBuf()
        msg.add_uint8(RelMessageType.RMSG_WDGMSG)
        msg.add_uint16(chat_id)
        msg.add_string('msg')
        msg.add_list([chat_msg])
        self.queue_rmsg(msg)
Exemple #7
0
    def handle_cl_message(self, data):
        if self.get_gs() != GameState.PLAY or self.flowermenu_wdg_id == -1:
            # TODO: Send response back to the client
            return

        option = data['option']

        msg = MessageBuf()
        msg.add_uint8(RelMessageType.RMSG_WDGMSG)
        msg.add_uint16(self.flowermenu_wdg_id)
        msg.add_string('cl')
        if option == -1:
            msg.add_list([option])
        else:
            msg.add_list([
                option,
                0  # modflags
            ])
        self.queue_rmsg(msg)

        self.flowermenu_wdg_id = -1  # TODO: Handle it on DSTWDG message or smth like that
Exemple #8
0
    def handle_transfer_message(self, data):
        if self.get_gs() != GameState.PLAY:
            # TODO: Send response back to the client
            return

        item_id = data['id']

        coords = None
        with self.items_lock:
            for item in self.items:
                if item.wdg_id == item_id:
                    coords = copy.copy(item.coords)
        if coords is None:
            # TODO: Send response back to the client
            return

        msg = MessageBuf()
        msg.add_uint8(RelMessageType.RMSG_WDGMSG)
        msg.add_uint16(item_id)
        msg.add_string('transfer')
        msg.add_list([coords])
        self.queue_rmsg(msg)
Exemple #9
0
    def handle_clicknearest_message(self, data):
        if self.get_gs() != GameState.PLAY:
            # TODO: Send response back to the client
            return

        if self.mapview_wdg_id == -1:
            self.sendMessage(
                unicode(
                    json.dumps({
                        'action': 'clicknearest',
                        'success': False,
                        'reason': 'Map has not been constructed yet'
                    })))
            return

        obj_name = data['name']
        if obj_name != 'table':
            self.sendMessage(
                unicode(
                    json.dumps({
                        'action': 'clicknearest',
                        'success': False,
                        'reason': 'Unsupported object name'
                    })))
            return

        with self.gobs_lock:
            tables = []
            pl = None
            for gob_id, gob in self.gobs.iteritems():
                if gob.c is None:
                    continue
                if gob.is_table():
                    tables.append(gob)
                elif gob_id == self.pgob_id:
                    pl = gob
            if len(tables) == 0:
                self.sendMessage(
                    unicode(
                        json.dumps({
                            'action':
                            'clicknearest',
                            'success':
                            False,
                            'reason':
                            'No tables found (try again later)'
                        })))
                return
            if pl is None:
                self.sendMessage(
                    unicode(
                        json.dumps({
                            'action':
                            'clicknearest',
                            'success':
                            False,
                            'reason':
                            'Player object has not been received yet'
                        })))
                return

            nearest = None
            nearestc = None
            for table in tables:
                d = Coord.diff(pl.c, table.c)
                if nearest is None or d.x + d.y < nearestc:
                    nearest = table
                    nearestc = d.x + d.y

            msg = MessageBuf()
            msg.add_uint8(RelMessageType.RMSG_WDGMSG)
            msg.add_uint16(self.mapview_wdg_id)
            msg.add_string('click')
            msg.add_list([
                Coords.Z,  # pc (not used)
                Coords.Z,  # mc (not used)
                3,  # RMB
                0,  # modflags (no Alt / Ctrl / etc)
                0,  # no overlay
                nearest.gob_id,
                Coord.floor(nearest.c, Coords.POSRES),
                0,  # overlay ID
                -1  # click ID
            ])
            self.queue_rmsg(msg)

            self.sendMessage(
                unicode(json.dumps({
                    'action': 'clicknearest',
                    'success': True
                })))