竞技场和猎妖之路刷新时间

zhangshanxue 2020-07-01 05:00:38 +08:00
parent 1abdf0bcb7
commit 6ab7e8beee
10 changed files with 356 additions and 216 deletions

View File

@ -107,6 +107,16 @@ public class CommonStaticConfig extends AbstractClassStaticConfig {
long timeInMillis = calendar.getTimeInMillis();
sGlobalSystemConfig.setSeasonOpenLong(timeInMillis + Integer.parseInt(sGlobalSystemConfig.getSeasonOpen()) * 1000L);
sGlobalSystemConfig.setSeasonEndLong(timeInMillis + Integer.parseInt(sGlobalSystemConfig.getSeasonEnd()) * 1000L);
}else if( 5 == sGlobalSystemConfig.getType()){
long cacheOpenTime = GameApplication.serverConfig.getCacheOpenTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(cacheOpenTime);
calendar.set(Calendar.HOUR_OF_DAY,5);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
long timeInMillis = calendar.getTimeInMillis();
sGlobalSystemConfig.setSeasonOpenLong(timeInMillis + Integer.parseInt(sGlobalSystemConfig.getSeasonOpen()) * 1000L);
sGlobalSystemConfig.setSeasonEndLong(timeInMillis + Integer.parseInt(sGlobalSystemConfig.getSeasonEnd()) * 1000L);
} else {
sGlobalSystemConfig.setSeasonOpenLong(TimeUtils.parseTimeToMiles(sGlobalSystemConfig.getSeasonOpen(), TimeUtils.Stand_CeHua_Data_format));
sGlobalSystemConfig.setSeasonEndLong(TimeUtils.parseTimeToMiles(sGlobalSystemConfig.getSeasonEnd(), TimeUtils.Stand_CeHua_Data_format));

View File

@ -21,7 +21,7 @@ import java.lang.reflect.Type;
public abstract class BaseHandler<T extends GeneratedMessage> {
Class<T> protoClazz;
private static final Logger LOGGER = LoggerFactory.getLogger(BaseHandler.class);
public static final Logger LOGGER = LoggerFactory.getLogger(BaseHandler.class);
public BaseHandler(){
getTClassIsNull();
}

View File

@ -1,25 +1,130 @@
package com.ljsd.jieling.handler.arena;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.ktbeans.KTGameType;
import com.ljsd.jieling.ktbeans.KtEventUtils;
import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean;
import com.ljsd.jieling.logic.activity.event.ArenaChallengeEvent;
import com.ljsd.jieling.logic.activity.event.Poster;
import com.ljsd.jieling.logic.arena.ArenaLogic;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.logic.dao.ArenaEnemy;
import com.ljsd.jieling.logic.dao.ArenaManager;
import com.ljsd.jieling.logic.dao.ArenaRecord;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.logic.mission.GameEvent;
import com.ljsd.jieling.network.server.ProtocolsManager;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.ArenaInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.*;
import config.SArenaSetting;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class ArenaChallengeHandler extends BaseHandler {
public class ArenaChallengeHandler extends BaseHandler<ArenaInfoProto.ArenaChallengeRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.ARENA_CHALLENGE_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
byte[] bytes = netData.parseClientProtoNetData();
ArenaInfoProto.ArenaChallengeRequest arenaChallengeRequest = ArenaInfoProto.ArenaChallengeRequest.parseFrom(bytes);
ArenaLogic.getInstance().challenge(iSession,arenaChallengeRequest.getChallengeUid(),arenaChallengeRequest.getTeamId(),arenaChallengeRequest.getSkipFight());
public void processWithProto(ISession session, ArenaInfoProto.ArenaChallengeRequest arenaChallengeRequest) throws Exception {
int challengeUid = arenaChallengeRequest.getChallengeUid();
int teamId = arenaChallengeRequest.getTeamId();
int skipFight =arenaChallengeRequest.getSkipFight();
int curSeason =ArenaLogic.getInstance().getCurSeason();
if(curSeason == 0){
throw new ErrorCodeException(ErrorCode.newDefineCode("season_close"));
}
int uid = session.getUid();
User user = UserManager.getUser(uid);
ArenaManager arenaManager = user.getArenaManager();
List<ArenaEnemy> arenaEnemies = arenaManager.getArenaEnemies();
ArenaEnemy enemyInfo = ArenaLogic.getInstance().getEnemyInList(challengeUid, arenaEnemies);
String err = ArenaLogic.getInstance().checkChallenge(user,skipFight,enemyInfo );
if(!"".equals(err)){
throw new ErrorCodeException(ErrorCode.newDefineCode(err));
}
int fightResult=0;
int myscore = SArenaSetting.getSArenaSetting().getScore();
int defScore = SArenaSetting.getSArenaSetting().getScore();
int enemyType = enemyInfo.getEnemyType();
int myscoreChange=0;
int defScoreChange=0;
if(arenaManager.getCount()!=0 && arenaManager.getSeason()==curSeason) {
myscore = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK, Integer.toString(curSeason), Integer.toString(uid)).intValue();
}
user.getTeamPosManager().setCurTeamPosId(teamId);
ArenaInfoProto.ArenaChallengeResponse.Builder builder = ArenaInfoProto.ArenaChallengeResponse.newBuilder();
User defUser = null;
if( enemyType == GlobalsDef.ARENA_PLAYER_TYPE){
ArenaRecord arenaRecord = new ArenaRecord();
defUser = UserManager.getUser(challengeUid);
fightResult = ArenaLogic.getFightResultByPersonToPerson(user, teamId, defUser, GlobalsDef.TEAM_ARENA_DEFENSE,arenaRecord,builder);
if(fightResult == -1){
throw new ErrorCodeException(ErrorCode.FIGHT_EXCEPTION);
}
defScore = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(challengeUid)).intValue();
if(defScore == -1){
defScore = SArenaSetting.getSArenaSetting().getScore();
}
defScoreChange = ArenaLogic.getInstance().calScore(defScore, myscore,fightResult==1?0:1);
myscoreChange = ArenaLogic.getInstance().calScore(myscore, defScore,fightResult);
if(defUser.getArenaManager().getCount()!=0 && defUser.getArenaManager().getSeason() == curSeason){
arenaRecord.setAttackId(uid);
arenaRecord.setDefScore(defScoreChange);
arenaRecord.setAttackForce( HeroLogic.getInstance().calTeamTotalForce(user, GlobalsDef.TEAM_ARENA_DEFENSE,false));
arenaRecord.setCreateTime((int)(System.currentTimeMillis()/1000));
arenaRecord.setId(KeyGenUtils.produceIdByModule(UUIDEnum.ARENARECORD,uid));
arenaRecord.setFightResult(fightResult^1);
RedisUtil.getInstence().putMapEntry(RedisKey.ARENA_RRECORD,Integer.toString(challengeUid),arenaRecord.getId(),arenaRecord);
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason),Integer.toString(challengeUid),defScoreChange);
MessageUtil.sendRedIndication(challengeUid,GlobalsDef.ARENA_CHALLENGE_TYPE);
}
}else{
fightResult = ArenaLogic.getInstance().getFightResultByPersonToRobot(user, teamId,challengeUid,builder);
if(fightResult == -1){
throw new ErrorCodeException(ErrorCode.FIGHT_EXCEPTION);
}
myscoreChange = ArenaLogic.getInstance().calScore(myscore, defScore,fightResult);
defScoreChange = ArenaLogic.getInstance().calScore(defScore, myscore,fightResult^1);
}
LOGGER.info("the uid={},the defUid={},myscore={},defScore={},fightResult={},myScoreChange={},defScoreChange={}",uid,challengeUid,myscore,defScore,fightResult,myscoreChange,defScoreChange);
if(arenaManager.getCount() == 0){
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason),Integer.toString(uid),myscoreChange + myscore);
}else{
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason),Integer.toString(uid),myscoreChange);
}
ArenaLogic.getInstance().setMyArenaEnemys(uid,user);
arenaManager.updateChallenge(fightResult);
//组战斗数据
ArenaInfoProto.ArenaChallengeResponse build = builder
.setMyScoreChange(myscoreChange).setDefScoreChange(defScoreChange)
.addAllArenaEnemys(ArenaLogic.getInstance().getArenaEnemyList(arenaManager.getArenaEnemies()))
.setFightResult(fightResult)
.build();
user.getUserMissionManager().onGameEvent(user, GameEvent.ARENA_CHALLENGE,fightResult, myscore + myscoreChange);
if(defUser!=null && defUser.getArenaManager().getCount()>0) {
AyyncWorker ayyncWorker = new AyyncWorker(defUser, true, new AynMissionWorker(GameEvent.ARENA_CHALLENGE, -999, defScore + defScoreChange));
ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
}
Poster.getPoster().dispatchEvent(new ArenaChallengeEvent(user.getId()));
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,build,true);
KtEventUtils.onKtEvent(user, ParamEventBean.UserGameType, KTGameType.ARENA.getIndex(),challengeUid);
}
}

