| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796 |
- package com.ljsd.jieling.logic.family;
- import com.google.protobuf.GeneratedMessage;
- import com.ljsd.GameApplication;
- import com.ljsd.jieling.core.GlobalsDef;
- import com.ljsd.jieling.core.Lockeys;
- import com.ljsd.jieling.core.SimpleTransaction;
- import com.ljsd.jieling.core.VipPrivilegeType;
- import com.ljsd.jieling.logic.activity.ActivityLogic;
- import com.ljsd.jieling.logic.activity.ActivityTypeEnum;
- import com.ljsd.jieling.reportBeans_37.ChatContentType;
- import com.ljsd.jieling.reportBeans_37.Repot37EventUtil;
- import com.ljsd.jieling.db.mongo.MongoUtil;
- import com.ljsd.jieling.db.redis.RedisKey;
- import com.ljsd.jieling.db.redis.RedisUtil;
- import com.ljsd.jieling.exception.ErrorCode;
- import com.ljsd.jieling.exception.ErrorCodeException;
- import com.ljsd.jieling.globals.BIReason;
- import com.ljsd.jieling.globals.Global;
- import com.ljsd.jieling.jbean.ActivityProgressInfo;
- import com.ljsd.jieling.ktbeans.ReportEventEnum;
- import com.ljsd.jieling.ktbeans.ReportUtil;
- import com.ljsd.jieling.logic.OnlineUserManager;
- import com.ljsd.jieling.logic.activity.ActivityType;
- import com.ljsd.jieling.logic.activity.IEventHandler;
- import com.ljsd.jieling.logic.activity.event.*;
- import com.ljsd.jieling.logic.dao.*;
- import com.ljsd.jieling.logic.dao.root.*;
- import com.ljsd.jieling.logic.mail.MailLogic;
- import com.ljsd.jieling.logic.mission.GameEvent;
- import com.ljsd.jieling.logic.player.PlayerLogic;
- import com.ljsd.jieling.logic.rank.RankContext;
- import com.ljsd.jieling.logic.rank.RankEnum;
- import com.ljsd.jieling.logic.rank.rankImpl.AbstractRank;
- import com.ljsd.jieling.logic.store.StoreLogic;
- import com.ljsd.jieling.network.server.ProtocolsManager;
- import com.ljsd.jieling.network.session.ISession;
- import com.ljsd.jieling.protocols.*;
- import com.ljsd.jieling.util.*;
- import config.*;
- import manager.STableManager;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import util.StringUtil;
- import util.TimeUtils;
- import java.util.*;
- public class GuildLogic {
- static GuildLogic guildLogicInstance = new GuildLogic();
- public static GuildLogic getInstance() {
- return guildLogicInstance;
- }
- public void flushEveryDay(User user, PlayerInfoProto.FivePlayerUpdateIndication.Builder fBuilder) throws Exception {
- // takeAllReward(user);
- refreshAndTakeAllReward(user);
- // 发送公会援助奖励
- // sendGuildHelpRewardEmail(user);
- user.getGuildMyInfo().setFetetype(0);
- user.getGuildMyInfo().clearHadTakeReward();
- //清空前天的活跃度
- user.getGuildMyInfo().setGuildActiveNumToday(0);
- if (!TimeUtils.isInSameWeek(user.getGuildMyInfo().getGuildActiveNumWeekTime() * 1000L, TimeUtils.now())) {
- user.getGuildMyInfo().setGuildActiveNumWeek(0);
- }
- if (null != fBuilder) {
- fBuilder.setLastFeteType(user.getGuildMyInfo().getFetetype());
- fBuilder.addAllTakeFeteReward(new HashSet<>());
- }
- //
- }
- void refreshAndTakeAllReward(User user) throws Exception {
- try {
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- return;
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- if (!TimeUtils.isOverTime(0, guildInfo.getLastRefreshTime())) {
- return;
- }
- long now = TimeUtils.now();
- List<int[][]> itemArrs = new LinkedList<>();
- //补发前日未领取的祭祀奖
- Map<Integer, SGuildSacrificeRewardConfig> config = STableManager.getConfig(SGuildSacrificeRewardConfig.class);
- if (null == config) {
- throw new ErrorCodeException(ErrorCode.CFG_NULL);
- }
- RedisUtil.getInstence().del(RedisKey.getKey(RedisKey.GUILD_RED_PACKAGE_RANK, String.valueOf(guildId), false));
- for (Set<Integer> items : guildInfo.getMembers().values()) {
- for (Integer uid : items) {
- User target = UserManager.getUser(uid);
- int gId = target.getPlayerInfoManager().getGuildId();
- if (gId == -1) {
- continue;
- }
- //check 最近一次公会id
- if (target.getGuildMyInfo().getFeteguild() != guildId) {
- continue;
- }
- Set<Integer> objects = new HashSet<>(config.keySet());
- objects.removeAll(target.getGuildMyInfo().getHadTakeReward());
- for (Integer missionId : objects) {
- //checkAndUpdate cfg
- SGuildSacrificeRewardConfig sGuildSacrificeRewardConfig = config.get(missionId);
- //take rewards checkAndUpdate
- int fete = guildInfo.getFete();
- if (sGuildSacrificeRewardConfig.getScore() > fete) {
- continue;
- }
- //up miss
- int[][] reward = sGuildSacrificeRewardConfig.getReward();
- itemArrs.add(reward);
- }
- if (itemArrs.isEmpty()) {
- continue;
- }
- String title = SErrorCodeEerverConfig.getI18NMessage("guildsacrifice_reward_title");
- String content = SErrorCodeEerverConfig.getI18NMessage("guildsacrifice_reward_txt");
- String mailReward = ItemUtil.getMailReward(itemArrs);
- int nowTime = (int) (now / 999);
- MailLogic.getInstance().sendMail(target.getId(), title, content, mailReward, nowTime, Global.MAIL_EFFECTIVE_TIME);
- }
- }
- guildInfo.reSetFete();
- guildInfo.setLastRefreshTime(now);
- SimpleTransaction transaction = SimpleTransaction.current();
- Set<Integer> sendUids = new HashSet<>();
- for (Set<Integer> items : guildInfo.getMembers().values()) {
- sendUids.addAll(items);
- }
- Lockeys.getLockeys().lock("guild", sendUids);
- guildInfo.clearGuildHelpLog();
- //统一清除
- for (Integer sendUid : sendUids) {
- User target = UserManager.getUser(sendUid);
- GuildLogic.sendGuildHelpRewardEmail(target);
- GuildMyInfo guildMyInfo = target.getGuildMyInfo();
- guildMyInfo.setGuidHelpInfo(new HashMap<>());
- guildMyInfo.setGuidHelpHadTakeInfo(new HashMap<>());
- guildMyInfo.setGuildHelpSendTime(0);
- guildMyInfo.setGuildHelpReward(false);
- guildMyInfo.setGuildHelpTime(0);
- }
- SimpleTransaction.remove();
- //处理公会援助信息
- //入库
- MongoUtil.getInstence().lastUpdate();
- } catch (Exception e) {
- LOGGER.error("Exception refreshAndTakeAllReward");
- }
- }
- void takeAllReward(User user) throws Exception {
- List<int[][]> itemArrs = new LinkedList<>();
- //补发前日未领取的祭祀奖
- Map<Integer, SGuildSacrificeRewardConfig> config = STableManager.getConfig(SGuildSacrificeRewardConfig.class);
- if (null == config) {
- throw new ErrorCodeException(ErrorCode.CFG_NULL);
- }
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- return;
- }
- //check 最近一次公会id
- if (user.getGuildMyInfo().getFeteguild() != guildId)
- return;
- Set<Integer> objects = new HashSet<>(config.keySet());
- objects.removeAll(user.getGuildMyInfo().getHadTakeReward());
- for (Integer missionId : objects) {
- //checkAndUpdate cfg
- SGuildSacrificeRewardConfig sGuildSacrificeRewardConfig = config.get(missionId);
- //take rewards checkAndUpdate
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- int fete = guildInfo.getFete();
- if (sGuildSacrificeRewardConfig.getScore() > fete) {
- continue;
- }
- //up miss
- int[][] reward = sGuildSacrificeRewardConfig.getReward();
- itemArrs.add(reward);
- }
- if (itemArrs.size() == 0)
- return;
- String title = SErrorCodeEerverConfig.getI18NMessage("guildsacrifice_reward_title");
- String content = SErrorCodeEerverConfig.getI18NMessage("guildsacrifice_reward_txt");
- String mailReward = ItemUtil.getMailReward(itemArrs);
- int nowTime = (int) (TimeUtils.now() / 1000);
- MailLogic.getInstance().sendMail(user.getId(), title, content, mailReward, nowTime, Global.MAIL_EFFECTIVE_TIME);
- }
- private static final Logger LOGGER = LoggerFactory.getLogger(GuildLogic.class);
- public static int getMemberType(int targetUid, Map<Integer, Set<Integer>> members) {
- for (Map.Entry<Integer, Set<Integer>> memberEntry : members.entrySet()) {
- Integer position = memberEntry.getKey();
- Set<Integer> value = memberEntry.getValue();
- if (value.contains(targetUid)) {
- return position;
- }
- }
- return GlobalsDef.MEMBER;
- }
- public static void getFamilyInfo(ISession session) throws Exception {
- int uid = session.getUid();
- int msgId = MessageTypeProto.MessageType.FAMILY_GET_INFO_RESPONSE_VALUE;
- User user = UserManager.getUser(uid);
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (0 == guildId) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NULL);
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- Family.GetFamilyInfoResponse.Builder builder = Family.GetFamilyInfoResponse.newBuilder()
- .setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo))
- .setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(user, getMemberType(uid, guildInfo.getMembers()))).setGuildBossId(GuildFightLogic.getCurSGuildBossConfig() == null ? 0 : GuildFightLogic.getCurSGuildBossConfig().getId());
- for (Set<Integer> members : guildInfo.getMembers().values()) {
- for (int uidOfMember : members) {
- User userMember = UserManager.getUser(uidOfMember);
- builder.addFamilyWalkIndicaiton(CBean2Proto.getFamilyWalkIndicaiton(userMember));
- }
- }
- // if (GuildFightLogic.carDelayProgressIndication != null) {
- // builder.setCarDelayProgressIndication(GuildFightLogic.carDelayProgressIndication);
- // if(GuildFightLogic.carDelayProgressIndication.getProgress() != user.getGuildMyInfo().getCarPlayProgress()){
- // user.getGuildMyInfo().setCarPlayTime(0);
- // user.getGuildMyInfo().setCarPlayProgress(GuildFightLogic.carDelayProgressIndication.getProgress());
- // }
- // }
- builder.setCarPlayTime(user.getGuildMyInfo().getCarPlayTime());
- MessageUtil.sendMessage(session, 1, msgId, builder.build(), true);
- }
- /**
- * 明斯克战役 需要跟工会分开
- *
- * @param session
- * @throws Exception
- */
- public static void getMinskWarProgressIndication(ISession session) throws Exception {
- int msgId = MessageTypeProto.MessageType.GET_CAR_CHALLENGE_INFO_RESPONSE.getNumber();
- Family.CarChallengeProgressIndication indication = GuildFightLogic.carChallengeProgressIndication;
- long totalHurt = 0L;
- String carDealyScoreKey = RedisUtil.getInstence().getKey(RedisKey.CAR_DEALY_SCORE, "");
- String totalHurtStr = (String) RedisUtil.getInstence().get(carDealyScoreKey);
- if (!StringUtil.isEmpty(totalHurtStr)) {
- totalHurt = Long.parseLong(totalHurtStr);
- }
- Family.CarChallengeProgressIndication cpi = Family.CarChallengeProgressIndication.newBuilder().
- setBossIndexId(indication.getBossIndexId()).
- setProgress(indication.getProgress()).
- setEndTime(indication.getEndTime()).
- setBattleStartTime(indication.getBattleStartTime()).
- setTotalHurt(totalHurt).
- build();
- MessageUtil.sendMessage(session, 1, msgId, cpi, true);
- }
- /**
- * 明斯克战役 我的信息
- *
- * @param session
- * @throws Exception
- */
- public static void getMinskWarMyInfo(ISession session) throws Exception {
- int msgId = MessageTypeProto.MessageType.GET_CAR_CHALLENGE_MY_INFO_RESPONSE.getNumber();
- //判断有没有参与
- User user = UserManager.getUser(session.getUid());
- initMinskWarBattleCount(user);
- PlayerManager playerManager = user.getPlayerInfoManager();
- MinskBattleCount minskBattleCount = playerManager.getMinskBattleCount();
- Family.CarChallengeMyInfo builder = Family.CarChallengeMyInfo.newBuilder().setBattleBuyCount(minskBattleCount.getHasBuyCount()).setBattleCount(minskBattleCount.getCount())
- .setBattleLastHurt(minskBattleCount.getLastHurt()).build();
- MessageUtil.sendMessage(session, 1, msgId, builder, true);
- }
- public static void initMinskWarBattleCount(User user) {
- PlayerManager playerManager = user.getPlayerInfoManager();
- if (playerManager.getStartMinskBattleFlag() == 0) {
- SWorldBossSetting sWorldBossSetting = STableManager.getConfig(SWorldBossSetting.class).get(1);
- int[] privilegge = sWorldBossSetting.getPrivilege();
- // SPrivilegeTypeConfig sPrivilegeTypeConfig = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(privilegge[0]);
- // int[][] buyCount = sPrivilegeTypeConfig.getCondition();
- int vigorTotalLimit = SPrivilegeTypeConfig.getConditionByVip(privilegge[0], user.getPlayerInfoManager().getVipLevel());
- MinskBattleCount minskBattleCount = playerManager.getMinskBattleCount();
- if (minskBattleCount == null) {
- minskBattleCount = new MinskBattleCount();
- }
- // minskBattleCount1.setCount(vigorTotalLimit);
- // minskBattleCount1.setHasBuyCount(0);
- // playerManager.setMinskBattleCount(minskBattleCount1);
- // } else {
- // minskBattleCount.setCount(vigorTotalLimit);
- // minskBattleCount.setHasBuyCount(0);
- // }
- minskBattleCount.setCount(vigorTotalLimit);
- minskBattleCount.setHasBuyCount(0);
- minskBattleCount.setLastHurt(0);
- playerManager.setMinskBattleCount(minskBattleCount);
- playerManager.setStartMinskBattleFlag(1);
- }
- }
- /**
- * 购买明斯克挑战次数
- * 购买 梦魇入侵 挑战次数
- * @param session
- * @throws Exception
- */
- public static void buyMinskBattleCount(ISession session) throws Exception {
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- initMinskWarBattleCount(user);
- MinskBattleCount minskBattleCount = user.getPlayerInfoManager().getMinskBattleCount();
- int nowCount = minskBattleCount.getCount();
- int hasBuyCount = minskBattleCount.getHasBuyCount();
- SWorldBossSetting sWorldBossSetting = STableManager.getConfig(SWorldBossSetting.class).get(1);
- int[] privilegge = sWorldBossSetting.getPrivilege();
- //SPrivilegeTypeConfig sPrivilegeTypeConfig = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(privilegge[1]);
- //int[][] buyCount = sPrivilegeTypeConfig.getCondition();
- int[][] buyPrice = sWorldBossSetting.getBuyPrice();
- int vigorTotalLimit = SPrivilegeTypeConfig.getConditionByVip(privilegge[0], user.getPlayerInfoManager().getVipLevel());
- if (hasBuyCount + 1 > vigorTotalLimit) {
- throw new ErrorCodeException(ErrorCode.MINSK_BATTLE_BUYCOUNT_ENOUGH);
- }
- int[] costItemNum = buyPrice[hasBuyCount];
- int[][] consumeMaterial = {{16, costItemNum[1]}};
- boolean enoughCost = ItemUtil.itemCost(user, consumeMaterial, BIReason.MINSK_BATTLE_COUNT, 1);
- if (!enoughCost) {
- throw new ErrorCodeException(ErrorCode.HERO_ITEM_NOT);
- }
- minskBattleCount.setCount(nowCount + 1);
- minskBattleCount.setHasBuyCount(hasBuyCount + 1);
- user.getPlayerInfoManager().setMinskBattleCount(minskBattleCount);
- Family.CarChallengeMyInfo builder = Family.CarChallengeMyInfo.newBuilder().setBattleBuyCount(minskBattleCount.getHasBuyCount()).setBattleCount(minskBattleCount.getCount()).build();
- MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.MINSK_BATTLE_BUYCOUNT_RESPONSE.getNumber(), builder, true);
- }
- /**
- * 创建公会
- *
- * @param session
- * @param familyName
- * @param announce 渠道Id,区分不同的语言版本,限制字符不同
- * @param channelId
- * @throws Exception
- */
- public static void createFamily(ISession session, String familyName, String announce,int channelId ) throws Exception {
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int msgId = MessageTypeProto.MessageType.FAMILY_CREATE_RESPONSE_VALUE;
- checkForCreateGuild(user, familyName, announce,channelId);
- boolean enough = ItemUtil.itemCost(user, SGuildSetting.sGuildSetting.getCreatCost(), BIReason.CREATE_GUILD_CONSUME, 0);
- if (!enough) {
- throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
- }
- if (user.getPlayerInfoManager().getGuildId() != 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_IN);
- }
- if (StringUtil.isEmpty(announce)) {
- announce = SGuildSetting.sGuildSetting.getDefaultDeclaration();
- }
- if (announce.length() == 0 || announce.length() > 32) {
- throw new ErrorCodeException(ErrorCode.ANNOUNCE_SIZE);
- }
- //设置加入公会时间
- user.getGuildMyInfo().setJoinTime(TimeUtils.nowInt());
- GuildInfo guildInfo = new GuildInfo(user.getId(), familyName, announce);
- GuilidManager.addGuildInfo(guildInfo);
- user.getPlayerInfoManager().setGuildId(guildInfo.getId());
- addGuildLog(guildInfo.getId(), GuildDef.Log.CREATE, user.getPlayerInfoManager().getNickName());
- RedisUtil.getInstence().putMapEntry(RedisKey.FAMILY_INFO, "", String.valueOf(guildInfo.getId()), new GuildCache(GameApplication.serverId, guildInfo.getIcon(), guildInfo.getLevel(), guildInfo.getName()));
- PlayerInfoCache cache = RedisUtil.getInstence().getMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(uid), PlayerInfoCache.class);
- cache.setGuildPosition(GlobalsDef.CHAIRMAN);
- RedisUtil.getInstence().putMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(uid), cache);
- user.getUserMissionManager().onGameEvent(user, GameEvent.JOIN_FAMILY);
- Family.FamilyCreateResponse build = Family.FamilyCreateResponse.newBuilder()
- .setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo))
- .setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(user, GlobalsDef.CHAIRMAN))
- .setFamilyWalkIndicaiton(CBean2Proto.getFamilyWalkIndicaiton(user))
- .build();
- Poster.getPoster().dispatchEvent(new GuildForceChangeEvent(user.getId(), user.getPlayerInfoManager().getGuildId(), 1, user.getPlayerInfoManager().getMaxForce()));
- //ReportUtil.onReportEvent(user, ReportEventEnum.CREATE_GUILD.getType(),String.valueOf(guildInfo.getId()),guildInfo.getName(),guildInfo.getLevel(),guildInfo.getTotalMembers());
- MessageUtil.sendMessage(session, 1, msgId, build, true);
- }
- public static void checkForCreateGuild(User user, String familyName, String announce,int channelId) throws Exception {
- // if(!Repot37EventUtil.Report37Chat(user, ChatContentType.FAMILY_NAME.getType(),announce)){
- // throw new ErrorCodeException(ErrorCode.FAMILY_IN_SENSITIVE);
- // }
- if(checkLeaveGuildCDing(user)){
- throw new ErrorCodeException(ErrorCode.LEAVE_GUILD_CD_ING);
- }
- if (StringUtil.isEmpty(familyName)) {
- throw new ErrorCodeException(ErrorCode.NULL_NAME);
- }
- if (!StringUtil.isEmpty(announce)) {
- if (!ShieldedWordUtils.checkName(user, familyName, false, ChatContentType.FAMILY_NAME) || !ShieldedWordUtils.checkName(user, announce, false, ChatContentType.FAMILY_NAME)) {
- throw new ErrorCodeException(ErrorCode.FAMILY_IN_SENSITIVE);
- }
- }
- if(channelId > 0){
- SMultiLanguage sMultiLanguage = SMultiLanguage.sMultiLanguageMap.get(channelId);
- int[] guildNameLimit = sMultiLanguage.getGuildNameLimit();
- if (familyName.length() > guildNameLimit[1] || familyName.length() < guildNameLimit[0]) {
- throw new ErrorCodeException(ErrorCode.NAME_LENGTH_ERROR); //名字长度为2-6个字
- }
- }else {
- if (familyName.length() < SGuildSetting.sGuildSetting.getNameSize()[0] || familyName.length() > SGuildSetting.sGuildSetting.getNameSize()[1]) {
- throw new ErrorCodeException(ErrorCode.NAME_LENGTH_ERROR);
- }
- }
- Map<Integer, GuildInfo> guildInfoMap = GuilidManager.guildInfoMap;
- for (Map.Entry<Integer, GuildInfo> entry : guildInfoMap.entrySet()) {
- if (entry.getValue().getName().equals(familyName)) {
- throw new ErrorCodeException(ErrorCode.EXIST_NAME);
- }
- }
- }
- /**
- * 推荐公会
- *
- * @param session
- * @throws Exception
- */
- public static void recommendFamily(ISession session) throws Exception {
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int msgId = MessageTypeProto.MessageType.FAMILY_RECOMEND_RESPONSE_VALUE;
- Collection<GuildInfo> guildInfos = GuilidManager.recommandGuild(user);
- Family.FamilyRecommandResponse.Builder builder = Family.FamilyRecommandResponse.newBuilder();
- Map<Integer, GuildApply> applyGuildInfos = GuilidManager.getApplyGuildInfos(uid, 1);
- int now = (int) (System.currentTimeMillis() / 1000);
- if (applyGuildInfos.size() > 0) {
- Iterator<Map.Entry<Integer, GuildApply>> iterator = applyGuildInfos.entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry<Integer, GuildApply> next = iterator.next();
- GuildApply guildApply = next.getValue();
- if (now - guildApply.getCreateTime() > SGuildSetting.sGuildSetting.getApplyReserve()) {
- GuilidManager.removeOneApplyGuildInfos(guildApply.getGuildId(), guildApply.getId());
- iterator.remove();
- }
- }
- }
- for (GuildInfo guildInfo : guildInfos) {
- builder.addFamilyRecomandInfo(Family.FamilyRecomandInfo.newBuilder().
- setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo))
- .setIsApply(applyGuildInfos.containsKey(guildInfo.getId()) ? 1 : 0)
- .build());
- }
- MessageUtil.sendMessage(session, 1, msgId, builder.build(), true);
- }
- /**
- * 搜素公会
- *
- * @param session
- * @param searchName
- * @throws Exception
- */
- public static void searchGuild(ISession session, String searchName) throws Exception {
- int msgId = MessageTypeProto.MessageType.FAMILY_SEARCH_RESPONSE_VALUE;
- if (StringUtil.isEmpty(searchName)) {
- throw new ErrorCodeException(ErrorCode.FAMILY_SEARCH_NULL);
- }
- GuildInfo guildInfo = GuilidManager.guildNameInfoMap.get(searchName);
- if (guildInfo == null) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NULL);
- }
- Map<Integer, GuildApply> applyGuildInfos = GuilidManager.getApplyGuildInfos(session.getUid(), 1);
- Family.FamilySeachResponse build = Family.FamilySeachResponse.newBuilder().addFamilyRecomandInfo(Family.FamilyRecomandInfo.newBuilder().
- setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo))
- .setIsApply(applyGuildInfos.containsKey(guildInfo.getId()) ? 1 : 0)
- .build()).build();
- MessageUtil.sendMessage(session, 1, msgId, build, true);
- }
- /**
- * 申请公会
- *
- * @param session
- * @param applyGuilds
- */
- public static void applyFamily(ISession session, List<Integer> applyGuilds) throws Exception {
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int msgId = MessageTypeProto.MessageType.FAMILY_APPLY_RESPONSE_VALUE;
- if (user.getPlayerInfoManager().getGuildId() != 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_IN);
- }
- if(checkLeaveGuildCDing(user)) {
- throw new ErrorCodeException(ErrorCode.LEAVE_GUILD_CD_ING);
- }
- Map<Integer, GuildApply> applyGuildPersonInfos = GuilidManager.getApplyGuildInfos(session.getUid(), 1);
- SGuildSetting guildSetting = SGuildSetting.sGuildSetting;
- if (applyGuildPersonInfos.size() >= guildSetting.getApplyLimit()) {
- throw new ErrorCodeException(ErrorCode.FAMILY_HAD_APPLY);
- }
- for (Integer applyGuildId : applyGuilds) {
- if (GuilidManager.guildInfoMap.get(applyGuildId).getJoinType() != 0 && applyGuilds.size() == 0) {
- if (applyGuilds.size() > 1) {
- throw new ErrorCodeException(ErrorCode.FAMILY_LIMIT_CHANGED);
- }
- continue;
- }
- GuildApply guildApply = new GuildApply(uid, applyGuildId);
- Map<Integer, GuildApply> applyGuildFamilyInfos = GuilidManager.getApplyGuildInfos(applyGuildId, 0);
- if (applyGuildFamilyInfos.size() >= guildSetting.getBeApplyLimit()) {
- if (applyGuilds.size() > 1) {
- throw new ErrorCodeException(ErrorCode.FAMILY_APPLY_LIMIT);
- }
- continue;
- }
- GuilidManager.addApplyGuildInfo(guildApply);
- Map<Integer, Set<Integer>> members = GuilidManager.guildInfoMap.get(applyGuildId).getMembers();
- for (Map.Entry<Integer, Set<Integer>> entry : members.entrySet()) {
- if (entry.getValue().size() < 1) {
- continue;
- }
- if (entry.getKey() == 3) {
- continue;
- }
- for (Integer sendUid : entry.getValue()) {
- MessageUtil.sendRedIndication(sendUid, GlobalsDef.GUILD_APPLY_TYPE);
- }
- }
- }
- MessageUtil.sendMessage(session, 1, msgId, null, true);
- }
- /**
- * 加入公会
- *
- * @param session
- * @param guildId
- * @throws Exception
- */
- public static void joinGuild(ISession session, int guildId) throws Exception {
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int msgId = MessageTypeProto.MessageType.FAMILY_JOIN_RESPONSE_VALUE;
- if (user.getPlayerInfoManager().getGuildId() != 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_IN);
- }
- if(checkLeaveGuildCDing(user)){
- throw new ErrorCodeException(ErrorCode.LEAVE_GUILD_CD_ING);
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- if (guildInfo == null) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NULL);
- }
- if (guildInfo.getJoinType() != 1) {
- throw new ErrorCodeException(ErrorCode.FAMILY_LIMIT_CHANGED);
- }
- if (user.getPlayerInfoManager().getLevel() < guildInfo.getIntoLevel()) {
- throw new ErrorCodeException(ErrorCode.FAMILY_LIMIT);
- }
- //todo 判读人数是否已达上限
- if (guildInfo.getTotalMembers() >= STableManager.getConfig(SGuildLevelConfig.class).get(guildInfo.getLevel()).getNum()) {
- throw new ErrorCodeException(ErrorCode.FAMILY_MAX);
- }
- boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.OPERATE_FAMILY, Integer.toString(guildId), Integer.toString(uid), 500);
- if (!isSuccess) {
- throw new ErrorCodeException(ErrorCode.FAMILY_DO_AGAIN);
- }
- try {
- applyToJoin(guildInfo, uid, false);
- } finally {
- RedisUtil.getInstence().releaseDistributedLock(RedisKey.OPERATE_FAMILY, Integer.toString(guildId), Integer.toString(uid));
- }
- //设置加入公会时间
- user.getGuildMyInfo().setJoinTime(TimeUtils.nowInt());
- RedisUtil.getInstence().expire(RedisKey.getKey(RedisKey.FAMILY_JOIN, String.valueOf(uid), false), TimeUtils.DAY);
- addGuildLog(guildInfo.getId(), GuildDef.Log.JOIN, user.getPlayerInfoManager().getNickName());
- //社稷大典需要初始化分数
- Set<Integer> openActivityIdsByType = ActivityLogic.getInstance().getOpenActivityIdsByType(user, ActivityTypeEnum.SHEJI_ACTIVITY.getType(), false);
- Poster.getPoster().dispatchEvent(new CommitSheJiEvent(guildId, uid, 0, 0, 0, openActivityIdsByType));
- Family.FamilyJoinIndicaion build = Family.FamilyJoinIndicaion.newBuilder().setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo)).setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(user, GlobalsDef.MEMBER)).build();
- Family.FamilyJoinResponse response = Family.FamilyJoinResponse.newBuilder().setFamilyJoinIndicaion(build).build();
- MessageUtil.sendMessage(session, 1, msgId, response, true);
- }
- /**
- * 获取公会日志信息
- *
- * @param session
- * @throws Exception
- */
- public static void getGuildLogInfo(ISession session) throws Exception {
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int msgId = MessageTypeProto.MessageType.FAMILY_GET_LOG_RESPOSNE_VALUE;
- if (user.getPlayerInfoManager().getGuildId() == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- Family.GetFamilyLogResponse.Builder builder = Family.GetFamilyLogResponse.newBuilder();
- List<GuildLog> guildLogs = GuilidManager.guildLogInfoMap.get(user.getPlayerInfoManager().getGuildId());
- if (guildLogs != null) {
- Family.FamilyLogInfo.Builder familyLogInfo;
- for (GuildLog guildLog : guildLogs) {
- familyLogInfo = Family.FamilyLogInfo.newBuilder();
- familyLogInfo.setInfo(guildLog.getInfo());
- familyLogInfo.setName(guildLog.getName());
- familyLogInfo.setTime(guildLog.getLogTime());
- if (guildLog.getGuildParam() != null && guildLog.getGuildParam().size() > 0) {
- familyLogInfo.addAllGuildparam(guildLog.getGuildParam());
- }
- builder.addFamilyLogInfo(familyLogInfo.build());
- }
- }
- MessageUtil.sendMessage(session, 1, msgId, builder.build(), true);
- }
- /**
- * 获取公会成员信息
- *
- * @param session
- */
- public static void getGuildMemberInfo(ISession session) throws Exception {
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int msgId = MessageTypeProto.MessageType.FAMILY_GET_MEMBER_RESPOSNE_VALUE;
- if (user.getPlayerInfoManager().getGuildId() == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(user.getPlayerInfoManager().getGuildId());
- Family.GetFamilyMemberInfoResponse.Builder builder = Family.GetFamilyMemberInfoResponse.newBuilder();
- Map<Integer, Set<Integer>> members = guildInfo.getMembers();
- for (Map.Entry<Integer, Set<Integer>> memberEntry : members.entrySet()) {
- Integer position = memberEntry.getKey();
- Set<Integer> value = memberEntry.getValue();
- for (Integer uidTmp : value) {
- LOGGER.info("uidTmp={}",uidTmp);
- if(uidTmp != null) {
- User userTmp = UserManager.getUser(uidTmp);
- LOGGER.info("userTmp={}", userTmp);
- if (userTmp != null) {
- builder.addFamilyUserInfo(CBean2Proto.getFamilyUserInfo(userTmp, position));
- }
- }
- }
- }
- MessageUtil.sendMessage(session, 1, msgId, builder.build(), true);
- }
- /**
- * 获取申请列表信息
- *
- * @param session
- */
- public static void getGuildApplyInfo(ISession session) throws Exception {
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int msgId = MessageTypeProto.MessageType.FAMILY_GET_APPLY_RESPOSNE_VALUE;
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- Map<Integer, GuildApply> applyGuildInfos = GuilidManager.getApplyGuildInfos(guildId, 0);
- List<GuildApply> guildApplies = new ArrayList<>();
- int now = (int) (System.currentTimeMillis() / 1000);
- for (GuildApply guildApply : applyGuildInfos.values()) {
- if (now - guildApply.getCreateTime() > SGuildSetting.sGuildSetting.getApplyReserve()) {
- GuilidManager.removeOneApplyGuildInfos(guildApply.getGuildId(), guildApply.getId());
- continue;
- }
- int id = guildApply.getId();
- User userApply = UserManager.getUser(id);
- if (userApply.getPlayerInfoManager().getGuildId() != 0) {
- GuilidManager.removeOneApplyGuildInfos(guildId, id);
- continue;
- }
- guildApplies.add(guildApply);
- }
- Collections.sort(guildApplies);
- Family.GetFamilyApplyResponse.Builder builder = Family.GetFamilyApplyResponse.newBuilder();
- for (GuildApply guildApply : guildApplies) {
- User userTmp = UserManager.getUser(guildApply.getId());
- builder.addFamilyApply(CBean2Proto.getFamilyApplyInfo(userTmp, guildApply.getCreateTime())).build();
- }
- user.getPlayerInfoManager().removeRed(GlobalsDef.GUILD_APPLY_TYPE);
- MessageUtil.sendMessage(session, 1, msgId, builder.build(), true);
- }
- /**
- * 操作申请列表
- *
- * @param session
- * @param type
- * @param applyId
- * @throws Exception
- */
- public static void operationApplyList(ISession session, int type, int applyId) throws Exception {
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int guildId = user.getPlayerInfoManager().getGuildId();
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- int msgId = MessageTypeProto.MessageType.FAMILY_OPERATION_APPLY_LIST_RESPONSE_VALUE;
- if (getMemberType(uid, guildInfo.getMembers()) >= GlobalsDef.MEMBER) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
- }
- if (guildId == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.OPERATE_FAMILY_APPLY, Integer.toString(guildId), Integer.toString(uid), 500);
- if (!isSuccess) {
- throw new ErrorCodeException(ErrorCode.FAMILY_DO_AGAIN);
- }
- // if(GuildFightLogic.getStatus()!=0&&(type==1||type==3)){
- // throw new ErrorCodeException(ErrorCode.FAMILY_NO_APPLY_IN_WAR);
- // }
- try {
- Map<Integer, GuildApply> applyGuild = GuilidManager.getApplyGuildInfos(guildId, 0);
- switch (type) {
- case 1: //全部同意
- Map<Integer, Set<Integer>> members = guildInfo.getMembers();
- int count = 0;
- for (Set<Integer> memberOfType : members.values()) {
- count += memberOfType.size();
- }
- if (guildInfo.getTotalMembers() + applyGuild.size() > STableManager.getConfig(SGuildLevelConfig.class).get(guildInfo.getLevel()).getNum()) {
- throw new ErrorCodeException(ErrorCode.FAMILY_MAXFULL);
- }
- boolean memberGuild = false;
- for (Integer addUid : applyGuild.keySet()) {
- if (UserManager.getUser(addUid).getPlayerInfoManager().getGuildId() != 0) {
- memberGuild = true;
- continue;
- }
- if (30 - count <= 0) {
- break;
- }
- applyToJoin(guildInfo, addUid, true);
- count++;
- }
- if (memberGuild) {
- throw new ErrorCodeException(ErrorCode.FAMILY_SOMEONE_QUIT);
- }
- for (Map.Entry<Integer, GuildApply> entry : applyGuild.entrySet()) {
- GuilidManager.removeOneApplyGuildInfos(entry.getValue().getGuildId(), entry.getValue().getId());
- Map<Integer, GuildApply> applyPersonal = GuilidManager.getApplyGuildInfos(entry.getValue().getId(), 1);
- for (Map.Entry<Integer, GuildApply> personalEntry : applyPersonal.entrySet()) {
- GuilidManager.removeOneApplyGuildInfos(personalEntry.getValue().getGuildId(), personalEntry.getValue().getId());
- }
- }
- break;
- case 2: //全部拒绝
- Family.RefuseJoinFamily refuse = Family.RefuseJoinFamily.newBuilder().setName(guildInfo.getName()).build();
- for (Map.Entry<Integer, GuildApply> entry : applyGuild.entrySet()) {
- if (OnlineUserManager.checkUidOnline(applyId)) {
- MessageUtil.sendIndicationMessage(OnlineUserManager.getSessionByUid(applyId), 1, MessageTypeProto.MessageType.FAMILY_REFUSE_JOIN_INDICATION_VALUE, refuse, true);
- }
- GuilidManager.removeOneApplyGuildInfos(entry.getValue().getGuildId(), entry.getValue().getId());
- }
- break;
- case 3: //同意一个
- if (UserManager.getUser(applyId).getPlayerInfoManager().getGuildId() != 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_SOMEONE_QUIT);
- }
- if (guildInfo.getTotalMembers() >= STableManager.getConfig(SGuildLevelConfig.class).get(guildInfo.getLevel()).getNum()) {
- throw new ErrorCodeException(ErrorCode.FAMILY_MAX);
- }
- applyToJoin(guildInfo, applyId, true);
- Map<Integer, GuildApply> applyPersonal = GuilidManager.getApplyGuildInfos(applyId, 1);
- for (Map.Entry<Integer, GuildApply> personalEntry : applyPersonal.entrySet()) {
- GuilidManager.removeOneApplyGuildInfos(personalEntry.getValue().getGuildId(), personalEntry.getValue().getId());
- }
- break;
- case 4: //拒绝一个
- GuilidManager.removeOneApplyGuildInfos(guildId, applyId);
- Family.RefuseJoinFamily refuseName = Family.RefuseJoinFamily.newBuilder().setName(guildInfo.getName()).build();
- ISession targetSession = OnlineUserManager.getSessionByUid(applyId);
- if (null != targetSession) {
- MessageUtil.sendIndicationMessage(targetSession, 1, MessageTypeProto.MessageType.FAMILY_REFUSE_JOIN_INDICATION_VALUE, refuseName, true);
- }
- break;
- }
- } finally {
- RedisUtil.getInstence().releaseDistributedLock(RedisKey.OPERATE_FAMILY_APPLY, Integer.toString(guildId), Integer.toString(uid));
- }
- MessageUtil.sendMessage(session, 1, msgId, null, true);
- }
- private static void applyToJoin(GuildInfo guildInfo, int applyId, boolean isApply) throws Exception {
- boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.OPERATE_FAMILY_APPLY_JOIN, Integer.toString(applyId), Integer.toString(applyId), 500);
- if (!isSuccess) {
- return;
- }
- User targetUser = UserManager.getUser(applyId);
- try {
- if (targetUser.getPlayerInfoManager().getGuildId() != 0) {
- return;
- }
- if(checkLeaveGuildCDing(targetUser)) {
- return;
- }
- GuilidManager.removeOneApplyGuildInfos(guildInfo.getId(), applyId);
- guildInfo.addMembers(GlobalsDef.MEMBER, applyId);
- targetUser.getPlayerInfoManager().setGuildId(guildInfo.getId());
- MessageUtil.sendIndicationMessage(targetUser.getId(), Family.FamilyFeteRewardProcessIndication.newBuilder().setScore(guildInfo.getFete()).build());
- PlayerInfoCache cache = RedisUtil.getInstence().getMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(applyId), PlayerInfoCache.class);
- cache.setGuildPosition(GlobalsDef.MEMBER);
- RedisUtil.getInstence().putMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(applyId), cache);
- AyyncWorker ayyncWorker = new AyyncWorker(targetUser, true, new AynMissionWorker(GameEvent.JOIN_FAMILY));
- ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
- RedisUtil.getInstence().removeMapEntrys(RedisKey.USER_LEVEL_GUILD_INFO, "", String.valueOf(applyId));
- Poster.getPoster().dispatchEvent(new GuildForceChangeEvent(targetUser.getId(), targetUser.getPlayerInfoManager().getGuildId(), 1, targetUser.getPlayerInfoManager().getMaxForce()));
- Family.GuildHelpInfoIndication.Builder builder = Family.GuildHelpInfoIndication.newBuilder();
- for (Map.Entry<Integer, Integer> entry : targetUser.getGuildMyInfo().getGuidHelpInfo().entrySet()) {
- builder.addGuildHelpInfo(CommonProto.GuildHelpInfo.newBuilder()
- .setHadtakenum(targetUser.getGuildMyInfo().getGuidHelpHadTakeInfo().getOrDefault(entry.getKey(), 0))
- .setType(entry.getKey())
- .setNum(entry.getValue()));
- }
- //notify all change
- Family.GuildHelpInfoIndication build = builder.setUid(targetUser.getId()).setName(targetUser.getPlayerInfoManager().getNickName()).build();
- GuildLogic.sendIndicationToMember(GuilidManager.guildInfoMap.get(guildInfo.getId()), MessageTypeProto.MessageType.GuildHelpInfoIndication, build);
- // targetUser.getUserMissionManager().onGameEvent(targetUser, GameEvent.JOIN_FAMILY);
- } finally {
- RedisUtil.getInstence().releaseDistributedLock(RedisKey.OPERATE_FAMILY_APPLY_JOIN, Integer.toString(applyId), Integer.toString(applyId));
- }
- if (isApply) {
- Family.FamilyJoinIndicaion.Builder builder = Family.FamilyJoinIndicaion.newBuilder();
- Family.FamilyJoinIndicaion build = builder.setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo)).setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(targetUser, GlobalsDef.MEMBER)).build();
- sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_JOIN_INDICATION, build);
- }
- //设置加入公会时间
- targetUser.getGuildMyInfo().setJoinTime(TimeUtils.nowInt());
- //ReportUtil.onReportEvent(targetUser, ReportEventEnum.JOIN_GUILD.getType(),String.valueOf(guildInfo.getId()),guildInfo.getName(),guildInfo.getLevel(),guildInfo.getTotalMembers());
- }
- /**
- * 踢人出宗门
- *
- * @param session
- * @param targetUid
- */
- public static void kickOutGuild(ISession session, int targetUid) throws Exception {
- int uid = session.getUid();
- int msgId = MessageTypeProto.MessageType.FAMILY_KICK_OUT_RESPONSE_VALUE;
- if (uid == targetUid) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NOT_SELF);
- }
- User user = UserManager.getUser(uid);
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- int uidType = getMemberType(uid, guildInfo.getMembers());
- int targetType = getMemberType(targetUid, guildInfo.getMembers());
- if (uidType > targetType) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
- }
- if (GuildFightLogic.getStatus() != 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NOT_KICK_IN_WAR);
- }
- User targetUser = UserManager.getUser(targetUid);
- //TODO lock check
- OnUserLeveFamily(targetUser);
- Family.KickOutIndication kickIndication = Family.KickOutIndication.newBuilder().setUid(targetUid).build();
- sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_KICK_INDICATION, kickIndication);
- boolean remove = guildInfo.removeMember(targetType, targetUid);
- if (!remove) {
- throw new ErrorCodeException(ErrorCode.FAMILY_HAD_KICK);
- }
- //如果有防守信息则删除
- if (guildInfo.getDefendInfo().containsKey((targetUid))) {
- guildInfo.removeDefendInfo(targetUid);
- }
- targetUser.getPlayerInfoManager().setGuildId(0);
- targetUser.getGuildMyInfo().clearOfLevelGuild();
- addGuildLog(guildInfo.getId(), GuildDef.Log.KICK, targetUser.getPlayerInfoManager().getNickName());
- // Family.FamilyKickIndication build = Family.FamilyKickIndication.newBuilder().setType(1).build();
- // ISession targetSession = OnlineUserManager.getSessionByUid(targetUid);
- // if(targetSession!=null){
- //// MessageUtil.sendIndicationMessage(targetSession,1, MessageTypeProto.MessageType.FAMILY_KICK_INDICATION_VALUE,build,true);
- // }
- String title = SErrorCodeEerverConfig.getI18NMessage("family_kick_title");
- List<String> content = SErrorCodeEerverConfig.getI18NMessageNew("family_kick_txt", new Object[]{guildInfo.getName()});
- MailLogic.getInstance().sendMail(targetUid, title, content, "", (int) (TimeUtils.now() / 1000), Global.MAIL_EFFECTIVE_TIME);
- MessageUtil.sendMessage(session, 1, msgId, null, true);
- }
- /**
- * 任命
- *
- * @param session
- * @param targetUid
- * @param position
- */
- public static void appointMent(ISession session, int targetUid, int position) throws Exception {
- int msgId = MessageTypeProto.MessageType.FAMILY_APPOINTMENT_RESPONSE_VALUE;
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- int uidType = getMemberType(uid, guildInfo.getMembers());
- int targetType = getMemberType(targetUid, guildInfo.getMembers());
- if (uidType > 1 || uidType > targetType) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
- }
- if (GuildFightLogic.getStatus() != 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_APPOINT_NOT_IN_WAR);
- }
- if (position == 2) {
- if (guildInfo.getMembers().get(2) != null && guildInfo.getMembers().get(2).size() >= STableManager.getConfig(SGuildLevelConfig.class).get(guildInfo.getLevel()).getOfficalNum()) {
- throw new ErrorCodeException(ErrorCode.FAMILY_LEADER_MAX);
- }
- }
- guildInfo.removeMember(targetType, targetUid);
- guildInfo.addMembers(position, targetUid);
- // PlayerInfoCache cache = RedisUtil.getInstence().getMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(uid), PlayerInfoCache.class);
- // cache.setGuildPosition(position);
- // RedisUtil.getInstence().putMapEntry(RedisKey.PLAYER_INFO_CACHE,"",String.valueOf(uid),cache);
- PlayerLogic.getInstance().playerInfoUpdate(UserManager.getUser(targetUid));
- sendPositionChange(targetUid, position);
- User targetUser = UserManager.getUser(targetUid);
- if (position == GlobalsDef.CHAIRMAN) {
- guildInfo.removeMember(GlobalsDef.CHAIRMAN, uid);
- PlayerLogic.getInstance().playerInfoUpdate(user);
- guildInfo.addMembers(GlobalsDef.MEMBER, uid);
- sendPositionChange(uid, GlobalsDef.CHAIRMAN_TO_MENBER);
- addGuildLog(guildInfo.getId(), GuildDef.Log.TRANSFER, targetUser.getPlayerInfoManager().getNickName());
- } else {
- addGuildLog(guildInfo.getId(), GuildDef.Log.APPOINTMENT, targetUser.getPlayerInfoManager().getNickName());
- }
- MessageUtil.sendMessage(session, 1, msgId, null, true);
- }
- /**
- * 解散公会
- * type 操作类型 1 :解散公会 2 : 取消解散公会
- * @param session
- */
- public static void dissolution(ISession session, int type) throws Exception {
- int msgId = MessageTypeProto.MessageType.FAMILY_DISSOLUTION_RESPONSE_VALUE;
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- int uidType = getMemberType(uid, guildInfo.getMembers());
- if (uidType != 1) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
- }
- if (type == 1 && guildInfo.getLevelTime() > 0) {
- throw new ErrorCodeException(ErrorCode.ALREADY_OPERATED);
- }
- if (type == 1 && GuildFightLogic.getStatus() != 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_DESTROY_IN_WAR);
- }
- //解散公会
- if (type == 1) {
- guildInfo.setLevelTime((int) (System.currentTimeMillis() / 1000));
- } else {
- guildInfo.setLevelTime(0);
- }
- sendFamilyBaseUpdateIndication(guildInfo); //公会信息变更推送
- GuilidManager.addGuildToRelease(guildInfo); //公会解散信息:删除和增加解散信息
- MessageUtil.sendMessage(session, 1, msgId, null, true);
- }
- /**
- * 修改公会名,修改公会宣言
- *
- * @param session
- * @param content
- * @param channelId 渠道Id,区分不同的语言版本,限制字符不同
- */
- public static void changeNotice(ISession session, int type, String content,int channelId) throws Exception {
- int msgId = MessageTypeProto.MessageType.FAMILY_CHANGE_NOTICE_RESPONSE_VALUE;
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- int uidType = getMemberType(uid, guildInfo.getMembers());
- if (uidType > 2) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
- }
- // if(!Repot37EventUtil.Report37Chat(user, ChatContentType.ANNOUNCE.getType(),content)){
- // throw new ErrorCodeException(ErrorCode.FAMILY_IN_SENSITIVE);
- // }
- boolean result = ShieldedWordUtils.checkName(user, content, false, ChatContentType.ANNOUNCE);
- int resultCode = 1;
- String err = "修改成功";
- if (!result) {
- err = "包含铭感字";
- resultCode = 0;
- }
- sendFamilyBaseUpdateIndication(guildInfo);
- Family.FamilyChangeResponse response = Family.FamilyChangeResponse.newBuilder().setErr(err).setResult(resultCode).build();
- if (resultCode == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_IN_SENSITIVE);
- } else {
- if (type == 1) {
- if (content.length() < 0 || content.length() > 32) {
- throw new ErrorCodeException(ErrorCode.ANNOUNCE_SIZE);
- }
- guildInfo.setAnnounce(content);
- } else {
- String oldName=guildInfo.getName();
- checkForCreateGuild(user, content, guildInfo.getAnnounce(),channelId);
- int[][] renameCost = SGuildSetting.sGuildSetting.getRenameCost();
- boolean b = ItemUtil.itemCost(user, renameCost, BIReason.FAMILY_RENAME, 1);
- if (!b) {
- throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
- }
- guildInfo.setName(content);
- GuilidManager.changeGuildInfo(guildInfo,oldName);
- addGuildLog(guildInfo.getId(), GuildDef.Log.CNAME, user.getPlayerInfoManager().getNickName(),content);
- }
- MessageUtil.sendMessage(session, resultCode, msgId, response, true);
- }
- }
- /**
- * 修改公会加入类型
- *
- * @param session
- * @param joinType
- * @throws Exception
- */
- public static void changeJoinType(ISession session, int joinType, int joinLevel) throws Exception {
- int msgId = MessageTypeProto.MessageType.FAMILY_CHANGE_JOIN_TYPE_RESPONSE_VALUE;
- if (joinType <= 0 || joinType > 3) {
- throw new ErrorCodeException(ErrorCode.PARAM_ERR);
- }
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- int uidType = getMemberType(uid, guildInfo.getMembers());
- if (uidType > 2) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
- }
- guildInfo.updateIntoLevel(joinLevel);
- guildInfo.setJoinType(joinType);
- sendFamilyBaseUpdateIndication(guildInfo);
- MessageUtil.sendMessage(session, 1, msgId, null, true);
- }
- public static void releaseGuild(GuildInfo guildInfo) throws Exception {
- Map<Integer, Set<Integer>> members = guildInfo.getMembers();
- Family.KickOutIndication build = Family.KickOutIndication.newBuilder().build();
- String title = SErrorCodeEerverConfig.getI18NMessage("guild_breakup_title");
- Set<Integer> chairmans = guildInfo.getMembers().get(GlobalsDef.CHAIRMAN);
- Integer chairmanUid = chairmans.iterator().next();
- User chairmanUser = UserManager.getUser(chairmanUid);
- List<String> content = SErrorCodeEerverConfig.getI18NMessageNew("guild_breakup_txt", new String[]{guildInfo.getName(), chairmanUser.getPlayerInfoManager().getNickName()});
- for (Set<Integer> items : members.values()) {
- for (Integer sendUid : items) {
- ISession session = OnlineUserManager.getSessionByUid(sendUid);
- if (session != null) {
- MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.FAMILY_KICK_INDICATION_VALUE, build, true);
- }
- User user = UserManager.getUser(sendUid);
- //TODO lock check
- OnUserLeveFamily(user);
- user.getPlayerInfoManager().setGuildId(0);
- MailLogic.getInstance().sendMail(user.getId(), title, content, "", (int) (System.currentTimeMillis() / 1000), Global.MAIL_EFFECTIVE_TIME);
- }
- }
- GuilidManager.removeGuildInfo(guildInfo);
- MongoUtil.getInstence().lastUpdate();
- }
- public static void chairmanChange(ISession session, int targetUid) throws Exception {
- int msgId = MessageTypeProto.MessageType.FAMILY_TRANSFER_CHAIRMAN_RESPONSE_VALUE;
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- int uidType = getMemberType(uid, guildInfo.getMembers());
- if (uidType > 1) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
- }
- guildInfo.removeMember(GlobalsDef.CHAIRMAN, uid);
- guildInfo.addMembers(GlobalsDef.MEMBER, uid);
- guildInfo.addMembers(GlobalsDef.CHAIRMAN, targetUid);
- sendPositionChange(uid, GlobalsDef.MEMBER);
- sendPositionChange(targetUid, GlobalsDef.CHAIRMAN);
- MessageUtil.sendMessage(session, 1, msgId, null, true);
- }
- public static void levelFamily(ISession session) throws Exception {
- int msgId = MessageTypeProto.MessageType.FAMILY_LEVEL_RESPONSE_VALUE;
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- int uidType = getMemberType(uid, guildInfo.getMembers());
- if (uidType == GlobalsDef.CHAIRMAN) {
- throw new ErrorCodeException(ErrorCode.FAMILY_LEADER_QUIT_ERR);
- }
- if (guildInfo.getDefendInfo().containsKey((uid))) {
- guildInfo.removeDefendInfo(uid);
- }
- //TODO lock check
- OnUserLeveFamily(user);
- user.getPlayerInfoManager().setLeaveGuildTime(System.currentTimeMillis());
- PlayerInfoCache cache = RedisUtil.getInstence().getMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(uid), PlayerInfoCache.class);
- cache.setGuildPosition(0);
- RedisUtil.getInstence().putMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(uid), cache);
- guildInfo.removeMember(uidType, uid);
- user.getPlayerInfoManager().setGuildId(0);
- user.getGuildMyInfo().clearOfLevelGuild();
- addGuildLog(guildInfo.getId(), GuildDef.Log.LEVEL, user.getPlayerInfoManager().getNickName());
- Family.FamilyLeaveResponse builder = Family.FamilyLeaveResponse.newBuilder().setLeaveTime(user.getPlayerInfoManager().getLeaveGuildTime()/1000).build();
- MessageUtil.sendMessage(session, 1, msgId, builder, true);
- }
- public static void sendPositionChange(int uid, int position) throws Exception {
- String title = "";
- String content = "";
- //给玩家发邮件
- switch (position) {
- case 1:
- title = SErrorCodeEerverConfig.getI18NMessage("family_leader_title");
- content = SErrorCodeEerverConfig.getI18NMessage("family_leader_txt");
- break;
- case 2:
- title = SErrorCodeEerverConfig.getI18NMessage("family_position_title");
- content = SErrorCodeEerverConfig.getI18NMessage("family_position_txt");
- break;
- case 3:
- title = SErrorCodeEerverConfig.getI18NMessage("family_relieve_title");
- content = SErrorCodeEerverConfig.getI18NMessage("family_relieve_txt");
- break;
- case 4:
- title = SErrorCodeEerverConfig.getI18NMessage("family_relieved_leader_title");
- content = SErrorCodeEerverConfig.getI18NMessage("family_relieved_leader_txt");
- position = 3;
- break;
- default:
- break;
- }
- if (StringUtil.isEmpty(title) || StringUtil.isEmpty(content)) {
- return;
- }
- MailLogic.getInstance().sendMail(uid, title, content, "", (int) (TimeUtils.now() / 1000), Global.MAIL_EFFECTIVE_TIME);
- Family.FamilyPositionUpdateIndication build = Family.FamilyPositionUpdateIndication.newBuilder().setPosition(position).setUid(uid).build();
- User userInMem = UserManager.getUserInMem(uid);
- sendIndicationToMember(GuilidManager.guildInfoMap.get(userInMem.getPlayerInfoManager().getGuildId()), MessageTypeProto.MessageType.FAMILY_POSITION_UPDATE_INDICAITON, build);
- }
- public static void sendFamilyBaseUpdateIndication(GuildInfo guildInfo) {
- CommonProto.FamilyBaseInfo familyBaseInfo = CBean2Proto.getFamilyBaseInfo(guildInfo);
- Family.FamilyChangeIndication build = Family.FamilyChangeIndication.newBuilder().setFamilyBaseInfo(familyBaseInfo).build();
- sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_CHANGE_BASE_INDICATION, build);
- }
- public static void sendFamilyJoinIndication(int uid, GuildInfo guildInfo) throws Exception {
- ISession session = OnlineUserManager.getSessionByUid(uid);
- if (session != null) {
- User user = UserManager.getUser(uid);
- Family.FamilyJoinIndicaion.Builder builder = Family.FamilyJoinIndicaion.newBuilder();
- Family.FamilyJoinIndicaion build = builder.setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo)).setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(user, GlobalsDef.MEMBER)).build();
- MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.FAMILY_JOIN_INDICATION_VALUE, build, true);
- }
- }
- public static void walkInGuildScene(ISession session, List<Integer> path) throws Exception {
- int msgId = MessageTypeProto.MessageType.FAMILY_WALK_RESPONSE_VALUE;
- int uid = session.getUid();
- User user = UserManager.getUser(uid);
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NO);
- }
- user.getGuildMyInfo().move(System.currentTimeMillis());
- GuildMyInfo guildMyInfo = user.getGuildMyInfo();
- LOGGER.info("cur ={},path={}", guildMyInfo.getCurPos(), path);
- /* boolean continuous = CellUtil.isContinuous(guildMyInfo.getCurPos(),path);
- if(!continuous){
- LOGGER.info("the uid={},path is wrong",uid);
- MessageUtil.sendMessage(session,1, msgId,null,true);
- return;
- }*/
- user.getGuildMyInfo().move(path);
- Family.FamilyWalkIndicaiton familyWalkIndicaiton = CBean2Proto.getFamilyWalkIndicaiton(user);
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_WALK_INDICATION, familyWalkIndicaiton);
- MessageUtil.sendMessage(session, 1, msgId, null, true);
- }
- public static void updateMyPos(User user) {
- int guildId = user.getPlayerInfoManager().getGuildId();
- if (guildId == 0) {
- return;
- }
- user.getGuildMyInfo().move(new ArrayList<>());
- Family.FamilyWalkIndicaiton familyWalkIndicaiton = CBean2Proto.getFamilyWalkIndicaiton(user);
- GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
- sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_WALK_INDICATION, familyWalkIndicaiton);
- }
- public static void addGuildLog(int guildId, int type, String name,String... params) throws Exception {
- switch (type) {
- case GuildDef.Log.CREATE: {
- // 宗门创立
- GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logCreate", new Object[]{name}));
- GuilidManager.addGuildLog(cGuildLog);
- break;
- }
- case GuildDef.Log.JOIN: {
- // 加入宗门
- GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logJoin", new Object[]{name}));
- GuilidManager.addGuildLog(cGuildLog);
- break;
- }
- case GuildDef.Log.KICK: {
- // 退出宗门
- GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logKick", new Object[]{name}));
- GuilidManager.addGuildLog(cGuildLog);
- break;
- }
- case GuildDef.Log.TRANSFER: {
- // 宗门转让
- GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logTransfer", new Object[]{name}));
- GuilidManager.addGuildLog(cGuildLog);
- break;
- }
- case GuildDef.Log.APPOINTMENT: {
- // 宗门任免
- GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logAppointment", new Object[]{name}));
- GuilidManager.addGuildLog(cGuildLog);
- break;
- }
- case GuildDef.Log.LEVEL: {
- // 宗门退出
- GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logLevel", new Object[]{name}));
- GuilidManager.addGuildLog(cGuildLog);
- break;
- }
- case GuildDef.Log.CNAME: {
- // 宗门退出
- GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.changename", new Object[]{name,params[0]}));
- GuilidManager.addGuildLog(cGuildLog);
- break;
- }
- case GuildDef.Log.IMPEACH: {
- // 会长弹劾
- GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logImpeach", new Object[]{name}));
- GuilidManager.addGuildLog(cGuildLog);
- break;
- }
- default: {
- break;
- }
- }
- }
- /**
- * 给公会所有在线成员发送indication
- *
- * @param guildInfo
- * @param messageType
- * @param generatedMessage
- */
- public static void sendIndicationToMember(GuildInfo guildInfo, MessageTypeProto.MessageType messageType, GeneratedMessage generatedMessage) {
- Map<Integer, Set<Integer>> members = guildInfo.getMembers();
- for (Set<Integer> items : members.values()) {
- for (Integer sendUid : items) {
- ISession isession = OnlineUserManager.getSessionByUid(sendUid);
- if (isession != null) {
- LOGGER.info("向{}发送indication", sendUid);
- MessageUtil.sendIndicationMessage(isession, 1, messageType.getNumber(), generatedMessage, true);
- }
- }
- }
- }
- public static void sendIndicationToMemberWithoutUser(GuildInfo guildInfo, MessageTypeProto.MessageType messageType, GeneratedMessage generatedMessage, int withOutUId) {
- Map<Integer, Set<Integer>> members = guildInfo.getMembers();
- for (Set<Integer> items : members.values()) {
- for (Integer sendUid : items) {
- if (sendUid == withOutUId) {
- continue;
- }
- ISession isession = OnlineUserManager.getSessionByUid(sendUid);
- if (isession != null) {
- LOGGER.info("向{}发送indication", sendUid);
- MessageUtil.sendIndicationMessage(isession, 1, messageType.getNumber(), generatedMessage, true);
- }
- }
- }
- }
- /**
- * 修改公会图腾
- *
- * @param session
- * @param iconId
- * @param messageType
- */
- public static void changeFamilyIcon(ISession session, int iconId, MessageTypeProto.MessageType messageType) throws Exception {
- User user = UserManager.getUser(session.getUid());
- PlayerManager playerInfoManager = user.getPlayerInfoManager();
- int[] cost = SGuildSetting.sGuildSetting.getTotemCost();
- int[][] cost1 = new int[1][];
- cost1[0] = cost;
- boolean b = ItemUtil.itemCost(user, cost1, BIReason.FAMILY_SET_ICON, 1);
- if (!b) {
- throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
- }
- GuilidManager.guildInfoMap.get(playerInfoManager.getGuildId()).updateIcon(iconId);
- RedisUtil.getInstence().putMapEntry(RedisKey.FAMILY_INFO, "", String.valueOf(playerInfoManager.getGuildId()), new GuildCache(GameApplication.serverId, iconId, GuilidManager.guildInfoMap.get(playerInfoManager.getGuildId()).getLevel(), GuilidManager.guildInfoMap.get(playerInfoManager.getGuildId()).getName()));
- MessageUtil.sendMessage(session, 1, messageType.getNumber(), null, true);
- }
- /**
- * 发公会红包
- *
- * @param redId
- * @throws Exception
- */
- public static void sendRedPackage(int uid, int redId) throws Exception {
- User user = UserManager.getUser(uid);
- SGuildRedPackConfig config = SGuildRedPackConfig.sGuildRedPackConfigMap.get(redId);
- if (config == null) {
- return;
- }
- int maxCount = config.getTotalMoney()[1];
- long[] generate = HongBaoAlgorithm.generate(maxCount, config.getNum(), maxCount * config.getMaxPercent() / 10000, maxCount * config.getMinPercent() / 10000);
- if (generate == null) {
- throw new ErrorCodeException(ErrorCode.RED_PACKAGE_NOT);
- }
- long increment = RedisUtil.getInstence().increment(RedisKey.getKey(RedisKey.FAMILY_RED_PACKAGE_INCRE_ID, "", false));
- RedisUtil.getInstence().putMapEntry(RedisKey.FAMILY_RED_PACKAGE, String.valueOf(user.getPlayerInfoManager().getGuildId()), String.valueOf(increment), new RedPackage(redId, uid, (int) (TimeUtils.now() / 1000), config.getLastTime()));
- List<String> reward = new ArrayList<>();
- for (Long count : generate) {
- reward.add(String.valueOf(count));
- }
- AbstractRank rank = RankContext.getRankEnum(RankEnum.GUILD_RED_PACKAGE_RANK.getType());
- double scoreById = rank.getScoreById(uid, String.valueOf(user.getPlayerInfoManager().getGuildId()));
- double price = SRechargeCommodityConfig.rechargeCommodityConfigMap.get(config.getTradeId()).getPrice();
- if (scoreById == -1 || scoreById == 0) {
- price += TimeUtils.getDoubleTime();
- } else {
- price += scoreById;
- }
- rank.addRank(uid, String.valueOf(user.getPlayerInfoManager().getGuildId()), price);
- RedisUtil.getInstence().lSet(RedisKey.getKey("red_remain_list", String.valueOf(increment), false), reward, config.getLastTime());
- }
- /**
- * 获取所有红包信息
- *
- * @param session
- * @param messageType
- */
- public static void getAllRedPackageInfo(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
- User user = UserManager.getUser(session.getUid());
- int guildId = user.getPlayerInfoManager().getGuildId();
- Map<String, RedPackage> redPackageMap = RedisUtil.getInstence().getMapValues(RedisKey.FAMILY_RED_PACKAGE, String.valueOf(guildId), String.class, RedPackage.class);
- Family.GetAllRedPackageResponse.Builder builder = Family.GetAllRedPackageResponse.newBuilder();
- List<String> removeId = new ArrayList<>();
- for (Map.Entry<String, RedPackage> entry : redPackageMap.entrySet()) {
- if (TimeUtils.now() / 1000 > entry.getValue().getEffectTime() + entry.getValue().getSendTime()) {
- removeId.add(entry.getKey());
- continue;
- }
- CommonProto.RedPackage.Builder redPackage = CommonProto.RedPackage.newBuilder();
- redPackage.setGetCount(RedisUtil.getInstence().getMapValues("red_already_list", entry.getKey(), int.class, AcceptRedInfo.class).size());
- AcceptRedInfo already = RedisUtil.getInstence().getMapEntry("red_already_list", entry.getKey(), String.valueOf(session.getUid()), AcceptRedInfo.class);
- redPackage.setIsGet(already == null ? 0 : 1);
- redPackage.setRedId(Integer.parseInt(entry.getKey()));
- redPackage.setUserName(UserManager.getUser(entry.getValue().getUid()).getPlayerInfoManager().getNickName());
- redPackage.setRedType(entry.getValue().getTypeId());
- redPackage.setSendTime(entry.getValue().getSendTime());
- builder.addInfo(redPackage);
- }
- for (String id : removeId) {
- RedisUtil.getInstence().removeMapEntrys(RedisKey.FAMILY_RED_PACKAGE, String.valueOf(guildId), id);
- }
- MessageUtil.sendMessage(session, 1, messageType.getNumber(), builder.build(), true);
- }
- /**
- * 抢红包
- */
- public static void robRedPackage(ISession session, int redId, MessageTypeProto.MessageType messageType) throws Exception {
- int uid = session.getUid();
- AcceptRedInfo isAlready = RedisUtil.getInstence().getMapValue("red_already_list", String.valueOf(redId), String.valueOf(uid), AcceptRedInfo.class);
- if (isAlready != null) {
- throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
- }
- Object redPackage = RedisUtil.getInstence().lPop(RedisKey.getKey("red_remain_list", String.valueOf(redId), false));
- Family.RobRedPackageResponse.Builder builder = Family.RobRedPackageResponse.newBuilder();
- if (redPackage != null) {
- builder.setIsSuccess(1);
- RedPackage packInfo = RedisUtil.getInstence().getMapValue(RedisKey.FAMILY_RED_PACKAGE, String.valueOf(UserManager.getUser(uid).getPlayerInfoManager().getGuildId()), String.valueOf(redId), RedPackage.class);
- if (packInfo == null) {
- throw new ErrorCodeException(ErrorCode.FAMILY_NULL);
- }
- SGuildRedPackConfig config = SGuildRedPackConfig.sGuildRedPackConfigMap.get(packInfo.getTypeId());
- int count = Integer.parseInt(String.valueOf(redPackage));
- ItemUtil.drop(UserManager.getUser(uid), new int[][]{new int[]{config.getTotalMoney()[0], count}}, BIReason.RED_PACKAGE_REWARD);
- builder.setCount(count);
- builder.setItemId(config.getTotalMoney()[0]);
- int position = getMemberType(uid, GuilidManager.guildInfoMap.get(UserManager.getUser(uid).getPlayerInfoManager().getGuildId()).getMembers());
- RedisUtil.getInstence().putMapEntry("red_already_list", String.valueOf(redId), String.valueOf(uid), new AcceptRedInfo(uid, config.getTotalMoney()[0], count, (int) (TimeUtils.now() / 1000), position));
- } else {
- throw new ErrorCodeException(ErrorCode.RED_PACKAGE_NOT);
- }
- MessageUtil.sendMessage(session, 1, messageType.getNumber(), builder.build(), true);
- }
- /**
- * 查看红包详情
- *
- * @param session
- * @param redId
- * @param messageType
- */
- public static void getRedPackageDetail(ISession session, int redId, MessageTypeProto.MessageType messageType) throws Exception {
- Map<Integer, AcceptRedInfo> alreadyList = RedisUtil.getInstence().getMapValues("red_already_list", String.valueOf(redId), Integer.class, AcceptRedInfo.class);
- int guildId = UserManager.getUser(session.getUid()).getPlayerInfoManager().getGuildId();
- Family.RedPackageDetailResponse.Builder builder = Family.RedPackageDetailResponse.newBuilder();
- if (!alreadyList.isEmpty()) {
- for (Map.Entry<Integer, AcceptRedInfo> already : alreadyList.entrySet()) {
- PlayerManager playerInfoManager = UserManager.getUser(already.getValue().getUid()).getPlayerInfoManager();
- CommonProto.RedOneDetail.Builder detail = CommonProto.RedOneDetail.newBuilder()
- .setUid(already.getValue().getUid())
- .setHead(playerInfoManager.getHead())
- .setHeadFrame(playerInfoManager.getHeadFrame())
- .setName(playerInfoManager.getNickName())
- .setTime(already.getValue().getTime())
- .setItemId(already.getValue().getItemId())
- .setCount(already.getValue().getCount())
- .setPosition(already.getValue().getPosition());
- builder.addInfo(detail.build());
- }
- }
- RedPackage packInfo = RedisUtil.getInstence().getMapValue(RedisKey.FAMILY_RED_PACKAGE, String.valueOf(guildId), String.valueOf(redId), RedPackage.class);
- PlayerManager playerInfoManager = UserManager.getUser(packInfo.getUid()).getPlayerInfoManager();
- builder.setSendName(playerInfoManager.getNickName())
- .setHead(playerInfoManager.getHead())
- .setHeadFrame(playerInfoManager.getHeadFrame())
- .setRemainTime(packInfo.getSendTime() + packInfo.getEffectTime() - (int) (TimeUtils.now() / 1000));
- MessageUtil.sendMessage(session, 1, messageType.getNumber(), builder.build(), true);
- }
- /**
- * 点赞!
- *
- * @param session
- * @param targetUid
- * @param messageType
- */
- public static void redPackageSendLike(ISession session, int targetUid, MessageTypeProto.MessageType messageType) throws Exception {
- User user = UserManager.getUser(session.getUid());
- int guildId = user.getPlayerInfoManager().getGuildId();
- Double price = RedisUtil.getInstence().getZSetScore(RedisKey.GUILD_RED_PACKAGE_RANK, String.valueOf(guildId), String.valueOf(targetUid));
- if (price <= 0) {
- throw new ErrorCodeException(ErrorCode.AMOUNT_ERR);
- }
- if (user.getFriendManager().getTodayLike().contains(targetUid)) {
- throw new ErrorCodeException(ErrorCode.ALREADY_LIKE);
- }
- ItemUtil.drop(user, new int[][]{SGuildSetting.sGuildSetting.getGiveLikeReward()}, BIReason.SEND_LIKE_REWARD);
- User targetUser = UserManager.getUser(targetUid);
- AyyncWorker ayyncWorker = new AyyncWorker(targetUser, true, n -> targetUser.getFriendManager().addBeLikedCount(1));
- user.getFriendManager().addTodayLike(targetUid);
- ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
- MessageUtil.sendMessage(session, 1, messageType.getNumber(), null, true);
- }
- /**
- * 获取今天给谁点过赞
- *
- * @param session
- * @param messageType
- */
- public static void getAllTodayLike(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
- User user = UserManager.getUser(session.getUid());
- Family.GetAllSendLikeResponse response = Family.GetAllSendLikeResponse.newBuilder().addAllUid(user.getFriendManager().getTodayLike()).build();
- MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
- }
- /**
- * 获取所有公会技能
- *
- * @param session
- * @param messageType
- * @throws Exception
- */
- public static void getAllSkill(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
- User user = UserManager.getUser(session.getUid());
- Map<Integer, Integer> guildSkill = user.getGuildMyInfo().getGuildSkill();
- Family.GetAllGuildSkillResponse.Builder response = Family.GetAllGuildSkillResponse.newBuilder();
- for (Map.Entry<Integer, Integer> entry : guildSkill.entrySet()) {
- Family.GuildSkill skill = Family.GuildSkill.newBuilder().setType(entry.getKey()).setLevel(entry.getValue()).build();
- response.addSkill(skill);
- }
- MessageUtil.sendMessage(session, 1, messageType.getNumber(), response.build(), true);
- }
- /**
- * 公会技能升级
- *
- * @param session
- * @param type
- * @param messageType
- */
- public static void guildSkillLevelUp(ISession session, int type, MessageTypeProto.MessageType messageType) throws Exception {
- User user = UserManager.getUser(session.getUid());
- //todo 消耗校验
- Map<Integer, Integer> skillInfo = user.getGuildMyInfo().getGuildSkill();
- Map<Integer, Map<Integer, SGuildTechnology>> typeMap = SGuildTechnology.technologyMap.get(type);
- int size = typeMap.size();
- int[][] consume;
- int level =0;
- if (!skillInfo.containsKey(type)) {
- consume = typeMap.get(1).get(0).getConsume();
- } else {
- level = skillInfo.get(type);
- consume = typeMap.get(level % size + 1).get(level / size).getConsume();
- if (typeMap.get(level % size + 1).get(level / size + 1) == null) {
- throw new ErrorCodeException(ErrorCode.HERO_LEVE_MAX);
- }
- }
- boolean itemCost = ItemUtil.itemCost(user, consume, BIReason.GUILD_SKILL_LEVEL_UP_CONSUME, 1);
- if (!itemCost) {
- throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
- }
- user.getGuildMyInfo().addGuildSkillByType(type);
- Poster.getPoster().dispatchEvent(new UserMainTeamForceEvent(session.getUid()));
- user.getUserMissionManager().onGameEvent(user, GameEvent.GUILD_ACTIVE_MISSION_UPDATE, 127);
- user.getUserMissionManager().onGameEvent(user, GameEvent.GUILD_SKILL_LEVEL_UP_TIMES);
- user.getUserMissionManager().onGameEvent(user, GameEvent.GUILD_TECH_LEVEL, type,level);
- MessageUtil.sendMessage(session, 1, messageType.getNumber(), null, true);
- }
- /**
- * 公会技能重置
- *
- * @param session
- * @param type
- * @param messageType
- */
- public static void resetGuildSkill(ISession session, int type, MessageTypeProto.MessageType messageType) throws Exception {
- User user = UserManager.getUser(session.getUid());
- GuildMyInfo guildMyInfo = user.getGuildMyInfo();
- if (!guildMyInfo.getGuildSkill().containsKey(type)) {
- throw new ErrorCodeException(ErrorCode.GUILD_SKILL_NULL);
- }
- int level = guildMyInfo.getGuildSkill().get(type);
- int size = SGuildTechnology.technologyMap.get(type).size();
- String err = StoreLogic.checkBuyGoodsAndUpdate(user, 7, 10028, 1);
- if (!err.isEmpty()) {
- throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
- }
- List<int[]> consume = new ArrayList<>();
- for (int i = 1; i <= size; i++) {
- int baseLevel = level / size;
- if (level % size >= i) {
- baseLevel += 1;
- }
- Map<Integer, SGuildTechnology> levelMap = SGuildTechnology.technologyMap.get(type).get(i);
- for (int j = 0; j < baseLevel; j++) {
- SGuildTechnology sGuildTechnology = levelMap.get(j);
- consume.addAll(Arrays.asList(sGuildTechnology.getConsume()));
- }
- }
- int percent = SSpecialConfig.getIntegerValue(SSpecialConfig.GUILD_TECHNOLOGY_RETURN_PERCENT);
- int[][] dropArray = consume.toArray(new int[consume.size()][]);
- Map<Integer, Integer> reward = new HashMap<>();
- for (int[] aDropArray : dropArray) {
- if (aDropArray.length < 2) {
- continue;
- }
- if (!reward.containsKey(aDropArray[0])) {
- reward.put(aDropArray[0], 0);
- }
- reward.put(aDropArray[0], reward.get(aDropArray[0]) + aDropArray[1]);
- }
- int[][] dropArrayReally = new int[reward.size()][];
- int index = 0;
- for (Map.Entry<Integer, Integer> entry : reward.entrySet()) {
- double doublePercent = (double) percent;
- dropArrayReally[index] = new int[]{entry.getKey(), (int) (entry.getValue() * doublePercent / 10000)};
- index++;
- }
- CommonProto.Drop.Builder drop = ItemUtil.drop(user, dropArrayReally, BIReason.RESET_GUILD_SKILL);
- guildMyInfo.removeGuildSkillByType(type);
- Family.ResetGuildSkillResponse response = Family.ResetGuildSkillResponse.newBuilder().setDrop(drop).build();
- Poster.getPoster().dispatchEvent(new UserMainTeamForceEvent(session.getUid()));
- MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
- }
- public static CommonProto.GuildHelpLog getLog(GuildHelpLog log) {
- return CommonProto.GuildHelpLog.newBuilder()
- .setHelperuid(log.getHelpId()).setTargetuid(log.getTargetId())
- .setHelpername(log.getHelperName())
- .setTargetname(log.getTargetName())
- .setTime(log.getLogTime())
- .setType(log.getType()).build();
- }
- /**
- * 公会id清零之前调用
- *
- * @param user
- * @throws Exception
- */
- public static void OnUserLeveFamily(User user) throws Exception {
- //TODO lock all 公会id清零之前调用
- //退公会清除数据 补发奖励
- sendGuildHelpRewardEmail(user);
- int guildId = user.getPlayerInfoManager().getGuildId();
- //注掉原因:这是梦魇入侵的排行不要在这清
- //RedisUtil.getInstence().zsetRemoveOne(RedisKey.getKey(RedisKey.CAR_DEALY_RANK, "", false), String.valueOf(user.getId()));
- RedisUtil.getInstence().putMapEntry(RedisKey.USER_LEVEL_GUILD_INFO, "", String.valueOf(user.getId()), guildId);
- //删除战力
- Poster.getPoster().dispatchEvent(new GuildForceChangeEvent(user.getId(), user.getPlayerInfoManager().getGuildId(), 3, 0 - user.getPlayerInfoManager().getMaxForce()));
- //notify ALL
- Family.GuildHelpInfoIndication.Builder build = Family.GuildHelpInfoIndication.newBuilder();
- for (Map.Entry<Integer, Integer> entry : user.getGuildMyInfo().getGuidHelpInfo().entrySet()) {
- //通知前端清除公会成员援助信息
- build.setUid(user.getId());
- build.addGuildHelpInfo(CommonProto.GuildHelpInfo.newBuilder().setType(entry.getKey()).setNum(-1));
- }
- GuildLogic.sendIndicationToMember(GuilidManager.guildInfoMap.get(user.getPlayerInfoManager().getGuildId()), MessageTypeProto.MessageType.GuildHelpInfoIndication, build.build());
- }
- //sendGuildHelpRewardEmail
- public static void sendGuildHelpRewardEmail(User user) throws Exception {
- // 补发奖励
- GuildMyInfo guildMyInfo = user.getGuildMyInfo();
- String title = SErrorCodeEerverConfig.getI18NMessage("guildhelp_reward_title");
- String content = SErrorCodeEerverConfig.getI18NMessage("guildhelp_reward_txt");
- List<int[][]> list = new LinkedList<>();
- for (Map.Entry<Integer, Integer> entry : user.getGuildMyInfo().getGuidHelpInfo().entrySet()) {
- int i = entry.getValue() - user.getGuildMyInfo().getGuidHelpHadTakeInfo().getOrDefault(entry.getKey(), 0);
- if (i <= 0) {
- continue;
- }
- int[][] drop = new int[1][];
- drop[0] = new int[2];
- drop[0][0] = entry.getKey();
- drop[0][1] = i;
- list.add(drop);
- guildMyInfo.putGuidHelpHadTakeInfo(entry.getKey(), entry.getValue());
- }
- if (list.size() == 0) {
- return;
- }
- boolean isfinish = true;
- SGuildHelpConfig sGuildHelpConfig = STableManager.getConfig(SGuildHelpConfig.class).get(1);
- if (guildMyInfo.getGuidHelpHadTakeInfo().size() == sGuildHelpConfig.getRecourseTime()[0]) {
- for (Map.Entry<Integer, Integer> entry : guildMyInfo.getGuidHelpHadTakeInfo().entrySet()) {
- if (entry.getValue() < sGuildHelpConfig.getRecourseTime()[1]) {
- isfinish = false;
- break;
- }
- }
- } else {
- isfinish = false;
- }
- if (isfinish && !guildMyInfo.isGuildHelpReward()) {
- list.add(sGuildHelpConfig.getReward());
- guildMyInfo.setGuildHelpReward(true);
- }
- String mailReward = ItemUtil.getMailReward(list);
- MailLogic.getInstance().sendMail(user.getId(), title, content, mailReward, (int) (TimeUtils.now() / 1000), Global.MAIL_EFFECTIVE_TIME);
- }
- /**
- * 是否在退出公会CD中
- * @param user
- * @return
- */
- public static boolean checkLeaveGuildCDing(User user){
- int CD_TIME = SSpecialConfig.getIntegerValue("Guild_Rejion_Cdtime");//冷却小时
- if(CD_TIME <= 0) return false;
- long leaveGuildTime = user.getPlayerInfoManager().getLeaveGuildTime();
- if(leaveGuildTime > 0) {
- long endTime = TimeUtils.getTimeBeforeOrAfterMinute(leaveGuildTime,CD_TIME * TimeUtils.MIN_HOUR);
- if(System.currentTimeMillis() <= endTime) {
- return true;
- }
- }
- return false;
- }
- }
|