Exemplo n.º 1
0
    def make_slot_msg(self, slot_ids=None):
        if not slot_ids:
            slot_ids = range(1, MAX_SLOT_AMOUNT + 1)

        sm = StaffManger(self.server_id, self.char_id)

        msgs = []
        for _id in slot_ids:
            msg_slot = MsgFormationSlot()
            msg_slot.slot_id = int(_id)

            try:
                data = self.doc['slots'][str(_id)]
            except KeyError:
                msg_slot.status = FORMATION_SLOT_NOT_OPEN
            else:
                if not data['staff_id']:
                    msg_slot.status = FORMATION_SLOT_EMPTY
                else:
                    msg_slot.status = FORMATION_SLOT_USE
                    msg_slot.staff_id = data['staff_id']
                    msg_slot.unit_id = data['unit_id']
                    if data['unit_id']:
                        msg_slot.position = self.doc['position'].index(int(_id))
                    else:
                        msg_slot.position = -1

                    msg_slot.staff_oid = sm.get_staff_object(data['staff_id']).oid
                    msg_slot.policy = data.get('policy', 1)

            msgs.append(msg_slot)

        return msgs
Exemplo n.º 2
0
    def make_protobuf(self):
        msg = MsgPlunderFormation()
        msg.way = self.way_id

        msg.power = self.power

        sm = StaffManger(self.server_id, self.char_id)

        for k, v in self.doc['slots'].iteritems():
            msg_slot = msg.formation.add()
            msg_slot.slot_id = int(k)
            if v['staff_id']:
                msg_slot.status = FORMATION_SLOT_USE
                msg_slot.staff_id = v['staff_id']
                msg_slot.unit_id = v['unit_id']
                if v['unit_id']:
                    msg_slot.position = self.doc['position'].index(int(k))
                else:
                    msg_slot.position = -1

                msg_slot.staff_oid = sm.get_staff_object(v['staff_id']).oid
                msg_slot.policy = v.get('policy', 1)
            else:
                msg_slot.status = FORMATION_SLOT_EMPTY

        skill_sequence = self.get_skill_sequence()
        for k, v in skill_sequence.iteritems():
            notify_skill_sequence = msg.skill_sequence.add()
            notify_skill_sequence.id = k
            notify_skill_sequence.staff_id.extend(v)

        return msg
Exemplo n.º 3
0
    def _get_value_for_task_condition(self):
        # 给任务条件用的
        # 要求上阵6人,每人都要有 键盘,鼠标,显示器装备
        from core.bag import Bag

        staffs = self.in_formation_staffs().keys()
        if len(staffs) < 6:
            return 0, 0

        qualities = []
        levels = []
        sm = StaffManger(self.server_id, self.char_id)
        bag = Bag(self.server_id, self.char_id)

        for sid in staffs:
            obj = sm.get_staff_object(sid)
            for bag_slot_id in [obj.equip_keyboard, obj.equip_mouse, obj.equip_monitor]:
                if not bag_slot_id:
                    return 0, 0

                item_data = bag.get_slot(bag_slot_id)
                qualities.append(ConfigItemNew.get(item_data['item_id']).quality)
                levels.append(item_data['level'])

        return min(qualities), min(levels)
Exemplo n.º 4
0
    def make_protobuf(self):
        msg = MsgPlunderFormation()
        msg.way = self.way_id

        msg.power = self.power

        sm = StaffManger(self.server_id, self.char_id)

        for k, v in self.doc['slots'].iteritems():
            msg_slot = msg.formation.add()
            msg_slot.slot_id = int(k)
            if v['staff_id']:
                msg_slot.status = FORMATION_SLOT_USE
                msg_slot.staff_id = v['staff_id']
                msg_slot.unit_id = v['unit_id']
                if v['unit_id']:
                    msg_slot.position = self.doc['position'].index(int(k))
                else:
                    msg_slot.position = -1

                msg_slot.staff_oid = sm.get_staff_object(v['staff_id']).oid
                msg_slot.policy = v.get('policy', 1)
            else:
                msg_slot.status = FORMATION_SLOT_EMPTY

        skill_sequence = self.get_skill_sequence()
        for k, v in skill_sequence.iteritems():
            notify_skill_sequence = msg.skill_sequence.add()
            notify_skill_sequence.id = k
            notify_skill_sequence.staff_id.extend(v)

        return msg
Exemplo n.º 5
0
    def load_formation_staffs(self):
        # NOTE: 这段代码其实是从 Club.force_load_staffs 抄来的
        from core.formation import Formation
        from core.unit import UnitManager
        from core.talent import TalentManager
        from core.collection import Collection
        from core.party import Party
        from core.inspire import Inspire

        self.formation_staffs = []
        """:type: list[core.staff.Staff]"""

        sm = StaffManger(self.server_id, self.char_id)
        fm = Formation(self.server_id, self.char_id)
        um = UnitManager(self.server_id, self.char_id)
        ins = Inspire(self.server_id, self.char_id)

        staffs = sm.get_staffs_data()
        in_formation_staffs = self.in_formation_staffs()

        for k, v in in_formation_staffs.iteritems():
            obj = Staff(self.server_id, self.char_id, k, staffs[k])
            self.formation_staffs.append(obj)

            obj.policy = in_formation_staffs[k]['policy']
            obj.formation_position = in_formation_staffs[k]['position']
            unit_id = in_formation_staffs[k]['unit_id']
            if unit_id:
                obj.set_unit(um.get_unit_object(unit_id))

        club = Club(self.server_id, self.char_id, load_staffs=False)
        club.formation_staffs = self.formation_staffs

        working_staff_oids = self.working_staff_oids()

        for obj in self.formation_staffs:
            obj.check_qianban(working_staff_oids)
            obj.add_self_talent_effect(club)

        talent_effects_1 = TalentManager(self.server_id,
                                         self.char_id).get_talent_effects()
        talent_effects_2 = Collection(self.server_id,
                                      self.char_id).get_talent_effects()
        talent_effects_3 = fm.get_talent_effects()
        talent_effects_4 = Party(self.server_id,
                                 self.char_id).get_talent_effects()

        club.add_talent_effects(talent_effects_1)
        club.add_talent_effects(talent_effects_2)
        club.add_talent_effects(talent_effects_3)
        club.add_talent_effects(talent_effects_4)

        config_inspire_level_addition, config_inspire_step_addition = ins.get_addition_config(
        )

        for obj in self.formation_staffs:
            obj.config_inspire_level_addition = config_inspire_level_addition
            obj.config_inspire_step_addition = config_inspire_step_addition
            obj.calculate()
