package com.qiwuai.garden.common.schedule; import com.qiwuai.garden.common.Constants; import com.qiwuai.garden.common.TimingAcquisition; import com.qiwuai.garden.dto.BackPackDto; import com.qiwuai.garden.dto.ItemBagDto; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @Component @EnableScheduling //启用多线程定时任务 @EnableAsync //启用异步执行 public class ScheduleTask { Logger log = LoggerFactory.getLogger(ScheduleTask.class); //定时投喂宠物,消耗物品 // @Scheduled(cron = "0/5 * * * * ?") public void petFeeding() { log.info("开始投喂所有宠物"); //遍历所有玩家 for (String uid : TimingAcquisition.gardenerMap.keySet()) { //优先投喂宠物栏中的宠物 //获取当前玩家的背包 BackPackDto backPack = TimingAcquisition.gardenerMap.get(uid).getBackPack(); //获取果实袋 ItemBagDto fruitBag = backPack.getItemBags().get(Constants.ITEM_TYPE_FRUIT); //获取材料袋 ItemBagDto materialBag = backPack.getItemBags().get(Constants.ITEM_TYPE_MATERIAL); //获取其他袋 ItemBagDto otherBag = backPack.getItemBags().get(Constants.ITEM_TYPE_OTHER); } } }