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 faction_cancel_apply(self, msgtype, body): req = poem_pb.CancelApplyFaction() req.ParseFromString(body) if not is_applied(self.player): return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_APPLYED) try: faction = Faction.load(req.factionID) except EntityNotFoundError: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_THIS_FACTION) safe_remove(faction.applyset, self.player.entityID) safe_remove(self.player.applyFactions, req.factionID) # self.player.applyFactionID = 0 # self.player.applyFactionTime = 0 faction.save() proxy.sync_apply(faction.leaderID) self.player.save() self.player.sync() return success_msg(msgtype, '')
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_research(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 1 faction = Faction.load(factionID) req = poem_pb.FactionResearchOrLearn() req.ParseFromString(body) prefix = { poem_pb.FactionStrengthen.hp: 'strengthen_hp', poem_pb.FactionStrengthen.at: 'strengthen_at', poem_pb.FactionStrengthen.ct: 'strengthen_ct', poem_pb.FactionStrengthen.df: 'strengthen_df', }[req.type] k = prefix + '_level' slevel = getattr(faction, k, 0) if slevel >= level: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_MAX_LEVEL) configs = get_config(FactionStrengthenConfig) config = configs.get(slevel + 1) if not config: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_MAX_LEVEL) if faction.totalfp < config.cost: return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_ENOUGH_TOTALFP) faction.totalfp -= config.cost setattr(faction, k, slevel + 1) faction.save() FactionSkillRanking.incr_score(faction.factionID, 1) notify_strengthen_change(factionID) return success_msg(msgtype, '')