def vip_packs_buy(self, msgtype, body): req = poem_pb.VipPacksBuyRequest() req.ParseFromString(body) p = self.player from entity.manager import save_guide save_guide(p, req.guide_type) # 保存新手引导进度 now = int(time.time()) today = datedate.fromtimestamp(now) config = get_config(VipPacksConfig).get(req.ID) if not config: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) if config.gift_type != VipPackType.Daily: if now < config.gift_starttime or now > config.gift_lasttime: return fail_msg(msgtype, msgTips.FAIL_MSG_VIP_PACKS_EXPIRED) rest = get_vip_pack_rest_count(p, req.ID, today=today) if rest != -1 and rest <= 0: return fail_msg(msgtype, reason="次数不足") if p.vip < config.vip_level: return fail_msg(msgtype, reason="VIP不足") cost = parse_reward([{ 'count': config.discount_price, 'type': config.discount_price_type}]) gain = parse_reward(config.rewards) try: apply_reward(p, gain, cost=cost, type=RewardType.VipPacks) except AttrNotEnoughError: return fail_msg(msgtype, reason="消耗不足") set_vip_packs_limits(p, config.ID, now) p.vip_packs_today_bought_count += 1 p.save() p.sync() return success_msg(msgtype, "")
def breed(self, msgtype, body): from protocol.poem_pb import BreedRequest req = BreedRequest() req.ParseFromString(body) player = self.player from entity.manager import save_guide save_guide(player, req.guide_type) # 保存新手引导进度 c = req.count or 1 pet = player.pets.get(req.petID) if not pet: return fail_msg(msgtype, reason='精灵不存在') if pet.level + c > pet.max_level: return fail_msg(msgtype, reason='超过最大等级') # info = get_config(PetConfig)[pet.prototypeID] # money, soul = breed_cost(info.cexp, pet.level, pet.level + c) cost = {} for level in range(pet.level, pet.level + c): linfo = get_config(PetLevelOrSkillLevelUpConfig)[level] combine_reward([linfo.units_cost1, linfo.units_cost2], {}, data=cost) try: apply_reward(player, None, cost=cost, type=RewardType.BreedPet) except AttrNotEnoughError: return fail_msg(msgtype, reason="金币或水晶不足") pet.level += c pet.save() from task.manager import on_breed on_breed(player, pet) # player.update_power() player.save() pet.sync() player.sync() return success_msg(msgtype, '')
def advance(self, msgtype, body): req = AdvanceEquip() req.ParseFromString(body) p = self.player from entity.manager import save_guide save_guide(p, req.guide_type) # 保存新手引导进度 err = advance_equip(p, req.petID, req.equipID, req.equips) if err: return fail_msg(msgtype, err) p.save() p.sync() return success_msg(msgtype, "")
def strengthen(self, msgtype, body): p = self.player req = poem_pb.StrengthenEquip() req.ParseFromString(body) p = self.player from entity.manager import save_guide save_guide(p, req.guide_type) # 保存新手引导进度 err, rollback = strengthen_equip(p, req.petID, req.equipID) if err: return fail_msg(msgtype, err) rsp = poem_pb.StrengthenEquipResponse(success=not rollback) p.save() p.sync() return success_msg(msgtype, rsp)
def refining(self, msgtype, body): from lineup.manager import in_lineup from config.configs import get_config from config.configs import RefineryConfig req = poem_pb.RefiningRequest() req.ParseFromString(body) player = self.player from entity.manager import save_guide save_guide(player, req.guide_type) # 保存新手引导进度 # 统计材料的种类和数量 total_mat = 0 mats = {} for matInfo in req.materials: total_mat += 1 if matInfo.id in mats: mats[matInfo.id] += matInfo.count else: mats[matInfo.id] = matInfo.count if len(req.pet_ids) + len(req.equip_ids) + total_mat > 6: return fail_msg(msgtype, reason='总共可以炼化6个精灵和装备') if len(req.pet_ids) != len(set(req.pet_ids)): return fail_msg(msgtype, reason='重复的精灵实体ID') if len(req.equip_ids) != len(set(req.equip_ids)): return fail_msg(msgtype, reason='重复的装备实体ID') refining_pet = [] configs = get_config(RefineryConfig) rewards = {} for petID in req.pet_ids: pet = player.pets.get(petID) if not pet: return fail_msg(msgtype, reason='找不到精灵炼化') if in_lineup(player, pet.entityID) and \ not in_lineup(player, pet.entityID, type=LineupType.ATK): return fail_msg(msgtype, reason='阵上将不可作为材料') petInfo = get_config(PetConfig)[pet.prototypeID] if not petInfo: return fail_msg(msgtype, msgTips.FAIL_MSG_PET_NOTCONFIG) refinery = configs.get(petInfo.cls) if not refinery: return fail_msg(msgtype, msgTips.FAIL_MSG_PET_NOTCONFIG) addition_rewards = {} # 升级消耗 level_configs = get_config(PetLevelOrSkillLevelUpConfig) level_configs = [level_configs[i] for i in filter( lambda s: s < pet.level, level_configs)] for each in level_configs: combine_reward( [each.units_cost1, each.units_cost2], {}, data=addition_rewards) # 技能消耗 level_configs = get_config(PetLevelOrSkillLevelUpConfig) for l in [1, 2, 3, 4, 5]: slevel = getattr(pet, "skill%d" % l, 1) skilllevel_configs = [ level_configs[i] for i in filter( lambda s: s < slevel, level_configs)] for each in skilllevel_configs: combine_reward( [getattr(each, "skill%d_cost" % l, {})], {}, data=addition_rewards) # 升阶消耗 step = petInfo.rarity * 10 + petInfo.step grow_configs = get_config(GrowthConfig) grow_configs = [grow_configs[i] for i in filter( lambda s: s < step, grow_configs)] for each in grow_configs: combine_reward( {"money": int(each.evo_cost * petInfo.cexp)}, {}, data=addition_rewards) # 升星消耗 break_configs = get_config(BreakConfig) break_configs = [break_configs[i] for i in filter( lambda s: s < pet.breaklevel, break_configs)] for each in break_configs: combine_reward( {"money": each.money}, {}, data=addition_rewards) for k, v in addition_rewards.items(): if isinstance(v, int): addition_rewards[k] = int(v * refinery.scale) for i in range(pet.star // petInfo.need_patch): combine_reward(refinery.rewards, {}, data=rewards) combine_reward(addition_rewards, {}, data=rewards) refining_pet.append(pet) # 神将身上的装备 equips = [] for pet in refining_pet: for e in pet.equipeds.values(): equips.append(player.equips[e]) from config.configs import EquRefineConfig equ_refine_config = get_config(EquRefineConfig) # 单个分解的装备 for equID in req.equip_ids: equ = player.equips[equID] if not equ: return fail_msg(msgtype, reason='找不到装备炼化') equips.append(equ) _equ_refine_config = equ_refine_config.get(equ.prototypeID) if not _equ_refine_config: return fail_msg(msgtype, msgTips.FAIL_MSG_PET_NOTCONFIG) combine_reward(_equ_refine_config.equ_rewards, {}, data=rewards) # 单个分解的材料 matList = [] for matID, count in mats.iteritems(): mat1 = player.mats.get(matID, 0) if mat1 < count: return fail_msg(msgtype, reason='材料数量不足炼化') matList.append([matID, count]) mat_refine_config = equ_refine_config.get(matID) if not mat_refine_config: return fail_msg(msgtype, msgTips.FAIL_MSG_PET_NOTCONFIG) for i in range(0, count): combine_reward(mat_refine_config.mat_rewards, {}, data=rewards) l = list(player.lineups.get(LineupType.ATK, [0, 0, 0, 0])) # 攻击阵型可以被炼化 flag = False for each in refining_pet: if in_lineup(player, each.entityID, type=LineupType.ATK): flag = True l[l.index(each.entityID)] = 0 if flag: save_lineup(player, l, LineupType.ATK) player.del_pets(*refining_pet) player.del_equips(*equips) apply_reward(player, rewards, cost={"matList": matList}, type=RewardType.REFINING) player.save() player.sync() rsp = poem_pb.RefiningResponse() build_reward_msg(rsp, rewards) logger.debug(rsp) return success_msg(msgtype, rsp)
def lottery(self, msgtype, body): req = poem_pb.LotteryRequest() req.ParseFromString(body) p = self.player from entity.manager import save_guide save_guide(p, req.guide_type) # 保存新手引导进度 logger.debug("req: {}".format(req)) LOTTERY_ID2TYPE = { LotteryType.Lottery1: ("A", "ball", 1), LotteryType.Lottery2: ("B", "ball", 10), LotteryType.Lottery3: ("C", "gold", 1), LotteryType.Lottery4: ("D", "gold", 10), } kind_cfg = get_config(LotteryFunctionConfig)[req.type] if req.type not in LOTTERY_ID2TYPE: return fail_msg(msgtype, reason="类型不对") if p.level < kind_cfg.level: return fail_msg(msgtype, reason="等级不足") kind, cost_type, cost_count = LOTTERY_ID2TYPE[req.type] cost = kind_cfg.Price if req.type == LotteryType.Lottery2: if p.ball < 10: cost_count = p.ball cost = p.ball now = time.time() loterry_hero_count = getattr( p, "loterry_hero_count_{}".format(kind)) loterry_hero_gold_first = getattr( p, "loterry_hero_gold_first_{}".format(kind)) loterry_hero_used_free_count = getattr( p, "loterry_hero_used_free_count_{}".format(kind)) or 0 loterry_hero_cd = getattr( p, "loterry_hero_cd_{}".format(kind)) cd = datetime.fromtimestamp(loterry_hero_cd).strftime('%Y-%m-%d %H:%M') logger.debug('loterry_hero_cd: {}'.format(cd)) cd = datetime.fromtimestamp(loterry_hero_cd).strftime('%Y-%m-%d %H:%M') logger.debug('loterry_hero_cd: {}'.format(cd)) key = "NormalGold{}".format(kind) if loterry_hero_cd <= now and \ loterry_hero_used_free_count < kind_cfg.FreeTimes: # 免费 if not loterry_hero_count: # 引导抽 key = "FirstFree{}".format(kind) ID = kind_cfg.rangeset[1] elif loterry_hero_count == 1: # 首抽 key = "NormalFree{}".format(kind) ID = kind_cfg.rangeset[2] else: # 普通 key = "NormalFree{}".format(kind) ID = kind_cfg.rangeset[0] else: # 付费 if not loterry_hero_count: # 引导抽 key = "FirstGold{}".format(kind) ID = kind_cfg.rangeset[1] if not ID: ID = kind_cfg.rangeset[2] elif loterry_hero_count == 1: # 首抽 key = "FirstGold{}".format(kind) ID = kind_cfg.rangeset[2] else: key = "NormalGold{}".format(kind) ID = kind_cfg.rangeset[0] loterry_hero_count += 1 logger.debug( '\nused_free_count_A: {},\ \nused_free_count_B: {},\ \nused_free_count_C: {},\ \nused_free_count_D: {}'.format( p.loterry_hero_used_free_count_A, p.loterry_hero_used_free_count_B, p.loterry_hero_used_free_count_C, p.loterry_hero_used_free_count_D)) logger.debug('loterry_hero_key: {}'.format(key)) costs = {} if "Free" in key: cost = 0 loterry_hero_used_free_count += 1 loterry_hero_cd = now + kind_cfg.ColdDown else: costs = {cost_type: cost} if p.lottery_campaign_discount < 10: gold = costs.get("gold", 0) if gold: gold = int(gold * p.lottery_campaign_discount / float(10)) costs["gold"] = gold try: from reward.base import check_cost_attr check_cost_attr(p, costs) except AttrNotEnoughError: return fail_msg(msgtype, reason="材料不足") loterry_hero_gold_first = False if not ID: ID = kind_cfg.rangeset[0] attr_drop = get_config(AttributeDroppackConfig)[ID] dropID = attr_drop.RewardDroppack if cost_type == "gold": if cost_count > 1: if p.lottery_gold_accumulating10 >= abs( attr_drop.Accumulating): dropID = attr_drop.AccumDroppack if attr_drop.Accumulating > 0: p.lottery_gold_accumulating10 -= attr_drop.Accumulating else: if p.lottery_gold_accumulating >= abs( attr_drop.Accumulating): dropID = attr_drop.AccumDroppack if attr_drop.Accumulating > 0: p.lottery_gold_accumulating -= attr_drop.Accumulating else: if cost_count > 1: if p.lottery_money_accumulating10 >= abs( attr_drop.Accumulating): dropID = attr_drop.AccumDroppack if attr_drop.Accumulating > 0: p.lottery_money_accumulating10 -= \ attr_drop.Accumulating else: if p.lottery_money_accumulating >= abs( attr_drop.Accumulating): dropID = attr_drop.AccumDroppack if attr_drop.Accumulating > 0: p.lottery_money_accumulating -= attr_drop.Accumulating logger.debug("DropID:{}".format(dropID)) rsp = poem_pb.LotteryResponse() reward = open_reward(RewardType.Lottery, rsp, dropID, cost_count) from campaign.manager import g_campaignManager if g_campaignManager.hot_lottery_campaign.is_open() and\ req.type == LotteryType.Lottery4: campaign_config = g_campaignManager.hot_lottery_campaign.\ get_current() hot_configs = get_config(HotLotteryCampaignConfig).get( campaign_config.group, []) hot_rewards = weighted_random2([ [i.rewards, i.prob] for i in hot_configs]) reward.add(parse_reward(hot_rewards)) rsp.hot_rewards = hot_rewards reward.cost_after(p, **costs) extra = {} result = reward.apply(p, extra=extra) logger.debug("result {}:".format(result)) # Save setattr( p, "loterry_hero_count_{}".format(kind), loterry_hero_count) setattr( p, "loterry_hero_gold_first_{}".format(kind), loterry_hero_gold_first) setattr( p, "loterry_hero_used_free_count_{}".format(kind), loterry_hero_used_free_count) setattr( p, "loterry_hero_cd_{}".format(kind), loterry_hero_cd) is_first_consume = int(not p.consume_count and bool( p.lottery_count) and (cost_type == "gold")) role_custom.info(player=p, type=role_custom.Consume, arg1=ujson.dumps({ "type": RewardType.Lottery, "kind": req.type, "cost": costs, "is_first_consume": is_first_consume, })) p.lottery_count += cost_count from task.manager import on_lottery on_lottery(p, cost_count, (cost_type == "gold")) if kind == "D": from task.manager import on_lottery10 on_lottery10(p) ACCUMULATING_DELTA = 1 if cost_type == "gold": if cost_count > 1: p.lottery_gold_accumulating10 += \ ACCUMULATING_DELTA * kind_cfg.Price else: p.lottery_gold_accumulating += \ ACCUMULATING_DELTA * kind_cfg.Price p.consume_count += 1 else: if cost_count > 1: p.lottery_money_accumulating10 += \ ACCUMULATING_DELTA * kind_cfg.Price else: p.lottery_money_accumulating += \ ACCUMULATING_DELTA * kind_cfg.Price if "FirstFree" not in key: save_guide(p, "FAKE_GOLDEN_LOTTERY") from task.manager import on_collect_pet1 from task.manager import on_collect_pet2 pets = extra.get("pets", []) on_collect_pet1(p, *pets) on_collect_pet2(p, *pets) p.save() p.sync() from chat.manager import on_news_pet_quality_lottery from chat.manager import on_news_pet_special_lottery from chat.manager import on_news_equip_quality_lottery on_news_pet_quality_lottery(p, rsp.rewards) on_news_pet_special_lottery(p, rsp.rewards) on_news_equip_quality_lottery(p, rsp.rewards) return success_msg(msgtype, rsp)
def evolute(self, msgtype, body): from lineup.manager import in_lineup from reward.constants import RewardItemType req = RequestHeroEvolution() req.ParseFromString(body) player = self.player from entity.manager import save_guide save_guide(player, req.guide_type) # 保存新手引导进度 pet = player.pets.get(req.targetHeroID) if not pet: return fail_msg(msgtype, reason='找不到对应的将') configs = get_config(PetConfig) info = configs.get(pet.prototypeID) grow = get_config(GrowthConfig)[info.rarity * 10 + info.step] if not info: return fail_msg(msgtype, reason='找不到对应的将') if pet.level < grow.hero_lv: # 检查等级是否为满级 return fail_msg(msgtype, reason='等级不足') # if in_lineup(player, pet.entityID) and \ # not in_lineup(player, pet.entityID, type=LineupType.ATK): # return fail_msg(msgtype, reason='阵上将不可作为材料') price = int(grow.evo_cost * info.cexp) # 取得开销 logger.debug('ID {}, price {}'.format(info.rarity * 10 + info.step, price)) gups = zip(info.gups, info.guptypes, info.gupnums) need_mats, need_pets = {}, {} for gup, guptype, gupnum in gups: if guptype == RewardItemType.Mat: need_mats[gup] = need_mats.setdefault(gup, 0) + gupnum elif guptype == RewardItemType.Pet: need_pets[gup] = need_pets.setdefault(gup, 0) + gupnum else: continue all_pets = {} for petID, p in player.pets.items(): all_pets.setdefault(p.prototypeID, []).append(petID) pets, mats = [], [list(i) for i in need_mats.items()] for k, v in need_pets.items(): ps = filter( lambda s: not in_lineup(player, s) and not have_break_level( player, s), all_pets.get(k, [])) if len(ps) < v: return fail_msg(msgtype, reason='材料不足') pets.extend([player.pets[i] for i in ps[:v]]) assert len(pets) == len(set(pets)), '有重复的pet' try: apply_reward(player, {}, cost={ 'matList': mats, 'money': price }, type=RewardType.EvolutionPet) except AttrNotEnoughError: return fail_msg(msgtype, reason='金币不足') except MatNotEnoughError: return fail_msg(msgtype, reason='材料不足') else: # 删除材料英雄 equips = [] for each in pets: for k, v in each.equipeds.items(): e = player.equips.get(v) if e: equips.append(e) l = list(player.lineups.get(LineupType.ATK, [0, 0, 0, 0])) # 攻击阵型可以被炼化 flag = False for each in pets: if in_lineup(player, each.entityID, type=LineupType.ATK): flag = True l[l.index(each.entityID)] = 0 if flag: save_lineup(player, l, LineupType.ATK) player.del_pets(*pets) player.del_equips(*equips) # 进阶, 精灵等级,精灵突破等级,精灵技能等级要进行继承 pet.prototypeID = info.gupr # 情缘 # FIXME from config.configs import AntiRelationConfig from config.configs import RelationConfig sames_info = get_config(AntiRelationConfig) relas_info = get_config(RelationConfig) same = sames_info.get(info.same) if same: for each in same.relas: rela = relas_info.get(each) if not rela: continue if rela.same in player.sames: needs = set() for i in rela.units: ii = configs.get(i) if not ii: continue needs.add(ii.same) if len(needs & set(player.sames)) == len(needs): flag = False for same in needs: if same == rela.same: continue for petID in player.sames.get(same, []): ii = configs[player.pets[petID].prototypeID] if ii.rarity == 5: flag = True break if not flag: break for petID in player.sames[rela.same]: pp = player.pets[petID] this_flag = True if flag: if configs[pp.prototypeID].rarity != 5: this_flag = False if flag and this_flag: multi = 2 else: multi = 1 pp.activated_relations[rela.ID] = multi pp.save() pp.sync() pet.exp = 0 pet.save() pet.sync() # 扣除金钱 from task.manager import on_evolution on_evolution(player, pet) from task.manager import on_collect_pet1 on_collect_pet1(player, pet) # player.update_power() player.save() player.sync() msg = ResponseHeroEvolution(costHeroIDs=[i.entityID for i in pets]) return success_msg(msgtype, msg)
def fusion(self, msgtype, body): req = poem_pb.FusionRequest() req.ParseFromString(body) p = self.player from entity.manager import save_guide save_guide(p, req.guide_type) # 保存新手引导进度 configs = get_config(PetConfig) cls = None # 品级 maxLevel = 1 maxStep = 0 maxSkill1 = 1 maxSkill2 = 1 maxSkill3 = 1 maxSkill4 = 1 maxSkill5 = 1 error = fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) pets = [] bestEquips = {} equipsNeedDelete = [] if len(req.pets) != 6: return error star = 0 for t in req.pets: pet = p.pets.get(t) if not pet: return error if in_lineup(p, t): if not in_lineup(p, t, type=LineupType.ATK): return error pets.append(pet) config = configs.get(pet.prototypeID) if not config: return error if cls and config.cls != cls: # 校验全部品级相同 return error cls = config.cls # 上一个品级 if cls >= 6: return error for i in pet.equipeds.values(): equip = p.equips.get(i) if not equip: continue if equip.type in (EquipType.FaBao, EquipType.ZuoQi): equipsNeedDelete.append(equip) else: best = bestEquips.get(equip.type) if not best or equip.step > best.step: # 比之前的装备好 bestEquips[equip.type] = equip if best: equipsNeedDelete.append(best) else: equipsNeedDelete.append(equip) maxLevel = max(maxLevel, pet.level) # 继承最大等级 maxStep = max(maxStep, config.herostep) # 继承最大阶级 maxSkill1 = max(maxSkill1, pet.skill1) maxSkill2 = max(maxSkill2, pet.skill2) maxSkill3 = max(maxSkill3, pet.skill3) maxSkill4 = max(maxSkill4, pet.skill4) maxSkill5 = max(maxSkill5, pet.skill5) star += pet.star / float(config.need_patch) pool = get_config(FusionPoolConfig).get(cls + 1, []) if not pool: return error t = weighted_random2([[c.prototypeID, c.prob] for c in pool]) config = configs.get(t) if not config: return error same = config.same # 继承阶级 config = None for t in get_config(PetBySameConfig).get(same): pp = configs.get(t.prototypeID) if not pp: return error if pp.herostep == maxStep: config = pp break if not config: return error fusion_cost = get_config(FusionCostConfig).get(cls) if not fusion_cost: return error cost = parse_reward([{ "type": fusion_cost.type, "count": fusion_cost.cost }]) gain = {'petList': [[config.prototypeID, 1]]} extra = {} try: apply_reward(p, gain, cost, type=RewardType.Fusion, extra=extra) except AttrNotEnoughError: return error except MatNotEnoughError: return error pet = extra.get("pets")[0] # 继承等级 for _, equip in bestEquips.items(): from equip.manager import install_equip install_equip(p, pet.entityID, equip.entityID, force=True, sync=False) pet.level = maxLevel # 继承星级 star = int(star / float(6) * config.need_patch) pet.add_star = star - pet.base_star # 继承技能 pet.skill1 = maxSkill1 pet.skill2 = maxSkill2 pet.skill3 = maxSkill3 pet.skill4 = maxSkill4 pet.skill5 = maxSkill5 l = list(p.lineups.get(LineupType.ATK, [0, 0, 0, 0])) # 攻击阵型可以被炼化 flag = False for each in pets: if in_lineup(p, each.entityID, type=LineupType.ATK): flag = True l[l.index(each.entityID)] = 0 if flag: save_lineup(p, l, LineupType.ATK) p.del_pets(*pets) p.del_equips(*equipsNeedDelete) from task.manager import on_collect_pet2 on_collect_pet2(p, pet) from task.manager import on_pet_fusion_count on_pet_fusion_count(p, pet) pet.save() pet.sync() rsp = poem_pb.FustionResponse() rsp.pet_entity_id = pet.entityID # p.update_power() p.save() p.sync() return success_msg(msgtype, rsp)
def pet_break(self, msgtype, body): from config.configs import get_config from config.configs import PetConfig from lineup.manager import in_lineup p = self.player req = poem_pb.BreakRequest() req.ParseFromString(body) from entity.manager import save_guide save_guide(p, req.guide_type) # 保存新手引导进度 if len(req.pets) != len(set(req.pets)): return fail_msg(msgtype, reason="重复的精灵ID") if req.petID in req.pets: return fail_msg(msgtype, reason="重复的精灵ID") # 检查是否存在 pet = p.pets.get(req.petID) if not pet: return fail_msg(msgtype, reason="精灵不存在") pets = [] configs = get_config(PetConfig) config = configs[pet.prototypeID] for pt in req.pets: pt = p.pets.get(pt) if in_lineup(p, pt.entityID) and \ not in_lineup(p, pt.entityID, type=LineupType.ATK): return fail_msg(msgtype, reason='阵上将不可作为材料') if not pt: return fail_msg(msgtype, reason="精灵不存在") c = configs.get(pt.prototypeID) if c.same != config.same: return fail_msg(msgtype, reason="只能消耗同种类精灵") pets.append(pt) mats = defaultdict(int) mats_ = dict(zip(req.mats, req.mats_count)) for k, v in mats_.items(): mats[k] += v for k, v in mats.items(): if p.mats.get(k, 0) < v: return fail_msg(msgtype, reason="碎片数量不足") # 计算提供的星魄数 star = sum(mats.values()) for pt in pets: star += break_star(pt.prototypeID, pt.breaklevel) star_ = star rest_star = pet.add_star for i in range(1, pet.breaklevel): rest_star -= break_cost(pet.prototypeID, i + 1) logger.debug("rest_star %r", rest_star) star_ += rest_star breaklevel = pet.breaklevel incr = 0 money = 0 while star_: logger.debug("star_ %d", star_) logger.debug("breaklevel %d", breaklevel) try: need = break_cost(pet.prototypeID, breaklevel + 1) money_ = break_money(pet.prototypeID, breaklevel + 1) except KeyError: break logger.debug("need %d %d", need, money_) logger.debug("star_ - need >= 0 is %r" % (star_ - need >= 0)) if star_ - need >= 0: incr += 1 breaklevel += 1 star_ -= need money += money_ logger.debug("money %r", money) else: break logger.debug("incr %d" % incr) logger.debug("result star_ incr %d %d", star_, incr) matList = [[k, v] for k, v in mats.items()] cost = {'money': money, 'matList': matList} try: apply_reward(p, {}, cost, type=RewardType.Break) except AttrNotEnoughError: return fail_msg(msgtype, reason="金币不足") l = list(p.lineups.get(LineupType.ATK, [0, 0, 0, 0])) flag = False for each in pets: if in_lineup(p, each.entityID, type=LineupType.ATK): flag = True l[l.index(each.entityID)] = 0 if flag: save_lineup(p, l, LineupType.ATK) equips = [] for each in pets: for k, v in each.equipeds.items(): e = p.equips.get(v) if e: equips.append(e) p.del_pets(*pets) p.del_equips(*equips) pet.add_star += star pet.save() pet.sync() from task.manager import on_break_pet on_break_pet(p, pet) # p.update_power() p.save() p.sync() from chat.manager import on_news_pet_breaklevel_break on_news_pet_breaklevel_break(p, pet) return success_msg(msgtype, '')