def get_target(self, p): if p.daily_cache_targetID: targetID = p.daily_cache_targetID else: # 下区间 = int(500/(2*最高连胜数+10)) # 上区间 = int(最高连胜数/2) top = int(p.daily_max_win_count / 2) + 2 bot = int(500/(2 * p.daily_max_win_count + 10)) need = bot + top targets = map( int, PlayerDailyRankRanking.get_range_by_score( p.daily_rank, "+inf", count=top)) need = need - len(targets) targets.extend(map( int, PlayerDailyRankRanking.get_range_by_score( "-inf", max(p.daily_rank - 1, 0), count=need))) try: targets = list(set(targets)) targets.remove(p.entityID) except ValueError: pass if not targets: return None targetID = choice_one(targets) p.daily_cache_targetID = targetID p.save() detail = get_opponent_detail(targetID, type=LineupType.Daily) if not detail.get("pets"): detail = get_opponent_detail(targetID) return detail
def get_target(self, p): if not p.city_contend_cache_target: if self.is_top_faction(p.factionID): targets_pool = CityContendAttackRanking else: targets_pool = CityContendDefendRanking size = targets_pool.count() if not size: targets_pool = CityDungeonSelfBackupRanking size = targets_pool.count() if not size: targets_pool = PlayerLevelRanking size = targets_pool.count() rank = int(random.randint(1, size) or 0) if not rank: return None targetID = targets_pool.get_by_rank(rank) detail = get_opponent_detail( targetID, type=LineupType.City) if not detail.get("pets"): detail = get_opponent_detail(targetID) result = detail try: del result["lastlogin"] except KeyError: pass p.city_contend_cache_target = result return dict(p.city_contend_cache_target)
def challenge(self, player): """挑战""" from lineup.constants import LineupType p = player floor = p.climb_tower_floor + 1 max_retry = 5 retry = 0 config = get_config(ClimbTowerAccreditConfig).get(floor, None) if not config: config = get_config(ClimbTowerConfig)[floor] t = config.zombie_id if floor in self.floors: self.floors[floor].cleanup() f = self.floors[floor].idx # 如果派驻满了而且有空闲对手 while retry < max_retry and self.floors[floor].is_full() \ and f.count() > self.floors[floor].lock.count(): start = random.randint(0, f.count()) targets = f.pool.execute('ZRANGE', f.key, start, start + 10) logger.debug('climb_tower targets: %s' % targets) for m in targets: if int(m) == player.entityID or self.floors[floor].lock.exists(m): continue logger.debug('challenge player') return get_opponent_detail(int(m), type=LineupType.Accredit) retry += 1 logger.debug('challenge zombie') return get_opponent_detail(t)
def get_target_detail(self, entityID, detail=True): originID = entityID swaprank = self.get_rank(entityID) name = None if entityID < 0: entityID = int(str(entityID)[:-4]) config = get_config(RobotNameConfig).get(swaprank) if config: name = config.name if detail: detail = get_opponent_detail(entityID, type=LineupType.DEF) if not detail.get("pets"): detail = get_opponent_detail(entityID, type=LineupType.ATK) else: detail = g_entityManager.get_players_info([entityID], [ 'entityID', 'name', 'level', 'prototypeID', 'vip', 'borderID', 'point', 'faction_name', ]) if detail: detail = detail[0] if detail: detail['swaprank'] = swaprank detail["entityID"] = originID if name: detail["name"] = name return detail
def faction_member_detail(self, msgtype, body): req = poem_pb.RequestMemberDetail() req.ParseFromString(body) from pvp.manager import get_opponent_detail d = get_opponent_detail(req.entityID) rsp = poem_pb.TargetDetailResponse(**d) return success_msg(msgtype, rsp)
def faction_invite_infos(self, msgtype, body): factionID = self.player.factionID if not factionID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION) faction = Faction.simple_load(factionID, ['leaderID', 'inviteset']) if self.player.entityID != faction.leaderID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED) memberIDs = faction.inviteset thumbs = g_entityManager.get_players_info(memberIDs, [ 'entityID', 'name', 'career', 'prototypeID', 'totalfp', 'level', 'todayfp', 'lastlogin', ]) rsp = poem_pb.MemberInfos() now = int(time.time()) for thumb in thumbs: last = int(time.mktime(thumb['lastlogin'].timetuple())) thumb['time'] = now - last # rs = get_lineup_details_atk(thumb['entityID']) detail = get_opponent_detail(thumb["entityID"]) thumb.update(detail) rsp.members.add(**thumb) return success_msg(msgtype, rsp)
def dlc_helper_list(self, msgtype, body): p = self.player req = poem_pb.DlcHelperListRequest() req.ParseFromString(body) now = int(time.time()) if req.social == 1: # friend helpers = list(p.friendset) else: if not p.factionID: helpers = [] else: f = Faction.simple_load(p.factionID, ["memberset"]) helpers = list(f.memberset) try: helpers.remove(p.entityID) except ValueError: pass if req.social == 3: # both helpers += list(p.friendset) helpers = list(set(helpers)) rsp = poem_pb.DlcHelperList() details = [] for helper in helpers: detail = get_opponent_detail(helper) last = int(time.mktime( detail['lastlogin'].timetuple() )) detail['time'] = now - last detail["dlc_cd"] = get_helper_cd(p, helper, now=now) details.append(detail) update_onlines(details) rsp.helpers = details return success_msg(msgtype, rsp)
def loot_target(player, power, loot, count): dvalue = 100 + power * 0.06 s, e = int(max(0, power - dvalue)), int(power + dvalue) samples = set(PlayerPowerRanking.get_range_by_score(s, e, count=16)) - set( [player.entityID]) zombies = set(get_zombies_by_power(s, e, count=5)) # s = max(player.level - 12, 1) # e = max(player.level - 6, 1) # samples = set( # PlayerLevelRanking.get_range_by_score( # s, e, count=16) # ) - set([player.entityID]) # zombies = set(reduce( # lambda x, y: x+y, # [get_zombies_by_level(l)[:5] # for l in range(s, e + 1)])) samples = samples.union(zombies) chosen = choice_one(list(samples)) logger.debug("search targets is {}".format(samples)) if not is_zombie(chosen): rest = search_targets_loot([chosen], loot)[0] p = Player.simple_load(chosen, "loot_protect_time") now = int(time.time()) if PlayerLootLock.locked(chosen) or \ now < p.loot_protect_time and rest < 50 and rest < count: chosen = choice_one(list(zombies)) if not chosen: chosen = choice_one(list(get_zombies())) # # NOTE FIXME FOR DEBUG # chosen = player.entityID return get_opponent_detail(chosen)
def get_group_info(groupID): g = Group.simple_load(groupID, ["name", "leaderID", "members"]) if not g: return {} g.members.load() intimate = 0 members = OrderedDict( sorted(g.members.items(), key=lambda v: (v[0] == g.leaderID) or v[1]["jointime"])) memberlist = [] for entityID, member in members.items(): member.setdefault("intimate", 0) intimate += member["intimate"] member.update(get_opponent_detail(entityID)) members[entityID] = member memberlist.append(member) rs = { "groupID": g.groupID, "name": g.name, "members": memberlist, "membercount": len(members), "intimate": intimate, "leaderID": g.leaderID } return rs
def faction_member_infos(self, msgtype, body): factionID = self.player.factionID if not factionID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION) faction = Faction.simple_load(factionID, ['memberset']) thumbs = g_entityManager.get_players_info(list(faction.memberset), [ 'entityID', 'name', 'career', 'prototypeID', 'totalfp', 'level', 'todayfp', 'lastlogin', 'joinFactionTime', ]) rsp = poem_pb.MemberInfos() now = int(time.time()) DAY = 86400 for thumb in thumbs: last = int(time.mktime(thumb['lastlogin'].timetuple())) thumb['time'] = now - last if thumb['time'] >= DAY: thumb['todayfp'] = 0 thumb['jointime'] = now - thumb['joinFactionTime'] detail = get_opponent_detail(thumb["entityID"]) detail['beMyFriend'] = thumb["entityID"] in self.player.friendset detail['applied'] = thumb["entityID"] in self.player.friend_applys thumb.update(detail) update_onlines(thumbs) rsp.members = thumbs return success_msg(msgtype, rsp)
def group_apply_list(self, msgtype, body): p = self.player g = Group.simple_load(p.groupID, ["leaderID"]) if p.entityID != g.leaderID: return fail_msg(msgtype, msgTips.FAIL_MSG_GROUP_PERMISSION_DENIED) rsp = poem_pb.GroupApplyList() for i in p.group_applys or []: info = get_opponent_detail(i) rsp.members.add(**info) return success_msg(msgtype, rsp)
def rob_target(player, targetID, booty, type): if is_zombie(targetID): detail = get_opponent_detail(targetID) return ('', booty, detail), 0 now = int(time.time()) # 检查保护 t = Player.simple_load(targetID, ['mine_protect_time']) if t.mine_protect_time > now: return None, msgTips.FAIL_MSG_ROB_ALREADY_IN_PROTECTION try: # 检查是否正在战斗 unlocking_key = PlayerMineLock.lock(targetID) curr = get_curr_products(targetID, now, type) if booty is not None: if curr < booty: PlayerMineLock.unlock(targetID, unlocking_key) return None, msgTips.FAIL_MSG_ROB_ALREADY_HARVESTED else: booty = curr booty = max(booty, 0) detail = get_opponent_detail( targetID, type=get_lineuptype_by_type(type)) return (unlocking_key, booty, detail), 0 except PlayerMineLock.LockedError: return None, msgTips.FAIL_MSG_ROB_ALREADY_ROBBED
def search_target(p, fbID): detail = p.dlc_detail_cache.get(fbID, {}) if detail: return detail dlc_fb = get_config(DlcFbInfoConfig)[fbID] lo, hi = dlc_fb.range if lo or hi: spower = (1 + lo / float(100)) * p.max_power epower = (1 + hi / float(100)) * p.max_power if p.max_power > spower and p.max_power < epower: count = 11 else: count = 10 ranks = PlayerMaxPowerRanking.get_range_by_score( spower, epower, count=count) try: ranks.remove(p.entityID) except ValueError: pass if ranks: if dlc_fb.rule == 1: target = ranks[-1] elif dlc_fb.rule == 2: target = ranks[0] else: target = choice_one(ranks) detail = get_opponent_detail(target) if not detail: # robot lo, hi = dlc_fb.rob_range if lo or hi: spower = (1 + lo / float(100)) * p.max_power epower = (1 + hi / float(100)) * p.max_power zombies = get_zombies_by_power( spower, epower, count=5, hide=False, group=dlc_fb.robot_group) logger.debug("zombies by power: %r", zombies) if not zombies: zombies = get_zombies_by_level( p.level, hide=False, group=dlc_fb.robot_group) logger.debug("zombies by level: %r", zombies) if dlc_fb.rob_rule == 1: target = zombies[-1] elif dlc_fb.rob_rule == 2: target = zombies[0] else: target = choice_one(zombies) detail = get_zombie(target) p.dlc_detail_cache[fbID] = detail return detail
def backup(self): rankers = convert_list_to_dict( PlayerDailyRankRanking.get_range_by_score( "-inf", "+inf", count=3, withscores=True)) result = [] sorted_rankers = sorted( rankers.items(), key=operator.itemgetter(1), reverse=True) index_pool.execute("DEL", DailyTopThreeBackup) for rank, (i, daily_max_win_count) in enumerate(sorted_rankers, 1): detail = get_opponent_detail(i) detail["daily_max_win_count"] = daily_max_win_count result.append(detail) index_pool.execute( "HSET", DailyTopThreeBackup, rank, cPickle.dumps(detail)) self.reload_top_three() return result
def get_rankers(self, count=50): from campaign.manager import g_campaignManager opened = g_campaignManager.dailypvp_campaign.is_open() if opened: rankers = convert_list_to_dict( PlayerDailyRankRanking.get_range_by_score( "-inf", "+inf", count=count, withscores=True)) result = [] sorted_rankers = sorted( rankers.items(), key=operator.itemgetter(1), reverse=True) for i, daily_max_win_count in sorted_rankers: detail = get_opponent_detail(i) detail["daily_max_win_count"] = daily_max_win_count result.append(detail) else: result = self.get_backup_top_three() return result
def get_opponent_detail_by_strategy(self, player): from config.configs import get_config, PvpDegreeConfig configs = get_config(PvpDegreeConfig) opps = [] score = player.totalbp logger.debug("score: %d", score) for config in configs: logger.debug("start:%d, end:%d", config.start, config.end) if score >= config.start and score < config.end: logger.debug("prob:%f", config.prob) if guess(config.prob): logger.debug("guess:true") opps = get_zombies_by_level(player.level) break if not opps: opps = self.get_opponents_by_strategy(player.level, player.totalbp) opps = filter(lambda s: s != player.entityID, opps) logger.debug('random opps {}'.format(opps)) oppID = choice_one(opps) assert oppID, 'not opp' logger.debug("choose opp:%d", oppID) return get_opponent_detail(oppID, type=LineupType.DEF)
def get_group_member_detail_across_region(regionID, entityID): assert regionID == settings.REGION["ID"] detail = get_opponent_detail(entityID) return detail
def build_player_item(self, entityID, item): detail = get_opponent_detail(entityID) item.detail = poem_pb.TargetDetailResponse(**detail) item.name = item.detail.name item.prototypeID = item.detail.prototypeID
def get_detail(targetID): return get_opponent_detail(targetID)