View File

@ -1,11 +1,20 @@
package com.ljsd.jieling.handler.arena;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.arena.ArenaLogic;
import com.ljsd.jieling.logic.dao.ArenaManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.ArenaInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.MessageUtil;
import config.SArenaSetting;
import org.springframework.stereotype.Component;
import util.TimeUtils;
@Component
@ -16,7 +25,28 @@ public class ArenaRandomHandler extends BaseHandler {
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
ArenaLogic.getInstance().randomEnemys(iSession);
public void process(ISession session, PacketNetData netData) throws Exception {
int curSeason =ArenaLogic.getInstance().getCurSeason();
if(curSeason == 0){
throw new ErrorCodeException(ErrorCode.newDefineCode("season_close"));
}
int uid = session.getUid();
SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting();
if(sArenaSetting == null){
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
User user = UserManager.getUser(uid);
ArenaManager arenaManager = user.getArenaManager();
int flushEnenyTime = arenaManager.getFlushTime();
int coldTime = sArenaSetting.getColdTime();
int now = (int)(TimeUtils.now()/1000);
if( now - flushEnenyTime < coldTime-1 ){
throw new ErrorCodeException(ErrorCode.ARENA_RANDOM_ENEMY_CODE_TIME);
}
//刷新选手
ArenaLogic.getInstance().setMyArenaEnemys(uid,user);
arenaManager.setFlushTime(now);
ArenaInfoProto.ArenaRandomResponse build = ArenaInfoProto.ArenaRandomResponse.newBuilder().addAllArenaEnemys(ArenaLogic.getInstance().getArenaEnemyList(arenaManager.getArenaEnemies())).build();
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_RANDOM_ENEMY_RESPONSE_VALUE,build,true);
}
}

