예제 #1
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
예제 #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
예제 #3
0
파일: plunder.py 프로젝트: yueyoum/dianjing
    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
예제 #4
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
예제 #5
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)
예제 #6
0
파일: club.py 프로젝트: zhifuliu/dianjing
    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))
예제 #7
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
예제 #8
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
예제 #9
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)
예제 #10
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
        )
예제 #11
0
파일: bag.py 프로젝트: yueyoum/dianjing
    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])
예제 #12
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)