任务相关

This commit is contained in:
李玉东 2025-09-20 15:48:14 +08:00
parent d7dc7d6110
commit f5ba96e225
5 changed files with 36 additions and 7 deletions

View File

@ -28,10 +28,9 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import com.hivekion.statistic.bean.ScenarioInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;
import org.springframework.web.reactive.function.client.WebClient;
@ -62,7 +61,8 @@ public abstract class AbtParentTask implements TaskAction {
protected final String roomId;
//http请求
protected WebClient webClient = WebClient.create();
protected final AtomicBoolean canMoved = new AtomicBoolean(true);
protected final AtomicReference<Coordinate> coordinateReference = new AtomicReference<>();
/**
* 任务相对与想定的开始时间

View File

@ -1,6 +1,7 @@
package com.hivekion.room.bean;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson2.JSON;
import com.hivekion.Global;
import com.hivekion.common.entity.ResponseCmdInfo;
import com.hivekion.common.redis.RedisUtil;
@ -13,6 +14,7 @@ import com.hivekion.scenario.entity.ScenarioTask;
import com.hivekion.scenario.service.impl.BattleConsumeServiceImpl;
import com.hivekion.scenario.service.impl.BattleSupplierServiceImpl;
import com.hivekion.scenario.service.impl.ScenarioTaskServiceImpl;
import com.hivekion.statistic.bean.ScenarioInfo;
import com.hivekion.statistic.bean.StatisticBean;
import com.hivekion.statistic.service.impl.StatisticServiceImpl;
import com.hivekion.supplier.entity.SupplierRequest;
@ -138,7 +140,13 @@ public class MoveTask extends AbtParentTask implements TaskAction {
return;
}
fuel = fuel - currentUseUp;
Object statisticObj = redis.hget(
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
"scenarioInfo");
if (statisticObj != null) {
setCurrentFuel(currentUseUp);
}
redis.hset(
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
"fuelConsume", fuel);
@ -226,14 +234,24 @@ public class MoveTask extends AbtParentTask implements TaskAction {
}
private double getCurrentFuel() {
Object currentFuelObj = redis.hget(
Object statisticObj = redis.hget(
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
"fuel");
if (currentFuelObj != null) {
return Double.parseDouble(currentFuelObj.toString());
"scenarioInfo");
if (statisticObj != null) {
ScenarioInfo scenarioInfo = JSON.parseObject(statisticObj.toString(), ScenarioInfo.class);
return scenarioInfo.getFuel().getCurrent();
}
return 0;
}
private void setCurrentFuel(double num) {
Object statisticObj = redis.hget(
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
"scenarioInfo");
if (statisticObj != null) {
ScenarioInfo scenarioInfo = JSON.parseObject(statisticObj.toString(), ScenarioInfo.class);
scenarioInfo.getFuel().setCurrent( scenarioInfo.getFuel().getCurrent()-num);
}
}
}

View File

@ -10,6 +10,7 @@ import com.hivekion.common.utils;
import com.hivekion.common.uuid.IdUtils;
import com.hivekion.room.func.TaskAction;
import com.hivekion.scenario.bean.ScenarioWsParam;
import com.hivekion.scenario.service.impl.ScenarioResourceServiceImpl;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
@ -220,6 +221,8 @@ public class Room implements AutoCloseable {
if( scenarioService == null) {
scenarioService = SpringUtil.getBean(com.hivekion.statistic.service.ScenarioService.class);
}
//设置资源列表
scenario.setResourceList(SpringUtil.getBean(ScenarioResourceServiceImpl.class).getResourceListByScenarioId(scenario.getId()));
for(ScenarioResource scenarioResource:this.scenario.getResourceList() ){
ScenarioInfo scenarioInfo = scenarioService.listScenarioInfo(scenarioResource.getScenarioId(),roomId,scenarioResource.getId());
if( redisUtil == null){

View File

@ -16,4 +16,5 @@ import java.util.Map;
public interface ScenarioResourceService extends IService<ScenarioResource> {
List<ScenarioResource> getResourceList(ScenarioResource resource);
Map<String,ScenarioResource> resourceMap();
List<ScenarioResource> getResourceListByScenarioId(Integer scenarioId);
}

View File

@ -106,4 +106,11 @@ public class ScenarioResourceServiceImpl extends
return this.list().stream().collect(Collectors.toMap(ScenarioResource::getId, r -> r));
}
@Override
public List<ScenarioResource> getResourceListByScenarioId(Integer scenarioId) {
QueryWrapper<ScenarioResource> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("scenario_id", scenarioId);
return this.list(queryWrapper);
}
}