Parcourir la source

枯萎、养殖放牧渔场新加条件判断

xst il y a 3 ans
Parent
commit
49f1315fd1

+ 22 - 0
src/main/java/com/td/boss/common/pojo/CultivateKeys.java

@@ -0,0 +1,22 @@
+package com.td.boss.common.pojo;
+
+/**
+ * 牧场养殖渔场需求
+ */
+public class CultivateKeys {
+
+    /**
+     * 1、牧场 2、养殖 3、渔场淡水区 4、渔场海水区
+     */
+    public static final Integer[] mallType = new Integer[]{1, 2, 3, 4};
+    /**
+     * 土堆分别最大种植数量
+     */
+    public static final int[] amountLimit = new int[]{50, 100, 200, 200};
+
+    /**
+     * 超过这个值就枯萎
+     */
+    public static final int witheredDay=10;
+    public static final long dayLong= 1000*60*60*24;
+}

+ 1 - 0
src/main/java/com/td/boss/config/enums/ResultEnum.java

@@ -108,6 +108,7 @@ public enum ResultEnum {
     LAND_NO_PLANT_ERROR(816,"土地未养殖,喂养失败!"),
     FOOD_NO_ERROR(817,"未找到养料!"),
     FOOD_REPEAT_ERROR(818,"今日已喂养!"),
+    SEED_LAND_WITHERED(819,"果实已枯萎!"),
     //装备相关
     MALL_OTHER_IS_NULL(810,"商城装备不存在!"),
     MALL_OTHER_IS_HAVE(811,"商城装备已经存在!"),

+ 13 - 1
src/main/java/com/td/boss/game/complayercultivate/controller/ComPlayerCultivateController.java

@@ -40,6 +40,7 @@ public class ComPlayerCultivateController {
 
     /**
      * 解锁某个土地 【牧场养殖渔场】
+     *
      * @param userId
      * @param configLandId
      * @return
@@ -47,7 +48,18 @@ public class ComPlayerCultivateController {
     @PostMapping("payLand")
     @Transactional(rollbackFor = Exception.class)
     public Result<?> payLand(@RequestParam(value = "userId") String userId,
-                                                   @RequestParam(value = "configLandId") Integer configLandId) {
+                             @RequestParam(value = "configLandId") Integer configLandId) {
         return comPlayerCultivateSerivce.payLand(userId, configLandId);
     }
+
+    /**
+     * 获取租赁机会
+     * @param userId
+     * @return
+     */
+    @GetMapping("getTimes")
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> getTimes(@RequestParam(value = "userId") String userId) {
+        return Result.of(comPlayerCultivateSerivce.getTimes(userId));
+    }
 }

+ 23 - 5
src/main/java/com/td/boss/game/complayergoods/controller/ComPlayerGoodsController.java

@@ -1,7 +1,9 @@
 package com.td.boss.game.complayergoods.controller;
 
 import cn.hutool.core.convert.Convert;
+import cn.hutool.core.util.ArrayUtil;
 import com.td.boss.common.controller.*;
+import com.td.boss.common.pojo.CultivateKeys;
 import com.td.boss.common.pojo.Result;
 import com.td.boss.common.service.ComConfigService;
 import com.td.boss.config.enums.ResultEnum;
@@ -236,7 +238,7 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
         }
 
         //todo [牧场养殖渔场需求] 如果是养殖类的,计算延期后的成熟期
-        if (comPlayerLand.getMallType() > 0) {
+        if (ArrayUtil.contains(CultivateKeys.mallType,comPlayerLand.getMallType())) {
             Integer days = comPlayerCultivateSerivce.getHarvestDays(userId, comPlayerLand.getConfigLandId());
             comMallSeedVo.setMaturity(days);
         }
@@ -246,10 +248,15 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
         // 两个时间差, 逻辑是_harvestTime 时间慢慢接近种植时间
         long diff = comPlayerLand.getPlantStart().getTime() - _harvestTime.getTime();
         //if (DateUtil.getNowDateMinusDay(comMallSeedVo.getMaturity()).getTime() < comPlayerLand.getPlantStart().getTime())
+        boolean isWithered=false;
         if (diff > 0) {
             //如果当前时间减去种子的成熟期,还是小于种植日期,则判断未成熟
             return Result.of(null, false, ResultEnum.SEED_DATE_ERROR.getMessage(), ResultEnum.SEED_DATE_ERROR.getCode());
         }
+        else {
+            //判断是否枯萎
+            isWithered= diff*-1/CultivateKeys.dayLong>CultivateKeys.witheredDay;
+        }
         //获取数据库相关配置
         ComSettingVo comSettingVo = comSettingService.get("1").getData();
         if (comSettingVo.equals(null)) {
@@ -340,6 +347,12 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
             _amount -= _profit;
             //用户收取的对应数量,固定收入+被偷取后剩余的部分 (改成全部影响利润了。没有固定收入)
             _amountPart = _userHarvestPart;// DoubleUtil.add(_residualProfit, _userHarvestPart);
+
+            //todo [枯萎] 没枯萎才有利润
+            if(isWithered) {
+                _amount=0;
+                _amountPart=0d;
+            }
             //果实 Type =1
             ComPlayerGoods comPlayerGoodsSimpleVo = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, comMallSeedVo.getHarvestId(), 1);
             Integer _beforeAmount = 0;
@@ -370,9 +383,10 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
 
                 _afterProfitPart = comPlayerGoodsSimpleVo.getAmountPart();
             }
