试炼排行榜实现
parent
f602185b16
commit
35c69631b2
|
|
@ -1,8 +1,11 @@
|
|||
package com.ljsd.jieling.config.json;
|
||||
|
||||
public class KTSDKConstans {
|
||||
public static String appid = "jl_test";
|
||||
public static String appidTest = "jl_test";
|
||||
public static String appidOnlie = "lj_jl_7qdsc";
|
||||
public static String appid = appidTest;
|
||||
public static String appkey = "c0fb59eb68559b6c9c1463e4d5d0c806";
|
||||
public static String md5Key = "0A008C48E74E8A399F1F80DBED71161C";
|
||||
public static String appsecret = "d53b3e8ef74bf72d8aafce3a1c8671a0";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,6 +106,8 @@ public class RedisKey {
|
|||
|
||||
public static final String USER_LOGIN_URL = "USER_LOGIN_URL:";
|
||||
|
||||
public static final String TOWER_RANK = "TOWER_RANK";
|
||||
|
||||
public static String getKey(String type, String key, boolean withoutServerId) {
|
||||
if (withoutServerId) {
|
||||
return GameApplication.areaId + Delimiter_colon + type + Delimiter_colon + String.valueOf(key);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.ljsd.jieling.handler;
|
||||
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TowerRankHandler extends BaseHandler {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.GET_TOWER_RANK_BY_PAGE_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ISession iSession, PacketNetData netData) throws Exception {
|
||||
byte[] bytes = netData.parseClientProtoNetData();
|
||||
MapInfoProto.TowerRankRequest towerRankRequest = MapInfoProto.TowerRankRequest.parseFrom(bytes);
|
||||
int page = towerRankRequest.getPage();
|
||||
MapLogic.getInstance().getTowerRank(iSession,page,MessageTypeProto.MessageType.GET_TOWER_RANK_BY_PAGE_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ import org.luaj.vm2.LuaValue;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
|
@ -177,7 +178,7 @@ public class MapLogic {
|
|||
MapInfoProto.MapEnterResponse.Builder mapEnterResponse = MapInfoProto.MapEnterResponse.newBuilder();
|
||||
mapEnterResponse.setLeftTime(getLeftTime(user, true));
|
||||
for (Map.Entry<Integer, Integer> buffEntry : mapManager.getFoodBufferMap().entrySet()) {
|
||||
if (buffEntry.getValue()!=-1 && buffEntry.getValue() <= 0) {
|
||||
if (buffEntry.getValue()==0) {
|
||||
continue;
|
||||
}
|
||||
CommonProto.FoodBuffer foodBuffer = CBean2Proto.getFoodBuffer(buffEntry.getKey(), buffEntry.getValue());
|
||||
|
|
@ -814,16 +815,9 @@ public class MapLogic {
|
|||
};
|
||||
LOGGER.info("退出地图");
|
||||
if(challengeConfig.getType()==2){
|
||||
// int time = (int)((System.currentTimeMillis()-mapManager.getStartExporeTime())/1000);
|
||||
// mapManager.setCurrTowerTime(time);
|
||||
// if(mapManager.getEveryTowerTime()!=null&&mapManager.getEveryTowerTime().get(mapManager.getTower())!=null){
|
||||
// mapManager.setTowerTimeByTower(mapManager.getTower(),time);
|
||||
// }
|
||||
if(mapManager.getTower()>=1){
|
||||
mapManager.setMapIntoFlag(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
mapManager.setEssenceValue(0);
|
||||
mapManager.setCurrTowerTime(0);
|
||||
|
|
@ -836,9 +830,6 @@ public class MapLogic {
|
|||
int time = (int)(mapManager.getCurrTowerTime())/1000;
|
||||
builder.setUseTime(time);
|
||||
LOGGER.info("当前层使用时间{}",time);
|
||||
if(mapManager.getTower()>mapManager.getHighestTower()){
|
||||
mapManager.setHighestTower(mapManager.getTower());
|
||||
}
|
||||
MessageUtil.sendMessage(session, 1, messageType.getNumber(), builder.build(), true);
|
||||
return;
|
||||
}
|
||||
|
|
@ -2132,9 +2123,9 @@ public class MapLogic {
|
|||
int[][] bossType = config.getRandomBossType();
|
||||
|
||||
type = MathUtils.randomFromWeight(bossType);
|
||||
// if(mapManager.getTower()%5!=0){
|
||||
// type = 4;
|
||||
// }
|
||||
if(mapManager.getTower()%5!=0){
|
||||
type = 3;
|
||||
}
|
||||
LOGGER.info("trigger!!!!!!!!!!!!!!!!!-------->{},{}",CellUtil.pos2XY(mapManager.getCurXY())[0],CellUtil.pos2XY(mapManager.getCurXY())[1]);
|
||||
int[][][] pointId = config.getRandomMapPointId();
|
||||
int mapId = config.getMapId();
|
||||
|
|
@ -2189,7 +2180,7 @@ public class MapLogic {
|
|||
}
|
||||
|
||||
/**
|
||||
* 使用炸弹
|
||||
* 使用炸弹`
|
||||
*
|
||||
* @param session
|
||||
* @param messageType
|
||||
|
|
@ -2300,7 +2291,7 @@ public class MapLogic {
|
|||
MessageUtil.sendErrorResponse(iSession,0,messageType.getNumber(),"最高层数为0,无需重置。");
|
||||
return;
|
||||
}
|
||||
int afterResetTower = mapManager.getHighestTower()-(mapManager.getHighestTower()%5==0?5:mapManager.getHighestTower()%5);
|
||||
int afterResetTower = mapManager.getHighestTower()-(mapManager.getHighestTower()%5);
|
||||
LOGGER.info("重置当前层,当前层为{},重置为{}",mapManager.getTower(),afterResetTower);
|
||||
if(mapManager.getTower()>5){
|
||||
mapManager.setTower(afterResetTower);
|
||||
|
|
@ -2454,5 +2445,56 @@ public class MapLogic {
|
|||
public void setTower(int uid,int towerNumber) throws Exception {
|
||||
UserManager.getUser(uid).getMapManager().setTower(towerNumber);
|
||||
}
|
||||
public void getTowerRank(ISession session,int page,MessageTypeProto.MessageType messageType) throws Exception {
|
||||
// if(page==0){
|
||||
// MessageUtil.sendErrorResponse(session,0,messageType.getNumber(),"页码不能为0");
|
||||
// return;
|
||||
// }
|
||||
User user = UserManager.getUser(session.getUid());
|
||||
Set<ZSetOperations.TypedTuple<String>> zsetreverseRangeWithScores = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.TOWER_RANK, "", 1, 100);
|
||||
Iterator<ZSetOperations.TypedTuple<String>> iterator = zsetreverseRangeWithScores.iterator();
|
||||
MapInfoProto.TowerRankResponse.Builder response = MapInfoProto.TowerRankResponse.newBuilder();
|
||||
if(!iterator.hasNext()){
|
||||
MessageUtil.sendErrorResponse(session,0,messageType.getNumber(),"暂无排行榜数据!");
|
||||
return;
|
||||
}
|
||||
int rank = 1;
|
||||
while (iterator.hasNext()){
|
||||
ZSetOperations.TypedTuple<String> next = iterator.next();
|
||||
LOGGER.info("用户为:{},分数为{}",next.getValue() , next.getScore());
|
||||
|
||||
int data = next.getScore().intValue();
|
||||
int tower = TowerRankUtil.getTowerAndTime(data)[0];
|
||||
int time = TowerRankUtil.getTowerAndTime(data)[1];
|
||||
User everyUser = UserManager.getUser(Integer.parseInt(next.getValue()));
|
||||
CommonProto.TowerRankInfo everyRankInfo = CommonProto.TowerRankInfo.newBuilder()
|
||||
// RedisUtil.getInstence().getZSetreverseRank(RedisKey.TOWER_RANK,"",Integer.toString(everyUser.getId())).intValue()
|
||||
.setRank(rank)
|
||||
.setHighestTower(tower)
|
||||
.setTime(time)
|
||||
.build();
|
||||
CommonProto.TowerRank everyRank = CommonProto.TowerRank.newBuilder()
|
||||
.setUid(everyUser.getId())
|
||||
.setUserName(everyUser.getPlayerInfoManager().getNickName())
|
||||
.setHead(0)
|
||||
.setLevel(everyUser.getPlayerInfoManager().getLevel())
|
||||
.setTowerRankInfo(everyRankInfo)
|
||||
.build();
|
||||
response.addTowerRanks(everyRank);
|
||||
rank++;
|
||||
}
|
||||
//当前用户信息
|
||||
int myRank= RedisUtil.getInstence().getZSetreverseRank(RedisKey.TOWER_RANK,"",Integer.toString(user.getId())).intValue();
|
||||
int zSetScore = RedisUtil.getInstence().getZSetScore(RedisKey.TOWER_RANK, "", Integer.toString(user.getId())).intValue();
|
||||
int[] towerAndTime = TowerRankUtil.getTowerAndTime(zSetScore);
|
||||
CommonProto.TowerRankInfo towerRankInfo = CommonProto.TowerRankInfo.newBuilder()
|
||||
.setRank(myRank)
|
||||
.setHighestTower(towerAndTime[0])
|
||||
.setTime(towerAndTime[1]).build();
|
||||
response.setUserRank(towerRankInfo);
|
||||
|
||||
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ public class MapManager extends MongoBase {
|
|||
}
|
||||
|
||||
public void setCurXY(int curXY) throws Exception {
|
||||
System.out.println("设置位置"+curXY);
|
||||
updateString("curXY", curXY);
|
||||
this.curXY = curXY;
|
||||
}
|
||||
|
|
@ -188,6 +189,9 @@ public class MapManager extends MongoBase {
|
|||
|
||||
|
||||
public void eatFood(int foodId,int remainStep){
|
||||
if(remainStep == -1 && this.foodBufferMap.containsKey(foodId)){
|
||||
remainStep = this.foodBufferMap.get(foodId) -1 ;
|
||||
}
|
||||
this.foodBufferMap.put(foodId,remainStep);
|
||||
updateString( "foodBufferMap."+foodId, remainStep);
|
||||
}
|
||||
|
|
@ -201,7 +205,7 @@ public class MapManager extends MongoBase {
|
|||
for(Map.Entry<Integer, Integer> item : entries){
|
||||
Integer foodId = item.getKey();
|
||||
Integer remainStep = item.getValue();
|
||||
if( remainStep == -1 ){
|
||||
if( remainStep <= -1 ){
|
||||
continue;
|
||||
}
|
||||
int finalRemainStep = remainStep - step;
|
||||
|
|
@ -570,6 +574,8 @@ public class MapManager extends MongoBase {
|
|||
this.everyTowerTime = everyTowerTime;
|
||||
}
|
||||
public void setTowerTimeByTower(int tower,int time){
|
||||
updateString(getMongoKey()+".everyTowerTime."+tower,time);
|
||||
|
||||
if(everyTowerTime!=null){
|
||||
everyTowerTime.put(tower,time);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,10 @@ import com.ljsd.jieling.config.STrialConfig;
|
|||
import com.ljsd.jieling.handler.map.Cell;
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.handler.map.MapManager;
|
||||
import com.ljsd.jieling.logic.dao.StoreManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.store.StoreLogic;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import com.ljsd.jieling.util.MathUtils;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.ljsd.jieling.handler.map.behavior;
|
|||
|
||||
import com.ljsd.jieling.config.SChallengeConfig;
|
||||
import com.ljsd.jieling.config.STrialConfig;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.handler.map.MapManager;
|
||||
|
|
@ -12,7 +14,8 @@ import com.ljsd.jieling.util.TimeUtils;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FourtyTwoBehavior extends BaseBehavior{
|
||||
public class FourtyTwoBehavior extends BaseBehavior {
|
||||
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.fourtyTwo;
|
||||
|
|
@ -23,25 +26,36 @@ public class FourtyTwoBehavior extends BaseBehavior{
|
|||
MapManager mapManager = user.getMapManager();
|
||||
int maxTower = STrialConfig.getHighestTower();
|
||||
SChallengeConfig challengeConfig = SChallengeConfig.sChallengeConfigs.get(user.getMapManager().getCurMapId());
|
||||
if(challengeConfig.getType()==2&&mapManager.getTower()>=maxTower){
|
||||
mapManager.setTower(mapManager.getTower()+1);
|
||||
LOGGER.info("当前层为{},最大层为{}",mapManager.getTower(),maxTower);
|
||||
if (challengeConfig.getType() == 2 && mapManager.getTower() >= maxTower) {
|
||||
mapManager.setTower(mapManager.getTower() + 1);
|
||||
LOGGER.info("当前层为{},最大层为{}", mapManager.getTower(), maxTower);
|
||||
return false;
|
||||
}
|
||||
LOGGER.info("当前层为{},进入下一层",mapManager.getTower());
|
||||
LOGGER.info("当前层为{},进入下一层", mapManager.getTower());
|
||||
MapLogic.getInstance().clearNormalMonster(user);
|
||||
mapManager.removeBoss();
|
||||
mapManager.setTower(mapManager.getTower()+1);
|
||||
long time = TimeUtils.now() - mapManager.getTowerStartTime();
|
||||
mapManager.setCurrTowerTime(time);
|
||||
LOGGER.info("上层使用时间{}", time);
|
||||
//判断通关最高层是否需要替换
|
||||
if(mapManager.getTower()>mapManager.getHighestTower()){
|
||||
mapManager.setHighestTower(mapManager.getTower());
|
||||
Double zSetScore = RedisUtil.getInstence().getZSetScore(RedisKey.TOWER_RANK, "", String.valueOf(user.getId()));
|
||||
if(mapManager.getTower()*3601+3600-(int)(time/1000)>zSetScore){
|
||||
String key = RedisKey.getKey(RedisKey.TOWER_RANK,"",false);
|
||||
RedisUtil.getInstence().zsetAddOne(key,String.valueOf(user.getId()),mapManager.getTower()*3601+3600-(int)(time/1000));
|
||||
}
|
||||
}
|
||||
user.getUserMissionManager().onGameEvent(user, GameEvent.COPY_TOWER_LEVEL, mapManager.getTower());
|
||||
mapManager.setTower(mapManager.getTower() + 1);
|
||||
// if(mapManager.getTower()==6){
|
||||
// mapManager.setTower(50);
|
||||
// }
|
||||
mapManager.setEssenceValue(0);
|
||||
long time = TimeUtils.now()-mapManager.getTowerStartTime();
|
||||
mapManager.setCurrTowerTime(time);
|
||||
LOGGER.info("上层使用时间{}",time);
|
||||
|
||||
mapManager.setStartExporeTime(0);
|
||||
mapManager.setMapIntoFlag(2);
|
||||
user.getUserMissionManager().onGameEvent(user, GameEvent.COPY_TOWER_LEVEL,mapManager.getTower());
|
||||
|
||||
MapLogic.getInstance().initTrialMap(mapManager, user);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import com.google.protobuf.MessageLite;
|
|||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.jieling.config.SDailyTasksConfig;
|
||||
import com.ljsd.jieling.config.SGlobalSystemConfig;
|
||||
import com.ljsd.jieling.config.json.KTSDKConstans;
|
||||
import com.ljsd.jieling.config.json.ServerProperties;
|
||||
import com.ljsd.jieling.core.FunctionIdEnum;
|
||||
import com.ljsd.jieling.core.GlobalsDef;
|
||||
import com.ljsd.jieling.core.HandlerLogicThread;
|
||||
|
|
@ -183,6 +185,7 @@ public class GlobalDataManaager {
|
|||
}
|
||||
MissionEventDistributor.init();
|
||||
DataManagerDistributor.init();
|
||||
initServerIsLanEnviornment(configurableApplicationContext);
|
||||
new RPCServerTask(configurableApplicationContext).start();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("e",e);
|
||||
|
|
@ -282,5 +285,16 @@ public class GlobalDataManaager {
|
|||
return packetData;
|
||||
}
|
||||
|
||||
private static void initServerIsLanEnviornment(ConfigurableApplicationContext configurableApplicationContext){
|
||||
ServerProperties serverProperties = configurableApplicationContext.getBean(ServerProperties.class);
|
||||
if(serverProperties.getIsLAN()==0){
|
||||
KTSDKConstans.appid= KTSDKConstans.appidTest;
|
||||
}else if(serverProperties.getIsLAN()==1){
|
||||
KTSDKConstans.appid= KTSDKConstans.appidOnlie;
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,8 +75,15 @@ public class CombatLogic {
|
|||
}else{
|
||||
if(sPropertyConfig.getTargetPropertyId()!=0){
|
||||
effectId = sPropertyConfig.getTargetPropertyId();
|
||||
effectValue = value.get(effectId) + effectValue/10000;
|
||||
}else{
|
||||
int baseValue = 0;
|
||||
if(value.containsKey(effectId)){
|
||||
baseValue = value.get(effectId);
|
||||
}
|
||||
effectValue = baseValue + effectValue/10000;
|
||||
}
|
||||
effectValue = value.get(effectId) * effectValue/10000;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +125,7 @@ public class CombatLogic {
|
|||
Map<Integer, Integer> foodBufferMap = mapManager.getFoodBufferMap();
|
||||
for(Map.Entry<Integer,Integer> foodBuffer : foodBufferMap.entrySet()){
|
||||
Integer remainStep = foodBuffer.getValue();
|
||||
if(remainStep == -1){
|
||||
if(remainStep <= -1){
|
||||
continue;
|
||||
}
|
||||
int foodId = foodBuffer.getKey();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package com.ljsd.jieling.util;
|
||||
|
||||
public class TowerRankUtil {
|
||||
|
||||
public static int[] getTowerAndTime(int data){
|
||||
int[] array = new int [2];
|
||||
array[0] = data/3601;
|
||||
array[1] =3600-data%3601;
|
||||
return array;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue