From 86a91c0c2adc352f9a99053f006010d7904f97c4 Mon Sep 17 00:00:00 2001 From: xuexinpeng Date: Wed, 23 Mar 2022 13:47:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A2=E7=B4=A2=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/explorerMap/ExplorerMapLogic.java | 85 +++++++++++-------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/explorerMap/ExplorerMapLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/explorerMap/ExplorerMapLogic.java index 241e7878c..0b4d5f3c2 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/explorerMap/ExplorerMapLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/explorerMap/ExplorerMapLogic.java @@ -9,7 +9,6 @@ import com.ljsd.jieling.globals.Global; import com.ljsd.jieling.logic.GlobleSystemLogic; import com.ljsd.jieling.logic.OnlineUserManager; import com.ljsd.jieling.logic.activity.ActivityLogic; -import com.ljsd.jieling.logic.activity.ActivityType; import com.ljsd.jieling.logic.activity.ActivityTypeEnum; import com.ljsd.jieling.logic.activity.crossService.CrossServiceLogic; import com.ljsd.jieling.logic.activity.event.ExploreEvent; @@ -119,11 +118,11 @@ public class ExplorerMapLogic { explorerInfo.setPlayerHp(explorerInfo.getPlayerHp() - reducePlayer); explorerInfo.setEnemyHp(0); LOGGER.info("{}玩家掉血:=》{},剩余血量-》{}", user.getId(), reducePlayer, explorerInfo.getPlayerHp()); - LOGGER.info("{}玩家赢了 怪物死 怪物走复活逻辑=>{} 掉落组=>{}",user.getId(), explorerInfo.getEnemyReliveTime(), exploreConfig.getReward()); + LOGGER.info("{}玩家赢了 怪物死 怪物走复活逻辑=>{} 掉落组=>{}", user.getId(), explorerInfo.getEnemyReliveTime(), exploreConfig.getReward()); //活动是否开启 Set openActivityIdsByType = ActivityLogic.getInstance().getOpenActivityIdsByType(user, ActivityTypeEnum.EXPLORE_EXPECT_ACTIVITY.getType(), false); //if (ActivityLogic.checkActivityOpen(user, ActivityType.EXPLORE_EXPECT_ACTIVITY)) { - if(openActivityIdsByType.size()>0){ + if (openActivityIdsByType.size() > 0) { //同个工会 死亡计数 int guildId = user.getPlayerInfoManager().getGuildId(); if (guildId != 0) { @@ -133,7 +132,7 @@ public class ExplorerMapLogic { Poster.getPoster().dispatchEvent(new ExploreEvent(user.getId(), 1)); Set allUid = new HashSet<>(); allUid.addAll(guildInfo.getMembers().get(GlobalsDef.CHAIRMAN)); - if(guildInfo.getMembers().get(GlobalsDef.MEMBER)!=null){ + if (guildInfo.getMembers().get(GlobalsDef.MEMBER) != null) { allUid.addAll(guildInfo.getMembers().get(GlobalsDef.MEMBER)); } for (int uid : allUid) { @@ -161,7 +160,7 @@ public class ExplorerMapLogic { } //玩家死亡 设置重生时间 if (explorerInfo.getPlayerHp() == 0) { - explorerInfo.setDeathNum(explorerInfo.getDeathNum()+1); + explorerInfo.setDeathNum(explorerInfo.getDeathNum() + 1); int reliveTime = SSpecialConfig.getIntegerValue(SSpecialConfig.EXPLORERE_LIVETIME); if (time == 0) { explorerInfo.setPlayerReliveTime(TimeUtils.nowInt() + reliveTime); @@ -172,14 +171,14 @@ public class ExplorerMapLogic { } //怪物死亡 设置重生时间 if (explorerInfo.getEnemyHp() == 0) { - explorerInfo.setKillNum(explorerInfo.getKillNum()+1); + explorerInfo.setKillNum(explorerInfo.getKillNum() + 1); if (time == 0) { explorerInfo.setEnemyReliveTime(TimeUtils.nowInt() + exploreConfig.getBattleInterval()); } else { explorerInfo.setEnemyReliveTime(time + exploreConfig.getBattleInterval()); } LOGGER.info("{}怪物死亡=》重生时间{}", user.getId(), explorerInfo.getEnemyReliveTime()); - RankEnum.toRank(RankEnum.EXPLORE_RANK.getType()).incrementRankScore(user.getId(),"",1); + RankEnum.toRank(RankEnum.EXPLORE_RANK.getType()).incrementRankScore(user.getId(), "", 1); user.getUserMissionManager().onGameEvent(user, GameEvent.EXPLORE, MissionType.EXPLORE_ENEMY_NUM, 1); @@ -225,6 +224,27 @@ public class ExplorerMapLogic { .build(); } + public static void sendRandomEvent(User user) { + ISession sess = OnlineUserManager.sessionMap.get(user.getId()); + Map config = STableManager.getConfig(SExplore.class); + Map exploreEventConfig = STableManager.getConfig(SExploreEvent.class); + List limitConfig = config.values().stream().filter(n -> n.getLevel() <= user.getPlayerInfoManager().getLevel()).collect(Collectors.toList()); + Random random = new Random(); + int randomMapId = random.nextInt(limitConfig.size()); + SExplore rankExplore = limitConfig.get(randomMapId); + int randomEventId = random.nextInt(rankExplore.getEventList().length); + int eventId = rankExplore.getEventList()[randomEventId]; + LOGGER.info("explore add eventId:" + eventId + " randomMapId: " + randomMapId); + user.getPlayerInfoManager().addExploreEvent(new KeyVal(eventId, TimeUtils.nowInt() + exploreEventConfig.get(eventId).getTime(), randomMapId + 1)); + PlayerInfoProto.ExplorerMapIndicationResponse.Builder indication = PlayerInfoProto.ExplorerMapIndicationResponse.newBuilder(); + List event = user.getPlayerInfoManager().getExploreEvent(); + for (KeyVal keyVal : event) { + indication.addRandEvent(CommonProto.CommKeyVal.newBuilder().setKey(keyVal.getKey()).setVal(keyVal.getVal()). + setVal2(keyVal.getVa2()).build()); + } + MessageUtil.sendIndicationMessage(sess, 1, MessageTypeProto.MessageType.ExplorerMapIndicationResponse_VALUE, indication.build(), true); + } + public void calOfflineReward(User user) throws Exception { //计算离线奖励 Map explorer = user.getPlayerInfoManager().getExplorer(); @@ -252,6 +272,11 @@ public class ExplorerMapLogic { continue; } LOGGER.info("离线玩家队伍id", keyVal.getKey()); + //探索事件 + long gapDay = TimeUtils.getGapDaysByTwoTime( TimeUtils.getTimeStamp2(keyVal.getValue().getBatteTime()*1000L), TimeUtils.getTimeStamp2(offlineEndTime*1000L)); + for(int i = 0;i< gapDay;i++){ + sendRandomEvent(user); + } for (int i = keyVal.getValue().getBatteTime(); i <= offlineEndTime; i = i + battleInterval) { //复活玩家 if (keyVal.getValue().getPlayerHp() == 0 && keyVal.getValue().getPlayerReliveTime() <= i) { @@ -282,21 +307,13 @@ public class ExplorerMapLogic { long now = TimeUtils.now(); for (int uid : uids) { User user = UserManager.getUser(uid); - if(user == null){ + if (user == null) { continue; } //登录一分钟后才执行 避免消息线程和分钟线程同时修改数据 - if(now < user.getPlayerInfoManager().getLoginTime()+60000){ + if (now < user.getPlayerInfoManager().getLoginTime() + 60000) { continue; } - //整点刷出随机事件 - Calendar calendar = Calendar.getInstance(); - int minute = calendar.get(Calendar.MINUTE); - //sendRandomEvent(user); - MongoUtil.getLjsdMongoTemplate().lastUpdate(); - if(minute == 0){ - sendRandomEvent(user); - } Map explorer = user.getPlayerInfoManager().getExplorer(); if (explorer == null || explorer.size() == 0) { continue; @@ -304,7 +321,7 @@ public class ExplorerMapLogic { List delayId = new ArrayList<>(); List deleteMapPlayer = new ArrayList<>(); //地图玩家信息 for (Map.Entry keyVal : explorer.entrySet()) { - if(keyVal.getValue().getMapId() == 0){ + if (keyVal.getValue().getMapId() == 0) { delayId.add(keyVal.getKey()); continue; } @@ -384,14 +401,13 @@ public class ExplorerMapLogic { MailLogic.getInstance().sendMail(uid, title, content, "", TimeUtils.nowInt(), Global.MAIL_EFFECTIVE_TIME); } else { - String title = SErrorCodeEerverConfig.getI18NMessage("exploresuccess_mail_title"); String content = SErrorCodeEerverConfig.getFormatMessage("exploresuccess_mail_txt", new Object[]{ - teamName, mapName, hour,explorer.get(id).getKillNum(),explorer.get(id).getDeathNum()}); + teamName, mapName, hour, explorer.get(id).getKillNum(), explorer.get(id).getDeathNum()}); //CommonProto.Drop.Builder drop = ItemUtil.drop(user, explorer.get(id).getDropItem().stream().toArray(int[][]::new), BIReason.EXPEDITION_BOX_REWARD); int[][] dropArray = explorer.get(id).getDropMap().entrySet().stream().map(n -> new int[]{n.getKey(), n.getValue()}).toArray(int[][]::new); String reward = StringUtil.parseArrayToString(dropArray); - LOGGER.info("{}探索{}小时到期发id=>{}邮件,邮件内容=>{}",uid,hour,id,reward); + LOGGER.info("{}探索{}小时到期发id=>{}邮件,邮件内容=>{}", uid, hour, id, reward); MailLogic.getInstance().sendMail(uid, title, content, reward, TimeUtils.nowInt(), Global.MAIL_EFFECTIVE_TIME); } @@ -407,6 +423,17 @@ public class ExplorerMapLogic { if (delayId.size() > 0) { user.getPlayerInfoManager().setExplorer(explorer); } + + //探索有消耗 整点刷出随机事件 + if (explorer.size() > 0) { + Calendar calendar = Calendar.getInstance(); + /*int minute = calendar.get(Calendar.MINUTE); + if (minute == 0) { + sendRandomEvent(user); + MongoUtil.getLjsdMongoTemplate().lastUpdate(); + }*/ + sendRandomEvent(user); + } MongoUtil.getLjsdMongoTemplate().lastUpdate(); } } catch (Exception e) { @@ -414,22 +441,6 @@ public class ExplorerMapLogic { } } - public static void sendRandomEvent(User user){ - //map - Map config = STableManager.getConfig(SExplore.class); - Map exploreEventConfig = STableManager.getConfig(SExploreEvent.class); - List limitConfig = config.values().stream().filter(n->n.getLevel()<= user.getPlayerInfoManager().getLevel()).collect(Collectors.toList()); - Random random = new Random(); - int randomMapId = random.nextInt(limitConfig.size()); - SExplore rankExplore = limitConfig.get(randomMapId); - //user.getPlayerInfoManager().getExploreEvent(); - - int randomEventId = random.nextInt(rankExplore.getEventList().length); - int eventId = rankExplore.getEventList()[randomEventId]; - LOGGER.error("explore add eventId:"+eventId+" randomMapId: "+randomMapId); - user.getPlayerInfoManager().addExploreEvent(new KeyVal(eventId,TimeUtils.nowInt()+exploreEventConfig.get(eventId).getTime(),randomMapId+1)); - - } public static class Instance { public final static ExplorerMapLogic instance = new ExplorerMapLogic(); }