战斗校验

back_recharge
mashiyu 2019-03-12 14:11:16 +08:00
parent 373664aef1
commit ae2bc788dc
2 changed files with 263 additions and 0 deletions

View File

@ -0,0 +1,93 @@
package com.ljsd.jieling.logic.fight;
import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.jse.JsePlatform;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
public class CheckFight {
private static final Logger LOGGER = Logger.getLogger("CheckFightLog");
private Globals globals;
private String luaFileName = null;
private CheckFight(){}
public static class Instance {
public final static CheckFight instance = new CheckFight();
}
public static CheckFight getInstance() {
return CheckFight.Instance.instance;
}
public void init(String path){
try {
luaFileName = getPath(path);
} catch (IOException e) {
e.printStackTrace();
}
globals = JsePlatform.standardGlobals();
}
public static String getPath(String prefixDir, String... filePath) throws IOException {
StringBuilder path = new StringBuilder();
path.append(getRootPath()).append(prefixDir);
for (String p : filePath) {
path.append(File.separator).append(p);
}
return path.toString();
}
public static String getRootPath() throws IOException {
StringBuilder path = new StringBuilder();
if (isWindows()) {// Window 系统
path.append(new File(".").getCanonicalPath()).append(File.separator);
}else {
path.append("../");
}
return path.toString();
}
public static boolean isWindows() {
String osName = System.getProperty("os.name");
return osName.matches("^(?i)Windows.*$");
}
public int[] checkFight(int seed, LuaValue fightData, LuaValue optionData){
LuaValue transCoderObj = globals.loadfile(luaFileName).call();
LuaValue func = transCoderObj.get(LuaValue.valueOf("Execute"));
LuaValue result = func.call(LuaValue.valueOf(932590676),fightData,optionData);
int status = result.get("result").toint();
int[] resultCache = new int[6];
resultCache[0]=status;
LOGGER.info("result : "+ status);
if (status==1){
for (int i = 1; i <= result.length(); i++) {
resultCache[i] = result.rawget(i).toint();
LOGGER.info(i+" --> 单位剩余血量 : "+ resultCache[i]);
}
}
return resultCache;
}
}

View File

@ -0,0 +1,170 @@
package com.ljsd.jieling.util;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import java.util.List;
public class FightDataUtil {
public static LuaValue getFightData(LuaValue playerData, LuaValue enemyData){
LuaValue LuaTable = new LuaTable();
LuaTable.set("playerData",playerData);
LuaTable.set("enemyData",enemyData);
return LuaTable;
}
public static LuaValue getPlayerData(List<LuaValue> unitDataList){
LuaValue playerData = new LuaTable();
for (LuaValue unitData : unitDataList){
playerData.add(unitData);
}
return playerData;
}
public static LuaValue getEnemyData(List<LuaValue> enemyDataList){
LuaValue enemyData = new LuaTable();
for (LuaValue unitData : enemyDataList){
enemyData.add(unitData);
}
return enemyData;
}
public static LuaValue getEnemyListData(List<LuaValue> enemyList){
LuaValue enemyDataList = new LuaTable();
for (LuaValue unitData : enemyList){
enemyDataList.add(unitData);
}
return enemyDataList;
}
public static LuaValue getTestFightData() {
LuaValue LuaTable = new LuaTable();
LuaTable.set("playerData",getTestPlayerData());
LuaTable.set("enemyData",getTestEnemyData());
return LuaTable;
}
private static LuaValue getTestEnemyData() {
LuaValue playerDataMap = new LuaTable();
LuaValue playerData = new LuaTable();
for (int i = 1; i <= 5; i++) {
playerData.rawset(i, getTestFightUnit(false));
}
// for (int i = 1; i <= 3; i++) {
// }
playerDataMap.rawset(1, playerData);
return playerDataMap;
}
private static LuaValue getTestFightUnit(boolean b) {
LuaValue unitData = new LuaTable();
unitData.set("type",1);
unitData.set("quality",1);
unitData.set("skill",getTestSkill(true));
unitData.set("passivity",getTestSkill(false));
if (b){
unitData.set("roleId",10001);
unitData.set("professionId",4);
unitData.set("camp",0);
unitData.set("superSkill",getTestSkill(true));
unitData.set("property",getTestProperty(true));
}else {
unitData.set("roleId",1);
unitData.set("professionId",2);
unitData.set("camp",1);
unitData.set("superSkill",getTestSkill(false));
unitData.set("property",getTestProperty(false));
}
return unitData;
}
public static final Double[] propertyEm = new Double[]{
1d, 144d, 144d, 285d, 152d, 53d, 154d, 0d, 0d, 0.7, 0.35, 0.3, 1.5, 1d, 0d, 0d, 0d, 0d, 0.05, 0d, 0d, 0d, 0d, 0d, 0.05, 0d
};
public static final Double[] propertyHero = new Double[]{
1d, 10000d, 10000d, 169d, 271d, 95d, 176d, 0d, 0d, 0.3, 0.15, 0.3, 1.5, 1d, 0.05, 0d, 0d, 0d, 0d, 0d, 0.05, 0d, 0d, 0d, 0d, 0d
};
private static LuaValue getTestProperty(boolean isHero) {
LuaValue property = new LuaTable();
if (isHero){
for (int i = 1; i <= propertyHero.length; i++) {
property.rawset(i,LuaValue.valueOf(propertyHero[i-1]));
}
}else {
for (int i = 1; i <= propertyEm.length; i++) {
property.rawset(i,LuaValue.valueOf(propertyEm[i-1]));
}
}
return property;
}
//"{1, 10000, 10000, 169, 271, 95, 176, 0, 0, 0.3, 0.15, 0.3, 1.5, 1, 0.05, 0, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0}"
//{ 0.5, {20011, 0.7,{1, 0.1, 1}}}
private static LuaValue getTestSkill(boolean notNull) {
LuaValue skill = new LuaTable();
if (notNull){
skill.rawset(1,LuaValue.valueOf(0.5));
skill.rawset(2,getTestEffect());
}
return skill;
}
private static LuaValue getTestEffect() {
LuaValue effect = new LuaTable();
effect.rawset(1,LuaValue.valueOf(20011));
effect.rawset(2,LuaValue.valueOf(0.7));
effect.rawset(3,getTestEffectArgs());
return effect;
}
private static LuaValue getTestEffectArgs() {
LuaValue effectArgs = new LuaTable();
effectArgs.rawset(1,LuaValue.valueOf(1));
effectArgs.rawset(2,LuaValue.valueOf(0.1));
effectArgs.rawset(3,LuaValue.valueOf(1));
return effectArgs;
}
private static LuaValue getTestPlayerData() {
LuaValue playerData = new LuaTable();
for (int i = 1; i <= 5; i++) {
playerData.rawset(i,getTestFightUnit(true));
}
return playerData;
}
/**
*
* @param data
* @return
*/
public static LuaValue getOptionData(String data) {
String[] tempData1 = data.split("\\|");
LuaValue tableA = new LuaTable();
for (int i = 0; i < tempData1.length; i++) {
String[] tempData2 = tempData1[i].split("#");
LuaValue tableB = new LuaTable();
for (int j = 0; j < tempData2.length; j++) {
tableB.rawset(j+1,LuaValue.valueOf(Integer.parseInt(tempData2[j])));
}
tableA.rawset(i+1,tableB);
}
return tableA;
}
// public static void main(String[] args) throws Exception {
// String optionData = "14#1#0|132#2#3|152#2#5|178#3#2|219#2#4|260#3#1|287#2#2|312#3#5|467#1#1";
// getOptionData(optionData);
// }
}