Exemplo n.º 6
0
    def create(cls, server_id, char_id, club_name, club_flag):
        from core.staff import StaffManger
        from core.formation import Formation
        from core.mail import MailManager
        from apps.config.models import Mail as ModelMail

        doc = MongoCharacter.document()
        doc['_id'] = char_id
        doc['create_at'] = arrow.utcnow().timestamp

        doc['name'] = club_name
        doc['flag'] = club_flag
        doc['gold'] = CHAR_INIT_GOLD
        doc['diamond'] = CHAR_INIT_DIAMOND
        doc['crystal'] = CHAR_INIT_CRYSTAL
        doc['gas'] = CHAR_INIT_GAS

        sm = StaffManger(server_id, char_id)

        formation_init_data = []
        for staff_id, unit_id in CHAR_INIT_STAFFS:
            uid = sm.add(staff_id, send_notify=False, trig_signal=False)
            formation_init_data.append((uid, unit_id))

        fm = Formation(server_id, char_id)
        fm.initialize(formation_init_data)

        MongoCharacter.db(server_id).insert_one(doc)

        # add welfare mail
        start_time = get_start_time_of_today()
        condition = Q(send_at__gte=start_time.format("YYYY-MM-DD HH:mm:ssZ")) &\
                    Q(send_at__lte=arrow.utcnow().format("YYYY-MM-DD HH:mm:ssZ"))
        mails = ModelMail.objects.filter(condition)

        m = MailManager(server_id, char_id)
        for m_obj in mails:
            if not m_obj.welfare:
                continue

            ok = False
            if m_obj.condition_type == 1:
                ok = True
            elif m_obj.condition_type == 2 and server_id in m_obj.get_parsed_condition_value():
                ok = True
            elif m_obj.condition_type == 3 and server_id not in m_obj.get_parsed_condition_value():
                ok = True

            if not ok:
                continue

            if m_obj.items:
                rc = ResourceClassification.classify(m_obj.get_parsed_items())
                attachment = rc.to_json()
            else:
                attachment = ""

            m.add(m_obj.title, m_obj.content, attachment=attachment, send_notify=False)
Exemplo n.º 7
0
    def add(self, server_id, char_id, message=""):
        from core.club import Club
        from core.bag import Bag
        from core.staff import StaffManger, StaffRecruit
        from core.talent import TalentManager
        from core.territory import Territory
        from core.vip import VIP
        from core.arena import Arena
        from core.energy import Energy
        from core.plunder import Plunder

        club_property = self.money_as_text_dict()
        if self.club_exp:
            club_property['exp'] = self.club_exp
        if club_property:
            club_property['message'] = message
            Club(server_id, char_id).update(**club_property)

        if self.vip_exp:
            VIP(server_id, char_id).add_exp(self.vip_exp)

        if self.bag:
            bag = Bag(server_id, char_id)
            bag.batch_add(self.bag)

        sm = StaffManger(server_id, char_id)
        if self.staff:
            sm.batch_add(self.staff)

        if self.staff_exp_pool:
            sm.add_exp_pool(self.staff_exp_pool)

        if self.talent_point:
            TalentManager(server_id, char_id).add_talent_points(self.talent_point)

        if self.arena_point:
            Arena(server_id, char_id).add_point(self.arena_point)

        if self.territory_product:
            Territory(server_id, char_id).add_product(self.territory_product)

        if self.work_card:
            Territory(server_id, char_id).add_work_card(self.work_card)

        if self.energy:
            Energy(server_id, char_id).add(self.energy)

        if self.staff_recruit_score:
            StaffRecruit(server_id, char_id).add_score(self.staff_recruit_score)

        if self.station_exp:
            Plunder(server_id, char_id).add_station_exp(self.station_exp)

        if self.resource_data:
            _r = _Resource()
            _r.resource = dict(self.resource_data)
            _r.add(server_id, char_id)
Exemplo n.º 8
0
    def load_formation_staffs(self):
        # NOTE: 这段代码其实是从 Club.force_load_staffs 抄来的
        from core.formation import Formation
        from core.unit import UnitManager
        from core.talent import TalentManager
        from core.collection import Collection
        from core.party import Party
        from core.inspire import Inspire

        self.formation_staffs = []
        """:type: list[core.staff.Staff]"""

        sm = StaffManger(self.server_id, self.char_id)
        fm = Formation(self.server_id, self.char_id)
        um = UnitManager(self.server_id, self.char_id)
        ins = Inspire(self.server_id, self.char_id)

        staffs = sm.get_staffs_data()
        in_formation_staffs = self.in_formation_staffs()

        for k, v in in_formation_staffs.iteritems():
            obj = Staff(self.server_id, self.char_id, k, staffs[k])
            self.formation_staffs.append(obj)

            obj.policy = in_formation_staffs[k]['policy']
            obj.formation_position = in_formation_staffs[k]['position']
            unit_id = in_formation_staffs[k]['unit_id']
            if unit_id:
                obj.set_unit(um.get_unit_object(unit_id))

        club = Club(self.server_id, self.char_id, load_staffs=False)
        club.formation_staffs = self.formation_staffs

        working_staff_oids = self.working_staff_oids()

        for obj in self.formation_staffs:
            obj.check_qianban(working_staff_oids)
            obj.add_self_talent_effect(club)

        talent_effects_1 = TalentManager(self.server_id, self.char_id).get_talent_effects()
        talent_effects_2 = Collection(self.server_id, self.char_id).get_talent_effects()
        talent_effects_3 = fm.get_talent_effects()
        talent_effects_4 = Party(self.server_id, self.char_id).get_talent_effects()

        club.add_talent_effects(talent_effects_1)
        club.add_talent_effects(talent_effects_2)
        club.add_talent_effects(talent_effects_3)
        club.add_talent_effects(talent_effects_4)

        config_inspire_level_addition, config_inspire_step_addition = ins.get_addition_config()

        for obj in self.formation_staffs:
            obj.config_inspire_level_addition = config_inspire_level_addition
            obj.config_inspire_step_addition = config_inspire_step_addition
            obj.calculate()
Exemplo n.º 9
0
    def load_staffs(self):
        from core.staff import StaffManger
        from core.formation import Formation

        self.formation_staffs = []

        sm = StaffManger(self.server_id, self.char_id)
        fm = Formation(self.server_id, self.char_id)

        for k in fm.in_formation_staffs():
            self.formation_staffs.append(sm.get_staff_object(k))
Exemplo n.º 10
0
    def test_match(self):
        staff_ids = ConfigStaff.INSTANCES.keys()
        staff_ids = random.sample(staff_ids, 10)

        sm = StaffManger(1, 1)
        for i in staff_ids:
            sm.add(i)

        Club(1, 1).set_match_staffs(staff_ids)

        Challenge(1, 1).start()
Exemplo n.º 11
0
    def test_match(self):
        staff_ids = ConfigStaff.INSTANCES.keys()
        staff_ids = random.sample(staff_ids, 10)

        sm = StaffManger(1, 1)
        for i in staff_ids:
            sm.add(i)

        Club(1, 1).set_match_staffs(staff_ids)

        Challenge(1, 1).start()
Exemplo n.º 12
0
    def test_add(self):
        staff_ids = ConfigStaff.INSTANCES.keys()
        doc = MongoStaff.db(self.server_id).find_one({'_id': self.char_id}, {'staffs': 1})

        add_id = 0
        for staff_id in staff_ids:
            if str(staff_id) not in doc['staffs'].keys():
                add_id = staff_id

        StaffManger(self.server_id, self.char_id).add(add_id)
        assert StaffManger(self.server_id, self.char_id).has_staff(add_id) is True
Exemplo n.º 13
0
    def test_add_duplicate(self):
        doc = MongoStaff.db(self.server_id).find_one({'_id': self.char_id}, {'staffs': 1})
        staff_id = int(random.choice(doc['staffs'].keys()))

        assert StaffManger(self.server_id, self.char_id).has_staff(staff_id) is True
        try:
            StaffManger(self.server_id, self.char_id).add(staff_id)
        except GameException as e:
            assert e.error_id == ConfigErrorMessage.get_error_id("STAFF_ALREADY_HAVE")
        else:
            raise Exception("can not be here!")
Exemplo n.º 14
0
def batch_destroy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    staff_ids = request._proto.staff_ids

    rc = StaffManger(server_id, char_id).batch_destroy([i for i in staff_ids])

    response = StaffBatchDestroyResponse()
    response.ret = 0
    response.drop.MergeFrom(rc.make_protomsg())
    return ProtobufResponse(response)
Exemplo n.º 15
0
    def test_match(self):
        self.set_friend_data()

        staff_ids = random.sample(ConfigStaff.INSTANCES.keys(), 10)
        for i in staff_ids:
            StaffManger(1, 1).add(i)
            StaffManger(1, 2).add(i)

        Club(1, 1).set_match_staffs(staff_ids)
        Club(1, 2).set_match_staffs(staff_ids)

        FriendManager(1, 1).match(2)
Exemplo n.º 16
0
def batch_destroy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    staff_ids = request._proto.staff_ids

    rc = StaffManger(server_id, char_id).batch_destroy([i for i in staff_ids])

    response = StaffBatchDestroyResponse()
    response.ret = 0
    response.drop.MergeFrom(rc.make_protomsg())
    return ProtobufResponse(response)
Exemplo n.º 17
0
def destroy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    staff_id = request._proto.staff_id
    tp = request._proto.tp

    resource_classified = StaffManger(server_id, char_id).destroy(staff_id, tp)

    response = StaffDestroyResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())
    return ProtobufResponse(response)
Exemplo n.º 18
0
def destroy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    staff_id = request._proto.staff_id
    tp = request._proto.tp

    resource_classified = StaffManger(server_id, char_id).destroy(staff_id, tp)

    response = StaffDestroyResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())
    return ProtobufResponse(response)
Exemplo n.º 19
0
    def set_staff(self, slot_id, staff_id):
        from core.inspire import Inspire

        if str(slot_id) not in self.doc['slots']:
            raise GameException(ConfigErrorMessage.get_error_id("FORMATION_SLOT_NOT_OPEN"))

        sm = StaffManger(self.server_id, self.char_id)
        sm.check_staff(ids=[staff_id])

        Inspire(self.server_id, self.char_id).check_staff_in(staff_id)

        this_staff_obj = sm.get_staff_object(staff_id)

        in_formation_staffs = self.in_formation_staffs()
        for k, v in in_formation_staffs.iteritems():
            if k == staff_id:
                raise GameException(ConfigErrorMessage.get_error_id("FORMATION_STAFF_ALREADY_IN"))

            if v['slot_id'] != slot_id and sm.get_staff_object(k).oid == this_staff_obj.oid:
                # 其他位置 不能上 oid 一样的人
                # 但是这个slot替换就可以
                raise GameException(ConfigErrorMessage.get_error_id("FORMATION_STAFF_ALREADY_IN"))

        old_staff_id = self.doc['slots'][str(slot_id)]['staff_id']
        self.doc['slots'][str(slot_id)]['staff_id'] = staff_id
        self.doc['slots'][str(slot_id)]['unit_id'] = 0
        self.doc['slots'][str(slot_id)]['policy'] = 1

        updater = {
            'slots.{0}.staff_id'.format(slot_id): staff_id,
            'slots.{0}.unit_id'.format(slot_id): 0,
            'slots.{0}.policy'.format(slot_id): 1
        }

        if slot_id in self.doc['position']:
            # 换完人,兵种清空了,也就从阵型位置上撤掉了
            index = self.doc['position'].index(slot_id)
            self.doc['position'][index] = 0

            updater['position.{0}'.format(index)] = 0

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

        if old_staff_id:
            self.skill_sequence_try_unset_staff(old_staff_id)

        return old_staff_id
Exemplo n.º 20
0
    def test_remove(self):
        staff_ids = ConfigStaff.INSTANCES.keys()
        doc = MongoStaff.db(self.server_id).find_one({'_id': self.char_id})
        staff_id = 0
        for i in staff_ids:
            if str(i) not in doc['staffs'].keys():
                staff_id = i
                break

        StaffManger(self.server_id, self.char_id).add(staff_id)
        assert StaffManger(self.server_id, self.char_id).has_staff(staff_id) is True

        StaffManger(self.server_id, self.char_id).remove(staff_id)
        assert StaffManger(self.server_id, self.char_id).has_staff(staff_id) is False
Exemplo n.º 21
0
    def test_set_staffs(self):
        staff_ids = random.sample(ConfigStaff.INSTANCES.keys(), 10)
        sm = StaffManger(1, 1)
        for sid in staff_ids:
            sm.add(sid)

        Club(1, 1).set_match_staffs(staff_ids)

        assert len(Club(1, 1).match_staffs) == 5
        assert len(Club(1, 1).tibu_staffs) == 5

        for c in Club(1, 1).match_staffs:
            assert c != 0

        for c in Club(1, 1).tibu_staffs:
            assert c != 0
Exemplo n.º 22
0
    def test_set_staffs(self):
        staff_ids = random.sample(ConfigStaff.INSTANCES.keys(), 10)
        sm = StaffManger(1, 1)
        for sid in staff_ids:
            sm.add(sid)

        Club(1, 1).set_match_staffs(staff_ids)

        assert len(Club(1, 1).match_staffs) == 5
        assert len(Club(1, 1).tibu_staffs) == 5

        for c in Club(1, 1).match_staffs:
            assert c != 0

        for c in Club(1, 1).tibu_staffs:
            assert c != 0
Exemplo n.º 23
0
    def check_exist(self, server_id, char_id):
        from core.club import Club
        from core.bag import Bag
        from core.staff import StaffManger, StaffRecruit
        from core.territory import Territory
        from core.arena import Arena
        from core.energy import Energy

        money_text = self.money_as_text_dict()
        if money_text:
            Club(server_id, char_id).check_money(**money_text)
        if self.bag:
            Bag(server_id, char_id).check_items(self.bag)
        if self.staff:
            StaffManger(server_id,
                        char_id).check_original_staff_is_initial_state(
                            self.staff)
        if self.territory_product:
            Territory(server_id, char_id).check_product(self.territory_product)
        if self.work_card:
            Territory(server_id, char_id).check_work_card(self.work_card)
        if self.arena_point:
            Arena(server_id, char_id).check_point(self.arena_point)
        if self.energy:
            Energy(server_id, char_id).check(self.energy)
        if self.staff_recruit_score:
            StaffRecruit(server_id,
                         char_id).check_score(self.staff_recruit_score)
        if self.resource_data:
            _r = _Resource()
            _r.resource = dict(self.resource_data)
            _r.check_exists(server_id, char_id)
Exemplo n.º 24
0
    def get_addition_config(self):
        sm = StaffManger(self.server_id, self.char_id)
        # XXX 不能用 get_staff_object
        all_staffs = sm.get_staffs_data()

        levels = 0
        steps = 0

        for s in self.all_staffs():
            data = all_staffs[s]
            levels += data['level']
            steps += data['step']

        config_level_addition = ConfigInspireAddition.get_by_level(levels)
        config_step_addition = ConfigInspireAddition.get_by_step(steps)

        return config_level_addition, config_step_addition
Exemplo n.º 25
0
    def get_addition_config(self):
        sm = StaffManger(self.server_id, self.char_id)
        # XXX 不能用 get_staff_object
        all_staffs = sm.get_staffs_data()

        levels = 0
        steps = 0

        for s in self.all_staffs():
            data = all_staffs[s]
            levels += data['level']
            steps += data['step']

        config_level_addition = ConfigInspireAddition.get_by_level(levels)
        config_step_addition = ConfigInspireAddition.get_by_step(steps)

        return config_level_addition, config_step_addition
Exemplo n.º 26
0
    def test_level_up(self):
        doc = MongoStaff.db(self.server_id).find_one({'_id': self.char_id}, {'staffs': 1})
        s = ConfigStaff.get(int(random.choice(doc['staffs'].keys())))

        level = 5
        exp = 0
        for i in range(1, level):
            exp += ConfigStaffLevel.get(i).exp[s.quality]

        exp += 1

        assert StaffManger(self.server_id, self.char_id).get_staff_object(s.id).level == 1
        assert StaffManger(self.server_id, self.char_id).get_staff_object(s.id).exp == 0

        StaffManger(self.server_id, self.char_id).update(s.id, exp=exp)
        assert StaffManger(self.server_id, self.char_id).get_staff_object(s.id).level == level
        assert StaffManger(self.server_id, self.char_id).get_staff_object(s.id).exp == 1
Exemplo n.º 27
0
    def is_staff_training_check_by_oid(self, oid):
        sm = StaffManger(self.server_id, self.char_id)

        for k, v in self.get_all_building_objects().iteritems():
            if not v.open:
                continue

            for _, s in v.slots.iteritems():
                if not s.open:
                    continue

                if not s.staff_id:
                    continue

                if sm.get_staff_object(s.staff_id).oid == oid:
                    return True

        return False
Exemplo n.º 28
0
    def working_staff_oids(self):
        from core.inspire import Inspire
        oids = []

        sm = StaffManger(self.server_id, self.char_id)
        # XXX: 这里不能用 get_staff_object
        # 因为get_staff_obj 可能用调用到 Club.force_load_staffs
        # 在 Club.force_load_staffs 中又会调用 这个方法
        # 然后就死循环了
        all_staffs = sm.get_staffs_data()

        working_staffs = self.in_formation_staffs().keys()
        working_staffs.extend(Inspire(self.server_id, self.char_id).all_staffs())

        for s in working_staffs:
            oids.append(all_staffs[s]['oid'])

        return oids
