def init_equipment_chip(player):

    for k, val in game_configs.chip_config.get('chips').items():
        if val.get('type') == 1:
            continue
        equipment_chip = EquipmentChip(int(k), 1000)
        player.equipment_chip_component.add_chip(equipment_chip)

    return
    chip1 = EquipmentChip(2100005, 16)
    chip2 = EquipmentChip(2100006, 16)

    player.equipment_chip_component.add_chip(chip1)
    player.equipment_chip_component.add_chip(chip2)
Beispiel #2
0
    def init_data(self):
        equipment_chip_data = tb_character_equipment_chip.getObjData(self.owner.base_info.id)

        if equipment_chip_data:
            chips = equipment_chip_data.get('chips')
            for chip_no, chip_num in chips.items():
                equipment_chip = EquipmentChip(chip_no, chip_num)
                self._chips[chip_no] = equipment_chip
        else:
            data = {'id': self.owner.base_info.id, 'chips': {}}
            tb_character_equipment_chip.new(data)
Beispiel #3
0
def deal_target_player(player, target_id, chip_id):
    target_data_obj = tb_character_info.getObj(target_id)
    isexist = target_data_obj.exists()
    if not isexist:
        logger.error('deal_target_player, player id error')
        return

    target_data = target_data_obj.hmget(['equipment_chips', 'truce'])
    now = int(time.time())
    truce = target_data.get('truce', [0, 0])
    item_config_item = game_configs.item_config.get(130001)
    end_time = truce[1] + truce[0] * item_config_item.funcArg1 * 60
    if truce[1] and end_time > now:
        return
    chips = target_data.get('equipment_chips')
    chips_obj = {}
    for chip_id_x, chip_num in chips.items():
        equipment_chip = EquipmentChip(chip_id_x, chip_num)
        chips_obj[chip_id_x] = equipment_chip

    chip_obj = chips_obj.get(chip_id)
    if not chip_obj or chip_obj.chip_num == 0:
        return
    # 如果对方有的话
    is_online = remote_gate.is_online_remote('modify_equ_chip_remote',
                                             target_id, {'chip_id': chip_id})
    if is_online == "notonline":
        chip_obj.chip_num -= 1

        props = {}
        for chip_id_x, chip_obj in chips_obj.items():
            if chip_obj.chip_num:  # 如果chip num == 0, 则不保存
                props[chip_id_x] = chip_obj.chip_num
        target_data_obj.hset('equipment_chips', props)

    mail_arg1 = [{104: [1, 1, chip_id]}]
    send_mail(conf_id=701,
              receive_id=target_id,
              nickname=player.base_info.base_name,
              arg1=str(mail_arg1))
