Beispiel #1
0
    def add(self, staff_original_id, send_notify=True, trig_signal=True):
        if not ConfigStaffNew.get(staff_original_id):
            raise GameException(ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST"))

        unique_id = make_string_id()
        doc = MongoStaff.document_staff()
        doc['oid'] = staff_original_id

        MongoStaff.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {'staffs.{0}'.format(unique_id): doc}},
        )

        if send_notify:
            self.send_notify(ids=[unique_id])

        staff_new_add_signal.send(
            sender=None,
            server_id=self.server_id,
            char_id=self.char_id,
            staffs_info=[(staff_original_id, unique_id), ],
            force_load_staffs=send_notify,
        )

        if trig_signal:
            self.after_staffs_change_for_trig_signal()
        return unique_id
Beispiel #2
0
    def add(self, staff_original_id, send_notify=True, trig_signal=True):
        if not ConfigStaffNew.get(staff_original_id):
            raise GameException(
                ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST"))

        unique_id = make_string_id()
        doc = MongoStaff.document_staff()
        doc['oid'] = staff_original_id

        MongoStaff.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'staffs.{0}'.format(unique_id): doc
            }},
        )

        if send_notify:
            self.send_notify(ids=[unique_id])

        staff_new_add_signal.send(
            sender=None,
            server_id=self.server_id,
            char_id=self.char_id,
            staffs_info=[
                (staff_original_id, unique_id),
            ],
            force_load_staffs=send_notify,
        )

        if trig_signal:
            self.after_staffs_change_for_trig_signal()
        return unique_id
Beispiel #3
0
    def batch_add(self, staffs):
        # [(oid, amount), ...]

        updater = {}
        unique_id_list = []

        info = []

        for oid, amount in staffs:
            if not ConfigStaffNew.get(oid):
                raise GameException(ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST"))

            for i in range(amount):
                unique_id = make_string_id()
                doc = MongoStaff.document_staff()
                doc['oid'] = oid

                unique_id_list.append(unique_id)
                updater['staffs.{0}'.format(unique_id)] = doc
                info.append((oid, unique_id))

        MongoStaff.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': updater}
        )

        self.send_notify(ids=unique_id_list)

        staff_new_add_signal.send(
            sender=None,
            server_id=self.server_id,
            char_id=self.char_id,
            staffs_info=info,
            force_load_staffs=True,
        )

        self.after_staffs_change_for_trig_signal()
Beispiel #4
0
    def batch_add(self, staffs):
        # [(oid, amount), ...]

        updater = {}
        unique_id_list = []

        info = []

        for oid, amount in staffs:
            if not ConfigStaffNew.get(oid):
                raise GameException(
                    ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST"))

            for i in range(amount):
                unique_id = make_string_id()
                doc = MongoStaff.document_staff()
                doc['oid'] = oid

                unique_id_list.append(unique_id)
                updater['staffs.{0}'.format(unique_id)] = doc
                info.append((oid, unique_id))

        MongoStaff.db(self.server_id).update_one({'_id': self.char_id},
                                                 {'$set': updater})

        self.send_notify(ids=unique_id_list)

        staff_new_add_signal.send(
            sender=None,
            server_id=self.server_id,
            char_id=self.char_id,
            staffs_info=info,
            force_load_staffs=True,
        )

        self.after_staffs_change_for_trig_signal()