def giftkey(self, msgtype, body): from protocol.poem_pb import Giftkey, GiftkeyResponse from config.configs import get_config, GiftkeyConfig from reward.manager import open_reward, build_reward_msg, RewardType from giftkey import use_key, InvalidGiftkeyError, ExceedUseCountError, ExceedDeallineError player = self.player req = Giftkey() req.ParseFromString(body) try: giftID = use_key(player, req.key) except InvalidGiftkeyError: return fail_msg(msgtype, reason='无效的兑换码') except ExceedUseCountError: return fail_msg(msgtype, reason='已经达到最大兑换次数了') except ExceedDeallineError: return fail_msg(msgtype, reason='已经超过有效期了') gift = get_config(GiftkeyConfig)[giftID] reward = open_reward(RewardType.Giftkey, gift) result = reward.apply(player) player.save() player.sync() rsp = GiftkeyResponse() build_reward_msg(rsp, result) gm_logger.info( {'giftkey': { 'entityID': player.entityID, 'giftkey': req.key }}) return success_msg(msgtype, rsp)
def city_treasure_recv(self, msgtype, body): if g_campaignManager.city_dungeon_campaign.is_open(): return fail_msg(msgtype, reason="活动开启中") if g_campaignManager.city_contend_campaign.is_open(): return fail_msg(msgtype, reason="活动开启中") p = self.player info = g_cityDungeon.get_top_info() top_factionID = info.get("top_factionID", 0) if not top_factionID: return fail_msg(msgtype, reason="还没有公会获得宝藏") if p.factionID != top_factionID: return fail_msg(msgtype, reason="您不属于这个公会") if p.city_treasure_recv_flag: return fail_msg(msgtype, reason="今天已经领取过了") f = Faction.simple_load(p.factionID, ["faction_treasure"]) if not f.faction_treasure: return fail_msg(msgtype, reason="还没有公会获得宝藏") current = None configs = get_config(CityTreasureRecvConfig) for config in configs.values(): if f.faction_treasure >= config.treasure_count: current = config else: break if not current: return fail_msg(msgtype, reason="没有奖励可以领取") result = apply_reward(p, parse_reward(current.rewards), type=RewardType.CityTreasure) rsp = poem_pb.CityTreasureRecv() build_reward_msg(rsp, result) p.city_treasure_recv_flag = True p.save() p.sync() return success_msg(msgtype, rsp)
def trigger_chest_recv(self, msgtype, body): p = self.player if not check_trigger_event_type(p, EventType.Chest): return fail_msg(msgtype, reason="无触发事件或错误的事件类型") req = poem_pb.TriggerChestRecvRequest() req.ParseFromString(body) config = get_config(TriggerEventConfig)[p.trigger_event] chest = get_config(TriggerChestConfig).get(config.event_param) if not chest: return fail_msg(msgtype, reason="不存在的宝箱") if req.is_double: cost = {"gold": get_cons_value("TriggerChestDoubleCost")} gain = {} for i in range(get_cons_value("TriggerChestMultiple")): gain = combine_reward([chest.reward], [], data=gain) else: cost = {} gain = parse_reward([chest.reward]) try: apply_reward(p, gain, cost=cost, type=RewardType.TriggerChest) except AttrNotEnoughError: return fail_msg(msgtype, reason="钻石不足") p.trigger_event = 0 p.save() p.sync() rsp = poem_pb.TriggerChestRecv() build_reward_msg(rsp, gain) return success_msg(msgtype, rsp)
def trigger_chests_recv(self, msgtype, body): p = self.player if not check_trigger_event_type(p, EventType.Chests): return fail_msg(msgtype, reason="无触发事件或错误的事件类型") config = get_config(TriggerEventConfig)[p.trigger_event] chest = get_config(TriggerChestsConfig).get(config.event_param) if len(p.trigger_chests) > 0: cost = {"gold": get_cons_value("TriggerChestsMoreCost")} else: cost = {} rests = set(range(len(chest.rewards))) - p.trigger_chests if not rests: return fail_msg(msgtype, reason="已经没有宝箱了") index = choice_one(list(rests)) is_best = False if index == 0: p.trigger_event = 0 is_best = True gain = parse_reward([chest.rewards[index]]) try: apply_reward(p, gain, cost=cost, type=RewardType.TriggerChests) except AttrNotEnoughError: return fail_msg(msgtype, reason="钻石不足") p.trigger_chests.add(index) p.save() p.sync() rsp = poem_pb.TriggerChestsRecv(is_best=is_best) build_reward_msg(rsp, gain) return success_msg(msgtype, rsp)
def maze_case_recv(self, msgtype, body): p = self.player req = poem_pb.MazeEventRequest() req.ParseFromString(body) index = req.index or 0 try: event = p.mazes[index] except IndexError: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) count = 1 cost = {} if req.treble: count = 3 cost = {"gold": p.maze_case_cost} if event.get("type") != MazeEventType.Case: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) drop = event.get("argv", 0) drops = [drop] * count if drop: reward = open_reward(RewardType.MazeDrop, *drops) if cost: reward.cost_after(p, **cost) result = reward.apply(p) p.mazes.remove(event) p.touch_mazes() p.save() p.sync() rsp = poem_pb.MazeCaseResponse() build_reward_msg(rsp, result) return success_msg(msgtype, rsp)
def dlc_dispatch_end(self, msgtype, body): p = self.player req = poem_pb.DlcDispatchEndRequest() req.ParseFromString(body) # 检查关卡开启 if not validate_prevs(p, req.fbID): return fail_msg(msgtype, reason="前置未通") if not validate_dlc_fb(p, req.fbID): return fail_msg(msgtype, reason="此关已通") dispatch = p.dlc_dispatch.get(req.fbID) if not dispatch: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) now = int(time.time()) if now < dispatch["time"]: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) reward = apply_dlc_reward(req.fbID, isfirst=is_first(p, req.fbID)) apply_reward(p, reward, type=RewardType.DlcDispatch) set_dlc_progress(p, req.fbID) set_fb_score(p, req.fbID, 1) # FIXME from task.manager import on_end_dlc_fb from task.manager import on_dlc_score from task.manager import on_end_spec_fb_count from task.manager import on_end_fb_count on_end_spec_fb_count(p, req.fbID) on_end_fb_count(p, req.fbID) on_end_dlc_fb(p, req.fbID) on_dlc_score(p) p.save() p.sync() rsp = poem_pb.DlcDispatchEnd() build_reward_msg(rsp, reward) return success_msg(msgtype, rsp)
def friend_gift(self, msgtype, body): p = self.player req = poem_pb.GiftFriend() req.ParseFromString(body) logger.debug(req) count = len(req.ids) if p.friend_gift_used_count + count > p.friend_gift_max_count: return fail_msg(msgtype, reason="次数不足,无法赠送能量") for i in req.ids: if i not in p.friendset: return fail_msg(msgtype, reason="该玩家还不是你的好友") if i in p.friendgiftedset: return fail_msg(msgtype, reason="已经给该玩家赠送过能量") sp = 1 money = 1000 rewards = {"sp": sp, "money": money} for i in req.ids: proxy.gift_friend(i, p.name, rewards) p.friend_gift_used_count += 1 p.friendgiftedset.add(i) self_rewards = {"sp": sp * count, "money": money * count} apply_reward(p, self_rewards, type=RewardType.GiftFriend) p.save() p.sync() rsp = poem_pb.GiftFriendResponse(ids=req.ids) build_reward_msg(rsp, self_rewards) return success_msg(msgtype, rsp)
def friend_friendfb_end(self, msgtype, body): p = self.player req = poem_pb.EndFriendfb() req.ParseFromString(body) if not PlayerFightLock.unlock(p.entityID, req.verify_code): return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) assert p.cache_friendfbID, "impossible" rsp = poem_pb.EndFriendfbResponse() try: createtime, hp, fbID = simple_load_friendfb( p.cache_friendfbID, 'createtime', 'hp', 'fbID') except DoesNotExistsException: error_code = msgTips.FAIL_MSG_FRIENDFB_ALREADY_DISAPPEARED else: if hp <= 0: error_code = msgTips.FAIL_MSG_FRIENDFB_ALREADY_DEAD # return fail_msg(msgtype, reason='BOSS已经被击杀了') else: from pvp.manager import send_fight_verify from fightverifier.direct_verifier import verify send_fight_verify(p, req.fight) if not verify(p, req.fight): return fail_msg(msgtype, msgTips.FAIL_MSG_FIGHT_VERIFY_FAILED) error_code = 0 now = int(time.time()) if if_boss(p.cache_friendfbID) and\ not if_boss_campaign_opened(p.cache_friendfbID) or \ not if_boss(p.cache_friendfbID) and \ now > createtime + FRIENDFB_INTERVAL: error_code = msgTips.FAIL_MSG_FRIENDFB_ALREADY_DISAPPEARED # NOQA else: info = get_config(FriendfbConfig)[fbID] if info.drop: r = open_reward(RewardType.Friendfb, info.drop) result = r.apply(p) build_reward_msg(rsp, result) damage = max(req.fight.total_damage or 0, 0) hp = hurt_boss(p, fbID, p.cache_friendfbID, damage) if hp <= 0: if if_boss(p.cache_friendfbID): # 提前发奖 bc = get_boss_campaign(p.cache_friendfbID) proxy.notify_boss_campaign_end(bc.config.ID) entityID = bc.get_by_rank(1) proxy.sync_on_task_change(entityID, TaskCond.FriendfbFirst, p.cache_friendfbID) else: give_reward(p.cache_friendfbID) on_friendfb_count(p, fbID) else: p.friendfb_deads.add(p.cache_friendfbID) p.friendfb_deadtimes[fbID] = now p.friendfb_buff = 0 p.save() p.sync() rsp.error_code = error_code return success_msg(msgtype, rsp)
def trigger_chests_info(self, msgtype, body): p = self.player if not check_trigger_event_type(p, EventType.Chests): return fail_msg(msgtype, reason="无触发事件或错误的事件类型") config = get_config(TriggerEventConfig)[p.trigger_event] chest = get_config(TriggerChestsConfig).get(config.event_param) reward = chest.rewards[0] # 默认第一个是最好的 rsp = poem_pb.TriggerChestsInfo( more_cost=get_cons_value("TriggerChestsMoreCost")) build_reward_msg(rsp, parse_reward([reward])) return success_msg(msgtype, rsp)
def mail_list(self, msgtype, body): req = poem_pb.MailListRequest() req.ParseFromString(body) player = self.player mails = sorted(player.mails.values(), key=lambda s: s.addtime) rsp = poem_pb.MailList() now = int(time.time()) # 删除过期邮件 pending = [] for mail in mails: if mail.cd and now > mail.addtime + mail.cd: if mail.isread and mail.isreceived: pending.append(mail) else: data = {} config = get_config(MailConfig).get(mail.configID) if config: data.update(**config._asdict()) data.update( mailID=mail.mailID, title=mail.title, type=mail.type, content=mail.content, cd=mail.cd - (now - mail.addtime), isread=mail.isread, isreceived=mail.isreceived, addtime=mail.addtime, ) each = rsp.mails.add(**data) tmp_transform = { 500026: 800026, 500027: 800027, 500028: 800028, 500029: 800029, 500030: 800030, 500031: 800031, 500032: 800032, 500021: 800021, 14000371: 21000371, 14000372: 21000372, 14000373: 21000373, 14000374: 21000374, 14000375: 21000375, } for item in mail.addition.get('matList', []): item[0] = tmp_transform.get(item[0], item[0]) build_reward_msg(each, mail.addition) if pending: player.del_mails(*pending) logger.debug("newmailcount %r", player.newmailcount) player.save() player.sync() return success_msg(msgtype, rsp)
def spar_request(self, msgtype, body): p = self.player req = poem_pb.SparRequest() req.ParseFromString(body) config = get_config(SparConfig).get(req.ID) if not config: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) logger.debug(req) spar_count = p.spar_counts.get(req.ID, 0) count = config.onekeycount if req.onekey else 1 # cost = config.onekeycost if req.onekey else 1 if not count: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) drops = [] for i in range(count): if spar_count >= config.dropex_use_count: drops.append(config.dropex) spar_count = 0 else: drops.append(config.drop) spar_count += 1 if not drops: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) try: reward = open_reward(RewardType.Spar, *drops) reward.cost_after( p, matList=[[config.itemID, count]], money=config.money*count) result = reward.apply(p) except AttrNotEnoughError: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) except MatNotEnoughError: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) rsp = poem_pb.SparResponse() build_reward_msg(rsp, result) on_pet_spar(p, rsp.rewards) on_equip_spar(p, rsp.rewards) p.spar_counts[req.ID] = spar_count from task.manager import on_spar_count on_spar_count(p, spar_count) p.save() p.sync() logger.debug(rsp) count = config.dropex_use_count - p.spar_counts.get(req.ID, 0) info = config._asdict() if count == 0: info['tips'] = config.final_tips else: info['tips'] = config.tips.format(count + 1) rsp.item = poem_pb.SparItem(**info) return success_msg(msgtype, rsp)
def maze_pool_recv(self, msgtype, body): p = self.player if not p.money_rest_pool: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) result = apply_reward( p, {"money": p.money_rest_pool}, type=RewardType.MazePool) p.money_rest_pool = 0 p.save() p.sync() rsp = poem_pb.MazePoolResponse() build_reward_msg(rsp, result) return success_msg(msgtype, rsp)
def treasure_end(self, msgtype, body): p = self.player req = poem_pb.EndTreasure() req.ParseFromString(body) if not PlayerTreasureLock.unlock(p.entityID, req.verify_code): logger.debug("verify_code %s", req.verify_code) return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) if not p.treasure_cache: logger.debug("not treasure_cache") return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) rewards = [] for type, subtype, count in p.treasure_cache: if type == TreasureGrid.TreasureGridTypeReward: rewards.append(poem_pb.RewardData( type=subtype, count=count)) r1 = parse_reward(req.rewards) r2 = parse_reward(rewards) logger.debug("reward %r %r", r1, r2) if not compare_reward(r1, r2): logger.debug("compare reward fail") return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) config = get_config(TreasureChestConfig)[p.treasure_type] gain_chest = bool(req.gain_chest) if gain_chest: reward = open_reward(RewardType.Treasure, config.drop) result = reward.apply_after() else: result = {} result = combine_reward(r1, result) rsp = poem_pb.EndTreasureResponse() finisheds = [] finisheds.append(gain_chest) finisheds.append(bool(req.kill_monster)) need = get_cons_value("TreasureNeedBuffCount") finisheds.append(len(req.rewards) >= need) rsp.stars = len(filter(lambda s: s, finisheds)) if rsp.stars == len(finisheds): rewardex = open_reward(RewardType.Treasure, config.dropex) rsp.rewardsex = build_reward(rewardex.apply(p)) rsp.finisheds = finisheds apply_reward(p, result, type=RewardType.Treasure) build_reward_msg(rsp, result) now = int(time.time()) p.treasure_used_count += 1 p.treasure_cd = now + 10 * 60 p.treasure_cache = [] refresh_treasure(p) on_treasure_count(p) p.save() p.sync() return success_msg(msgtype, rsp)
def tap_onekey(self, msgtype, body): p = self.player if not p.tap_onekey: return fail_msg(msgtype, msgTips.FAIL_MSG_CANT_TAP_ONEKEY) rsp = poem_pb.OnekeyTapResponse() reward, count = onekey_tap(p) m = get_config(TapMonsterConfig)[p.tap_monster] rsp.next = poem_pb.StartTapResponse(**m._asdict()) rsp.next.hurts = p.tap_hurts rsp.next.index = p.tap_hurts_index build_reward_msg(rsp, reward) on_tap_count(p, count) p.save() p.sync() return success_msg(msgtype, rsp)
def tap_end(self, msgtype, body): p = self.player req = poem_pb.EndTap() req.ParseFromString(body) logger.debug("tap end") logger.debug(req) reward = end_tap(p, req.count) if not reward: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) rsp = poem_pb.EndTapResponse() build_reward_msg(rsp, reward) logger.debug(rsp) on_tap_count(p, req.count) p.save() p.sync() return success_msg(msgtype, rsp)
def use_mat(self, msgtype, body): p = self.player req = poem_pb.UseMatRequest() req.ParseFromString(body) config = get_config(MatConfig).get(req.matID) if not config: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) rsp = poem_pb.UseMatResponse() if config.type == MatType.Drop: drop = config.arg attr = "" elif config.type in USEINGS: drop = 0 attr = USEINGS.get(config.type) elif config.type == MatType.RipeningAgent: if p.seed_state == poem_pb.SeedStateNormal or\ p.seed_state == poem_pb.SeedStateRipening or\ p.seed_state == poem_pb.SeedStateRoot: return fail_msg(msgtype, reason="无法使用!") p.seed_state = poem_pb.SeedStateRipening p.seed_state_last_change_time = 0 p.seed_state_next_change_time = 0 p.seed_state_ripening_time = 0 drop = 0 attr = '' else: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) reward = open_reward(RewardType.UseMat, drop) reward.cost_after(p, matList=[[req.matID, 1]]) result = reward.apply(p) if attr: value = getattr(p, attr, 0) + config.arg setattr(p, attr, value) rsp.tips = config.tips build_reward_msg(rsp, result) 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 flowerboss_friendfb_end(self, msgtype, body): p = self.player req = poem_pb.EndFriendfb() req.ParseFromString(body) if not PlayerFightLock.unlock(p.entityID, req.verify_code): return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) assert p.cache_friendfbID, "impossible" from campaign.manager import g_campaignManager flower_boss_friendfbID = "bosscampaign:%d" % g_campaignManager.flower_boss_campaign.flower_boss_config_id if p.cache_friendfbID != flower_boss_friendfbID: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) rsp = poem_pb.EndFriendfbResponse() try: createtime, hp, fbID = simple_load_friendfb( p.cache_friendfbID, 'createtime', 'hp', 'fbID') except DoesNotExistsException: error_code = msgTips.FAIL_MSG_FRIENDFB_ALREADY_DISAPPEARED else: if hp <= 0: error_code = msgTips.FAIL_MSG_FRIENDFB_ALREADY_DEAD # return fail_msg(msgtype, reason='BOSS已经被击杀了') else: from pvp.manager import send_fight_verify from fightverifier.direct_verifier import verify send_fight_verify(p, req.fight) if not verify(p, req.fight): return fail_msg(msgtype, msgTips.FAIL_MSG_FIGHT_VERIFY_FAILED) error_code = 0 now = int(time.time()) if if_boss(p.cache_friendfbID) and\ not if_boss_campaign_opened(p.cache_friendfbID) or \ not if_boss(p.cache_friendfbID) and \ now > createtime + FRIENDFB_INTERVAL: error_code = msgTips.FAIL_MSG_FRIENDFB_ALREADY_DISAPPEARED # NOQA else: damage = max(req.fight.total_damage or 0, 0) info = get_config(FriendfbConfig)[fbID] if info.drop: from config.configs import HandselMulRewardConfig mr_configs = get_config(HandselMulRewardConfig) mr_id = g_campaignManager.flower_boss_campaign.get_mulreward_id( ) mr_config = mr_configs[mr_id] mr = mr_config.mulreward import math r = open_reward(RewardType.Flower315Campaign, info.drop, int(math.ceil(mr * damage))) result = r.apply(p) build_reward_msg(rsp, result) start_time, end_time = g_campaignManager.flower_boss_campaign.get_current_time( ) if p.flower_boss_campaign_last_time < start_time or p.flower_boss_campaign_last_time > end_time: p.flower_boss_campaign_total_hurt = 0 p.flower_boss_campaign_total_hurt += damage p.flower_boss_campaign_last_time = now hp = hurt_boss(p, fbID, p.cache_friendfbID, damage) if hp <= 0: if if_boss(p.cache_friendfbID): # 提前发奖 bc = get_boss_campaign(p.cache_friendfbID) proxy.notify_boss_campaign_end(bc.config.ID) entityID = bc.get_by_rank(1) proxy.sync_on_task_change(entityID, TaskCond.FriendfbFirst, p.cache_friendfbID) else: give_reward(p.cache_friendfbID) on_friendfb_count(p, fbID) else: p.friendfb_deads.add(p.cache_friendfbID) p.friendfb_deadtimes[fbID] = now p.friendfb_buff = 0 p.save() p.sync() rsp.error_code = error_code return success_msg(msgtype, rsp)
def battle(self, p, fight, rsp): mg = p.city_dungeon_mg_cache message_configs = get_config(CityDungeonMessageConfig) self_message = "" message_config = message_configs.get(mg["id"]) if not message_config: message_config = message_configs[max(message_configs)] if fight.fightResult: kills = len(mg.get("monsters", [])) config = self.get_mg_config_by_id(mg["id"]) rewards = parse_reward(config.rewards) self_message = message_config.single_win_desc.format(mg["id"]) # 玩家损血 # {{ 使用每日PVP for each in fight.player_team: pet = p.pets[each.entityID] if each.restHP == 0: pet.daily_dead = True else: pet.daily_restHP = each.restHP pet.save() pet.sync() # }} else: kills = 0 pending = [] for enemy in fight.enemy_team: for m in mg["monsters"]: if m["pos"] == enemy.posIndex: if not enemy.restHP: pending.append(m) kills += 1 else: m["restHP"] = enemy.restHP for m in pending: mg["monsters"].remove(m) self.add_mg_into_pool(p, mg) now = int(time.time()) # {{ 使用每日PVP p.daily_dead_cd = now + get_cons_value("DailyDeadCD") # }} rewards = {} self_message = message_config.single_lose_desc.format(mg["id"]) if fight.total_damage: CityDungeonSelfRanking.incr_score( p.entityID, fight.total_damage) if kills: self.incr_mg_kill(p, mg["id"], kills) if fight.fightResult: self.sync_city_dungeon_current_info(p) if rewards: rewards = combine_reward( rewards, config.must_rewards) rewards = apply_reward( p, rewards, type=RewardType.CityDungeon) build_reward_msg(rsp, rewards) combine_reward(rewards, {}, p.city_dungeon_rewards) if self_message: g_redManager.send_red_message( p, self_message, to_self=True, module=RedModuleType.CityDungeon) p.city_dungeon_mg_cache.clear() p.save() p.sync()
def get_end_panel(self, p, rsp): build_reward_msg(rsp, p.city_contend_rewards)