fix globaldata & champion in redis
parent
206aae7aa3
commit
3b52fbfa63
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,4 +1,4 @@
|
|||
---- linux
|
||||
-- linux
|
||||
package.path = package.path ..';../luafight/?.lua';
|
||||
|
||||
require("Modules.Battle.Logic.Misc.BattleDefine")
|
||||
|
|
@ -22,6 +22,7 @@ require("Modules.Battle.Logic.RoleLogic")
|
|||
local BattleMain = {}
|
||||
local BattleLogic = BattleLogic
|
||||
local Random = Random
|
||||
local BattleRecord
|
||||
|
||||
local _BattleErrorCache = {}
|
||||
local _BattleErrorIndex = 0
|
||||
|
|
@ -128,6 +129,19 @@ local function addBattleData()
|
|||
_BattleErrorCache[_BattleErrorIndex] = str
|
||||
end
|
||||
|
||||
local function AddRecord()
|
||||
BattleRecord = {}
|
||||
BattleLogic.Event:AddEvent(BattleEventName.AddRole, function (role)
|
||||
local record = {}
|
||||
record.uid = role.uid
|
||||
record.camp = role.camp
|
||||
record.damage = 0
|
||||
role.Event:AddEvent(BattleEventName.RoleDamage, function (defRole, damage, bCrit, finalDmg)
|
||||
record.damage = record.damage + finalDmg
|
||||
end)
|
||||
BattleRecord[role.uid] = record
|
||||
end)
|
||||
end
|
||||
function BattleMain.Execute(args, fightData, optionData)
|
||||
_seed = args.seed
|
||||
_type = args.type
|
||||
|
|
@ -135,7 +149,7 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
_optionData = optionData or {}
|
||||
|
||||
--该开关用于输出战斗过程中的日志,用于验证前后端是否出现战斗不同步
|
||||
BattleLogic.IsOpenBattleRecord = false
|
||||
BattleLogic.IsOpenBattleRecord = true
|
||||
|
||||
local isError = false
|
||||
local errorCache
|
||||
|
|
@ -143,6 +157,9 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
Random.SetSeed(args.seed)
|
||||
BattleLogic.Init(args.maxTime, fightData, optionData)
|
||||
BattleLogic.Type = _type
|
||||
if _type == 9 then
|
||||
AddRecord()
|
||||
end
|
||||
BattleLogic.StartOrder()
|
||||
|
||||
while not BattleLogic.IsEnd do
|
||||
|
|
@ -164,7 +181,7 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
resultList[i] = arr[i]:GetRoleData(RoleDataName.Hp)
|
||||
end
|
||||
end
|
||||
resultList.result = BattleLogic.Result
|
||||
|
||||
|
||||
if BattleLogic.IsOpenBattleRecord then
|
||||
generateRecordFile()
|
||||
|
|
@ -175,6 +192,20 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
-- print("hp:"..resultList[i])
|
||||
--end
|
||||
--print("最终运行帧数:"..BattleLogic.CurFrame())
|
||||
if BattleLogic.CurFrame() > BattleLogic.GameFrameRate * args.maxTime and _type == 9 then
|
||||
local playerDamage=0
|
||||
local enemyDamage=0
|
||||
for k,v in pairs(BattleRecord)do
|
||||
if v.camp == 0 then
|
||||
playerDamage = playerDamage + v.damage
|
||||
else
|
||||
enemyDamage = enemyDamage + v.damage
|
||||
end
|
||||
end
|
||||
resultList.result = playerDamage > enemyDamage and 1 or 0
|
||||
else
|
||||
resultList.result = BattleLogic.Result
|
||||
end
|
||||
--print("result:"..BattleLogic.Result)
|
||||
|
||||
addBattleData()
|
||||
|
|
@ -203,10 +234,5 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
end
|
||||
return { result = -1 }
|
||||
end
|
||||
--[[
|
||||
BattleMain.Execute({seed=1565094199,maxTime=300}
|
||||
,{enemyData={{{ai={0},camp=1,element=1,passivity={{45,1},{45,2}},professionId=0,property={139,117440,117440,18564,2911,2911,5960,0.0,0.0,0.05,0.15,0.2,1.5,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0},quality=3,roleId=23,skill={0,{20001,0.7,{1,0.848,1},{13,2,0.1,2,4},{4,4,0.2,12,4}}},superSkill={1.5,{20002,0.7,{10,1.072,1,0.4},{13,3,0.2,1,4}},{30000,0.7,{4,4,0.2,9,2}}},type=4},teamSkill={}}},playerData={{camp=0,element=4,passivity={{5,0.3,1,0.1,5},{39,5,2800},{12,0.15,0.15,2},{44,0.1,4,0.05,6,2}},professionId=5,property={139,76728,76728,4144,3372,2321,3740,0,0,0,0,0.0847,1.5,0,1,1,0,0,0,0,0,0,0,0,0},quality=1,roleId=10005,skill={0,{20001,0.7,{1,0.65,2}},{30101,0.7,{24,1,0.68}},{30001,0.7,{4,1,0.2,9,2}}},superSkill={2,{20004,0.7,{2,0.86,2}},{10100,0.7,{24,1,0.74}}},type=1},{camp=0,element=3,passivity={{5,0.3,1,0.1,5},{39,5,2800},{12,0.15,0.15,2},{44,0.1,4,0.05,6,2}},professionId=5,property={139,76559,76559,4086,2372,3370,3734,0,0,0,0,0.0808,1.5,0,1,1,0,0,0,0,0,0,0,0,0},quality=1,roleId=10007,skill={0,{20001,0.7,{6,3,3,0.88,1},{4,2,0.15,8,4},{4,3,0.15,8,4}}},superSkill={2,{20001,0.7,{1,1.1,1}},{10721,0.7,{8,0,1,1}}},type=1},{camp=0,element=5,passivity={{6,0.25,1,0.25,1,10},{39,5,2800},{12,0.15,0.15,2},{44,0.1,4,0.05,6,2}},professionId=2,property={139,60127,60127,7669,1672,3242,4060,0,0,0,0,0.1287,1.5,0,1,1,0,0,0,0,0,0,0,0,0},quality=1,roleId=10015,skill={0,{20001,0.7,{10,0.95,2,0.3}}},superSkill={3,{20002,0.7,{33,1.4,2,1,10015,0.15,10},{16,0.04,1,10,2}}},type=1},{camp=0,element=1,passivity={{6,0.25,1,0.25,1,10},{39,5,2800},{12,0.15,0.15,2},{44,0.1,4,0.05,6,2}},professionId=1,property={140,72220,72220,3858,4378,2630,4246,0,0,0,0,0.1274,1.5,0,1,1,0,0,0,0,0,0,0,0,0},quality=1,roleId=10020,skill={0,{20001,0.7,{6,3,3,0.35,1}},{10002,0.7,{24,1,0.9}}},superSkill={5,{20000,0.7,{2,0.65,1}},{10000,0.7,{4,6,0.15,6,1}}},type=1},{camp=0,element=2,passivity={{14,0.4,2,0.3,1,10,1},{39,5,2800},{12,0.15,0.15,2},{44,0.1,4,0.05,6,2}},professionId=3,property={139,58750,58750,5175,2145,3634,3581,0,0,0,0,0.0915,1.5,0,1,1,0,0,0,0,0,0,0,0,0},quality=1,roleId=10008,skill={0,{20001,0.7,{29,4,4,0.45,2,2,0.1}}},superSkill={4,{20000,0.7,{2,0.7,2}},{20000,0.7,{3,0.15,1,8}}},type=1},teamSkill={}}}
|
||||
,{{1,1,0},{1,6,11},{1,6,21},{1,6,31},{1,6,41},{1,6,51},{1,5,0}})
|
||||
]]--
|
||||
|
||||
return BattleMain
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ require("Modules.Battle.Logic.RoleLogic")
|
|||
local BattleMain = {}
|
||||
local BattleLogic = BattleLogic
|
||||
local Random = Random
|
||||
local BattleRecord
|
||||
|
||||
local _BattleErrorCache = {}
|
||||
local _BattleErrorIndex = 0
|
||||
|
|
@ -129,15 +130,27 @@ local function addBattleData()
|
|||
_BattleErrorCache[_BattleErrorIndex] = str
|
||||
end
|
||||
|
||||
local function AddRecord()
|
||||
BattleRecord = {}
|
||||
BattleLogic.Event:AddEvent(BattleEventName.AddRole, function (role)
|
||||
local record = {}
|
||||
record.uid = role.uid
|
||||
record.camp = role.camp
|
||||
record.damage = 0
|
||||
role.Event:AddEvent(BattleEventName.RoleDamage, function (defRole, damage, bCrit, finalDmg)
|
||||
record.damage = record.damage + finalDmg
|
||||
end)
|
||||
BattleRecord[role.uid] = record
|
||||
end)
|
||||
end
|
||||
function BattleMain.Execute(args, fightData, optionData)
|
||||
print("trfghjdfgucvhbjnfdcgvj")
|
||||
_seed = args.seed
|
||||
_type = args.type
|
||||
_fightData = fightData
|
||||
_optionData = optionData or {}
|
||||
|
||||
--该开关用于输出战斗过程中的日志,用于验证前后端是否出现战斗不同步
|
||||
BattleLogic.IsOpenBattleRecord = false
|
||||
BattleLogic.IsOpenBattleRecord = true
|
||||
|
||||
local isError = false
|
||||
local errorCache
|
||||
|
|
@ -145,6 +158,9 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
Random.SetSeed(args.seed)
|
||||
BattleLogic.Init(args.maxTime, fightData, optionData)
|
||||
BattleLogic.Type = _type
|
||||
if _type == 9 then
|
||||
AddRecord()
|
||||
end
|
||||
BattleLogic.StartOrder()
|
||||
|
||||
while not BattleLogic.IsEnd do
|
||||
|
|
@ -166,7 +182,7 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
resultList[i] = arr[i]:GetRoleData(RoleDataName.Hp)
|
||||
end
|
||||
end
|
||||
resultList.result = BattleLogic.Result
|
||||
|
||||
|
||||
if BattleLogic.IsOpenBattleRecord then
|
||||
generateRecordFile()
|
||||
|
|
@ -177,6 +193,20 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
-- print("hp:"..resultList[i])
|
||||
--end
|
||||
--print("最终运行帧数:"..BattleLogic.CurFrame())
|
||||
if BattleLogic.CurFrame() > BattleLogic.GameFrameRate * args.maxTime and _type == 9 then
|
||||
local playerDamage=0
|
||||
local enemyDamage=0
|
||||
for k,v in pairs(BattleRecord)do
|
||||
if v.camp == 0 then
|
||||
playerDamage = playerDamage + v.damage
|
||||
else
|
||||
enemyDamage = enemyDamage + v.damage
|
||||
end
|
||||
end
|
||||
resultList.result = playerDamage > enemyDamage and 1 or 0
|
||||
else
|
||||
resultList.result = BattleLogic.Result
|
||||
end
|
||||
--print("result:"..BattleLogic.Result)
|
||||
|
||||
addBattleData()
|
||||
|
|
@ -205,10 +235,5 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
end
|
||||
return { result = -1 }
|
||||
end
|
||||
--[[
|
||||
BattleMain.Execute({seed=1565094199,maxTime=300}
|
||||
,{enemyData={{{ai={0},camp=1,element=1,passivity={{45,1},{45,2}},professionId=0,property={139,117440,117440,18564,2911,2911,5960,0.0,0.0,0.05,0.15,0.2,1.5,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0},quality=3,roleId=23,skill={0,{20001,0.7,{1,0.848,1},{13,2,0.1,2,4},{4,4,0.2,12,4}}},superSkill={1.5,{20002,0.7,{10,1.072,1,0.4},{13,3,0.2,1,4}},{30000,0.7,{4,4,0.2,9,2}}},type=4},teamSkill={}}},playerData={{camp=0,element=4,passivity={{5,0.3,1,0.1,5},{39,5,2800},{12,0.15,0.15,2},{44,0.1,4,0.05,6,2}},professionId=5,property={139,76728,76728,4144,3372,2321,3740,0,0,0,0,0.0847,1.5,0,1,1,0,0,0,0,0,0,0,0,0},quality=1,roleId=10005,skill={0,{20001,0.7,{1,0.65,2}},{30101,0.7,{24,1,0.68}},{30001,0.7,{4,1,0.2,9,2}}},superSkill={2,{20004,0.7,{2,0.86,2}},{10100,0.7,{24,1,0.74}}},type=1},{camp=0,element=3,passivity={{5,0.3,1,0.1,5},{39,5,2800},{12,0.15,0.15,2},{44,0.1,4,0.05,6,2}},professionId=5,property={139,76559,76559,4086,2372,3370,3734,0,0,0,0,0.0808,1.5,0,1,1,0,0,0,0,0,0,0,0,0},quality=1,roleId=10007,skill={0,{20001,0.7,{6,3,3,0.88,1},{4,2,0.15,8,4},{4,3,0.15,8,4}}},superSkill={2,{20001,0.7,{1,1.1,1}},{10721,0.7,{8,0,1,1}}},type=1},{camp=0,element=5,passivity={{6,0.25,1,0.25,1,10},{39,5,2800},{12,0.15,0.15,2},{44,0.1,4,0.05,6,2}},professionId=2,property={139,60127,60127,7669,1672,3242,4060,0,0,0,0,0.1287,1.5,0,1,1,0,0,0,0,0,0,0,0,0},quality=1,roleId=10015,skill={0,{20001,0.7,{10,0.95,2,0.3}}},superSkill={3,{20002,0.7,{33,1.4,2,1,10015,0.15,10},{16,0.04,1,10,2}}},type=1},{camp=0,element=1,passivity={{6,0.25,1,0.25,1,10},{39,5,2800},{12,0.15,0.15,2},{44,0.1,4,0.05,6,2}},professionId=1,property={140,72220,72220,3858,4378,2630,4246,0,0,0,0,0.1274,1.5,0,1,1,0,0,0,0,0,0,0,0,0},quality=1,roleId=10020,skill={0,{20001,0.7,{6,3,3,0.35,1}},{10002,0.7,{24,1,0.9}}},superSkill={5,{20000,0.7,{2,0.65,1}},{10000,0.7,{4,6,0.15,6,1}}},type=1},{camp=0,element=2,passivity={{14,0.4,2,0.3,1,10,1},{39,5,2800},{12,0.15,0.15,2},{44,0.1,4,0.05,6,2}},professionId=3,property={139,58750,58750,5175,2145,3634,3581,0,0,0,0,0.0915,1.5,0,1,1,0,0,0,0,0,0,0,0,0},quality=1,roleId=10008,skill={0,{20001,0.7,{29,4,4,0.45,2,2,0.1}}},superSkill={4,{20000,0.7,{2,0.7,2}},{20000,0.7,{3,0.15,1,8}}},type=1},teamSkill={}}}
|
||||
,{{1,1,0},{1,6,11},{1,6,21},{1,6,31},{1,6,41},{1,6,51},{1,5,0}})
|
||||
]]--
|
||||
|
||||
return BattleMain
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.ljsd.jieling.core.function;
|
||||
|
||||
import com.ljsd.jieling.core.FunctionManager;
|
||||
import com.ljsd.jieling.logic.championship.ChampionshipLogic;
|
||||
import com.ljsd.jieling.logic.dao.TimeControllerOfFunction;
|
||||
|
||||
public class ChampionFunction implements FunctionManager {
|
||||
@Override
|
||||
public void startAction(TimeControllerOfFunction timeControllerOfFunction) throws Exception {
|
||||
ChampionshipLogic.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAction() throws Exception {
|
||||
ChampionshipLogic.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -198,10 +198,21 @@ public class RedisKey {
|
|||
public final static String CHAMPION_FIGHT = "CHAMPION_FIGHT";
|
||||
public final static String CHAMPION_RANK = "CHAMPION_RANK";
|
||||
public final static String CHAMPION_JOIN = "CHAMPION_JOIN";
|
||||
public final static String CHAMPION_ARENA_RECORD = "CHAMPION_ARENA_RECORD";
|
||||
public final static String CHAMPION_CUR_JOIN_IDS = "CHAMPION_CUR_JOIN_IDS";
|
||||
public final static String CHAMPION_MY_BATTLLE_IDS = "CHAMPION_MY_BATTLLE_IDS";
|
||||
|
||||
public final static String CHAMPION_CUR_BETID = "CHAMPION_CUR_BETID";
|
||||
|
||||
|
||||
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_PROGRESS = "CHAMPION_PROGRESS"; //
|
||||
public final static String CHAMPION_BET_MINE = "CHAMPION_BET_MINE"; // 我的竞猜
|
||||
public final static String CHAMPION_BET_ALL = "CHAMPION_BET_ALL"; // 竞猜信息
|
||||
public final static String CHAMPION_BET_RANK = "CHAMPION_BET_RANK"; // 巅峰赛排名
|
||||
public final static String CHAMPION_FINAL_RECODED_IDS = "CHAMPION_FINAL_RECODED_IDS"; // 巅峰赛決賽信息
|
||||
|
||||
public final static String PIDGIDTEMP = "PIDGIDTEMP";
|
||||
|
||||
|
|
|
|||
|
|
@ -542,9 +542,10 @@ public class RedisUtil {
|
|||
* 结束 0 到 -1代表所有值
|
||||
* @return
|
||||
*/
|
||||
public List<String> lGet(String key, long start, long end) {
|
||||
public List<String> lGet(String type,String key, long start, long end) {
|
||||
try {
|
||||
return redisTemplate.opsForList().range(key, start, end);
|
||||
String key1 = getKey(type, key);
|
||||
return redisTemplate.opsForList().range(key1, start, end);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
|
@ -630,15 +631,17 @@ public class RedisUtil {
|
|||
/**
|
||||
* 将list放入缓存
|
||||
*
|
||||
* @param type
|
||||
* @param key
|
||||
* 键
|
||||
* @param value
|
||||
* 值
|
||||
* @return
|
||||
*/
|
||||
public boolean lSet(String key, List<String> value) {
|
||||
public boolean lSet(String type,String key, List<String> value) {
|
||||
try {
|
||||
redisTemplate.opsForList().rightPushAll(key, value);
|
||||
String rkey = getKey(type, key);
|
||||
redisTemplate.opsForList().rightPushAll(rkey, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -978,6 +981,22 @@ public class RedisUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public <T> void putMapEntrys(String type,String key,Map<String,T> valus){
|
||||
String rkey = getKey(type, key);
|
||||
Map<String, String> result = new HashMap<>();
|
||||
valus.forEach((k,v)->{
|
||||
result.put(k,gson.toJson(v));
|
||||
});
|
||||
for (int i = 0; i < MAX_TRY_TIMES; i++) {
|
||||
try {
|
||||
redisTemplate.opsForHash().putAll(rkey,result);
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
TimeUtils.sleep(FAILED_SLEEP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T getMapEntry(String type,String key,String mapKey,Class<T> valueClazz){
|
||||
String rkey = getKey(type, key);
|
||||
for (int i = 0; i < MAX_TRY_TIMES; i++) {
|
||||
|
|
|
|||
|
|
@ -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 ChampinGetHandler extends BaseHandler {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.CHAMPION_GET_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ISession iSession, PacketNetData netData) throws Exception {
|
||||
ChampionshipLogic.getChampionInfo(iSession);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 ChampionBetHandler extends BaseHandler<ArenaInfoProto.ChampionBetReqeust> {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.CHAMPION_BET_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession iSession, ArenaInfoProto.ChampionBetReqeust proto) throws Exception {
|
||||
ChampionshipLogic.guess(iSession,proto.getWinUid(),proto.getCoins());
|
||||
}
|
||||
}
|
||||
|
|
@ -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 ChampionGetTeamInfoHandler extends BaseHandler {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.CHAMPION_GET_MYTEAM_REQUESST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ISession iSession, PacketNetData netData) throws Exception {
|
||||
ChampionshipLogic.getMyTeamInfo(iSession);
|
||||
}
|
||||
}
|
||||
|
|
@ -89,6 +89,17 @@ public class GlobalDataManaager implements IManager {
|
|||
return openTimeOfFuntionCache.get(functionId);
|
||||
}
|
||||
|
||||
public TimeControllerOfFunction getTimeControllerOfFunctionByFunctinoType(FunctionIdEnum functionIdEnum){
|
||||
Map<Integer, SGlobalSystemConfig> sGlobalSystemConfigMap = STableManager.getConfig(SGlobalSystemConfig.class);
|
||||
for(Map.Entry<Integer,TimeControllerOfFunction> item : openTimeOfFuntionCache.entrySet()){
|
||||
SGlobalSystemConfig sGlobalSystemConfig = sGlobalSystemConfigMap.get(item.getKey());
|
||||
if(sGlobalSystemConfig.getIsIDdSame() == functionIdEnum.getFunctionId()){
|
||||
return item.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkSystemFunctioIsOpen() throws Exception {
|
||||
long now = TimeUtils.now();
|
||||
Map<Integer, SGlobalSystemConfig> sGlobalSystemConfigMap = STableManager.getConfig(SGlobalSystemConfig.class);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
package com.ljsd.jieling.logic.championship;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
|
||||
import com.ljsd.jieling.core.FunctionIdEnum;
|
||||
import com.ljsd.jieling.core.GlobalsDef;
|
||||
import com.ljsd.jieling.core.HandlerLogicThread;
|
||||
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.globals.BIReason;
|
||||
import com.ljsd.jieling.logic.GlobalDataManaager;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.arena.ArenaLogic;
|
||||
import com.ljsd.jieling.logic.blood.BloodLogic;
|
||||
|
|
@ -29,19 +34,21 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.data.redis.core.DefaultTypedTuple;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import util.StringUtil;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
|
||||
public class ChampionshipLogic {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(HeroLogic.class);
|
||||
//启动服务器应该去redis获取
|
||||
private static int progress = -1; //阶段
|
||||
|
||||
private static Gson gson = new Gson();
|
||||
|
||||
private static int startTime;
|
||||
private static int roundTimes; //比赛进行第几轮
|
||||
|
||||
private static int endTime;
|
||||
private static int roundTimes;
|
||||
|
||||
private static Map<Integer,GameFightType> gameFightTypeMap = new HashMap<>();
|
||||
static {
|
||||
|
|
@ -55,8 +62,11 @@ public class ChampionshipLogic {
|
|||
private int uid;
|
||||
private int type;
|
||||
private int score; // 选拔积分
|
||||
private int finalScore; //決賽積分
|
||||
private int teamId;
|
||||
private FamilyFightInfo fightInfo;
|
||||
|
||||
|
||||
public MemberInfo( int uid, int type) {
|
||||
this.uid = uid;
|
||||
this.type = type;
|
||||
|
|
@ -74,33 +84,119 @@ public class ChampionshipLogic {
|
|||
return score;
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public FamilyFightInfo getFightInfo() {
|
||||
return fightInfo;
|
||||
}
|
||||
|
||||
public int getFinalScore() {
|
||||
return finalScore;
|
||||
}
|
||||
|
||||
public void setFinalScore(int finalScore) {
|
||||
this.finalScore = finalScore;
|
||||
}
|
||||
|
||||
public int getTeamId() {
|
||||
return teamId;
|
||||
}
|
||||
|
||||
public void setTeamId(int teamId) {
|
||||
this.teamId = teamId;
|
||||
}
|
||||
|
||||
public void setFightInfo(FamilyFightInfo fightInfo) {
|
||||
this.fightInfo = fightInfo;
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<Integer,MemberInfo> joinMembers;
|
||||
// private static Map<String,ArenaRecord> arenaRecordMap = new HashMap<>();//历史对战队伍信息
|
||||
|
||||
private static List<List<MemberInfo>> memberOfTeam;
|
||||
// private static Map<String,ArenaRecord> curArenaRecordMap = new HashMap<>();//当前进行对战队伍信息
|
||||
|
||||
private static Map<String,ArenaRecord> arenaRecordMap = new HashMap<>();
|
||||
// private static List<String> finalRecodedIds = new ArrayList<>();
|
||||
|
||||
private static Map<String,ArenaRecord> curArenaRecordMap = new HashMap<>();
|
||||
// private static List<List<Integer>> finalmemberOfTeam; // 决赛队伍信息
|
||||
|
||||
private static String selectUid = "";
|
||||
// private static String selectUid = "";
|
||||
|
||||
private static int schedule=1;
|
||||
|
||||
//提前把分数缓存进来
|
||||
public static void setScoreForSuccess(int winnerUid,int failerUid){
|
||||
MemberInfo memberInfo = getJoinMemberInfo(winnerUid);
|
||||
if(schedule == 2){
|
||||
memberInfo.setFinalScore(memberInfo.getFinalScore()+1);
|
||||
MemberInfo failMemberInfo = getJoinMemberInfo(failerUid);
|
||||
failMemberInfo.setFinalScore(memberInfo.getFinalScore()*-1);
|
||||
LOGGER.info("the falid={}",failerUid);
|
||||
updateJoinMemberInfo(memberInfo);
|
||||
updateJoinMemberInfo(failMemberInfo);
|
||||
return;
|
||||
}
|
||||
memberInfo.setScore(memberInfo.getScore() + 1);
|
||||
updateJoinMemberInfo(memberInfo);
|
||||
}
|
||||
|
||||
private static MemberInfo getJoinMemberInfo(int joinUid){
|
||||
return RedisUtil.getInstence().getMapValue(RedisKey.CHAMPION_JOIN,"",Integer.toString(joinUid),MemberInfo.class);
|
||||
}
|
||||
|
||||
private static void updateJoinMemberInfo(MemberInfo memberInfo){
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.CHAMPION_JOIN, "",Integer.toString(memberInfo.getUid()),memberInfo);
|
||||
}
|
||||
|
||||
public static void scoreToRedis(){
|
||||
List<String> curArenaRecordIds = RedisUtil.getInstence().lGet(RedisKey.CHAMPION_CUR_JOIN_IDS, "", 0, -1);
|
||||
List<Object> ids = new ArrayList<>(curArenaRecordIds);
|
||||
List<ArenaRecord> arenaRecords = RedisUtil.getInstence().getMapEntrys(RedisKey.CHAMPION_ARENA_RECORD, "", ids, ArenaRecord.class);
|
||||
while (!battleIsFinish(arenaRecords)){
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
arenaRecords = RedisUtil.getInstence().getMapEntrys(RedisKey.CHAMPION_ARENA_RECORD, "", ids, ArenaRecord.class);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Set<ZSetOperations.TypedTuple<String>> arenaRankInfoForChampion= new HashSet<>();
|
||||
List<String> finalArenaIds = new ArrayList<>();
|
||||
arenaRecords.forEach((v)->{
|
||||
int winnerUid = v.getAttackId();
|
||||
if(v.getFightResult() == 0){
|
||||
winnerUid = v.getDefUid();
|
||||
}
|
||||
MemberInfo joinMemberInfo = getJoinMemberInfo(winnerUid);
|
||||
int score =joinMemberInfo.getScore();
|
||||
if(schedule==2){
|
||||
score = joinMemberInfo.getFinalScore();
|
||||
finalArenaIds.add(v.getId());
|
||||
}
|
||||
arenaRankInfoForChampion.add(new DefaultTypedTuple(Integer.toString(winnerUid), (double)score));
|
||||
});
|
||||
RedisUtil.getInstence().updateZsetScores(RedisKey.CHAMPION_RANK,"",arenaRankInfoForChampion);
|
||||
if(schedule == 2){
|
||||
RedisUtil.getInstence().lSet(RedisKey.CHAMPION_FINAL_RECODED_IDS,"",finalArenaIds);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean battleIsFinish( List<ArenaRecord> arenaRecords){
|
||||
for(ArenaRecord arenaRecord : arenaRecords){
|
||||
if(arenaRecord.getFightResult() == -2){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 巅峰赛开始准备工作
|
||||
* 1.数据准备:制作参与巅峰赛
|
||||
* 2.告知前端现在是准备阶段,并告诉我是否加入了巅峰赛
|
||||
* 参赛人员信息
|
||||
* 参赛队伍信息
|
||||
*/
|
||||
public static void whenStart() throws Exception {
|
||||
progress = 0;
|
||||
public static void start() {
|
||||
SChampionshipSetting sChampionshipSetting = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting();
|
||||
int championshipPlayer = sChampionshipSetting.getChampionshipPlayer();
|
||||
int curSeason = ArenaLogic.getInstance().getCurSeason();
|
||||
|
|
@ -110,12 +206,12 @@ public class ChampionshipLogic {
|
|||
arenaRankInfo.addAll(arenaRankInfoOne);
|
||||
}
|
||||
Set<ZSetOperations.TypedTuple<String>> arenaRankInfoForChampion= new HashSet<>();
|
||||
joinMembers = new HashMap<>(championshipPlayer);
|
||||
List<MemberInfo> joinMembers = new ArrayList<>(championshipPlayer);
|
||||
List<MemberInfo> memberInfos = new ArrayList<>(championshipPlayer);
|
||||
arenaRankInfo.forEach(item->{
|
||||
String uidStr = item.getValue();
|
||||
MemberInfo memberInfo = new MemberInfo(Integer.parseInt(uidStr), 0);
|
||||
joinMembers.put(Integer.parseInt(uidStr),memberInfo);
|
||||
joinMembers.add(memberInfo);
|
||||
ZSetOperations.TypedTuple typedTuple = new DefaultTypedTuple(uidStr,0D);
|
||||
arenaRankInfoForChampion.add(typedTuple);
|
||||
memberInfos.add(memberInfo);
|
||||
|
|
@ -141,50 +237,76 @@ public class ChampionshipLogic {
|
|||
break;
|
||||
}
|
||||
MemberInfo memberInfo = new MemberInfo(sArenaRobotConfig.getId(), 1);
|
||||
joinMembers.put(sArenaRobotConfig.getId(),memberInfo);
|
||||
joinMembers.add(memberInfo);
|
||||
ZSetOperations.TypedTuple typedTuple = new DefaultTypedTuple(Integer.toString(sArenaRobotConfig.getId()),0D);
|
||||
arenaRankInfoForChampion.add(typedTuple);
|
||||
memberInfos.add(memberInfo);
|
||||
LOGGER.info("the end={},the robotID={},the size={}",end,sArenaRobotConfig.getId(),joinMembers.size());
|
||||
}
|
||||
}
|
||||
Collections.shuffle(memberInfos);
|
||||
int index=0;
|
||||
int trialsGroup = sChampionshipSetting.getTrialsGroup();
|
||||
int nums = championshipPlayer / trialsGroup;
|
||||
List<List<MemberInfo>> memberOfTeamTmp = new ArrayList<>();
|
||||
while (nums-->0){
|
||||
memberOfTeamTmp.add(new ArrayList<>());
|
||||
}
|
||||
nums = championshipPlayer / trialsGroup;
|
||||
for(MemberInfo memberInfo : memberInfos){
|
||||
int teamId = (index++ % nums);
|
||||
memberOfTeamTmp.get(teamId).add(memberInfo);
|
||||
}
|
||||
memberOfTeam = memberOfTeamTmp;
|
||||
|
||||
|
||||
|
||||
List<List<Integer>> memberOfTeamOfGroup = getMemberOfTeamOfGroup(memberInfos, nums);
|
||||
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);
|
||||
RedisUtil.getInstence().set(key, gson.toJson(joinMembers));
|
||||
|
||||
|
||||
//
|
||||
for(int i=1;i<8;i++){
|
||||
roundTimes=i;
|
||||
selectToBattle();
|
||||
switchBet();
|
||||
LOGGER.info("i------------------------------------->>>>>>>>>>>>>>>>>>>>{},size={}",i,curArenaRecordMap.size());
|
||||
curArenaRecordMap.clear();
|
||||
joinMembers.forEach(memberInfo->{
|
||||
updateJoinMemberInfo(memberInfo);
|
||||
});
|
||||
for(int i=0;i<memberOfTeamOfGroup.size();i++){
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.CHAMPION_CHOSE_TEAM_INFO, "",Integer.toString(i),memberOfTeamOfGroup.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void close() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 巅峰赛开始准备工作
|
||||
* 1.数据准备:制作参与巅峰赛
|
||||
* 2.告知前端现在是准备阶段,并告诉我是否加入了巅峰赛
|
||||
*/
|
||||
public static void whenStart() throws Exception {
|
||||
TimeControllerOfFunction timeControllerOfFunction = GlobalDataManaager.getInstance().getTimeControllerOfFunctionByFunctinoType(FunctionIdEnum.TopBattle);
|
||||
if( null == timeControllerOfFunction){
|
||||
progress = -1;
|
||||
return;
|
||||
}
|
||||
String key = RedisUtil.getInstence().getKey(RedisKey.CHAMPION_JOIN, "");
|
||||
Type type = new TypeToken<Map<Integer, byte[]>>() {
|
||||
}.getType();
|
||||
Object championJoins = RedisUtil.getInstence().get(key);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取分组情况
|
||||
* @param memberInfoList 将要被分配的成员信息
|
||||
* @param groupNums 分成几组
|
||||
* @return
|
||||
*/
|
||||
private static List<List<Integer>> getMemberOfTeamOfGroup(List<MemberInfo> memberInfoList,int groupNums){
|
||||
Collections.shuffle(memberInfoList);
|
||||
int index=0;
|
||||
List<List<Integer>> memberOfTeamTmp = new ArrayList<>();
|
||||
int temp = groupNums;
|
||||
while (temp-->0){
|
||||
memberOfTeamTmp.add(new ArrayList<>());
|
||||
}
|
||||
for(MemberInfo memberInfo : memberInfoList){
|
||||
int teamId = (index++ % groupNums);
|
||||
memberOfTeamTmp.get(teamId).add(memberInfo.getUid());
|
||||
if(schedule == 1){
|
||||
memberInfo.setTeamId(teamId);
|
||||
}
|
||||
}
|
||||
return memberOfTeamTmp;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -198,28 +320,97 @@ public class ChampionshipLogic {
|
|||
*/
|
||||
public static void getChampionInfo(ISession session) throws Exception {
|
||||
int uid = session.getUid();
|
||||
List<String> championshipIds = new ArrayList<>();
|
||||
boolean isJoin = joinMembers.containsKey(uid);
|
||||
if(!championshipIds.isEmpty()){
|
||||
String championshipId = championshipIds.get(championshipIds.size() - 1);
|
||||
ArenaRecord arenaRecord = arenaRecordMap.get(championshipId);
|
||||
int enemyId = arenaRecord.getDefUid();
|
||||
if(enemyId == uid){
|
||||
enemyId = arenaRecord.getAttackId();
|
||||
}
|
||||
CommonProto.ArenaEnemy arenaEnemy = ArenaLogic.getInstance().getArenaEnemy(enemyId, arenaRecord.getType());
|
||||
int fightResult = arenaRecord.getFightResult(); // 0
|
||||
}
|
||||
//组装数据
|
||||
int myRank = RedisUtil.getInstence().getZSetreverseRank(RedisKey.CHAMPION_RANK, "", Integer.toString(uid)).intValue();
|
||||
String myCurJoinBattleId = getMyCurJoinBattleId(uid);
|
||||
ArenaInfoProto.ChampionGetInfoResponse.Builder builder = ArenaInfoProto.ChampionGetInfoResponse.newBuilder().setProgress(progress).setEndTime(endTime).setMyrank(myRank);
|
||||
if(!StringUtil.isEmpty(myCurJoinBattleId)){
|
||||
builder.setJoinState(1);
|
||||
ArenaRecord arenaRecord =RedisUtil.getInstence().getMapValue(RedisKey.CHAMPION_ARENA_RECORD,"",myCurJoinBattleId,ArenaRecord.class);
|
||||
int enemyId = arenaRecord.getDefUid();
|
||||
int fightResult = arenaRecord.getFightResult();
|
||||
if(uid == enemyId){
|
||||
enemyId = arenaRecord.getAttackId();
|
||||
fightResult=1^fightResult;
|
||||
}
|
||||
if(progress%3 != 0){
|
||||
fightResult =-1;
|
||||
}
|
||||
builder.setChampionBattleInfo(CommonProto.ChampionBattleInfo.newBuilder()
|
||||
/* .setMyInfo(getEnemyInfo(uid,0))
|
||||
.setEnemyInfo(getEnemyInfo(enemyId,0))*/
|
||||
.setResult(fightResult)
|
||||
.build());
|
||||
|
||||
}
|
||||
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.CHAMPION_GET_RESPONSE_VALUE,builder.build(),true);
|
||||
}
|
||||
|
||||
private static String getMyCurJoinBattleId(int uid){
|
||||
List<ArenaRecord> curArenaRecordList = getCurArenaRecordList();
|
||||
for(ArenaRecord arenaRecord :curArenaRecordList){
|
||||
if(arenaRecord.getDefUid() == uid || arenaRecord.getAttackId() == uid){
|
||||
return arenaRecord.getId();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的队伍信息
|
||||
* @param session
|
||||
* @throws ErrorCodeException
|
||||
*/
|
||||
public static void getMyTeamInfo(ISession session) throws ErrorCodeException {
|
||||
int uid = session.getUid();
|
||||
MemberInfo memberInfo = getJoinMemberInfo(uid);
|
||||
if(memberInfo == null){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
|
||||
}
|
||||
int teamId = memberInfo.getTeamId();
|
||||
List<Integer> memberIds = RedisUtil.getInstence().getMapValue(RedisKey.CHAMPION_CHOSE_TEAM_INFO, "", Integer.toString(teamId), List.class);
|
||||
Map<Integer, SArenaRobotConfig> robotConfigMap = STableManager.getConfig(SArenaRobotConfig.class);
|
||||
|
||||
List<CommonProto.ChampionTeamPersonInfo> championTeamPersonInfoList = new ArrayList<>(memberIds.size());
|
||||
memberIds.forEach(uidTmp -> {
|
||||
int score = getJoinMemberInfo(uidTmp).getScore();
|
||||
String name=null;
|
||||
if(robotConfigMap.containsKey(uidTmp)){
|
||||
SArenaRobotConfig sArenaRobotConfig = robotConfigMap.get(uidTmp);
|
||||
name = sArenaRobotConfig.getRobotName();
|
||||
}else{
|
||||
try {
|
||||
User user = UserManager.getUser(uidTmp);
|
||||
name = user.getPlayerInfoManager().getNickName();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
championTeamPersonInfoList.add( CommonProto.ChampionTeamPersonInfo.newBuilder()
|
||||
.setUid(uidTmp)
|
||||
.setScore(score)
|
||||
.setName(name)
|
||||
.build());
|
||||
});
|
||||
Collections.sort(championTeamPersonInfoList, new Comparator<CommonProto.ChampionTeamPersonInfo>() {
|
||||
@Override
|
||||
public int compare(CommonProto.ChampionTeamPersonInfo o1, CommonProto.ChampionTeamPersonInfo o2) {
|
||||
return o2.getScore() - o1.getScore();
|
||||
}
|
||||
});
|
||||
ArenaInfoProto.ChampionGetMyTeamInfoResponse build = ArenaInfoProto.ChampionGetMyTeamInfoResponse.newBuilder().addAllChampionTeamPersonInfo(championTeamPersonInfoList).build();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//查看我的战斗记录
|
||||
public static void viewAllMyBattleInfo(ISession session) throws Exception {
|
||||
int uid = session.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
List<String> championshipIds = new ArrayList<>();
|
||||
for(String championshipId : championshipIds){
|
||||
ArenaRecord arenaRecord = arenaRecordMap.get(championshipId);
|
||||
List<String> championshipIds = RedisUtil.getInstence().getMapEntry(RedisKey.CHAMPION_MY_BATTLLE_IDS,"",Integer.toString(uid),List.class);
|
||||
List<Object> ids = new ArrayList<>(championshipIds);
|
||||
List<ArenaRecord> myArenaRecordInfos = RedisUtil.getInstence().getMapEntrys(RedisKey.CHAMPION_ARENA_RECORD, "", ids, ArenaRecord.class);
|
||||
for(ArenaRecord arenaRecord : myArenaRecordInfos){
|
||||
ArenaLogic.getInstance().getArenaEnemy(arenaRecord.getAttackId(),arenaRecord.getType());
|
||||
int fightResult = arenaRecord.getFightResult();
|
||||
if(fightResult == -1){
|
||||
|
|
@ -232,33 +423,37 @@ public class ChampionshipLogic {
|
|||
int snapTeamId = GlobalsDef.CHAMPION_ATTACK_TEAM;
|
||||
RedisUtil.getInstence().del( RedisUtil.getInstence().getKey(RedisKey.CHAMPION_FIGHT, ""));
|
||||
int warTime = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting().getWarTime();
|
||||
|
||||
for(ArenaRecord arenaRecord : curArenaRecordMap.values()){
|
||||
Map<Integer, MemberInfo> memberInfoMap = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_JOIN, "", Integer.class, MemberInfo.class);
|
||||
List<ArenaRecord> curArenaRecords= getCurArenaRecordList();
|
||||
for(ArenaRecord arenaRecord :curArenaRecords){
|
||||
int attackId = arenaRecord.getAttackId();
|
||||
int defUid = arenaRecord.getDefUid();
|
||||
snapOneFightInfo(attackId);
|
||||
snapOneFightInfo(defUid);
|
||||
PVPFightEvent pvpFightEvent = new PVPFightEvent(attackId,snapTeamId,warTime,"",gameFightTypeMap.get(arenaRecord.getType()),defUid,snapTeamId);
|
||||
|
||||
long id =FightDispatcher.dispatcherAsync(pvpFightEvent);
|
||||
snapOneFightInfo(attackId,memberInfoMap);
|
||||
snapOneFightInfo(defUid,memberInfoMap);
|
||||
|
||||
long id =FightDispatcher.getFIghtId();
|
||||
EndFightProcessor endFightProcessor = new AreFightPro();
|
||||
((AreFightPro) endFightProcessor).setArenaRecord(arenaRecord);
|
||||
FightDispatcher.getMap().put(id, endFightProcessor) ;
|
||||
PVPFightEvent pvpFightEvent = new PVPFightEvent(attackId,snapTeamId,warTime,"",gameFightTypeMap.get(arenaRecord.getType()),defUid,snapTeamId);
|
||||
FightDispatcher.dispatcherAsync(pvpFightEvent,id);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void snapOneFightInfo(int uid) throws Exception {
|
||||
public static void snapOneFightInfo(int uid,Map<Integer,MemberInfo> joinMembers) throws Exception {
|
||||
int snapTeamId = 201;
|
||||
MemberInfo memberInfo = joinMembers.get(uid);
|
||||
|
||||
Map<Integer, SArenaRobotConfig> config = STableManager.getConfig(SArenaRobotConfig.class);
|
||||
if(config.containsKey(uid)){
|
||||
SArenaRobotConfig sArenaRobotConfig = config.get(uid);
|
||||
|
||||
return;
|
||||
}
|
||||
MemberInfo memberInfo = joinMembers.get(uid);
|
||||
User user = UserManager.getUser(uid);
|
||||
FamilyFightInfo fightInfo = new FamilyFightInfo();
|
||||
//血量处理,buff处理
|
||||
|
|
@ -292,7 +487,9 @@ public class ChampionshipLogic {
|
|||
int min = Integer.MAX_VALUE;
|
||||
String selectBetId = "";
|
||||
Map<Integer, SArenaRobotConfig> config = STableManager.getConfig(SArenaRobotConfig.class);
|
||||
for(ArenaRecord arenaRecord : curArenaRecordMap.values()){
|
||||
Map<Integer, MemberInfo> joinMembers = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_JOIN, "", Integer.class, MemberInfo.class);
|
||||
List<ArenaRecord> curArenaRecords = getCurArenaRecordList();
|
||||
for(ArenaRecord arenaRecord : curArenaRecords){
|
||||
int attackId = arenaRecord.getAttackId();
|
||||
int defUid = arenaRecord.getDefUid();
|
||||
MemberInfo attackMemberInfo = joinMembers.get(attackId);
|
||||
|
|
@ -306,12 +503,11 @@ public class ChampionshipLogic {
|
|||
}
|
||||
}
|
||||
int guessNum = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting().getGuessNum();
|
||||
ArenaRecord arenaRecord = arenaRecordMap.get(selectBetId);
|
||||
ArenaRecord arenaRecord =RedisUtil.getInstence().getMapValue(RedisKey.CHAMPION_ARENA_RECORD,"",selectBetId,ArenaRecord.class);
|
||||
int attackId = arenaRecord.getAttackId();
|
||||
int defUid = arenaRecord.getDefUid();
|
||||
RedisUtil.getInstence().incrementZsetScore(RedisKey.CHAMPION_BET_ALL,"",selectBetId +":" + attackId,guessNum);
|
||||
RedisUtil.getInstence().incrementZsetScore(RedisKey.CHAMPION_BET_ALL,"",selectBetId +":" + defUid,guessNum);
|
||||
selectUid = selectBetId;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -338,69 +534,90 @@ public class ChampionshipLogic {
|
|||
* @chip chip 筹码
|
||||
*/
|
||||
public static void guess(ISession session, int winUid,int chip) throws Exception {
|
||||
if(progress%3!=2 || StringUtil.isEmpty(selectUid)){
|
||||
return;
|
||||
}
|
||||
int uid = session.getUid();
|
||||
String selectUid = getSelectIdForRedis();
|
||||
if(progress%3!=2 || StringUtil.isEmpty(selectUid)){
|
||||
LOGGER.error("the uid={} not in time",uid);
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
|
||||
}
|
||||
ArenaRecord arenaRecord = RedisUtil.getInstence().getMapValue(RedisKey.CHAMPION_ARENA_RECORD, "", selectUid, ArenaRecord.class);
|
||||
if(arenaRecord.getAttackId()!=winUid && arenaRecord.getDefUid()!=winUid){
|
||||
LOGGER.error("the uid={} guess winner={} is not exists",uid,winUid);
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
|
||||
}
|
||||
User user = UserManager.getUser(uid);
|
||||
int[] arenaItem = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting().getArenaItem();
|
||||
Map<Integer,Integer> itemCost = new HashMap<>(1);
|
||||
itemCost.put(arenaItem[0], chip);
|
||||
boolean enough = ItemUtil.itemCost(user, itemCost, BIReason.CHAMPIION_BET_CONSUME, winUid);
|
||||
if(!enough){
|
||||
return;
|
||||
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
|
||||
}
|
||||
//我下注信息
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.CHAMPION_BET_MINE,Integer.toString(uid),selectUid +":" + winUid,chip);
|
||||
RedisUtil.getInstence().incrementZsetScore(RedisKey.CHAMPION_BET_ALL,"",selectUid +":" + winUid,chip);
|
||||
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.CHAMPION_BET_MINE,selectUid +":" + winUid,Integer.toString(uid),chip);
|
||||
|
||||
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.CHAMPION_BET_RESPONSE_VALUE,null,true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 回收资源
|
||||
*/
|
||||
public static void clearReidsWhenEnd(){
|
||||
List<String> delKeys = new ArrayList<>();
|
||||
String betAllKey = RedisUtil.getInstence().getKey(RedisKey.CHAMPION_BET_ALL, "");
|
||||
Set<String> betDetails = RedisUtil.getInstence().getZset(betAllKey, 0, -1);
|
||||
for(String betInfo : betDetails){
|
||||
delKeys.add(RedisUtil.getInstence().getKey(RedisKey.CHAMPION_BET_MINE, betInfo));
|
||||
}
|
||||
delKeys.add(betAllKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送竞猜奖
|
||||
*
|
||||
* 比赛结束后删除
|
||||
*/
|
||||
public static void sendBetReward(){
|
||||
List<String> delKeys = new ArrayList<>(128);
|
||||
String selectUid = getSelectIdForRedis();
|
||||
int[] arenaItem = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting().getArenaItem();
|
||||
for(ArenaRecord arenaRecord : curArenaRecordMap.values()){
|
||||
int fightResult = arenaRecord.getFightResult();
|
||||
int winUid = arenaRecord.getDefUid();
|
||||
int failUid = arenaRecord.getAttackId();
|
||||
if(fightResult == 1){
|
||||
winUid = arenaRecord.getAttackId();
|
||||
failUid = arenaRecord.getDefUid();
|
||||
}
|
||||
Double winCoins = RedisUtil.getInstence().getZSetScore(RedisKey.CHAMPION_BET_ALL, "", selectUid + ":" +winUid);
|
||||
Double failCoins = RedisUtil.getInstence().getZSetScore(RedisKey.CHAMPION_BET_ALL, "", selectUid + ":" + failUid);
|
||||
ArenaRecord arenaRecord = RedisUtil.getInstence().getMapValue(RedisKey.CHAMPION_ARENA_RECORD, "", selectUid, ArenaRecord.class);
|
||||
|
||||
double winRate = (winCoins + failCoins) / winCoins;
|
||||
Map<Integer, Integer> betPersonInfoMap = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_BET_MINE, selectUid + ":" + winUid, Integer.class, Integer.class);
|
||||
betPersonInfoMap.forEach((betUid,coins)->{
|
||||
try {
|
||||
User user = UserManager.getUser(betUid);
|
||||
AyyncWorker ayyncWorker = new AyyncWorker(user, true, new AyncWorkerRunnable() {
|
||||
@Override
|
||||
public void work(User user) throws Exception {
|
||||
int mineWinCoins = (int) (winRate * coins);
|
||||
int[][] drop = new int[1][];
|
||||
drop[0] = new int[2];
|
||||
drop[0][0] = arenaItem[0];
|
||||
drop[0][1] = mineWinCoins;
|
||||
ItemUtil.drop(user, drop, BIReason.CHAMPIION_BET_WIN_REWARD);
|
||||
}
|
||||
});
|
||||
ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
/* delKeys.add(RedisUtil.getInstence().getKey(RedisKey.CHAMPION_BET_MINE, selectUid + ":" + winUid));
|
||||
delKeys.add(RedisUtil.getInstence().getKey(RedisKey.CHAMPION_BET_MINE, selectUid + ":" + failUid));*/
|
||||
int fightResult = arenaRecord.getFightResult();
|
||||
int winUid = arenaRecord.getDefUid();
|
||||
int failUid = arenaRecord.getAttackId();
|
||||
if(fightResult == 1){
|
||||
winUid = arenaRecord.getAttackId();
|
||||
failUid = arenaRecord.getDefUid();
|
||||
}
|
||||
//RedisUtil.getInstence().del();
|
||||
Double winCoins = RedisUtil.getInstence().getZSetScore(RedisKey.CHAMPION_BET_ALL, "", selectUid + ":" +winUid);
|
||||
Double failCoins = RedisUtil.getInstence().getZSetScore(RedisKey.CHAMPION_BET_ALL, "", selectUid + ":" + failUid);
|
||||
|
||||
double winRate = (winCoins + failCoins) / winCoins;
|
||||
Map<Integer, Integer> betPersonInfoMap = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_BET_MINE, selectUid + ":" + winUid, Integer.class, Integer.class);
|
||||
betPersonInfoMap.forEach((betUid,coins)->{
|
||||
try {
|
||||
User user = UserManager.getUser(betUid);
|
||||
AyyncWorker ayyncWorker = new AyyncWorker(user, true, new AyncWorkerRunnable() {
|
||||
@Override
|
||||
public void work(User user) throws Exception {
|
||||
int mineWinCoins = (int) (winRate * coins);
|
||||
int[][] drop = new int[1][];
|
||||
drop[0] = new int[2];
|
||||
drop[0][0] = arenaItem[0];
|
||||
drop[0][1] = mineWinCoins;
|
||||
ItemUtil.drop(user, drop, BIReason.CHAMPIION_BET_WIN_REWARD);
|
||||
}
|
||||
});
|
||||
ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -430,52 +647,136 @@ public class ChampionshipLogic {
|
|||
* 向全服玩家广播赔率
|
||||
*/
|
||||
public static CommonProto.ChampionBetInfo getBetOdds(){
|
||||
ArenaRecord arenaRecord = arenaRecordMap.get(selectUid);
|
||||
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 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().setRedRate(attackRateStr).setBlueRate(defRateStr).setId(selectUid).build();
|
||||
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<>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 1.发给战斗处理器处理。
|
||||
* 2.选择本场次竞猜队伍id
|
||||
* 3.给参战玩家记录
|
||||
*
|
||||
* 1.选出参战人员
|
||||
*/
|
||||
public static void selectToBattle(){
|
||||
List<int[]> joinIndexs = STableManager.getFigureConfig(CommonStaticConfig.class).getMatrixforGroupInfo().get(roundTimes);
|
||||
if(joinIndexs != null){
|
||||
for(int[] joinIndex : joinIndexs){
|
||||
int joinIndexRed = joinIndex[0]-1;
|
||||
int joinIndexBlue = joinIndex[1]-1;
|
||||
for(List<MemberInfo> memberOfOneTeam : memberOfTeam){
|
||||
MemberInfo memberInfoAttack = memberOfOneTeam.get(joinIndexRed);
|
||||
MemberInfo memberInfoDef = memberOfOneTeam.get(joinIndexBlue);
|
||||
int attackUid = memberInfoAttack.getUid();
|
||||
int defUid = memberInfoDef.getUid();
|
||||
int type = memberInfoAttack.getType() + memberInfoDef.getType();
|
||||
if(memberInfoAttack.getType() == 1){
|
||||
attackUid = memberInfoDef.getUid();
|
||||
defUid = memberInfoAttack.getUid();
|
||||
RedisUtil.getInstence().del(RedisUtil.getInstence().getKey(RedisKey.CHAMPION_CUR_JOIN_IDS,""));
|
||||
Map<String,ArenaRecord> arenaRecordMap = new HashMap<>();
|
||||
List<String> arenaRecordIds = new ArrayList<>();
|
||||
if(schedule == 1){
|
||||
List<int[]> joinIndexs = STableManager.getFigureConfig(CommonStaticConfig.class).getMatrixforGroupInfo().get(roundTimes);
|
||||
Map<Integer, MemberInfo> joinMembers = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_JOIN, "", Integer.class, MemberInfo.class);
|
||||
if(joinIndexs != null){
|
||||
Map<Integer, List<Integer>> memberOfTeam =getMermberTeam();
|
||||
RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_CUR_JOIN_IDS, "", Integer.class, List.class);
|
||||
for(int[] joinIndex : joinIndexs){
|
||||
int joinIndexRed = joinIndex[0]-1;
|
||||
int joinIndexBlue = joinIndex[1]-1;
|
||||
for(List<Integer> memberOfOneTeam : memberOfTeam.values()){
|
||||
MemberInfo memberInfoAttack =joinMembers.get(memberOfOneTeam.get(joinIndexRed));
|
||||
MemberInfo memberInfoDef =joinMembers.get(memberOfOneTeam.get(joinIndexBlue));
|
||||
int attackUid = memberInfoAttack.getUid();
|
||||
int defUid = memberInfoDef.getUid();
|
||||
int type = memberInfoAttack.getType() + memberInfoDef.getType();
|
||||
if(memberInfoAttack.getType() == 1){
|
||||
attackUid = memberInfoDef.getUid();
|
||||
defUid = memberInfoAttack.getUid();
|
||||
}
|
||||
ArenaRecord arenaRecord = new ArenaRecord();
|
||||
arenaRecord.setId(KeyGenUtils.produceIdByModule(UUIDEnum.ARENARECORD,memberInfoAttack.getUid()));
|
||||
arenaRecord.setAttackId(attackUid);
|
||||
arenaRecord.setDefUid(defUid);
|
||||
arenaRecord.setType(type);
|
||||
arenaRecordMap.put(arenaRecord.getId(),arenaRecord);
|
||||
}
|
||||
ArenaRecord arenaRecord = new ArenaRecord();
|
||||
arenaRecord.setId(KeyGenUtils.produceIdByModule(UUIDEnum.ARENARECORD,memberInfoAttack.getUid()));
|
||||
arenaRecord.setAttackId(attackUid);
|
||||
arenaRecord.setDefUid(defUid);
|
||||
arenaRecord.setType(type);
|
||||
arenaRecordMap.put(arenaRecord.getId(),arenaRecord);
|
||||
curArenaRecordMap.put(arenaRecord.getId(),arenaRecord);
|
||||
}
|
||||
}
|
||||
}else{ //决赛
|
||||
Map<Integer, List> finalmemberOfTeam = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_FINAL_TEAM_INFO, "", Integer.class, List.class);
|
||||
List<MemberInfo> possibleJoin = new ArrayList<>();
|
||||
for(List<MemberInfo> memberOfOneTeam : finalmemberOfTeam.values()){
|
||||
memberOfOneTeam.forEach(memberInfo -> {
|
||||
if(memberInfo.getFinalScore()>0){
|
||||
possibleJoin.add(memberInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
for(int i=0;i<possibleJoin.size();i=i+2){
|
||||
MemberInfo memberInfoAttack = possibleJoin.get(i);
|
||||
MemberInfo memberInfoDef = possibleJoin.get(i+1);
|
||||
int attackUid = memberInfoAttack.getUid();
|
||||
int defUid = memberInfoDef.getUid();
|
||||
int type = memberInfoAttack.getType() + memberInfoDef.getType();
|
||||
if(memberInfoAttack.getType() == 1){
|
||||
attackUid = memberInfoDef.getUid();
|
||||
defUid = memberInfoAttack.getUid();
|
||||
}
|
||||
ArenaRecord arenaRecord = new ArenaRecord();
|
||||
arenaRecord.setId(KeyGenUtils.produceIdByModule(UUIDEnum.ARENARECORD,memberInfoAttack.getUid()));
|
||||
arenaRecord.setAttackId(attackUid);
|
||||
arenaRecord.setDefUid(defUid);
|
||||
arenaRecord.setType(type);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
public static List<ArenaRecord> getCurArenaRecordList(){
|
||||
List<String> curArenaRecordIds = RedisUtil.getInstence().lGet(RedisKey.CHAMPION_CUR_JOIN_IDS, "", 0, -1);
|
||||
List<Object> ids = new ArrayList<>(curArenaRecordIds);
|
||||
return RedisUtil.getInstence().getMapEntrys(RedisKey.CHAMPION_ARENA_RECORD, "", ids, ArenaRecord.class);
|
||||
}
|
||||
|
||||
public static String getSelectIdForRedis(){
|
||||
String key = RedisUtil.getInstence().getKey(RedisKey.CHAMPION_CUR_BETID, "");
|
||||
return RedisUtil.getInstence().get(key).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 选出每组前n名参与决赛人,重置他们分数为100分,进行同台竞技
|
||||
*
|
||||
*/
|
||||
public static void selectToJoinFinal(){
|
||||
int knockoutGroup = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting().getKnockoutGroup();
|
||||
int trialsGroupWinner = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting().getTrialsGroupWinner();
|
||||
Map<Integer, List<Integer>> mermberTeam = getMermberTeam();
|
||||
List<MemberInfo> canJoinFinal = new ArrayList<>(trialsGroupWinner*mermberTeam.size());
|
||||
Set<ZSetOperations.TypedTuple<String>> arenaRankInfoForChampion= new HashSet<>();
|
||||
Map<Integer, MemberInfo> joinMembers = RedisUtil.getInstence().getMapValues(RedisKey.CHAMPION_JOIN, "", Integer.class, MemberInfo.class);
|
||||
for(List<Integer> memberOfOneTeam : mermberTeam.values()){
|
||||
Collections.sort(memberOfOneTeam, new Comparator<Integer>() {
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
return joinMembers.get(o2).getScore() -joinMembers.get(o1).getScore();
|
||||
}
|
||||
});
|
||||
for(int i=0;i<trialsGroupWinner;i++){
|
||||
MemberInfo memberInfo =joinMembers.get(memberOfOneTeam.get(i));
|
||||
memberInfo.setFinalScore(100);
|
||||
canJoinFinal.add(memberInfo);
|
||||
arenaRankInfoForChampion.add(new DefaultTypedTuple(Integer.toString(memberInfo.getUid()),100D));
|
||||
}
|
||||
}
|
||||
RedisUtil.getInstence().updateZsetScores(RedisKey.CHAMPION_RANK,"",arenaRankInfoForChampion);
|
||||
List<List<Integer>> finalmemberOfTeam = getMemberOfTeamOfGroup(canJoinFinal,knockoutGroup);
|
||||
for(int i=0;i<finalmemberOfTeam.size();i++){
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.CHAMPION_FINAL_TEAM_INFO, "",Integer.toString(i),finalmemberOfTeam.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -508,16 +809,6 @@ public class ChampionshipLogic {
|
|||
}, new LinkedList<>(OnlineUserManager.sessionMap.keySet()),1);
|
||||
snapPlayFightInfo();
|
||||
selectBetTeam();
|
||||
selectToBattle();
|
||||
|
||||
//每隔ns向前端广播赔率
|
||||
CommonProto.ChampionBetInfo betOdds = getBetOdds();
|
||||
ArenaInfoProto.ChampionBetBroadIndication build = ArenaInfoProto.ChampionBetBroadIndication.newBuilder().setChampionBetInfo(betOdds).build();
|
||||
OnlineUserManager.sessionMap.forEach((id,session)->{
|
||||
MessageUtil.sendIndicationMessage(session,1, MessageTypeProto.MessageType.CHAMPION_BET_BROAD_INDICATION_VALUE,build,true);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -530,60 +821,19 @@ public class ChampionshipLogic {
|
|||
List<CommonProto.ArenaEnemy> arenaRankMemberInfo = new ArrayList<>(20);
|
||||
|
||||
int rankEndLine = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting().getChampionshipPlayer();
|
||||
Map<Integer, SArenaRobotConfig> robotConfigMap = STableManager.getConfig(SArenaRobotConfig.class);
|
||||
|
||||
if(end<rankEndLine) {
|
||||
Set<ZSetOperations.TypedTuple<String>> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.CHAMPION_BET_RANK, Integer.toString(1), start, end);
|
||||
for (ZSetOperations.TypedTuple<String> item : arenaRankInfo) {
|
||||
String value = item.getValue();
|
||||
int score = item.getScore().intValue();
|
||||
int uid = Integer.parseInt(value);
|
||||
if(robotConfigMap.containsKey(uid)){
|
||||
SArenaRobotConfig sArenaRobotConfig = robotConfigMap.get(uid);
|
||||
CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(sArenaRobotConfig.getHeroList()).build();
|
||||
CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder()
|
||||
.setUid(uid)
|
||||
.setLevel(sArenaRobotConfig.getRobotLevel())
|
||||
.setName(sArenaRobotConfig.getRobotName())
|
||||
.setScore(score)
|
||||
.setHead(0)
|
||||
.setRank(++start)
|
||||
.setTotalForce(sArenaRobotConfig.getTotalForce())
|
||||
.setHeadFrame(0)
|
||||
.build();
|
||||
arenaRankMemberInfo.add(CommonProto.ArenaEnemy.newBuilder()
|
||||
.setPersonInfo(personInfoBuild)
|
||||
.setTeam(teamBuild)
|
||||
.build());
|
||||
start++;
|
||||
CommonProto.ArenaEnemy enemyInfo = getEnemyInfo(uid, start);
|
||||
if(enemyInfo == null){
|
||||
start--;
|
||||
continue;
|
||||
}
|
||||
|
||||
User user = UserManager.getUser(uid,true);
|
||||
if (null == user) {
|
||||
continue;
|
||||
}
|
||||
int totalForce = HeroLogic.getInstance().calTeamTotalForce(user, GlobalsDef.TEAM_ARENA_DEFENSE, false);
|
||||
List<TeamPosHeroInfo> teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(GlobalsDef.TEAM_ARENA_DEFENSE);
|
||||
Map<String, Hero> heroMap = user.getHeroManager().getHeroMap();
|
||||
List<Integer> heroTids = new ArrayList<>(teamPosHeroInfoList.size());
|
||||
for (TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfoList) {
|
||||
heroTids.add(heroMap.get(teamPosHeroInfo.getHeroId()).getTemplateId());
|
||||
}
|
||||
CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(heroTids).build();
|
||||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||
CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder()
|
||||
.setUid(uid)
|
||||
.setLevel(playerInfoManager.getLevel())
|
||||
.setName(playerInfoManager.getNickName())
|
||||
.setScore(score)
|
||||
.setHead(playerInfoManager.getHead())
|
||||
.setRank(++start)
|
||||
.setTotalForce(totalForce)
|
||||
.setHeadFrame(playerInfoManager.getHeadFrame())
|
||||
.build();
|
||||
arenaRankMemberInfo.add(CommonProto.ArenaEnemy.newBuilder()
|
||||
.setPersonInfo(personInfoBuild)
|
||||
.setTeam(teamBuild)
|
||||
.build());
|
||||
arenaRankMemberInfo.add(enemyInfo);
|
||||
}
|
||||
}
|
||||
int uid = session.getUid();
|
||||
|
|
@ -604,8 +854,56 @@ public class ChampionshipLogic {
|
|||
|
||||
}
|
||||
|
||||
private static CommonProto.ArenaEnemy getEnemyInfo(int uid,int start) throws Exception {
|
||||
Map<Integer, SArenaRobotConfig> robotConfigMap = STableManager.getConfig(SArenaRobotConfig.class);
|
||||
if(robotConfigMap.containsKey(uid)){
|
||||
SArenaRobotConfig sArenaRobotConfig = robotConfigMap.get(uid);
|
||||
CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(sArenaRobotConfig.getHeroList()).build();
|
||||
CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder()
|
||||
.setUid(uid)
|
||||
.setLevel(sArenaRobotConfig.getRobotLevel())
|
||||
.setName(sArenaRobotConfig.getRobotName())
|
||||
.setHead(0)
|
||||
.setRank(start)
|
||||
.setTotalForce(sArenaRobotConfig.getTotalForce())
|
||||
.setHeadFrame(0)
|
||||
.build();
|
||||
return CommonProto.ArenaEnemy.newBuilder()
|
||||
.setPersonInfo(personInfoBuild)
|
||||
.setTeam(teamBuild)
|
||||
.build();
|
||||
}
|
||||
|
||||
User user = UserManager.getUser(uid,true);
|
||||
if (null == user) {
|
||||
return null;
|
||||
}
|
||||
int totalForce = HeroLogic.getInstance().calTeamTotalForce(user, GlobalsDef.TEAM_ARENA_DEFENSE, false);
|
||||
List<TeamPosHeroInfo> teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(GlobalsDef.TEAM_ARENA_DEFENSE);
|
||||
Map<String, Hero> heroMap = user.getHeroManager().getHeroMap();
|
||||
List<Integer> heroTids = new ArrayList<>(teamPosHeroInfoList.size());
|
||||
for (TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfoList) {
|
||||
heroTids.add(heroMap.get(teamPosHeroInfo.getHeroId()).getTemplateId());
|
||||
}
|
||||
CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(heroTids).build();
|
||||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||
CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder()
|
||||
.setUid(uid)
|
||||
.setLevel(playerInfoManager.getLevel())
|
||||
.setName(playerInfoManager.getNickName())
|
||||
.setHead(playerInfoManager.getHead())
|
||||
.setRank(start)
|
||||
.setTotalForce(totalForce)
|
||||
.setHeadFrame(playerInfoManager.getHeadFrame())
|
||||
.build();
|
||||
return CommonProto.ArenaEnemy.newBuilder()
|
||||
.setPersonInfo(personInfoBuild)
|
||||
.setTeam(teamBuild)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static void minuteCheck() throws Exception {
|
||||
/* TimeControllerOfFunction timeControllerOfFunction = GlobalDataManaager.getInstance().getTimeControllerOfFunctionByFunctinoId(1);
|
||||
TimeControllerOfFunction timeControllerOfFunction = GlobalDataManaager.getInstance().getTimeControllerOfFunctionByFunctinoType(FunctionIdEnum.TopBattle);
|
||||
if( null == timeControllerOfFunction){
|
||||
progress = -1;
|
||||
return;
|
||||
|
|
@ -613,24 +911,69 @@ 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()*60*1000;
|
||||
int progressTmp=(int)((now - startTime)%duration +1);
|
||||
long round = (now - startTime) / duration + 1;
|
||||
int duration = sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime() + sChampionshipSetting.getBattleTime();
|
||||
int progressState=getProgress((int)((now - startTime)/1000%duration +1));
|
||||
long round = (now - startTime) /1000/ duration + 1;
|
||||
roundTimes = (int) round;
|
||||
long diff = round - sChampionshipSetting.getTrialsGroup() * (sChampionshipSetting.getTrialsGroup() - 1) / 2;
|
||||
long diff = round - (sChampionshipSetting.getTrialsGroup() - 1);
|
||||
int progressTmp;
|
||||
|
||||
if(diff<0){ //选拔赛
|
||||
progress =10 + progressTmp;
|
||||
progressTmp =9 + progressState;
|
||||
schedule=1;
|
||||
}else {//决赛
|
||||
int totalWiner =sChampionshipSetting.getChampionshipPlayer()/ sChampionshipSetting.getTrialsGroup() * sChampionshipSetting.getTrialsGroupWinner();
|
||||
int roundTimes = (int) (totalWiner / (diff + 1));
|
||||
progress =roundTimes*100 + progressTmp;
|
||||
int roundTimes = totalWiner>>diff;
|
||||
if(roundTimes<2){
|
||||
return;
|
||||
}
|
||||
progressTmp =roundTimes*100 + progressState;
|
||||
if(schedule==1){ // 刚开始进入决赛,选拔出选手
|
||||
selectToJoinFinal();
|
||||
}
|
||||
schedule=2;
|
||||
}
|
||||
|
||||
if(progress%3==2){ //竞猜阶段
|
||||
switchBet();
|
||||
}else if(progress%3==0){ //比赛阶段
|
||||
if(progressTmp == progress){
|
||||
return;
|
||||
}
|
||||
endTime = (int)( startTime/1000 + round*duration + getDuratimeByProgressState(progressState));
|
||||
progress = progressTmp;
|
||||
RedisUtil.getInstence().set(RedisUtil.getInstence().getKey(RedisKey.CHAMPION_PROGRESS,""),Integer.toString(progress));
|
||||
|
||||
}*/
|
||||
if(progress%3==0){
|
||||
selectToBattle();
|
||||
}
|
||||
if(progress%3==1){ //竞猜阶段 后台自动运行战斗
|
||||
switchBet();
|
||||
}else if(progress%3==2){ //比赛阶段
|
||||
//等待玩家数据分数入redis
|
||||
scoreToRedis();
|
||||
}
|
||||
}
|
||||
|
||||
private static int getDuratimeByProgressState(int progressState){
|
||||
SChampionshipSetting sChampionshipSetting = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting();
|
||||
if(progressState == 0){
|
||||
return sChampionshipSetting.getPrepareTime();
|
||||
}
|
||||
if(progressState == 1){
|
||||
return sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime();
|
||||
}
|
||||
return sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime() + sChampionshipSetting.getBattleTime();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static int getProgress(int progressTmp){
|
||||
SChampionshipSetting sChampionshipSetting = STableManager.getFigureConfig(CommonStaticConfig.class).getsChampionshipSetting();
|
||||
if(progressTmp<sChampionshipSetting.getPrepareTime()){
|
||||
return 0;// 准备
|
||||
}
|
||||
if(progressTmp>=sChampionshipSetting.getPrepareTime() && progressTmp<sChampionshipSetting.getPrepareTime() + sChampionshipSetting.getGuessTime()){
|
||||
return 1;//竞猜
|
||||
}
|
||||
return 2;//比赛
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,12 @@ public class ArenaRecord {
|
|||
|
||||
private int createTime;
|
||||
|
||||
private int fightResult = -1; //表示进行中
|
||||
private int fightResult = -2; //表示进行中
|
||||
|
||||
private int defUid;
|
||||
|
||||
private int roundTims; //决赛阶段赋值 十位表示队伍id 个位表示第几轮
|
||||
|
||||
public ArenaRecord(){}
|
||||
|
||||
public int getAttackId() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ljsd.jieling.logic.fight;
|
||||
|
||||
import com.ljsd.jieling.logic.championship.ChampionshipLogic;
|
||||
import com.ljsd.jieling.logic.dao.ArenaRecord;
|
||||
import com.ljsd.jieling.logic.fight.result.FightResult;
|
||||
|
||||
|
|
@ -7,7 +8,15 @@ public class AreFightPro implements EndFightProcessor {
|
|||
ArenaRecord arenaRecord;
|
||||
@Override
|
||||
public void endfightProcess(FightResult fightResult) {
|
||||
int result = fightResult.getCheckResult()[0];
|
||||
arenaRecord.setFightResult(fightResult.getCheckResult()[0]);
|
||||
int winnerUid = arenaRecord.getAttackId();
|
||||
int failerUid = arenaRecord.getDefUid();
|
||||
if(result == 0){
|
||||
winnerUid = arenaRecord.getDefUid();
|
||||
failerUid = arenaRecord.getAttackId();
|
||||
}
|
||||
ChampionshipLogic.setScoreForSuccess(winnerUid,failerUid);
|
||||
}
|
||||
|
||||
public ArenaRecord getArenaRecord() {
|
||||
|
|
|
|||
|
|
@ -5,9 +5,12 @@ import com.ljsd.jieling.thread.ThreadManager;
|
|||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
|
||||
public class FightDispatcher {
|
||||
private static AtomicLong fightId = new AtomicLong(1);
|
||||
|
||||
|
||||
public static FightResult dispatcher(FightEvent fightEvent) throws Exception {
|
||||
|
|
@ -16,22 +19,20 @@ public class FightDispatcher {
|
|||
}
|
||||
|
||||
//gs-fight
|
||||
public static long dispatcherAsync(FightEvent fightEvent) throws Exception {
|
||||
long fightId = 0;
|
||||
public static void dispatcherAsync(FightEvent fightEvent,long id) throws Exception {
|
||||
ThreadManager.getScheduledExecutor().submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
GameFightType fightType = fightEvent.getFightType();
|
||||
FightResult fightResult = fightType.getFightEventProcesor().process(fightEvent);
|
||||
fightResult.setId(id);
|
||||
FightDispatcher.dispatcherAsyncToGs(fightResult);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
return fightId;
|
||||
|
||||
}
|
||||
|
||||
private static Map<Long,EndFightProcessor> map = new ConcurrentHashMap<>();
|
||||
|
|
@ -42,6 +43,10 @@ public class FightDispatcher {
|
|||
map.get(fightResult.getId()).endfightProcess(fightResult);
|
||||
}
|
||||
|
||||
public static long getFIghtId(){
|
||||
return fightId.getAndIncrement();
|
||||
}
|
||||
|
||||
public static Map<Long, EndFightProcessor> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import com.ljsd.jieling.logic.GlobalDataManaager;
|
|||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||
import com.ljsd.jieling.logic.arena.ArenaLogic;
|
||||
import com.ljsd.jieling.logic.championship.ChampionshipLogic;
|
||||
import com.ljsd.jieling.logic.family.GuildFightLogic;
|
||||
import com.ljsd.jieling.logic.fight.CombatLogic;
|
||||
import com.ljsd.jieling.logic.mail.MailLogic;
|
||||
|
|
@ -68,6 +69,7 @@ public class MinuteTask extends Thread {
|
|||
CoreLogic.getInstance().checkCoreCdk();
|
||||
BuyGoodsLogic.minuteCheckReharge();
|
||||
RedisUtil.getInstence().set(RedisKey.ONLINE_NUM+RedisKey.Delimiter_colon+GameApplication.serverId, String.valueOf(OnlineUserManager.sessionMap.entrySet().size()));
|
||||
ChampionshipLogic.minuteCheck();
|
||||
LOGGER.info("MinuteTask end...");
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("e",e);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
#server info
|
||||
server.id = 10215
|
||||
server.id = 20215
|
||||
server.openTime = 20190101000101
|
||||
server.num = 1
|
||||
server.debug = true
|
||||
|
||||
server.guildFight = false
|
||||
|
||||
# redis config
|
||||
# Redis数据库索引(默认为0)
|
||||
spring.redis.database=1
|
||||
spring.redis.database=0
|
||||
#spring.redis.database=2
|
||||
# Redis服务器地址
|
||||
spring.redis.host=60.1.1.21
|
||||
|
|
@ -32,7 +33,7 @@ spring.redis.expireTime = -1
|
|||
#spring.data.mongodb.uri = mongodb://mongouser:ysj#2017#ljsd@111.231.54.96:27017/ysj_wx_1
|
||||
#spring.data.mongodb2.uri = mongodb://mongouser:ysj#2017#ljsd@111.231.54.96:27017/develop_ysj_wx_1
|
||||
#mongodb2 develop
|
||||
spring.data.mongodb.uri = mongodb://60.1.1.14:27017/jieling_10215
|
||||
spring.data.mongodb.uri = mongodb://60.1.1.14:27017/jieling_20215
|
||||
spring.data.mongodbcore.uri = mongodb://60.1.1.14:27017/jl_core
|
||||
#spring.data.mongodb.uri = mongodb://60.1.1.14:27017/jieling_10212
|
||||
mongodb.options.maxWaitTime = 120000
|
||||
|
|
@ -45,7 +46,7 @@ mongodb.options.maxConnectionIdleTime = 1000
|
|||
|
||||
|
||||
# netty config
|
||||
netty.tcpPort = 26080
|
||||
netty.tcpPort = 16080
|
||||
netty.chatTcpPort = 20001
|
||||
netty.logintcpPort = 18091
|
||||
netty.udpPort = 18092
|
||||
|
|
|
|||
|
|
@ -100,4 +100,8 @@ public class SChampionshipSetting implements BaseConfig {
|
|||
public int getGuessNum() {
|
||||
return guessNum;
|
||||
}
|
||||
|
||||
public int getKnockoutGroup() {
|
||||
return knockoutGroup;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue