def add_attr(role, attrs): adds = {} for attr, value in attrs.items(): assert value >= 0 if attr == 'exp': set_exp(role, value) else: old = getattr(role, attr) new = old + value setattr(role, attr, new) if attr == 'totalfp': role.todayfp_task += value if role.factionID: Faction.incr_attribute(role.factionID, 'totalfp', value) if attr == 'money': from task.manager import on_money on_money(role, value) elif attr == "gold": from task.manager import on_gold on_gold(role, value) elif attr == "soul": from task.manager import on_soul on_soul(role, value) adds[attr] = value return adds
def load_faction(self): from faction.model import Faction from faction.model import FactionRankRanking from faction.manager import update_strengthen_level # now = int(time.time()) if self.factionID: faction = Faction.simple_load( self.factionID, [ 'leaderID', 'name', 'strengthen_at_level', 'strengthen_hp_level', 'strengthen_ct_level' ]) if faction: if self.entityID == faction.leaderID: applyset = Faction.simple_load( self.factionID, ['applyset']).applyset self.applyMemberSet = applyset self.faction_name = faction.name level = self.faction_level = FactionRankRanking.get_score( self.factionID) or 1 from task.manager import on_faction_level on_faction_level(self, level) update_strengthen_level(self, self.factionID) # if self.applyFactionTime and self.applyFactionTime < now: # self.applyFactionTime = 0 # self.applyFactionID = 0 return
def donate_sp(p, sp): # 并不消耗人物的能量 # 推图等消耗能量后,贡献公会贡献 if not p.factionID: return if p.todayfp_sp >= p.todayfp_sp_max: return configs = get_config(FactionDonateConfig) # 能量兑换贡献 config = configs[4] mul = p.faction_sp / config.arg1 base = config.arg2 * mul rest = p.todayfp_sp_max - p.todayfp_sp # 不能超过上限 if base > rest: base = rest # 重新计算,需要消耗多少能量 cost = base / config.arg2 * config.arg1 # 贡献兑换声望 fpconfig = configs[3] fp = base / fpconfig.arg1 * fpconfig.arg2 logger.debug("donate sp %r", sp) logger.debug("faction_sp %r", p.faction_sp) logger.debug("cost sp %r", cost) p.faction_sp -= cost logger.debug("remain sp %r", p.faction_sp) p.fp += fp logger.debug("gain fp %r", fp) p.todayfp_sp += base logger.debug("donate %r", base) p.totalfp += base logger.debug("todayfp_sp %r", p.todayfp_sp) p.save() p.sync() Faction.incr_attribute(p.factionID, 'totalfp', base)
def join_faction(entityID, factionID): faction = Faction.simple_load(factionID, [ "level", "name", "memberset", "inviteset", "applyset", "strengthen_hp_level", "strengthen_at_level", "strengthen_ct_level", "strengthen_df_level" ]) # recommend level = FactionRankRanking.get_score(factionID) or 1 limit = get_config(FactionLimitConfig)[level].limit if limit - len(faction.memberset) <= 1: unrecommend(factionID) clean_faction(entityID) p = g_entityManager.get_player(entityID) if not p: p = Player.simple_load(entityID, [ 'inviteFactionSet', 'factionID', 'last_factionID', 'strengthen_at_level', 'strengthen_hp_level', 'strengthen_ct_level', 'strengthen_df_level', ]) p.factionID = faction.factionID p.faction_name = faction.name p.faction_level = level now = int(time.time()) p.joinFactionTime = now # FIXME for fid in p.inviteFactionSet: f = Faction.simple_load(fid, ['inviteset']) safe_remove(f.inviteset, p.entityID) f.save() p.inviteFactionSet.clear() if p.factionID != p.last_factionID: p.totalfp = 0 p.todayfp_donate = 0 p.todayfp_task = 0 p.todayfp_sp = 0 faction.memberset.add(p.entityID) safe_remove(faction.applyset, p.entityID) safe_remove(faction.inviteset, p.entityID) if g_entityManager.get_player(entityID): p.load_faction() p.sync() p.save() faction.save() gm_logger.info({ 'faction': { 'entityID': p.entityID, 'type': 'join_faction', 'factionID': faction.factionID, } })
def clean_faction(entityID): p = g_entityManager.get_player(entityID) if not p: p = Player.simple_load(entityID, ['factionID', 'applyFactions']) if p.factionID: faction = Faction.simple_load(p.factionID, ['memberset']) if faction: safe_remove(faction.memberset, p.entityID) faction.save() p.last_factionID = p.factionID gm_logger.info({ 'faction': { 'entityID': p.entityID, 'type': 'quit_faction', 'factionID': p.factionID, } }) p.factionID = 0 p.fp = 0 p.faction_name = '' p.faction_level = 0 p.faction_is_leader = False p.applyFactions.clear() # p.applyFactionTime = 0 p.save() if g_entityManager.get_player(entityID): p.sync()
def faction_accept_invite(self, msgtype, body): p = self.player if p.factionID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_ALREADY_HAD_FACTION) if is_applied(p): return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_ALREADY_APPLYED) req = poem_pb.AcceptInvite() req.ParseFromString(body) try: faction = Faction.load(req.factionID) except EntityNotFoundError: safe_remove(self.player.inviteFactionSet, req.factionID) return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_THIS_FACTION) if req.isaccept: if not isrecommend(req.factionID): return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_MEMBERS_LIMIT_EXCEED) join_faction(p.entityID, faction.factionID) else: safe_remove(self.player.inviteFactionSet, req.factionID) safe_remove(faction.inviteset, self.player.entityID) faction.save() p.save() p.sync() return success_msg(msgtype, '')
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 faction_info(self, msgtype, body): p = self.player factionID = p.factionID if not factionID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION) info = get_faction_info(p.factionID) if not info: p.factionID = 0 p.save() p.sync() return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION) if info['dflag']: if info['leaderID'] == p.entityID: # 检查解散公会 if p.dismissCD: if p.dismissCD < int(time.time()): faction = Faction.simple_load(factionID, ['name']) faction.delete() FactionnameIndexing.unregister(faction.name) FactionRankRanking.del_key(factionID) clean_faction(p.entityID) p.dismissCD = 0 p.save() p.sync() return fail_msg( msgtype, msgTips.FAIL_MSG_FACTION_ALREADY_DISMISSED) if not info: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_THIS_FACTION) rsp = poem_pb.FactionInfo(**info) return success_msg(msgtype, rsp)
def friend_invite_list(self, msgtype, body): p = self.player if not p.factionID: return success_msg(msgtype, "") req = poem_pb.InviteFriendList() req.ParseFromString(body) logger.debug(req) try: ownerID, fbID = simple_load_friendfb(req.friendfbID, 'ownerID', 'fbID') except DoesNotExistsException: return fail_msg(msgtype, msgTips.FAIL_MSG_FRIENDFB_ALREADY_DISAPPEARED) if p.entityID != ownerID: return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST) invitees = load_friendfb_invitees(req.friendfbID) # invitees 起码会有发现者 assert invitees, "impossible" fields = ['entityID', 'name', 'prototypeID', 'level', "borderID"] # 过滤已经邀请的好友(2016-02-18 改会公会成员) f = Faction.simple_load(p.factionID, ["memberset"]) rs = Player.batch_load(list(set(f.memberset) - invitees), fields) rsp = poem_pb.InviteFriendListResponse() config = get_config(FriendfbConfig)[fbID] for each in rs: info = {} if each.level < config.openlv: continue for f in fields: info[f] = getattr(each, f) info['id'] = info['entityID'] rsp.friends.add(**info) return success_msg(msgtype, rsp)
def get_faction_info(factionID): faction = Faction.get(factionID) if not faction: return {} player = Player.simple_load(faction.leaderID, ['prototypeID', 'name']) return dict( factionID=factionID, name=faction.name, level=FactionRankRanking.get_score(faction.factionID) or 1, mcount=len(faction.memberset), acount=len(faction.applyset), totalfp=faction.totalfp, todayfp=faction.todayfp, rank=FactionRankRanking.get_rank(factionID), prototypeID=player.prototypeID, leader=player.name, createtime=faction.createtime, notice=faction.notice, mode=faction.mode, strengthen_hp_level=faction.strengthen_hp_level, strengthen_at_level=faction.strengthen_at_level, strengthen_ct_level=faction.strengthen_ct_level, strengthen_df_level=faction.strengthen_df_level, can_strengthen=get_config(CanStrengthenConfig)[1].can, leaderID=faction.leaderID, dflag=faction.dflag, )
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 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 incr_mg_kill(self, p, mg_id, incr=1): p.city_dungeon_kill_count += incr CityDungeonKillRanking.incr_score(p.factionID, incr) kill_key = self.get_mg_kill_key(p.factionID) entity_pool.execute("HINCRBY", kill_key, mg_id, incr) f = Faction.simple_load(p.factionID, ['city_top_member_kills']) if p.city_dungeon_kill_count > f.city_top_member_kills: dd = { "name": p.name, "prototypeID": p.prototypeID, "borderID": p.borderID, } lineup = p.lineups.get(LineupType.City, []) if not lineup: lineup = p.lineups.get(LineupType.ATK, []) if lineup: petID = filter(lambda s: s, lineup)[0] pet = p.pets.get(petID) if pet: dd.update({ "petID": pet.prototypeID, "pet_step": pet.breaklevel, }) f.city_top_member = dd f.city_top_member_kills = p.city_dungeon_kill_count f.save() p.save() p.sync()
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 faction_donate(self, msgtype, body): p = self.player if not p.factionID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION) if p.todayfp_donate >= p.todayfp_donate_max: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_EXCEED_DAILY_DONATE_LIMIT) req = poem_pb.FactionDonate() req.ParseFromString(body) config = get_config(FactionDonateConfig)[1] fp = req.gold / config.arg1 * config.arg2 if req.gold < config.arg1 or \ req.gold % 10 != 0 or \ (p.todayfp_donate + fp) > p.todayfp_donate_max: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_DONATE_AMOUNT_INVALID) try: cc = get_config(FactionDonateConfig)[3] apply_reward(p, {'fp': fp / cc.arg1 * cc.arg2}, cost={'gold': req.gold}, type=RewardType.DonateFaction) except AttrNotEnoughError: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_ENOUGH_GOLD) totalfp = Faction.incr_attribute(p.factionID, 'totalfp', fp) p.totalfp += fp p.todayfp_donate += fp p.save() p.sync() rsp = poem_pb.FactionDonateResponse() rsp.totalfp = totalfp 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 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)
def sync_apply(entityID): player = g_entityManager.get_player(entityID) if player: faction = Faction.simple_load(player.factionID, ['applyset', 'leaderID']) player.applyMemberSet = faction.applyset player.sync() return SUCCESS
def give_reward(self, date=None): if not date: now = int(time.time()) tm = date = datedate.fromtimestamp(now).strftime("%Y-%m-%d") else: tm = date ranking = get_ranking_backup(self.type) key = ranking.key ll = get_config(RankingCampaignRewardByGroupConfig).get( self.config.group, []) configs = get_config(RankingCampaignRewardConfig) configs = [configs[i.id] for i in ll] key = "%s{%s}" % (key, tm) limit = get_ranking_limit(self.type) if limit is not None: rankers = ranking.get_range_by_score(limit, "+inf", withscores=True) else: rankers = ranking.get_range_by_score("-inf", "+inf", withscores=True) rankers = convert_list_to_dict(rankers, dictcls=OrderedDict).items() for rank, (entityID, score) in enumerate(rankers, 1): config = None for c in configs: start, end = c.range if start: if start > rank: continue if end: if end < rank: continue config = c if not config: continue title, content, ID = get_mail("RankingReward") content = content.format(self.config.day, self.config.title, rank) if self.type in get_faction_types(): f = Faction.simple_load(entityID, ["leaderID", "memberset"]) for i in set(f.memberset): if i == f.leaderID: rewards = parse_reward(config.rewards) else: rewards = parse_reward(config.rewards2) try: proxy.ranking_send_mail(i, title, content, rewards, key, ID) except AttributeError: pass else: rewards = parse_reward(config.rewards) try: proxy.ranking_send_mail(entityID, title, content, rewards, key, ID) except AttributeError: pass
def faction_levelup(self, msgtype, body): '''只有会长能操作''' player = self.player factionID = player.factionID if not factionID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION) faction = Faction.simple_load(factionID, ['leaderID']) if player.entityID != faction.leaderID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED) level = FactionRankRanking.get_score(factionID) or 0 configs = get_config(FactionLimitConfig) config = configs.get((level or 1) + 1) if not config: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_MAX_LEVEL) faction = Faction.load(factionID) if faction.totalfp < config.exp: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_ENOUGH_TOTALFP) faction.incr('totalfp', -config.exp) faction.save() if not level: incr = 2 else: incr = 1 rs = FactionRankRanking.incr_score(factionID, incr) limit1 = get_config(FactionLimitConfig)[level or 1] limit2 = get_config(FactionLimitConfig).get((level or 1) + 1) if limit2 and limit2.limit > limit1.limit: recommend(factionID) player.save() player.sync() notify_change(factionID) gm_logger.info({ 'faction': { 'entityID': player.entityID, 'type': 'levelup_faction', 'factionLevel': rs, 'factionID': faction.factionID, } }) return success_msg(msgtype, '')
def faction_create(self, msgtype, body): p = self.player # 判断是否可以创建公会 if p.factionID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_ALREADY_HAD_FACTION) # if is_applied(p): # return fail_msg( # msgtype, msgTips.FAIL_MSG_FACTION_ALREADY_APPLYED) req = poem_pb.AlterNameFaction() req.ParseFromString(body) name, err = validate_name(req.name) if err: return fail_msg(msgtype, err) try: FactionnameIndexing.register(0, name) # 占位 except DuplicateIndexException: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_DUPLICATE_FACTION_NAME) try: now = int(time.time()) faction = Faction.create(name=name, createtime=now, leaderID=p.entityID) except EntityExistsException: FactionnameIndexing.unregister(name) return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_CREATE_FAIL) try: apply_reward(p, {}, cost={'gold': 500}, type=RewardType.CreateFaction) except AttrNotEnoughError: FactionnameIndexing.unregister(name) return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_ENOUGH_GOLD) FactionnameIndexing.pool.execute('HSET', FactionnameIndexing.key, name, faction.entityID) # 更新 faction.save() gm_logger.info({ 'faction': { 'entityID': p.entityID, 'type': 'create_faction', 'factionName': faction.name, 'factionLevel': 1, 'factionID': faction.factionID, } }) join_faction(p.entityID, faction.factionID) p.faction_is_leader = True p.save() p.sync() recommend(faction.factionID) # 加入推荐列表 FactionRankRanking.update_score(faction.factionID, 1) rsp = poem_pb.FactionInfo(**get_faction_info(faction.factionID)) return success_msg(msgtype, rsp)
def build_faction_item(self, factionID, item): f = Faction.simple_load( factionID, ["name", "leaderID", "memberset"] ) if f: l = Player.simple_load(f.leaderID, ["prototypeID"]) item.name = f.name item.prototypeID = l.prototypeID item.faction_count = len(f.memberset) item.faction_level = FactionRankRanking.get_score(factionID) or 1 item.entityID = factionID
def reset(self): from campaign.manager import g_campaignManager start_time = g_campaignManager.city_dungeon_campaign.get_start_time() final_time = g_campaignManager.city_dungeon_campaign.get_final_time() reset = int(float(index_pool.execute( "GETSET", CityDungeonReset, start_time) or 0)) if reset >= start_time and reset <= final_time: index_pool.execute( "SET", CityDungeonReset, reset) logger.info("Not need reset city dungeon") return logger.info("Reset city dungeon") # 发送奖励 self.give_reward() cmds = [] # 备份 self.set_top_info() CityDungeonKillRanking.pool.execute( 'ZUNIONSTORE', CityDungeonKillBackupRanking.key, 1, CityDungeonKillRanking.key) CityDungeonSelfRanking.pool.execute( 'ZUNIONSTORE', CityDungeonSelfBackupRanking.key, 1, CityDungeonSelfRanking.key) # 清除数据 ranking = CityDungeonKillRanking.get_range_by_score("-inf", "+inf") for k in ranking: k = int(k) f = Faction.simple_load(k, [ "entityID", "faction_treasure", "city_top_member_kills"]) f.city_top_member_kills = 0 f.faction_treasure = 0 f.save() cmds.append([ "DEL", self.get_mg_pool_key(k), self.get_mg_sums_key(k), ]) cmds.append([ "HCLEAR", self.get_mg_kill_key(k) ]) entity_pool.execute_pipeline(*cmds) index_pool.execute_pipeline( ("DEL", CityDungeonKillRanking.key), ("DEL", CityDungeonSelfRanking.key), ("DEL", CityDungeonSumsRanking.key), ) g_redManager.clean_red(module=RedModuleType.CityDungeon) top_faction = self.get_top_faction() if top_faction: g_cityContend.set_top_faction(top_faction) self.reset_players()
def get_faction_thumb(factionID): faction = Faction.get(factionID) if not faction: return {} player = Player.simple_load(faction.leaderID, ['prototypeID']) return { 'factionID': faction.factionID, 'name': faction.name, 'totalfp': faction.totalfp, 'todayfp': faction.todayfp, 'prototypeID': player.prototypeID, 'mcount': len(faction.memberset), }
def deny_apply_failure(factionID, entityID): faction = Faction.simple_load(factionID, ['applyset', 'leaderID']) safe_remove(faction.applyset, entityID) faction.save() proxy.sync_apply(faction.leaderID) player = Player.simple_load(entityID, ['applyFactions']) if is_apply(player, factionID): # 玩家还没有取消申请 safe_remove(player.applyFactions, factionID) # player.applyFactionTime = 0 faction.save() player.save() return SUCCESS return msgTips.FAIL_MSG_FACTION_ALREADY_CANCEL_APPLY
def broadcast_faction_message(m): msg = success_msg(msgid.RECV_MESSAGE, m) from entity.manager import g_entityManager p = g_entityManager.get_player(m.entityID) if not p: p = Player.simple_load(m.entityID, ["factionID"]) from player.manager import g_playerManager from faction.model import Faction if p.factionID: g_chatManager.cache_message(m, factionID=p.factionID) f = Faction.simple_load(p.factionID, ["memberset"]) if f: g_playerManager.broadcast(f.memberset, msg)
def update_strengthen_level(p, factionID): faction = Faction.simple_load(factionID, [ "strengthen_hp_level", "strengthen_at_level", "strengthen_ct_level", "strengthen_df_level" ]) p.strengthen_at_level = min(p.strengthen_at_max_level, faction.strengthen_at_level) p.strengthen_hp_level = min(p.strengthen_hp_max_level, faction.strengthen_hp_level) p.strengthen_ct_level = min(p.strengthen_ct_max_level, faction.strengthen_ct_level) p.strengthen_df_level = min(p.strengthen_df_max_level, faction.strengthen_df_level)
def faction_kick(self, msgtype, body): factionID = self.player.factionID faction = Faction.simple_load(factionID, ['leaderID']) if self.player.entityID != faction.leaderID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED) req = poem_pb.KickMember() req.ParseFromString(body) err = proxy.kick_member(factionID, req.entityID) if err: return fail_msg(msgtype, err) else: # 加入推荐列表 recommend(factionID) return success_msg(msgtype, '')
def faction_cancel_dismiss(self, msgtype, body): player = self.player factionID = player.factionID faction = Faction.simple_load(factionID, ['leaderID', 'dflag']) if player.entityID != faction.leaderID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED) faction.dflag = False faction.save() recommend(factionID) player.dismissCD = 0 player.save() player.sync() return success_msg(msgtype, '')
def faction_review(self, msgtype, body): factionID = self.player.factionID fs = Faction.expend_fields(['level', 'memberset', 'leaderID', 'dflag']) faction = Faction.simple_load(factionID, fs) if self.player.entityID != faction.leaderID: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED) req = poem_pb.ReviewMember() req.ParseFromString(body) if req.isallow: if faction.dflag: return fail_msg( msgtype, msgTips. FAIL_MSG_FACTION_CAN_NOT_ALLOW_JOIN_WILL_DISMISS_FACTION ) # NOQA err = proxy.allow_apply(factionID, req.entityID) if err == msgTips.FAIL_MSG_FACTION_ALREADY_CANCEL_APPLY: recommend(factionID) else: err = proxy.deny_apply(factionID, req.entityID) if not err: return success_msg(msgtype, '') return fail_msg(msgtype, err)