back_recharge
mashiyu 2019-03-20 10:15:34 +08:00
parent 139a7562a1
commit 333caa887c
5 changed files with 255 additions and 69 deletions

View File

@ -37,7 +37,7 @@ public class SSkillLogicConfig implements BaseConfig {
sSkillLogicVoMap = skillLogicVoMap;
}
public static SSkillLogicVo getsSkillLogicVoMap(int skillId) {
public static SSkillLogicVo getsSkillLogicVo(int skillId) {
return sSkillLogicVoMap.get(skillId);
}

View File

@ -19,6 +19,12 @@ public class RedisKey {
*
*/
public static final String FIGHT = "FIGHT";
/**
*
*/
public static final String FIGHT_SEED = "FIGHT_SEED";
/**
*
*/

View File

@ -2,10 +2,13 @@ package com.ljsd.jieling.handler.map;
import com.ljsd.jieling.config.*;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.handler.map.behavior.BaseBehavior;
import com.ljsd.jieling.handler.mission.Mission;
import com.ljsd.jieling.logic.dao.*;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.fight.CheckFight;
import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
@ -13,6 +16,7 @@ import com.ljsd.jieling.protocols.FightInfoProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.*;
import org.luaj.vm2.LuaValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
@ -544,6 +548,7 @@ public class MapLogic {
public void endFight(ISession session, int result, MessageTypeProto.MessageType messageType, int monsterGroupId) throws Exception {
int uid = session.getUid();
User user = UserManager.getUser(uid);
// String key = RedisKey.getKey(RedisKey.FIGHT, user.getId() , false);
// String value = (String) RedisUtil.getInstence().get(key);
// if (value == null || value.isEmpty()) {
@ -551,6 +556,20 @@ public class MapLogic {
// MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
// return;
// }
List<Integer> pokemonSkill = new ArrayList<>();
List<String> heroList = new ArrayList<>();
List<String> monsterIdList = new ArrayList<>();
String key = RedisKey.getKey(RedisKey.FIGHT_SEED, user.getId() , false);
int seed = (Integer) RedisUtil.getInstence().getAndDelete(key);
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";
LuaValue getFightData = FightDataUtil.getFinalFightData(heroList,pokemonSkill,monsterIdList);
LuaValue getOptionData = FightDataUtil.getOptionData(optionData);
int[] checkResult = CheckFight.getInstance().checkFight(seed, getFightData, getOptionData);
SMonsterGroup sMonsterGroup = SMonsterGroup.getsMonsterGroupMap().get(monsterGroupId);
if (sMonsterGroup == null) {
LOGGER.info("endFight() uid=>{} monsterGroupId=>{} sMonsterGroup == null", uid, monsterGroupId);

View File

@ -77,6 +77,11 @@ public class BehaviorUtil {
MapManager mapManager = user.getMapManager();
String key = RedisKey.getKey(RedisKey.FIGHT, user.getId(), false);
RedisUtil.getInstence().set(key, Integer.toString(groupId), RedisKey.EXPIRE_TIME);
String seed_key = RedisKey.getKey(RedisKey.FIGHT_SEED, user.getId(), false);
RedisUtil.getInstence().set(seed_key, Integer.toString((int)(System.currentTimeMillis()/1000)), RedisKey.EXPIRE_TIME);
Set<String> heroes = mapManager.getHeroes();
List<CommonProto.HeroFightInfo> heroFightInfos = new ArrayList<>(heroes.size());
for (String heroId : heroes) {

View File

@ -1,51 +1,129 @@
package com.ljsd.jieling.util;
import com.ljsd.jieling.config.*;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.logic.STableManager;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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);
/**
*
*
* @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 playerData;
return tableA;
}
public static LuaValue getFinalFightData(List<String> heroList, List<Integer> pokemonSkill, List<String> monsterIdList) {
public static LuaValue getEnemyData(List<LuaValue> enemyDataList){
LuaValue LuaTable = new LuaTable();
LuaTable.set("playerData", getPlayerData(heroList, pokemonSkill));
LuaTable.set("enemyData", getEnemyData(monsterIdList));
return LuaTable;
}
public static LuaValue getEnemyData(List<String> enemyDataList) {
LuaValue enemyData = new LuaTable();
for (LuaValue unitData : enemyDataList){
enemyData.add(unitData);
for (int i = 0; i < enemyDataList.size(); i++) {
enemyData.rawset(i + 1, getMonsterFightUnit(enemyDataList.get(i)));
}
return enemyData;
}
private static LuaValue getMonsterFightUnit(String id) {
public static LuaValue getEnemyListData(List<LuaValue> enemyList){
SMonsterConfig sMonster = SMonsterConfig.getsMonsterConfigMap().get(Integer.parseInt(id));
LuaValue unitData = new LuaTable();
unitData.set("roleId", sMonster.getId());
unitData.set("professionId", sMonster.getProfession());
unitData.set("camp", 1);
unitData.set("type", sMonster.getType());
unitData.set("quality", sMonster.getQuality());
unitData.set("skill", getSkill(Integer.toString(sMonster.getSkillList()[0])));
unitData.set("superSkill", new LuaTable());
unitData.set("passivity", new LuaTable());
unitData.set("property", getMonsterProperty(sMonster));
return unitData;
}
/**
* -- {,,,,,,,%,%,%,%,%,%,%
* -- ,%,%,%,%,%,%,%
* -- ,%,%,%,%,%}
* @param sMonster
* @return
*/
private static LuaValue getMonsterProperty(SMonsterConfig sMonster) {
LuaValue property = new LuaTable();
property.rawset(1, LuaValue.valueOf(sMonster.getLevel()));
property.rawset(2, LuaValue.valueOf(sMonster.getHp()));
property.rawset(3, LuaValue.valueOf(sMonster.getHp()));
property.rawset(4, LuaValue.valueOf(sMonster.getAttack()));
property.rawset(5, LuaValue.valueOf(sMonster.getPhysicalDefence()));
property.rawset(6, LuaValue.valueOf(sMonster.getMagicDefence()));
property.rawset(7, LuaValue.valueOf(sMonster.getSpeed()));
property.rawset(8, LuaValue.valueOf(0));
property.rawset(9, LuaValue.valueOf(0));
property.rawset(10, LuaValue.valueOf(sMonster.getHit()));
property.rawset(11, LuaValue.valueOf(sMonster.getDodge()));
property.rawset(12, LuaValue.valueOf(sMonster.getCritFactor()));
property.rawset(13, LuaValue.valueOf(sMonster.getCritDamageFactor()));
property.rawset(14, LuaValue.valueOf(1));
property.rawset(15, LuaValue.valueOf(sMonster.getDamageBonusFactor()[0]));
property.rawset(16, LuaValue.valueOf(sMonster.getDamageReduceFactor()[0]));
property.rawset(17, LuaValue.valueOf(sMonster.getDamageBonusFactor()[1]));
property.rawset(18, LuaValue.valueOf(sMonster.getDamageReduceFactor()[1]));
property.rawset(19, LuaValue.valueOf(sMonster.getDamageBonusFactor()[2]));
property.rawset(20, LuaValue.valueOf(sMonster.getDamageReduceFactor()[2]));
property.rawset(21, LuaValue.valueOf(sMonster.getDamageBonusFactor()[3]));
property.rawset(22, LuaValue.valueOf(sMonster.getDamageReduceFactor()[3]));
property.rawset(23, LuaValue.valueOf(sMonster.getDamageBonusFactor()[4]));
property.rawset(24, LuaValue.valueOf(sMonster.getDamageReduceFactor()[4]));
property.rawset(25, LuaValue.valueOf(sMonster.getDamageBonusFactor()[5]));
property.rawset(26, LuaValue.valueOf(sMonster.getDamageReduceFactor()[5]));
return property;
}
public static LuaValue getEnemyListData(List<LuaValue> enemyList) {
LuaValue enemyDataList = new LuaTable();
for (LuaValue unitData : enemyList){
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());
LuaTable.set("playerData", getTestPlayerData());
LuaTable.set("enemyData", getTestEnemyData());
return LuaTable;
}
@ -61,26 +139,121 @@ public class FightDataUtil {
return playerDataMap;
}
public static LuaValue getPlayerData(List<String> heroList, List<Integer> pokemonSkill) {
LuaValue playerData = new LuaTable();
for (int i = 1; i <= heroList.size(); i++) {
playerData.rawset(i, getHeroFightUnit(heroList.get(i - 1)));
}
playerData.rawset("teamSkill", getTeamSkill(pokemonSkill));
return playerData;
}
private static LuaValue getTeamSkill(List<Integer> pokemonSkill) {
LuaValue teamSkill = new LuaTable();
for (int i = 0; i < pokemonSkill.size(); i++) {
teamSkill.rawset(i + 1, getSkill(Integer.toString(pokemonSkill.get(i))));
}
return teamSkill;
}
private static LuaValue getHeroFightUnit(String data) {
String[] dataList = data.split("#");
SCHero hero = SCHero.getsCHero().get(dataList[0]);
LuaValue unitData = new LuaTable();
unitData.set("roleId", hero.getId());
unitData.set("professionId", hero.getProfession());
unitData.set("camp", 0);
unitData.set("type", 1);
unitData.set("quality", 1);
unitData.set("skill", getSkill(dataList[1]));
unitData.set("superSkill", getSkill(dataList[2]));
unitData.set("passivity", getTestSkill(false));
unitData.set("property", getProperty(dataList));
return unitData;
}
private static LuaValue getProperty(String[] dataList) {
LuaValue property = new LuaTable();
for (int i = 3; i <= dataList.length - 1; i++) {
property.rawset(i, LuaValue.valueOf(propertyHero[i]));
}
return property;
}
private static LuaValue getSkill(String skillId) {
LuaValue skill = new LuaTable();
SSkillLogicVo sSkillLogicVo = SSkillLogicConfig.getsSkillLogicVo(Integer.valueOf(skillId));
if (sSkillLogicVo != null) {
skill.rawset(1, LuaValue.valueOf(sSkillLogicVo.getCd()));
List<LuaValue> effectList = getEffect(sSkillLogicVo);
int size = effectList.size();
if (size > 0) {
for (int i = 0; i < size; i++) {
skill.rawset(i + 2, 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()));
effect.rawset(2, LuaValue.valueOf(skillTargetVos.getContinuedTime()));
List<LuaValue> effectValueList = getEffectArgs(skillTargetVos.getEffectVale());
int size = effectValueList.size();
if (size > 0) {
for (int i = 0; i < size; i++) {
effect.rawset(i + 3, 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;
}
private static LuaValue getTestFightUnit(boolean b) {
LuaValue unitData = new LuaTable();
unitData.set("type",1);
unitData.set("quality",1);
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));
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;
}
@ -93,15 +266,16 @@ public class FightDataUtil {
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){
if (isHero) {
for (int i = 1; i <= propertyHero.length; i++) {
property.rawset(i,LuaValue.valueOf(propertyHero[i-1]));
property.rawset(i, LuaValue.valueOf(propertyHero[i - 1]));
}
}else {
} else {
for (int i = 1; i <= propertyEm.length; i++) {
property.rawset(i,LuaValue.valueOf(propertyEm[i-1]));
property.rawset(i, LuaValue.valueOf(propertyEm[i - 1]));
}
}
return property;
@ -113,55 +287,37 @@ public class FightDataUtil {
//{ 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());
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());
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));
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.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";