Exemplo n.º 29
0
    def is_staff_training_check_by_oid(self, oid):
        sm = StaffManger(self.server_id, self.char_id)

        for k, v in self.get_all_building_objects().iteritems():
            if not v.open:
                continue

            for _, s in v.slots.iteritems():
                if not s.open:
                    continue

                if not s.staff_id:
                    continue

                if sm.get_staff_object(s.staff_id).oid == oid:
                    return True

        return False
Exemplo n.º 30
0
    def harass(self, union_id, staff_id):
        doc = MongoUnion.db(self.server_id).find_one({'_id': union_id},
                                                     {'owner': 1})
        if not doc:
            raise GameException(
                ConfigErrorMessage.get_error_id("UNION_NOT_EXIST"))

        staff = StaffManger(self.server_id,
                            self.char_id).get_staff_object(staff_id)

        hi = HarassInfo(self.server_id, self.char_id)
        if not hi.remained_times:
            hi.buy_times()

        if staff.oid == self.member_doc['harass_staff']:
            param = 2
        else:
            param = 1

        hi.record()

        union_coin = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) *
            3.5 * param)
        explore_point = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 7 *
            param)
        union_skill_point = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 5 *
            param)

        my_explore_point = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 5 *
            param)
        self.add_explore_point(my_explore_point)

        Union(self.server_id, doc['owner']).add_explore_point(-explore_point)

        reward = ConfigUnionExplore.get_harass_reward()
        reward = [(_id, _amount * param) for _id, _amount in reward]
        reward.append((UNION_COIN_ID, union_coin))
        reward.append((UNION_SKILL_POINT_ID, union_skill_point))

        rc = ResourceClassification.classify(reward)
        rc.add(self.server_id, self.char_id, message="UnionJoined.harass")

        self.member_doc['harass_staff'] = ConfigUnionExplore.get_staff_id()
        MongoUnionMember.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'harass_staff': self.member_doc['harass_staff']
            }})

        self.send_explore_notify()
        return explore_point, rc, my_explore_point
Exemplo n.º 31
0
def step_up(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    staff_id = request._proto.staff_id

    StaffManger(server_id, char_id).step_up(staff_id)

    response = StaffStepUpResponse()
    response.ret = 0
    return ProtobufResponse(response)
Exemplo n.º 32
0
    def test_recruit(self):
        config = ConfigStaffRecruit.get(RECRUIT_ENUM_TO_CONFIG_ID[RECRUIT_NORMAL])
        cost_type = 'gold' if config.cost_type == 1 else 'diamond'
        self.update(**{cost_type: config.cost_value})
        StaffRecruit(self.server_id, self.char_id).refresh(RECRUIT_NORMAL)

        staff_ids = StaffRecruit(self.server_id, self.char_id).get_self_refreshed_staffs()
        doc = MongoStaff.db(self.server_id).find_one({'_id': self.char_id}, {'staffs': 1})
        test_id = 0
        for staff_id in staff_ids:
            if str(staff_id) not in doc['staffs'].keys():
                test_id = staff_id
                break

        assert StaffManger(self.server_id, self.char_id).has_staff(test_id) is False
        staff_cfg = ConfigStaff.get(test_id)
        tp = 'gold' if staff_cfg.buy_type == 1 else 'diamond'
        self.update(**{tp: staff_cfg.buy_cost})
        StaffRecruit(self.server_id, self.char_id).recruit(test_id)
        assert StaffManger(self.server_id, self.char_id).has_staff(test_id) is True
Exemplo n.º 33
0
def level_up(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    staff_id = request._proto.staff_id
    up_level = request._proto.up_level

    StaffManger(server_id, char_id).level_up(staff_id, up_level)

    response = StaffLevelUpResponse()
    response.ret = 0
    return ProtobufResponse(response)
Exemplo n.º 34
0
def equipment_change(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    staff_id = request._proto.staff_id
    slot_id = request._proto.slot_id
    tp = request._proto.tp

    StaffManger(server_id, char_id).equipment_change(staff_id, slot_id, tp)

    response = StaffEquipChangeResponse()
    response.ret = 0
    return ProtobufResponse(response)
Exemplo n.º 35
0
    def add(self, server_id, char_id, message=""):
        from core.club import Club
        from core.bag import Bag
        from core.staff import StaffManger, StaffRecruit
        from core.talent import TalentManager
        from core.territory import Territory
        from core.vip import VIP
        from core.arena import Arena
        from core.energy import Energy
        from core.plunder import Plunder

        club_property = self.money_as_text_dict()
        if self.club_exp:
            club_property['exp'] = self.club_exp
        if club_property:
            club_property['message'] = message
            Club(server_id, char_id).update(**club_property)

        if self.vip_exp:
            VIP(server_id, char_id).add_exp(self.vip_exp)

        if self.bag:
            bag = Bag(server_id, char_id)
            bag.batch_add(self.bag)

        sm = StaffManger(server_id, char_id)
        if self.staff:
            sm.batch_add(self.staff)

        if self.staff_exp_pool:
            sm.add_exp_pool(self.staff_exp_pool)

        if self.talent_point:
            TalentManager(server_id,
                          char_id).add_talent_points(self.talent_point)

        if self.arena_point:
            Arena(server_id, char_id).add_point(self.arena_point)

        if self.territory_product:
            Territory(server_id, char_id).add_product(self.territory_product)

        if self.work_card:
            Territory(server_id, char_id).add_work_card(self.work_card)

        if self.energy:
            Energy(server_id, char_id).add(self.energy)

        if self.staff_recruit_score:
            StaffRecruit(server_id,
                         char_id).add_score(self.staff_recruit_score)

        if self.station_exp:
            Plunder(server_id, char_id).add_station_exp(self.station_exp)

        if self.resource_data:
            _r = _Resource()
            _r.resource = dict(self.resource_data)
            _r.add(server_id, char_id)
Exemplo n.º 36
0
    def test_remove_not_exist(self):
        staff_ids = ConfigStaff.INSTANCES.keys()

        staff_id = 0
        for i in range(1, 10000):
            if str(i) not in staff_ids:
                staff_id = i
                break
        try:
            StaffManger(self.server_id, self.char_id).remove(staff_id)
        except GameException as e:
            assert e.error_id == ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST")
        else:
            raise Exception("can not be here!")
Exemplo n.º 37
0
    def test_add_not_exist(self):
        def get_id():
            while True:
                staff_id = random.randint(1, 1000000)
                if staff_id not in ConfigStaff.INSTANCES.keys():
                    return staff_id

        staff_id = get_id()
        try:
            StaffManger(self.server_id, self.char_id).add(staff_id)
        except GameException as e:
            assert e.error_id == ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST")
        else:
            raise Exception("can not be here!")
Exemplo n.º 38
0
def star_up(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    staff_id = request._proto.staff_id
    single = request._proto.single

    crit, inc_exp, cost_item_id, cost_item_amount = StaffManger(
        server_id, char_id).star_up(staff_id, single)

    response = StaffStarUpResponse()
    response.ret = 0
    response.crit = crit
    response.increase = inc_exp
    response.cost_item_id = cost_item_id
    response.cost_item_amount = cost_item_amount
    return ProtobufResponse(response)
Exemplo n.º 39
0
    def explore(self, staff_id):
        staff = StaffManger(self.server_id,
                            self.char_id).get_staff_object(staff_id)

        ei = ExploreInfo(self.server_id, self.char_id)
        ei.check_cd()
        if not ei.remained_times:
            raise GameException(
                ConfigErrorMessage.get_error_id("UNION_EXPLORE_NO_TIMES"))

        if staff.oid == self.member_doc['explore_staff']:
            param = 2
        else:
            param = 1

        ei.record()

        union_coin = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 3 *
            param)
        explore_point = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 10 *
            param)
        union_skill_point = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 4 *
            param)

        self.add_explore_point(explore_point)

        reward = ConfigUnionExplore.get_explore_reward()
        reward = [(_id, _amount * param) for _id, _amount in reward]
        reward.append((UNION_COIN_ID, union_coin))
        reward.append((UNION_SKILL_POINT_ID, union_skill_point))

        rc = ResourceClassification.classify(reward)
        rc.add(self.server_id, self.char_id, message="UnionJoined.explore")

        self.member_doc['explore_staff'] = ConfigUnionExplore.get_staff_id()
        MongoUnionMember.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'explore_staff': self.member_doc['explore_staff']
            }})

        self.send_explore_notify()
        return explore_point, rc