View File

@ -1,12 +1,27 @@
package com.ljsd.jieling.handler.arena;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.arena.ArenaLogic;
import com.ljsd.jieling.logic.dao.ArenaEnemy;
import com.ljsd.jieling.logic.dao.ArenaManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.ArenaInfoProto;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.MessageUtil;
import config.SArenaSetting;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@Component
public class GetArenaInfoHandler extends BaseHandler {
@Override
@ -15,7 +30,34 @@ public class GetArenaInfoHandler extends BaseHandler {
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
ArenaLogic.getInstance().getArenaInfo(iSession);
public void process(ISession session, PacketNetData netData) throws Exception {
int curSeason =ArenaLogic.getInstance().getCurSeason();
int uid = session.getUid();
User user = UserManager.getUser(uid);
ArenaManager arenaManager = user.getArenaManager();
if(arenaManager.getSeason()!=curSeason){
arenaManager.resetSeason(curSeason);
RedisUtil.getInstence().del(RedisKey.ARENA_RRECORD,Integer.toString(uid));
}
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(uid)).intValue();
if(score == -1){
score = SArenaSetting.getSArenaSetting().getScore();
}
if(arenaManager.getFlushNums() == 0){
List<ArenaEnemy> arenaEnemies = new ArrayList<>();
Set<Integer> robotIds = ArenaLogic.randomRobot(score, 5);
ArenaLogic.getInstance().toArenaEnemy(uid,robotIds,arenaEnemies, GlobalsDef.ARENA_ROBOT_TYPE);
arenaManager.setArenaEnemies(arenaEnemies);
}
CommonProto.ArenaInfo build = CommonProto.ArenaInfo.newBuilder()
.setFailNums(arenaManager.getFailNums())
.setSuccessNums(arenaManager.getSuccessNums())
.setScore(score)
.addAllArenaEnemys(ArenaLogic.getInstance().getArenaEnemyList(arenaManager.getArenaEnemies()))
.build();
ArenaInfoProto.GetArenaInfoResponse getArenaInfoResponse = ArenaInfoProto.GetArenaInfoResponse.newBuilder().setArenaInfo(build).build();
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_INFO_RESPONSE_VALUE,getArenaInfoResponse,true);
}
}

