新将来袭初版

back_recharge
duhui 2020-12-03 10:27:55 +08:00
parent e0c2c51303
commit 686596375d
1 changed files with 28 additions and 8 deletions

View File

@ -23,6 +23,8 @@ import config.SNewHeroConfig;
import manager.STableManager;
import org.springframework.stereotype.Component;
import java.text.NumberFormat;
/***
* @author hj
* @date 2020-11-27
@ -58,17 +60,28 @@ public class NewGeneralAttackHandler extends BaseHandler<ActivityProto.NewGenera
int[][] hurt = newHeroConfig.getDropList(); //伤害奖励表
SMonsterGroup sMonsterGroup = SMonsterGroup.getsMonsterGroupMap().get(monsterGroupId);
// 获取怪物组
int[][] contents = sMonsterGroup.getContents();
for (int i = 0; i < contents.length; i++) {
if (contents[i][0] == 0){
break;
int[] ints = contents[i];
for (int j = 0; j < ints.length; j++) {
if (ints[j] == 0){
// 怪物不存在
continue;
}
SMonsterConfig monsterConfig = STableManager.getConfig(SMonsterConfig.class).get(ints[j]);
// 计算总血量
bossBlood+=monsterConfig.getHp();
}
SMonsterConfig monsterConfig = STableManager.getConfig(SMonsterConfig.class).get(contents[i][1]);
bossBlood+=monsterConfig.getHp();
}
if (bossBlood == 0){
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
}
// 战斗逻辑
PVEFightEvent pveFightEvent = new PVEFightEvent(user.getId(), GlobalsDef.FORMATION_NORMAL, 1000, "", GameFightType.DailyChallenge, monsterGroupId, 3);
PVEFightEvent pveFightEvent = new PVEFightEvent(user.getId(), GlobalsDef.FORMATION_NORMAL, 1000, "", GameFightType.GuildChallenge, monsterGroupId, 3);
FightResult fightResult = FightDispatcher.dispatcher(pveFightEvent);
CommonProto.FightData fightData = CommonProto.FightData.newBuilder()
.setFightMaxTime(20)
@ -80,12 +93,19 @@ public class NewGeneralAttackHandler extends BaseHandler<ActivityProto.NewGenera
// 战斗结果,第二位是伤害
int[] checkResult = fightResult.getCheckResult();
// 伤害对比血量,百分比
int blood = checkResult[1] / bossBlood;
// 设置小数点后4位
NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(4);
// 伤害/血量 用float表示
String blood = numberFormat.format((float) checkResult[1] / (float)bossBlood);
// 表里面配置的伤害是万分比所以这里的概率乘以10000
float b = Float.parseFloat(blood)*10000;
// 获取奖励id
int[] dropList = new int[hurt.length];
for (int i=0;i<hurt.length;i++){
if (blood > hurt[i][0]/100){
float h = hurt[i][0];
if (b >= h){
dropList[i] = hurt[i][1];
}
}