Exemplo n.º 40
0
    def get_building_reward(self):
        if not self.open:
            return 0, 0

        if not self.staff_id:
            return 0, 0

        staff_obj = StaffManger(self.server_id,
                                self.char_id).get_staff_object(self.staff_id)

        quality_modulus = STAFF_QUALITY_MODULUS[staff_obj.quality]
        slot_modulus = ConfigTerritoryBuilding.get(
            self.building_id).slots[self.id].exp_modulus

        exp = 10 * math.pow(self.hour, 0.8) * quality_modulus * slot_modulus
        product_amount = 100 * math.pow(self.hour,
                                        0.8) * quality_modulus * slot_modulus

        return int(exp), int(product_amount)
Exemplo n.º 41
0
    def remove(self, server_id, char_id, message=""):
        from core.club import Club
        from core.bag import Bag
        from core.staff import StaffManger, StaffRecruit
        from core.territory import Territory
        from core.arena import Arena
        from core.energy import Energy

        money_text = self.money_as_text_dict()
        if money_text:
            money_text = {k: -v for k, v in money_text.iteritems()}
            money_text['message'] = message
            Club(server_id, char_id).update(**money_text)

        if self.bag:
            bag = Bag(server_id, char_id)
            for _id, _amount in self.bag:
                bag.remove_by_item_id(_id, _amount)

        if self.staff:
            StaffManger(server_id, char_id).internal_remove_by_oid(self.staff)

        if self.territory_product:
            Territory(server_id,
                      char_id).remove_product(self.territory_product)

        if self.work_card:
            Territory(server_id, char_id).remove_work_card(self.work_card)

        if self.arena_point:
            Arena(server_id, char_id).remove_point(self.arena_point)

        if self.energy:
            Energy(server_id, char_id).remove(self.energy)

        if self.staff_recruit_score:
            StaffRecruit(server_id,
                         char_id).remove_score(self.staff_recruit_score)

        if self.resource_data:
            _r = _Resource()
            _r.resource = dict(self.resource_data)
            _r.remove(server_id, char_id)
Exemplo n.º 42
0
    def test_recruit_already_have(self):
        config = ConfigStaffRecruit.get(RECRUIT_ENUM_TO_CONFIG_ID[RECRUIT_NORMAL])
        cost_type = 'gold' if config.cost_type == 1 else 'diamond'
        self.update(**{cost_type: config.cost_value})
        StaffRecruit(self.server_id, self.char_id).refresh(RECRUIT_NORMAL)

        staff_ids = StaffRecruit(self.server_id, self.char_id).get_self_refreshed_staffs()
        doc = MongoStaff.db(self.server_id).find_one({'_id': 1}, {'staffs': 1})
        test_id = 0
        for staff_id in staff_ids:
            if str(staff_id) not in doc['staffs'].keys():
                StaffManger(self.server_id, self.char_id).add(staff_id)
                test_id = staff_id
                break
        try:
            StaffRecruit(self.server_id, self.char_id).recruit(test_id)
        except GameException as e:
            assert e.error_id == ConfigErrorMessage.get_error_id("STAFF_ALREADY_HAVE")
        else:
            raise Exception("can not be here!")
Exemplo n.º 43
0
    def setup_class(cls):
        MongoCharacter.db(1).update_one({'_id': 1},
                                        {'$set': {
                                            'club.level': 10
                                        }})

        doc = MongoStaff.db(1).find_one({'_id': 1}, {'staffs': 1})
        staff_ids = random.sample(ConfigStaff.INSTANCES.keys(), 15)
        for i in staff_ids:
            if str(i) not in doc['staffs']:
                StaffManger(1, 1).add(i)

        match_staff_ids = []
        for k in doc['staffs'].keys():
            match_staff_ids.append(int(k))

        for staff_id in staff_ids:
            if staff_id not in match_staff_ids:
                match_staff_ids.append(staff_id)

        Club(1, 1).set_match_staffs(random.sample(match_staff_ids, 10))

        LeagueGame.new(1)
Exemplo n.º 44
0
    def force_load_staffs(self, send_notify=False):
        from core.staff import StaffManger, Staff
        from core.formation import Formation
        from core.unit import UnitManager
        from core.talent import TalentManager
        from core.collection import Collection
        from core.party import Party
        from core.inspire import Inspire
        from core.union import Union
        from core.bag import Bag

        self.formation_staffs = []

        sm = StaffManger(self.server_id, self.char_id)
        fm = Formation(self.server_id, self.char_id)
        um = UnitManager(self.server_id, self.char_id)
        ins = Inspire(self.server_id, self.char_id)

        staffs = sm.get_staffs_data()
        in_formation_staffs = fm.in_formation_staffs()

        staff_objs = {}
        """:type: dict[str, core.staff.Staff]"""
        for k, v in staffs.items():
            staff_objs[k] = Staff(self.server_id, self.char_id, k, v)

        for k, v in staff_objs.iteritems():
            if k in in_formation_staffs:
                self.formation_staffs.append(v)

                v.policy = in_formation_staffs[k]['policy']
                v.formation_position = in_formation_staffs[k]['position']
                unit_id = in_formation_staffs[k]['unit_id']
                if unit_id:
                    v.set_unit(um.get_unit_object(unit_id))

        working_staff_oids = fm.working_staff_oids()

        for k in in_formation_staffs:
            staff_objs[k].check_qianban(working_staff_oids)
            staff_objs[k].add_self_talent_effect(self)

        talent_effects_1 = TalentManager(self.server_id, self.char_id).get_talent_effects()
        talent_effects_2 = Collection(self.server_id, self.char_id).get_talent_effects()
        talent_effects_3 = fm.get_talent_effects()
        talent_effects_4 = Party(self.server_id, self.char_id).get_talent_effects()
        talent_effects_5 = Union(self.server_id, self.char_id).get_union_skill_talent_effects()

        self.add_talent_effects(talent_effects_1)
        self.add_talent_effects(talent_effects_2)
        self.add_talent_effects(talent_effects_3)
        self.add_talent_effects(talent_effects_4)
        self.add_talent_effects(talent_effects_5)

        config_inspire_level_addition, config_inspire_step_addition = ins.get_addition_config()

        bag = Bag(self.server_id, self.char_id)
        for _, v in staff_objs.iteritems():
            v.config_inspire_level_addition = config_inspire_level_addition
            v.config_inspire_step_addition = config_inspire_step_addition
            v.calculate(bag=bag, um=um)
            v.make_cache()

        if send_notify:
            self.send_notify()
            in_formation_staff_ids = fm.in_formation_staffs().keys()
            sm.send_notify(ids=in_formation_staff_ids)
Exemplo n.º 45
0
    def equipment_level_up(self, slot_id, times=1):
        from core.staff import StaffManger
        from core.formation import Formation
        from core.plunder import Plunder

        this_slot = self.doc['slots'][slot_id]
        item_id = this_slot['item_id']

        if get_item_type(item_id) != TYPE_EQUIPMENT:
            raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        equip = Equipment.load_from_slot_data(this_slot)
        level = equip.level

        if equip.is_special:
            if level >= ConfigEquipmentSpecialLevel.MAX_LEVEL:
                raise GameException(ConfigErrorMessage.get_error_id("EQUIPMENT_SELF_REACH_MAX_LEVEL"))

            station_level_limit = Plunder(self.server_id, self.char_id).get_station_level() * 2
            if level >= station_level_limit:
                raise GameException(ConfigErrorMessage.get_error_id("EQUIPMENT_SPECIAL_REACH_MAX_LEVEL"))

            max_level = min(ConfigEquipmentSpecialLevel.MAX_LEVEL, station_level_limit)
        else:
            config = ConfigEquipmentNew.get(item_id)
            if level >= config.max_level:
                raise GameException(ConfigErrorMessage.get_error_id("EQUIPMENT_SELF_REACH_MAX_LEVEL"))

            club_level_limit = get_club_property(self.server_id, self.char_id, 'level') * 2
            if level >= club_level_limit:
                raise GameException(ConfigErrorMessage.get_error_id("EQUIPMENT_REACH_MAX_LEVEL"))

            max_level = min(config.max_level, club_level_limit)

        can_add_level = max_level - level
        if times > can_add_level:
            times = can_add_level

        def do_level_up(_add):
            _item_needs = equip.get_level_up_needs_items(_add)

            resource_classified = ResourceClassification.classify(_item_needs)
            resource_classified.check_exist(self.server_id, self.char_id)
            resource_classified.remove(self.server_id, self.char_id,
                                       message="Bag.equipment_level_up:{0}".format(item_id))

        old_level = level
        error_code = 0

        for i in range(times, 0, -1):
            try:
                do_level_up(i)
            except GameException as e:
                error_code = e.error_id
            else:
                level += i
                break

        if level > old_level:
            self.doc['slots'][slot_id]['level'] = level

            MongoBag.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$set': {
                    'slots.{0}.level'.format(slot_id): level
                }}
            )

            ValueLogEquipmentLevelUpTimes(self.server_id, self.char_id).record(value=level - old_level)
            self.send_notify(slot_ids=[slot_id])

            sm = StaffManger(self.server_id, self.char_id)
            staff_id = sm.find_staff_id_with_equip(slot_id)
            if staff_id:
                s_obj = sm.get_staff_object(staff_id)
                s_obj.calculate()
                s_obj.make_cache()
                sm.send_notify(ids=[staff_id])

                fm = Formation(self.server_id, self.char_id)
                if staff_id in fm.in_formation_staffs():
                    Club(self.server_id, self.char_id).send_notify()

                    task_condition_trig_signal.send(
                        sender=None,
                        server_id=self.server_id,
                        char_id=self.char_id,
                        condition_name='core.formation.Formation'
                    )

        return error_code, level != old_level, Equipment.load_from_slot_data(self.doc['slots'][slot_id])
