Merge branch 'main' of http://git.hivekion.com:3000/liyudong/simulation-backend
# Conflicts: # src/main/java/com/hivekion/room/bean/AbtParentTask.java # src/main/java/com/hivekion/room/bean/Room.java
This commit is contained in:
commit
d7dc7d6110
|
|
@ -28,9 +28,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import com.hivekion.statistic.bean.ScenarioInfo;
|
import com.hivekion.statistic.bean.ScenarioInfo;
|
||||||
|
|
@ -65,12 +63,7 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
//http请求
|
//http请求
|
||||||
protected WebClient webClient = WebClient.create();
|
protected WebClient webClient = WebClient.create();
|
||||||
|
|
||||||
private RedisUtil redisUtil;
|
|
||||||
|
|
||||||
private com.hivekion.statistic.service.ScenarioService scenarioService;
|
|
||||||
//是否可以移动
|
|
||||||
protected final AtomicBoolean canMoved = new AtomicBoolean(true);
|
|
||||||
protected final AtomicReference<Coordinate> coordinateReference = new AtomicReference<>(new Coordinate());
|
|
||||||
/**
|
/**
|
||||||
* 任务相对与想定的开始时间
|
* 任务相对与想定的开始时间
|
||||||
*/
|
*/
|
||||||
|
|
@ -119,9 +112,7 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
public long getDuringTime() {
|
public long getDuringTime() {
|
||||||
return RoomManager.getRoomDuringTime(this.roomId);
|
return RoomManager.getRoomDuringTime(this.roomId);
|
||||||
}
|
}
|
||||||
protected int getMag(){
|
|
||||||
return RoomManager.getMag(this.roomId);
|
|
||||||
}
|
|
||||||
//获取房间状态
|
//获取房间状态
|
||||||
public boolean getRoomStatus() {
|
public boolean getRoomStatus() {
|
||||||
return RoomManager.isRunning(roomId);
|
return RoomManager.isRunning(roomId);
|
||||||
|
|
@ -211,14 +202,13 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updatePath(double speed,TaskAction duringAction, TaskAction finishedAction) {
|
protected void updatePath(double speed,TaskAction duringAction, TaskAction finishedAction) {
|
||||||
AtomicLong runSeconds = new AtomicLong(0);
|
|
||||||
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
||||||
1);
|
1);
|
||||||
schedule.scheduleWithFixedDelay(() -> {
|
schedule.scheduleWithFixedDelay(() -> {
|
||||||
log.info("task is running....");
|
log.info("task is running....");
|
||||||
try {
|
try {
|
||||||
|
if (this.getRoomStatus()) {
|
||||||
if (this.getRoomStatus()&&canMoved.get()) {
|
|
||||||
if (distanceInfoMap.isEmpty()) {
|
if (distanceInfoMap.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -229,9 +219,8 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
if(duringAction!=null){
|
if(duringAction!=null){
|
||||||
duringAction.doSomeThing();
|
duringAction.doSomeThing();
|
||||||
}
|
}
|
||||||
runSeconds.getAndAdd(getMag());
|
|
||||||
//跑动距离
|
//跑动距离
|
||||||
double distance = runSeconds.get() * speed;
|
double distance = duringTime * speed;
|
||||||
|
|
||||||
//获取大与此距离的第一个路线点key
|
//获取大与此距离的第一个路线点key
|
||||||
Entry<Double, Coordinate> endPoint = distanceInfoMap.ceilingEntry(distance);
|
Entry<Double, Coordinate> endPoint = distanceInfoMap.ceilingEntry(distance);
|
||||||
|
|
@ -271,7 +260,6 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
Coordinate coordinate = new Coordinate();
|
Coordinate coordinate = new Coordinate();
|
||||||
coordinate.setLat(insertPoints[0]);
|
coordinate.setLat(insertPoints[0]);
|
||||||
coordinate.setLng(insertPoints[1]);
|
coordinate.setLng(insertPoints[1]);
|
||||||
coordinateReference.set(coordinate);
|
|
||||||
distanceInfoMap.put(distance, coordinate);
|
distanceInfoMap.put(distance, coordinate);
|
||||||
startPoint.set(distance);
|
startPoint.set(distance);
|
||||||
SpringUtil.getBean(RedisUtil.class).hset(
|
SpringUtil.getBean(RedisUtil.class).hset(
|
||||||
|
|
@ -282,7 +270,6 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_UPDATE.getCode(), roomId,
|
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_UPDATE.getCode(), roomId,
|
||||||
scenarioTask.getScenarioId(), dataMap));
|
scenarioTask.getScenarioId(), dataMap));
|
||||||
|
|
||||||
|
|
||||||
} else if (Double.compare(distance, endPoint.getKey()) == 0) {
|
} else if (Double.compare(distance, endPoint.getKey()) == 0) {
|
||||||
NavigableMap<Double, Coordinate> subPathMap = distanceInfoMap.subMap(startPoint.get(),
|
NavigableMap<Double, Coordinate> subPathMap = distanceInfoMap.subMap(startPoint.get(),
|
||||||
true, endPoint.getKey(), true);
|
true, endPoint.getKey(), true);
|
||||||
|
|
@ -290,7 +277,7 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
Coordinate coordinate = subPathMap.get(key);
|
Coordinate coordinate = subPathMap.get(key);
|
||||||
dataList.add(new double[]{coordinate.getLng(), coordinate.getLat()});
|
dataList.add(new double[]{coordinate.getLng(), coordinate.getLat()});
|
||||||
}
|
}
|
||||||
coordinateReference.set(endPoint.getValue());
|
|
||||||
startPoint.set(endPoint.getKey());
|
startPoint.set(endPoint.getKey());
|
||||||
Global.sendCmdInfoQueue.add(
|
Global.sendCmdInfoQueue.add(
|
||||||
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_UPDATE.getCode(), roomId,
|
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_UPDATE.getCode(), roomId,
|
||||||
|
|
@ -300,7 +287,6 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
if (finishedAction != null) {
|
if (finishedAction != null) {
|
||||||
finishedAction.doSomeThing();
|
finishedAction.doSomeThing();
|
||||||
}
|
}
|
||||||
coordinateReference.set(endPoint.getValue());
|
|
||||||
//完成路径
|
//完成路径
|
||||||
Global.sendCmdInfoQueue.add(
|
Global.sendCmdInfoQueue.add(
|
||||||
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_FINISHED.getCode(), roomId,
|
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_FINISHED.getCode(), roomId,
|
||||||
|
|
@ -311,7 +297,6 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("error::", e);
|
log.error("error::", e);
|
||||||
}
|
}
|
||||||
|
|
@ -322,19 +307,19 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
//房间统一管理定时器;房间关闭后,定时器销毁
|
//房间统一管理定时器;房间关闭后,定时器销毁
|
||||||
addScheduledExecutorServiceRefenceToRoom(schedule);
|
addScheduledExecutorServiceRefenceToRoom(schedule);
|
||||||
}
|
}
|
||||||
|
private RedisUtil redisUtil;
|
||||||
//统一推送方法
|
//统一推送方法
|
||||||
protected void pushStatus(String resourceId) {
|
protected void pushStatus(String resourceId) {
|
||||||
if( scenarioService == null) {
|
if( redisUtil == null) {
|
||||||
scenarioService = SpringUtil.getBean(com.hivekion.statistic.service.ScenarioService.class);
|
|
||||||
}
|
|
||||||
ScenarioInfo scenarioInfo = scenarioService.listScenarioInfo(this.scenarioTask.getScenarioId(),roomId,resourceId);
|
|
||||||
|
|
||||||
if( redisUtil == null){
|
|
||||||
redisUtil = SpringUtil.getBean(RedisUtil.class);
|
redisUtil = SpringUtil.getBean(RedisUtil.class);
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo",JSON.toJSONString(scenarioInfo));
|
|
||||||
}else{
|
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo",JSON.toJSONString(scenarioInfo));
|
|
||||||
}
|
}
|
||||||
|
String jsonStr= (String) redisUtil.hget(this.scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo");
|
||||||
|
ResponseCmdInfo<String> respObj = new ResponseCmdInfo<>();
|
||||||
|
respObj.setData(jsonStr);
|
||||||
|
respObj.setRoom(roomId);
|
||||||
|
respObj.setScenarioId(scenarioTask.getScenarioId());
|
||||||
|
respObj.setCmdType("scenarioInfo");
|
||||||
|
Global.sendCmdInfoQueue.add(respObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,14 +82,8 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
this.initBean();
|
this.initBean();
|
||||||
if(this.getRoomStatus()) {
|
if(this.getRoomStatus()) {
|
||||||
long initDuringTime = this.getDuringTime();
|
long initDuringTime = this.getDuringTime();
|
||||||
StatisticBean statisticBean = null;
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"duringTime",String.valueOf(initDuringTime));
|
||||||
try {
|
|
||||||
statisticBean = statisticService.statistic(scenarioTask.getResourceId());
|
|
||||||
}catch (Exception ex){
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
String jsonStr = (String)redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo");
|
String jsonStr = (String)redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo");
|
||||||
|
|
||||||
ScenarioInfo scenarioInfo =JSONObject.parseObject(jsonStr,ScenarioInfo.class);
|
ScenarioInfo scenarioInfo =JSONObject.parseObject(jsonStr,ScenarioInfo.class);
|
||||||
HashMap<String,Object> battleParams = new HashMap<>();
|
HashMap<String,Object> battleParams = new HashMap<>();
|
||||||
//初始化本次战斗任务各种资源数
|
//初始化本次战斗任务各种资源数
|
||||||
|
|
@ -105,9 +99,9 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
battleParams.put("teamLng",scenarioInfo.getTeam().getLng().toString());
|
battleParams.put("teamLng",scenarioInfo.getTeam().getLng().toString());
|
||||||
battleParams.put("duringTime",Long.valueOf(initDuringTime).toString());
|
battleParams.put("duringTime",Long.valueOf(initDuringTime).toString());
|
||||||
log.info("===============================初始化本次战斗任务各种资源数====================================");
|
log.info("===============================初始化本次战斗任务各种资源数====================================");
|
||||||
double suppleAmount =statisticBean.getAmmunition().getTotal();
|
double suppleAmount =scenarioInfo.getAmmunition().getTotal();
|
||||||
int suppleDeath =statisticBean.getPerson().getDeath();
|
int suppleDeath =scenarioInfo.getPerson().getDeath();
|
||||||
int suppleInjured =statisticBean.getPerson().getInjured();
|
int suppleInjured =scenarioInfo.getPerson().getInjured();
|
||||||
final Map<String,Boolean> suppleFlagMap = new HashMap<>();
|
final Map<String,Boolean> suppleFlagMap = new HashMap<>();
|
||||||
suppleFlagMap.put("ammunition",false);
|
suppleFlagMap.put("ammunition",false);
|
||||||
suppleFlagMap.put("death",false);
|
suppleFlagMap.put("death",false);
|
||||||
|
|
@ -129,9 +123,8 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
String teamLng = null;
|
String teamLng = null;
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
try {
|
try {
|
||||||
HashMap<String,Object> battleParams = (HashMap<String, Object>) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId());
|
|
||||||
long duringTime = getDuringTime();
|
long duringTime = getDuringTime();
|
||||||
long lastDuringTime = Long.valueOf(battleParams.get("duringTime").toString());
|
long lastDuringTime = Long.valueOf(redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"duringTime").toString());
|
||||||
long intervalDuringTime = duringTime - lastDuringTime;
|
long intervalDuringTime = duringTime - lastDuringTime;
|
||||||
double ammunition = Double.valueOf(battleParams.get("ammunition").toString());
|
double ammunition = Double.valueOf(battleParams.get("ammunition").toString());
|
||||||
double food = Double.valueOf(battleParams.get("food").toString());
|
double food = Double.valueOf(battleParams.get("food").toString());
|
||||||
|
|
@ -165,10 +158,10 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
scenarioInfo.getFuel().setCurrent(Double.valueOf(fuel - fuelConsume));
|
scenarioInfo.getFuel().setCurrent(Double.valueOf(fuel - fuelConsume));
|
||||||
scenarioInfo.getMedical().setCurrent(Double.valueOf(medical - medicalConsume));
|
scenarioInfo.getMedical().setCurrent(Double.valueOf(medical - medicalConsume));
|
||||||
scenarioInfo.getWater().setCurrent(Double.valueOf(water - waterConsume));
|
scenarioInfo.getWater().setCurrent(Double.valueOf(water - waterConsume));
|
||||||
battleParams.put("death",Long.valueOf(death+deathConsume).toString());
|
scenarioInfo.getPerson().setDeath(Long.valueOf(death+deathConsume).intValue());
|
||||||
battleParams.put("injured",Long.valueOf(injured +injuredConsume).toString());
|
scenarioInfo.getPerson().setInjured(Long.valueOf(injured +injuredConsume).intValue());
|
||||||
battleParams.put("duringTime",Long.valueOf(duringTime).toString());
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"duringTime",String.valueOf(duringTime));
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), battleParams);
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "scenarioInfo",JSONObject.toJSONString(scenarioInfo));
|
||||||
}catch (Exception ex){
|
}catch (Exception ex){
|
||||||
log.error("==============================设置消耗信息失败=============================================",ex.getMessage());
|
log.error("==============================设置消耗信息失败=============================================",ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
package com.hivekion.room.bean;
|
package com.hivekion.room.bean;
|
||||||
|
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.hivekion.Global;
|
import com.hivekion.Global;
|
||||||
import com.hivekion.baseData.entity.Scenario;
|
import com.hivekion.baseData.entity.Scenario;
|
||||||
import com.hivekion.common.entity.ResponseCmdInfo;
|
import com.hivekion.common.entity.ResponseCmdInfo;
|
||||||
|
import com.hivekion.common.redis.RedisUtil;
|
||||||
import com.hivekion.common.utils;
|
import com.hivekion.common.utils;
|
||||||
import com.hivekion.common.uuid.IdUtils;
|
import com.hivekion.common.uuid.IdUtils;
|
||||||
import com.hivekion.room.func.TaskAction;
|
import com.hivekion.room.func.TaskAction;
|
||||||
|
|
@ -22,6 +25,9 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
import com.hivekion.scenario.entity.ScenarioResource;
|
||||||
|
import com.hivekion.statistic.bean.ScenarioInfo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
@ -52,6 +58,10 @@ public class Room implements AutoCloseable {
|
||||||
* 想定信息
|
* 想定信息
|
||||||
*/
|
*/
|
||||||
private Scenario scenario;
|
private Scenario scenario;
|
||||||
|
|
||||||
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
|
private com.hivekion.statistic.service.ScenarioService scenarioService;
|
||||||
/**
|
/**
|
||||||
* 任务容器
|
* 任务容器
|
||||||
*/
|
*/
|
||||||
|
|
@ -92,9 +102,8 @@ public class Room implements AutoCloseable {
|
||||||
status.set(true);
|
status.set(true);
|
||||||
totalTime.set(time);
|
totalTime.set(time);
|
||||||
startTask();
|
startTask();
|
||||||
//初始化系统资源 初始化resource下物资信息
|
//初始化系统资源 物资人员等信息
|
||||||
//1.
|
initRoomParam();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -207,8 +216,21 @@ public class Room implements AutoCloseable {
|
||||||
return status.get();
|
return status.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMag() {
|
public void initRoomParam(){
|
||||||
return this.mag;
|
if( scenarioService == null) {
|
||||||
|
scenarioService = SpringUtil.getBean(com.hivekion.statistic.service.ScenarioService.class);
|
||||||
|
}
|
||||||
|
for(ScenarioResource scenarioResource:this.scenario.getResourceList() ){
|
||||||
|
ScenarioInfo scenarioInfo = scenarioService.listScenarioInfo(scenarioResource.getScenarioId(),roomId,scenarioResource.getId());
|
||||||
|
if( redisUtil == null){
|
||||||
|
redisUtil = SpringUtil.getBean(RedisUtil.class);
|
||||||
|
redisUtil.hset(scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(),"scenarioInfo", JSON.toJSONString(scenarioInfo));
|
||||||
|
}else{
|
||||||
|
redisUtil.hset(scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(),"scenarioInfo",JSON.toJSONString(scenarioInfo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user