Beispiel #4
0
def gain(player, item_group, reason,
         result=None,
         multiple=1,
         event_id='',
         part_multiple=[],
         lucky_attr_id=0):
    """获取
    @param item_group: [obj,obj]
    act 掉落翻倍. [[type_ids], xs]  [[翻倍类型列表],系数]
    """
    if result is None:
        result = []
    after_num = 0
    itid = 0

    for group_item in item_group:
        type_id = group_item.item_type

        num = int(group_item.num * multiple)
        item_no = group_item.item_no

        multiple2 = 1
        for _part_multiple in part_multiple:
            _times = _part_multiple["times"]
            _item_type = _part_multiple["item_type"]
            _item_ids = _part_multiple["item_ids"]
            if type_id == _item_type:
                if not _item_ids[0] or item_no in _item_ids:
                    multiple2 = _times

        logger.debug("multiple %s multiple2 %s" % (multiple, multiple2))
        num = int(multiple2 * num)

        front_type_id = type_id # 记录类型,用于武将已存在的情况。
        if type_id == const.COIN:
            player.finance.coin += num
            player.finance.save_data()
            after_num = player.finance.coin

        elif type_id == const.RESOURCE:
            if item_no == 27:
                hook_task(player, CONDITIONId.GGZJ, num)
            elif item_no == const.TEAM_EXPERIENCE:
                player.base_info.addexp(num, reason)
                player.base_info.save_data()
                after_num = player.base_info.exp
            else:
                player.finance.add(item_no, num)
                player.finance.save_data()
                after_num = player.finance[item_no]

            if item_no == 1 or item_no == 2:
                tlog_action.log('MoneyFlow', player, after_num, num, reason,
                                const.ADD, item_no)

        elif type_id == const.GOLD:
            player.finance.add_gold(num, 0)
            player.finance.save_data()

        elif type_id == const.HERO_SOUL:
            player.finance.hero_soul += num
            player.finance.save_data()

        elif type_id == const.PVP:
            player.finance.pvp_score += num
            player.finance.save_data()

        elif type_id == const.HERO_CHIP:
            if game_configs.chip_config.get('chips').get(item_no):
                hero_chip = HeroChip(item_no, num)
                player.hero_chip_component.add_chip(hero_chip)
                player.hero_chip_component.save_data()
                after_num = player.hero_chip_component.get_chip(item_no).num
            else:
                logger.error('chip config not found:%', item_no)

        elif type_id == const.ITEM:
            item = Item(item_no, num)
            player.item_package.add_item(item)
            player.item_package.save_data()
            after_num = player.item_package.get_item(item_no).num

        elif type_id == const.HERO:
            is_have = player.hero_component.contain_hero(item_no)
            if not is_have:
                num -= 1
            if num != 0:
                # 已经存在该武将,自动转换为武将碎片
                # 获取hero对应的hero_chip_no, hero_chip_num
                hero_chip_config_item = game_configs.chip_config.get("mapping").get(item_no)
                hero_chip_no = hero_chip_config_item.id
                CardImparirment = 1
                if reason == const.SHOP_DRAW_HERO:
                    CardImparirment = game_configs.base_config.get("CardImparirment")
                hero_chip_num = int(hero_chip_config_item.needNum * num * CardImparirment)

                hero_chip = HeroChip(hero_chip_no, hero_chip_num)
                player.hero_chip_component.add_chip(hero_chip)
                player.hero_chip_component.save_data()
                after_num = player.hero_chip_component.get_chip(hero_chip_no).num

                result.append([const.HERO_CHIP, hero_chip_num, hero_chip_no])

                tlog_action.log('ItemFlow', player, const.ADD, type_id,
                                hero_chip_num, hero_chip_no, itid, reason,
                                after_num, event_id)
            if not is_have:
                hero = player.hero_component.add_hero(item_no)
                notice_item = game_configs.notes_config.get(2002)
                logger.debug("=================%s %s %s" % (reason, hero.hero_info.quality, notice_item.parameter1))
                if reason == const.SHOP_DRAW_HERO and hero.hero_info.quality in notice_item.parameter1:
                    push_notice(2002, player_name=player.base_info.base_name, hero_no=item_no)
                after_num = 1

                result.append([type_id, 1, item_no])

                tlog_action.log('ItemFlow', player, const.ADD, type_id,
                                1, item_no, itid, reason,
                                after_num, event_id)

        elif type_id == const.BIG_BAG:
            big_bag = BigBag(item_no)
            for i in range(num):
                temp = big_bag.get_drop_items()
                gain(player, temp, reason, result)
            return result

        elif type_id == const.EQUIPMENT:
            for _ in range(num):
                itid = item_no
                equipment = player.equipment_component.add_equipment(itid, lucky_attr_id)
                equ_item_no = equipment.base_info.id
                after_num = player.equipment_component.get_equipment_num(itid)
                notice_item = game_configs.notes_config.get(2004)
                if reason == const.COMMON_BUY_PVP and equipment.equipment_config_info.quality in notice_item.parameter1:
                    push_notice(2004, player_name=player.base_info.base_name, equipment_no=itid)

                notice_item = game_configs.notes_config.get(2005)
                if reason ==const.COMMON_BUY_MELT and equipment.equipment_config_info.quality in notice_item.parameter1:
                    push_notice(2005, player_name=player.base_info.base_name, equipment_no=itid)

                notice_item = game_configs.notes_config.get(2006)
                if reason == const.COMMON_BUY_EQUIPMENT and equipment.equipment_config_info.quality in notice_item.parameter1:
                    push_notice(2006, player_name=player.base_info.base_name, equipment_no=itid)

                result.append([type_id, 1, equ_item_no])
                tlog_action.log('ItemFlow', player, const.ADD, type_id, 1,
                                itid, item_no, reason, after_num, event_id)

        elif type_id == const.EQUIPMENT_CHIP:
            if game_configs.chip_config.get('chips').get(item_no):
                chip = EquipmentChip(item_no, num)
                player.equipment_chip_component.add_chip(chip)
                player.equipment_chip_component.save_data()
                after_num = player.equipment_chip_component.get_chip(item_no).chip_num
            else:
                logger.error('chip config not found:%', item_no)

        elif type_id == const.STAMINA:
            player.stamina.stamina += num
            # logger.debug(str(num)+" , stamina+++++++++++")
            player.stamina.save_data()

        elif type_id == const.TEAM_EXPERIENCE:
            player.base_info.addexp(num, reason)
            player.base_info.save_data()

        elif type_id == const.TRAVEL_ITEM:
            after_num = num
            stage_id = game_configs.travel_item_config.get('items').get(item_no).stageId
            flag1 = 1
            flag2 = 0
            stage_item_info = player.travel_component.travel_item.get(stage_id)
            for [travel_item_id, travel_item_num] in stage_item_info:
                if travel_item_id == item_no:
                    the_num = travel_item_num + num
                    stage_item_info[flag2] = \
                        [travel_item_id, the_num]
                    flag1 = 0
                    after_num = the_num
                    break
                flag2 += 1
            if flag1:
                stage_item_info.append([item_no, num])
            player.travel_component.save()

        elif type_id == const.RUNT:
            for _ in range(num):
                runt_id = player.runt.add_runt(item_no)
                result.append([type_id, 1, runt_id])
            player.runt.save()
            after_num = player.runt.get_runt_num(item_no)

        if type_id == const.COIN or type_id == const.GOLD:
            tlog_action.log('MoneyFlow', player, after_num, num, reason,
                            const.ADD, item_no)

        is_over = False       # 是否累加
        for i in result:
            if i[0] == type_id and i[2] == item_no and (front_type_id != const.HERO and type_id != const.HERO_CHIP and type_id != const.RUNT and type_id != const.EQUIPMENT and type_id != const.HERO):
                i[1] += num
                is_over = True
                continue

        if not is_over and type_id !=const.RUNT and type_id != const.HERO and type_id != const.EQUIPMENT:
            result.append([type_id, num, item_no])

        # ====tlog======
        if type_id != const.TEAM_EXPERIENCE and type_id != const.EQUIPMENT and type_id != const.HERO:
            tlog_action.log('ItemFlow', player, const.ADD, type_id, num,
                            item_no, itid, reason, after_num, event_id)
        # ==============

    return result
 def init_data(self, character_info):
     chips = character_info.get('equipment_chips')
     for chip_no, chip_num in chips.items():
         equipment_chip = EquipmentChip(chip_no, chip_num)
         self._chips[chip_no] = equipment_chip