Exemplo n.º 46
0
    def training_star(self, building_id, slot_id, staff_id, hour):
        if hour not in TRAINING_HOURS:
            raise GameException(ConfigErrorMessage.get_error_id('BAD_MESSAGE'))

        sm = StaffManger(self.server_id, self.char_id)
        sm.check_staff([staff_id])

        building = self.get_building_object(building_id, slots_ids=[slot_id])
        try:
            slot = building.slots[slot_id]
        except KeyError:
            raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        if not slot.open:
            raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_SLOT_LOCK"))

        if slot.staff_id:
            raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_SLOT_HAS_STAFF"))

        if self.is_staff_training_check_by_oid(sm.get_staff_object(staff_id).oid):
            raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_STAFF_IS_TRAINING"))

        config_slot = ConfigTerritoryBuilding.get(building_id).slots[slot_id]
        cost_amount = config_slot.get_cost_amount(building.level, TRAINING_HOURS.index(hour))

        new_amount = self.check_work_card(cost_amount)
        self.doc['work_card'] = new_amount

        slot.staff_id = staff_id
        slot.hour = hour

        start_at = arrow.utcnow().timestamp

        slot_doc = MongoTerritory.document_slot()
        slot_doc['staff_id'] = staff_id
        slot_doc['start_at'] = start_at
        slot_doc['hour'] = hour

        building_exp, product_amount = slot.get_building_reward()
        reward = {
            'building_exp': building_exp,
            'product_amount': product_amount,
            'items': []
        }

        ri = ResultItems()

        # 固定奖励
        report = [
            (
                1,
                [str(building_exp), ConfigItemNew.get(slot.product_id).name,
                 str(product_amount)],
                0,
            ),
        ]

        # 选手特产
        config_staff_product = ConfigTerritoryStaffProduct.get(sm.get_staff_object(staff_id).oid)
        if config_staff_product:
            _id, _amount = config_staff_product.get_product(TRAINING_HOURS.index(hour))
            if _amount:
                report.append((
                    2,
                    [ConfigItemNew.get(_id).name, str(_amount)],
                    0,
                ))

                ri.add(_id, _amount)

        # 概率奖励
        end_at = start_at + hour * 3600
        extra_at = start_at + 3600
        while extra_at < end_at:
            _id, _amount = ConfigTerritoryBuilding.get(building_id).slots[slot_id].get_extra_product(1)

            report.append((
                3,
                [ConfigItemNew.get(_id).name, str(_amount)],
                extra_at
            ))

            ri.add(_id, _amount)
            extra_at += 3600

        reward['items'] = ri.items.items()

        slot_doc['report'] = report
        slot_doc['reward'] = reward

        self.doc['buildings'][str(building_id)]['slots'][str(slot_id)] = slot_doc
        MongoTerritory.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'work_card': self.doc['work_card'],
                'buildings.{0}.slots.{1}'.format(building_id, slot_id): slot_doc
            }}
        )

        ValueLogTerritoryTrainingTimes(self.server_id, self.char_id).record()

        self.send_notify(building_id=building_id, slot_id=slot_id)
Exemplo n.º 47
0
    def _single_response(_char):
        context['show'] = True
        context['char_id'] = _char.id
        context['char_name'] = _char.name
        context['server_id'] = _char.server_id

        _club = Club(_char.server_id, _char.id)
        _bag = Bag(_char.server_id, _char.id)
        _vip = VIP(_char.server_id, _char.id)
        _sm = StaffManger(_char.server_id, _char.id)
        _fm = Formation(_char.server_id, _char.id)
        _te = Territory(_char.server_id, _char.id)
        _union = Union(_char.server_id, _char.id)

        context['last_login'] = arrow.get(_club.last_login).to(settings.TIME_ZONE).format("YYYY-MM-DD HH:mm:ss")
        context['club_level'] = _club.level
        context['vip_level'] = _vip.doc['vip']
        context['vip_exp'] = _vip.doc['exp']
        context['power'] = _club.power

        context['diamond'] = _club.diamond
        context['gold'] = _club.gold
        context['crystal'] = _club.crystal
        context['gas'] = _club.gas
        context['item_30007'] = _bag.get_amount_by_item_id(30007)
        context['item_30008'] = _bag.get_amount_by_item_id(30008)
        context['item_30009'] = _bag.get_amount_by_item_id(30009)
        context['item_30015'] = _te.get_work_card_amount()

        _res = MongoResource.db(_char.server_id).find_one({'_id': _char.id})
        if not _res:
            _res = {'resource': {}}
        context['item_30022'] = _res['resource'].get('30022', 0)
        context['item_30023'] = _res['resource'].get('30023', 0)
        context['item_30019'] = _res['resource'].get('30019', 0)

        _union_id = _union.get_joined_union_id()
        if not _union_id:
            context['union'] = {}
        else:
            context['union'] = {
                'id': _union_id,
                'name': _union.union_doc['name'],
                'joined_at': arrow.get(_union.member_doc['joined_at']).to(settings.TIME_ZONE).format(
                    "YYYY-MM-DD HH:mm:ss"),
                'contribution': _union.member_doc['contribution']
            }

        in_formation_staffs = _fm.in_formation_staffs()
        staffs_data = []
        equip_data = []

        for k, v in in_formation_staffs.iteritems():
            staff_obj = _sm.get_staff_object(k)
            staff_name = ConfigItemNew.get(staff_obj.oid).name

            staffs_data.append({
                'id': staff_obj.id,
                'oid': staff_obj.oid,
                'name': staff_name,
                'level': staff_obj.level,
                'step': staff_obj.step,
                'star': staff_obj.star,
                'power': staff_obj.power,
                'unit_id': v['unit_id'],
                'position': v['position'],
            })

            for bag_slot_id in [staff_obj.equip_special, staff_obj.equip_decoration, staff_obj.equip_keyboard,
                                staff_obj.equip_monitor, staff_obj.equip_mouse]:

                if not bag_slot_id:
                    continue

                equip = _bag.get_slot(bag_slot_id)
                equip_data.append({
                    'oid': equip['item_id'],
                    'level': equip['level'],
                    'name': ConfigItemNew.get(equip['item_id']).name,
                    'staff_name': staff_name
                })

        context['staffs'] = staffs_data
        context['equips'] = equip_data

        return render_to_response(
            'dianjing_statistics_char.html',
            context=context
        )