|
|
|
@ -10,15 +10,23 @@ import com.hivekion.common.entity.ResponseCmdInfo;
|
|
|
|
|
import com.hivekion.common.redis.RedisUtil;
|
|
|
|
|
import com.hivekion.common.uuid.IdUtils;
|
|
|
|
|
import com.hivekion.room.RoomManager;
|
|
|
|
|
import com.hivekion.room.func.TaskAction;
|
|
|
|
|
import com.hivekion.scenario.entity.BattleConsume;
|
|
|
|
|
import com.hivekion.scenario.entity.ScenarioResource;
|
|
|
|
|
import com.hivekion.scenario.entity.ScenarioTask;
|
|
|
|
|
import com.hivekion.scenario.service.IBattleConsumeService;
|
|
|
|
|
import com.hivekion.scenario.service.impl.BattleSupplierServiceImpl;
|
|
|
|
|
import com.hivekion.scenario.service.impl.ScenarioResourceServiceImpl;
|
|
|
|
|
import com.hivekion.scenario.service.impl.ScenarioTaskServiceImpl;
|
|
|
|
|
import com.hivekion.statistic.bean.*;
|
|
|
|
|
import com.hivekion.statistic.service.StatisticService;
|
|
|
|
|
import com.hivekion.statistic.service.impl.StatisticServiceImpl;
|
|
|
|
|
import com.hivekion.supplier.entity.SupplierRequest;
|
|
|
|
|
import com.hivekion.supplier.service.ISupplierRequestService;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
|
|
|
|
import com.hivekion.team.entity.Teaminfo;
|
|
|
|
|
import com.hivekion.team.service.impl.TeaminfoServiceImpl;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
@ -49,6 +57,7 @@ public class BattleRootTask extends AbtParentTask {
|
|
|
|
|
|
|
|
|
|
private IBattleConsumeService battleConsumeService;
|
|
|
|
|
|
|
|
|
|
private ScenarioInfo scenarioInfo;
|
|
|
|
|
|
|
|
|
|
private static final Double FOOD_SPREED = 0.3D;
|
|
|
|
|
private static final Double WATER_SPREED = 0.1D;
|
|
|
|
@ -83,7 +92,7 @@ public class BattleRootTask extends AbtParentTask {
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"duringTime",String.valueOf(initDuringTime));
|
|
|
|
|
String jsonStr = (String)redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo");
|
|
|
|
|
ScenarioInfo scenarioInfo =JSONObject.parseObject(jsonStr,ScenarioInfo.class);
|
|
|
|
|
|
|
|
|
|
this.scenarioInfo = scenarioInfo;
|
|
|
|
|
log.info("===============================初始化本次战斗任务各种资源数====================================");
|
|
|
|
|
double suppleAmount =scenarioInfo.getAmmunition().getTotal();
|
|
|
|
|
int suppleDeath =scenarioInfo.getPerson().getDeath();
|
|
|
|
@ -125,11 +134,11 @@ public class BattleRootTask extends AbtParentTask {
|
|
|
|
|
teamLng = scenarioInfoOnTime.getTeam().getLng().toString();
|
|
|
|
|
if(scenarioInfoOnTime.getPerson().getCurrent() >0) {
|
|
|
|
|
//
|
|
|
|
|
deathConsume = RandomUtil.getSecureRandom().nextInt(2) * intervalDuringTime* RoomManager.getMag(roomId);
|
|
|
|
|
injuredConsume = RandomUtil.getSecureRandom().nextInt(3) * intervalDuringTime* RoomManager.getMag(roomId);
|
|
|
|
|
ammunitionConsume = intervalDuringTime * (0.1D + RandomUtil.getSecureRandom().nextDouble())* RoomManager.getMag(roomId);
|
|
|
|
|
foodConsume = intervalDuringTime * FOOD_SPREED* RoomManager.getMag(roomId);
|
|
|
|
|
waterConsume = intervalDuringTime * WATER_SPREED* RoomManager.getMag(roomId);
|
|
|
|
|
deathConsume = RandomUtil.getSecureRandom().nextInt(2) * intervalDuringTime;
|
|
|
|
|
injuredConsume = RandomUtil.getSecureRandom().nextInt(3) * intervalDuringTime;
|
|
|
|
|
ammunitionConsume = intervalDuringTime * (0.1D + RandomUtil.getSecureRandom().nextDouble());
|
|
|
|
|
foodConsume = intervalDuringTime * FOOD_SPREED;
|
|
|
|
|
waterConsume = intervalDuringTime * WATER_SPREED;
|
|
|
|
|
|
|
|
|
|
medicalConsume = intervalDuringTime * MEDICAL_SPREED* RoomManager.getMag(roomId);
|
|
|
|
|
|
|
|
|
@ -148,7 +157,7 @@ public class BattleRootTask extends AbtParentTask {
|
|
|
|
|
}
|
|
|
|
|
scenarioInfoOnTime.getPerson().setDeath(Long.valueOf(death + deathConsume).intValue());
|
|
|
|
|
scenarioInfoOnTime.getPerson().setInjured(Long.valueOf(injured + injuredConsume).intValue());
|
|
|
|
|
scenarioInfoOnTime.getPerson().setCurrent(scenarioInfo.getPerson().getCurrent() - Long.valueOf(deathConsume).intValue()-Long.valueOf(injuredConsume).intValue());
|
|
|
|
|
scenarioInfoOnTime.getPerson().setCurrent(scenarioInfoOnTime.getPerson().getCurrent() - Long.valueOf(deathConsume).intValue()-Long.valueOf(injuredConsume).intValue());
|
|
|
|
|
|
|
|
|
|
String updJsonStr = (String) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "updScenarioInfo");
|
|
|
|
|
EditScenarioInfo updScenarioInfo = JSON.parseObject(updJsonStr, EditScenarioInfo.class);
|
|
|
|
@ -178,6 +187,26 @@ public class BattleRootTask extends AbtParentTask {
|
|
|
|
|
Global.sendCmdInfoQueue.add(respObj);
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "duringTime", String.valueOf(duringTime));
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "scenarioInfo", JSONObject.toJSONString(scenarioInfoOnTime));
|
|
|
|
|
}else{
|
|
|
|
|
log.info("=========================scenarioInfoOnTime.getPerson().getCurrent()==========={}========================================================",scenarioInfoOnTime.getPerson().getCurrent());
|
|
|
|
|
String updJsonStr = (String) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "updScenarioInfo");
|
|
|
|
|
EditScenarioInfo updScenarioInfo = JSON.parseObject(updJsonStr, EditScenarioInfo.class);
|
|
|
|
|
if(updScenarioInfo.getJbxx().getAmmunition().getCurrent() <0) {
|
|
|
|
|
updScenarioInfo.getJbxx().getAmmunition().setCurrent(Double.valueOf(0));
|
|
|
|
|
}
|
|
|
|
|
if(updScenarioInfo.getJbxx().getFood().getCurrent() < 0) {
|
|
|
|
|
updScenarioInfo.getJbxx().getFood().setCurrent(Double.valueOf(0));
|
|
|
|
|
}
|
|
|
|
|
// updScenarioInfo.getJbxx().getFuel().setCurrent(Double.valueOf(fuel - fuelConsume));
|
|
|
|
|
if(updScenarioInfo.getJbxx().getMedical().getCurrent() < 0) {
|
|
|
|
|
updScenarioInfo.getJbxx().getMedical().setCurrent(Double.valueOf(0));
|
|
|
|
|
}
|
|
|
|
|
if(updScenarioInfo.getJbxx().getWater().getCurrent() < 0) {
|
|
|
|
|
updScenarioInfo.getJbxx().getWater().setCurrent(Double.valueOf(0));
|
|
|
|
|
}
|
|
|
|
|
updScenarioInfo.getJbxx().getPerson().setCurrent(0);
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
|
|
|
|
"updScenarioInfo", JSON.toJSONString(updScenarioInfo));
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception ex){
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
@ -290,7 +319,7 @@ public class BattleRootTask extends AbtParentTask {
|
|
|
|
|
SupplierRequest supplierRequest = new SupplierRequest();
|
|
|
|
|
supplierRequest.setId(IdUtils.simpleUUID());
|
|
|
|
|
supplierRequest.setFromResourceId(scenarioTask.getResourceId());
|
|
|
|
|
supplierRequest.setSupplierNum(String.valueOf(suppleInjured));
|
|
|
|
|
supplierRequest.setSupplierNum(String.valueOf(scenarioInfoOnTime.getPerson().getInjured()));
|
|
|
|
|
supplierRequest.setSupplierType("injured");
|
|
|
|
|
supplierRequest.setGeneralTime(currentDateTime);
|
|
|
|
|
supplierRequest.setLat(jsonObject.get("teamLat").toString());
|
|
|
|
@ -302,6 +331,18 @@ public class BattleRootTask extends AbtParentTask {
|
|
|
|
|
respObj.setScenarioId(scenarioTask.getScenarioId());
|
|
|
|
|
respObj.setCmdType("injuredRequest");
|
|
|
|
|
Global.sendCmdInfoQueue.add(respObj);
|
|
|
|
|
log.info("================================begin injured Supplier Task=====================================");
|
|
|
|
|
produceTask(scenarioInfoOnTime.getPerson().getInjured());
|
|
|
|
|
String jsonInjured = (String)redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo");
|
|
|
|
|
ScenarioInfo scenarioInfoInjured =JSONObject.parseObject(jsonInjured,ScenarioInfo.class);
|
|
|
|
|
scenarioInfoInjured.getPerson().setInjured(Long.valueOf(0).intValue());
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "scenarioInfo", JSONObject.toJSONString(scenarioInfoInjured));
|
|
|
|
|
String updJsonStr = (String) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "updScenarioInfo");
|
|
|
|
|
EditScenarioInfo updScenarioInfo = JSON.parseObject(updJsonStr, EditScenarioInfo.class);
|
|
|
|
|
updScenarioInfo.getJbxx().getPerson().setInjured(Long.valueOf(0).intValue());
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
|
|
|
|
"updScenarioInfo", JSON.toJSONString(updScenarioInfo));
|
|
|
|
|
log.info("================================end injured Supplier Task=====================================");
|
|
|
|
|
suppleFlagMap.put("injured", true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -318,6 +359,109 @@ public class BattleRootTask extends AbtParentTask {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void produceTask(Integer injured) {
|
|
|
|
|
try {
|
|
|
|
|
Map<Integer, Teaminfo> teamInfoMap = SpringUtil.getBean(TeaminfoServiceImpl.class)
|
|
|
|
|
.teamInfoMap();
|
|
|
|
|
|
|
|
|
|
log.info("{}-产生自动保障任务", this.scenarioTask.getResourceId());
|
|
|
|
|
List<ScenarioResource> resourceList = SpringUtil.getBean(BattleSupplierServiceImpl.class)
|
|
|
|
|
.selectSupplierResource(scenarioTask.getResourceId());
|
|
|
|
|
log.info("{}-可选保障分队长度{}", scenarioTask.getResourceId(), resourceList.size());
|
|
|
|
|
if (!resourceList.isEmpty()) {
|
|
|
|
|
ScenarioResource supplierResource = null;
|
|
|
|
|
// 找出油料保障分队
|
|
|
|
|
for (ScenarioResource resource : resourceList) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Teaminfo teaminfo = teamInfoMap.get(resource.getResourceId());
|
|
|
|
|
|
|
|
|
|
if ("HOSPITAL".equals(teaminfo.getRoleCode())) {
|
|
|
|
|
supplierResource = resource;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (supplierResource == null) {
|
|
|
|
|
log.error("找不到对应的医院分队");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//找出医院
|
|
|
|
|
List<ScenarioResource> resources = SpringUtil.getBean(ScenarioResourceServiceImpl.class)
|
|
|
|
|
.selectResourceByRoleCode(scenarioTask.getScenarioId(), "HOSPITAL");
|
|
|
|
|
if (resources.isEmpty()) {
|
|
|
|
|
log.error("找不到医院仓库");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
produceMoveTask(supplierResource, resources.get(0), this.coordinateReference.get(), injured);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
log.error("{}-没有保障分队可以选择", scenarioTask.getResourceId());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("produceTask exception", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void produceMoveTask(ScenarioResource supplierResource, ScenarioResource fuelResource,
|
|
|
|
|
Coordinate coordinate, Integer injured) {
|
|
|
|
|
ScenarioTask task = new ScenarioTask();
|
|
|
|
|
task.setId(IdUtils.simpleUUID());
|
|
|
|
|
task.setScenarioId(scenarioTask.getScenarioId());
|
|
|
|
|
task.setResourceId(supplierResource.getId());
|
|
|
|
|
task.setTaskType("1");
|
|
|
|
|
|
|
|
|
|
task.setFromLat(supplierResource.getLat());
|
|
|
|
|
task.setFromLng(supplierResource.getLng());
|
|
|
|
|
task.setToLat(fuelResource.getLat());
|
|
|
|
|
task.setToLng(fuelResource.getLng());
|
|
|
|
|
task.setStartTime(LocalDateTime.now());
|
|
|
|
|
task.setFromSource("general");
|
|
|
|
|
log.info("承担保障任务的resourceId::{}", supplierResource.getId());
|
|
|
|
|
SpringUtil.getBean(ScenarioTaskServiceImpl.class).save(task);
|
|
|
|
|
MoveTask moveTask = new MoveTask(task, this.roomId, new TaskAction() {
|
|
|
|
|
@Override
|
|
|
|
|
public void doSomeThing() {
|
|
|
|
|
//创建一个保障任务
|
|
|
|
|
|
|
|
|
|
ScenarioTask task = new ScenarioTask();
|
|
|
|
|
task.setId(IdUtils.simpleUUID());
|
|
|
|
|
task.setScenarioId(scenarioTask.getScenarioId());
|
|
|
|
|
task.setResourceId(supplierResource.getId());
|
|
|
|
|
task.setTaskType("3");
|
|
|
|
|
task.setInsureResourceId(scenarioTask.getResourceId());
|
|
|
|
|
task.setSupplierNum(injured);
|
|
|
|
|
task.setToLat(coordinate.getLat() + "");
|
|
|
|
|
task.setToLng(coordinate.getLng() + "");
|
|
|
|
|
task.setStartTime(LocalDateTime.now());
|
|
|
|
|
task.setFromLat(fuelResource.getLat());
|
|
|
|
|
task.setFromLng(fuelResource.getLng());
|
|
|
|
|
task.setFromSource("general");
|
|
|
|
|
SpringUtil.getBean(ScenarioTaskServiceImpl.class).save(task);
|
|
|
|
|
SupplierTask supplierTask = new SupplierTask(task, roomId);
|
|
|
|
|
RoomManager.addAction(roomId, 0, supplierTask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getId() {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getType() {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//立即执行
|
|
|
|
|
RoomManager.addAction(roomId, 0, moveTask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|