自动切赛季

back_recharge
wangyuan 2019-05-13 17:41:53 +08:00
parent b467cd23f2
commit 41ec525158
9 changed files with 130 additions and 29 deletions

View File

@ -3,6 +3,7 @@ package com.ljsd.jieling.handler;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.logic.activity.ActivityLogic;
import com.ljsd.jieling.logic.activity.ActivityType;
import com.ljsd.jieling.logic.arena.ArenaLogic;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.store.StoreLogic;
@ -54,6 +55,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
//商店刷新次数重置
StoreLogic.resetStoreRefreshNum(userId);
//竞技场免费次数刷新
ArenaLogic.getInstance().flushFreeUseTimes(user);
}
user.getPlayerInfoManager().setLoginTime(TimeUtils.now());

View File

@ -79,6 +79,9 @@ public class GlobalDataManaager {
return;
}
GlobalSystemControl globalSystemControl = MongoUtil.getInstence().getMyMongoTemplate().findById(GameApplication.serverId, GlobalSystemControl.class);
if(globalSystemControl == null){
globalSystemControl = new GlobalSystemControl(GameApplication.serverId);
}
Map<Integer, TimeControllerOfFunction> timeControllerOfFunctionMap = globalSystemControl.getTimeControllerOfFunctionMap();
List<Integer> reallyOpenList = new ArrayList<>();
List<Integer> reallyCloseList = new ArrayList<>();
@ -87,6 +90,12 @@ public class GlobalDataManaager {
TimeControllerOfFunction timeControllerOfFunction = timeControllerOfFunctionMap.get(id);
if(timeControllerOfFunction == null || timeControllerOfFunction.getStartTime()!=openTimeOfFuntionCache.get(id).getStartTime()){
needUpdate = true;
TimeControllerOfFunction timeControllerOfFunctionCacheItem = openTimeOfFuntionCache.get(id);
if(timeControllerOfFunction!=null){
timeControllerOfFunctionCacheItem.setTimes(timeControllerOfFunction.getTimes()+1);
}else{
timeControllerOfFunctionCacheItem.setTimes(1);
}
globalSystemControl.updateTimeControllerOfFunction(openTimeOfFuntionCache.get(id));
reallyOpenList.add(id);
}
@ -94,7 +103,7 @@ public class GlobalDataManaager {
for(Integer id: closeList){
TimeControllerOfFunction timeControllerOfFunction = timeControllerOfFunctionMap.get(id);
if(timeControllerOfFunction != null || timeControllerOfFunction.getStartTime()!=openTimeOfFuntionCache.get(id).getStartTime()){
if(timeControllerOfFunction != null && timeControllerOfFunction.getStartTime()!=openTimeOfFuntionCache.get(id).getStartTime()){
needUpdate = true;
globalSystemControl.updateTimeControllerOfFunction(openTimeOfFuntionCache.get(id));
reallyCloseList.add(id);
@ -111,7 +120,10 @@ public class GlobalDataManaager {
public void openAction(List<Integer> ids){
for(Integer openId : ids){
TimeControllerOfFunction timeControllerOfFunction = openTimeOfFuntionCache.get(openId);
switch (openId){
case 8:
ArenaLogic.getInstance().updateArenaSeason(timeControllerOfFunction.getTimes());
default:
break;
}
@ -124,6 +136,7 @@ public class GlobalDataManaager {
switch (closeId){
case 8:
ArenaLogic.getInstance().sendReward(GlobalsDef.ARENA_SEASON_REWARD);
ArenaLogic.getInstance().updateArenaSeason(0);
default:
break;
}
@ -131,7 +144,12 @@ public class GlobalDataManaager {
}
public void whenServerStart(){
ActivityLogic.getInstance().checkSecretBoxSeason();
try {
ActivityLogic.getInstance().checkSecretBoxSeason();
checkSystemFunctioIsOpen();
} catch (Exception e) {
LOGGER.error("e",e);
}
}

View File

@ -401,10 +401,12 @@ public class ActivityLogic {
private void flushSecretBoxFreeTimes(User user){
SecretBoxManager secretBoxManager = user.getSecretBoxManager();
Map<Integer, Integer> freeUseInfos = secretBoxManager.getFreeUseInfos();
if(freeUseInfos!=null && !freeUseInfos.isEmpty()){
for(Integer key : freeUseInfos.keySet()){
freeUseInfos.put(key,0);
if(secretBoxManager!=null){
Map<Integer, Integer> freeUseInfos = secretBoxManager.getFreeUseInfos();
if(freeUseInfos!=null && !freeUseInfos.isEmpty()){
for(Integer key : freeUseInfos.keySet()){
freeUseInfos.put(key,0);
}
}
}
}

View File

@ -40,6 +40,8 @@ public class ArenaLogic {
public static ArenaLogic getInstance() {
return ArenaLogic.Instance.instance;
}
private int curSeason;
@ -56,9 +58,9 @@ public class ArenaLogic {
arenaManager.setArenaEnemies(arenaEnemies);
}
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,"1", Integer.toString(uid)).intValue();
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(uid)).intValue();
if(score == -1){
score = 1000;
score = SArenaSetting.getSArenaSetting().getScore();
}
CommonProto.ArenaInfo build = CommonProto.ArenaInfo.newBuilder()
.setFailNums(arenaManager.getFailNums())
@ -108,7 +110,7 @@ public class ArenaLogic {
.setUid(enemyId)
.setLevel(playerInfoManager.getLevel())
.setName(playerInfoManager.getNickName())
.setScore(RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,"1", Integer.toString(enemyId)).intValue())
.setScore(RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(enemyId)).intValue())
.setHead(0)
.setTotalForce(totalForce)
.build();
@ -123,6 +125,10 @@ public class ArenaLogic {
public void challenge(ISession session,int challengeUid,int teamId,int skipFight) throws Exception {
if(curSeason == 0){
MessageUtil.sendErrorResponse(session,1, MessageTypeProto.MessageType.ARENA_CHALLENGE_RESPONSE_VALUE,"season_close");
return;
}
int uid = session.getUid();
User user = UserManager.getUser(uid);
String err = checkChallenge(user);
@ -145,24 +151,24 @@ public class ArenaLogic {
int defScoreChange=0;
if(arenaManager.getCount() != 0){
myscore = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,"1", Integer.toString(challengeUid)).intValue();
myscore = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(challengeUid)).intValue();
}
setMyArenaEnemys(uid,user);
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,"1",Integer.toString(uid),myscoreChange);
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason),Integer.toString(uid),myscoreChange);
ArenaInfoProto.ArenaChallengeResponse.Builder builder = ArenaInfoProto.ArenaChallengeResponse.newBuilder();
if( enemyType == GlobalsDef.ARENA_PLAYER_TYPE){
ArenaRecord arenaRecord = new ArenaRecord();
User defUser = UserManager.getUser(challengeUid);
fightResult = getFightResultByPersonToPerson(user, teamId, defUser, GlobalsDef.TEAM_ARENA_DEFENSE,arenaRecord,skipFight,builder);
defScore = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,"1", Integer.toString(challengeUid)).intValue();
defScore = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(challengeUid)).intValue();
defScoreChange = calScore(defScore, myscore,fightResult==1?0:1);
myscoreChange = calScore(myscore, defScore,fightResult);
arenaRecord.setAttackId(uid);
arenaRecord.setCreateTime((int)(System.currentTimeMillis()/1000));
arenaRecord.setId(KeyGenUtils.produceIdByModule(UUIDEnum.ARENARECORD,Integer.toString(uid)));
RedisUtil.getInstence().putMapEntry(RedisKey.ARENA_RRECORD,Integer.toString(challengeUid),arenaRecord.getId(),arenaRecord);
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,"1",Integer.toString(challengeUid),defScoreChange);
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason),Integer.toString(challengeUid),defScoreChange);
}else{
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(challengeUid);
fightResult = getFightResultByPersonToRobot(user, teamId,sArenaRobotConfig,skipFight,builder);
@ -171,7 +177,7 @@ public class ArenaLogic {
}
if(arenaManager.getCount() == 0){
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,"1",Integer.toString(uid),myscoreChange + SArenaSetting.getSArenaSetting().getScore() );
RedisUtil.getInstence().incrementZsetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason),Integer.toString(uid),myscoreChange + SArenaSetting.getSArenaSetting().getScore() );
}
arenaManager.updateChallenge(fightResult);
//组战斗数据
@ -186,7 +192,7 @@ public class ArenaLogic {
Set<Integer> robotIds = randomRobot(user.getPlayerInfoManager().getLevel(), 5);
toArenaEnemy(uid,robotIds,arenaEnemies,GlobalsDef.ARENA_ROBOT_TYPE);
}else{
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,"1", Integer.toString(uid)).intValue();
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(uid)).intValue();
if(score == -1){
score = SArenaSetting.getSArenaSetting().getScore();
}
@ -259,6 +265,11 @@ public class ArenaLogic {
return "";
}
public void flushFreeUseTimes(User user){
ArenaManager arenaManager = user.getArenaManager();
arenaManager.setUseFreeTimes(0);
}
private ArenaEnemy getEnemyInList(int challengeUid, List<ArenaEnemy> enemys) {
for (ArenaEnemy data : enemys) {
if (data.getEnemyId() == challengeUid) {
@ -271,6 +282,10 @@ public class ArenaLogic {
public void randomEnemys(ISession session) throws Exception {
if(curSeason == 0){
MessageUtil.sendErrorResponse(session,1, MessageTypeProto.MessageType.ARENA_RANDOM_ENEMY_RESPONSE_VALUE,"season_close");
return;
}
int uid = session.getUid();
SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting();
if(sArenaSetting == null){
@ -317,7 +332,7 @@ public class ArenaLogic {
for(int[] item: interval){
int low = item[0];
int high = item[1];
Set<String> arenaRank = RedisUtil.getInstence().getZsetRange(RedisKey.ARENA_RANK,"1", myScore * low / 100.0f-1, myScore * high / 100.0f +1);
Set<String> arenaRank = RedisUtil.getInstence().getZsetRange(RedisKey.ARENA_RANK,Integer.toString(curSeason), myScore * low / 100.0f-1, myScore * high / 100.0f +1);
if(arenaRank!=null && !arenaRank.isEmpty()){
arenaRank.remove(Integer.toString(uid));
String s = randomSet(arenaRank);
@ -351,13 +366,16 @@ public class ArenaLogic {
public void getWorldRankByPage(ISession session,int page) throws Exception {
if(curSeason == 0){
MessageUtil.sendErrorResponse(session,1, MessageTypeProto.MessageType.ARENA_RANK_RESPONSE_VALUE,"season_close");
return;
}
if (page == 0) {
page = 1;
}
int start = (page - 1) * 20, end = page * 20 - 1;
List<CommonProto.ArenaEnemy> arenaRankMemberInfo = new ArrayList<>(20);
Set<ZSetOperations.TypedTuple<String>> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK,"1", start, end);
Set<ZSetOperations.TypedTuple<String>> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK,Integer.toString(curSeason), start, end);
for(ZSetOperations.TypedTuple<String> item : arenaRankInfo){
String value = item.getValue();
int score =item.getScore().intValue();
@ -387,12 +405,12 @@ public class ArenaLogic {
.build());
}
int uid = session.getUid();
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,"1", Integer.toString(uid)).intValue();
int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(uid)).intValue();
int myRank =-1;
if(score == -1){
score = SArenaSetting.getSArenaSetting().getScore();
}else{
myRank= RedisUtil.getInstence().getZSetreverseRank(RedisKey.ARENA_RANK,"1",Integer.toString(uid)).intValue();
myRank= RedisUtil.getInstence().getZSetreverseRank(RedisKey.ARENA_RANK,Integer.toString(curSeason),Integer.toString(uid)).intValue();
}
ArenaInfoProto.GetArenaRankInfoResponse buildResponse = ArenaInfoProto.GetArenaRankInfoResponse.newBuilder()
@ -407,6 +425,10 @@ public class ArenaLogic {
public void getArenaRecord(ISession iSession) throws Exception {
if(curSeason == 0){
MessageUtil.sendErrorResponse(iSession,1, MessageTypeProto.MessageType.ARENA_DEFENSE_RESPONSE_VALUE,"season_close");
return;
}
int uid = iSession.getUid();
Map<String, ArenaRecord> result = RedisUtil.getInstence().getMapValues(RedisKey.ARENA_RRECORD, Integer.toString(uid), String.class, ArenaRecord.class);
if(result!=null && !result.isEmpty()){
@ -503,6 +525,9 @@ public class ArenaLogic {
* @throws Exception
*/
public void sendReward(int type) throws Exception {
if(curSeason == 0){
return;
}
String title;
String content;
if(type == GlobalsDef.ARENA_DAILY_REWARD){
@ -512,7 +537,7 @@ public class ArenaLogic {
title = SErrorCodeEerverConfig.getI18NMessage("arena_season_reward_title");
content = SErrorCodeEerverConfig.getI18NMessage("arena_season_reward_txt");
}
Set<ZSetOperations.TypedTuple<String>> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK,"1", 0, -1);
Set<ZSetOperations.TypedTuple<String>> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK,Integer.toString(curSeason), 0, -1);
int rank = 1;
int nowTime =(int) (TimeUtils.now()/1000);
for(ZSetOperations.TypedTuple<String> item : arenaRankInfo){
@ -544,6 +569,10 @@ public class ArenaLogic {
}
return "";
}
public void updateArenaSeason(int curSeason){
this.curSeason = curSeason;
}

View File

@ -1,13 +1,13 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
public class TimeControllerOfFunction extends MongoBase {
public class TimeControllerOfFunction {
private int id;
private int status;
private long startTime;
private long endTime;
private int times; //开了几次
public TimeControllerOfFunction(){}
@ -33,4 +33,12 @@ public class TimeControllerOfFunction extends MongoBase {
public long getEndTime() {
return endTime;
}
public int getTimes() {
return times;
}
public void setTimes(int times) {
this.times = times;
}
}

View File

@ -1,6 +1,5 @@
package com.ljsd.jieling.logic.dao.root;
import com.ljsd.common.mogodb.MongoRoot;
import com.ljsd.jieling.logic.dao.TimeControllerOfFunction;
import java.util.HashMap;
@ -14,6 +13,10 @@ public class GlobalSystemControl {
private Map<Integer, TimeControllerOfFunction> timeControllerOfFunctionMap = new HashMap<>();
public GlobalSystemControl(int id){
this.id = id;
}
public void updateTimeControllerOfFunction(TimeControllerOfFunction timeControllerOfFunction){
timeControllerOfFunctionMap.put(timeControllerOfFunction.getId(),timeControllerOfFunction);
}

View File

@ -1,5 +1,6 @@
package com.ljsd.jieling.thread;
import com.ljsd.jieling.thread.task.DailyOfZeroTask;
import com.ljsd.jieling.thread.task.MinuteTask;
import com.ljsd.jieling.thread.task.PlatConfigureTask;
import org.slf4j.Logger;
@ -59,12 +60,16 @@ public class ThreadManager {
public void go() {
long now = System.currentTimeMillis();
int now = (int)(System.currentTimeMillis()/1000);
scheduledExecutor = new ScheduledThreadPoolExecutor(16, new ScheduleThreadFactory());
// testTask 已秒为单位 延迟10s, 间隔30s为周期执行
int delayForMinute = 60 - (now%60);
int delayForDay = 3600*24 - (now%(3600*24));
scheduledExecutor.scheduleAtFixedRate(platConfigureTask, 10, PlatConfigureTask.SLEEP_INTEVAL_TIME, TimeUnit.SECONDS);
scheduledExecutor.scheduleAtFixedRate(new MinuteTask(), 10, 60, TimeUnit.SECONDS);
scheduledExecutor.scheduleAtFixedRate(new MinuteTask(), delayForMinute, 60, TimeUnit.SECONDS);
scheduledExecutor.scheduleAtFixedRate(new DailyOfZeroTask(), delayForDay, 3600*24, TimeUnit.SECONDS);
}
public ScheduledThreadPoolExecutor getScheduledExecutor() {

View File

@ -0,0 +1,26 @@
package com.ljsd.jieling.thread.task;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.logic.arena.ArenaLogic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DailyOfZeroTask extends Thread {
private static final Logger LOGGER = LoggerFactory.getLogger(DailyOfZeroTask.class);
public DailyOfZeroTask() {
this.setName("DailyOfZeroTask");
}
@Override
public void run() {
try {
LOGGER.info("DailyOfZeroTask start ...");
ArenaLogic.getInstance().sendReward(GlobalsDef.ARENA_DAILY_REWARD);
LOGGER.info("DailyOfZeroTask end ...");
} catch (Exception e) {
LOGGER.info("e",e);
}
}
}

View File

@ -1,6 +1,7 @@
package com.ljsd.jieling.thread.task;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.logic.GlobalDataManaager;
import com.ljsd.jieling.logic.activity.ActivityLogic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -14,8 +15,15 @@ public class MinuteTask extends Thread {
@Override
public void run() {
ActivityLogic.getInstance().checkActiviyStatus();
ActivityLogic.getInstance().checkSecretBoxSeason();
MapLogic.getInstance().minuteCheckAndRemoveMapRank();
try {
LOGGER.info("MinuteTask start...");
ActivityLogic.getInstance().checkActiviyStatus();
ActivityLogic.getInstance().checkSecretBoxSeason();
MapLogic.getInstance().minuteCheckAndRemoveMapRank();
GlobalDataManaager.getInstance().checkSystemFunctioIsOpen();
LOGGER.info("MinuteTask end...");
} catch (Exception e) {
LOGGER.error("e",e);
}
}
}