战斗校验逻辑优化
parent
b760741462
commit
6368008837
|
|
@ -86,76 +86,86 @@ public class CheckFight {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单线程执行每次用时50ms,目前支持并发100以内,再大用线程池异步处理
|
* 单线程执行每次用时50ms,目前支持并发100以内,再大用线程池异步处理
|
||||||
* http://www.luaj.org/luaj/3.0/examples/jse/SampleMultiThreaded.java
|
|
||||||
* @param seed
|
|
||||||
* @param fightData
|
|
||||||
* @param optionData
|
|
||||||
* @return {战斗结果, 战斗伤害/战斗时间,单位1剩余血量,单位2剩余血量,单位3剩余血量,单位4剩余血量,单位5剩余血量}
|
* @return {战斗结果, 战斗伤害/战斗时间,单位1剩余血量,单位2剩余血量,单位3剩余血量,单位4剩余血量,单位5剩余血量}
|
||||||
*/
|
*/
|
||||||
public long[] checkFight(int seed,int maxTime, LuaValue fightData, LuaValue optionData,FightType fightType){
|
/**
|
||||||
|
* 执行战斗检查并返回结果。
|
||||||
|
* @param seed 随机数种子
|
||||||
|
* @param maxTime 最大时间或轮数
|
||||||
|
* @param fightData 战斗数据
|
||||||
|
* @param optionData 选项数据
|
||||||
|
* @param fightType 战斗类型
|
||||||
|
* @return 返回一个长整型数组,包含:战斗结果,战斗时间,以及各单位剩余血量等信息。
|
||||||
|
*/
|
||||||
|
public long[] checkFight(int seed, int maxTime, LuaValue fightData, LuaValue optionData, FightType fightType) {
|
||||||
LuaValue transCoderObj = this.getTransCoderObj();
|
LuaValue transCoderObj = this.getTransCoderObj();
|
||||||
LuaValue func = transCoderObj.get(LuaValue.valueOf("Execute"));
|
LuaValue result = callLuaValue(seed, maxTime, fightData, optionData, fightType, transCoderObj);
|
||||||
LuaValue args = new LuaTable();
|
long[] resultCache = new long[9]; // 假定最多有8个单位的剩余血量信息
|
||||||
args.set("seed",seed);
|
|
||||||
//todo type
|
resultCache[0] = result.get("result").tolong();
|
||||||
args.set("type",fightType.getType());
|
resultCache[1] = result.get("duration").tolong();
|
||||||
args.set("maxRound",maxTime);
|
LOGGER.info("Lua check test fight result: {} Length: {}", resultCache[0], result.length());
|
||||||
LuaValue result = func.call(args,fightData,optionData);
|
|
||||||
long[] resultCache = new long[9];//对方阵容走配置 Todo 后面结构走配置
|
for (int i = 1; i <= result.length() && i < 8; i++) {
|
||||||
resultCache[0]= result.get("result").tolong();
|
long remainingHealth = result.rawget(i).tolong();
|
||||||
resultCache[1]= result.get("duration").tolong();
|
resultCache[i + 1] = remainingHealth;
|
||||||
LOGGER.info(" lua check test fight result : {} {}", resultCache[0] , result.length());
|
LOGGER.info("{} --> 单位剩余血量: {}", i, remainingHealth);
|
||||||
for (int i = 1; i <= result.length(); i++) {
|
|
||||||
long talon = result.rawget(i).tolong();
|
|
||||||
if (talon > 0) {
|
|
||||||
resultCache[i + 1] = Math.min(Long.MAX_VALUE, talon);
|
|
||||||
} else {
|
|
||||||
resultCache[i + 1] = Math.max(Long.MIN_VALUE, talon);
|
|
||||||
}
|
|
||||||
resultCache[i + 1] = result.rawget(i).tolong();
|
|
||||||
LOGGER.info(i + " --> 单位剩余血量 : " + resultCache[i + 1]);
|
|
||||||
}
|
}
|
||||||
resultCache[8]= result.get("curRound").tolong();
|
|
||||||
|
resultCache[8] = result.get("curRound").tolong();
|
||||||
return resultCache;
|
return resultCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long[][] checkHardStageFight(int seed,int maxTime, LuaValue fightData, LuaValue optionData,FightType fightType){
|
public long[][] checkHardStageFight(int seed, int maxTime, LuaValue fightData, LuaValue optionData, FightType fightType) {
|
||||||
LuaValue transCoderObj = this.getTransCoderObj();
|
LuaValue transCoderObj = this.getTransCoderObj();
|
||||||
long[][] resultX = new long[2][];
|
long[][] resultX = new long[2][];
|
||||||
LuaValue func = transCoderObj.get(LuaValue.valueOf("Execute"));
|
LuaValue result = callLuaValue(seed, maxTime, fightData, optionData, fightType, transCoderObj);
|
||||||
LuaValue args = new LuaTable();
|
|
||||||
args.set("seed",seed);
|
int status = 0;
|
||||||
//todo type
|
int duration = 0;
|
||||||
args.set("type",fightType.getType());
|
LuaValue resultVal = result.get("result");
|
||||||
args.set("maxRound",maxTime);
|
if (!resultVal.isnil()) status = resultVal.toint();
|
||||||
LuaValue result = func.call( args,fightData,optionData);
|
|
||||||
int status = result.get("result").toint();
|
resultVal = result.get("duration");
|
||||||
int duration = result.get("duration").toint();
|
if (!resultVal.isnil()) duration = resultVal.toint();
|
||||||
|
|
||||||
long[] starRecord = new long[6];
|
long[] starRecord = new long[6];
|
||||||
for(int x = 1; x <= result.get("starRecord").length() ; x++){
|
LuaValue starRecordVal = result.get("starRecord");
|
||||||
long s = result.get("starRecord").rawget(x).tolong();
|
if (!starRecordVal.isnil()) {
|
||||||
starRecord[x-1] = s;
|
for (int x = 1; x <= starRecordVal.length() && x <= starRecord.length; x++) {
|
||||||
|
LuaValue val = starRecordVal.rawget(x);
|
||||||
|
if (!val.isnil()) {
|
||||||
|
starRecord[x - 1] = val.tolong();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long[] resultCache = new long[8];//对方阵容走配置 Todo 后面结构走配置
|
long[] resultCache = new long[8];
|
||||||
resultCache[0]= (long) status;
|
resultCache[0] = status;
|
||||||
resultCache[1]= (long) duration;
|
resultCache[1] = duration;
|
||||||
LOGGER.info(" lua check test fight result : {} {}", resultCache[0] , result.length());
|
|
||||||
for (int i = 1; i <= result.length(); i++) {
|
for (int i = 2; i < resultCache.length && i <= result.length(); i++) {
|
||||||
long tolong = result.rawget(i).tolong();
|
LuaValue val = result.rawget(i);
|
||||||
if(tolong>0){
|
if (!val.isnil()) {
|
||||||
resultCache[i+1]= Math.min((long) Integer.MAX_VALUE,tolong);
|
resultCache[i] = val.toint();
|
||||||
}else {
|
|
||||||
resultCache[i+1]= Math.max((long) Integer.MIN_VALUE,tolong);
|
|
||||||
}
|
}
|
||||||
resultCache[i+1] = (long) result.rawget(i).toint();
|
LOGGER.info("{} --> 单位剩余血量 : {}", i, resultCache[i]);
|
||||||
LOGGER.info(i+" --> 单位剩余血量 : "+ resultCache[i+1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resultX[0] = resultCache;
|
resultX[0] = resultCache;
|
||||||
resultX[1] = starRecord;
|
resultX[1] = starRecord;
|
||||||
return resultX;
|
return resultX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LuaValue callLuaValue(int seed, int maxTime, LuaValue fightData, LuaValue optionData, FightType fightType, LuaValue transCoderObj) {
|
||||||
|
LuaValue func = transCoderObj.get(LuaValue.valueOf("Execute"));
|
||||||
|
LuaValue args = new LuaTable();
|
||||||
|
args.set("seed", seed);
|
||||||
|
args.set("type", fightType.getType());
|
||||||
|
args.set("maxRound", maxTime);
|
||||||
|
return func.call(args, fightData, optionData);
|
||||||
|
}
|
||||||
|
|
||||||
public LuaValue getTransCoderObj(){
|
public LuaValue getTransCoderObj(){
|
||||||
LuaValue transCoderObj = localTransCoderObj.get();
|
LuaValue transCoderObj = localTransCoderObj.get();
|
||||||
if(transCoderObj == null||localVersion.get()!=hotFixVersion.get()){
|
if(transCoderObj == null||localVersion.get()!=hotFixVersion.get()){
|
||||||
|
|
@ -174,12 +184,4 @@ public class CheckFight {
|
||||||
return transCoderObj;
|
return transCoderObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.ljsd.jieling.logic.dao;
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
|
||||||
import com.ljsd.GameApplication;
|
import com.ljsd.GameApplication;
|
||||||
import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
|
import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
|
||||||
import com.ljsd.jieling.core.GlobalsDef;
|
import com.ljsd.jieling.core.GlobalsDef;
|
||||||
|
|
@ -35,7 +34,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class UserManager {
|
public class UserManager {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue