GuildLogic.java 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. package com.ljsd.jieling.logic.family;
  2. import com.google.protobuf.GeneratedMessage;
  3. import com.ljsd.GameApplication;
  4. import com.ljsd.jieling.core.GlobalsDef;
  5. import com.ljsd.jieling.core.Lockeys;
  6. import com.ljsd.jieling.core.SimpleTransaction;
  7. import com.ljsd.jieling.core.VipPrivilegeType;
  8. import com.ljsd.jieling.logic.activity.ActivityLogic;
  9. import com.ljsd.jieling.logic.activity.ActivityTypeEnum;
  10. import com.ljsd.jieling.reportBeans_37.ChatContentType;
  11. import com.ljsd.jieling.reportBeans_37.Repot37EventUtil;
  12. import com.ljsd.jieling.db.mongo.MongoUtil;
  13. import com.ljsd.jieling.db.redis.RedisKey;
  14. import com.ljsd.jieling.db.redis.RedisUtil;
  15. import com.ljsd.jieling.exception.ErrorCode;
  16. import com.ljsd.jieling.exception.ErrorCodeException;
  17. import com.ljsd.jieling.globals.BIReason;
  18. import com.ljsd.jieling.globals.Global;
  19. import com.ljsd.jieling.jbean.ActivityProgressInfo;
  20. import com.ljsd.jieling.ktbeans.ReportEventEnum;
  21. import com.ljsd.jieling.ktbeans.ReportUtil;
  22. import com.ljsd.jieling.logic.OnlineUserManager;
  23. import com.ljsd.jieling.logic.activity.ActivityType;
  24. import com.ljsd.jieling.logic.activity.IEventHandler;
  25. import com.ljsd.jieling.logic.activity.event.*;
  26. import com.ljsd.jieling.logic.dao.*;
  27. import com.ljsd.jieling.logic.dao.root.*;
  28. import com.ljsd.jieling.logic.mail.MailLogic;
  29. import com.ljsd.jieling.logic.mission.GameEvent;
  30. import com.ljsd.jieling.logic.player.PlayerLogic;
  31. import com.ljsd.jieling.logic.rank.RankContext;
  32. import com.ljsd.jieling.logic.rank.RankEnum;
  33. import com.ljsd.jieling.logic.rank.rankImpl.AbstractRank;
  34. import com.ljsd.jieling.logic.store.StoreLogic;
  35. import com.ljsd.jieling.network.server.ProtocolsManager;
  36. import com.ljsd.jieling.network.session.ISession;
  37. import com.ljsd.jieling.protocols.*;
  38. import com.ljsd.jieling.util.*;
  39. import config.*;
  40. import manager.STableManager;
  41. import org.slf4j.Logger;
  42. import org.slf4j.LoggerFactory;
  43. import util.StringUtil;
  44. import util.TimeUtils;
  45. import java.util.*;
  46. public class GuildLogic {
  47. static GuildLogic guildLogicInstance = new GuildLogic();
  48. public static GuildLogic getInstance() {
  49. return guildLogicInstance;
  50. }
  51. public void flushEveryDay(User user, PlayerInfoProto.FivePlayerUpdateIndication.Builder fBuilder) throws Exception {
  52. // takeAllReward(user);
  53. refreshAndTakeAllReward(user);
  54. // 发送公会援助奖励
  55. // sendGuildHelpRewardEmail(user);
  56. user.getGuildMyInfo().setFetetype(0);
  57. user.getGuildMyInfo().clearHadTakeReward();
  58. //清空前天的活跃度
  59. user.getGuildMyInfo().setGuildActiveNumToday(0);
  60. if (!TimeUtils.isInSameWeek(user.getGuildMyInfo().getGuildActiveNumWeekTime() * 1000L, TimeUtils.now())) {
  61. user.getGuildMyInfo().setGuildActiveNumWeek(0);
  62. }
  63. if (null != fBuilder) {
  64. fBuilder.setLastFeteType(user.getGuildMyInfo().getFetetype());
  65. fBuilder.addAllTakeFeteReward(new HashSet<>());
  66. }
  67. //
  68. }
  69. void refreshAndTakeAllReward(User user) throws Exception {
  70. try {
  71. int guildId = user.getPlayerInfoManager().getGuildId();
  72. if (guildId == 0) {
  73. return;
  74. }
  75. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  76. if (!TimeUtils.isOverTime(0, guildInfo.getLastRefreshTime())) {
  77. return;
  78. }
  79. long now = TimeUtils.now();
  80. List<int[][]> itemArrs = new LinkedList<>();
  81. //补发前日未领取的祭祀奖
  82. Map<Integer, SGuildSacrificeRewardConfig> config = STableManager.getConfig(SGuildSacrificeRewardConfig.class);
  83. if (null == config) {
  84. throw new ErrorCodeException(ErrorCode.CFG_NULL);
  85. }
  86. RedisUtil.getInstence().del(RedisKey.getKey(RedisKey.GUILD_RED_PACKAGE_RANK, String.valueOf(guildId), false));
  87. for (Set<Integer> items : guildInfo.getMembers().values()) {
  88. for (Integer uid : items) {
  89. User target = UserManager.getUser(uid);
  90. int gId = target.getPlayerInfoManager().getGuildId();
  91. if (gId == -1) {
  92. continue;
  93. }
  94. //check 最近一次公会id
  95. if (target.getGuildMyInfo().getFeteguild() != guildId) {
  96. continue;
  97. }
  98. Set<Integer> objects = new HashSet<>(config.keySet());
  99. objects.removeAll(target.getGuildMyInfo().getHadTakeReward());
  100. for (Integer missionId : objects) {
  101. //checkAndUpdate cfg
  102. SGuildSacrificeRewardConfig sGuildSacrificeRewardConfig = config.get(missionId);
  103. //take rewards checkAndUpdate
  104. int fete = guildInfo.getFete();
  105. if (sGuildSacrificeRewardConfig.getScore() > fete) {
  106. continue;
  107. }
  108. //up miss
  109. int[][] reward = sGuildSacrificeRewardConfig.getReward();
  110. itemArrs.add(reward);
  111. }
  112. if (itemArrs.isEmpty()) {
  113. continue;
  114. }
  115. String title = SErrorCodeEerverConfig.getI18NMessage("guildsacrifice_reward_title");
  116. String content = SErrorCodeEerverConfig.getI18NMessage("guildsacrifice_reward_txt");
  117. String mailReward = ItemUtil.getMailReward(itemArrs);
  118. int nowTime = (int) (now / 999);
  119. MailLogic.getInstance().sendMail(target.getId(), title, content, mailReward, nowTime, Global.MAIL_EFFECTIVE_TIME);
  120. }
  121. }
  122. guildInfo.reSetFete();
  123. guildInfo.setLastRefreshTime(now);
  124. SimpleTransaction transaction = SimpleTransaction.current();
  125. Set<Integer> sendUids = new HashSet<>();
  126. for (Set<Integer> items : guildInfo.getMembers().values()) {
  127. sendUids.addAll(items);
  128. }
  129. Lockeys.getLockeys().lock("guild", sendUids);
  130. guildInfo.clearGuildHelpLog();
  131. //统一清除
  132. for (Integer sendUid : sendUids) {
  133. User target = UserManager.getUser(sendUid);
  134. GuildLogic.sendGuildHelpRewardEmail(target);
  135. GuildMyInfo guildMyInfo = target.getGuildMyInfo();
  136. guildMyInfo.setGuidHelpInfo(new HashMap<>());
  137. guildMyInfo.setGuidHelpHadTakeInfo(new HashMap<>());
  138. guildMyInfo.setGuildHelpSendTime(0);
  139. guildMyInfo.setGuildHelpReward(false);
  140. guildMyInfo.setGuildHelpTime(0);
  141. }
  142. SimpleTransaction.remove();
  143. //处理公会援助信息
  144. //入库
  145. MongoUtil.getInstence().lastUpdate();
  146. } catch (Exception e) {
  147. LOGGER.error("Exception refreshAndTakeAllReward");
  148. }
  149. }
  150. void takeAllReward(User user) throws Exception {
  151. List<int[][]> itemArrs = new LinkedList<>();
  152. //补发前日未领取的祭祀奖
  153. Map<Integer, SGuildSacrificeRewardConfig> config = STableManager.getConfig(SGuildSacrificeRewardConfig.class);
  154. if (null == config) {
  155. throw new ErrorCodeException(ErrorCode.CFG_NULL);
  156. }
  157. int guildId = user.getPlayerInfoManager().getGuildId();
  158. if (guildId == 0) {
  159. return;
  160. }
  161. //check 最近一次公会id
  162. if (user.getGuildMyInfo().getFeteguild() != guildId)
  163. return;
  164. Set<Integer> objects = new HashSet<>(config.keySet());
  165. objects.removeAll(user.getGuildMyInfo().getHadTakeReward());
  166. for (Integer missionId : objects) {
  167. //checkAndUpdate cfg
  168. SGuildSacrificeRewardConfig sGuildSacrificeRewardConfig = config.get(missionId);
  169. //take rewards checkAndUpdate
  170. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  171. int fete = guildInfo.getFete();
  172. if (sGuildSacrificeRewardConfig.getScore() > fete) {
  173. continue;
  174. }
  175. //up miss
  176. int[][] reward = sGuildSacrificeRewardConfig.getReward();
  177. itemArrs.add(reward);
  178. }
  179. if (itemArrs.size() == 0)
  180. return;
  181. String title = SErrorCodeEerverConfig.getI18NMessage("guildsacrifice_reward_title");
  182. String content = SErrorCodeEerverConfig.getI18NMessage("guildsacrifice_reward_txt");
  183. String mailReward = ItemUtil.getMailReward(itemArrs);
  184. int nowTime = (int) (TimeUtils.now() / 1000);
  185. MailLogic.getInstance().sendMail(user.getId(), title, content, mailReward, nowTime, Global.MAIL_EFFECTIVE_TIME);
  186. }
  187. private static final Logger LOGGER = LoggerFactory.getLogger(GuildLogic.class);
  188. public static int getMemberType(int targetUid, Map<Integer, Set<Integer>> members) {
  189. for (Map.Entry<Integer, Set<Integer>> memberEntry : members.entrySet()) {
  190. Integer position = memberEntry.getKey();
  191. Set<Integer> value = memberEntry.getValue();
  192. if (value.contains(targetUid)) {
  193. return position;
  194. }
  195. }
  196. return GlobalsDef.MEMBER;
  197. }
  198. public static void getFamilyInfo(ISession session) throws Exception {
  199. int uid = session.getUid();
  200. int msgId = MessageTypeProto.MessageType.FAMILY_GET_INFO_RESPONSE_VALUE;
  201. User user = UserManager.getUser(uid);
  202. int guildId = user.getPlayerInfoManager().getGuildId();
  203. if (0 == guildId) {
  204. throw new ErrorCodeException(ErrorCode.FAMILY_NULL);
  205. }
  206. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  207. Family.GetFamilyInfoResponse.Builder builder = Family.GetFamilyInfoResponse.newBuilder()
  208. .setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo))
  209. .setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(user, getMemberType(uid, guildInfo.getMembers()))).setGuildBossId(GuildFightLogic.getCurSGuildBossConfig() == null ? 0 : GuildFightLogic.getCurSGuildBossConfig().getId());
  210. for (Set<Integer> members : guildInfo.getMembers().values()) {
  211. for (int uidOfMember : members) {
  212. User userMember = UserManager.getUser(uidOfMember);
  213. builder.addFamilyWalkIndicaiton(CBean2Proto.getFamilyWalkIndicaiton(userMember));
  214. }
  215. }
  216. // if (GuildFightLogic.carDelayProgressIndication != null) {
  217. // builder.setCarDelayProgressIndication(GuildFightLogic.carDelayProgressIndication);
  218. // if(GuildFightLogic.carDelayProgressIndication.getProgress() != user.getGuildMyInfo().getCarPlayProgress()){
  219. // user.getGuildMyInfo().setCarPlayTime(0);
  220. // user.getGuildMyInfo().setCarPlayProgress(GuildFightLogic.carDelayProgressIndication.getProgress());
  221. // }
  222. // }
  223. builder.setCarPlayTime(user.getGuildMyInfo().getCarPlayTime());
  224. MessageUtil.sendMessage(session, 1, msgId, builder.build(), true);
  225. }
  226. /**
  227. * 明斯克战役 需要跟工会分开
  228. *
  229. * @param session
  230. * @throws Exception
  231. */
  232. public static void getMinskWarProgressIndication(ISession session) throws Exception {
  233. int msgId = MessageTypeProto.MessageType.GET_CAR_CHALLENGE_INFO_RESPONSE.getNumber();
  234. Family.CarChallengeProgressIndication indication = GuildFightLogic.carChallengeProgressIndication;
  235. long totalHurt = 0L;
  236. String carDealyScoreKey = RedisUtil.getInstence().getKey(RedisKey.CAR_DEALY_SCORE, "");
  237. String totalHurtStr = (String) RedisUtil.getInstence().get(carDealyScoreKey);
  238. if (!StringUtil.isEmpty(totalHurtStr)) {
  239. totalHurt = Long.parseLong(totalHurtStr);
  240. }
  241. Family.CarChallengeProgressIndication cpi = Family.CarChallengeProgressIndication.newBuilder().
  242. setBossIndexId(indication.getBossIndexId()).
  243. setProgress(indication.getProgress()).
  244. setEndTime(indication.getEndTime()).
  245. setBattleStartTime(indication.getBattleStartTime()).
  246. setTotalHurt(totalHurt).
  247. build();
  248. MessageUtil.sendMessage(session, 1, msgId, cpi, true);
  249. }
  250. /**
  251. * 明斯克战役 我的信息
  252. *
  253. * @param session
  254. * @throws Exception
  255. */
  256. public static void getMinskWarMyInfo(ISession session) throws Exception {
  257. int msgId = MessageTypeProto.MessageType.GET_CAR_CHALLENGE_MY_INFO_RESPONSE.getNumber();
  258. //判断有没有参与
  259. User user = UserManager.getUser(session.getUid());
  260. initMinskWarBattleCount(user);
  261. PlayerManager playerManager = user.getPlayerInfoManager();
  262. MinskBattleCount minskBattleCount = playerManager.getMinskBattleCount();
  263. Family.CarChallengeMyInfo builder = Family.CarChallengeMyInfo.newBuilder().setBattleBuyCount(minskBattleCount.getHasBuyCount()).setBattleCount(minskBattleCount.getCount())
  264. .setBattleLastHurt(minskBattleCount.getLastHurt()).build();
  265. MessageUtil.sendMessage(session, 1, msgId, builder, true);
  266. }
  267. public static void initMinskWarBattleCount(User user) {
  268. PlayerManager playerManager = user.getPlayerInfoManager();
  269. if (playerManager.getStartMinskBattleFlag() == 0) {
  270. SWorldBossSetting sWorldBossSetting = STableManager.getConfig(SWorldBossSetting.class).get(1);
  271. int[] privilegge = sWorldBossSetting.getPrivilege();
  272. // SPrivilegeTypeConfig sPrivilegeTypeConfig = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(privilegge[0]);
  273. // int[][] buyCount = sPrivilegeTypeConfig.getCondition();
  274. int vigorTotalLimit = SPrivilegeTypeConfig.getConditionByVip(privilegge[0], user.getPlayerInfoManager().getVipLevel());
  275. MinskBattleCount minskBattleCount = playerManager.getMinskBattleCount();
  276. if (minskBattleCount == null) {
  277. minskBattleCount = new MinskBattleCount();
  278. }
  279. // minskBattleCount1.setCount(vigorTotalLimit);
  280. // minskBattleCount1.setHasBuyCount(0);
  281. // playerManager.setMinskBattleCount(minskBattleCount1);
  282. // } else {
  283. // minskBattleCount.setCount(vigorTotalLimit);
  284. // minskBattleCount.setHasBuyCount(0);
  285. // }
  286. minskBattleCount.setCount(vigorTotalLimit);
  287. minskBattleCount.setHasBuyCount(0);
  288. minskBattleCount.setLastHurt(0);
  289. playerManager.setMinskBattleCount(minskBattleCount);
  290. playerManager.setStartMinskBattleFlag(1);
  291. }
  292. }
  293. /**
  294. * 购买明斯克挑战次数
  295. * 购买 梦魇入侵 挑战次数
  296. * @param session
  297. * @throws Exception
  298. */
  299. public static void buyMinskBattleCount(ISession session) throws Exception {
  300. int uid = session.getUid();
  301. User user = UserManager.getUser(uid);
  302. initMinskWarBattleCount(user);
  303. MinskBattleCount minskBattleCount = user.getPlayerInfoManager().getMinskBattleCount();
  304. int nowCount = minskBattleCount.getCount();
  305. int hasBuyCount = minskBattleCount.getHasBuyCount();
  306. SWorldBossSetting sWorldBossSetting = STableManager.getConfig(SWorldBossSetting.class).get(1);
  307. int[] privilegge = sWorldBossSetting.getPrivilege();
  308. //SPrivilegeTypeConfig sPrivilegeTypeConfig = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(privilegge[1]);
  309. //int[][] buyCount = sPrivilegeTypeConfig.getCondition();
  310. int[][] buyPrice = sWorldBossSetting.getBuyPrice();
  311. int vigorTotalLimit = SPrivilegeTypeConfig.getConditionByVip(privilegge[0], user.getPlayerInfoManager().getVipLevel());
  312. if (hasBuyCount + 1 > vigorTotalLimit) {
  313. throw new ErrorCodeException(ErrorCode.MINSK_BATTLE_BUYCOUNT_ENOUGH);
  314. }
  315. int[] costItemNum = buyPrice[hasBuyCount];
  316. int[][] consumeMaterial = {{16, costItemNum[1]}};
  317. boolean enoughCost = ItemUtil.itemCost(user, consumeMaterial, BIReason.MINSK_BATTLE_COUNT, 1);
  318. if (!enoughCost) {
  319. throw new ErrorCodeException(ErrorCode.HERO_ITEM_NOT);
  320. }
  321. minskBattleCount.setCount(nowCount + 1);
  322. minskBattleCount.setHasBuyCount(hasBuyCount + 1);
  323. user.getPlayerInfoManager().setMinskBattleCount(minskBattleCount);
  324. Family.CarChallengeMyInfo builder = Family.CarChallengeMyInfo.newBuilder().setBattleBuyCount(minskBattleCount.getHasBuyCount()).setBattleCount(minskBattleCount.getCount()).build();
  325. MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.MINSK_BATTLE_BUYCOUNT_RESPONSE.getNumber(), builder, true);
  326. }
  327. /**
  328. * 创建公会
  329. *
  330. * @param session
  331. * @param familyName
  332. * @param announce 渠道Id,区分不同的语言版本,限制字符不同
  333. * @param channelId
  334. * @throws Exception
  335. */
  336. public static void createFamily(ISession session, String familyName, String announce,int channelId ) throws Exception {
  337. int uid = session.getUid();
  338. User user = UserManager.getUser(uid);
  339. int msgId = MessageTypeProto.MessageType.FAMILY_CREATE_RESPONSE_VALUE;
  340. checkForCreateGuild(user, familyName, announce,channelId);
  341. boolean enough = ItemUtil.itemCost(user, SGuildSetting.sGuildSetting.getCreatCost(), BIReason.CREATE_GUILD_CONSUME, 0);
  342. if (!enough) {
  343. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  344. }
  345. if (user.getPlayerInfoManager().getGuildId() != 0) {
  346. throw new ErrorCodeException(ErrorCode.FAMILY_IN);
  347. }
  348. if (StringUtil.isEmpty(announce)) {
  349. announce = SGuildSetting.sGuildSetting.getDefaultDeclaration();
  350. }
  351. if (announce.length() == 0 || announce.length() > 32) {
  352. throw new ErrorCodeException(ErrorCode.ANNOUNCE_SIZE);
  353. }
  354. //设置加入公会时间
  355. user.getGuildMyInfo().setJoinTime(TimeUtils.nowInt());
  356. GuildInfo guildInfo = new GuildInfo(user.getId(), familyName, announce);
  357. GuilidManager.addGuildInfo(guildInfo);
  358. user.getPlayerInfoManager().setGuildId(guildInfo.getId());
  359. addGuildLog(guildInfo.getId(), GuildDef.Log.CREATE, user.getPlayerInfoManager().getNickName());
  360. RedisUtil.getInstence().putMapEntry(RedisKey.FAMILY_INFO, "", String.valueOf(guildInfo.getId()), new GuildCache(GameApplication.serverId, guildInfo.getIcon(), guildInfo.getLevel(), guildInfo.getName()));
  361. PlayerInfoCache cache = RedisUtil.getInstence().getMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(uid), PlayerInfoCache.class);
  362. cache.setGuildPosition(GlobalsDef.CHAIRMAN);
  363. RedisUtil.getInstence().putMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(uid), cache);
  364. user.getUserMissionManager().onGameEvent(user, GameEvent.JOIN_FAMILY);
  365. Family.FamilyCreateResponse build = Family.FamilyCreateResponse.newBuilder()
  366. .setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo))
  367. .setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(user, GlobalsDef.CHAIRMAN))
  368. .setFamilyWalkIndicaiton(CBean2Proto.getFamilyWalkIndicaiton(user))
  369. .build();
  370. Poster.getPoster().dispatchEvent(new GuildForceChangeEvent(user.getId(), user.getPlayerInfoManager().getGuildId(), 1, user.getPlayerInfoManager().getMaxForce()));
  371. //ReportUtil.onReportEvent(user, ReportEventEnum.CREATE_GUILD.getType(),String.valueOf(guildInfo.getId()),guildInfo.getName(),guildInfo.getLevel(),guildInfo.getTotalMembers());
  372. MessageUtil.sendMessage(session, 1, msgId, build, true);
  373. }
  374. public static void checkForCreateGuild(User user, String familyName, String announce,int channelId) throws Exception {
  375. // if(!Repot37EventUtil.Report37Chat(user, ChatContentType.FAMILY_NAME.getType(),announce)){
  376. // throw new ErrorCodeException(ErrorCode.FAMILY_IN_SENSITIVE);
  377. // }
  378. if(checkLeaveGuildCDing(user)){
  379. throw new ErrorCodeException(ErrorCode.LEAVE_GUILD_CD_ING);
  380. }
  381. if (StringUtil.isEmpty(familyName)) {
  382. throw new ErrorCodeException(ErrorCode.NULL_NAME);
  383. }
  384. if (!StringUtil.isEmpty(announce)) {
  385. if (!ShieldedWordUtils.checkName(user, familyName, false, ChatContentType.FAMILY_NAME) || !ShieldedWordUtils.checkName(user, announce, false, ChatContentType.FAMILY_NAME)) {
  386. throw new ErrorCodeException(ErrorCode.FAMILY_IN_SENSITIVE);
  387. }
  388. }
  389. if(channelId > 0){
  390. SMultiLanguage sMultiLanguage = SMultiLanguage.sMultiLanguageMap.get(channelId);
  391. int[] guildNameLimit = sMultiLanguage.getGuildNameLimit();
  392. if (familyName.length() > guildNameLimit[1] || familyName.length() < guildNameLimit[0]) {
  393. throw new ErrorCodeException(ErrorCode.NAME_LENGTH_ERROR); //名字长度为2-6个字
  394. }
  395. }else {
  396. if (familyName.length() < SGuildSetting.sGuildSetting.getNameSize()[0] || familyName.length() > SGuildSetting.sGuildSetting.getNameSize()[1]) {
  397. throw new ErrorCodeException(ErrorCode.NAME_LENGTH_ERROR);
  398. }
  399. }
  400. Map<Integer, GuildInfo> guildInfoMap = GuilidManager.guildInfoMap;
  401. for (Map.Entry<Integer, GuildInfo> entry : guildInfoMap.entrySet()) {
  402. if (entry.getValue().getName().equals(familyName)) {
  403. throw new ErrorCodeException(ErrorCode.EXIST_NAME);
  404. }
  405. }
  406. }
  407. /**
  408. * 推荐公会
  409. *
  410. * @param session
  411. * @throws Exception
  412. */
  413. public static void recommendFamily(ISession session) throws Exception {
  414. int uid = session.getUid();
  415. User user = UserManager.getUser(uid);
  416. int msgId = MessageTypeProto.MessageType.FAMILY_RECOMEND_RESPONSE_VALUE;
  417. Collection<GuildInfo> guildInfos = GuilidManager.recommandGuild(user);
  418. Family.FamilyRecommandResponse.Builder builder = Family.FamilyRecommandResponse.newBuilder();
  419. Map<Integer, GuildApply> applyGuildInfos = GuilidManager.getApplyGuildInfos(uid, 1);
  420. int now = (int) (System.currentTimeMillis() / 1000);
  421. if (applyGuildInfos.size() > 0) {
  422. Iterator<Map.Entry<Integer, GuildApply>> iterator = applyGuildInfos.entrySet().iterator();
  423. while (iterator.hasNext()) {
  424. Map.Entry<Integer, GuildApply> next = iterator.next();
  425. GuildApply guildApply = next.getValue();
  426. if (now - guildApply.getCreateTime() > SGuildSetting.sGuildSetting.getApplyReserve()) {
  427. GuilidManager.removeOneApplyGuildInfos(guildApply.getGuildId(), guildApply.getId());
  428. iterator.remove();
  429. }
  430. }
  431. }
  432. for (GuildInfo guildInfo : guildInfos) {
  433. builder.addFamilyRecomandInfo(Family.FamilyRecomandInfo.newBuilder().
  434. setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo))
  435. .setIsApply(applyGuildInfos.containsKey(guildInfo.getId()) ? 1 : 0)
  436. .build());
  437. }
  438. MessageUtil.sendMessage(session, 1, msgId, builder.build(), true);
  439. }
  440. /**
  441. * 搜素公会
  442. *
  443. * @param session
  444. * @param searchName
  445. * @throws Exception
  446. */
  447. public static void searchGuild(ISession session, String searchName) throws Exception {
  448. int msgId = MessageTypeProto.MessageType.FAMILY_SEARCH_RESPONSE_VALUE;
  449. if (StringUtil.isEmpty(searchName)) {
  450. throw new ErrorCodeException(ErrorCode.FAMILY_SEARCH_NULL);
  451. }
  452. GuildInfo guildInfo = GuilidManager.guildNameInfoMap.get(searchName);
  453. if (guildInfo == null) {
  454. throw new ErrorCodeException(ErrorCode.FAMILY_NULL);
  455. }
  456. Map<Integer, GuildApply> applyGuildInfos = GuilidManager.getApplyGuildInfos(session.getUid(), 1);
  457. Family.FamilySeachResponse build = Family.FamilySeachResponse.newBuilder().addFamilyRecomandInfo(Family.FamilyRecomandInfo.newBuilder().
  458. setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo))
  459. .setIsApply(applyGuildInfos.containsKey(guildInfo.getId()) ? 1 : 0)
  460. .build()).build();
  461. MessageUtil.sendMessage(session, 1, msgId, build, true);
  462. }
  463. /**
  464. * 申请公会
  465. *
  466. * @param session
  467. * @param applyGuilds
  468. */
  469. public static void applyFamily(ISession session, List<Integer> applyGuilds) throws Exception {
  470. int uid = session.getUid();
  471. User user = UserManager.getUser(uid);
  472. int msgId = MessageTypeProto.MessageType.FAMILY_APPLY_RESPONSE_VALUE;
  473. if (user.getPlayerInfoManager().getGuildId() != 0) {
  474. throw new ErrorCodeException(ErrorCode.FAMILY_IN);
  475. }
  476. if(checkLeaveGuildCDing(user)) {
  477. throw new ErrorCodeException(ErrorCode.LEAVE_GUILD_CD_ING);
  478. }
  479. Map<Integer, GuildApply> applyGuildPersonInfos = GuilidManager.getApplyGuildInfos(session.getUid(), 1);
  480. SGuildSetting guildSetting = SGuildSetting.sGuildSetting;
  481. if (applyGuildPersonInfos.size() >= guildSetting.getApplyLimit()) {
  482. throw new ErrorCodeException(ErrorCode.FAMILY_HAD_APPLY);
  483. }
  484. for (Integer applyGuildId : applyGuilds) {
  485. if (GuilidManager.guildInfoMap.get(applyGuildId).getJoinType() != 0 && applyGuilds.size() == 0) {
  486. if (applyGuilds.size() > 1) {
  487. throw new ErrorCodeException(ErrorCode.FAMILY_LIMIT_CHANGED);
  488. }
  489. continue;
  490. }
  491. GuildApply guildApply = new GuildApply(uid, applyGuildId);
  492. Map<Integer, GuildApply> applyGuildFamilyInfos = GuilidManager.getApplyGuildInfos(applyGuildId, 0);
  493. if (applyGuildFamilyInfos.size() >= guildSetting.getBeApplyLimit()) {
  494. if (applyGuilds.size() > 1) {
  495. throw new ErrorCodeException(ErrorCode.FAMILY_APPLY_LIMIT);
  496. }
  497. continue;
  498. }
  499. GuilidManager.addApplyGuildInfo(guildApply);
  500. Map<Integer, Set<Integer>> members = GuilidManager.guildInfoMap.get(applyGuildId).getMembers();
  501. for (Map.Entry<Integer, Set<Integer>> entry : members.entrySet()) {
  502. if (entry.getValue().size() < 1) {
  503. continue;
  504. }
  505. if (entry.getKey() == 3) {
  506. continue;
  507. }
  508. for (Integer sendUid : entry.getValue()) {
  509. MessageUtil.sendRedIndication(sendUid, GlobalsDef.GUILD_APPLY_TYPE);
  510. }
  511. }
  512. }
  513. MessageUtil.sendMessage(session, 1, msgId, null, true);
  514. }
  515. /**
  516. * 加入公会
  517. *
  518. * @param session
  519. * @param guildId
  520. * @throws Exception
  521. */
  522. public static void joinGuild(ISession session, int guildId) throws Exception {
  523. int uid = session.getUid();
  524. User user = UserManager.getUser(uid);
  525. int msgId = MessageTypeProto.MessageType.FAMILY_JOIN_RESPONSE_VALUE;
  526. if (user.getPlayerInfoManager().getGuildId() != 0) {
  527. throw new ErrorCodeException(ErrorCode.FAMILY_IN);
  528. }
  529. if(checkLeaveGuildCDing(user)){
  530. throw new ErrorCodeException(ErrorCode.LEAVE_GUILD_CD_ING);
  531. }
  532. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  533. if (guildInfo == null) {
  534. throw new ErrorCodeException(ErrorCode.FAMILY_NULL);
  535. }
  536. if (guildInfo.getJoinType() != 1) {
  537. throw new ErrorCodeException(ErrorCode.FAMILY_LIMIT_CHANGED);
  538. }
  539. if (user.getPlayerInfoManager().getLevel() < guildInfo.getIntoLevel()) {
  540. throw new ErrorCodeException(ErrorCode.FAMILY_LIMIT);
  541. }
  542. //todo 判读人数是否已达上限
  543. if (guildInfo.getTotalMembers() >= STableManager.getConfig(SGuildLevelConfig.class).get(guildInfo.getLevel()).getNum()) {
  544. throw new ErrorCodeException(ErrorCode.FAMILY_MAX);
  545. }
  546. boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.OPERATE_FAMILY, Integer.toString(guildId), Integer.toString(uid), 500);
  547. if (!isSuccess) {
  548. throw new ErrorCodeException(ErrorCode.FAMILY_DO_AGAIN);
  549. }
  550. try {
  551. applyToJoin(guildInfo, uid, false);
  552. } finally {
  553. RedisUtil.getInstence().releaseDistributedLock(RedisKey.OPERATE_FAMILY, Integer.toString(guildId), Integer.toString(uid));
  554. }
  555. //设置加入公会时间
  556. user.getGuildMyInfo().setJoinTime(TimeUtils.nowInt());
  557. RedisUtil.getInstence().expire(RedisKey.getKey(RedisKey.FAMILY_JOIN, String.valueOf(uid), false), TimeUtils.DAY);
  558. addGuildLog(guildInfo.getId(), GuildDef.Log.JOIN, user.getPlayerInfoManager().getNickName());
  559. //社稷大典需要初始化分数
  560. Set<Integer> openActivityIdsByType = ActivityLogic.getInstance().getOpenActivityIdsByType(user, ActivityTypeEnum.SHEJI_ACTIVITY.getType(), false);
  561. Poster.getPoster().dispatchEvent(new CommitSheJiEvent(guildId, uid, 0, 0, 0, openActivityIdsByType));
  562. Family.FamilyJoinIndicaion build = Family.FamilyJoinIndicaion.newBuilder().setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo)).setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(user, GlobalsDef.MEMBER)).build();
  563. Family.FamilyJoinResponse response = Family.FamilyJoinResponse.newBuilder().setFamilyJoinIndicaion(build).build();
  564. MessageUtil.sendMessage(session, 1, msgId, response, true);
  565. }
  566. /**
  567. * 获取公会日志信息
  568. *
  569. * @param session
  570. * @throws Exception
  571. */
  572. public static void getGuildLogInfo(ISession session) throws Exception {
  573. int uid = session.getUid();
  574. User user = UserManager.getUser(uid);
  575. int msgId = MessageTypeProto.MessageType.FAMILY_GET_LOG_RESPOSNE_VALUE;
  576. if (user.getPlayerInfoManager().getGuildId() == 0) {
  577. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  578. }
  579. Family.GetFamilyLogResponse.Builder builder = Family.GetFamilyLogResponse.newBuilder();
  580. List<GuildLog> guildLogs = GuilidManager.guildLogInfoMap.get(user.getPlayerInfoManager().getGuildId());
  581. if (guildLogs != null) {
  582. Family.FamilyLogInfo.Builder familyLogInfo;
  583. for (GuildLog guildLog : guildLogs) {
  584. familyLogInfo = Family.FamilyLogInfo.newBuilder();
  585. familyLogInfo.setInfo(guildLog.getInfo());
  586. familyLogInfo.setName(guildLog.getName());
  587. familyLogInfo.setTime(guildLog.getLogTime());
  588. if (guildLog.getGuildParam() != null && guildLog.getGuildParam().size() > 0) {
  589. familyLogInfo.addAllGuildparam(guildLog.getGuildParam());
  590. }
  591. builder.addFamilyLogInfo(familyLogInfo.build());
  592. }
  593. }
  594. MessageUtil.sendMessage(session, 1, msgId, builder.build(), true);
  595. }
  596. /**
  597. * 获取公会成员信息
  598. *
  599. * @param session
  600. */
  601. public static void getGuildMemberInfo(ISession session) throws Exception {
  602. int uid = session.getUid();
  603. User user = UserManager.getUser(uid);
  604. int msgId = MessageTypeProto.MessageType.FAMILY_GET_MEMBER_RESPOSNE_VALUE;
  605. if (user.getPlayerInfoManager().getGuildId() == 0) {
  606. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  607. }
  608. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(user.getPlayerInfoManager().getGuildId());
  609. Family.GetFamilyMemberInfoResponse.Builder builder = Family.GetFamilyMemberInfoResponse.newBuilder();
  610. Map<Integer, Set<Integer>> members = guildInfo.getMembers();
  611. for (Map.Entry<Integer, Set<Integer>> memberEntry : members.entrySet()) {
  612. Integer position = memberEntry.getKey();
  613. Set<Integer> value = memberEntry.getValue();
  614. for (Integer uidTmp : value) {
  615. LOGGER.info("uidTmp={}",uidTmp);
  616. if(uidTmp != null) {
  617. User userTmp = UserManager.getUser(uidTmp);
  618. LOGGER.info("userTmp={}", userTmp);
  619. if (userTmp != null) {
  620. builder.addFamilyUserInfo(CBean2Proto.getFamilyUserInfo(userTmp, position));
  621. }
  622. }
  623. }
  624. }
  625. MessageUtil.sendMessage(session, 1, msgId, builder.build(), true);
  626. }
  627. /**
  628. * 获取申请列表信息
  629. *
  630. * @param session
  631. */
  632. public static void getGuildApplyInfo(ISession session) throws Exception {
  633. int uid = session.getUid();
  634. User user = UserManager.getUser(uid);
  635. int msgId = MessageTypeProto.MessageType.FAMILY_GET_APPLY_RESPOSNE_VALUE;
  636. int guildId = user.getPlayerInfoManager().getGuildId();
  637. if (guildId == 0) {
  638. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  639. }
  640. Map<Integer, GuildApply> applyGuildInfos = GuilidManager.getApplyGuildInfos(guildId, 0);
  641. List<GuildApply> guildApplies = new ArrayList<>();
  642. int now = (int) (System.currentTimeMillis() / 1000);
  643. for (GuildApply guildApply : applyGuildInfos.values()) {
  644. if (now - guildApply.getCreateTime() > SGuildSetting.sGuildSetting.getApplyReserve()) {
  645. GuilidManager.removeOneApplyGuildInfos(guildApply.getGuildId(), guildApply.getId());
  646. continue;
  647. }
  648. int id = guildApply.getId();
  649. User userApply = UserManager.getUser(id);
  650. if (userApply.getPlayerInfoManager().getGuildId() != 0) {
  651. GuilidManager.removeOneApplyGuildInfos(guildId, id);
  652. continue;
  653. }
  654. guildApplies.add(guildApply);
  655. }
  656. Collections.sort(guildApplies);
  657. Family.GetFamilyApplyResponse.Builder builder = Family.GetFamilyApplyResponse.newBuilder();
  658. for (GuildApply guildApply : guildApplies) {
  659. User userTmp = UserManager.getUser(guildApply.getId());
  660. builder.addFamilyApply(CBean2Proto.getFamilyApplyInfo(userTmp, guildApply.getCreateTime())).build();
  661. }
  662. user.getPlayerInfoManager().removeRed(GlobalsDef.GUILD_APPLY_TYPE);
  663. MessageUtil.sendMessage(session, 1, msgId, builder.build(), true);
  664. }
  665. /**
  666. * 操作申请列表
  667. *
  668. * @param session
  669. * @param type
  670. * @param applyId
  671. * @throws Exception
  672. */
  673. public static void operationApplyList(ISession session, int type, int applyId) throws Exception {
  674. int uid = session.getUid();
  675. User user = UserManager.getUser(uid);
  676. int guildId = user.getPlayerInfoManager().getGuildId();
  677. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  678. int msgId = MessageTypeProto.MessageType.FAMILY_OPERATION_APPLY_LIST_RESPONSE_VALUE;
  679. if (getMemberType(uid, guildInfo.getMembers()) >= GlobalsDef.MEMBER) {
  680. throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
  681. }
  682. if (guildId == 0) {
  683. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  684. }
  685. boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.OPERATE_FAMILY_APPLY, Integer.toString(guildId), Integer.toString(uid), 500);
  686. if (!isSuccess) {
  687. throw new ErrorCodeException(ErrorCode.FAMILY_DO_AGAIN);
  688. }
  689. // if(GuildFightLogic.getStatus()!=0&&(type==1||type==3)){
  690. // throw new ErrorCodeException(ErrorCode.FAMILY_NO_APPLY_IN_WAR);
  691. // }
  692. try {
  693. Map<Integer, GuildApply> applyGuild = GuilidManager.getApplyGuildInfos(guildId, 0);
  694. switch (type) {
  695. case 1: //全部同意
  696. Map<Integer, Set<Integer>> members = guildInfo.getMembers();
  697. int count = 0;
  698. for (Set<Integer> memberOfType : members.values()) {
  699. count += memberOfType.size();
  700. }
  701. if (guildInfo.getTotalMembers() + applyGuild.size() > STableManager.getConfig(SGuildLevelConfig.class).get(guildInfo.getLevel()).getNum()) {
  702. throw new ErrorCodeException(ErrorCode.FAMILY_MAXFULL);
  703. }
  704. boolean memberGuild = false;
  705. for (Integer addUid : applyGuild.keySet()) {
  706. if (UserManager.getUser(addUid).getPlayerInfoManager().getGuildId() != 0) {
  707. memberGuild = true;
  708. continue;
  709. }
  710. if (30 - count <= 0) {
  711. break;
  712. }
  713. applyToJoin(guildInfo, addUid, true);
  714. count++;
  715. }
  716. if (memberGuild) {
  717. throw new ErrorCodeException(ErrorCode.FAMILY_SOMEONE_QUIT);
  718. }
  719. for (Map.Entry<Integer, GuildApply> entry : applyGuild.entrySet()) {
  720. GuilidManager.removeOneApplyGuildInfos(entry.getValue().getGuildId(), entry.getValue().getId());
  721. Map<Integer, GuildApply> applyPersonal = GuilidManager.getApplyGuildInfos(entry.getValue().getId(), 1);
  722. for (Map.Entry<Integer, GuildApply> personalEntry : applyPersonal.entrySet()) {
  723. GuilidManager.removeOneApplyGuildInfos(personalEntry.getValue().getGuildId(), personalEntry.getValue().getId());
  724. }
  725. }
  726. break;
  727. case 2: //全部拒绝
  728. Family.RefuseJoinFamily refuse = Family.RefuseJoinFamily.newBuilder().setName(guildInfo.getName()).build();
  729. for (Map.Entry<Integer, GuildApply> entry : applyGuild.entrySet()) {
  730. if (OnlineUserManager.checkUidOnline(applyId)) {
  731. MessageUtil.sendIndicationMessage(OnlineUserManager.getSessionByUid(applyId), 1, MessageTypeProto.MessageType.FAMILY_REFUSE_JOIN_INDICATION_VALUE, refuse, true);
  732. }
  733. GuilidManager.removeOneApplyGuildInfos(entry.getValue().getGuildId(), entry.getValue().getId());
  734. }
  735. break;
  736. case 3: //同意一个
  737. if (UserManager.getUser(applyId).getPlayerInfoManager().getGuildId() != 0) {
  738. throw new ErrorCodeException(ErrorCode.FAMILY_SOMEONE_QUIT);
  739. }
  740. if (guildInfo.getTotalMembers() >= STableManager.getConfig(SGuildLevelConfig.class).get(guildInfo.getLevel()).getNum()) {
  741. throw new ErrorCodeException(ErrorCode.FAMILY_MAX);
  742. }
  743. applyToJoin(guildInfo, applyId, true);
  744. Map<Integer, GuildApply> applyPersonal = GuilidManager.getApplyGuildInfos(applyId, 1);
  745. for (Map.Entry<Integer, GuildApply> personalEntry : applyPersonal.entrySet()) {
  746. GuilidManager.removeOneApplyGuildInfos(personalEntry.getValue().getGuildId(), personalEntry.getValue().getId());
  747. }
  748. break;
  749. case 4: //拒绝一个
  750. GuilidManager.removeOneApplyGuildInfos(guildId, applyId);
  751. Family.RefuseJoinFamily refuseName = Family.RefuseJoinFamily.newBuilder().setName(guildInfo.getName()).build();
  752. ISession targetSession = OnlineUserManager.getSessionByUid(applyId);
  753. if (null != targetSession) {
  754. MessageUtil.sendIndicationMessage(targetSession, 1, MessageTypeProto.MessageType.FAMILY_REFUSE_JOIN_INDICATION_VALUE, refuseName, true);
  755. }
  756. break;
  757. }
  758. } finally {
  759. RedisUtil.getInstence().releaseDistributedLock(RedisKey.OPERATE_FAMILY_APPLY, Integer.toString(guildId), Integer.toString(uid));
  760. }
  761. MessageUtil.sendMessage(session, 1, msgId, null, true);
  762. }
  763. private static void applyToJoin(GuildInfo guildInfo, int applyId, boolean isApply) throws Exception {
  764. boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.OPERATE_FAMILY_APPLY_JOIN, Integer.toString(applyId), Integer.toString(applyId), 500);
  765. if (!isSuccess) {
  766. return;
  767. }
  768. User targetUser = UserManager.getUser(applyId);
  769. try {
  770. if (targetUser.getPlayerInfoManager().getGuildId() != 0) {
  771. return;
  772. }
  773. if(checkLeaveGuildCDing(targetUser)) {
  774. return;
  775. }
  776. GuilidManager.removeOneApplyGuildInfos(guildInfo.getId(), applyId);
  777. guildInfo.addMembers(GlobalsDef.MEMBER, applyId);
  778. targetUser.getPlayerInfoManager().setGuildId(guildInfo.getId());
  779. MessageUtil.sendIndicationMessage(targetUser.getId(), Family.FamilyFeteRewardProcessIndication.newBuilder().setScore(guildInfo.getFete()).build());
  780. PlayerInfoCache cache = RedisUtil.getInstence().getMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(applyId), PlayerInfoCache.class);
  781. cache.setGuildPosition(GlobalsDef.MEMBER);
  782. RedisUtil.getInstence().putMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(applyId), cache);
  783. AyyncWorker ayyncWorker = new AyyncWorker(targetUser, true, new AynMissionWorker(GameEvent.JOIN_FAMILY));
  784. ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
  785. RedisUtil.getInstence().removeMapEntrys(RedisKey.USER_LEVEL_GUILD_INFO, "", String.valueOf(applyId));
  786. Poster.getPoster().dispatchEvent(new GuildForceChangeEvent(targetUser.getId(), targetUser.getPlayerInfoManager().getGuildId(), 1, targetUser.getPlayerInfoManager().getMaxForce()));
  787. Family.GuildHelpInfoIndication.Builder builder = Family.GuildHelpInfoIndication.newBuilder();
  788. for (Map.Entry<Integer, Integer> entry : targetUser.getGuildMyInfo().getGuidHelpInfo().entrySet()) {
  789. builder.addGuildHelpInfo(CommonProto.GuildHelpInfo.newBuilder()
  790. .setHadtakenum(targetUser.getGuildMyInfo().getGuidHelpHadTakeInfo().getOrDefault(entry.getKey(), 0))
  791. .setType(entry.getKey())
  792. .setNum(entry.getValue()));
  793. }
  794. //notify all change
  795. Family.GuildHelpInfoIndication build = builder.setUid(targetUser.getId()).setName(targetUser.getPlayerInfoManager().getNickName()).build();
  796. GuildLogic.sendIndicationToMember(GuilidManager.guildInfoMap.get(guildInfo.getId()), MessageTypeProto.MessageType.GuildHelpInfoIndication, build);
  797. // targetUser.getUserMissionManager().onGameEvent(targetUser, GameEvent.JOIN_FAMILY);
  798. } finally {
  799. RedisUtil.getInstence().releaseDistributedLock(RedisKey.OPERATE_FAMILY_APPLY_JOIN, Integer.toString(applyId), Integer.toString(applyId));
  800. }
  801. if (isApply) {
  802. Family.FamilyJoinIndicaion.Builder builder = Family.FamilyJoinIndicaion.newBuilder();
  803. Family.FamilyJoinIndicaion build = builder.setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo)).setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(targetUser, GlobalsDef.MEMBER)).build();
  804. sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_JOIN_INDICATION, build);
  805. }
  806. //设置加入公会时间
  807. targetUser.getGuildMyInfo().setJoinTime(TimeUtils.nowInt());
  808. //ReportUtil.onReportEvent(targetUser, ReportEventEnum.JOIN_GUILD.getType(),String.valueOf(guildInfo.getId()),guildInfo.getName(),guildInfo.getLevel(),guildInfo.getTotalMembers());
  809. }
  810. /**
  811. * 踢人出宗门
  812. *
  813. * @param session
  814. * @param targetUid
  815. */
  816. public static void kickOutGuild(ISession session, int targetUid) throws Exception {
  817. int uid = session.getUid();
  818. int msgId = MessageTypeProto.MessageType.FAMILY_KICK_OUT_RESPONSE_VALUE;
  819. if (uid == targetUid) {
  820. throw new ErrorCodeException(ErrorCode.FAMILY_NOT_SELF);
  821. }
  822. User user = UserManager.getUser(uid);
  823. int guildId = user.getPlayerInfoManager().getGuildId();
  824. if (guildId == 0) {
  825. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  826. }
  827. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  828. int uidType = getMemberType(uid, guildInfo.getMembers());
  829. int targetType = getMemberType(targetUid, guildInfo.getMembers());
  830. if (uidType > targetType) {
  831. throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
  832. }
  833. if (GuildFightLogic.getStatus() != 0) {
  834. throw new ErrorCodeException(ErrorCode.FAMILY_NOT_KICK_IN_WAR);
  835. }
  836. User targetUser = UserManager.getUser(targetUid);
  837. //TODO lock check
  838. OnUserLeveFamily(targetUser);
  839. Family.KickOutIndication kickIndication = Family.KickOutIndication.newBuilder().setUid(targetUid).build();
  840. sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_KICK_INDICATION, kickIndication);
  841. boolean remove = guildInfo.removeMember(targetType, targetUid);
  842. if (!remove) {
  843. throw new ErrorCodeException(ErrorCode.FAMILY_HAD_KICK);
  844. }
  845. //如果有防守信息则删除
  846. if (guildInfo.getDefendInfo().containsKey((targetUid))) {
  847. guildInfo.removeDefendInfo(targetUid);
  848. }
  849. targetUser.getPlayerInfoManager().setGuildId(0);
  850. targetUser.getGuildMyInfo().clearOfLevelGuild();
  851. addGuildLog(guildInfo.getId(), GuildDef.Log.KICK, targetUser.getPlayerInfoManager().getNickName());
  852. // Family.FamilyKickIndication build = Family.FamilyKickIndication.newBuilder().setType(1).build();
  853. // ISession targetSession = OnlineUserManager.getSessionByUid(targetUid);
  854. // if(targetSession!=null){
  855. //// MessageUtil.sendIndicationMessage(targetSession,1, MessageTypeProto.MessageType.FAMILY_KICK_INDICATION_VALUE,build,true);
  856. // }
  857. String title = SErrorCodeEerverConfig.getI18NMessage("family_kick_title");
  858. List<String> content = SErrorCodeEerverConfig.getI18NMessageNew("family_kick_txt", new Object[]{guildInfo.getName()});
  859. MailLogic.getInstance().sendMail(targetUid, title, content, "", (int) (TimeUtils.now() / 1000), Global.MAIL_EFFECTIVE_TIME);
  860. MessageUtil.sendMessage(session, 1, msgId, null, true);
  861. }
  862. /**
  863. * 任命
  864. *
  865. * @param session
  866. * @param targetUid
  867. * @param position
  868. */
  869. public static void appointMent(ISession session, int targetUid, int position) throws Exception {
  870. int msgId = MessageTypeProto.MessageType.FAMILY_APPOINTMENT_RESPONSE_VALUE;
  871. int uid = session.getUid();
  872. User user = UserManager.getUser(uid);
  873. int guildId = user.getPlayerInfoManager().getGuildId();
  874. if (guildId == 0) {
  875. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  876. }
  877. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  878. int uidType = getMemberType(uid, guildInfo.getMembers());
  879. int targetType = getMemberType(targetUid, guildInfo.getMembers());
  880. if (uidType > 1 || uidType > targetType) {
  881. throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
  882. }
  883. if (GuildFightLogic.getStatus() != 0) {
  884. throw new ErrorCodeException(ErrorCode.FAMILY_APPOINT_NOT_IN_WAR);
  885. }
  886. if (position == 2) {
  887. if (guildInfo.getMembers().get(2) != null && guildInfo.getMembers().get(2).size() >= STableManager.getConfig(SGuildLevelConfig.class).get(guildInfo.getLevel()).getOfficalNum()) {
  888. throw new ErrorCodeException(ErrorCode.FAMILY_LEADER_MAX);
  889. }
  890. }
  891. guildInfo.removeMember(targetType, targetUid);
  892. guildInfo.addMembers(position, targetUid);
  893. // PlayerInfoCache cache = RedisUtil.getInstence().getMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(uid), PlayerInfoCache.class);
  894. // cache.setGuildPosition(position);
  895. // RedisUtil.getInstence().putMapEntry(RedisKey.PLAYER_INFO_CACHE,"",String.valueOf(uid),cache);
  896. PlayerLogic.getInstance().playerInfoUpdate(UserManager.getUser(targetUid));
  897. sendPositionChange(targetUid, position);
  898. User targetUser = UserManager.getUser(targetUid);
  899. if (position == GlobalsDef.CHAIRMAN) {
  900. guildInfo.removeMember(GlobalsDef.CHAIRMAN, uid);
  901. PlayerLogic.getInstance().playerInfoUpdate(user);
  902. guildInfo.addMembers(GlobalsDef.MEMBER, uid);
  903. sendPositionChange(uid, GlobalsDef.CHAIRMAN_TO_MENBER);
  904. addGuildLog(guildInfo.getId(), GuildDef.Log.TRANSFER, targetUser.getPlayerInfoManager().getNickName());
  905. } else {
  906. addGuildLog(guildInfo.getId(), GuildDef.Log.APPOINTMENT, targetUser.getPlayerInfoManager().getNickName());
  907. }
  908. MessageUtil.sendMessage(session, 1, msgId, null, true);
  909. }
  910. /**
  911. * 解散公会
  912. * type 操作类型 1 :解散公会 2 : 取消解散公会
  913. * @param session
  914. */
  915. public static void dissolution(ISession session, int type) throws Exception {
  916. int msgId = MessageTypeProto.MessageType.FAMILY_DISSOLUTION_RESPONSE_VALUE;
  917. int uid = session.getUid();
  918. User user = UserManager.getUser(uid);
  919. int guildId = user.getPlayerInfoManager().getGuildId();
  920. if (guildId == 0) {
  921. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  922. }
  923. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  924. int uidType = getMemberType(uid, guildInfo.getMembers());
  925. if (uidType != 1) {
  926. throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
  927. }
  928. if (type == 1 && guildInfo.getLevelTime() > 0) {
  929. throw new ErrorCodeException(ErrorCode.ALREADY_OPERATED);
  930. }
  931. if (type == 1 && GuildFightLogic.getStatus() != 0) {
  932. throw new ErrorCodeException(ErrorCode.FAMILY_DESTROY_IN_WAR);
  933. }
  934. //解散公会
  935. if (type == 1) {
  936. guildInfo.setLevelTime((int) (System.currentTimeMillis() / 1000));
  937. } else {
  938. guildInfo.setLevelTime(0);
  939. }
  940. sendFamilyBaseUpdateIndication(guildInfo); //公会信息变更推送
  941. GuilidManager.addGuildToRelease(guildInfo); //公会解散信息:删除和增加解散信息
  942. MessageUtil.sendMessage(session, 1, msgId, null, true);
  943. }
  944. /**
  945. * 修改公会名,修改公会宣言
  946. *
  947. * @param session
  948. * @param content
  949. * @param channelId 渠道Id,区分不同的语言版本,限制字符不同
  950. */
  951. public static void changeNotice(ISession session, int type, String content,int channelId) throws Exception {
  952. int msgId = MessageTypeProto.MessageType.FAMILY_CHANGE_NOTICE_RESPONSE_VALUE;
  953. int uid = session.getUid();
  954. User user = UserManager.getUser(uid);
  955. int guildId = user.getPlayerInfoManager().getGuildId();
  956. if (guildId == 0) {
  957. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  958. }
  959. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  960. int uidType = getMemberType(uid, guildInfo.getMembers());
  961. if (uidType > 2) {
  962. throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
  963. }
  964. // if(!Repot37EventUtil.Report37Chat(user, ChatContentType.ANNOUNCE.getType(),content)){
  965. // throw new ErrorCodeException(ErrorCode.FAMILY_IN_SENSITIVE);
  966. // }
  967. boolean result = ShieldedWordUtils.checkName(user, content, false, ChatContentType.ANNOUNCE);
  968. int resultCode = 1;
  969. String err = "修改成功";
  970. if (!result) {
  971. err = "包含铭感字";
  972. resultCode = 0;
  973. }
  974. sendFamilyBaseUpdateIndication(guildInfo);
  975. Family.FamilyChangeResponse response = Family.FamilyChangeResponse.newBuilder().setErr(err).setResult(resultCode).build();
  976. if (resultCode == 0) {
  977. throw new ErrorCodeException(ErrorCode.FAMILY_IN_SENSITIVE);
  978. } else {
  979. if (type == 1) {
  980. if (content.length() < 0 || content.length() > 32) {
  981. throw new ErrorCodeException(ErrorCode.ANNOUNCE_SIZE);
  982. }
  983. guildInfo.setAnnounce(content);
  984. } else {
  985. String oldName=guildInfo.getName();
  986. checkForCreateGuild(user, content, guildInfo.getAnnounce(),channelId);
  987. int[][] renameCost = SGuildSetting.sGuildSetting.getRenameCost();
  988. boolean b = ItemUtil.itemCost(user, renameCost, BIReason.FAMILY_RENAME, 1);
  989. if (!b) {
  990. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  991. }
  992. guildInfo.setName(content);
  993. GuilidManager.changeGuildInfo(guildInfo,oldName);
  994. addGuildLog(guildInfo.getId(), GuildDef.Log.CNAME, user.getPlayerInfoManager().getNickName(),content);
  995. }
  996. MessageUtil.sendMessage(session, resultCode, msgId, response, true);
  997. }
  998. }
  999. /**
  1000. * 修改公会加入类型
  1001. *
  1002. * @param session
  1003. * @param joinType
  1004. * @throws Exception
  1005. */
  1006. public static void changeJoinType(ISession session, int joinType, int joinLevel) throws Exception {
  1007. int msgId = MessageTypeProto.MessageType.FAMILY_CHANGE_JOIN_TYPE_RESPONSE_VALUE;
  1008. if (joinType <= 0 || joinType > 3) {
  1009. throw new ErrorCodeException(ErrorCode.PARAM_ERR);
  1010. }
  1011. int uid = session.getUid();
  1012. User user = UserManager.getUser(uid);
  1013. int guildId = user.getPlayerInfoManager().getGuildId();
  1014. if (guildId == 0) {
  1015. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  1016. }
  1017. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  1018. int uidType = getMemberType(uid, guildInfo.getMembers());
  1019. if (uidType > 2) {
  1020. throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
  1021. }
  1022. guildInfo.updateIntoLevel(joinLevel);
  1023. guildInfo.setJoinType(joinType);
  1024. sendFamilyBaseUpdateIndication(guildInfo);
  1025. MessageUtil.sendMessage(session, 1, msgId, null, true);
  1026. }
  1027. public static void releaseGuild(GuildInfo guildInfo) throws Exception {
  1028. Map<Integer, Set<Integer>> members = guildInfo.getMembers();
  1029. Family.KickOutIndication build = Family.KickOutIndication.newBuilder().build();
  1030. String title = SErrorCodeEerverConfig.getI18NMessage("guild_breakup_title");
  1031. Set<Integer> chairmans = guildInfo.getMembers().get(GlobalsDef.CHAIRMAN);
  1032. Integer chairmanUid = chairmans.iterator().next();
  1033. User chairmanUser = UserManager.getUser(chairmanUid);
  1034. List<String> content = SErrorCodeEerverConfig.getI18NMessageNew("guild_breakup_txt", new String[]{guildInfo.getName(), chairmanUser.getPlayerInfoManager().getNickName()});
  1035. for (Set<Integer> items : members.values()) {
  1036. for (Integer sendUid : items) {
  1037. ISession session = OnlineUserManager.getSessionByUid(sendUid);
  1038. if (session != null) {
  1039. MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.FAMILY_KICK_INDICATION_VALUE, build, true);
  1040. }
  1041. User user = UserManager.getUser(sendUid);
  1042. //TODO lock check
  1043. OnUserLeveFamily(user);
  1044. user.getPlayerInfoManager().setGuildId(0);
  1045. MailLogic.getInstance().sendMail(user.getId(), title, content, "", (int) (System.currentTimeMillis() / 1000), Global.MAIL_EFFECTIVE_TIME);
  1046. }
  1047. }
  1048. GuilidManager.removeGuildInfo(guildInfo);
  1049. MongoUtil.getInstence().lastUpdate();
  1050. }
  1051. public static void chairmanChange(ISession session, int targetUid) throws Exception {
  1052. int msgId = MessageTypeProto.MessageType.FAMILY_TRANSFER_CHAIRMAN_RESPONSE_VALUE;
  1053. int uid = session.getUid();
  1054. User user = UserManager.getUser(uid);
  1055. int guildId = user.getPlayerInfoManager().getGuildId();
  1056. if (guildId == 0) {
  1057. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  1058. }
  1059. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  1060. int uidType = getMemberType(uid, guildInfo.getMembers());
  1061. if (uidType > 1) {
  1062. throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
  1063. }
  1064. guildInfo.removeMember(GlobalsDef.CHAIRMAN, uid);
  1065. guildInfo.addMembers(GlobalsDef.MEMBER, uid);
  1066. guildInfo.addMembers(GlobalsDef.CHAIRMAN, targetUid);
  1067. sendPositionChange(uid, GlobalsDef.MEMBER);
  1068. sendPositionChange(targetUid, GlobalsDef.CHAIRMAN);
  1069. MessageUtil.sendMessage(session, 1, msgId, null, true);
  1070. }
  1071. public static void levelFamily(ISession session) throws Exception {
  1072. int msgId = MessageTypeProto.MessageType.FAMILY_LEVEL_RESPONSE_VALUE;
  1073. int uid = session.getUid();
  1074. User user = UserManager.getUser(uid);
  1075. int guildId = user.getPlayerInfoManager().getGuildId();
  1076. if (guildId == 0) {
  1077. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  1078. }
  1079. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  1080. int uidType = getMemberType(uid, guildInfo.getMembers());
  1081. if (uidType == GlobalsDef.CHAIRMAN) {
  1082. throw new ErrorCodeException(ErrorCode.FAMILY_LEADER_QUIT_ERR);
  1083. }
  1084. if (guildInfo.getDefendInfo().containsKey((uid))) {
  1085. guildInfo.removeDefendInfo(uid);
  1086. }
  1087. //TODO lock check
  1088. OnUserLeveFamily(user);
  1089. user.getPlayerInfoManager().setLeaveGuildTime(System.currentTimeMillis());
  1090. PlayerInfoCache cache = RedisUtil.getInstence().getMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(uid), PlayerInfoCache.class);
  1091. cache.setGuildPosition(0);
  1092. RedisUtil.getInstence().putMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(uid), cache);
  1093. guildInfo.removeMember(uidType, uid);
  1094. user.getPlayerInfoManager().setGuildId(0);
  1095. user.getGuildMyInfo().clearOfLevelGuild();
  1096. addGuildLog(guildInfo.getId(), GuildDef.Log.LEVEL, user.getPlayerInfoManager().getNickName());
  1097. Family.FamilyLeaveResponse builder = Family.FamilyLeaveResponse.newBuilder().setLeaveTime(user.getPlayerInfoManager().getLeaveGuildTime()/1000).build();
  1098. MessageUtil.sendMessage(session, 1, msgId, builder, true);
  1099. }
  1100. public static void sendPositionChange(int uid, int position) throws Exception {
  1101. String title = "";
  1102. String content = "";
  1103. //给玩家发邮件
  1104. switch (position) {
  1105. case 1:
  1106. title = SErrorCodeEerverConfig.getI18NMessage("family_leader_title");
  1107. content = SErrorCodeEerverConfig.getI18NMessage("family_leader_txt");
  1108. break;
  1109. case 2:
  1110. title = SErrorCodeEerverConfig.getI18NMessage("family_position_title");
  1111. content = SErrorCodeEerverConfig.getI18NMessage("family_position_txt");
  1112. break;
  1113. case 3:
  1114. title = SErrorCodeEerverConfig.getI18NMessage("family_relieve_title");
  1115. content = SErrorCodeEerverConfig.getI18NMessage("family_relieve_txt");
  1116. break;
  1117. case 4:
  1118. title = SErrorCodeEerverConfig.getI18NMessage("family_relieved_leader_title");
  1119. content = SErrorCodeEerverConfig.getI18NMessage("family_relieved_leader_txt");
  1120. position = 3;
  1121. break;
  1122. default:
  1123. break;
  1124. }
  1125. if (StringUtil.isEmpty(title) || StringUtil.isEmpty(content)) {
  1126. return;
  1127. }
  1128. MailLogic.getInstance().sendMail(uid, title, content, "", (int) (TimeUtils.now() / 1000), Global.MAIL_EFFECTIVE_TIME);
  1129. Family.FamilyPositionUpdateIndication build = Family.FamilyPositionUpdateIndication.newBuilder().setPosition(position).setUid(uid).build();
  1130. User userInMem = UserManager.getUserInMem(uid);
  1131. sendIndicationToMember(GuilidManager.guildInfoMap.get(userInMem.getPlayerInfoManager().getGuildId()), MessageTypeProto.MessageType.FAMILY_POSITION_UPDATE_INDICAITON, build);
  1132. }
  1133. public static void sendFamilyBaseUpdateIndication(GuildInfo guildInfo) {
  1134. CommonProto.FamilyBaseInfo familyBaseInfo = CBean2Proto.getFamilyBaseInfo(guildInfo);
  1135. Family.FamilyChangeIndication build = Family.FamilyChangeIndication.newBuilder().setFamilyBaseInfo(familyBaseInfo).build();
  1136. sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_CHANGE_BASE_INDICATION, build);
  1137. }
  1138. public static void sendFamilyJoinIndication(int uid, GuildInfo guildInfo) throws Exception {
  1139. ISession session = OnlineUserManager.getSessionByUid(uid);
  1140. if (session != null) {
  1141. User user = UserManager.getUser(uid);
  1142. Family.FamilyJoinIndicaion.Builder builder = Family.FamilyJoinIndicaion.newBuilder();
  1143. Family.FamilyJoinIndicaion build = builder.setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo)).setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(user, GlobalsDef.MEMBER)).build();
  1144. MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.FAMILY_JOIN_INDICATION_VALUE, build, true);
  1145. }
  1146. }
  1147. public static void walkInGuildScene(ISession session, List<Integer> path) throws Exception {
  1148. int msgId = MessageTypeProto.MessageType.FAMILY_WALK_RESPONSE_VALUE;
  1149. int uid = session.getUid();
  1150. User user = UserManager.getUser(uid);
  1151. int guildId = user.getPlayerInfoManager().getGuildId();
  1152. if (guildId == 0) {
  1153. throw new ErrorCodeException(ErrorCode.FAMILY_NO);
  1154. }
  1155. user.getGuildMyInfo().move(System.currentTimeMillis());
  1156. GuildMyInfo guildMyInfo = user.getGuildMyInfo();
  1157. LOGGER.info("cur ={},path={}", guildMyInfo.getCurPos(), path);
  1158. /* boolean continuous = CellUtil.isContinuous(guildMyInfo.getCurPos(),path);
  1159. if(!continuous){
  1160. LOGGER.info("the uid={},path is wrong",uid);
  1161. MessageUtil.sendMessage(session,1, msgId,null,true);
  1162. return;
  1163. }*/
  1164. user.getGuildMyInfo().move(path);
  1165. Family.FamilyWalkIndicaiton familyWalkIndicaiton = CBean2Proto.getFamilyWalkIndicaiton(user);
  1166. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  1167. sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_WALK_INDICATION, familyWalkIndicaiton);
  1168. MessageUtil.sendMessage(session, 1, msgId, null, true);
  1169. }
  1170. public static void updateMyPos(User user) {
  1171. int guildId = user.getPlayerInfoManager().getGuildId();
  1172. if (guildId == 0) {
  1173. return;
  1174. }
  1175. user.getGuildMyInfo().move(new ArrayList<>());
  1176. Family.FamilyWalkIndicaiton familyWalkIndicaiton = CBean2Proto.getFamilyWalkIndicaiton(user);
  1177. GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
  1178. sendIndicationToMember(guildInfo, MessageTypeProto.MessageType.FAMILY_WALK_INDICATION, familyWalkIndicaiton);
  1179. }
  1180. public static void addGuildLog(int guildId, int type, String name,String... params) throws Exception {
  1181. switch (type) {
  1182. case GuildDef.Log.CREATE: {
  1183. // 宗门创立
  1184. GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logCreate", new Object[]{name}));
  1185. GuilidManager.addGuildLog(cGuildLog);
  1186. break;
  1187. }
  1188. case GuildDef.Log.JOIN: {
  1189. // 加入宗门
  1190. GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logJoin", new Object[]{name}));
  1191. GuilidManager.addGuildLog(cGuildLog);
  1192. break;
  1193. }
  1194. case GuildDef.Log.KICK: {
  1195. // 退出宗门
  1196. GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logKick", new Object[]{name}));
  1197. GuilidManager.addGuildLog(cGuildLog);
  1198. break;
  1199. }
  1200. case GuildDef.Log.TRANSFER: {
  1201. // 宗门转让
  1202. GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logTransfer", new Object[]{name}));
  1203. GuilidManager.addGuildLog(cGuildLog);
  1204. break;
  1205. }
  1206. case GuildDef.Log.APPOINTMENT: {
  1207. // 宗门任免
  1208. GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logAppointment", new Object[]{name}));
  1209. GuilidManager.addGuildLog(cGuildLog);
  1210. break;
  1211. }
  1212. case GuildDef.Log.LEVEL: {
  1213. // 宗门退出
  1214. GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logLevel", new Object[]{name}));
  1215. GuilidManager.addGuildLog(cGuildLog);
  1216. break;
  1217. }
  1218. case GuildDef.Log.CNAME: {
  1219. // 宗门退出
  1220. GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.changename", new Object[]{name,params[0]}));
  1221. GuilidManager.addGuildLog(cGuildLog);
  1222. break;
  1223. }
  1224. case GuildDef.Log.IMPEACH: {
  1225. // 会长弹劾
  1226. GuildLog cGuildLog = new GuildLog(guildId, name, SErrorCodeEerverConfig.getI18NMessageNew("guild.logImpeach", new Object[]{name}));
  1227. GuilidManager.addGuildLog(cGuildLog);
  1228. break;
  1229. }
  1230. default: {
  1231. break;
  1232. }
  1233. }
  1234. }
  1235. /**
  1236. * 给公会所有在线成员发送indication
  1237. *
  1238. * @param guildInfo
  1239. * @param messageType
  1240. * @param generatedMessage
  1241. */
  1242. public static void sendIndicationToMember(GuildInfo guildInfo, MessageTypeProto.MessageType messageType, GeneratedMessage generatedMessage) {
  1243. Map<Integer, Set<Integer>> members = guildInfo.getMembers();
  1244. for (Set<Integer> items : members.values()) {
  1245. for (Integer sendUid : items) {
  1246. ISession isession = OnlineUserManager.getSessionByUid(sendUid);
  1247. if (isession != null) {
  1248. LOGGER.info("向{}发送indication", sendUid);
  1249. MessageUtil.sendIndicationMessage(isession, 1, messageType.getNumber(), generatedMessage, true);
  1250. }
  1251. }
  1252. }
  1253. }
  1254. public static void sendIndicationToMemberWithoutUser(GuildInfo guildInfo, MessageTypeProto.MessageType messageType, GeneratedMessage generatedMessage, int withOutUId) {
  1255. Map<Integer, Set<Integer>> members = guildInfo.getMembers();
  1256. for (Set<Integer> items : members.values()) {
  1257. for (Integer sendUid : items) {
  1258. if (sendUid == withOutUId) {
  1259. continue;
  1260. }
  1261. ISession isession = OnlineUserManager.getSessionByUid(sendUid);
  1262. if (isession != null) {
  1263. LOGGER.info("向{}发送indication", sendUid);
  1264. MessageUtil.sendIndicationMessage(isession, 1, messageType.getNumber(), generatedMessage, true);
  1265. }
  1266. }
  1267. }
  1268. }
  1269. /**
  1270. * 修改公会图腾
  1271. *
  1272. * @param session
  1273. * @param iconId
  1274. * @param messageType
  1275. */
  1276. public static void changeFamilyIcon(ISession session, int iconId, MessageTypeProto.MessageType messageType) throws Exception {
  1277. User user = UserManager.getUser(session.getUid());
  1278. PlayerManager playerInfoManager = user.getPlayerInfoManager();
  1279. int[] cost = SGuildSetting.sGuildSetting.getTotemCost();
  1280. int[][] cost1 = new int[1][];
  1281. cost1[0] = cost;
  1282. boolean b = ItemUtil.itemCost(user, cost1, BIReason.FAMILY_SET_ICON, 1);
  1283. if (!b) {
  1284. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  1285. }
  1286. GuilidManager.guildInfoMap.get(playerInfoManager.getGuildId()).updateIcon(iconId);
  1287. 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()));
  1288. MessageUtil.sendMessage(session, 1, messageType.getNumber(), null, true);
  1289. }
  1290. /**
  1291. * 发公会红包
  1292. *
  1293. * @param redId
  1294. * @throws Exception
  1295. */
  1296. public static void sendRedPackage(int uid, int redId) throws Exception {
  1297. User user = UserManager.getUser(uid);
  1298. SGuildRedPackConfig config = SGuildRedPackConfig.sGuildRedPackConfigMap.get(redId);
  1299. if (config == null) {
  1300. return;
  1301. }
  1302. int maxCount = config.getTotalMoney()[1];
  1303. long[] generate = HongBaoAlgorithm.generate(maxCount, config.getNum(), maxCount * config.getMaxPercent() / 10000, maxCount * config.getMinPercent() / 10000);
  1304. if (generate == null) {
  1305. throw new ErrorCodeException(ErrorCode.RED_PACKAGE_NOT);
  1306. }
  1307. long increment = RedisUtil.getInstence().increment(RedisKey.getKey(RedisKey.FAMILY_RED_PACKAGE_INCRE_ID, "", false));
  1308. 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()));
  1309. List<String> reward = new ArrayList<>();
  1310. for (Long count : generate) {
  1311. reward.add(String.valueOf(count));
  1312. }
  1313. AbstractRank rank = RankContext.getRankEnum(RankEnum.GUILD_RED_PACKAGE_RANK.getType());
  1314. double scoreById = rank.getScoreById(uid, String.valueOf(user.getPlayerInfoManager().getGuildId()));
  1315. double price = SRechargeCommodityConfig.rechargeCommodityConfigMap.get(config.getTradeId()).getPrice();
  1316. if (scoreById == -1 || scoreById == 0) {
  1317. price += TimeUtils.getDoubleTime();
  1318. } else {
  1319. price += scoreById;
  1320. }
  1321. rank.addRank(uid, String.valueOf(user.getPlayerInfoManager().getGuildId()), price);
  1322. RedisUtil.getInstence().lSet(RedisKey.getKey("red_remain_list", String.valueOf(increment), false), reward, config.getLastTime());
  1323. }
  1324. /**
  1325. * 获取所有红包信息
  1326. *
  1327. * @param session
  1328. * @param messageType
  1329. */
  1330. public static void getAllRedPackageInfo(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1331. User user = UserManager.getUser(session.getUid());
  1332. int guildId = user.getPlayerInfoManager().getGuildId();
  1333. Map<String, RedPackage> redPackageMap = RedisUtil.getInstence().getMapValues(RedisKey.FAMILY_RED_PACKAGE, String.valueOf(guildId), String.class, RedPackage.class);
  1334. Family.GetAllRedPackageResponse.Builder builder = Family.GetAllRedPackageResponse.newBuilder();
  1335. List<String> removeId = new ArrayList<>();
  1336. for (Map.Entry<String, RedPackage> entry : redPackageMap.entrySet()) {
  1337. if (TimeUtils.now() / 1000 > entry.getValue().getEffectTime() + entry.getValue().getSendTime()) {
  1338. removeId.add(entry.getKey());
  1339. continue;
  1340. }
  1341. CommonProto.RedPackage.Builder redPackage = CommonProto.RedPackage.newBuilder();
  1342. redPackage.setGetCount(RedisUtil.getInstence().getMapValues("red_already_list", entry.getKey(), int.class, AcceptRedInfo.class).size());
  1343. AcceptRedInfo already = RedisUtil.getInstence().getMapEntry("red_already_list", entry.getKey(), String.valueOf(session.getUid()), AcceptRedInfo.class);
  1344. redPackage.setIsGet(already == null ? 0 : 1);
  1345. redPackage.setRedId(Integer.parseInt(entry.getKey()));
  1346. redPackage.setUserName(UserManager.getUser(entry.getValue().getUid()).getPlayerInfoManager().getNickName());
  1347. redPackage.setRedType(entry.getValue().getTypeId());
  1348. redPackage.setSendTime(entry.getValue().getSendTime());
  1349. builder.addInfo(redPackage);
  1350. }
  1351. for (String id : removeId) {
  1352. RedisUtil.getInstence().removeMapEntrys(RedisKey.FAMILY_RED_PACKAGE, String.valueOf(guildId), id);
  1353. }
  1354. MessageUtil.sendMessage(session, 1, messageType.getNumber(), builder.build(), true);
  1355. }
  1356. /**
  1357. * 抢红包
  1358. */
  1359. public static void robRedPackage(ISession session, int redId, MessageTypeProto.MessageType messageType) throws Exception {
  1360. int uid = session.getUid();
  1361. AcceptRedInfo isAlready = RedisUtil.getInstence().getMapValue("red_already_list", String.valueOf(redId), String.valueOf(uid), AcceptRedInfo.class);
  1362. if (isAlready != null) {
  1363. throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
  1364. }
  1365. Object redPackage = RedisUtil.getInstence().lPop(RedisKey.getKey("red_remain_list", String.valueOf(redId), false));
  1366. Family.RobRedPackageResponse.Builder builder = Family.RobRedPackageResponse.newBuilder();
  1367. if (redPackage != null) {
  1368. builder.setIsSuccess(1);
  1369. RedPackage packInfo = RedisUtil.getInstence().getMapValue(RedisKey.FAMILY_RED_PACKAGE, String.valueOf(UserManager.getUser(uid).getPlayerInfoManager().getGuildId()), String.valueOf(redId), RedPackage.class);
  1370. if (packInfo == null) {
  1371. throw new ErrorCodeException(ErrorCode.FAMILY_NULL);
  1372. }
  1373. SGuildRedPackConfig config = SGuildRedPackConfig.sGuildRedPackConfigMap.get(packInfo.getTypeId());
  1374. int count = Integer.parseInt(String.valueOf(redPackage));
  1375. ItemUtil.drop(UserManager.getUser(uid), new int[][]{new int[]{config.getTotalMoney()[0], count}}, BIReason.RED_PACKAGE_REWARD);
  1376. builder.setCount(count);
  1377. builder.setItemId(config.getTotalMoney()[0]);
  1378. int position = getMemberType(uid, GuilidManager.guildInfoMap.get(UserManager.getUser(uid).getPlayerInfoManager().getGuildId()).getMembers());
  1379. RedisUtil.getInstence().putMapEntry("red_already_list", String.valueOf(redId), String.valueOf(uid), new AcceptRedInfo(uid, config.getTotalMoney()[0], count, (int) (TimeUtils.now() / 1000), position));
  1380. } else {
  1381. throw new ErrorCodeException(ErrorCode.RED_PACKAGE_NOT);
  1382. }
  1383. MessageUtil.sendMessage(session, 1, messageType.getNumber(), builder.build(), true);
  1384. }
  1385. /**
  1386. * 查看红包详情
  1387. *
  1388. * @param session
  1389. * @param redId
  1390. * @param messageType
  1391. */
  1392. public static void getRedPackageDetail(ISession session, int redId, MessageTypeProto.MessageType messageType) throws Exception {
  1393. Map<Integer, AcceptRedInfo> alreadyList = RedisUtil.getInstence().getMapValues("red_already_list", String.valueOf(redId), Integer.class, AcceptRedInfo.class);
  1394. int guildId = UserManager.getUser(session.getUid()).getPlayerInfoManager().getGuildId();
  1395. Family.RedPackageDetailResponse.Builder builder = Family.RedPackageDetailResponse.newBuilder();
  1396. if (!alreadyList.isEmpty()) {
  1397. for (Map.Entry<Integer, AcceptRedInfo> already : alreadyList.entrySet()) {
  1398. PlayerManager playerInfoManager = UserManager.getUser(already.getValue().getUid()).getPlayerInfoManager();
  1399. CommonProto.RedOneDetail.Builder detail = CommonProto.RedOneDetail.newBuilder()
  1400. .setUid(already.getValue().getUid())
  1401. .setHead(playerInfoManager.getHead())
  1402. .setHeadFrame(playerInfoManager.getHeadFrame())
  1403. .setName(playerInfoManager.getNickName())
  1404. .setTime(already.getValue().getTime())
  1405. .setItemId(already.getValue().getItemId())
  1406. .setCount(already.getValue().getCount())
  1407. .setPosition(already.getValue().getPosition());
  1408. builder.addInfo(detail.build());
  1409. }
  1410. }
  1411. RedPackage packInfo = RedisUtil.getInstence().getMapValue(RedisKey.FAMILY_RED_PACKAGE, String.valueOf(guildId), String.valueOf(redId), RedPackage.class);
  1412. PlayerManager playerInfoManager = UserManager.getUser(packInfo.getUid()).getPlayerInfoManager();
  1413. builder.setSendName(playerInfoManager.getNickName())
  1414. .setHead(playerInfoManager.getHead())
  1415. .setHeadFrame(playerInfoManager.getHeadFrame())
  1416. .setRemainTime(packInfo.getSendTime() + packInfo.getEffectTime() - (int) (TimeUtils.now() / 1000));
  1417. MessageUtil.sendMessage(session, 1, messageType.getNumber(), builder.build(), true);
  1418. }
  1419. /**
  1420. * 点赞!
  1421. *
  1422. * @param session
  1423. * @param targetUid
  1424. * @param messageType
  1425. */
  1426. public static void redPackageSendLike(ISession session, int targetUid, MessageTypeProto.MessageType messageType) throws Exception {
  1427. User user = UserManager.getUser(session.getUid());
  1428. int guildId = user.getPlayerInfoManager().getGuildId();
  1429. Double price = RedisUtil.getInstence().getZSetScore(RedisKey.GUILD_RED_PACKAGE_RANK, String.valueOf(guildId), String.valueOf(targetUid));
  1430. if (price <= 0) {
  1431. throw new ErrorCodeException(ErrorCode.AMOUNT_ERR);
  1432. }
  1433. if (user.getFriendManager().getTodayLike().contains(targetUid)) {
  1434. throw new ErrorCodeException(ErrorCode.ALREADY_LIKE);
  1435. }
  1436. ItemUtil.drop(user, new int[][]{SGuildSetting.sGuildSetting.getGiveLikeReward()}, BIReason.SEND_LIKE_REWARD);
  1437. User targetUser = UserManager.getUser(targetUid);
  1438. AyyncWorker ayyncWorker = new AyyncWorker(targetUser, true, n -> targetUser.getFriendManager().addBeLikedCount(1));
  1439. user.getFriendManager().addTodayLike(targetUid);
  1440. ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
  1441. MessageUtil.sendMessage(session, 1, messageType.getNumber(), null, true);
  1442. }
  1443. /**
  1444. * 获取今天给谁点过赞
  1445. *
  1446. * @param session
  1447. * @param messageType
  1448. */
  1449. public static void getAllTodayLike(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1450. User user = UserManager.getUser(session.getUid());
  1451. Family.GetAllSendLikeResponse response = Family.GetAllSendLikeResponse.newBuilder().addAllUid(user.getFriendManager().getTodayLike()).build();
  1452. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
  1453. }
  1454. /**
  1455. * 获取所有公会技能
  1456. *
  1457. * @param session
  1458. * @param messageType
  1459. * @throws Exception
  1460. */
  1461. public static void getAllSkill(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1462. User user = UserManager.getUser(session.getUid());
  1463. Map<Integer, Integer> guildSkill = user.getGuildMyInfo().getGuildSkill();
  1464. Family.GetAllGuildSkillResponse.Builder response = Family.GetAllGuildSkillResponse.newBuilder();
  1465. for (Map.Entry<Integer, Integer> entry : guildSkill.entrySet()) {
  1466. Family.GuildSkill skill = Family.GuildSkill.newBuilder().setType(entry.getKey()).setLevel(entry.getValue()).build();
  1467. response.addSkill(skill);
  1468. }
  1469. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response.build(), true);
  1470. }
  1471. /**
  1472. * 公会技能升级
  1473. *
  1474. * @param session
  1475. * @param type
  1476. * @param messageType
  1477. */
  1478. public static void guildSkillLevelUp(ISession session, int type, MessageTypeProto.MessageType messageType) throws Exception {
  1479. User user = UserManager.getUser(session.getUid());
  1480. //todo 消耗校验
  1481. Map<Integer, Integer> skillInfo = user.getGuildMyInfo().getGuildSkill();
  1482. Map<Integer, Map<Integer, SGuildTechnology>> typeMap = SGuildTechnology.technologyMap.get(type);
  1483. int size = typeMap.size();
  1484. int[][] consume;
  1485. int level =0;
  1486. if (!skillInfo.containsKey(type)) {
  1487. consume = typeMap.get(1).get(0).getConsume();
  1488. } else {
  1489. level = skillInfo.get(type);
  1490. consume = typeMap.get(level % size + 1).get(level / size).getConsume();
  1491. if (typeMap.get(level % size + 1).get(level / size + 1) == null) {
  1492. throw new ErrorCodeException(ErrorCode.HERO_LEVE_MAX);
  1493. }
  1494. }
  1495. boolean itemCost = ItemUtil.itemCost(user, consume, BIReason.GUILD_SKILL_LEVEL_UP_CONSUME, 1);
  1496. if (!itemCost) {
  1497. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  1498. }
  1499. user.getGuildMyInfo().addGuildSkillByType(type);
  1500. Poster.getPoster().dispatchEvent(new UserMainTeamForceEvent(session.getUid()));
  1501. user.getUserMissionManager().onGameEvent(user, GameEvent.GUILD_ACTIVE_MISSION_UPDATE, 127);
  1502. user.getUserMissionManager().onGameEvent(user, GameEvent.GUILD_SKILL_LEVEL_UP_TIMES);
  1503. user.getUserMissionManager().onGameEvent(user, GameEvent.GUILD_TECH_LEVEL, type,level);
  1504. MessageUtil.sendMessage(session, 1, messageType.getNumber(), null, true);
  1505. }
  1506. /**
  1507. * 公会技能重置
  1508. *
  1509. * @param session
  1510. * @param type
  1511. * @param messageType
  1512. */
  1513. public static void resetGuildSkill(ISession session, int type, MessageTypeProto.MessageType messageType) throws Exception {
  1514. User user = UserManager.getUser(session.getUid());
  1515. GuildMyInfo guildMyInfo = user.getGuildMyInfo();
  1516. if (!guildMyInfo.getGuildSkill().containsKey(type)) {
  1517. throw new ErrorCodeException(ErrorCode.GUILD_SKILL_NULL);
  1518. }
  1519. int level = guildMyInfo.getGuildSkill().get(type);
  1520. int size = SGuildTechnology.technologyMap.get(type).size();
  1521. String err = StoreLogic.checkBuyGoodsAndUpdate(user, 7, 10028, 1);
  1522. if (!err.isEmpty()) {
  1523. throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
  1524. }
  1525. List<int[]> consume = new ArrayList<>();
  1526. for (int i = 1; i <= size; i++) {
  1527. int baseLevel = level / size;
  1528. if (level % size >= i) {
  1529. baseLevel += 1;
  1530. }
  1531. Map<Integer, SGuildTechnology> levelMap = SGuildTechnology.technologyMap.get(type).get(i);
  1532. for (int j = 0; j < baseLevel; j++) {
  1533. SGuildTechnology sGuildTechnology = levelMap.get(j);
  1534. consume.addAll(Arrays.asList(sGuildTechnology.getConsume()));
  1535. }
  1536. }
  1537. int percent = SSpecialConfig.getIntegerValue(SSpecialConfig.GUILD_TECHNOLOGY_RETURN_PERCENT);
  1538. int[][] dropArray = consume.toArray(new int[consume.size()][]);
  1539. Map<Integer, Integer> reward = new HashMap<>();
  1540. for (int[] aDropArray : dropArray) {
  1541. if (aDropArray.length < 2) {
  1542. continue;
  1543. }
  1544. if (!reward.containsKey(aDropArray[0])) {
  1545. reward.put(aDropArray[0], 0);
  1546. }
  1547. reward.put(aDropArray[0], reward.get(aDropArray[0]) + aDropArray[1]);
  1548. }
  1549. int[][] dropArrayReally = new int[reward.size()][];
  1550. int index = 0;
  1551. for (Map.Entry<Integer, Integer> entry : reward.entrySet()) {
  1552. double doublePercent = (double) percent;
  1553. dropArrayReally[index] = new int[]{entry.getKey(), (int) (entry.getValue() * doublePercent / 10000)};
  1554. index++;
  1555. }
  1556. CommonProto.Drop.Builder drop = ItemUtil.drop(user, dropArrayReally, BIReason.RESET_GUILD_SKILL);
  1557. guildMyInfo.removeGuildSkillByType(type);
  1558. Family.ResetGuildSkillResponse response = Family.ResetGuildSkillResponse.newBuilder().setDrop(drop).build();
  1559. Poster.getPoster().dispatchEvent(new UserMainTeamForceEvent(session.getUid()));
  1560. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
  1561. }
  1562. public static CommonProto.GuildHelpLog getLog(GuildHelpLog log) {
  1563. return CommonProto.GuildHelpLog.newBuilder()
  1564. .setHelperuid(log.getHelpId()).setTargetuid(log.getTargetId())
  1565. .setHelpername(log.getHelperName())
  1566. .setTargetname(log.getTargetName())
  1567. .setTime(log.getLogTime())
  1568. .setType(log.getType()).build();
  1569. }
  1570. /**
  1571. * 公会id清零之前调用
  1572. *
  1573. * @param user
  1574. * @throws Exception
  1575. */
  1576. public static void OnUserLeveFamily(User user) throws Exception {
  1577. //TODO lock all 公会id清零之前调用
  1578. //退公会清除数据 补发奖励
  1579. sendGuildHelpRewardEmail(user);
  1580. int guildId = user.getPlayerInfoManager().getGuildId();
  1581. //注掉原因:这是梦魇入侵的排行不要在这清
  1582. //RedisUtil.getInstence().zsetRemoveOne(RedisKey.getKey(RedisKey.CAR_DEALY_RANK, "", false), String.valueOf(user.getId()));
  1583. RedisUtil.getInstence().putMapEntry(RedisKey.USER_LEVEL_GUILD_INFO, "", String.valueOf(user.getId()), guildId);
  1584. //删除战力
  1585. Poster.getPoster().dispatchEvent(new GuildForceChangeEvent(user.getId(), user.getPlayerInfoManager().getGuildId(), 3, 0 - user.getPlayerInfoManager().getMaxForce()));
  1586. //notify ALL
  1587. Family.GuildHelpInfoIndication.Builder build = Family.GuildHelpInfoIndication.newBuilder();
  1588. for (Map.Entry<Integer, Integer> entry : user.getGuildMyInfo().getGuidHelpInfo().entrySet()) {
  1589. //通知前端清除公会成员援助信息
  1590. build.setUid(user.getId());
  1591. build.addGuildHelpInfo(CommonProto.GuildHelpInfo.newBuilder().setType(entry.getKey()).setNum(-1));
  1592. }
  1593. GuildLogic.sendIndicationToMember(GuilidManager.guildInfoMap.get(user.getPlayerInfoManager().getGuildId()), MessageTypeProto.MessageType.GuildHelpInfoIndication, build.build());
  1594. }
  1595. //sendGuildHelpRewardEmail
  1596. public static void sendGuildHelpRewardEmail(User user) throws Exception {
  1597. // 补发奖励
  1598. GuildMyInfo guildMyInfo = user.getGuildMyInfo();
  1599. String title = SErrorCodeEerverConfig.getI18NMessage("guildhelp_reward_title");
  1600. String content = SErrorCodeEerverConfig.getI18NMessage("guildhelp_reward_txt");
  1601. List<int[][]> list = new LinkedList<>();
  1602. for (Map.Entry<Integer, Integer> entry : user.getGuildMyInfo().getGuidHelpInfo().entrySet()) {
  1603. int i = entry.getValue() - user.getGuildMyInfo().getGuidHelpHadTakeInfo().getOrDefault(entry.getKey(), 0);
  1604. if (i <= 0) {
  1605. continue;
  1606. }
  1607. int[][] drop = new int[1][];
  1608. drop[0] = new int[2];
  1609. drop[0][0] = entry.getKey();
  1610. drop[0][1] = i;
  1611. list.add(drop);
  1612. guildMyInfo.putGuidHelpHadTakeInfo(entry.getKey(), entry.getValue());
  1613. }
  1614. if (list.size() == 0) {
  1615. return;
  1616. }
  1617. boolean isfinish = true;
  1618. SGuildHelpConfig sGuildHelpConfig = STableManager.getConfig(SGuildHelpConfig.class).get(1);
  1619. if (guildMyInfo.getGuidHelpHadTakeInfo().size() == sGuildHelpConfig.getRecourseTime()[0]) {
  1620. for (Map.Entry<Integer, Integer> entry : guildMyInfo.getGuidHelpHadTakeInfo().entrySet()) {
  1621. if (entry.getValue() < sGuildHelpConfig.getRecourseTime()[1]) {
  1622. isfinish = false;
  1623. break;
  1624. }
  1625. }
  1626. } else {
  1627. isfinish = false;
  1628. }
  1629. if (isfinish && !guildMyInfo.isGuildHelpReward()) {
  1630. list.add(sGuildHelpConfig.getReward());
  1631. guildMyInfo.setGuildHelpReward(true);
  1632. }
  1633. String mailReward = ItemUtil.getMailReward(list);
  1634. MailLogic.getInstance().sendMail(user.getId(), title, content, mailReward, (int) (TimeUtils.now() / 1000), Global.MAIL_EFFECTIVE_TIME);
  1635. }
  1636. /**
  1637. * 是否在退出公会CD中
  1638. * @param user
  1639. * @return
  1640. */
  1641. public static boolean checkLeaveGuildCDing(User user){
  1642. int CD_TIME = SSpecialConfig.getIntegerValue("Guild_Rejion_Cdtime");//冷却小时
  1643. if(CD_TIME <= 0) return false;
  1644. long leaveGuildTime = user.getPlayerInfoManager().getLeaveGuildTime();
  1645. if(leaveGuildTime > 0) {
  1646. long endTime = TimeUtils.getTimeBeforeOrAfterMinute(leaveGuildTime,CD_TIME * TimeUtils.MIN_HOUR);
  1647. if(System.currentTimeMillis() <= endTime) {
  1648. return true;
  1649. }
  1650. }
  1651. return false;
  1652. }
  1653. }