def visit_visit(self, msgtype, body): p = self.player req = poem_pb.VisitRequest() req.ParseFromString(body) cost = {} count = 1 if req.onekey: count = 10 gain, cost, ids, luck = visit(p, count) try: apply_reward(p, gain, cost=cost, type=RewardType.Visit) except AttrNotEnoughError: incr_visit_flag(count=-count) return fail_msg(msgtype, reason="钻石不足") if p.visit_free_rest_count < count: p.visit_free_used_count += p.visit_free_rest_count count -= p.visit_free_rest_count else: p.visit_free_used_count += count count = 0 p.visit_today_used_count += count rsp = poem_pb.VisitResponse(ids=ids) if luck: rsp.rewards = build_reward(luck) campaign = g_campaignManager.visit_campaign if campaign.is_open(): config = campaign.get_current() p.visit_group = config.reward_group p.visit_time = int(time.time()) p.save() p.sync() from chat.manager import on_visit on_visit(p, rsp.rewards) return success_msg(msgtype, rsp)
def get_panel(self, p, rsp): if self.is_top_faction(p.factionID): # 防守方 rsp.self_rank = CityContendDefendRanking.get_rank(p.entityID) if not rsp.self_rank: CityContendDefendRanking.update_score(p.entityID, 0) rsp.self_ranking = self.get_player_ranking( CityContendDefendRanking) if not p.city_contend_treasure: configs = get_config(CityTreasureConfig) config = configs.get(p.level) if not config: config = configs[max(configs)] p.city_contend_treasure = config.defend_treasure p.save() p.sync() else: # 攻击方 rsp.self_rank = CityContendAttackRanking.get_rank(p.entityID) if not rsp.self_rank: CityContendAttackRanking.update_score(p.entityID, 0) rsp.faction_rank = CityContendFactionRanking.get_rank(p.factionID) if not rsp.faction_rank: CityContendFactionRanking.update_score(p.factionID, 0) rsp.self_ranking = self.get_player_ranking( CityContendAttackRanking) rsp.faction_ranking = self.get_faction_ranking( CityContendFactionRanking) rsp.reds = list(g_redManager.get_red_messages( module=RedModuleType.CityContendDefend)) + list( g_redManager.get_red_messages( module=RedModuleType.CityContendAttack)) rsp.events = self.get_events(p) rsp.rewards = build_reward(parse_reward(p.city_contend_rewards)) f = Faction.simple_load(p.factionID, ["faction_treasure"]) rsp.faction_treasure = f.faction_treasure
def vip_packs_info(self, msgtype, body): req = poem_pb.VipPacksInfoRequest() req.ParseFromString(body) rsp = poem_pb.VipPacksInfo() p = self.player now = int(time.time()) today = datedate.fromtimestamp(now) configs = get_config(VipPacksConfig) if req.type == VipPackType.Daily: try: config = get_config(VipConfig)[req.vip or p.vip] except KeyError: config = get_config(VipConfig)[p.vip] group = [config.day_giftID] else: group = [i.ID for i in get_config( VipPacksByGroupConfig).get(req.type, [])] for each in group: config = configs[each] if config.gift_type != VipPackType.Daily: if now < config.gift_starttime or now > config.gift_lasttime: continue info = dict(config._asdict()) info["rewards"] = build_reward(parse_reward(info["rewards"])) # 同组共用一个限购数据 count = get_vip_pack_rest_count(p, each, today=today) info["count"] = count rsp.packs.add(**info) return success_msg(msgtype, rsp)
def trigger_store_info(self, msgtype, body): p = self.player if not check_trigger_event_type(p, EventType.Store): return fail_msg(msgtype, reason="无触发事件或错误的事件类型") config = get_config(TriggerEventConfig)[p.trigger_event] goods = get_config(TriggerStoreConfig).get(config.event_param) if not goods: return fail_msg(msgtype, reason="没有这个商品") info = goods._asdict() info["rewards"] = build_reward(parse_reward([goods.reward])) rsp = poem_pb.TriggerStoreInfo(**info) return success_msg(msgtype, rsp)
def maze_step(self, msgtype, body): p = self.player req = poem_pb.MazeStepRequest() req.ParseFromString(body) count = p.maze_rest_count if req.onekey else 1 # check count if count > p.maze_rest_count: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) gains = {} attr = {} mazes = [] incr = {} results = step_mazes(p, attr, incr, count) count = len(results) rsp = poem_pb.MazeStepResponse() for each in results: drop = each.get("drop", 0) if drop: maze_drop = open_reward(RewardType.MazeDrop, drop) rewards = maze_drop.apply_after() gains = combine_reward(rewards, {}, data=gains) if each.get("append", False): mazes.append(each) drop = get_cons_value("MazeMustDropID") must_drop = open_reward(RewardType.MazeDrop, drop) rewards = must_drop.apply_after() gains = combine_reward(rewards, {}, data=gains) rsp.events.add(**each) rsp.rewards = build_reward(gains) for each in mazes: p.mazes.append(each) apply_reward(p, gains, type=RewardType.MazeDrop) for each, value in attr.items(): setattr(p, each, value) for each, value in incr.items(): setattr(p, each, getattr(p, each) + value) if "mall_silver_open_remain" in attr: try: del p.malls[MallType.Silver] except KeyError: pass if "mall_golden_open_remain" in attr: try: del p.malls[MallType.Golden] except KeyError: pass p.touch_mazes() p.maze_step_count += count on_maze_count(p, count) p.save() p.sync() return success_msg(msgtype, rsp)
def visit_reward(self, msgtype, body): campaign = g_campaignManager.visit_campaign if campaign.is_open(): group = campaign.get_current().reward_group else: group = 1 configs = get_config(VisitRewardByGroupConfig).get(group) rsp = poem_pb.VisitRewardResponse() for config in sorted(configs, key=lambda s: s.pious, reverse=True): info = config._asdict() info["rewards"] = build_reward(parse_reward(config.rewards)) rsp.items.add(**info) 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 city_dungeon_end_panel(self, msgtype, body): p = self.player info = g_cityDungeon.get_top_info() or {} rsp = poem_pb.CityDungeonEndPanel(**info) rsp.self_rewards = build_reward(p.city_dungeon_rewards) rank = CityDungeonSelfBackupRanking.get_rank(p.entityID) rsp.faction_rank = CityDungeonKillBackupRanking.get_rank(p.factionID) configs = get_config(CityDungeonRewardConfig) config = None for c in configs.values(): start, end = c.range if start: if start > rank: continue if end: if end < rank: continue config = c if config: rsp.faction_rewards = build_reward(parse_reward(config.rewards)) p.city_dungeon_rewards.clear() p.save() p.sync() return success_msg(msgtype, rsp)
def get_campaign_info(p, dlcID): from task.manager import get_task_info from task.manager import get_plan campaign = g_dlcCampaignManager.campaigns.get(dlcID) if not campaign or not campaign.is_open(): return rsp = poem_pb.DlcCampaignInfo() today = datedate.today() dlc_tasks = p.dlc_tasks.get(dlcID, []) task = None count = 0 total = len(dlc_tasks) configs = get_config(DlcTaskConfig) infos = get_config(TaskConfig) cost = 0 for i in sorted(dlc_tasks): dlc_task = configs[i] info = infos[i] is_done = get_plan(p, i, today) >= info.goal if dlc_task.rewards: rsp.nodes.add( rewards=build_reward( parse_reward(dlc_task.rewards)), can_receive=(i in p.taskrewards), is_done=is_done, index=dlc_task.index) if is_done: count += 1 if task is None: if i in p.taskrewards: task = get_task_info(p, i, today) cost = dlc_task.gold elif task is None: task = get_task_info(p, i, today) cost = dlc_task.gold if task: now = int(time.time()) rsp.campaign_cd = max(campaign.get_end_time() - now, 0) rsp.task = task rsp.count = count rsp.total = total rsp.cost = cost cd = p.dlc_tasks_cd.get(dlcID, 0) if cd: rsp.cd = max(cd - now, 0) return rsp return None
def dlc_star_packs_info(self, msgtype, body): p = self.player req = poem_pb.DlcStarPacksInfoRequest() req.ParseFromString(body) group = get_config(DlcStarPacksByDlcConfig).get(req.dlcID, []) configs = get_config(DlcStarPacksConfig) rsp = poem_pb.DlcStarPacksInfo() for each in group: config = configs[each.ID] if each.ID in p.dlc_star_packs_end: continue rsp.packs.add( id=config.ID, star=config.score, rewards=build_reward( parse_reward(config.rewards))) # rsp.rank = get_current_rank("DLC%d" % req.dlcID, p.entityID) return success_msg(msgtype, rsp)
def get_panel(self, p, rsp): lives = self.get_lives(count=10) rsp.lives = lives rankers = self.get_rankers(count=10) rsp.ranks = rankers rsp.rewards = build_reward(p.daily_rewards) rsp.reds = g_redManager.get_red_messages() # 检查战斗期间内是否被已死亡 rsp.registers = PlayerDailyRankRanking.count() p.clear_daily_dead() if p.daily_dead and p.daily_count: now = int(time.time()) p.daily_dead_cd = now + get_cons_value("DailyDeadCD") self.pool.execute("DEL", "daily_dead_p{%d}" % p.entityID) p.clear_daily_dead() p.save() p.sync() return rsp
def cleanfbs(p, fbID, count, cost): assert count > 0 items = [] rewards = {} useless = poem_pb.EnterFbResponse() # cost_ = dict(cost) # cost.clear() for i in range(count): item = poem_pb.CleanFbRspStruct() set_fb_score(p, fbID, 3) item.curFbInfo = poem_pb.FbInfo(**get_fb_info(p, fbID)) reward = open_reward(RewardType.FB, p, fbID, False, useless) result = filter_cleanfb_reward(reward) item.rewards = build_reward(result) rewards = combine_reward(rewards, result) # combine_reward(cost_, [], cost) items.append(item) apply_reward(p, rewards, cost=cost, type=RewardType.CleanFB) p.save() p.sync() return items
def city_contend_drop_event(self, msgtype, body): p = self.player if not p.factionID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION) if not g_campaignManager.city_contend_campaign.is_open(): return fail_msg(msgtype, msgTips.FAIL_MSG_CITY_CAMPAIGN_CLOSED) if not g_cityContend.check_event(p, CityContendEventType.Drop): return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) event = g_cityContend.get_current_step(p) if g_cityContend.is_top_faction(p.factionID): result = open_reward(RewardType.CityContend, event["argv"]) else: result = open_reward(RewardType.CityContend, event["argv"]) rewards = result.apply(p) rsp = poem_pb.CityContendDropEventResponse() combine_reward(rewards, {}, p.city_contend_rewards) rsp.rewards = build_reward(p.city_contend_rewards) p.city_contend_step += 1 p.city_contend_total_step += 1 p.save() p.sync() return success_msg(msgtype, rsp)
def reset(self, p=None): from campaign.manager import g_campaignManager if p: ps = [p] else: ps = g_entityManager.players.values() # now = int(time.time()) for p in ps: start = g_campaignManager.dailypvp_campaign.get_start_time() final = g_campaignManager.dailypvp_campaign.get_final_time() if p.daily_reset_time < start or p.daily_reset_time > final: p.daily_end_panel = { "daily_rank": p.daily_rank, "daily_kill_count": p.daily_kill_count, "daily_max_win_count": p.daily_max_win_count, "rewards": build_reward(p.daily_rewards, cls=dict), } p.daily_cache_targetID = 0 self.pool.execute("del", "daily_win_count_p{%d}" % p.entityID) p.clear_daily_win_count() # {{ 鼓舞及复活 p.daily_dead_cd = 0 self.pool.execute("del", "daily_dead_p{%d}" % p.entityID) p.clear_daily_dead() p.daily_inspire_used_count = 0 # }} p.daily_histories.clear() p.daily_rewards.clear() p.daily_history_flag = False p.daily_max_win_count = 0 p.daily_kill_count = 0 p.daily_count = 0 p.daily_rank = 0 p.daily_registered = False p.daily_reset_time = start p.save() p.sync()
def battle(self, p, targetID, fight, raw, rsp): target_win_count = 0 # 对手连胜次数 max_win_count = 0 history = None # 战斗记录 shutdown = False self_message = "" full_message = "" horn = False red_message = "" red_count = 0 self_shutdown_message = "" full_shutdown_message = "" peer_shutdown_message = "" count = 0 rsp.before_daily_win_count = p.daily_win_count if fight.fightResult: # 胜利 # 终结对手连胜 target_win_count = int(self.pool.execute( "GETSET", "daily_win_count_p{%d}" % targetID, 0) or 0) self.pool.execute("SET", "daily_dead_p{%d}" % targetID, 1) # 添加自己连胜 daily_win_count = int(self.pool.execute( "INCRBY", "daily_win_count_p{%d}" % p.entityID, 1) or 0) p.clear_daily_win_count() # 更新最大连胜次数 if p.daily_win_count > p.daily_max_win_count: p.daily_max_win_count = p.daily_win_count count = update_daily_rank( PlayerDailyRankRanking, p.entityID, p.daily_max_win_count) # PlayerDailyRankRanking.update_score( # p.entityID, p.daily_max_win_count) # 连胜任务 from task.manager import on_dailypvp_count on_dailypvp_count(p, p.daily_max_win_count) # 取全服最大次数 top = PlayerDailyRankRanking.get_range_by_score( "-inf", "+inf", withscores=True, count=1) if top: max_win_count = top[1] rsp.max_win_count = max_win_count daily_win_config = get_config(DailyWinConfig).get( p.daily_win_count) if not daily_win_config and \ p.daily_win_count > max(get_config(DailyWinConfig)): daily_win_config = get_config( DailyWinConfig)[max(get_config(DailyWinConfig))] if daily_win_config: if not daily_win_config.multiple or ( daily_win_config.multiple and count == 1): self_message = daily_win_config.single_desc full_message = daily_win_config.all_desc horn = daily_win_config.horn if daily_win_config.red_paper: red_message = daily_win_config.red_paper_desc red_count = daily_win_config.red_paper_count red_drop = daily_win_config.red_paper daily_lose_config = get_config(DailyLoseConfig).get( target_win_count) if not daily_lose_config and \ target_win_count > max(get_config(DailyLoseConfig)): daily_lose_config = get_config( DailyLoseConfig)[max(get_config(DailyLoseConfig))] if daily_lose_config: self_shutdown_message = daily_lose_config.single_win_desc peer_shutdown_message = daily_lose_config.single_lose_desc full_shutdown_message = daily_lose_config.all_desc # 增加胜利次数 p.daily_kill_count += 1 # 奖励加成系数 multi = min(40, 2 * daily_win_count) + min( 80, target_win_count * 4) shutdown = target_win_count > 2 history = { "active": False, "name": p.name, "win": not fight.fightResult, "faction_name": p.faction_name, "daily_win_count": p.daily_win_count, "fight": raw.encode("base64"), "prototypeID": p.prototypeID, "borderID": p.borderID, "shutdown": shutdown} 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: if not p.daily_rank: PlayerDailyRankRanking.update_score( p.entityID, p.daily_max_win_count) # 自己连胜被终结 daily_win_count = int(self.pool.execute( "GETSET", "daily_win_count_p{%d}" % p.entityID, 0) or 0) # 死亡 self.pool.execute("SET", "daily_dead_p{%d}" % p.entityID, 1) p.clear_daily_win_count() # 奖励加成系数 multi = 0 daily_lose_config = get_config(DailyLoseConfig).get( daily_win_count) if not daily_lose_config and \ daily_win_count > max(get_config(DailyLoseConfig)): daily_lose_config = get_config( DailyLoseConfig)[max(get_config(DailyLoseConfig))] if daily_lose_config: self_shutdown_message = daily_lose_config.single_lose_desc peer_shutdown_message = daily_lose_config.single_win_desc full_shutdown_message = daily_lose_config.all_desc # 取对手数据 data = g_entityManager.get_players_info( [targetID], [ "entityID", "name", "daily_win_count", "faction_name", "prototypeID", "borderID"])[0] # 终结连胜 shutdown = target_win_count > 2 data.update({ "active": True, "shutdown": shutdown, "win": fight.fightResult, "fight": raw.encode("base64") }) # 自己的战斗记录 p.daily_histories.appendleft(data) p.daily_histories.ltrim(0, MAX_HIST_LEN - 1) # 更新排名 p.daily_rank = PlayerDailyRankRanking.get_rank(p.entityID) rewards = {} reward = open_reward( RewardType.DailyPVP, get_cons_value("DailyPVPDrop")) rewards = reward.apply_after() # 奖励加成 if multi: for k, v in rewards.items(): if isinstance(v, int) and k != 'exp': rewards[k] = int(v * (100 + multi) / float(100)) # 记录累计奖励 apply_reward(p, rewards, type=RewardType.DailyPVP) combine_reward(rewards, [], data=p.daily_rewards) p.daily_rewards = dict(p.daily_rewards) p.daily_count += 1 p.daily_cache_targetID = 0 p.save() p.sync() # 添加直播 self.add_live({ "self_name": p.name, "self_prototypeID": p.prototypeID, "self_borderID": p.borderID, "peer_name": data["name"], "peer_prototypeID": data["prototypeID"], "peer_borderID": data["borderID"], "is_win": fight.fightResult, }, top=p.daily_rank and p.daily_rank <= 5) rsp.daily_win_count = p.daily_win_count rsp.rewards = build_reward(rewards) if self_message: self_message = self_message.format(data["name"], p.daily_win_count) g_redManager.send_red_message( p, self_message, to_self=True, type=RedType.Normal) if full_message: full_message = full_message.format( p.name, data["name"], p.daily_win_count) _type = RedType.Horn if horn else RedType.Normal g_redManager.send_red_message( p, full_message, type=_type) if red_count and red_message: if daily_win_count == 1: red_message = red_message.format( p.name, red_count) else: red_message = red_message.format( p.name, daily_win_count, red_count) g_redManager.send_red_message( p, red_message, red_drop=red_drop, red_count=red_count, type=RedType.Red) if full_shutdown_message: if fight.fightResult: full_shutdown_message = full_shutdown_message.format( p.name, data["name"], target_win_count) else: full_shutdown_message = full_shutdown_message.format( data["name"], p.name, daily_win_count) _type = RedType.Horn if horn else RedType.Normal g_redManager.send_red_message( p, full_shutdown_message, type=_type) if fight.fightResult: if self_shutdown_message: self_shutdown_message = self_shutdown_message.format( data["name"], target_win_count) g_redManager.send_red_message( p.entityID, self_shutdown_message, to_self=True, type=RedType.Normal) if peer_shutdown_message: peer_shutdown_message = peer_shutdown_message.format( p.name, target_win_count) g_redManager.send_red_message( data["entityID"], peer_shutdown_message, to_self=True, type=RedType.Normal) else: if self_shutdown_message: self_shutdown_message = self_shutdown_message.format( data["name"], daily_win_count) g_redManager.send_red_message( p.entityID, self_shutdown_message, to_self=True, type=RedType.Normal) if peer_shutdown_message: peer_shutdown_message = peer_shutdown_message.format( p.name, daily_win_count) g_redManager.send_red_message( data["entityID"], peer_shutdown_message, to_self=True, type=RedType.Normal) proxy.sync_daily_rank(targetID, history) return rewards
def battle(self, p, fight, rsp): treasures = get_config(CityTreasureConfig) self_message = "" full_message = "" red_message = "" red_count = 0 horn = False target = p.city_contend_cache_target if self.is_top_faction(p.factionID): message_configs = get_config(CityContendDefendMessageConfig) message_config = message_configs.get(p.city_contend_count) if not message_config: message_config = message_configs[max(message_configs)] if fight.fightResult: event = self.get_current_step(p) drop = event["argv"] reward = open_reward(RewardType.CityContendDefend, drop) rewards = reward.apply(p) combine_reward(rewards, {}, p.city_contend_rewards) try: target_name = target.get("name", u"").decode("utf-8") target_faction_name = (target.get( "faction_name", u"") or u"").decode("utf-8") except UnicodeEncodeError: target_name = target.get("name", u"") target_faction_name = target.get("faction_name", u"") self_message = message_config.single_defend_win_desc.format( target_faction_name, target_name ) # {{ 使用每日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() # }} rsp.rewards = build_reward(rewards) else: sub = p.city_contend_treasure * get_cons_value( "CityContendFailPunish") / float(100) p.city_contend_treasure = max( p.city_contend_treasure - sub, 1) # {{ 每日PVP now = int(time.time()) p.daily_dead_cd = now + get_cons_value("DailyDeadCD") # }} try: target_name = target.get("name", u"").decode("utf-8") target_faction_name = (target.get( "faction_name", u"") or u"").decode("utf-8") except UnicodeEncodeError: target_name = target.get("name", u"") target_faction_name = target.get("faction_name", u"") self_message = message_config.single_defend_lose_desc.format( target_faction_name, target_name ) module = RedModuleType.CityContendDefend else: message_configs = get_config(CityContendAttackMessageConfig) message_config = message_configs.get(p.city_contend_count + 1) if not message_config: message_config = message_configs[max(message_configs)] if fight.fightResult: p.city_contend_count += 1 self_count = CityContendAttackRanking.update_score( p.entityID, p.city_contend_count) count = CityContendAttackRanking.pool.execute( "ZCOUNT", CityContendAttackRanking.key, self_count, "+inf") CityContendFactionRanking.incr_score( p.factionID, 1) treasure = treasures.get( p.city_contend_cache_target.get("level", 1)) if not treasure: treasure = treasures[max(treasures)] money = treasure.attack_treasure * get_cons_value( "CityContendAttackMoney") soul = treasure.attack_treasure * get_cons_value( "CityContendAttackSoul") event = self.get_current_step(p) drop = event["argv"] gain = {"money": money, "soul": soul} reward = open_reward( RewardType.CityContendAttack, drop ) drop_reward = reward.apply_after() total_reward = apply_reward( p, combine_reward(gain, drop_reward), type=RewardType.CityContendAttack) combine_reward(total_reward, {}, p.city_contend_rewards) p.city_contend_total_treasure += treasure.attack_treasure rsp.rewards = build_reward(drop_reward) rsp.treasure_rewards = build_reward(gain) rsp.treasure_count = treasure.attack_treasure if not message_config.multiple1 or message_config.multiple1 \ and count == 1: full_message = message_config.attack_count_desc.format( p.faction_name, p.name, p.city_contend_count ) horn = message_config.horn1 try: target_name = target.get("name", u"").decode("utf-8") except UnicodeEncodeError: target_name = target.get("name", u"") self_message = message_config.single_attack_win_desc.format( target_name ) if not message_config.multiple2 or message_config.multiple2 \ and count == 1: red_count = message_config.red_paper_count red_drop = message_config.red_paper red_message = message_config.red_paper_desc.format( p.faction_name, p.name, p.city_contend_count, red_count ) # {{ 使用每日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: # {{ 每日PVP now = int(time.time()) p.daily_dead_cd = now + get_cons_value("DailyDeadCD") # }} # FIXME try: target_name = target.get("name", u"").decode("utf-8") except UnicodeEncodeError: target_name = target.get("name", u"") self_message = message_config.single_attack_lose_desc.format( target_name ) module = RedModuleType.CityContendAttack if self_message: g_redManager.send_red_message( p, self_message, to_self=True, module=module) if full_message: _type = RedType.Horn if horn else RedType.Normal g_redManager.send_red_message( p, full_message, type=_type, module=module) if red_message and red_count: g_redManager.send_red_message( p, red_message, red_drop=red_drop, red_count=red_count, type=RedType.Red, module=module) p.save() p.sync()
def on_wish(p, rewards, news): rewards = build_reward(rewards) return news.desc, p.name, p.entityID, rewards