Ejemplo n.º 1
0
    def add_equipment_property_for_unit(self):
        if not self.equip_special:
            return

        # NOTE !!!
        unit = self.unit
        if not unit:
            return

        bag = Bag(self.server_id, self.char_id)
        data = bag.get_slot(self.equip_special)

        equip = Equipment.load_from_slot_data(data)

        unit.hp_percent += equip.get_property_value(PROPERTY_UNIT_HP_PERCENT)
        unit.attack_percent += equip.get_property_value(PROPERTY_UNIT_ATTACK_PERCENT)
        unit.defense_percent += equip.get_property_value(PROPERTY_UNIT_DEFENSE_PERCENT)
        unit.hit_rate += equip.get_property_value(PROPERTY_UNIT_HIT_PERCENT)
        unit.dodge_rate += equip.get_property_value(PROPERTY_UNIT_DODGE_PERCENT)
        unit.crit_rate += equip.get_property_value(PROPERTY_UNIT_CRIT_PERCENT)
        unit.toughness_rate += equip.get_property_value(PROPERTY_UNIT_TOUGHNESS_PERCENT)
        unit.crit_multiple += equip.get_property_value(PROPERTY_UNIT_CRIT_MULTIPLE)

        unit.hurt_addition_to_terran += equip.get_property_value(PROPERTY_UNIT_HURT_ADDIITON_TO_TERRAN)
        unit.hurt_addition_to_protoss += equip.get_property_value(PROPERTY_UNIT_HURT_ADDIITON_TO_PROTOSS)
        unit.hurt_addition_to_zerg += equip.get_property_value(PROPERTY_UNIT_HURT_ADDIITON_TO_ZERG)

        unit.hurt_addition_by_terran += equip.get_property_value(PROPERTY_UNIT_HURT_ADDIITON_BY_TERRAN)
        unit.hurt_addition_by_protoss += equip.get_property_value(PROPERTY_UNIT_HURT_ADDIITON_BY_PROTOSS)
        unit.hurt_addition_by_zerg += equip.get_property_value(PROPERTY_UNIT_HURT_ADDIITON_BY_ZERG)

        unit.final_hurt_addition += equip.get_property_value(PROPERTY_UNIT_FINAL_HURT_ADDITION)
        unit.final_hurt_reduce += equip.get_property_value(PROPERTY_UNIT_FINAL_HURT_REDUCE)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def add_equipment_property_for_staff(self, bag=None):
        if not bag:
            bag = Bag(self.server_id, self.char_id)

        levels = []
        qualities = []

        # 装备本身属性
        for slot_id in [self.equip_keyboard, self.equip_monitor, self.equip_mouse, self.equip_decoration,
                        self.equip_special]:
            if not slot_id:
                continue

            data = bag.get_slot(slot_id)
            config = ConfigItemNew.get(data['item_id'])

            equip = Equipment.load_from_slot_data(data)

            self.attack += equip.staff_attack
            self.defense += equip.staff_defense
            self.manage += equip.staff_manage
            self.operation += equip.staff_operation

            self.attack_percent += equip.get_property_value(PROPERTY_STAFF_ATTACK_PERCENT)
            self.defense_percent += equip.get_property_value(PROPERTY_STAFF_DEFENSE_PERCENT)
            self.manage_percent += equip.get_property_value(PROPERTY_STAFF_MANAGE_PERCENT)
            self.operation_percent += equip.get_property_value(PROPERTY_STAFF_OPERATION_PERCENT)

            if slot_id not in [self.equip_decoration, self.equip_special]:
                # 装备加成不算 饰品,神器
                levels.append(data['level'])
                qualities.append(config.quality)

        # 装备加成
        if len(levels) == 3:
            equip_level_addition = ConfigStaffEquipmentAddition.get_by_level(min(levels))
            if equip_level_addition:
                self.attack += equip_level_addition.attack
                self.attack_percent += equip_level_addition.attack_percent
                self.defense += equip_level_addition.defense
                self.defense_percent += equip_level_addition.defense_percent
                self.manage += equip_level_addition.manage
                self.manage_percent += equip_level_addition.manage_percent

        if len(qualities) == 3:
            equip_quality_addition = ConfigStaffEquipmentAddition.get_by_quality(min(qualities))
            if equip_quality_addition:
                self.attack += equip_quality_addition.attack
                self.attack_percent += equip_quality_addition.attack_percent
                self.defense += equip_quality_addition.defense
                self.defense_percent += equip_quality_addition.defense_percent
                self.manage += equip_quality_addition.manage
                self.manage_percent += equip_quality_addition.manage_percent
