Esempio n. 1
0
File: city.py Progetto: kimch2/x8623
 def gen_mg(self, p):
     incr = 1
     sums = self.incr_mg_sums(p, incr)
     origin = self.get_mg_by_count(sums - incr)
     current = self.get_mg_by_count(sums)
     horn = False
     if current["id"] != origin["id"]:
         # 进入下一层
         message_configs = get_config(CityDungeonMessageConfig)
         message_config = message_configs.get(origin["id"])
         if not message_config:
             message_config = message_configs[max(message_configs)]
         full_message = ""
         red_message = ""
         red_count = 0
         if message_config.multiple1 or message_config.multiple2:
             rs = CityDungeonSumsRanking.pool.execute_pipeline(
                 [
                     "ZADD",
                     CityDungeonSumsRanking.key,
                     current["id"],
                     p.factionID,
                 ],
                 [
                     "ZCOUNT",
                     CityDungeonSumsRanking.key,
                     current["id"],
                     "+inf",
                 ]
             )
             count = rs[1]
             if (not message_config.multiple1) or \
                     message_config.multiple1 and count == 1:
                 full_message = message_config.unions_win_desc.format(
                     p.faction_name, current["id"])
             if (not message_config.multiple2) or \
                     message_config.multiple2 and count == 1:
                 red_count = message_config.red_paper_count
                 red_message = message_config.red_paper_desc.format(
                     p.faction_name, current["id"], red_count)
                 red_drop = message_config.red_paper
         else:
             CityDungeonSumsRanking.update_score(p.factionID, current["id"])
             full_message = message_config.unions_win_desc
             red_count = message_config.red_paper_count
             red_message = message_config.red_paper_desc
         if full_message:
             _type = RedType.Horn if horn else RedType.Normal
             g_redManager.send_red_message(
                 p, full_message, type=_type,
                 module=RedModuleType.CityDungeon)
         if red_message and red_count:
             g_redManager.send_red_message(
                 p, red_message, red_count=red_count,
                 type=RedType.Red, red_drop=red_drop,
                 module=RedModuleType.CityDungeon, name=p.faction_name)
         self.sync_city_dungeon_current_info(p)
     return current
Esempio n. 2
0
File: city.py Progetto: kimch2/x8623
 def end_defend_event(self, p):
     Faction.incr_attribute(
         p.factionID, "faction_treasure", p.city_contend_treasure)
     p.city_contend_total_treasure += p.city_contend_treasure
     p.city_contend_treasure = 0
     p.city_contend_step = 0
     p.city_contend_events = []
     p.city_contend_count += 1
     p.save()
     p.sync()
     # self_count = CityContendDefendRanking.incr_score(
     #     p.entityID, p.city_contend_treasure)
     self_count = CityContendDefendRanking.update_score(
         p.entityID, p.city_contend_count)
     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)]
     count = CityContendDefendRanking.pool.execute(
         "ZCOUNT", CityContendDefendRanking.key, self_count, "+inf")
     full_message = ""
     red_message = ""
     red_count = 0
     if message_config.multiple1 or message_config.multiple1 \
             and count == 1:
         full_message = message_config.defend_count_desc.format(
             p.name, p.city_contend_count
         )
         horn = message_config.horn1
     if message_config.multiple2 or message_config.multiple2 \
             and count == 1:
         red_count = message_config.red_paper_count
         red_message = message_config.red_paper_desc.format(
             p.faction_name, p.name, p.city_contend_count, red_count
         )
         red_drop = message_config.red_paper
     if full_message:
         g_redManager.send_red_message
         _type = RedType.Horn if horn else RedType.Normal
         g_redManager.send_red_message(
             p, full_message, type=_type)
     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=RedModuleType.CityContendDefend)
Esempio n. 3
0
File: city.py Progetto: kimch2/x8623
 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()
Esempio n. 4
0
File: city.py Progetto: kimch2/x8623
 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()
Esempio n. 5
0
 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