back_recharge
lvxinran 2019-12-13 13:44:15 +08:00
commit 462a035592
19 changed files with 4410 additions and 784 deletions

View File

@ -106,10 +106,10 @@ public class CheckFight {
int[] resultCache = new int[7];
resultCache[0]=status;
resultCache[1]=duration;
// LOGGER.info(" lua check test fight result : "+ status);
LOGGER.info(" lua check test fight result : "+ status);
for (int i = 1; i <= result.length(); i++) {
resultCache[i+1] = result.rawget(i).toint();
// LOGGER.info(i+" --> 单位剩余血量 : "+ resultCache[i+1]);
LOGGER.info(i+" --> 单位剩余血量 : "+ resultCache[i+1]);
}
return resultCache;

View File

@ -1,6 +1,7 @@
package com.ljsd.jieling.core;
import com.ljsd.jieling.core.function.ArenaFunction;
import com.ljsd.jieling.core.function.ChampionFunction;
import com.ljsd.jieling.core.function.EndlessFunction;
import com.ljsd.jieling.protocols.MessageTypeProto;
@ -52,7 +53,7 @@ public enum FunctionIdEnum {
SoulEquip(52,null,
MessageTypeProto.MessageType.SOUL_RAND_EQUIP_REQUEST_VALUE,
MessageTypeProto.MessageType.SOUL_FORCE_RAND_EQUIP_REQUEST_VALUE),
TopBattle(57,null),
TopBattle(57,new ChampionFunction()),
WorkShopTech(101,null,MessageTypeProto.MessageType.WORKSHOP_TECHNOLOGY_LEVEL_REQUEST_VALUE),
WorkShopCreateEquip(102,null),
WorkShopCreateProtectEquip(103,null),

View File

@ -206,7 +206,7 @@ public class RedisKey {
public final static String CHAMPION_CHOSE_TEAM_INFO = "CHAMPION_CHOSE_TEAM_INFO";
public final static String CHAMPION_FINAL_TEAM_INFO = "CHAMPION_CHOSE_TEAM_INFO";
public final static String CHAMPION_FINAL_TEAM_INFO = "CHAMPION_FINAL_TEAM_INFO";
public final static String CHAMPION_PROGRESS = "CHAMPION_PROGRESS"; //
public final static String CHAMPION_BET_MINE = "CHAMPION_BET_MINE"; // 我的竞猜

View File

@ -1,6 +1,7 @@
package com.ljsd.jieling.db.redis;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ljsd.GameApplication;
import com.ljsd.common.mogodb.util.GlobalData;
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
@ -15,6 +16,7 @@ import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.util.CollectionUtils;
import redis.clients.jedis.Protocol;
import java.lang.reflect.Type;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ -1012,6 +1014,21 @@ public class RedisUtil {
return null;
}
public <T> T getMapEntry(String type,String key,String mapKey,Type parmsType){
String rkey = getKey(type, key);
for (int i = 0; i < MAX_TRY_TIMES; i++) {
try {
Object o = redisTemplate.opsForHash().get(rkey, mapKey);
if(o!=null){
return gson.fromJson(o.toString(),parmsType);
}
} catch (Exception e) {
TimeUtils.sleep(FAILED_SLEEP);
}
}
return null;
}
public <T> T getMapValue(String type, String key, String mapKey, Class<T> clazz) {
String rkey = getKey(type, key);
@ -1060,6 +1077,18 @@ public class RedisUtil {
return result;
}
public <K,T> Map<K,T> getMapValues(String type,String key,Class<K> keyClazz,Type valueType){
Map<K,T> result = new HashMap<>();
String rkey = getKey(type, key);
Map<Object, Object> entries = redisTemplate.opsForHash().entries(rkey);
for(Map.Entry<Object,Object> item : entries.entrySet()){
Object key1 = item.getKey();
Object value = item.getValue();
result.put(gson.fromJson(gson.toJson(key1),keyClazz),gson.fromJson(value.toString(),valueType));
}
return result;
}
public void removeMapEntrys(String type, String key, Object... mapKeys){
String rkey = getKey(type, key);
for (int i = 0; i < MAX_TRY_TIMES; i++) {

View File

@ -0,0 +1,19 @@
package com.ljsd.jieling.handler.champion;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.championship.ChampionshipLogic;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.ArenaInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
public class ChampionBetInfoHandler extends BaseHandler<ArenaInfoProto.ChampionGetBetRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.CHAMPION_BET_INFO_REQUEST;
}
@Override
public void processWithProto(ISession iSession, ArenaInfoProto.ChampionGetBetRequest proto) throws Exception {
ChampionshipLogic.getChampionBetInfo(iSession,proto.getType());
}
}

View File

@ -0,0 +1,19 @@
package com.ljsd.jieling.handler.champion;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.championship.ChampionshipLogic;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
public class ChampionGetMyAllBetHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.CHAMPION_GET_MYALL_BET_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
ChampionshipLogic.viewMGuessHistory(iSession);
}
}

View File

@ -0,0 +1,19 @@
package com.ljsd.jieling.handler.champion;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.championship.ChampionshipLogic;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
public class ChampionGetMyHistoryHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.CHAMPION_GET_MYHISTORY_REQEUST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
ChampionshipLogic.viewAllMyBattleInfo(iSession);
}
}