Ejemplo n.º 4
0
    def equipment_change(self, bag_slot_id, tp):
        # 会影响的其他staff_id
        other_staff_id = ""

        if not bag_slot_id:
            # 卸下
            bag_slot_id = ""
        else:
            # 更换
            bag = Bag(self.server_id, self.char_id)
            slot = bag.get_slot(bag_slot_id)

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

            equip_config = ConfigEquipmentNew.get(item_id)
            if equip_config.tp != tp:
                raise GameException(
                    ConfigErrorMessage.get_error_id(
                        "EQUIPMENT_TYPE_NOT_MATCH"))

            other_staff_id = StaffManger(
                self.server_id,
                self.char_id).find_staff_id_by_equipment_slot_id(bag_slot_id)

        if tp == EQUIP_MOUSE:
            key = 'equip_mouse'
        elif tp == EQUIP_KEYBOARD:
            key = 'equip_keyboard'
        elif tp == EQUIP_MONITOR:
            key = 'equip_monitor'
        elif tp == EQUIP_DECORATION:
            key = 'equip_decoration'
        elif tp == EQUIP_SPECIAL:
            key = 'equip_special'
        else:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        setattr(self, key, bag_slot_id)
        MongoStaff.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'staffs.{0}.{1}'.format(self.id, key): bag_slot_id
            }})

        self.calculate()
        self.make_cache()

        return other_staff_id
Ejemplo n.º 5
0
    def generate(self, bag_slot_id, tp):
        if self.doc['item_id']:
            raise GameException(
                ConfigErrorMessage.get_error_id(
                    "SPECIAL_EQUIPMENT_IS_IN_PROCESS"))

        if tp not in [
                SPECIAL_EQUIPMENT_GENERATE_NORMAL,
                SPECIAL_EQUIPMENT_GENERATE_ADVANCE
        ]:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        bag = Bag(self.server_id, self.char_id)
        slot = bag.get_slot(bag_slot_id)
        item_id = slot['item_id']
        config = ConfigEquipmentSpecialGenerate.get(item_id)
        if not config:
            raise GameException(
                ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        if tp == SPECIAL_EQUIPMENT_GENERATE_NORMAL:
            cost = config.normal_cost
        else:
            cost = config.advance_cost

        rc = ResourceClassification.classify(cost)
        rc.check_exist(self.server_id, self.char_id)
        rc.remove(self.server_id,
                  self.char_id,
                  message="SpecialEquipmentGenerator.generate:{0}".format(tp))

        bag.remove_by_slot_id(slot_id=bag_slot_id, amount=1)

        finish_at = arrow.utcnow().timestamp + config.minutes * 60

        self.doc['item_id'] = item_id
        self.doc['finish_at'] = finish_at
        self.doc['tp'] = tp

        MongoSpecialEquipment.db(self.server_id).update_one(
            {'_id': self.char_id}, {
                '$set': {
                    'item_id': self.doc['item_id'],
                    'finish_at': self.doc['finish_at'],
                    'tp': self.doc['tp'],
                }
            })

        self.send_notify()
Ejemplo n.º 6
0
    def equipment_change(self, bag_slot_id, tp):
        # 会影响的其他staff_id
        other_staff_id = ""

        if not bag_slot_id:
            # 卸下
            bag_slot_id = ""
        else:
            # 更换
            bag = Bag(self.server_id, self.char_id)
            slot = bag.get_slot(bag_slot_id)

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

            equip_config = ConfigEquipmentNew.get(item_id)
            if equip_config.tp != tp:
                raise GameException(ConfigErrorMessage.get_error_id("EQUIPMENT_TYPE_NOT_MATCH"))

            other_staff_id = StaffManger(self.server_id, self.char_id).find_staff_id_by_equipment_slot_id(bag_slot_id)

        if tp == EQUIP_MOUSE:
            key = 'equip_mouse'
        elif tp == EQUIP_KEYBOARD:
            key = 'equip_keyboard'
        elif tp == EQUIP_MONITOR:
            key = 'equip_monitor'
        elif tp == EQUIP_DECORATION:
            key = 'equip_decoration'
        elif tp == EQUIP_SPECIAL:
            key = 'equip_special'
        else:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        setattr(self, key, bag_slot_id)
        MongoStaff.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'staffs.{0}.{1}'.format(self.id, key): bag_slot_id
            }}
        )

        self.calculate()
        self.make_cache()

        return other_staff_id
