コード例 #1
0
ファイル: staff.py プロジェクト: yueyoum/dianjing
    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)
コード例 #2
0
ファイル: formation.py プロジェクト: yueyoum/dianjing
    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)
コード例 #3
0
ファイル: resource.py プロジェクト: zhifuliu/dianjing
    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)
コード例 #4
0
ファイル: resource.py プロジェクト: yueyoum/dianjing
    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)
コード例 #5
0
ファイル: staff.py プロジェクト: yueyoum/dianjing
    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
コード例 #6
0
ファイル: bag.py プロジェクト: yueyoum/dianjing
def equipment_batch_destroy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    slot_ids = request._proto.slot_ids

    bag = Bag(server_id, char_id)
    rc = bag.equipment_batch_destroy([i for i in slot_ids])

    response = BagEquipmentBatchDestroyResponse()
    response.ret = 0
    response.drop.MergeFrom(rc.make_protomsg())
    return ProtobufResponse(response)
コード例 #7
0
def equipment_batch_destroy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    slot_ids = request._proto.slot_ids

    bag = Bag(server_id, char_id)
    rc = bag.equipment_batch_destroy([i for i in slot_ids])

    response = BagEquipmentBatchDestroyResponse()
    response.ret = 0
    response.drop.MergeFrom(rc.make_protomsg())
    return ProtobufResponse(response)
コード例 #8
0
def item_destroy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    slot_id = request._proto.slot_id

    bag = Bag(server_id, char_id)
    resource_classified = bag.item_destroy(slot_id)

    response = BagItemDestroyResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())
    return ProtobufResponse(response)
コード例 #9
0
ファイル: bag.py プロジェクト: yueyoum/dianjing
def item_destroy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    slot_id = request._proto.slot_id

    bag = Bag(server_id, char_id)
    resource_classified = bag.item_destroy(slot_id)

    response = BagItemDestroyResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())
    return ProtobufResponse(response)
コード例 #10
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
コード例 #11
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()
コード例 #12
0
def equipment_destroy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    slot_id = request._proto.slot_id
    use_sycee = request._proto.use_sycee

    bag = Bag(server_id, char_id)
    resource_classified = bag.equipment_destroy(slot_id, use_sycee)

    response = BagEquipmentDestroyResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())

    return ProtobufResponse(response)
コード例 #13
0
ファイル: bag.py プロジェクト: yueyoum/dianjing
def equipment_destroy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    slot_id = request._proto.slot_id
    use_sycee = request._proto.use_sycee

    bag = Bag(server_id, char_id)
    resource_classified = bag.equipment_destroy(slot_id, use_sycee)

    response = BagEquipmentDestroyResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())

    return ProtobufResponse(response)
コード例 #14
0
ファイル: resource.py プロジェクト: zhifuliu/dianjing
    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)
コード例 #15
0
ファイル: bag.py プロジェクト: yueyoum/dianjing
def item_use(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    slot_id = request._proto.slot_id
    amount = request._proto.amount
    index = request._proto.index

    bag = Bag(server_id, char_id)
    resource_classified = bag.item_use(slot_id, amount, index=index)

    response = BagItemUseResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())

    return ProtobufResponse(response)
コード例 #16
0
def item_use(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    slot_id = request._proto.slot_id
    amount = request._proto.amount
    index = request._proto.index

    bag = Bag(server_id, char_id)
    resource_classified = bag.item_use(slot_id, amount, index=index)

    response = BagItemUseResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())

    return ProtobufResponse(response)
コード例 #17
0
ファイル: staff.py プロジェクト: yueyoum/dianjing
    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
コード例 #18
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)
コード例 #19
0
ファイル: resource.py プロジェクト: zhifuliu/dianjing
    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)
