From be088a61f93e37d55684a5a4f7e0915801bdd256 Mon Sep 17 00:00:00 2001 From: wangyuan Date: Tue, 22 Jan 2019 09:46:37 +0800 Subject: [PATCH] random --- .../ljsd/jieling/logic/hero/HeroLogic.java | 33 ++++++++++--------- .../com/ljsd/jieling/util/MessageUtil.java | 11 +++++-- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/hero/HeroLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/hero/HeroLogic.java index ff68a3caa..b88a45e7a 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/hero/HeroLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/hero/HeroLogic.java @@ -11,8 +11,8 @@ import com.ljsd.jieling.protocols.CommonProto; import com.ljsd.jieling.protocols.HeroInfoProto; import com.ljsd.jieling.protocols.MessageTypeProto; import com.ljsd.jieling.util.CBean2Proto; +import com.ljsd.jieling.util.MathUtils; import com.ljsd.jieling.util.MessageUtil; -import org.apache.commons.lang.math.RandomUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,7 +69,7 @@ public class HeroLogic { int[] poolWeightInfo = diamondBoxContain[i]; totalWeight += poolWeightInfo[1]; } - int randWeight = RandomUtils.nextInt(totalWeight) + 1; + int randWeight = MathUtils.randomInt(totalWeight) + 1; int weight = 0; for(int i=0;i sLotteryRewardConfigListByPoolId = SLotteryRewardConfig.getSLotteryRewardConfigListByPoolId(poolId); int totalCountByPoolId = SLotteryRewardConfig.getTotalCountByPoolId(poolId); - int randCount = RandomUtils.nextInt(totalCountByPoolId) + 1; + int randCount = MathUtils.randomInt(totalCountByPoolId) + 1; int weight =0; for(SLotteryRewardConfig sLotteryRewardConfig :sLotteryRewardConfigListByPoolId){ weight += sLotteryRewardConfig.getWeight(); @@ -154,42 +154,45 @@ public class HeroLogic { } public String extraReward(SLotterySetting sLotterySetting){ - if(sLotterySetting.getTenTimesMustGetItem()!=null){ + if(sLotterySetting.getTenTimesMustGetItem()!=null &&sLotterySetting.getTenTimesMustGetItem().length>0){ int[] tenTimesMustGetItem = sLotterySetting.getTenTimesMustGetItem(); return tenTimesMustGetItem[0] + "#" + tenTimesMustGetItem[1]; - // tenTimesMustGetItem } return ""; } - public void saveTeamPos(int uid,int teamId,List heroIds ,List pokenIds) throws Exception { - User user = UserManager.getUser(uid); - - user.getTeamPosManager().changeTeamInfo(teamId,heroIds,pokenIds); + public void saveTeamPos(ISession iSession,int teamId,List heroIds ,List pokemonoIds) throws Exception { + User user = UserManager.getUser(iSession.getUid()); + String err = checkTeamPos(user, teamId, heroIds); + if(!"".equals(err)){ + MessageUtil.sendMessage(iSession,0,MessageTypeProto.MessageType.TEAM_POS_SAVE_RESPONSE_VALUE,null,true); + return; + } + user.getTeamPosManager().changeTeamInfo(teamId,heroIds,pokemonoIds); } - public boolean checkTeamPos(User user,int teamId,List heroIds){ + public String checkTeamPos(User user,int teamId,List heroIds){ if(heroIds ==null || heroIds.isEmpty()){ - return false; + return ""; } Set cacheHeroIds = new HashSet<>(); Collection> values = user.getTeamPosManager().getTeamPosForHero().values(); for(String heroId : heroIds){ if(user.getHeroManager().getHero(heroId) == null) { // 卡牌不存在 - return false; + return "card not exists"; } // 卡牌重复 if(cacheHeroIds.contains(heroId)){ - return false; + return "card repeated"; } // 卡牌已上阵 if(values.contains(heroId)){ - return false; + return "card has already in teampos"; } cacheHeroIds.add(heroId); } - return true; + return ""; } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/util/MessageUtil.java b/serverlogic/src/main/java/com/ljsd/jieling/util/MessageUtil.java index 80410bc92..ffe7355bf 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/util/MessageUtil.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/util/MessageUtil.java @@ -5,6 +5,8 @@ import com.ljsd.jieling.logic.dao.UserManager; import com.ljsd.jieling.netty.PackageConstant; import com.ljsd.jieling.netty.cocdex.Tea; import com.ljsd.jieling.network.session.ISession; +import com.ljsd.jieling.protocols.PlayerInfoProto; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,8 +70,13 @@ public class MessageUtil { session.writeAndFlush(byteBuf); } - public static void sendErrorCode(ISession session) { - + public static void sendErrorCode(ISession session,int result,int msgId,String errMsg) throws Exception { + if(StringUtils.isEmpty(errMsg)){ + sendMessage(session, result, msgId, null, true); + }else{ + PlayerInfoProto.ErrorMsgResponse build = PlayerInfoProto.ErrorMsgResponse.newBuilder().setMsg(errMsg).build(); + sendMessage(session, result, msgId, build, true); + } }