View File

@ -1,12 +1,26 @@
package com.ljsd.jieling.handler.arena;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.arena.ArenaLogic;
import com.ljsd.jieling.logic.dao.ArenaRecord;
import com.ljsd.jieling.logic.dao.PlayerManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.ArenaInfoProto;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.MessageUtil;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class GetArenaRecordHandler extends BaseHandler {
@ -17,6 +31,61 @@ public class GetArenaRecordHandler extends BaseHandler {
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
ArenaLogic.getInstance().getArenaRecord(iSession);
int curSeason =ArenaLogic.getInstance().getCurSeason();
if(curSeason == 0){
throw new ErrorCodeException(ErrorCode.newDefineCode("season_close"));
}
int uid = iSession.getUid();
User user = UserManager.getUser(uid);
user.getPlayerInfoManager().removeRed(GlobalsDef.ARENA_CHALLENGE_TYPE);
Map<String, ArenaRecord> result = RedisUtil.getInstence().getMapValues(RedisKey.ARENA_RRECORD, Integer.toString(uid), String.class, ArenaRecord.class);
if(result!=null && !result.isEmpty()){
List<CommonProto.ArenaRecordInfo> arenaRecordInfos = new ArrayList<>();
List<ArenaRecord> arenaRecordList = new ArrayList<>(result.values());
Collections.sort(arenaRecordList, new Comparator<ArenaRecord>() {
@Override
public int compare(ArenaRecord o1, ArenaRecord o2) {
Integer createTime = o1.getCreateTime();
return createTime.compareTo(o2.getCreateTime());
}
});
int size = arenaRecordList.size();
if(size>10){
String[] removeMapKeys = new String[size - 10];
for(int i=0;i<size-10;i++){
ArenaRecord remove = arenaRecordList.remove(0);
String removeId = remove.getId();
removeMapKeys[i]=(removeId);
}
RedisUtil.getInstence().removeMapEntrys(RedisKey.ARENA_RRECORD,Integer.toString(uid),removeMapKeys);
}
for(ArenaRecord arenaRecord : arenaRecordList){
int attackId = arenaRecord.getAttackId();
int attackForce = arenaRecord.getAttackForce();
User attackUser = UserManager.getUser(attackId);
PlayerManager playerInfoManager = attackUser.getPlayerInfoManager();
CommonProto.ArenaPersonInfo arenaPersonInfo = CommonProto.ArenaPersonInfo.newBuilder()
.setUid(attackId)
.setName(playerInfoManager.getNickName())
.setLevel(playerInfoManager.getLevel())
.setHead(playerInfoManager.getHead())
.setTotalForce(attackForce)
.setScore( RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(attackId)).intValue())
.build();
arenaRecordInfos.add(CommonProto.ArenaRecordInfo.newBuilder()
.setId(arenaRecord.getId())
.setAttackInfo(arenaPersonInfo)
.setMyScoreChange(arenaRecord.getDefScore())
.setAttackTime(arenaRecord.getCreateTime())
.setFightResult(arenaRecord.getFightResult())
.build());
}
ArenaInfoProto.ArenaRecordInfoResponse build = ArenaInfoProto.ArenaRecordInfoResponse.newBuilder().addAllArenaRecordInfo(arenaRecordInfos).build();
MessageUtil.sendMessage(iSession,1, MessageTypeProto.MessageType.ARENA_DEFENSE_RESPONSE_VALUE,build,true);
return;
}
MessageUtil.sendMessage(iSession,1, MessageTypeProto.MessageType.ARENA_DEFENSE_RESPONSE_VALUE,null,true);
}
}

View File