コード例 #20
0
def equipment_level_up(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    slot_id = request._proto.slot_id
    single = request._proto.single

    if single:
        times = 1
    else:
        times = 5

    bag = Bag(server_id, char_id)
    error_code, levelup, equip = bag.equipment_level_up(slot_id, times)

    response = BagEquipmentLevelupResponse()
    response.ret = error_code
    response.equipment.MergeFrom(equip.make_protomsg())
    response.levelup = levelup
    return ProtobufResponse(response)
コード例 #21
0
ファイル: bag.py プロジェクト: yueyoum/dianjing
def equipment_level_up(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    slot_id = request._proto.slot_id
    single = request._proto.single

    if single:
        times = 1
    else:
        times = 5

    bag = Bag(server_id, char_id)
    error_code, levelup, equip = bag.equipment_level_up(slot_id, times)

    response = BagEquipmentLevelupResponse()
    response.ret = error_code
    response.equipment.MergeFrom(equip.make_protomsg())
    response.levelup = levelup
    return ProtobufResponse(response)
コード例 #22
0
ファイル: plunder.py プロジェクト: yueyoum/dianjing
    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()
コード例 #23
0
ファイル: resource.py プロジェクト: yueyoum/dianjing
    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)
コード例 #24
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
コード例 #25
0
ファイル: plunder.py プロジェクト: yueyoum/dianjing
    def get_result(self):
        if not self.doc['item_id']:
            raise GameException(ConfigErrorMessage.get_error_id("SPECIAL_EQUIPMENT_NOT_IN_PROCESS"))

        if arrow.utcnow().timestamp < self.doc['finish_at']:
            raise GameException(ConfigErrorMessage.get_error_id("SPECIAL_EQUIPMENT_NOT_FINISH"))

        tp = self.doc['tp']
        score = self.doc['score'][str(tp)]
        growing = ConfigEquipmentSpecialScoreToGrowing.get_random_growing_by_score(tp, score)

        config_generate = ConfigEquipmentSpecialGenerate.get(self.doc['item_id'])

        if tp == SPECIAL_EQUIPMENT_GENERATE_NORMAL:
            equip_id = random.choice(config_generate.normal_generate)
            if growing >= GlobalConfig.value("EQUIPMENT_SPECIAL_NORMAL_SCORE_RESET_AT"):
                new_score = 0
            else:
                new_score = score + 1
        else:
            equip_id = random.choice(config_generate.advance_generate)
            if growing >= GlobalConfig.value("EQUIPMENT_SPECIAL_ADVANCE_SCORE_RESET_AT"):
                new_score = 0
            else:
                new_score = score + 1

        config_property = ConfigEquipmentSpecialGrowingProperty.get_by_growing(growing)
        config_equipment = ConfigEquipmentSpecial.get(equip_id)

        properties = []
        for k, v in PROPERTY_TO_NAME_MAP.iteritems():
            if k in SPECIAL_EQUIPMENT_BASE_PROPERTY:
                continue

            if getattr(config_equipment, v, 0):
                properties.append(k)

        equip_properties = []
        for _ in config_property.property_active_levels:
            p = random.choice(properties)
            equip_properties.append(p)

        equip_skills = []
        for _ in config_property.skill_active_levels:
            s = random.choice(config_equipment.skills)
            equip_skills.append(s)

        equip_obj = Equipment.initialize_for_special(equip_id, self.doc['item_id'], tp, growing, equip_properties,
                                                     equip_skills)
        bag = Bag(self.server_id, self.char_id)
        bag.add_equipment_object(equip_obj)

        self.doc['item_id'] = 0
        self.doc['finish_at'] = 0
        self.doc['tp'] = 0
        self.doc['score'][str(tp)] = new_score

        MongoSpecialEquipment.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'item_id': 0,
                'finish_at': 0,
                'tp': 0,
                'score.{0}'.format(tp): new_score
            }}
        )

        ValueLogSpecialEquipmentGenerateTimes(self.server_id, self.char_id).record()
        self.send_notify()

        return equip_obj
コード例 #26
0
ファイル: game.py プロジェクト: zhifuliu/dianjing
def game_start_handler(server_id, char_id, **kwargs):
    MessagePipe(char_id).clean()

    msg = UTCNotify()
    msg.timestamp = arrow.utcnow().timestamp
    MessagePipe(char_id).put(msg=msg)

    msg = SocketServerNotify()
    ss = random.choice(settings.SOCKET_SERVERS)
    msg.ip = ss['host']
    msg.port = ss['tcp']
    MessagePipe(char_id).put(msg=msg)

    _Resource.send_notify(server_id, char_id)

    UnitManager(server_id, char_id).send_notify()

    Bag(server_id, char_id).send_notify()

    StaffManger(server_id, char_id).send_notify()
    StaffRecruit(server_id, char_id).send_notify()

    f = Formation(server_id, char_id)
    f.send_formation_notify()
    f.send_slot_notify()

    club = Club(server_id, char_id)
    club.set_login()
    club.send_notify()

    msg = CreateDaysNotify()
    msg.days = days_passed(club.create_at)
    msg.create_at = club.create_at
    MessagePipe(char_id).put(msg=msg)

    chall = Challenge(server_id, char_id)
    chall.send_chapter_notify()
    chall.send_challenge_notify()

    FriendManager(server_id, char_id).send_notify()
    MailManager(server_id, char_id).send_notify()

    TaskMain(server_id, char_id).send_notify()
    TaskDaily(server_id, char_id).send_notify()

    Chat(server_id, char_id).send_notify()

    Notification(server_id, char_id).send_notify()

    FinanceStatistics(server_id, char_id).send_notify()

    TalentManager(server_id, char_id).send_notify()

    Dungeon(server_id, char_id).send_notify()

    a = Arena(server_id, char_id)
    a.send_notify()
    a.send_honor_notify()

    t = Tower(server_id, char_id)
    t.send_notify()
    t.send_goods_notify()

    Territory(server_id, char_id).send_notify()
    TerritoryStore(server_id, char_id).send_notify()
    TerritoryFriend(server_id, char_id).send_remained_times_notify()

    Store(server_id, char_id).send_notify()
    VIP(server_id, char_id).send_notify()
    Collection(server_id, char_id).send_notify()

    Energy(server_id, char_id).send_notify()

    w = Welfare(server_id, char_id)
    w.send_signin_notify()
    w.send_new_player_notify()
    w.send_level_reward_notify()
    w.send_energy_reward_notify()

    Union(server_id, char_id).send_all_notify()

    Purchase(server_id, char_id).send_notify()

    ac = ActivityNewPlayer(server_id, char_id)
    ac.send_notify()
    ac.send_daily_buy_notify()

    ActivityOnlineTime(server_id, char_id).send_notify()
    ActivityChallenge(server_id, char_id).send_notify()
    ActivityPurchaseDaily(server_id, char_id).send_notify()
    ActivityPurchaseContinues(server_id, char_id).send_notify()
    ActivityLevelGrowing(server_id, char_id).send_notify()

    p = Plunder(server_id, char_id)

    p.send_search_notify()
    p.send_result_notify()
    p.send_revenge_notify()
    p.send_station_notify()
    p.send_formation_notify()
    p.send_plunder_times_notify()
    p.send_plunder_daily_reward_notify()

    SpecialEquipmentGenerator(server_id, char_id).send_notify()

    Party(server_id, char_id).send_notify()

    ins = Inspire(server_id, char_id)
    ins.try_open_slots(send_notify=False)
    ins.send_notify()

    cs = Championship(server_id, char_id)
    cs.try_initialize(send_notify=False)
    cs.send_notify()

    WinningPlunder(server_id, char_id).send_notify()
    WinningArena(server_id, char_id).send_notify()
    WinningChampionship(server_id, char_id).send_notify()
    Worship(server_id, char_id).send_notify()
    CommonArenaWinningChat(server_id, char_id).send_notify()
    CommonPlunderWinningChat(server_id, char_id).send_notify()
    CommonChampionshipChat(server_id, char_id).send_notify()

    send_system_notify(server_id, char_id)
    BroadCast(server_id, char_id).try_cast_login_notify()
コード例 #27
0
    def get_result(self):
        if not self.doc['item_id']:
            raise GameException(
                ConfigErrorMessage.get_error_id(
                    "SPECIAL_EQUIPMENT_NOT_IN_PROCESS"))

        if arrow.utcnow().timestamp < self.doc['finish_at']:
            raise GameException(
                ConfigErrorMessage.get_error_id(
                    "SPECIAL_EQUIPMENT_NOT_FINISH"))

        tp = self.doc['tp']
        score = self.doc['score'][str(tp)]
        growing = ConfigEquipmentSpecialScoreToGrowing.get_random_growing_by_score(
            tp, score)

        config_generate = ConfigEquipmentSpecialGenerate.get(
            self.doc['item_id'])

        if tp == SPECIAL_EQUIPMENT_GENERATE_NORMAL:
            equip_id = random.choice(config_generate.normal_generate)
            if growing >= GlobalConfig.value(
                    "EQUIPMENT_SPECIAL_NORMAL_SCORE_RESET_AT"):
                new_score = 0
            else:
                new_score = score + 1
        else:
            equip_id = random.choice(config_generate.advance_generate)
            if growing >= GlobalConfig.value(
                    "EQUIPMENT_SPECIAL_ADVANCE_SCORE_RESET_AT"):
                new_score = 0
            else:
                new_score = score + 1

        config_property = ConfigEquipmentSpecialGrowingProperty.get_by_growing(
            growing)
        config_equipment = ConfigEquipmentSpecial.get(equip_id)

        properties = []
        for k, v in PROPERTY_TO_NAME_MAP.iteritems():
            if k in SPECIAL_EQUIPMENT_BASE_PROPERTY:
                continue

            if getattr(config_equipment, v, 0):
                properties.append(k)

        equip_properties = []
        for _ in config_property.property_active_levels:
            p = random.choice(properties)
            equip_properties.append(p)

        equip_skills = []
        for _ in config_property.skill_active_levels:
            s = random.choice(config_equipment.skills)
            equip_skills.append(s)

        equip_obj = Equipment.initialize_for_special(equip_id,
                                                     self.doc['item_id'], tp,
                                                     growing, equip_properties,
                                                     equip_skills)
        bag = Bag(self.server_id, self.char_id)
        bag.add_equipment_object(equip_obj)

        self.doc['item_id'] = 0
        self.doc['finish_at'] = 0
        self.doc['tp'] = 0
        self.doc['score'][str(tp)] = new_score

        MongoSpecialEquipment.db(self.server_id).update_one(
            {'_id': self.char_id}, {
                '$set': {
                    'item_id': 0,
                    'finish_at': 0,
                    'tp': 0,
                    'score.{0}'.format(tp): new_score
                }
            })

        ValueLogSpecialEquipmentGenerateTimes(self.server_id,
                                              self.char_id).record()
        self.send_notify()

        return equip_obj