-
-            ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
-            comPlayerGoodsService.save(comPlayerGoodsVo);
+            if(isWithered==false) {
+                ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
+                comPlayerGoodsService.save(comPlayerGoodsVo);
+            }
 
             //todo 记录一个收获的操作日志
             ComPlayerLog _playerLog = new ComPlayerLog();
@@ -401,6 +415,7 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
             } catch (Exception e) {
                 System.err.println("断电损耗异常:" + e.getMessage());
             }
+            map.put("msg",isWithered?"果实已枯萎": "成功收取果实!");
             //redisLock.unlock(_disasterKey, String.valueOf(_disasterTime));
         } catch (Exception e) {
             //对应的,存在plantFlag则解锁
@@ -408,7 +423,6 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
             //redisLock.unlock(_disasterKey, String.valueOf(_disasterTime));
             throw new RuntimeException(e.getMessage());
         }
-        map.put("msg", "成功收取果实!");
         return Result.of(map);
     }
 
@@ -554,6 +568,10 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
             //如果当前时间减去种子的成熟期,还是小于种植日期,则判断未成熟
             return Result.of(null, false, ResultEnum.SEED_DATE_ERROR.getMessage(), ResultEnum.SEED_DATE_ERROR.getCode());
         }
+        //todo [枯萎] 超过一定时间不收取 就枯萎
+        else if(diff <0&&diff*-1/CultivateKeys.dayLong>CultivateKeys.witheredDay) {
+            return Result.of(null, false, ResultEnum.SEED_LAND_WITHERED.getMessage(), ResultEnum.SEED_LAND_WITHERED.getCode());
+        }
 
         //snb 的key
         String _redisSNBKey = "SNB_SAVE_" + userId;

+ 23 - 10
src/main/java/com/td/boss/game/complayerland/controller/ComPlayerLandController.java

@@ -2,9 +2,11 @@ package com.td.boss.game.complayerland.controller;
 
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.date.DateField;
+import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.json.JSONUtil;
 import com.td.boss.common.controller.*;
+import com.td.boss.common.pojo.CultivateKeys;
 import com.td.boss.common.pojo.Result;
 import com.td.boss.config.enums.ResultEnum;
 import com.td.boss.game.comexplainland.service.ComExplainLandService;
@@ -139,7 +141,7 @@ public class ComPlayerLandController extends CommonController<ComPlayerLandVo, C
                     Date _harvestTime = DateUtil.getNowDateMinusDay(comMallSeedVo.getMaturity());
 
                     //todo [牧场养殖渔场需求] 如果是养殖类的,成熟期需要单独计算
