巅峰赛临时提交

zhangshanxue 2020-11-07 12:28:04 +08:00
parent ca17f5d39d
commit c654004bc8
1 changed files with 240 additions and 140 deletions

View File

@ -1,7 +1,8 @@
package com.ljsd.jieling.logic.arena; package com.ljsd.jieling.logic.arena;
import com.ljsd.fight.CheckFight;
import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
import com.ljsd.jieling.core.GlobalsDef; import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.core.VipPrivilegeType; import com.ljsd.jieling.core.VipPrivilegeType;
import com.ljsd.jieling.db.mongo.MongoUtil; import com.ljsd.jieling.db.mongo.MongoUtil;
@ -18,6 +19,7 @@ import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean;
import com.ljsd.jieling.logic.OnlineUserManager; import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.activity.event.ArenaChallengeEvent; import com.ljsd.jieling.logic.activity.event.ArenaChallengeEvent;
import com.ljsd.jieling.logic.activity.event.Poster; import com.ljsd.jieling.logic.activity.event.Poster;
import com.ljsd.jieling.logic.championship.ChampionshipLogic;
import com.ljsd.jieling.logic.dao.*; import com.ljsd.jieling.logic.dao.*;
import com.ljsd.jieling.logic.dao.root.User; import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.fight.*; import com.ljsd.jieling.logic.fight.*;
@ -36,6 +38,7 @@ import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.*; import com.ljsd.jieling.util.*;
import config.*; import config.*;
import manager.STableManager; import manager.STableManager;
import org.luaj.vm2.LuaValue;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.ZSetOperations; import org.springframework.data.redis.core.ZSetOperations;
@ -48,8 +51,8 @@ import java.util.*;
public class ArenaLogic { public class ArenaLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(ArenaLogic.class); private static final Logger LOGGER = LoggerFactory.getLogger(ArenaLogic.class);
private ArenaLogic(){} private ArenaLogic() {
}
public static class Instance { public static class Instance {
@ -59,7 +62,7 @@ public class ArenaLogic {
public static ArenaLogic getInstance() { public static ArenaLogic getInstance() {
return ArenaLogic.Instance.instance; return ArenaLogic.Instance.instance;
} }
private int curSeason; private int curSeason;
private int viewSeason; private int viewSeason;
@ -73,16 +76,16 @@ public class ArenaLogic {
public List<CommonProto.ArenaEnemy> getArenaEnemyList(List<ArenaEnemy> arenaEnemies) throws Exception { public List<CommonProto.ArenaEnemy> getArenaEnemyList(List<ArenaEnemy> arenaEnemies) throws Exception {
List<CommonProto.ArenaEnemy> arenaEnemyList = new ArrayList<>(arenaEnemies.size()); List<CommonProto.ArenaEnemy> arenaEnemyList = new ArrayList<>(arenaEnemies.size());
for(ArenaEnemy arenaEnemy : arenaEnemies){ for (ArenaEnemy arenaEnemy : arenaEnemies) {
int enemyId = arenaEnemy.getEnemyId(); int enemyId = arenaEnemy.getEnemyId();
int enemyType = arenaEnemy.getEnemyType(); int enemyType = arenaEnemy.getEnemyType();
arenaEnemyList.add(getArenaEnemy(enemyId,enemyType)); arenaEnemyList.add(getArenaEnemy(enemyId, enemyType));
} }
return arenaEnemyList; return arenaEnemyList;
} }
public CommonProto.ArenaEnemy getArenaEnemy( int enemyId ,int enemyType) throws Exception { public CommonProto.ArenaEnemy getArenaEnemy(int enemyId, int enemyType) throws Exception {
if(enemyType == 0){ //机器人 if (enemyType == 0) { //机器人
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(enemyId); SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(enemyId);
CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(sArenaRobotConfig.getHeroList()).build(); CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(sArenaRobotConfig.getHeroList()).build();
CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder() CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder()
@ -96,19 +99,19 @@ public class ArenaLogic {
.setPersonInfo(personInfoBuild) .setPersonInfo(personInfoBuild)
.setTeam(teamBuild) .setTeam(teamBuild)
.build(); .build();
}else{ } else {
User user = UserManager.getUser(enemyId); User user = UserManager.getUser(enemyId);
int totalForce = HeroLogic.getInstance().calTeamTotalForce(user, GlobalsDef.TEAM_ARENA_DEFENSE,false); int totalForce = HeroLogic.getInstance().calTeamTotalForce(user, GlobalsDef.TEAM_ARENA_DEFENSE, false);
List<TeamPosHeroInfo> teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(GlobalsDef.TEAM_ARENA_DEFENSE); List<TeamPosHeroInfo> teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(GlobalsDef.TEAM_ARENA_DEFENSE);
Map<String, Hero> heroMap = user.getHeroManager().getHeroMap(); Map<String, Hero> heroMap = user.getHeroManager().getHeroMap();
List<Integer> heroTids = new ArrayList<>(teamPosHeroInfoList.size()); List<Integer> heroTids = new ArrayList<>(teamPosHeroInfoList.size());
for(TeamPosHeroInfo teamPosHeroInfo:teamPosHeroInfoList){ for (TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfoList) {
heroTids.add(heroMap.get(teamPosHeroInfo.getHeroId()).getTemplateId()); heroTids.add(heroMap.get(teamPosHeroInfo.getHeroId()).getTemplateId());
} }
CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(heroTids).build(); CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(heroTids).build();
PlayerManager playerInfoManager = user.getPlayerInfoManager(); PlayerManager playerInfoManager = user.getPlayerInfoManager();
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK, Integer.toString(curSeason), Integer.toString(enemyId)).intValue(); int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK, Integer.toString(curSeason), Integer.toString(enemyId)).intValue();
if(score == -1){ if (score == -1) {
score = SArenaSetting.getSArenaSetting().getScore(); score = SArenaSetting.getSArenaSetting().getScore();
} }
CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder() CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder()
@ -119,7 +122,7 @@ public class ArenaLogic {
.setHead(playerInfoManager.getHead()) .setHead(playerInfoManager.getHead())
.setTotalForce(totalForce) .setTotalForce(totalForce)
.build(); .build();
return CommonProto.ArenaEnemy.newBuilder() return CommonProto.ArenaEnemy.newBuilder()
.setPersonInfo(personInfoBuild) .setPersonInfo(personInfoBuild)
.setTeam(teamBuild) .setTeam(teamBuild)
.build(); .build();
@ -127,50 +130,47 @@ public class ArenaLogic {
} }
public void setMyArenaEnemys(int uid, User user) {
public void setMyArenaEnemys(int uid,User user){ int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK, Integer.toString(curSeason), Integer.toString(uid)).intValue();
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(uid)).intValue(); if (score == -1) {
if(score == -1){
score = SArenaSetting.getSArenaSetting().getScore(); score = SArenaSetting.getSArenaSetting().getScore();
} }
ArenaManager arenaManager = user.getArenaManager(); ArenaManager arenaManager = user.getArenaManager();
List<ArenaEnemy> arenaEnemies = new ArrayList<>(); List<ArenaEnemy> arenaEnemies = new ArrayList<>();
if(curSeason ==1 && arenaManager.getFlushNums()<SArenaSetting.getSArenaSetting().getPveNum()){ if (curSeason == 1 && arenaManager.getFlushNums() < SArenaSetting.getSArenaSetting().getPveNum()) {
Set<Integer> robotIds = randomRobot(score, 5); Set<Integer> robotIds = randomRobot(score, 5);
toArenaEnemy(uid,robotIds,arenaEnemies,GlobalsDef.ARENA_ROBOT_TYPE); toArenaEnemy(uid, robotIds, arenaEnemies, GlobalsDef.ARENA_ROBOT_TYPE);
}else{ } else {
Set<Integer> robotIds = randomPerson(uid,score,true); Set<Integer> robotIds = randomPerson(uid, score, true);
int type = GlobalsDef.ARENA_PLAYER_TYPE; int type = GlobalsDef.ARENA_PLAYER_TYPE;
toArenaEnemy(uid,robotIds,arenaEnemies,type); toArenaEnemy(uid, robotIds, arenaEnemies, type);
if(robotIds.isEmpty()){ if (robotIds.isEmpty()) {
if(curSeason>1){ if (curSeason > 1) {
robotIds = randomPerson(uid,score,false); robotIds = randomPerson(uid, score, false);
} }
toArenaEnemy(uid,robotIds,arenaEnemies,type); toArenaEnemy(uid, robotIds, arenaEnemies, type);
} }
int size = robotIds.size(); int size = robotIds.size();
if(size<5){ if (size < 5) {
robotIds = randomRobot(score, 5-size); robotIds = randomRobot(score, 5 - size);
type = GlobalsDef.ARENA_ROBOT_TYPE; type = GlobalsDef.ARENA_ROBOT_TYPE;
toArenaEnemy(uid,robotIds,arenaEnemies,type); toArenaEnemy(uid, robotIds, arenaEnemies, type);
} }
} }
arenaManager.setArenaEnemies(arenaEnemies); arenaManager.setArenaEnemies(arenaEnemies);
} }
public static int getFightResultByPersonToPerson(User mine, int myteamId, User defUser, int defTeamId, ArenaRecord arenaRecord, ArenaInfoProto.ArenaChallengeResponse.Builder builder) throws Exception {
PVPFightEvent pvpFightEvent = new PVPFightEvent(mine.getId(), myteamId, SArenaSetting.getSArenaSetting().getMostTime(), "", GameFightType.ArenaPersonFight, defUser.getId(), defTeamId);
public static int getFightResultByPersonToPerson(User mine, int myteamId, User defUser, int defTeamId, ArenaRecord arenaRecord, ArenaInfoProto.ArenaChallengeResponse.Builder builder) throws Exception {
PVPFightEvent pvpFightEvent = new PVPFightEvent(mine.getId(),myteamId,SArenaSetting.getSArenaSetting().getMostTime(),"", GameFightType.ArenaPersonFight,defUser.getId(),defTeamId);
int myforce = HeroLogic.getInstance().calTeamTotalForce(mine, GlobalsDef.TEAM_ARENA_DEFENSE, false); int myforce = HeroLogic.getInstance().calTeamTotalForce(mine, GlobalsDef.TEAM_ARENA_DEFENSE, false);
int defForce = HeroLogic.getInstance().calTeamTotalForce(defUser, GlobalsDef.TEAM_ARENA_DEFENSE, false); int defForce = HeroLogic.getInstance().calTeamTotalForce(defUser, GlobalsDef.TEAM_ARENA_DEFENSE, false);
arenaRecord.setAttackForce(myforce); arenaRecord.setAttackForce(myforce);
if(myforce<defForce){ if (myforce < defForce) {
pvpFightEvent.setRever(true); pvpFightEvent.setRever(true);
} }
FightResult fightResult = FightDispatcher.dispatcher(pvpFightEvent); FightResult fightResult = FightDispatcher.dispatcher(pvpFightEvent);
CommonProto.FightTeamInfo fightTeamInfo =fightResult.getFightTeamInfo(); CommonProto.FightTeamInfo fightTeamInfo = fightResult.getFightTeamInfo();
CommonProto.FightTeamInfo deffightTeamInfo = fightResult.getDefFightTeamInfo(); CommonProto.FightTeamInfo deffightTeamInfo = fightResult.getDefFightTeamInfo();
//设置战斗随机种子 //设置战斗随机种子
int seed = fightResult.getSeed(); int seed = fightResult.getSeed();
@ -188,16 +188,15 @@ public class ArenaLogic {
} }
public int getFightResultByPersonToRobot(User mine, int myteamId, int challengeUid, ArenaInfoProto.ArenaChallengeResponse.Builder builder) throws Exception {
public int getFightResultByPersonToRobot(User mine, int myteamId, int challengeUid,ArenaInfoProto.ArenaChallengeResponse.Builder builder) throws Exception { PVPFightEvent pvpFightEvent = new PVPFightEvent(mine.getId(), myteamId, SArenaSetting.getSArenaSetting().getMostTime(), "", GameFightType.ArenaRobotFight, challengeUid, -1);
PVPFightEvent pvpFightEvent = new PVPFightEvent(mine.getId(),myteamId,SArenaSetting.getSArenaSetting().getMostTime(),"", GameFightType.ArenaRobotFight,challengeUid,-1);
int myforce = HeroLogic.getInstance().calTeamTotalForce(mine, GlobalsDef.TEAM_ARENA_DEFENSE, false); int myforce = HeroLogic.getInstance().calTeamTotalForce(mine, GlobalsDef.TEAM_ARENA_DEFENSE, false);
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(myteamId); SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(myteamId);
if(sArenaRobotConfig!=null&&myforce<sArenaRobotConfig.getTotalForce()){ if (sArenaRobotConfig != null && myforce < sArenaRobotConfig.getTotalForce()) {
pvpFightEvent.setRever(true); pvpFightEvent.setRever(true);
} }
FightResult fightResult = FightDispatcher.dispatcher(pvpFightEvent); FightResult fightResult = FightDispatcher.dispatcher(pvpFightEvent);
CommonProto.FightTeamInfo fightTeamInfo =fightResult.getFightTeamInfo(); CommonProto.FightTeamInfo fightTeamInfo = fightResult.getFightTeamInfo();
CommonProto.FightTeamInfo deffightTeamInfo = fightResult.getDefFightTeamInfo(); CommonProto.FightTeamInfo deffightTeamInfo = fightResult.getDefFightTeamInfo();
//设置战斗随机种子 //设置战斗随机种子
int seed = fightResult.getSeed(); int seed = fightResult.getSeed();
@ -210,25 +209,25 @@ public class ArenaLogic {
return fightResult.getCheckResult()[0]; return fightResult.getCheckResult()[0];
} }
public String checkChallenge(User user,int skipFight, ArenaEnemy enemyInfo) throws Exception { public String checkChallenge(User user, int skipFight, ArenaEnemy enemyInfo) throws Exception {
if( null == enemyInfo ){ if (null == enemyInfo) {
return "对手错误"; return "对手错误";
} }
if(skipFight == 1){ if (skipFight == 1) {
boolean allowed = user.getPlayerInfoManager().checkFunctionIsAllowed(VipPrivilegeType.UNLOCK_SKIP_ARENA); boolean allowed = user.getPlayerInfoManager().checkFunctionIsAllowed(VipPrivilegeType.UNLOCK_SKIP_ARENA);
if(!allowed){ if (!allowed) {
return "not allowed"; return "not allowed";
} }
} }
if(!user.getTeamPosManager().getTeamPosForHero().containsKey(GlobalsDef.TEAM_ARENA_DEFENSE)){ if (!user.getTeamPosManager().getTeamPosForHero().containsKey(GlobalsDef.TEAM_ARENA_DEFENSE)) {
return "未设置防守阵容"; return "未设置防守阵容";
} }
SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting(); SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting();
int battleFree = sArenaSetting.getBattleFree(); int battleFree = sArenaSetting.getBattleFree();
if(!PlayerLogic.getInstance().checkAndUpdate(user,battleFree,1)){ if (!PlayerLogic.getInstance().checkAndUpdate(user, battleFree, 1)) {
//校验消耗 //校验消耗
boolean enough = ItemUtil.itemCost(user, new int[][]{sArenaSetting.getCost()}, BIReason.ARENA_CHALLENGE_CONSUME,enemyInfo.getEnemyId()); boolean enough = ItemUtil.itemCost(user, new int[][]{sArenaSetting.getCost()}, BIReason.ARENA_CHALLENGE_CONSUME, enemyInfo.getEnemyId());
if(!enough){ if (!enough) {
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH); throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
} }
} }
@ -271,17 +270,17 @@ public class ArenaLogic {
// MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_RANDOM_ENEMY_RESPONSE_VALUE,build,true); // MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_RANDOM_ENEMY_RESPONSE_VALUE,build,true);
// } // }
public static Set<Integer> randomRobot(int userSscore,int nums){ public static Set<Integer> randomRobot(int userSscore, int nums) {
Set<Integer> robotIds = new HashSet<>(5); Set<Integer> robotIds = new HashSet<>(5);
Map<Integer, SArenaRobotSetting> config = STableManager.getConfig(SArenaRobotSetting.class); Map<Integer, SArenaRobotSetting> config = STableManager.getConfig(SArenaRobotSetting.class);
for(SArenaRobotSetting sArenaRobotSetting : config.values()){ for (SArenaRobotSetting sArenaRobotSetting : config.values()) {
int playerLevelMin = sArenaRobotSetting.getPlayerScoreMin(); int playerLevelMin = sArenaRobotSetting.getPlayerScoreMin();
int playerLevelMax = sArenaRobotSetting.getPlayerScoreMax(); int playerLevelMax = sArenaRobotSetting.getPlayerScoreMax();
if(userSscore>=playerLevelMin && userSscore<=playerLevelMax){ if (userSscore >= playerLevelMin && userSscore <= playerLevelMax) {
int poolId = sArenaRobotSetting.getPool(); int poolId = sArenaRobotSetting.getPool();
List<SArenaRobotConfig> sArenaRobotConfigsByPool = SArenaRobotConfig.getSArenaRobotConfigsByPool(poolId); List<SArenaRobotConfig> sArenaRobotConfigsByPool = SArenaRobotConfig.getSArenaRobotConfigsByPool(poolId);
int size = sArenaRobotConfigsByPool.size(); int size = sArenaRobotConfigsByPool.size();
while (robotIds.size() < nums){ while (robotIds.size() < nums) {
robotIds.add(sArenaRobotConfigsByPool.get(MathUtils.randomInt(size)).getId()); robotIds.add(sArenaRobotConfigsByPool.get(MathUtils.randomInt(size)).getId());
} }
} }
@ -289,22 +288,22 @@ public class ArenaLogic {
return robotIds; return robotIds;
} }
public Set<Integer> randomPerson(int uid,int myScore,boolean useCurSeason){ public Set<Integer> randomPerson(int uid, int myScore, boolean useCurSeason) {
Set<Integer> result = new HashSet<>(5); Set<Integer> result = new HashSet<>(5);
int[][] interval = SArenaSetting.getSArenaSetting().getInterval(); int[][] interval = SArenaSetting.getSArenaSetting().getInterval();
int matchSeason = curSeason; int matchSeason = curSeason;
if(!useCurSeason){ if (!useCurSeason) {
matchSeason = curSeason - 1; matchSeason = curSeason - 1;
} }
for(int[] item: interval){ for (int[] item : interval) {
int low = item[0]; int low = item[0];
int high = item[1]; int high = item[1];
Set<String> arenaRank = RedisUtil.getInstence().getZsetRange(RedisKey.ARENA_RANK,Integer.toString(matchSeason), myScore * low / 10000.0f-1, myScore * high / 10000.0f +1); Set<String> arenaRank = RedisUtil.getInstence().getZsetRange(RedisKey.ARENA_RANK, Integer.toString(matchSeason), myScore * low / 10000.0f - 1, myScore * high / 10000.0f + 1);
LOGGER.info("curSeason={},matchSeason={},the uid={},the myscore={},the low={},the high={},mylow={},myhigh={},",curSeason,matchSeason,uid,myScore,low,high,myScore * low / 10000.0f-1,myScore * high / 10000.0f +1); LOGGER.info("curSeason={},matchSeason={},the uid={},the myscore={},the low={},the high={},mylow={},myhigh={},", curSeason, matchSeason, uid, myScore, low, high, myScore * low / 10000.0f - 1, myScore * high / 10000.0f + 1);
if(arenaRank!=null && !arenaRank.isEmpty()){ if (arenaRank != null && !arenaRank.isEmpty()) {
arenaRank.remove(Integer.toString(uid)); arenaRank.remove(Integer.toString(uid));
String s = randomSet(arenaRank); String s = randomSet(arenaRank);
if(!StringUtil.isEmpty(s)){ if (!StringUtil.isEmpty(s)) {
result.add(Integer.parseInt(s)); result.add(Integer.parseInt(s));
} }
} }
@ -312,31 +311,31 @@ public class ArenaLogic {
return result; return result;
} }
private String randomSet(Set<String> infos){ private String randomSet(Set<String> infos) {
if(infos == null || infos.isEmpty()){ if (infos == null || infos.isEmpty()) {
return null; return null;
} }
int num = MathUtils.randomInt(infos.size()); int num = MathUtils.randomInt(infos.size());
for(String id : infos){ for (String id : infos) {
if(num-- == 0){ if (num-- == 0) {
return id; return id;
} }
} }
return null; return null;
} }
public void toArenaEnemy(int uid,Set<Integer> enemyList,List<ArenaEnemy> arenaEnemies,int type){ public void toArenaEnemy(int uid, Set<Integer> enemyList, List<ArenaEnemy> arenaEnemies, int type) {
for(Integer enemyId: enemyList){ for (Integer enemyId : enemyList) {
if(1 == type && enemyId == uid){ if (1 == type && enemyId == uid) {
continue; continue;
} }
arenaEnemies.add(new ArenaEnemy(enemyId,type,type)); arenaEnemies.add(new ArenaEnemy(enemyId, type, type));
} }
} }
public void getWorldRankByPage(ISession session,int page) throws Exception { public void getWorldRankByPage(ISession session, int page) throws Exception {
if (page == 0) { if (page == 0) {
page = 1; page = 1;
} }
@ -344,13 +343,13 @@ public class ArenaLogic {
List<CommonProto.ArenaEnemy> arenaRankMemberInfo = new ArrayList<>(20); List<CommonProto.ArenaEnemy> arenaRankMemberInfo = new ArrayList<>(20);
int rankEndLine = SSpecialConfig.getIntegerValue(SSpecialConfig.ARENA_RANKINGSHOWNUM); int rankEndLine = SSpecialConfig.getIntegerValue(SSpecialConfig.ARENA_RANKINGSHOWNUM);
if(end<rankEndLine) { if (end < rankEndLine) {
Set<ZSetOperations.TypedTuple<String>> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK, Integer.toString(viewSeason), start, end); Set<ZSetOperations.TypedTuple<String>> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK, Integer.toString(viewSeason), start, end);
for (ZSetOperations.TypedTuple<String> item : arenaRankInfo) { for (ZSetOperations.TypedTuple<String> item : arenaRankInfo) {
String value = item.getValue(); String value = item.getValue();
int score = item.getScore().intValue(); int score = item.getScore().intValue();
int uid = Integer.parseInt(value); int uid = Integer.parseInt(value);
User user = UserManager.getUser(uid,true); User user = UserManager.getUser(uid, true);
if (null == user) { if (null == user) {
continue; continue;
} }
@ -380,12 +379,12 @@ public class ArenaLogic {
} }
} }
int uid = session.getUid(); int uid = session.getUid();
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(viewSeason), Integer.toString(uid)).intValue(); int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK, Integer.toString(viewSeason), Integer.toString(uid)).intValue();
int myRank =-1; int myRank = -1;
if(score == -1){ if (score == -1) {
score = SArenaSetting.getSArenaSetting().getScore(); score = SArenaSetting.getSArenaSetting().getScore();
}else{ } else {
myRank= RedisUtil.getInstence().getZSetreverseRank(RedisKey.ARENA_RANK,Integer.toString(viewSeason),Integer.toString(uid)).intValue(); myRank = RedisUtil.getInstence().getZSetreverseRank(RedisKey.ARENA_RANK, Integer.toString(viewSeason), Integer.toString(uid)).intValue();
} }
ArenaInfoProto.GetArenaRankInfoResponse buildResponse = ArenaInfoProto.GetArenaRankInfoResponse.newBuilder() ArenaInfoProto.GetArenaRankInfoResponse buildResponse = ArenaInfoProto.GetArenaRankInfoResponse.newBuilder()
@ -393,120 +392,222 @@ public class ArenaLogic {
.setMyRank(myRank) .setMyRank(myRank)
.setMyscore(score) .setMyscore(score)
.build(); .build();
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_RANK_RESPONSE_VALUE,buildResponse,true); MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.ARENA_RANK_RESPONSE_VALUE, buildResponse, true);
} }
/** /**
* * Sa: = 1 =0
Sa: = 1 =0 * <p>
* Ra: A Rb B
Ra: A Rb B * R'a: A R'b B
R'a: A R'b B * <p>
* EaEA = 1/(1+10^[(Rb-Ra)/400])
EaEA = 1/(1+10^[(Rb-Ra)/400]) * Eb: EB = 1/(1+10^[(Ra-Rb)/400])
Eb: EB = 1/(1+10^[(Ra-Rb)/400]) * R'a = Ra + K(Sa-Ea)
R'a = Ra + K(Sa-Ea) * R'b = Rb + K(Sb-Eb)
R'b = Rb + K(Sb-Eb)
*
*/ */
public int calScore(int myScore,int defScore,int result){ public int calScore(int myScore, int defScore, int result) {
SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting(); SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting();
int k = sArenaSetting.getK(); int k = sArenaSetting.getK();
double ea = 1.0/(1 + Math.pow(10,(defScore - myScore)/400.0f)); double ea = 1.0 / (1 + Math.pow(10, (defScore - myScore) / 400.0f));
int parm = result == 1?1:-1; int parm = result == 1 ? 1 : -1;
return (int)(k*(result-ea) + 0.5*parm); return (int) (k * (result - ea) + 0.5 * parm);
} }
public void getFightReplayData(ISession iSession,int type,String fightId) throws Exception { public void getFightReplayData(ISession iSession, int type, String fightId) throws Exception {
int uid = iSession.getUid(); int uid = iSession.getUid();
ArenaRecord arenaRecord=null; ArenaRecord arenaRecord = null;
if(type == 2){ if (type == 2) {
arenaRecord = RedisUtil.getInstence().getMapEntry(RedisKey.CHAMPION_ARENA_RECORD,"", fightId, ArenaRecord.class); arenaRecord = RedisUtil.getInstence().getMapEntry(RedisKey.CHAMPION_ARENA_RECORD, "", fightId, ArenaRecord.class);
}else if(type == 1){ } else if (type == 1) {
arenaRecord = RedisUtil.getInstence().getMapEntry(RedisKey.ARENA_RRECORD, Integer.toString(uid), fightId, ArenaRecord.class); arenaRecord = RedisUtil.getInstence().getMapEntry(RedisKey.ARENA_RRECORD, Integer.toString(uid), fightId, ArenaRecord.class);
}else if(type == 3){ } else if (type == 3) {
arenaRecord = RedisUtil.getInstence().get(RedisKey.GUILDBOSS_ARENA_RECORD, fightId, ArenaRecord.class); arenaRecord = RedisUtil.getInstence().get(RedisKey.GUILDBOSS_ARENA_RECORD, fightId, ArenaRecord.class);
} }
if(arenaRecord == null){ if (arenaRecord == null) {
throw new ErrorCodeException(ErrorCode.newDefineCode("arena_rrecord null")); throw new ErrorCodeException(ErrorCode.newDefineCode("arena_rrecord null"));
} }
byte[] fightData = arenaRecord.getFightData(); byte[] fightData = arenaRecord.getFightData();
CommonProto.FightData fightDataProto = CommonProto.FightData.parseFrom(fightData); CommonProto.FightData fightDataProto = CommonProto.FightData.parseFrom(fightData);
LuaValue getFightData;
int snapTeamId = GlobalsDef.CHAMPION_ATTACK_TEAM;
RedisUtil.getInstence().del(RedisUtil.getInstence().getKey(RedisKey.CHAMPION_FIGHT, ""));
int warTime = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting().getWarTime();
Map<Integer, ChampionshipLogic.MemberInfo> memberInfoMap = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_JOIN, "", Integer.class, ChampionshipLogic.MemberInfo.class);
int attackId = arenaRecord.getAttackId();
int defUid = arenaRecord.getDefUid();
ChampionshipLogic.snapOneFightInfo(attackId, memberInfoMap);
ChampionshipLogic.snapOneFightInfo(defUid, memberInfoMap);
long id = FightDispatcher.getFIghtId();
EndFightProcessor endFightProcessor = new AreFightPro();
((AreFightPro) endFightProcessor).setArenaRecord(arenaRecord);
FightDispatcher.getMap().put(id, endFightProcessor);
Map<Integer, GameFightType> gameFightTypeMap = new HashMap<>();
gameFightTypeMap.put(0, GameFightType.TOPArenaPersonFight);
gameFightTypeMap.put(1, GameFightType.TOPArenaRobotFight);
gameFightTypeMap.put(2, GameFightType.TOPArena2RobotFight);
PVPFightEvent pvpFightEvent = new PVPFightEvent(attackId, snapTeamId, warTime, "", gameFightTypeMap.get(arenaRecord.getType()), defUid, snapTeamId);
ChampionshipLogic.MemberInfo attackMemberInfo = memberInfoMap.get(attackId);
ChampionshipLogic.MemberInfo defMemberInfo = memberInfoMap.get(defUid);
int minForce = 0;
int defForce = 0;
if (defMemberInfo.getType() == 0) {
FamilyFightInfo fightInfo = defMemberInfo.getFightInfo();
pvpFightEvent.setDefFightSnapData(new DefFightSnapData(fightInfo.getHeroAttribute(), fightInfo.getHeroSkills(), fightInfo.getPokenmonSkills(), fightInfo.getPassiveSkills(), defUid));
defForce = fightInfo.getForce();
} else {
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(defUid);
if (sArenaRobotConfig != null) {
defForce = sArenaRobotConfig.getTotalForce();
}
}
if (attackMemberInfo.getType() == 0) {
FamilyFightInfo fightInfo = attackMemberInfo.getFightInfo();
pvpFightEvent.setAttackFightSnapData(new DefFightSnapData(fightInfo.getHeroAttribute(), fightInfo.getHeroSkills(), fightInfo.getPokenmonSkills(), fightInfo.getPassiveSkills(), attackId));
minForce = fightInfo.getForce();
} else {
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(attackId);
if (sArenaRobotConfig != null) {
minForce = sArenaRobotConfig.getTotalForce();
}
}
if (minForce > defForce) {
if (arenaRecord.getTurn() == 2) {
pvpFightEvent.setRever(true);
}
} else {
if (arenaRecord.getTurn() == 1 || arenaRecord.getTurn() == 3) {
pvpFightEvent.setRever(true);
}
}
CommonProto.FightTeamInfo fightTeamInfo = null;
CommonProto.FightTeamInfo deffightTeamInfo = null;
if(pvpFightEvent.getAttackFightSnapData()!=null){
fightTeamInfo = FightUtil.makeFightWithSnapData(pvpFightEvent.getAttackFightSnapData());
}
if(pvpFightEvent.getDefFightSnapData()!=null){
deffightTeamInfo = FightUtil.makeFightWithSnapData(pvpFightEvent.getDefFightSnapData());
} else{
if(pvpFightEvent.getFightType() == GameFightType.ArenaPersonFight ||pvpFightEvent.getFightType() == GameFightType.CarPersonChallenge ){
User defInMem = UserManager.getUserInMem(pvpFightEvent.getDefUid());
deffightTeamInfo = FightUtil.makePersonFightData(defInMem, pvpFightEvent.getDefTeamId(),null,null);
}else{
deffightTeamInfo =FightUtil. makeRobotFightData(pvpFightEvent.getDefUid());
}
}
if(fightTeamInfo==null){
if( pvpFightEvent.getFightType()!=GameFightType.TOPArena2RobotFight){
if( SArenaRobotConfig.getsArenaRobotConfigById(pvpFightEvent.getAttackUid()) !=null){
fightTeamInfo =FightUtil. makeRobotFightData(pvpFightEvent.getAttackUid());
}else{
User userInMem = UserManager.getUserInMem(pvpFightEvent.getAttackUid());
fightTeamInfo = FightUtil.makePersonFightData(userInMem, pvpFightEvent.getTeamId(),pvpFightEvent.getAttackBloodMap(),null);
}
}else{
fightTeamInfo = FightUtil.makeRobotFightData(pvpFightEvent.getAttackUid());
}
}
if (pvpFightEvent.isRever()) {
deffightTeamInfo = CommonProto.FightTeamInfo.newBuilder().mergeFrom(deffightTeamInfo).setFirstCamp(1).build();
getFightData = FightDataUtil.getFinalPlayerFightData(fightTeamInfo, deffightTeamInfo, true);//对方先手
} else {
getFightData = FightDataUtil.getFinalPlayerFightData(fightTeamInfo, deffightTeamInfo);
}
LuaValue getOptionData = FightDataUtil.getOptionData(pvpFightEvent.getAttackUid() + "");
int[] fightResult = CheckFight.getInstance().checkFight(fightDataProto.getFightSeed(), pvpFightEvent.getMostTime(), getFightData, getOptionData, pvpFightEvent.getFightType().getFightType());
String string = Arrays.toString(fightResult);
LOGGER.error("__________________________"+fightResult[0]+":::"+string);
System.out.println("string = " + string);
FightInfoProto.FightRePlayResponse build = FightInfoProto.FightRePlayResponse.newBuilder().setFightData(fightDataProto).build(); FightInfoProto.FightRePlayResponse build = FightInfoProto.FightRePlayResponse.newBuilder().setFightData(fightDataProto).build();
MessageUtil.sendMessage(iSession,1, MessageTypeProto.MessageType.VIEW_FIGHTREPLAY_RESPONSE_VALUE,build,true); MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.VIEW_FIGHTREPLAY_RESPONSE_VALUE, build, true);
} }
/** /**
* *
*
* @param type * @param type
* @throws Exception * @throws Exception
*/ */
public void sendReward(int type) throws Exception { public void sendReward(int type) throws Exception {
if(curSeason == 0){ if (curSeason == 0) {
return; return;
} }
String title; String title;
String content; String content;
if(type == GlobalsDef.ARENA_DAILY_REWARD){ if (type == GlobalsDef.ARENA_DAILY_REWARD) {
title = SErrorCodeEerverConfig.getI18NMessage("arena_daily_reward_title"); title = SErrorCodeEerverConfig.getI18NMessage("arena_daily_reward_title");
}else{ } else {
title = SErrorCodeEerverConfig.getI18NMessage("arena_season_reward_title"); title = SErrorCodeEerverConfig.getI18NMessage("arena_season_reward_title");
} }
Set<ZSetOperations.TypedTuple<String>> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK,Integer.toString(curSeason), 0, -1); Set<ZSetOperations.TypedTuple<String>> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK, Integer.toString(curSeason), 0, -1);
if(type == GlobalsDef.ARENA_SEASON_REWARD){ if (type == GlobalsDef.ARENA_SEASON_REWARD) {
curSeason=0; curSeason = 0;
} }
int rank = 1; int rank = 1;
int nowTime =(int) (TimeUtils.now()/1000); int nowTime = (int) (TimeUtils.now() / 1000);
for(ZSetOperations.TypedTuple<String> item : arenaRankInfo){ for (ZSetOperations.TypedTuple<String> item : arenaRankInfo) {
String value = item.getValue(); String value = item.getValue();
int uid = Integer.parseInt(value); int uid = Integer.parseInt(value);
User user = UserManager.getUser(uid, true); User user = UserManager.getUser(uid, true);
if (null == user) { if (null == user) {
continue; continue;
} }
if(type == GlobalsDef.ARENA_DAILY_REWARD){ if (type == GlobalsDef.ARENA_DAILY_REWARD) {
MissionEventDistributor.requestStart(); MissionEventDistributor.requestStart();
user.getUserMissionManager().onGameEvent(user,GameEvent.ARENA_UPDATE_RANK,rank); user.getUserMissionManager().onGameEvent(user, GameEvent.ARENA_UPDATE_RANK, rank);
ISession sessionByUid = OnlineUserManager.getSessionByUid(uid); ISession sessionByUid = OnlineUserManager.getSessionByUid(uid);
if(sessionByUid!=null){ if (sessionByUid != null) {
MissionEventDistributor.requestEnd(sessionByUid,true); MissionEventDistributor.requestEnd(sessionByUid, true);
} }
} }
if(type == GlobalsDef.ARENA_DAILY_REWARD){ if (type == GlobalsDef.ARENA_DAILY_REWARD) {
content = SErrorCodeEerverConfig.getI18NMessage("arena_daily_reward_txt",new Object[]{rank}); content = SErrorCodeEerverConfig.getI18NMessage("arena_daily_reward_txt", new Object[]{rank});
}else{ } else {
content = SErrorCodeEerverConfig.getI18NMessage("arena_season_reward_txt",new Object[]{rank}); content = SErrorCodeEerverConfig.getI18NMessage("arena_season_reward_txt", new Object[]{rank});
user.getPlayerInfoManager().removeRed(GlobalsDef.ARENA_CHALLENGE_TYPE); user.getPlayerInfoManager().removeRed(GlobalsDef.ARENA_CHALLENGE_TYPE);
String key = RedisUtil.getInstence().getKey(RedisKey.ARENA_RRECORD, Integer.toString(uid)); String key = RedisUtil.getInstence().getKey(RedisKey.ARENA_RRECORD, Integer.toString(uid));
RedisUtil.getInstence().del(key); RedisUtil.getInstence().del(key);
} }
String rewardByRank = getRewardByRank(rank++, type); String rewardByRank = getRewardByRank(rank++, type);
if(!"".equals(rewardByRank)){ if (!"".equals(rewardByRank)) {
MailLogic.getInstance().sendMail(user.getId(),title,content,rewardByRank,nowTime, Global.MAIL_EFFECTIVE_TIME); MailLogic.getInstance().sendMail(user.getId(), title, content, rewardByRank, nowTime, Global.MAIL_EFFECTIVE_TIME);
} }
} }
MongoUtil.getInstence().lastUpdate(); MongoUtil.getInstence().lastUpdate();
} }
public String getRewardByRank(int rank,int type){ public String getRewardByRank(int rank, int type) {
Map<Integer, SArenaReward> config = STableManager.getConfig(SArenaReward.class); Map<Integer, SArenaReward> config = STableManager.getConfig(SArenaReward.class);
for(SArenaReward sArenaReward : config.values()){ for (SArenaReward sArenaReward : config.values()) {
int minRank = sArenaReward.getMinRank(); int minRank = sArenaReward.getMinRank();
int maxRank = sArenaReward.getMaxRank(); int maxRank = sArenaReward.getMaxRank();
if(rank>=minRank && rank<=maxRank){ if (rank >= minRank && rank <= maxRank) {
if(type == GlobalsDef.ARENA_DAILY_REWARD){ if (type == GlobalsDef.ARENA_DAILY_REWARD) {
int[][] dailyReward = sArenaReward.getDailyReward(); int[][] dailyReward = sArenaReward.getDailyReward();
return StringUtil.parseArrayToString(dailyReward); return StringUtil.parseArrayToString(dailyReward);
}else{ } else {
int[][] seasonReward = sArenaReward.getSeasonReward(); int[][] seasonReward = sArenaReward.getSeasonReward();
return StringUtil.parseArrayToString(seasonReward); return StringUtil.parseArrayToString(seasonReward);
} }
@ -514,33 +615,33 @@ public class ArenaLogic {
} }
return ""; return "";
} }
public void updateArenaSeason(int curSeason){ public void updateArenaSeason(int curSeason) {
this.curSeason = curSeason; this.curSeason = curSeason;
if(this.curSeason!=0){ if (this.curSeason != 0) {
viewSeason = this.curSeason; viewSeason = this.curSeason;
} }
} }
public void playWithSb(ISession session,int challengeUid,int myteamId) throws Exception { public void playWithSb(ISession session, int challengeUid, int myteamId) throws Exception {
User mine = UserManager.getUser(session.getUid()); User mine = UserManager.getUser(session.getUid());
User defUser = UserManager.getUser(challengeUid); User defUser = UserManager.getUser(challengeUid);
if(!defUser.getTeamPosManager().getTeamPosForHero().containsKey(1)){ if (!defUser.getTeamPosManager().getTeamPosForHero().containsKey(1)) {
throw new ErrorCodeException(ErrorCode.newDefineCode("对方未设置阵容")); throw new ErrorCodeException(ErrorCode.newDefineCode("对方未设置阵容"));
} }
int myforce = HeroLogic.getInstance().calTeamTotalForce(mine, myteamId, false); int myforce = HeroLogic.getInstance().calTeamTotalForce(mine, myteamId, false);
int deforce = HeroLogic.getInstance().calTeamTotalForce(defUser, 1, false); int deforce = HeroLogic.getInstance().calTeamTotalForce(defUser, 1, false);
CommonProto.FightTeamInfo fightTeamInfo = BehaviorUtil.getFightTeamInfo(mine,myteamId,true); CommonProto.FightTeamInfo fightTeamInfo = BehaviorUtil.getFightTeamInfo(mine, myteamId, true);
CommonProto.FightTeamInfo deffightTeamInfo = BehaviorUtil.getFightTeamInfo(defUser,1,false); CommonProto.FightTeamInfo deffightTeamInfo = BehaviorUtil.getFightTeamInfo(defUser, 1, false);
if(myforce<deforce){ if (myforce < deforce) {
deffightTeamInfo = CommonProto.FightTeamInfo.newBuilder().mergeFrom(deffightTeamInfo).setFirstCamp(1).build(); deffightTeamInfo = CommonProto.FightTeamInfo.newBuilder().mergeFrom(deffightTeamInfo).setFirstCamp(1).build();
} }
//设置战斗随机种子 //设置战斗随机种子
int seed = (int)(System.currentTimeMillis()/1000); int seed = (int) (System.currentTimeMillis() / 1000);
CommonProto.FightData build = CommonProto.FightData.newBuilder() CommonProto.FightData build = CommonProto.FightData.newBuilder()
.setFightMaxTime(SArenaSetting.getSArenaSetting().getMostTime()) .setFightMaxTime(SArenaSetting.getSArenaSetting().getMostTime())
.setFightSeed(seed) .setFightSeed(seed)
@ -548,10 +649,9 @@ public class ArenaLogic {
.addMonsterList(deffightTeamInfo) .addMonsterList(deffightTeamInfo)
.build(); .build();
ArenaInfoProto.PlayWithSbResponse response = ArenaInfoProto.PlayWithSbResponse.newBuilder().setFightData(build).build(); ArenaInfoProto.PlayWithSbResponse response = ArenaInfoProto.PlayWithSbResponse.newBuilder().setFightData(build).build();
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.PLAY_WITH_SB_RESPONSE_VALUE,response,true); MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.PLAY_WITH_SB_RESPONSE_VALUE, response, true);
} }
} }