@ -1,10 +1,17 @@
package com.ljsd.jieling.handler.champion;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.championship.ChampionshipLogic;
import com.ljsd.jieling.logic.dao.ArenaRecord;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.ArenaInfoProto;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.MessageUtil;
public class ChampinGetHandler extends BaseHandler {
@Override
@ -13,7 +20,47 @@ public class ChampinGetHandler extends BaseHandler {
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
ChampionshipLogic.getChampionInfo(iSession);
public void process(ISession session, PacketNetData netData) throws Exception {
int uid = session.getUid();
int progress = ChampionshipLogic.getProgress(); //阶段
int roundTimes = ChampionshipLogic.getRoundTimes(); //比赛进行第几轮
int endTime = ChampionshipLogic.getEndTime(); //比赛进行第几轮
//组装数据
int myRank = RedisUtil.getInstence().getZSetreverseRank(RedisKey.CHAMPION_RANK, "", Integer.toString(uid)).intValue();
int topMaxRank = UserManager.getUser(uid).getArenaManager().getTopMaxRank();
ArenaInfoProto.ChampionGetInfoResponse.Builder builder = ArenaInfoProto.ChampionGetInfoResponse.newBuilder().setProgress(progress).setEndTime(endTime).setMyrank(myRank).setMaxRank(topMaxRank);
if(myRank!=-1){
if(progress == -2 || progress/100 == 2){
ChampionshipLogic.MemberInfo memberInfo = RedisUtil.getInstence().getMapEntry(RedisKey.CHAMPION_JOIN, "", Integer.toString(uid), ChampionshipLogic.MemberInfo.class);
builder.setMyscore(memberInfo.getScore());
}else{
builder.setMyscore(RedisUtil.getInstence().getZSetScore(RedisKey.CHAMPION_RANK, "", Integer.toString(uid)).intValue());
}
builder.setJoinState(1);
String key = RedisUtil.getInstence().getKey(RedisKey.CHAMPION_MY_BATTLLE_IDS, Integer.toString(uid));
Object latestKey = RedisUtil.getInstence().lGetIndex(key, -1);
if(latestKey!=null){
ArenaRecord arenaRecord = RedisUtil.getInstence().getMapValue(RedisKey.CHAMPION_ARENA_RECORD, "", latestKey.toString(), ArenaRecord.class);
int enemyId = arenaRecord.getDefUid();
int attackId = arenaRecord.getAttackId();
int fightResult = arenaRecord.getFightResult();
CommonProto.ChampionBattleInfo.Builder builder1 = CommonProto.ChampionBattleInfo.newBuilder();
if(roundTimes == arenaRecord.getRoundTims() && (progress%10%4 != 3 || fightResult==-2)){
fightResult =-1;
}
if(fightResult!=-1){
builder1.setFightData( CommonProto.FightData.parseFrom(arenaRecord.getFightData()));
}
builder.setChampionBattleInfo(builder1
.setMyInfo(ChampionshipLogic.getChampionBattleInfo(attackId))
.setEnemyInfo(ChampionshipLogic.getChampionBattleInfo(enemyId))
.setResult(fightResult)
.build());
}
}
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.CHAMPION_GET_RESPONSE_VALUE,builder.build(),true);
}
}

View File