Ejemplo n.º 7
0
    def add_equipment_property_for_unit(self):
        if not self.equip_special:
            return

        # NOTE !!!
        unit = self.unit
        if not unit:
            return

        bag = Bag(self.server_id, self.char_id)
        data = bag.get_slot(self.equip_special)

        equip = Equipment.load_from_slot_data(data)

        unit.hp_percent += equip.get_property_value(PROPERTY_UNIT_HP_PERCENT)
        unit.attack_percent += equip.get_property_value(
            PROPERTY_UNIT_ATTACK_PERCENT)
        unit.defense_percent += equip.get_property_value(
            PROPERTY_UNIT_DEFENSE_PERCENT)
        unit.hit_rate += equip.get_property_value(PROPERTY_UNIT_HIT_PERCENT)
        unit.dodge_rate += equip.get_property_value(
            PROPERTY_UNIT_DODGE_PERCENT)
        unit.crit_rate += equip.get_property_value(PROPERTY_UNIT_CRIT_PERCENT)
        unit.toughness_rate += equip.get_property_value(
            PROPERTY_UNIT_TOUGHNESS_PERCENT)
        unit.crit_multiple += equip.get_property_value(
            PROPERTY_UNIT_CRIT_MULTIPLE)

        unit.hurt_addition_to_terran += equip.get_property_value(
            PROPERTY_UNIT_HURT_ADDIITON_TO_TERRAN)
        unit.hurt_addition_to_protoss += equip.get_property_value(
            PROPERTY_UNIT_HURT_ADDIITON_TO_PROTOSS)
        unit.hurt_addition_to_zerg += equip.get_property_value(
            PROPERTY_UNIT_HURT_ADDIITON_TO_ZERG)

        unit.hurt_addition_by_terran += equip.get_property_value(
            PROPERTY_UNIT_HURT_ADDIITON_BY_TERRAN)
        unit.hurt_addition_by_protoss += equip.get_property_value(
            PROPERTY_UNIT_HURT_ADDIITON_BY_PROTOSS)
        unit.hurt_addition_by_zerg += equip.get_property_value(
            PROPERTY_UNIT_HURT_ADDIITON_BY_ZERG)

        unit.final_hurt_addition += equip.get_property_value(
            PROPERTY_UNIT_FINAL_HURT_ADDITION)
        unit.final_hurt_reduce += equip.get_property_value(
            PROPERTY_UNIT_FINAL_HURT_REDUCE)
Ejemplo n.º 8
0
    def generate(self, bag_slot_id, tp):
        if self.doc['item_id']:
            raise GameException(ConfigErrorMessage.get_error_id("SPECIAL_EQUIPMENT_IS_IN_PROCESS"))

        if tp not in [SPECIAL_EQUIPMENT_GENERATE_NORMAL, SPECIAL_EQUIPMENT_GENERATE_ADVANCE]:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        bag = Bag(self.server_id, self.char_id)
        slot = bag.get_slot(bag_slot_id)
        item_id = slot['item_id']
        config = ConfigEquipmentSpecialGenerate.get(item_id)
        if not config:
            raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        if tp == SPECIAL_EQUIPMENT_GENERATE_NORMAL:
            cost = config.normal_cost
        else:
            cost = config.advance_cost

        rc = ResourceClassification.classify(cost)
        rc.check_exist(self.server_id, self.char_id)
        rc.remove(self.server_id, self.char_id, message="SpecialEquipmentGenerator.generate:{0}".format(tp))

        bag.remove_by_slot_id(slot_id=bag_slot_id, amount=1)

        finish_at = arrow.utcnow().timestamp + config.minutes * 60

        self.doc['item_id'] = item_id
        self.doc['finish_at'] = finish_at
        self.doc['tp'] = tp

        MongoSpecialEquipment.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'item_id': self.doc['item_id'],
                'finish_at': self.doc['finish_at'],
                'tp': self.doc['tp'],
            }}
        )

        self.send_notify()
Ejemplo n.º 9
0
    def add_equipment_property_for_staff(self, bag=None):
        if not bag:
            bag = Bag(self.server_id, self.char_id)

        levels = []
        qualities = []

        # 装备本身属性
        for slot_id in [
                self.equip_keyboard, self.equip_monitor, self.equip_mouse,
                self.equip_decoration, self.equip_special
        ]:
            if not slot_id:
                continue

            data = bag.get_slot(slot_id)
            config = ConfigItemNew.get(data['item_id'])

            equip = Equipment.load_from_slot_data(data)

            self.attack += equip.staff_attack
            self.defense += equip.staff_defense
            self.manage += equip.staff_manage
            self.operation += equip.staff_operation

            self.attack_percent += equip.get_property_value(
                PROPERTY_STAFF_ATTACK_PERCENT)
            self.defense_percent += equip.get_property_value(
                PROPERTY_STAFF_DEFENSE_PERCENT)
            self.manage_percent += equip.get_property_value(
                PROPERTY_STAFF_MANAGE_PERCENT)
            self.operation_percent += equip.get_property_value(
                PROPERTY_STAFF_OPERATION_PERCENT)

            if slot_id not in [self.equip_decoration, self.equip_special]:
                # 装备加成不算 饰品,神器
                levels.append(data['level'])
                qualities.append(config.quality)

        # 装备加成
        if len(levels) == 3:
            equip_level_addition = ConfigStaffEquipmentAddition.get_by_level(
                min(levels))
            if equip_level_addition:
                self.attack += equip_level_addition.attack
                self.attack_percent += equip_level_addition.attack_percent
                self.defense += equip_level_addition.defense
                self.defense_percent += equip_level_addition.defense_percent
                self.manage += equip_level_addition.manage
                self.manage_percent += equip_level_addition.manage_percent

        if len(qualities) == 3:
            equip_quality_addition = ConfigStaffEquipmentAddition.get_by_quality(
                min(qualities))
            if equip_quality_addition:
                self.attack += equip_quality_addition.attack
                self.attack_percent += equip_quality_addition.attack_percent
                self.defense += equip_quality_addition.defense
                self.defense_percent += equip_quality_addition.defense_percent
                self.manage += equip_quality_addition.manage
                self.manage_percent += equip_quality_addition.manage_percent
Ejemplo n.º 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
        )