miduo_server/luafight/FightDataUtil.java

586 lines
24 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.ljsd.jieling.util;
import rpc.protocols.CommonProto;
import config.*;
import manager.STableManager;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import util.StringUtil;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class FightDataUtil {
/**
* 组装操作数据
*
* @param data
* @return
*/
public static LuaValue getOptionData(String data) {
LuaValue LuaTable = new LuaTable();
LuaTable.set("uid",data);
// LuaTable.set("enemyData", getEnemyData(monsterTeamList));
//
// if (data.equals("") || data==null){
// return new LuaTable();
// }
// 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 LuaTable;
}
public static LuaValue getFinalFightData(CommonProto.FightTeamInfo heroTeam, List<CommonProto.FightTeamInfo> monsterTeamList) {
LuaValue LuaTable = new LuaTable();
LuaTable.set("playerData", getPlayerData(heroTeam,0));
LuaTable.set("enemyData", getEnemyData(monsterTeamList));
return LuaTable;
}
public static LuaValue getFinalPlayerFightData(CommonProto.FightTeamInfo heroTeam, CommonProto.FightTeamInfo enemyHeroTeam) {
return getFinalPlayerFightData(heroTeam,enemyHeroTeam,false);
}
public static LuaValue getFinalPlayerFightData(CommonProto.FightTeamInfo heroTeam, CommonProto.FightTeamInfo enemyHeroTeam,boolean firstCamp) {
LuaValue LuaTable = new LuaTable();
LuaTable.set("playerData", getPlayerData(heroTeam,0));
LuaValue enemyData = new LuaTable();
enemyData.rawset( 1, getPlayerData(enemyHeroTeam,1,firstCamp));
LuaTable.set("enemyData", enemyData);
return LuaTable;
}
public static LuaValue getEnemyData(List<CommonProto.FightTeamInfo> enemyDataList) {
LuaValue enemyData = new LuaTable();
for (int i = 0; i < enemyDataList.size(); i++) {
enemyData.rawset(i + 1, getMonsterFightUnit(enemyDataList.get(i)));
}
return enemyData;
}
private static LuaValue getMonsterFightUnit(CommonProto.FightTeamInfo data) {
LuaValue enemyData = new LuaTable();
for (int i = 0; i < data.getFightUnitListCount(); i++) {
CommonProto.FightUnitInfo unitInfo = data.getFightUnitList(i);
String[] unitSkill = unitInfo.getUnitSkillIds().trim().split("#");
SMonsterConfig sMonster = STableManager.getConfig(SMonsterConfig.class).get(Integer.parseInt(unitInfo.getUnitId()));
LuaValue unitData = new LuaTable();
unitData.set("roleId", sMonster.getMonsterId());
unitData.set("professionId", sMonster.getProfession());
unitData.set("camp", 1);
unitData.set("type", sMonster.getType());
unitData.set("position",unitInfo.getPosition());
unitData.set("quality", sMonster.getQuality());
unitData.set("element",sMonster.getPropertyName());
unitData.set("skinId",sMonster.getSkinId());
SCHero hero = SCHero.getsCHero().get(sMonster.getMonsterId());
if(hero!=null){
unitData.set("job",hero.getJob());
unitData.set("star",hero.getStar());
}
if (unitSkill.length==1){
unitData.set("skill", getSkill(unitSkill[0],sMonster.getSkinId()));
unitData.set("superSkill", new LuaTable());
unitData.set("passivity", new LuaTable());
}else if (unitSkill.length==2){
unitData.set("skill", getSkill(unitSkill[0],sMonster.getSkinId()));
unitData.set("superSkill", getSkill(unitSkill[1],sMonster.getSkinId()));
unitData.set("passivity", new LuaTable());
}else {
unitData.set("skill", getSkill(unitSkill[0],sMonster.getSkinId()));
unitData.set("superSkill", getSkill(unitSkill[1],sMonster.getSkinId()));
unitData.set("passivity", getPassivity(unitSkill));
}
unitData.set("ai", getMonsterAi(sMonster.getMonsterAi()));
CommonProto.FightUnitInfo fightUnitList = data.getFightUnitList(i);
String property = fightUnitList.getProperty();
unitData.set("property", getMonsterProperty(property));
enemyData.rawset(i+1, unitData);
}
//todo 灵兽技能
enemyData.set("monsterList", getPokemonSkill(data.getPokemonUnitListList(),1));
enemyData.set("teamPassive", new LuaTable());
enemyData.set("teamSkill",new LuaTable());
return enemyData;
}
private static LuaValue getMonsterAi(int[] monsterAIs) {
LuaValue property = new LuaTable();
int index =1;
for(int monsterAI : monsterAIs){
property.rawset(index++, LuaValue.valueOf(monsterAI));
}
return property;
}
private static LuaValue getPassivity(String[] unitSkill) {
LuaValue passivityData = new LuaTable();
int length = unitSkill.length;
if(length<3){
return passivityData;
}
int passivityIndex = 1;
Set<Integer> tempSet = new HashSet<>(8);
for(int i=2;i<length;i++){
int passivityId = Integer.parseInt(unitSkill[i]);
SPassiveSkillLogicConfig sPassiveSkillLogicConfig = SPassiveSkillLogicConfig.getConfig(passivityId);
if(sPassiveSkillLogicConfig.getCoverID()!=0){
tempSet.add(sPassiveSkillLogicConfig.getCoverID());
}
}
for(int i=2;i<length;i++){
LuaValue detail = new LuaTable();
int passivityId = Integer.parseInt(unitSkill[i]);
SPassiveSkillLogicConfig sPassiveSkillLogicConfig = SPassiveSkillLogicConfig.getConfig(passivityId);
if(sPassiveSkillLogicConfig.getEffectiveRange()!=1){
continue;
}
//如果有覆盖的则不添加
if(tempSet.contains(sPassiveSkillLogicConfig.getId())){
continue;
}
detail.rawset(1,LuaValue.valueOf(sPassiveSkillLogicConfig.getId()));
detail.rawset(2, LuaValue.valueOf(sPassiveSkillLogicConfig.getJudge()));
detail.rawset(3, LuaValue.valueOf(sPassiveSkillLogicConfig.getType()));
List<LuaValue> effectList = parseArraayToLuaValues(sPassiveSkillLogicConfig.getValue());
int size = effectList.size();
if (size > 0) {
for (int j = 0; j < size; j++) {
detail.rawset(j + 4, effectList.get(j));
}
}
passivityData.rawset(passivityIndex,detail);
passivityIndex++;
}
return passivityData;
}
private static List<LuaValue> parseArraayToLuaValues(float[] source) {
List<LuaValue> result = new ArrayList<>(source.length);
for(float id : source){
result.add(LuaValue.valueOf(id));
}
return result;
}
/**
* --属性 {等级,生命,最大生命,攻击力,护甲,魔抗,速度,伤害加成系数(%,伤害减免系数(%,命中率(%,闪避率(%,暴击率(%,暴击伤害系数(%,治疗加成系数(%
* -- ,火系伤害加成系数(%,火系伤害减免系数(%,冰系伤害加成系数(%,冰系伤害减免系数(%,雷系伤害加成系数(%,雷系伤害减免系数(%,风系伤害加成系数(%
* -- ,风系伤害减免系数(%,地系伤害加成系数(%,地系伤害减免系数(%,暗系伤害加成系数(%,暗系伤害减免系数(%}
* @return
*/
private static LuaValue getMonsterProperty(String propertyString) {
LuaValue property = new LuaTable();
int index =1;
for(String value : propertyString.split("#")){
property.rawset(index++, LuaValue.valueOf(value));
}
return property;
}
public static LuaValue getPlayerData(CommonProto.FightTeamInfo heroTeam,int position) {
return getPlayerData(heroTeam, position,false);
}
public static LuaValue getPlayerData(CommonProto.FightTeamInfo heroTeam,int position,boolean first) {
LuaValue playerData = new LuaTable();
for (int i = 1; i <= heroTeam.getFightUnitListCount(); i++) {
playerData.rawset(i, getHeroFightUnit(heroTeam.getFightUnitList(i - 1),position));
}
playerData.set("teamSkill",new LuaTable());
playerData.set("teamPassive", getTeamPassive(heroTeam.getTeamPassiveList()));
playerData.set("outData",heroTeam.getSpecialPassive());
// 灵兽技能
playerData.set("monsterList", getPokemonSkill(heroTeam.getPokemonUnitListList(),position));
playerData.set("firstCamp",first?1:0);
return playerData;
}
private static LuaValue getTeamPassive(String pokemonSkill) {
LuaValue passivityData = new LuaTable();
if (StringUtil.isEmpty(pokemonSkill)){
return passivityData;
}
String[] skills = pokemonSkill.trim().split("\\|");
for (int j = 0; j < skills.length; j++) {
if (skills[j].length()>0){
String[] unitSkill = skills[j].split("#");
if(unitSkill.length==0){
continue;
}
LuaValue passivityDataPer= new LuaTable();
for(int i=0;i<unitSkill.length;i++){
LuaValue detail = new LuaTable();
if(StringUtil.isEmpty(unitSkill[i]) || unitSkill[i].equals("0")){
continue;
}
int passivityId = Integer.parseInt(unitSkill[i]);
SPassiveSkillLogicConfig sPassiveSkillLogicConfig = SPassiveSkillLogicConfig.getConfig(passivityId);
detail.rawset(1, LuaValue.valueOf(sPassiveSkillLogicConfig.getType()));
List<LuaValue> effectList = parseArraayToLuaValues(sPassiveSkillLogicConfig.getValue());
int size = effectList.size();
if (size > 0) {
for (int t = 0; t < size; t++) {
detail.rawset(t + 2, effectList.get(t));
}
}
passivityDataPer.rawset(i+1,detail);
}
passivityData.rawset(j+1,passivityDataPer);
}
}
return passivityData;
}
//组装灵兽技能数据 camp=0 自己 1 对方
private static LuaValue getPokemonSkill(List<CommonProto.FightUnitInfo> pokemonUnitList, int camp) {
LuaValue teamSkill = new LuaTable();
if (pokemonUnitList.isEmpty()){
return teamSkill;
}
for (int i = 0; i < pokemonUnitList.size(); i++) {
CommonProto.FightUnitInfo unitInfo=pokemonUnitList.get(i);
String skillId = unitInfo.getUnitSkillIds();
if(skillId.equals("0")|| StringUtil.isEmpty(skillId)){
continue;
}
///100代表是修行技能
if (unitInfo.getPosition()==100){
LuaValue monster = new LuaTable();
monster.set("id",0);
monster.set("star",unitInfo.getStar());
monster.set("teamDamage",unitInfo.getForceScore());
monster.set("camp",camp);
monster.set("position",unitInfo.getPosition());
monster.set("property",getProperty(unitInfo.getProperty()));
String[] skillIdArr = skillId.split("#");
LuaValue skillList= new LuaTable();
for (int k = 0; k < skillIdArr.length; k++) {
SPlayerSkill playerSkillConfig=STableManager.getConfig(SPlayerSkill.class).get(Integer.valueOf(skillIdArr[k]));
LuaValue skill= new LuaTable();
int[] skillIDList = playerSkillConfig.getSkillIDList();
for(int j = 0 ; j <skillIDList.length;j++){
LuaValue oneSkill = new LuaTable();
oneSkill.rawset("triggerId",playerSkillConfig.getReleasePoint()[j]);
int[][] releaseLimit = playerSkillConfig.getReleaseLimit();
LuaValue triggerCondition = new LuaTable();
if(releaseLimit!=null&&releaseLimit.length>0&&releaseLimit[0].length>0){
for(int l = 0 ; l<releaseLimit[j].length;l++){
triggerCondition.rawset(l+1, LuaValue.valueOf(releaseLimit[j][l]));
}
}else{
triggerCondition.rawset(1,LuaValue.valueOf(0));
}
oneSkill.set("effect",getSkill(String.valueOf(skillIDList[j]),0));
oneSkill.set("triggerCondition",triggerCondition);
oneSkill.set("maxCount",playerSkillConfig.getWarEffectCount()[j]);
oneSkill.set("maxRoundCount",playerSkillConfig.getTurnEffectCount()[j]);
skill.rawset(j+1,oneSkill);
}
skillList.rawset(k+1,skill);
}
monster.set("skill",skillList);
teamSkill.rawset(i+1,monster);
}else{
SSpiritAnimalSkill sSpiritAnimalSkill=STableManager.getConfig(SSpiritAnimalSkill.class).get(Integer.valueOf(skillId));
LuaValue monster = new LuaTable();
monster.set("id",sSpiritAnimalSkill.getSpiritAnimalMatch());
monster.set("star",sSpiritAnimalSkill.getStarMatch());
monster.set("camp",camp);
monster.set("position",unitInfo.getPosition());
monster.set("property",getProperty(unitInfo.getProperty()));
String[] skillIdArr = skillId.split("#");
LuaValue skillList= new LuaTable();
for (int k = 0; k < skillIdArr.length; k++) {
LuaValue skill = new LuaTable();
int[] skillIDList = sSpiritAnimalSkill.getSkillIDList();
for (int j = 0; j < skillIDList.length; j++) {
LuaValue oneSkill = new LuaTable();
oneSkill.rawset("triggerId", sSpiritAnimalSkill.getReleasePoint()[j]);
int[][] releaseLimit = sSpiritAnimalSkill.getReleaseLimit();
LuaValue triggerCondition = new LuaTable();
if (releaseLimit != null && releaseLimit.length > 0 && releaseLimit[0].length > 0) {
for (int l = 0; l < releaseLimit[j].length; l++) {
triggerCondition.rawset(l + 1, LuaValue.valueOf(releaseLimit[j][l]));
}
} else {
triggerCondition.rawset(1, LuaValue.valueOf(0));
}
oneSkill.set("effect", getSkill(String.valueOf(skillIDList[j]), 0));
oneSkill.set("triggerCondition", triggerCondition);
oneSkill.set("maxCount", sSpiritAnimalSkill.getWarEffectCount()[j]);
oneSkill.set("maxRoundCount", sSpiritAnimalSkill.getTurnEffectCount()[j]);
skill.rawset(j + 1, oneSkill);
}
skillList.rawset(k+1,skill);
}
monster.set("skill",skillList);
// String[] skillAndPosItem = skillAndPos.split("#");
// if (Integer.parseInt(skillAndPosItem[1])>0){
// teamSkill.rawset(i + 1, getSkill(skillAndPosItem[1],skillAndPosItem[0]));
// }
teamSkill.rawset(i+1,monster);
}
}
return teamSkill;
}
/**
*
* @param data
* @param postion 0:我方 1敌方
* @return
*/
private static LuaValue getHeroFightUnit(CommonProto.FightUnitInfo data,int postion) {
String unitId = data.getUnitId();
String[] skillIds = data.getUnitSkillIds().trim().split("#");
String property = data.getProperty();
SCHero hero = SCHero.getsCHero().get(Integer.parseInt(unitId));
LuaValue unitData = new LuaTable();
unitData.set("roleId", hero.getId());
unitData.set("professionId", hero.getProfession());
unitData.set("camp", postion);
unitData.set("type", 1);
unitData.set("quality", 1);
unitData.set("position", data.getPosition());
unitData.set("element", hero.getPropertyName());
unitData.set("skill", getSkill(skillIds[0],data.getSkinId()));
if(skillIds.length == 1){
unitData.set("superSkill", getSkill(null,data.getSkinId()));
}else {
unitData.set("superSkill", getSkill(skillIds[1],data.getSkinId()));
}
unitData.set("passivity", getPassivity(skillIds));
unitData.set("property", getProperty(property));
unitData.set("skinId",data.getSkinId());
unitData.set("job",hero.getJob());
unitData.set("star",data.getStar());
return unitData;
}
private static LuaValue getProperty(String dataList) {
String[] propertyArr = dataList.trim().split("#");
LuaValue property = new LuaTable();
for (int i = 1; i <= propertyArr.length; i++) {
property.rawset(i, LuaValue.valueOf(Double.parseDouble(propertyArr[i-1])));
}
return property;
}
private static LuaValue getSkill(String skillId,int skinId) {
LuaValue skill = new LuaTable();
if (StringUtil.isEmpty(skillId)){
return skill;
}
SSkillLogicVo sSkillLogicVo = SSkillLogicConfig.getsSkillLogicVo(Integer.parseInt(skillId));
if (sSkillLogicVo != null && sSkillLogicVo.getSkillTargetVoList().size()>0) {
// float cd = sSkillLogicVo.getCd();
// if(args!=null&&args.length>0){
// cd+=Integer.parseInt(args[0]);
// }
skill.rawset(1, LuaValue.valueOf(skillId));
int[][] display =sSkillLogicVo.getSkillDisplay();
int skillDisplay = display[0][0];
for(int[] skillArray:display){
if(skillArray[0]==skinId){
skillDisplay = skillArray[1];
break;
}
}
SCombatControl sCombatControl = STableManager.getConfig(SCombatControl.class).get(skillDisplay);
int KeyFrame = sCombatControl.getKeyFrame();
int SkillDuration = sCombatControl.getSkillDuration();
int SkillNumber = sCombatControl.getSkillNumber();
skill.rawset(2, LuaValue.valueOf(KeyFrame/1000f));
skill.rawset(3, LuaValue.valueOf(SkillDuration/1000f));
skill.rawset(4, LuaValue.valueOf(SkillNumber));
List<LuaValue> effectList = getEffect(sSkillLogicVo);
int size = effectList.size();
if (size > 0) {
for (int i = 0; i < size; i++) {
skill.rawset(i + 5, effectList.get(i));
}
}
}
return skill;
}
private static List<LuaValue> getEffect(SSkillLogicVo sSkillLogicVo) {
List<LuaValue> effectList = new ArrayList<>();
for (SkillTargetVo skillTargetVos : sSkillLogicVo.getSkillTargetVoList()) {
LuaValue effect = new LuaTable();
effect.rawset(1, LuaValue.valueOf(skillTargetVos.getTargetId()));
List<LuaValue> effectValueList = getEffectArgs(skillTargetVos.getEffectVale());
int size = effectValueList.size();
if (size > 0) {
for (int i = 0; i < size; i++) {
effect.rawset(i + 2, effectValueList.get(i));
}
}
effectList.add(effect);
}
return effectList;
}
private static List<LuaValue> getEffectArgs(float[][] effects) {
List<LuaValue> effectValueList = new ArrayList<>();
int sizeY = effects.length;
if (sizeY > 0) {
for (int i = 0; i < sizeY; i++) {
int sizeX = effects[i].length;
LuaValue effectValue = new LuaTable();
for (int j = 0; j < sizeX; j++) {
effectValue.rawset(j + 1, LuaValue.valueOf(effects[i][j]));
}
effectValueList.add(effectValue);
}
}
return effectValueList;
}
//==================================test data =================================
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));
}
playerData.set("teamSkill", new LuaTable());
for (int i = 1; i <= 3; i++) {
playerDataMap.rawset(i, 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));
}
playerData.set("teamSkill", new LuaTable());
return playerData;
}
}