@ -67,35 +67,6 @@ public class ArenaLogic {
return curSeason;
}
public void getArenaInfo(ISession session) throws Exception {
int uid = session.getUid();
User user = UserManager.getUser(uid);
ArenaManager arenaManager = user.getArenaManager();
if(arenaManager.getSeason()!=curSeason){
arenaManager.resetSeason(curSeason);
RedisUtil.getInstence().del(RedisKey.ARENA_RRECORD,Integer.toString(uid));
}
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(uid)).intValue();
if(score == -1){
score = SArenaSetting.getSArenaSetting().getScore();
}
if(arenaManager.getFlushNums() == 0){
List<ArenaEnemy> arenaEnemies = new ArrayList<>();
Set<Integer> robotIds = randomRobot(score, 5);
toArenaEnemy(uid,robotIds,arenaEnemies, GlobalsDef.ARENA_ROBOT_TYPE);
arenaManager.setArenaEnemies(arenaEnemies);
}
CommonProto.ArenaInfo build = CommonProto.ArenaInfo.newBuilder()
.setFailNums(arenaManager.getFailNums())
.setSuccessNums(arenaManager.getSuccessNums())
.setScore(score)
.addAllArenaEnemys(getArenaEnemyList(arenaManager.getArenaEnemies()))
.build();
ArenaInfoProto.GetArenaInfoResponse getArenaInfoResponse = ArenaInfoProto.GetArenaInfoResponse.newBuilder().setArenaInfo(build).build();
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_INFO_RESPONSE_VALUE,getArenaInfoResponse,true);
}
public List<CommonProto.ArenaEnemy> getArenaEnemyList(List<ArenaEnemy> arenaEnemies) throws Exception {
@ -154,88 +125,6 @@ public class ArenaLogic {
}
public void challenge(ISession session,int challengeUid,int teamId,int skipFight) throws Exception {
if(curSeason == 0){
throw new ErrorCodeException(ErrorCode.newDefineCode("season_close"));
}
int uid = session.getUid();
User user = UserManager.getUser(uid);
ArenaManager arenaManager = user.getArenaManager();
List<ArenaEnemy> arenaEnemies = arenaManager.getArenaEnemies();
ArenaEnemy enemyInfo = getEnemyInList(challengeUid, arenaEnemies);
String err = checkChallenge(user,skipFight,enemyInfo );
if(!"".equals(err)){
throw new ErrorCodeException(ErrorCode.newDefineCode(err));
}
int fightResult=0;
int myscore = SArenaSetting.getSArenaSetting().getScore();
int defScore = SArenaSetting.getSArenaSetting().getScore();
int enemyType = enemyInfo.getEnemyType();
int myscoreChange=0;
int defScoreChange=0;
if(arenaManager.getCount()!=0 && arenaManager.getSeason()==curSeason) {
myscore = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK, Integer.toString(curSeason), Integer.toString(uid)).intValue();
}
user.getTeamPosManager().setCurTeamPosId(teamId);
ArenaInfoProto.ArenaChallengeResponse.Builder builder = ArenaInfoProto.ArenaChallengeResponse.newBuilder();
User defUser = null;
if( enemyType == GlobalsDef.ARENA_PLAYER_TYPE){
ArenaRecord arenaRecord = new ArenaRecord();
defUser = UserManager.getUser(challengeUid);
fightResult = getFightResultByPersonToPerson(user, teamId, defUser, GlobalsDef.TEAM_ARENA_DEFENSE,arenaRecord,builder);
if(fightResult == -1){
throw new ErrorCodeException(ErrorCode.FIGHT_EXCEPTION);
}
defScore = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(challengeUid)).intValue();
if(defScore == -1){
defScore = SArenaSetting.getSArenaSetting().getScore();
}
defScoreChange = calScore(defScore, myscore,fightResult==1?0:1);
myscoreChange = calScore(myscore, defScore,fightResult);
if(defUser.getArenaManager().getCount()!=0 && defUser.getArenaManager().getSeason() == curSeason){
arenaRecord.setAttackId(uid);
arenaRecord.setDefScore(defScoreChange);
arenaRecord.setAttackForce( HeroLogic.getInstance().calTeamTotalForce(user, GlobalsDef.TEAM_ARENA_DEFENSE,false));
arenaRecord.setCreateTime((int)(System.currentTimeMillis()/1000));
arenaRecord.setId(KeyGenUtils.produceIdByModule(UUIDEnum.ARENARECORD,uid));
arenaRecord.setFightResult(fightResult^1);
RedisUtil.getInstence().putMapEntry(RedisKey.ARENA_RRECORD,Integer.toString(challengeUid),arenaRecord.getId(),arenaRecord);
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason),Integer.toString(challengeUid),defScoreChange);
MessageUtil.sendRedIndication(challengeUid,GlobalsDef.ARENA_CHALLENGE_TYPE);
}
}else{
fightResult = getFightResultByPersonToRobot(user, teamId,challengeUid,builder);
if(fightResult == -1){
throw new ErrorCodeException(ErrorCode.FIGHT_EXCEPTION);
}
myscoreChange = calScore(myscore, defScore,fightResult);
defScoreChange = calScore(defScore, myscore,fightResult^1);
}
LOGGER.info("the uid={},the defUid={},myscore={},defScore={},fightResult={},myScoreChange={},defScoreChange={}",uid,challengeUid,myscore,defScore,fightResult,myscoreChange,defScoreChange);
if(arenaManager.getCount() == 0){
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason),Integer.toString(uid),myscoreChange + myscore);
}else{
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason),Integer.toString(uid),myscoreChange);
}
setMyArenaEnemys(uid,user);
arenaManager.updateChallenge(fightResult);
//组战斗数据
ArenaInfoProto.ArenaChallengeResponse build = builder
.setMyScoreChange(myscoreChange).setDefScoreChange(defScoreChange)
.addAllArenaEnemys(getArenaEnemyList(arenaManager.getArenaEnemies()))
.setFightResult(fightResult)
.build();
user.getUserMissionManager().onGameEvent(user, GameEvent.ARENA_CHALLENGE,fightResult, myscore + myscoreChange);
if(defUser!=null && defUser.getArenaManager().getCount()>0) {
AyyncWorker ayyncWorker = new AyyncWorker(defUser, true, new AynMissionWorker(GameEvent.ARENA_CHALLENGE, -999, defScore + defScoreChange));
ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
}
Poster.getPoster().dispatchEvent(new ArenaChallengeEvent(user.getId()));
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,build,true);
KtEventUtils.onKtEvent(user, ParamEventBean.UserGameType,KTGameType.ARENA.getIndex(),challengeUid);
}
public void setMyArenaEnemys(int uid,User user){
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(uid)).intValue();
@ -308,7 +197,7 @@ public class ArenaLogic {
return fightResult.getCheckResult()[0];
}
private String checkChallenge(User user,int skipFight, ArenaEnemy enemyInfo) throws Exception {
public String checkChallenge(User user,int skipFight, ArenaEnemy enemyInfo) throws Exception {
if( null == enemyInfo ){
return "对手错误";
}
@ -334,7 +223,7 @@ public class ArenaLogic {
}
private ArenaEnemy getEnemyInList(int challengeUid, List<ArenaEnemy> enemys) {
public ArenaEnemy getEnemyInList(int challengeUid, List<ArenaEnemy> enemys) {
for (ArenaEnemy data : enemys) {
if (data.getEnemyId() == challengeUid) {
return data;
@ -344,30 +233,30 @@ public class ArenaLogic {
}
public void randomEnemys(ISession session) throws Exception {
if(curSeason == 0){
throw new ErrorCodeException(ErrorCode.newDefineCode("season_close"));
}
int uid = session.getUid();
SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting();
if(sArenaSetting == null){
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
User user = UserManager.getUser(uid);
ArenaManager arenaManager = user.getArenaManager();
int flushEnenyTime = arenaManager.getFlushTime();
int coldTime = sArenaSetting.getColdTime();
int now = (int)(TimeUtils.now()/1000);
if( now - flushEnenyTime < coldTime-1 ){
throw new ErrorCodeException(ErrorCode.ARENA_RANDOM_ENEMY_CODE_TIME);
}
//刷新选手
setMyArenaEnemys(uid,user);
arenaManager.setFlushTime(now);
ArenaInfoProto.ArenaRandomResponse build = ArenaInfoProto.ArenaRandomResponse.newBuilder().addAllArenaEnemys(getArenaEnemyList(arenaManager.getArenaEnemies())).build();
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_RANDOM_ENEMY_RESPONSE_VALUE,build,true);
}
//
// public void randomEnemys(ISession session) throws Exception {
// if(curSeason == 0){
// throw new ErrorCodeException(ErrorCode.newDefineCode("season_close"));
// }
// int uid = session.getUid();
// SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting();
// if(sArenaSetting == null){
// throw new ErrorCodeException(ErrorCode.CFG_NULL);
// }
// User user = UserManager.getUser(uid);
// ArenaManager arenaManager = user.getArenaManager();
// int flushEnenyTime = arenaManager.getFlushTime();
// int coldTime = sArenaSetting.getColdTime();
// int now = (int)(TimeUtils.now()/1000);
// if( now - flushEnenyTime < coldTime-1 ){
// throw new ErrorCodeException(ErrorCode.ARENA_RANDOM_ENEMY_CODE_TIME);
// }
// //刷新选手
// setMyArenaEnemys(uid,user);
// arenaManager.setFlushTime(now);
// ArenaInfoProto.ArenaRandomResponse build = ArenaInfoProto.ArenaRandomResponse.newBuilder().addAllArenaEnemys(getArenaEnemyList(arenaManager.getArenaEnemies())).build();
// MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_RANDOM_ENEMY_RESPONSE_VALUE,build,true);
// }
public static Set<Integer> randomRobot(int userSscore,int nums){
Set<Integer> robotIds = new HashSet<>(5);
@ -424,7 +313,7 @@ public class ArenaLogic {
}
private 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){
if(1 == type && enemyId == uid){
continue;
@ -497,68 +386,6 @@ public class ArenaLogic {
public void getArenaRecord(ISession iSession) throws Exception {
if(curSeason == 0){
throw new ErrorCodeException(ErrorCode.newDefineCode("season_close"));
}
int uid = iSession.getUid();
User user = UserManager.getUser(uid);
user.getPlayerInfoManager().removeRed(GlobalsDef.ARENA_CHALLENGE_TYPE);
Map<String, ArenaRecord> result = RedisUtil.getInstence().getMapValues(RedisKey.ARENA_RRECORD, Integer.toString(uid), String.class, ArenaRecord.class);
if(result!=null && !result.isEmpty()){
List<CommonProto.ArenaRecordInfo> arenaRecordInfos = new ArrayList<>();
List<ArenaRecord> arenaRecordList = new ArrayList<>(result.values());
Collections.sort(arenaRecordList, new Comparator<ArenaRecord>() {
@Override
public int compare(ArenaRecord o1, ArenaRecord o2) {
Integer createTime = o1.getCreateTime();
return createTime.compareTo(o2.getCreateTime());
}
});
int size = arenaRecordList.size();
if(size>10){
String[] removeMapKeys = new String[size - 10];
for(int i=0;i<size-10;i++){
ArenaRecord remove = arenaRecordList.remove(0);
String removeId = remove.getId();
removeMapKeys[i]=(removeId);
}
RedisUtil.getInstence().removeMapEntrys(RedisKey.ARENA_RRECORD,Integer.toString(uid),removeMapKeys);
}
for(ArenaRecord arenaRecord : arenaRecordList){
int attackId = arenaRecord.getAttackId();
int attackForce = arenaRecord.getAttackForce();
User attackUser = UserManager.getUser(attackId);
PlayerManager playerInfoManager = attackUser.getPlayerInfoManager();
CommonProto.ArenaPersonInfo arenaPersonInfo = CommonProto.ArenaPersonInfo.newBuilder()
.setUid(attackId)
.setName(playerInfoManager.getNickName())
.setLevel(playerInfoManager.getLevel())
.setHead(playerInfoManager.getHead())
.setTotalForce(attackForce)
.setScore( RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(attackId)).intValue())
.build();
arenaRecordInfos.add(CommonProto.ArenaRecordInfo.newBuilder()
.setId(arenaRecord.getId())
.setAttackInfo(arenaPersonInfo)
.setMyScoreChange(arenaRecord.getDefScore())
.setAttackTime(arenaRecord.getCreateTime())
.setFightResult(arenaRecord.getFightResult())
.build());
}
ArenaInfoProto.ArenaRecordInfoResponse build = ArenaInfoProto.ArenaRecordInfoResponse.newBuilder().addAllArenaRecordInfo(arenaRecordInfos).build();
MessageUtil.sendMessage(iSession,1, MessageTypeProto.MessageType.ARENA_DEFENSE_RESPONSE_VALUE,build,true);
return;
}
MessageUtil.sendMessage(iSession,1, MessageTypeProto.MessageType.ARENA_DEFENSE_RESPONSE_VALUE,null,true);
}
/**
*

View File

@ -60,6 +60,16 @@ public class ChampionshipLogic {
gameFightTypeMap.put(2,GameFightType.TOPArena2RobotFight);
}
public static int getProgress() {
return progress;
}
public static int getRoundTimes() {
return roundTimes;
}
public static int getEndTime() {
return endTime;
}
public static void viewFinalInfo(ISession iSession, int type) throws Exception {
if (schedule != 2) {
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
@ -541,7 +551,7 @@ public class ChampionshipLogic {
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.CHAMPION_BET_INFO_RESPONSE_VALUE,builder.build(),true);
}
private static CommonProto.TeamOneInfo.Builder getChampionBattleInfo(int uid) throws Exception {
public static CommonProto.TeamOneInfo.Builder getChampionBattleInfo(int uid) throws Exception {
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(uid);
if(sArenaRobotConfig!=null){
return PlayerLogic.getInstance().getRobotTeamInfo(sArenaRobotConfig);

View File

@ -101,7 +101,7 @@ public class ExpeditionLogic {
manager.getHeroMap().clear();
manager.clearEquipToTemp();
manager.clearEquip();
manager.setFreshTime((int)(System.currentTimeMillis()/1000));
manager.setFreshTime((int)(openTimeOfFuntionCacheByType.getStartTime()/1000));
checkAndResetTreasure(user);
SGlobalSystemConfig sGlobalSystemConfig = STableManager.getConfig(SGlobalSystemConfig.class).get(FunctionIdEnum.Expedition.getFunctionType());