2025-09-18 10:47:37 +08:00
|
|
|
|
package com.hivekion.room.bean;
|
|
|
|
|
|
|
2025-09-18 15:23:09 +08:00
|
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
2025-09-18 11:20:55 +08:00
|
|
|
|
import com.hivekion.Global;
|
2025-09-18 15:23:09 +08:00
|
|
|
|
import com.hivekion.common.entity.ResponseCmdInfo;
|
|
|
|
|
|
import com.hivekion.common.redis.RedisUtil;
|
2025-09-18 10:47:37 +08:00
|
|
|
|
import com.hivekion.scenario.entity.ScenarioTask;
|
2025-09-18 15:23:09 +08:00
|
|
|
|
import com.hivekion.statistic.bean.*;
|
|
|
|
|
|
import com.hivekion.statistic.service.StatisticService;
|
|
|
|
|
|
import com.hivekion.statistic.service.impl.StatisticServiceImpl;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2025-09-18 10:47:37 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* [类的简要说明]
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
* [详细描述,可选]
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author LiDongYU
|
|
|
|
|
|
* @since 2025/7/22
|
|
|
|
|
|
*/
|
|
|
|
|
|
public class BattleRootTask extends AbtParentTask {
|
|
|
|
|
|
|
2025-09-18 15:23:09 +08:00
|
|
|
|
private StatisticService statisticService = null;
|
|
|
|
|
|
private RedisUtil redisUtil = null;
|
|
|
|
|
|
|
|
|
|
|
|
private static final Double TEAM_SPREED = 1.2D;
|
|
|
|
|
|
private static final Integer PERSON_SPREED = 3;
|
|
|
|
|
|
private static final Double AMMUNITION_SPREED = 2.6D;
|
|
|
|
|
|
private static final Double FOOD_SPREED = 2.3D;
|
|
|
|
|
|
private static final Double WATER_SPREED = 3.6D;
|
|
|
|
|
|
private static final Double FUEL_SPREED = 3.6D;
|
|
|
|
|
|
private static final Double MEDICAL_SPREED = 1.6D;
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-18 10:47:37 +08:00
|
|
|
|
|
|
|
|
|
|
public BattleRootTask(ScenarioTask scenarioTask,String roomId) {
|
|
|
|
|
|
super(scenarioTask,roomId);
|
|
|
|
|
|
}
|
2025-09-18 15:23:09 +08:00
|
|
|
|
|
|
|
|
|
|
private void initBean(){
|
|
|
|
|
|
if(statisticService == null) {
|
|
|
|
|
|
statisticService = SpringUtil.getBean("statisticService");
|
|
|
|
|
|
}
|
|
|
|
|
|
if(redisUtil == null) {
|
|
|
|
|
|
redisUtil = SpringUtil.getBean("redisUtil");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-18 11:20:55 +08:00
|
|
|
|
//执行一次
|
2025-09-18 10:47:37 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void doSomeThing() {
|
2025-09-18 15:23:09 +08:00
|
|
|
|
this.initBean();
|
|
|
|
|
|
if(this.getRoomStatus()) {
|
|
|
|
|
|
long initduringTime = this.getDuringTime();
|
|
|
|
|
|
StatisticBean statisticBean = statisticService.statistic(scenarioTask.getResourceId());
|
|
|
|
|
|
// statisticBean.getAmmunition().getCurrent()
|
|
|
|
|
|
//初始化本次战斗任务各种资源数
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"ammunition",statisticBean.getAmmunition().getCurrent());
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"food",statisticBean.getFood().getCurrent());
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"fuel",statisticBean.getFuel().getCurrent());
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"medical",statisticBean.getMedical().getCurrent());
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"water",statisticBean.getWater().getCurrent());
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"person",statisticBean.getPerson().getCurrent());
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"duringTime",initduringTime);
|
|
|
|
|
|
//定时检查统计各种资源消耗量
|
|
|
|
|
|
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
|
|
|
|
|
1);
|
|
|
|
|
|
schedule.scheduleWithFixedDelay(() -> {
|
|
|
|
|
|
long duringTime = getDuringTime();
|
|
|
|
|
|
long lastDuringTime = (long) redisUtil.hget(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"duringTime");
|
|
|
|
|
|
long intervalDuringTime = duringTime - lastDuringTime;
|
|
|
|
|
|
double ammunition = (double) redisUtil.hget(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"ammunition");
|
|
|
|
|
|
double food = (double) redisUtil.hget(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"food");
|
|
|
|
|
|
double fuel = (double) redisUtil.hget(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"fuel");
|
|
|
|
|
|
double medical = (double) redisUtil.hget(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"medical");
|
|
|
|
|
|
double water = (double) redisUtil.hget(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"water");
|
|
|
|
|
|
int person = (int) redisUtil.hget(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"person");
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
double teamConsume = intervalDuringTime * TEAM_SPREED;
|
|
|
|
|
|
long personConsume = intervalDuringTime* PERSON_SPREED ;
|
|
|
|
|
|
Double ammunitionConsume = intervalDuringTime * AMMUNITION_SPREED;
|
|
|
|
|
|
Double foodConsume = intervalDuringTime * FOOD_SPREED;
|
|
|
|
|
|
Double waterConsume = intervalDuringTime * WATER_SPREED;
|
|
|
|
|
|
Double fuelConsume = intervalDuringTime * FUEL_SPREED;
|
|
|
|
|
|
Double medicalConsume = intervalDuringTime * MEDICAL_SPREED;
|
|
|
|
|
|
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"ammunition",ammunition-ammunitionConsume);
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"food",food-foodConsume);
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"fuel",fuel-foodConsume);
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"medical",medical-medicalConsume);
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"water",water-waterConsume);
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"person",person-personConsume);
|
|
|
|
|
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"duringTime",duringTime);
|
|
|
|
|
|
ResponseCmdInfo<JSONObject> sendConsumeMsg = new ResponseCmdInfo<>();
|
|
|
|
|
|
//推送消耗數據
|
|
|
|
|
|
Global.sendCmdInfoQueue.add(sendConsumeMsg);
|
|
|
|
|
|
|
|
|
|
|
|
}, 0, 10, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
|
|
|
|
//房间统一管理定时器;房间关闭后,定时器销毁
|
|
|
|
|
|
addScheduledExecutorServiceRefenceToRoom(schedule);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-18 10:47:37 +08:00
|
|
|
|
}
|
2025-09-18 11:41:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-09-18 10:47:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|