Beispiel #6
0
def gain(player, item_group, result=None):
    """获取
    @param item_group: [obj,obj]
    """
    if result is None:
        result = []

    for group_item in item_group:
        type_id = group_item.item_type
        num = group_item.num
        item_no = group_item.item_no
        if type_id == const.COIN:
            player.finance.coin += num
            player.finance.save_data()

        elif type_id == const.GOLD:
            player.finance.gold += num
            player.finance.save_data()

        elif type_id == const.HERO_SOUL:
            player.finance.hero_soul += num
            player.finance.save_data()

        elif type_id == const.JUNIOR_STONE:
            player.finance.junior_stone += num
            player.finance.save_data()
        elif type_id == const.MIDDLE_STONE:
            player.finance.middle_stone += num
            player.finance.save_data()
        elif type_id == const.HIGH_STONE:
            player.finance.high_stone += num
            player.finance.save_data()

        elif type_id == const.HERO_CHIP:
            hero_chip = HeroChip(item_no, num)
            player.hero_chip_component.add_chip(hero_chip)
            player.hero_chip_component.save_data()

        elif type_id == const.ITEM:
            item = Item(item_no, num)
            player.item_package.add_item(item)
            player.item_package.save_data()

        elif type_id == const.HERO:
            if player.hero_component.contain_hero(item_no):
                # 已经存在该武将,自动转换为武将碎片
                # 获取hero对应的hero_chip_no, hero_chip_num
                hero_chip_config_item = chip_config.get("mapping").get(item_no)
                hero_chip_no = hero_chip_config_item.id
                hero_chip_num = hero_chip_config_item.needNum

                hero_chip = HeroChip(hero_chip_no, hero_chip_num)
                player.hero_chip_component.add_chip(hero_chip)
                player.hero_chip_component.save_data()
                type_id = const.HERO_CHIP
                item_no = hero_chip_no
                num = hero_chip_num
            else:
                player.hero_component.add_hero(item_no)

        elif type_id == const.BIG_BAG:
            big_bag = BigBag(item_no)
            for i in range(num):
                gain(player, big_bag.get_drop_items(), result)
            return result

        elif type_id == const.EQUIPMENT:
            equipment = player.equipment_component.add_equipment(item_no)
            item_no = equipment.base_info.id

        elif type_id == const.EQUIPMENT_CHIP:
            chip = EquipmentChip(item_no, num)
            player.equipment_chip_component.add_chip(chip)
            player.equipment_chip_component.save_data()
        elif type_id == const.STAMINA:
            player.stamina.stamina += num
            logger.debug(str(num) + " , stamina+++++++++++")
            player.stamina.save_data()
        elif type_id == const.TRAVEL_ITEM:
            stage_id = travel_item_config.get(item_no).stageId
            flag1 = 1
            flag2 = 0
            stage_item_info = player.travel_component.travel_item.get(stage_id)
            for [travel_item_id, travel_item_num] in stage_item_info:
                if travel_item_id == item_no:
                    stage_item_info[flag2] = \
                        [travel_item_id, travel_item_num + num]
                    flag1 = 0
                    break
                flag2 += 1
            if flag1:
                stage_item_info.append([item_no, num])
            player.travel_component.save()
        elif type_id == u'107':
            shoes = player.travel_component.shoes
            if item_no == 18:
                shoes[0] += num
            elif item_no == 19:
                shoes[1] += num
            elif item_no == 20:
                shoes[2] += num

            player.travel_component.save()

        flag = 1
        for i in result:
            if i[0] == type_id and i[2] == item_no:
                i[1] += 1
                flag = 0
                continue
        if flag:
            result.append([type_id, num, item_no])
        # result.append([type_id, num, item_no])
    return result