-                    if (e.getMallType() > 0) {
+                    if (ArrayUtil.contains(CultivateKeys.mallType,e.getMallType())) {
                         _harvestTime = comPlayerCultivateSerivce.getHarvestTime(userId, e.getConfigLandId());
                     }
 
@@ -152,8 +154,13 @@ public class ComPlayerLandController extends CommonController<ComPlayerLandVo, C
                         comPlayerLandAndPlantVo.setPlantDaysRemaining(0);
                         comPlayerLandAndPlantVo.setPlantHoursRemaining(0);
 
+                        //todo [枯萎]
+                        if(diff*-1/CultivateKeys.dayLong>CultivateKeys.witheredDay){
+                            comPlayerLandAndPlantVo.setWithered(true);
+                        }
+
                         //todo [牧场养殖渔场需求]如果不是养殖,是传统种植才会有灾害
-                        if (e.getMallType() == 0) {
+                        if (ArrayUtil.contains(CultivateKeys.mallType,e.getMallType())==false) {
                             //生成第一次受灾 获取用户土地 getList
                             _InitFirstDisasterProfit(comPlayerLandAndPlantVo, comMallSeedVo);
                         }
@@ -221,7 +228,7 @@ public class ComPlayerLandController extends CommonController<ComPlayerLandVo, C
                     //获取当前时间 - 植物的成熟期 = 收获时间,收获时间 >= 种植时间,即可以收获
                     Date _harvestTime = DateUtil.getNowDateMinusDay(comMallSeedVo.getMaturity());
                     //todo [牧场养殖渔场需求] 如果是养殖类的,成熟期需要单独计算
-                    if (e.getMallType() > 0) {
+                    if (ArrayUtil.contains(CultivateKeys.mallType,e.getMallType())) {
                         _harvestTime = comPlayerCultivateSerivce.getHarvestTime(userId, e.getConfigLandId());
                     }
 
@@ -233,8 +240,12 @@ public class ComPlayerLandController extends CommonController<ComPlayerLandVo, C
                         //说明可以收获了
                         comPlayerLandAndPlantVo.setPlantDaysRemaining(0);
                         comPlayerLandAndPlantVo.setPlantHoursRemaining(0);
+                        //todo [枯萎]
+                        if(diff*-1/CultivateKeys.dayLong>CultivateKeys.witheredDay) {
+                            comPlayerLandAndPlantVo.setWithered(true);
+                        }
                         //todo [牧场养殖渔场需求]如果不是养殖,是传统种植才会有灾害
-                        if (e.getMallType() == 0) {
+                        if (ArrayUtil.contains(CultivateKeys.mallType,e.getMallType())==false) {
                             //生成第一次受灾 获取用户土地 getList
                             _InitFirstDisasterProfit(comPlayerLandAndPlantVo, comMallSeedVo);
                         }
@@ -373,14 +384,13 @@ public class ComPlayerLandController extends CommonController<ComPlayerLandVo, C
                 return Result.of(null, false, ResultEnum.LAND_NOT_LEASE.getMessage(), ResultEnum.LAND_NOT_LEASE.getCode());
             }
             //todo [牧场养殖渔场需求] 特有业务
-            if (comPlayerLand.getMallType() > 0) {
+            if (ArrayUtil.contains(CultivateKeys.mallType,comPlayerLand.getMallType())) {
                 //如果剩余时间不足。不允许放养
                 if (comPlayerLand.getLeaseTime().getTime() - (cn.hutool.core.date.DateUtil.date(DateUtil.getNowDate()).offset(DateField.DAY_OF_YEAR, comMallSeedVo.getMaturity())).getTime() < 0) {
                     return Result.of(null, false, "剩余租赁时间不足!");
                 }
                 //验证该土地最大种植数量
-                int[] amountlimit = new int[]{50, 100, 200, 200};
-                if (amount > amountlimit[comPlayerLand.getMallType() - 1]) {
+                if (amount > CultivateKeys.amountLimit[comPlayerLand.getMallType() - 1]) {
                     return Result.of(null, false, "超出最大养殖数量!");
                 }
                 //lease_multiple租赁倍数 填入实际养殖数量
@@ -470,7 +480,7 @@ public class ComPlayerLandController extends CommonController<ComPlayerLandVo, C
             comPlayerLandAndPlantVo.setLeaseDaysMill(leaseDaysMill);
 
             //todo [牧场养殖渔场需求] 如果是养殖类的,计算延期后的成熟期
-            if (comPlayerLand.getMallType() > 0) {
+            if (ArrayUtil.contains(CultivateKeys.mallType,comPlayerLand.getMallType())) {
                 Integer days = comPlayerCultivateSerivce.getHarvestDays(userId, comPlayerLand.getConfigLandId());
                 comMallSeedVo.setMaturity(days);
             }
@@ -488,12 +498,15 @@ public class ComPlayerLandController extends CommonController<ComPlayerLandVo, C
                 //说明可以收获了
                 comPlayerLandAndPlantVo.setPlantDaysRemaining(0);
                 comPlayerLandAndPlantVo.setPlantHoursRemaining(0);
+                //todo [枯萎]
+                if(diff*-1/CultivateKeys.dayLong>CultivateKeys.witheredDay) {
+                    comPlayerLandAndPlantVo.setWithered(true);
+                }
                 //todo [牧场养殖渔场需求]如果不是养殖,是传统种植才会有灾害
-                if (comPlayerLand.getMallType() > 0) {
+                if (ArrayUtil.contains(CultivateKeys.mallType,comPlayerLand.getMallType())==false) {
                     //生成第一次受灾 plant
                     _InitFirstDisasterProfit(comPlayerLandAndPlantVo, comMallSeedVo);
                 }
-
             } else {
                 comPlayerLandAndPlantVo.setPlantDaysRemaining(DateUtil.getDays(diff).intValue());
                 comPlayerLandAndPlantVo.setPlantHoursRemaining(DateUtil.getHours(diff).intValue());

+ 5 - 0
src/main/java/com/td/boss/game/complayerland/vo/ComPlayerLandAndPlantVo.java

@@ -67,4 +67,9 @@ public class ComPlayerLandAndPlantVo implements Serializable {
      * 原有需求种地值0 牧场1 养殖2 淡水区3 海水区4
      */
     private Integer mallType;
+
+    /**
+     * 新加是否枯萎
+     */
+    private boolean isWithered=false;
 }

+ 1 - 1
src/test/java/com/td/boss/ComPlayerCultivateTests.java

@@ -79,7 +79,7 @@ public class ComPlayerCultivateTests {
     //获取某个人所有土地 【修改完毕】【测试完】,需要查询喂养记录,重新计算成熟日期
     @Test
     public void getLandByUserId() {
-        Result<List<ComPlayerLandAndPlantVo>> landFunction = comPlayerLandController.getLandFunction(userId, null);
+        Result<List<ComPlayerLandAndPlantVo>> landFunction = comPlayerLandController.getLandFunction("1002", "1002");
         print(landFunction);
     }