コード例 #28
0
ファイル: statistics.py プロジェクト: zhifuliu/dianjing
    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
        )
コード例 #29
0
    def make_club_troop_msg(self, club_obj, skill_sequence):
        """

        :type club_obj: core.abstract.AbstractClub
        :type skill_sequence: dict[int, list]
        """
        from core.club import Club
        from core.bag import Bag, Equipment

        if isinstance(club_obj, Club):
            bag = Bag(club_obj.server_id, club_obj.char_id)
            slots = bag.doc['slots']
        else:
            slots = {}

        msg = MessageClubTroop()
        msg.club.MergeFrom(club_obj.make_protomsg())

        for fs in club_obj.formation_staffs:
            if not fs.unit:
                continue

            msg_troop = msg.troop.add()
            msg_troop.hero.id = fs.id
            msg_troop.hero.oid = fs.oid
            msg_troop.hero.position = fs.formation_position
            msg_troop.hero.attack = fs.attack
            msg_troop.hero.attackPercent = fs.attack_percent
            msg_troop.hero.defense = fs.defense
            msg_troop.hero.defensePercent = fs.defense_percent
            msg_troop.hero.manage = fs.manage
            msg_troop.hero.managePercent = fs.manage_percent
            msg_troop.hero.operation = fs.operation
            msg_troop.hero.operationPercent = fs.operation_percent
            msg_troop.hero.star = fs.star

            msg_troop.army.id = fs.unit.id
            msg_troop.army.hp = fs.unit.hp
            msg_troop.army.hpPercent = fs.unit.hp_percent
            msg_troop.army.attack = fs.unit.attack
            msg_troop.army.attackPercent = fs.unit.attack_percent
            msg_troop.army.defense = fs.unit.defense
            msg_troop.army.defensePercent = fs.unit.defense_percent
            msg_troop.army.attackSpeed = fs.unit.attack_speed
            msg_troop.army.attackSpeedPercent = fs.unit.attack_speed_percent
            msg_troop.army.attackDistance = fs.unit.attack_range
            msg_troop.army.attackDistancePercent = fs.unit.attack_range_percent
            msg_troop.army.moveSpeed = fs.unit.move_speed
            msg_troop.army.moveSpeedPercent = fs.unit.move_speed_percent
            msg_troop.army.hitRate = fs.unit.hit_rate
            msg_troop.army.dodgeRate = fs.unit.dodge_rate
            msg_troop.army.critRate = fs.unit.crit_rate
            msg_troop.army.critMulti = fs.unit.crit_multiple
            msg_troop.army.critAntiRate = fs.unit.toughness_rate

            msg_troop.army.appendAttackTerran = fs.unit.hurt_addition_to_terran
            msg_troop.army.appendAttackProtoss = fs.unit.hurt_addition_to_protoss
            msg_troop.army.appendAttackZerg = fs.unit.hurt_addition_to_zerg

            msg_troop.army.appendAttackedByTerran = fs.unit.hurt_addition_by_terran
            msg_troop.army.appendAttackedByProtoss = fs.unit.hurt_addition_by_protoss
            msg_troop.army.appendAttackedByZerg = fs.unit.hurt_addition_by_zerg

            msg_troop.army.finalHurtAppend = fs.unit.final_hurt_addition
            msg_troop.army.finalHurtReduce = fs.unit.final_hurt_reduce

            msg_troop.policy = fs.policy

            if fs.equip_special:
                slot_data = slots.get(fs.equip_special, '')
                if slot_data:
                    equip = Equipment.load_from_slot_data(slot_data)
                    msg_troop.special_equipment_skills.extend(
                        equip.get_active_skills_ids())

        for i in range(1, self.skill_sequence_amount + 1):
            notify_skill_sequence = msg.skill_sequence.add()
            notify_skill_sequence.id = i
            notify_skill_sequence.staff_id.extend(
                skill_sequence.get(i, ["", "", ""]))

        return msg
コード例 #30
0
ファイル: club.py プロジェクト: zhifuliu/dianjing
    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)