View File

@ -0,0 +1,19 @@
package com.ljsd.jieling.handler.champion;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.championship.ChampionshipLogic;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.ArenaInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
public class ChampionGetWorldRankHandler extends BaseHandler<ArenaInfoProto.ChampionGetWorldRankRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.CHAMPION_GET_RANK_REQUEST;
}
@Override
public void processWithProto(ISession iSession, ArenaInfoProto.ChampionGetWorldRankRequest proto) throws Exception {
ChampionshipLogic.getWorldRankByPage(iSession,proto.getPage());
}
}

View File

@ -6,7 +6,7 @@ import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.ArenaInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
public class ChampionBetHandler extends BaseHandler<ArenaInfoProto.ChampionBetReqeust> {
public class ChampionGuessHandler extends BaseHandler<ArenaInfoProto.ChampionBetReqeust> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.CHAMPION_BET_GUESS_REQUEST;

View File

@ -64,15 +64,26 @@ class ExpectRankActivity extends AbstractActivity {
if(null==sActivityRankingReward)
return;
int maxRank = 0;
int maxRewardId = 0;
Map<Integer, Integer> rank2miss = new HashMap<>();
for (SActivityRankingReward sActivityRankingReward1 : sActivityRankingReward) {
maxRank = Math.max(maxRank, sActivityRankingReward1.getMaxRank());
if(sActivityRankingReward1.getMaxRank()==-1){
maxRank =-1;
maxRewardId = sActivityRankingReward1.getId();
continue;
}
if(maxRank!=-1)
{
maxRank = Math.max(maxRank, sActivityRankingReward1.getMaxRank());
}
for (Integer rank : getRankSet(sActivityRankingReward1.getMinRank(), sActivityRankingReward1.getMaxRank())) {
rank2miss.put(rank, sActivityRankingReward1.getId());
}
}
Set<ZSetOperations.TypedTuple<String>> rankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.EXPERT_RANK, Integer.toString(id), 0, maxRank - 1);
Set<ZSetOperations.TypedTuple<String>> rankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.EXPERT_RANK, Integer.toString(id), 0, (maxRank==-1?0:maxRank) - 1);
int rank = 1;
int nowTime = (int) (TimeUtils.now() / 1000);
for (ZSetOperations.TypedTuple<String> item : rankInfo) {
@ -86,7 +97,17 @@ class ExpectRankActivity extends AbstractActivity {
if (activityMission == null || activityMission.getOpenType() == 0) {
continue;
}
int missionId = rank2miss.get(rank);
int missionId ;
if(rank2miss.containsKey(rank)) {
missionId = rank2miss.get(rank);
}else {
if(maxRank==-1){
missionId = maxRewardId;
}else {
continue;
}
}
//check value
SActivityRankingReward sActivityRankingReward1 = SActivityRankingReward.getsActivityRankingRewardMap().get(missionId);
//sendmail

View File

@ -11,6 +11,7 @@ import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.globals.Global;
import com.ljsd.jieling.logic.GlobalDataManaager;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.arena.ArenaLogic;
@ -19,6 +20,7 @@ import com.ljsd.jieling.logic.dao.*;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.fight.*;
import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.logic.mail.MailLogic;
import com.ljsd.jieling.logic.mission.event.MissionEventDistributor;
import com.ljsd.jieling.logic.player.PlayerLogic;
import com.ljsd.jieling.network.server.ProtocolsManager;
@ -59,7 +61,7 @@ public class ChampionshipLogic {
}
static class MemberInfo{
public static class MemberInfo{
private int uid;
private int type;
private int score; // 选拔积分
@ -114,16 +116,6 @@ public class ChampionshipLogic {
}
}
// private static Map<String,ArenaRecord> arenaRecordMap = new HashMap<>();//历史对战队伍信息
// private static Map<String,ArenaRecord> curArenaRecordMap = new HashMap<>();//当前进行对战队伍信息
// private static List<String> finalRecodedIds = new ArrayList<>();
// private static List<List<Integer>> finalmemberOfTeam; // 决赛队伍信息
// private static String selectUid = "";
private static int schedule=1;
//提前把分数缓存进来
@ -198,6 +190,7 @@ public class ChampionshipLogic {
*
*/
public static void start() {
LOGGER.info("the champion start...");
SChampionshipSetting sChampionshipSetting = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting();
int championshipPlayer = sChampionshipSetting.getChampionshipPlayer();
int curSeason = ArenaLogic.getInstance().getCurSeason();
@ -251,6 +244,11 @@ public class ChampionshipLogic {
String key = RedisUtil.getInstence().getKey(RedisKey.CHAMPION_JOIN, "");
RedisUtil.getInstence().del(key, RedisUtil.getInstence().getKey(RedisKey.CHAMPION_RANK, ""));
RedisUtil.getInstence().updateZsetScores(RedisKey.CHAMPION_RANK,"",arenaRankInfoForChampion);
Map<String,MemberInfo> memberInfoMap = new HashMap<>();
memberInfos.forEach(memberInfo -> {
memberInfoMap.put(Integer.toString(memberInfo.getUid()),memberInfo);
});
RedisUtil.getInstence().putMapEntrys(RedisKey.CHAMPION_JOIN,"",memberInfoMap);
for(int i=0;i<memberOfTeamOfGroup.size();i++){
RedisUtil.getInstence().putMapEntry(RedisKey.CHAMPION_CHOSE_TEAM_INFO, "",Integer.toString(i),memberOfTeamOfGroup.get(i));
@ -258,7 +256,35 @@ public class ChampionshipLogic {
}
public static void close() {
public static void close() throws Exception {
Map<Integer, SChampionshipReward> config = STableManager.getConfig(SChampionshipReward.class);
Map<Integer,SChampionshipReward> rewardsMap = new HashMap<>();
config.forEach((k,v)->{
int minRank = v.getMinRank();
int maxRank = v.getMaxRank();
while (minRank<=maxRank){
rewardsMap.put(minRank++,v);
}
});
int rank=1;
Set<ZSetOperations.TypedTuple<String>> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.CHAMPION_BET_RANK, Integer.toString(1), 0, -1);
Map<Integer, SArenaRobotConfig> robotConfigMap = STableManager.getConfig(SArenaRobotConfig.class);
int nowTime = (int)(TimeUtils.now()/1000);
for(ZSetOperations.TypedTuple<String> item : arenaRankInfo){
String uidStr = item.getValue();
int uid = Integer.parseInt(uidStr);
if(robotConfigMap.containsKey(uid)){
rank++;
continue;
}
User user = UserManager.getUser(uid);
SChampionshipReward sChampionshipReward = rewardsMap.get(rank);
String title = SErrorCodeEerverConfig.getI18NMessage("champion_reward_title");
String content = SErrorCodeEerverConfig.getI18NMessage("champion_reward_txt",new Object[]{rank++});
MailLogic.getInstance().sendMail(user.getId(),title,content,ItemUtil.getMailReward(sChampionshipReward.getSeasonReward()),nowTime, Global.MAIL_EFFECTIVE_TIME);
}
}
@ -279,11 +305,26 @@ public class ChampionshipLogic {
}.getType();
Object championJoins = RedisUtil.getInstence().get(key);*/
/* start();
List<Integer> memberIds = RedisUtil.getInstence().getMapValue(RedisKey.CHAMPION_CHOSE_TEAM_INFO, "", Integer.toString(1), List.class);
System.out.println();*/
// start();
/* for(int i=1;i<8;i++){
roundTimes=i;
selectToBattle();
switchBet();
scoreToRedis();
}
selectToJoinFinal();
schedule=2;
for(int i=8;i<13;i++){
roundTimes=i;
selectToBattle();
switchBet();
scoreToRedis();
}
*/
}
@ -336,7 +377,7 @@ public class ChampionshipLogic {
enemyId = arenaRecord.getAttackId();
fightResult=1^fightResult;
}
if(progress%3 != 0){
if(progress%10%4 != 0){
fightResult =-1;
}
builder.setChampionBattleInfo(CommonProto.ChampionBattleInfo.newBuilder()
@ -349,6 +390,38 @@ public class ChampionshipLogic {
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.CHAMPION_GET_RESPONSE_VALUE,builder.build(),true);
}
public static void getChampionBetInfo(ISession session,int type) throws Exception {
int uid = session.getUid();
String selectIdForRedis = getSelectIdForRedis();
ArenaInfoProto.ChampionGetBetResponse.Builder builder = ArenaInfoProto.ChampionGetBetResponse.newBuilder();
if(!StringUtil.isEmpty(selectIdForRedis)){
builder.setChampionBetInfo(getBetOdds());
ArenaRecord arenaRecord = RedisUtil.getInstence().getMapValue(RedisKey.CHAMPION_JOIN, "", selectIdForRedis, ArenaRecord.class);
if(type == 0){
int fightResult=arenaRecord.getFightResult();
if(progress%10%4 != 0){
fightResult =-1;
}
int myGuessID = arenaRecord.getAttackId();
Integer coins = RedisUtil.getInstence().getMapEntry(RedisKey.CHAMPION_BET_MINE, Integer.toString(uid), selectIdForRedis + ":" +myGuessID, Integer.class);
if(coins == null) {
myGuessID = arenaRecord.getDefUid();
coins = RedisUtil.getInstence().getMapEntry(RedisKey.CHAMPION_BET_MINE, Integer.toString(uid), selectIdForRedis + ":" +myGuessID, Integer.class);
}
if(coins == null){
myGuessID = 0;
}
builder.setChampionBattleInfo(CommonProto.ChampionBattleInfo.newBuilder()
.setMyInfo(getChampionBattleInfo(arenaRecord.getAttackId()))
.setEnemyInfo(getChampionBattleInfo(arenaRecord.getDefUid()))
.setResult(fightResult)
.build());
builder.setWinUid(myGuessID);
}
}
}
private static CommonProto.TeamOneInfo.Builder getChampionBattleInfo(int uid) throws Exception {
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(uid);
if(sArenaRobotConfig!=null){
@ -356,6 +429,9 @@ public class ChampionshipLogic {
}
MemberInfo memberInfo = RedisUtil.getInstence().getMapEntry(RedisKey.CHAMPION_JOIN, "", Integer.toString(uid), MemberInfo.class);
FamilyFightInfo fightInfo = memberInfo.getFightInfo();
if(fightInfo == null){
return PlayerLogic.getInstance().getUserTeamOneInfo(uid,201);
}
User user = UserManager.getUser(uid);
PlayerManager playerManager = user.getPlayerInfoManager();
@ -441,6 +517,7 @@ public class ChampionshipLogic {
}
});
ArenaInfoProto.ChampionGetMyTeamInfoResponse build = ArenaInfoProto.ChampionGetMyTeamInfoResponse.newBuilder().addAllChampionTeamPersonInfo(championTeamPersonInfoList).build();
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.CHAMPION_GET_MYTEAM_RESPONSE_VALUE,build,true);
@ -449,16 +526,33 @@ public class ChampionshipLogic {
//查看我的战斗记录
public static void viewAllMyBattleInfo(ISession session) throws Exception {
int uid = session.getUid();
List<String> championshipIds = RedisUtil.getInstence().getMapEntry(RedisKey.CHAMPION_MY_BATTLLE_IDS,"",Integer.toString(uid),List.class);
List<Object> ids = new ArrayList<>(championshipIds);
Map<String, Integer> mapValues = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_MY_BATTLLE_IDS, Integer.toString(uid), String.class, Integer.class);
List<Object> ids = new ArrayList<>(mapValues.keySet());
List<ArenaRecord> myArenaRecordInfos = RedisUtil.getInstence().getMapEntrys(RedisKey.CHAMPION_ARENA_RECORD, "", ids, ArenaRecord.class);
ArenaInfoProto.ChanpionGetAllMyBattleHistoryResponse.Builder builder = ArenaInfoProto.ChanpionGetAllMyBattleHistoryResponse.newBuilder();
for(ArenaRecord arenaRecord : myArenaRecordInfos){
ArenaLogic.getInstance().getArenaEnemy(arenaRecord.getAttackId(),arenaRecord.getType());
int fightResult = arenaRecord.getFightResult();
if(fightResult == -1){
continue;
int enemyId = arenaRecord.getDefUid();
if(arenaRecord.getDefUid() == uid){
enemyId = arenaRecord.getAttackId();
}
int fightResult = arenaRecord.getFightResult();
if(roundTimes == arenaRecord.getRoundTims()){
if(progress%10%4 != 0){
fightResult =-1;
}
}
if(fightResult == -2){
fightResult =-1;
}
if(fightResult!=-1 && enemyId!=arenaRecord.getDefUid()){
fightResult = 1^0;
}
CommonProto.ArenaEnemy arenaEnemy = ArenaLogic.getInstance().getArenaEnemy(enemyId, arenaRecord.getType());
ArenaInfoProto.ChampionTwoEnemInfo build = ArenaInfoProto.ChampionTwoEnemInfo.newBuilder().setBlueEnemy(arenaEnemy).setRoundTimes(arenaRecord.getRoundTims()).setFightResult(fightResult).build();
builder.addEnemyPairInfo(build);
}
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.CHAMPION_GET_MYHISTORY_RESPONSE_VALUE,builder.build(),true);
}
public static void snapPlayFightInfo() throws Exception {
@ -480,9 +574,7 @@ public class ChampionshipLogic {
PVPFightEvent pvpFightEvent = new PVPFightEvent(attackId,snapTeamId,warTime,"",gameFightTypeMap.get(arenaRecord.getType()),defUid,snapTeamId);
FightDispatcher.dispatcherAsync(pvpFightEvent,id);
}
}
@ -550,7 +642,8 @@ public class ChampionshipLogic {
int defUid = arenaRecord.getDefUid();
RedisUtil.getInstence().incrementZsetScore(RedisKey.CHAMPION_BET_ALL,"",selectBetId +":" + attackId,guessNum);
RedisUtil.getInstence().incrementZsetScore(RedisKey.CHAMPION_BET_ALL,"",selectBetId +":" + defUid,guessNum);
String key = RedisUtil.getInstence().getKey(RedisKey.CHAMPION_CUR_BETID, "");
RedisUtil.getInstence().set(key,selectBetId);
}
public static int getForce( MemberInfo memberInfo, Map<Integer, SArenaRobotConfig> config){
@ -578,7 +671,7 @@ public class ChampionshipLogic {
public static void guess(ISession session, int winUid,int chip) throws Exception {
int uid = session.getUid();
String selectUid = getSelectIdForRedis();
if(progress%3!=2 || StringUtil.isEmpty(selectUid)){
if(progress%10%4!=2 || StringUtil.isEmpty(selectUid)){
LOGGER.error("the uid={} not in time",uid);
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
}
@ -669,43 +762,75 @@ public class ChampionshipLogic {
*
* @param session
*/
public static void viewMGuessHistory(ISession session){
public static void viewMGuessHistory(ISession session) throws Exception {
int uid = session.getUid();
Map<String, Integer> betHistorys = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_BET_MINE, Integer.toString(uid), String.class, Integer.class);
ArenaInfoProto.ChampionGetAllMyBetInfoResponse.Builder builder = ArenaInfoProto.ChampionGetAllMyBetInfoResponse.newBuilder();
if(!betHistorys.isEmpty()){
List<String> guessIds = new ArrayList<>(betHistorys.size());
betHistorys.forEach((idAndBet,coins)->{
String[] idAndBetSplit = idAndBet.split(":");
String id = idAndBetSplit[0];
Integer betUid = Integer.parseInt(idAndBetSplit[1]);
guessIds.add(id);
});
List<Object> ids = new ArrayList<>(guessIds);
List<ArenaRecord> arenaRecords = RedisUtil.getInstence().getMapEntrys(RedisKey.CHAMPION_ARENA_RECORD, "", ids, ArenaRecord.class);
String selectIdForRedis = getSelectIdForRedis();
for(ArenaRecord arenaRecord: arenaRecords){
CommonProto.ArenaEnemy attackEnemy = ArenaLogic.getInstance().getArenaEnemy(arenaRecord.getAttackId(), arenaRecord.getType());
CommonProto.ArenaEnemy defEnemy = ArenaLogic.getInstance().getArenaEnemy(arenaRecord.getDefUid(), arenaRecord.getType());
int fightResult = arenaRecord.getFightResult();
int guessState = 3;
if(arenaRecord.getId().equals(selectIdForRedis)){
if(progress%10%4!=0){
fightResult=-1;
}
if(progress%10%4 == 4){
guessState=0;
}
if(progress%10%4 == 3){
guessState=1;
}
}
if(fightResult == -2){
fightResult =-1;
}
if(fightResult>=0){
int winner = arenaRecord.getAttackId();
if(fightResult == 0){
winner = arenaRecord.getDefUid();
}
Integer coins = betHistorys.get(arenaRecord.getId()+ ":" + winner);
if(coins!=null){
guessState = 2;
}
}
builder.addChampionMyBetDetails(ArenaInfoProto.ChampionMyBetDetail.newBuilder().setBetResult(guessState).setEnemyPairInfo(
ArenaInfoProto.ChampionTwoEnemInfo.newBuilder().setRedEnemy(attackEnemy).setBlueEnemy(defEnemy).setFightResult(fightResult)
));
}
}
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.CHAMPION_GET_MYALL_BET_RESPONSE_VALUE,builder.build(),true);
}
/**
* 广
*/
public static CommonProto.ChampionBetInfo getBetOdds(){
String selectUid = getSelectIdForRedis();
ArenaRecord arenaRecord = RedisUtil.getInstence().getMapValue(RedisKey.CHAMPION_ARENA_RECORD,"",selectUid,ArenaRecord.class);
Double attackCoins = RedisUtil.getInstence().getZSetScore(RedisKey.CHAMPION_BET_ALL, "", selectUid + ":" + arenaRecord.getAttackId());
Double defCoins = RedisUtil.getInstence().getZSetScore(RedisKey.CHAMPION_BET_ALL, "", selectUid + ":" + arenaRecord.getDefUid());
/* double totalCoins = attackCoins + defCoins;
double attackRate = totalCoins/attackCoins;
double defRate = totalCoins/defCoins;
DecimalFormat df = new DecimalFormat("0.00");
String attackRateStr = df.format(attackRate);
String defRateStr = df.format(defRate);*/
return CommonProto.ChampionBetInfo.newBuilder().setBlueCoins(defCoins.intValue()).setRedCoins(attackCoins.intValue()).setId(selectUid).build();
}
//todo
public static Map<Integer, List<Integer>> getMermberTeam(){
return new HashMap<>();
Type type = new TypeToken<List<Integer>>() {
}.getType();
return RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_CHOSE_TEAM_INFO,"",Integer.class,type);
}
@ -741,15 +866,20 @@ public class ChampionshipLogic {
arenaRecord.setAttackId(attackUid);
arenaRecord.setDefUid(defUid);
arenaRecord.setType(type);
arenaRecord.setRoundTims(roundTimes);
arenaRecordMap.put(arenaRecord.getId(),arenaRecord);
}
}
}
}else{ //决赛
Map<Integer, List> finalmemberOfTeam = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_FINAL_TEAM_INFO, "", Integer.class, List.class);
Type valueType = new TypeToken<List<Integer>>() {
}.getType();
Map<Integer, List<Integer>> finalmemberOfTeam = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_FINAL_TEAM_INFO, "", Integer.class, valueType);
Map<Integer, MemberInfo> allJoinMembers = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_JOIN, "", Integer.class, MemberInfo.class);
List<MemberInfo> possibleJoin = new ArrayList<>();
for(List<MemberInfo> memberOfOneTeam : finalmemberOfTeam.values()){
memberOfOneTeam.forEach(memberInfo -> {
for(List<Integer> memberOfOneTeam : finalmemberOfTeam.values()){
memberOfOneTeam.forEach(id -> {
MemberInfo memberInfo = allJoinMembers.get(id);
if(memberInfo.getFinalScore()>0){
possibleJoin.add(memberInfo);
}
@ -770,12 +900,24 @@ public class ChampionshipLogic {
arenaRecord.setAttackId(attackUid);
arenaRecord.setDefUid(defUid);
arenaRecord.setType(type);
arenaRecord.setRoundTims(roundTimes);
arenaRecordMap.put(arenaRecord.getId(),arenaRecord);
}
}
RedisUtil.getInstence().putMapEntrys(RedisKey.CHAMPION_ARENA_RECORD,"",arenaRecordMap);
arenaRecordIds.addAll(arenaRecordMap.keySet());
RedisUtil.getInstence().lSet(RedisKey.CHAMPION_CUR_JOIN_IDS,"",arenaRecordIds);
Map<Integer, SArenaRobotConfig> robotConfigMap = STableManager.getConfig(SArenaRobotConfig.class);
arenaRecordMap.forEach((id,arenaRecord)->{
int defUid = arenaRecord.getDefUid();
int attackId = arenaRecord.getAttackId();
if(!robotConfigMap.containsKey(defUid)){
RedisUtil.getInstence().putMapEntry(RedisKey.CHAMPION_MY_BATTLLE_IDS, Integer.toString(defUid),id, 0);
}
if(!robotConfigMap.containsKey(attackId)){
RedisUtil.getInstence().putMapEntry(RedisKey.CHAMPION_MY_BATTLLE_IDS, Integer.toString(attackId),id, 0);
}
});
}
@ -820,6 +962,12 @@ public class ChampionshipLogic {
for(int i=0;i<finalmemberOfTeam.size();i++){
RedisUtil.getInstence().putMapEntry(RedisKey.CHAMPION_FINAL_TEAM_INFO, "",Integer.toString(i),finalmemberOfTeam.get(i));
}
Map<String,MemberInfo> finalMemberInfoMap = new HashMap<>();
canJoinFinal.forEach(memberInfo -> {
finalMemberInfoMap.put(Integer.toString(memberInfo.getUid()),memberInfo);
});
RedisUtil.getInstence().putMapEntrys(RedisKey.CHAMPION_JOIN, "",finalMemberInfoMap);
}
@ -855,7 +1003,7 @@ public class ChampionshipLogic {
//获取排行榜信息
public void getWorldRankByPage(ISession session,int page) throws Exception {
public static void getWorldRankByPage(ISession session,int page) throws Exception {
if (page == 0) {
page = 1;
}
@ -953,7 +1101,7 @@ public class ChampionshipLogic {
long now = TimeUtils.now();
long startTime = timeControllerOfFunction.getStartTime();
SChampionshipSetting sChampionshipSetting = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting();
int duration = sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime() + sChampionshipSetting.getBattleTime();
int duration = sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime() + sChampionshipSetting.getBattleTime() + sChampionshipSetting.getSettleTime();
int progressState=getProgress((int)((now - startTime)/1000%duration +1));
long round = (now - startTime) /1000/ duration + 1;
roundTimes = (int) round;
@ -961,7 +1109,7 @@ public class ChampionshipLogic {
int progressTmp;
if(diff<0){ //选拔赛
progressTmp =9 + progressState;
progressTmp =100 + roundTimes*10 + progressState;
schedule=1;
}else {//决赛
int totalWiner =sChampionshipSetting.getChampionshipPlayer()/ sChampionshipSetting.getTrialsGroup() * sChampionshipSetting.getTrialsGroupWinner();
@ -969,7 +1117,7 @@ public class ChampionshipLogic {
if(roundTimes<2){
return;
}
progressTmp =roundTimes*100 + progressState;
progressTmp = 200 + (int)diff*10 + progressState;
if(schedule==1){ // 刚开始进入决赛,选拔出选手
selectToJoinFinal();
}
@ -983,14 +1131,20 @@ public class ChampionshipLogic {
progress = progressTmp;
RedisUtil.getInstence().set(RedisUtil.getInstence().getKey(RedisKey.CHAMPION_PROGRESS,""),Integer.toString(progress));
if(progress%3==0){
if(progress%10%4==0){
selectToBattle();
}
if(progress%3==1){ //竞猜阶段 后台自动运行战斗
if(progress%10%4==1){ //竞猜阶段 后台自动运行战斗
switchBet();
}else if(progress%3==2){ //比赛阶段
}else if(progress%10%4==3){ //结算阶段
//等待玩家数据分数入redis
scoreToRedis();
sendBetReward();
}
ArenaInfoProto.ChampionProgressUpdateIndication build = ArenaInfoProto.ChampionProgressUpdateIndication.newBuilder().setEndTime(endTime).setProgress(progress).build();
//向全服玩家广播进度变更信息
for(ISession session : OnlineUserManager.sessionMap.values()){
MessageUtil.sendIndicationMessage(session,1, MessageTypeProto.MessageType.CHAMPION_PROGRESS_UPDATE_INDICATION_VALUE,build,true);
}
}
@ -1002,7 +1156,10 @@ public class ChampionshipLogic {
if(progressState == 1){
return sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime();
}
return sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime() + sChampionshipSetting.getBattleTime();
if(progressState == 2){
return sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime() + sChampionshipSetting.getBattleTime();
}
return sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime() + sChampionshipSetting.getBattleTime() + sChampionshipSetting.getSettleTime();
}
@ -1012,10 +1169,13 @@ public class ChampionshipLogic {
if(progressTmp<sChampionshipSetting.getPrepareTime()){
return 0;// 准备
}
if(progressTmp>=sChampionshipSetting.getPrepareTime() && progressTmp<sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime()){
if(progressTmp<sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime()){
return 1;//竞猜
}
return 2;//比赛
if(progressTmp<sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime()+sChampionshipSetting.getBattleTime()){
return 2;//比赛
}
return 3; //战斗结算
}
}

View File

@ -97,4 +97,12 @@ public class ArenaRecord {
public void setType(int type) {
this.type = type;
}
public int getRoundTims() {
return roundTims;
}
public void setRoundTims(int roundTims) {
this.roundTims = roundTims;
}
}

View File

@ -1,5 +1,7 @@
package com.ljsd.jieling.logic.fight;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.logic.championship.ChampionshipLogic;
import com.ljsd.jieling.logic.dao.ArenaRecord;
import com.ljsd.jieling.logic.fight.result.FightResult;
@ -17,6 +19,7 @@ public class AreFightPro implements EndFightProcessor {
failerUid = arenaRecord.getAttackId();
}
ChampionshipLogic.setScoreForSuccess(winnerUid,failerUid);
RedisUtil.getInstence().putMapEntry(RedisKey.CHAMPION_ARENA_RECORD,"",arenaRecord.getId(),arenaRecord);
}
public ArenaRecord getArenaRecord() {

View File

@ -444,6 +444,40 @@ public class PlayerLogic {
}
public CommonProto.TeamOneInfo.Builder getUserTeamOneInfo(int uid,int teamId) throws Exception {
User user = UserManager.getUser(uid);
PlayerManager playerManager = user.getPlayerInfoManager();
CommonProto.TeamOneInfo.Builder oneInfo = CommonProto.TeamOneInfo.newBuilder()
.setHead(playerManager.getHead())
.setHeadFrame(playerManager.getHeadFrame())
.setLevel(playerManager.getLevel())
.setName(playerManager.getNickName()).setUid(uid);
TeamPosManager teamPosManager = user.getTeamPosManager();
CommonProto.TeamOneTeamInfo.Builder teamInfo = CommonProto.TeamOneTeamInfo.newBuilder();
teamInfo.setTotalForce(HeroLogic.getInstance().calTeamTotalForce(user,teamId,false));
if(teamPosManager.getTeamPosForPoken().get(teamId)!=null&&teamPosManager.getTeamPosForPoken().get(teamId).size()>0){
for(TeamPosForPokenInfo posForPokenInfo:teamPosManager.getTeamPosForPoken().get(teamId)){
teamInfo.addPokemonInfos(posForPokenInfo.getPokenId());
}
}
if(teamPosManager.getTeamPosForHero().containsKey(teamId)){
for (TeamPosHeroInfo heroInfo:teamPosManager.getTeamPosForHero().get(teamId)) {
Hero hero = user.getHeroManager().getHero(heroInfo.getHeroId());
teamInfo.addTeam(CBean2Proto.getSimpleTeamInfoByHero(hero));
}
}
int guildId = user.getPlayerInfoManager().getGuildId();
if(guildId!=0){
if(GuilidManager.guildInfoMap.containsKey(guildId)){
String name = GuilidManager.guildInfoMap.get(guildId).getName();
oneInfo.setGuildName(name);
}
}
oneInfo.setTeam(teamInfo);
return oneInfo;
}
public CommonProto.TeamOneInfo.Builder getRobotTeamInfo(SArenaRobotConfig sArenaRobotConfig){
CommonProto.TeamOneInfo.Builder oneInfo = CommonProto.TeamOneInfo.newBuilder()
.setLevel(sArenaRobotConfig.getRobotLevel())
@ -476,36 +510,7 @@ public class PlayerLogic {
if(sArenaRobotConfig!=null){
oneInfo=getRobotTeamInfo(sArenaRobotConfig);
}else{
User user = UserManager.getUser(id);
PlayerManager playerManager = user.getPlayerInfoManager();
oneInfo = CommonProto.TeamOneInfo.newBuilder()
.setHead(playerManager.getHead())
.setHeadFrame(playerManager.getHeadFrame())
.setLevel(playerManager.getLevel())
.setName(playerManager.getNickName()).setUid(id);
TeamPosManager teamPosManager = user.getTeamPosManager();
CommonProto.TeamOneTeamInfo.Builder teamInfo = CommonProto.TeamOneTeamInfo.newBuilder();
teamInfo.setTotalForce(HeroLogic.getInstance().calTeamTotalForce(user,teamId,false));
if(teamPosManager.getTeamPosForPoken().get(teamId)!=null&&teamPosManager.getTeamPosForPoken().get(teamId).size()>0){
for(TeamPosForPokenInfo posForPokenInfo:teamPosManager.getTeamPosForPoken().get(teamId)){
teamInfo.addPokemonInfos(posForPokenInfo.getPokenId());
}
}
if(teamPosManager.getTeamPosForHero().containsKey(teamId)){
for (TeamPosHeroInfo heroInfo:teamPosManager.getTeamPosForHero().get(teamId)) {
Hero hero = user.getHeroManager().getHero(heroInfo.getHeroId());
teamInfo.addTeam(CBean2Proto.getSimpleTeamInfoByHero(hero));
}
}
int guildId = user.getPlayerInfoManager().getGuildId();
if(guildId!=0){
if(GuilidManager.guildInfoMap.containsKey(guildId)){
String name = GuilidManager.guildInfoMap.get(guildId).getName();
oneInfo.setGuildName(name);
}
}
oneInfo.setTeam(teamInfo);
oneInfo = getUserTeamOneInfo(id, teamId);
if(UserManager.getUser(session.getUid()).getFriendManager().getMyApplyFriends().contains(id)){
oneInfo.setIsApplyed(1);
}

View File

@ -2,6 +2,7 @@ package com.ljsd.jieling.util;
import com.google.gson.Gson;
import com.google.protobuf.GeneratedMessage;
import com.googlecode.protobuf.format.JsonFormat;
import com.ljsd.GameApplication;
import com.ljsd.jieling.chat.messge.MessageCache;
import com.ljsd.jieling.core.GlobalsDef;
@ -39,7 +40,7 @@ public class MessageUtil {
backMessage = new byte[0];
} else {
backMessage = generatedMessage.toByteArray();
//LOGGER.info(JsonFormat.printToString(generatedMessage));
LOGGER.info(JsonFormat.printToString(generatedMessage));
}
int length = PackageConstant.UID_FIELD_LEN + PackageConstant.TOKEN_LEN

View File

@ -19,7 +19,7 @@ public class SChampionshipReward implements BaseConfig {
@Override
public void init() throws Exception {
}

View File

@ -24,6 +24,8 @@ public class SChampionshipSetting implements BaseConfig {
private int battleTime;
private int settleTime;
private int warTime;
private int arenaPercent;
@ -104,4 +106,8 @@ public class SChampionshipSetting implements BaseConfig {
public int getKnockoutGroup() {
return knockoutGroup;
}
public int getSettleTime() {
return settleTime;
}
}