Пример #1
0
    def initialize_socket(self,
                          socket_id=None,
                          hero=0,
                          weapon=0,
                          armor=0,
                          jewelry=0):
        if not socket_id:
            socket_id = self.max_socket_id() + 1
            socket = MongoSocket()
        else:
            try:
                socket = self.formation.sockets[str(socket_id)]
            except KeyError:
                raise SanguoException(errormsg.FORMATION_NONE_EXIST_SOCKET,
                                      self.char_id, "Formation Save Socket",
                                      "Socket {0} not exist".format(socket_id))

        socket.hero = hero
        socket.weapon = weapon
        socket.armor = armor
        socket.jewelry = jewelry

        self.formation.sockets[str(socket_id)] = socket
        self.formation.save()

        return socket_id
Пример #2
0
    def open_socket(self, all_amount):
        # 条件达成自动开启新的socket
        opened = self.opened_socket_amount()
        needed = all_amount - opened
        if needed <= 0:
            return False

        now_id = self.max_socket_id()
        new_socket_ids = []

        msg = protomsg.AddSocketNotify()

        # new socket
        for i in range(needed):
            socket_id = now_id + 1
            socket = MongoSocket()
            socket.hero = 0
            socket.weapon = 0
            socket.armor = 0
            socket.jewelry = 0
            socket.horse = 0
            self.formation.sockets[str(socket_id)] = socket

            new_socket_ids.append(socket_id)
            now_id += 1

            msg_s = msg.sockets.add()
            self._msg_socket(msg_s, socket_id, socket)

        # put socket in formation
        for index, sid in enumerate(self.formation.formation):
            if not new_socket_ids:
                break

            if sid == 0:
                self.formation.formation[index] = new_socket_ids[0]
                new_socket_ids.pop(0)

        self.formation.save()
        publish_to_char(self.char_id, pack_msg(msg))
        self.send_formation_notify()
        return True
Пример #3
0
    def open_socket(self, all_amount):
        # 条件达成自动开启新的socket
        opened = self.opened_socket_amount()
        needed = all_amount - opened
        if needed <= 0:
            return False

        now_id = self.max_socket_id()
        new_socket_ids = []

        msg = protomsg.AddSocketNotify()

        # new socket
        for i in range(needed):
            socket_id = now_id + 1
            socket = MongoSocket()
            socket.hero = 0
            socket.weapon = 0
            socket.armor = 0
            socket.jewelry = 0
            socket.horse = 0
            self.formation.sockets[str(socket_id)] = socket

            new_socket_ids.append(socket_id)
            now_id += 1

            msg_s = msg.sockets.add()
            self._msg_socket(msg_s, socket_id, socket)

        # put socket in formation
        for index, sid in enumerate(self.formation.formation):
            if not new_socket_ids:
                break

            if sid == 0:
                self.formation.formation[index] = new_socket_ids[0]
                new_socket_ids.pop(0)

        self.formation.save()
        publish_to_char(self.char_id, pack_msg(msg))
        self.send_formation_notify()
        return True
Пример #4
0
    def initialize_socket(self, socket_id=None, hero=0, weapon=0, armor=0, jewelry=0):
        if not socket_id:
            socket_id = self.max_socket_id() + 1
            socket = MongoSocket()
        else:
            try:
                socket = self.formation.sockets[str(socket_id)]
            except KeyError:
                raise SanguoException(
                    errormsg.FORMATION_NONE_EXIST_SOCKET,
                    self.char_id,
                    "Formation Save Socket",
                    "Socket {0} not exist".format(socket_id)
                )

        socket.hero = hero
        socket.weapon = weapon
        socket.armor = armor
        socket.jewelry = jewelry

        self.formation.sockets[str(socket_id)] = socket
        self.formation.save()

        return socket_id