|
@@ -744,227 +744,227 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
* @param otherUserId
|
|
* @param otherUserId
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- @PostMapping("stealAllFruit")
|
|
|
|
|
- @ResponseBody
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
- public Result<Map> stealAllFruitFunction(
|
|
|
|
|
- @RequestParam(value = "userId") String userId,
|
|
|
|
|
- @RequestParam(value = "otherUserId") String otherUserId) {
|
|
|
|
|
-
|
|
|
|
|
- Map map = new HashMap();
|
|
|
|
|
-
|
|
|
|
|
- //获取数据库相关配置
|
|
|
|
|
- ComSettingVo comSettingVo = comSettingService.get("1").getData();
|
|
|
|
|
- if (comSettingVo.equals(null)) {
|
|
|
|
|
- return Result.of(null, false, ResultEnum.SETTING_IS_NULL.getMessage(), ResultEnum.SETTING_IS_NULL.getCode());
|
|
|
|
|
- }
|
|
|
|
|
- //todo 后台可配置,获取一个链上数据
|
|
|
|
|
- Integer _configStrength = comSettingVo.getMaxStrength(), _chainStrength = DappUtil.getChildrenCount(userId);
|
|
|
|
|
- //前端的显示,输出一个不小于0的体力值
|
|
|
|
|
- Integer _maxStrength = _configStrength + _chainStrength;
|
|
|
|
|
- //1.先判断用户是否有足够的体力,根据snb判断。2. 收取到果实,扣除用户一个体力值
|
|
|
|
|
- ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
|
|
|
|
|
- ComPlayersAttriVo playersAttribute = comPlayersAttriService.findByUserId(userId);
|
|
|
|
|
- Integer _out = _maxStrength - Math.abs(playersAttribute.getStrength());
|
|
|
|
|
- if (comUsersVo.getSnb() < comSettingVo.getDeductSnb()) {
|
|
|
|
|
- //判断是否有双倍体力
|
|
|
|
|
- if (_out < comSettingVo.getSnbUnitStrength()) {
|
|
|
|
|
- map.put("msg", "需要双倍体力:" + comSettingVo.getSnbUnitStrength());
|
|
|
|
|
- return Result.of(map, false, ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getMessage(), ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getCode());
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- //正常判断体力
|
|
|
|
|
- if (_out < comSettingVo.getUnitStrength()) {
|
|
|
|
|
- map.put("msg", "需要单倍体力:" + comSettingVo.getUnitStrength());
|
|
|
|
|
- return Result.of(map, false, ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getMessage(), ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getCode());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- List<Map> _stealLandInfos = new ArrayList<>();
|
|
|
|
|
- Double _finalStealAmountSum = 0d;
|
|
|
|
|
- //todo 偷取用户的对象信息等id
|
|
|
|
|
- List<ComPlayerLandAndCanSteal> otherPlayerLandAndCanSteal = comPlayerLandService.findCanStealByUserIdAndOtherUserId(userId, otherUserId);
|
|
|
|
|
- //List<ComPlayerLand> otherPlayerLands = comPlayerLandService.findAllByCanStealOtherLands(userId, otherUserId);
|
|
|
|
|
- List<ComPlayerLand> otherPlayerLands = new ArrayList<>();
|
|
|
|
|
- for (int i = 0; i < otherPlayerLandAndCanSteal.size(); i++) {
|
|
|
|
|
- if (otherPlayerLandAndCanSteal.get(i).getCanSteal().equals(1)) {
|
|
|
|
|
- otherPlayerLands.add(CopyUtil.copy(otherPlayerLandAndCanSteal.get(i), ComPlayerLand.class));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (otherPlayerLands.size() == 0) {
|
|
|
|
|
- return Result.of(null, false, ResultEnum.LAND_CAN_STEAL_IS_ZERO.getMessage(), ResultEnum.LAND_CAN_STEAL_IS_ZERO.getCode());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for (int i = 0; i < otherPlayerLands.size(); i++) {
|
|
|
|
|
- ComPlayerLand otherPlayerLand = otherPlayerLands.get(i);
|
|
|
|
|
- //获取当前种植的种子
|
|
|
|
|
- ComMallSeedVo comMallSeedVo = comMallSeedService.findById(otherPlayerLand.getPlantId());
|
|
|
|
|
- //需要redis 加锁
|
|
|
|
|
- long time = System.currentTimeMillis() + RedisData.getPlayerGoodsTimeout();
|
|
|
|
|
- //获取用户的plantFlag,因为之前的用户没有设置这个flag,所以设为第一次,用 userId 和 landId 组合成key
|
|
|
|
|
- String _redisKey = otherPlayerLand.getPlantFlag();
|
|
|
|
|
- if (!StringUtils.hasText(_redisKey)) {
|
|
|
|
|
- //return Result.of(null, false, ResultEnum.LAND_PLANT_FLAG_IS_NULL.getMessage(), ResultEnum.LAND_PLANT_FLAG_IS_NULL.getCode());
|
|
|
|
|
- _redisKey = otherPlayerLand.getUserId() + "or" + otherPlayerLand.getConfigLandId();
|
|
|
|
|
- }
|
|
|
|
|
- try {
|
|
|
|
|
- if (!redisLock.lock(_redisKey, String.valueOf(time))) {
|
|
|
|
|
- //如果有冲突锁,跳过
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- //todo 如果当前人员偷窃水果。记录一个信息,存储当前玩家已偷过的水果的信息
|
|
|
|
|
- //计算一个偷取的收获量, 租赁倍数* 租赁日期下的产量
|
|
|
|
|
- Integer _otherAmount = 0;
|
|
|
|
|
- if (otherPlayerLand.getLeaseDate().equals(1)) {
|
|
|
|
|
- _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest1();
|
|
|
|
|
- } else if (otherPlayerLand.getLeaseDate().equals(2)) {
|
|
|
|
|
- _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest2();
|
|
|
|
|
- } else if (otherPlayerLand.getLeaseDate().equals(3)) {
|
|
|
|
|
- _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest3();
|
|
|
|
|
- }
|
|
|
|
|
- //todo 拿出计算利润,收获量减去种子的成本(snb)后的百分之30 ,后面需要后台可调整
|
|
|
|
|
- Integer _profit = _otherAmount - otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb();
|
|
|
|
|
- // 配置的参数。这里先直接定义
|
|
|
|
|
- Double profitConfig = comSettingVo.getProfit(), stealRatioMaxConfig = comSettingVo.getStealMaxRatio(), stealRatioMinConfig = comSettingVo.getStealMinRatio(), finallyGetRatioConfig = comSettingVo.getFinalRatio();
|
|
|
|
|
- Double _stealRatio = new Random().nextDouble() * DoubleUtil.sub(stealRatioMaxConfig, stealRatioMinConfig) + stealRatioMinConfig;// 1%-3%
|
|
|
|
|
- //todo 被偷取的人扣除 一个损失量,初利润算 _profit
|
|
|
|
|
- Double _stolenAmount = DoubleUtil.mul(_profit.doubleValue(), _stealRatio);
|
|
|
|
|
- //这里根据plantFlag判断目标用户当前种植被偷取完,看下是否需要处理更新前端信息,暂不处理
|
|
|
|
|
- Double _sumStolen = comPlayerProfitService.getStolenSumByOtherUserIdAndPlantFlag(otherUserId, _redisKey);
|
|
|
|
|
- //todo 这里的可偷利润应该是最大值,用户不能超过这个,需要限制判断
|
|
|
|
|
- Double _maxAmount = DoubleUtil.mul(_profit.doubleValue(), profitConfig); //可偷取的利润
|
|
|
|
|
- //1 一键 就是 _sumStolen>_maxAmount 或者 _sumStolen == _maxAmount ,被偷完了
|
|
|
|
|
- if (!DoubleUtil.compare(_sumStolen, _maxAmount).equals(-1)) {
|
|
|
|
|
- // 需要redis 解锁
|
|
|
|
|
- redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
|
|
- //记录一个不可偷取的状态
|
|
|
|
|
- otherPlayerLand.setPlantSteal(0);
|
|
|
|
|
- comPlayerLandService.save(CopyUtil.copy(otherPlayerLand, ComPlayerLandVo.class));
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- //计算剩下可偷利润的差,防止过多偷取用户利润 _stolenAmount
|
|
|
|
|
- Double _diff = Math.abs(DoubleUtil.sub(_maxAmount, _sumStolen));
|
|
|
|
|
- if (DoubleUtil.compare(_stolenAmount, _diff).equals(1)) {
|
|
|
|
|
- //_stolenAmount>_diff
|
|
|
|
|
- _stolenAmount = _diff;
|
|
|
|
|
- }
|
|
|
|
|
- //最终偷窃人获取的是偷取的是目标用户损失量的10% finallyGetRatioConfig
|
|
|
|
|
- Double _finalStealAmount = DoubleUtil.mul(_stolenAmount, finallyGetRatioConfig);
|
|
|
|
|
- //偷窃后,系统回收部分
|
|
|
|
|
- Double _lostStealAmount = DoubleUtil.sub(1d, finallyGetRatioConfig) * _stolenAmount;
|
|
|
|
|
- //果实 Type =1
|
|
|
|
|
- //todo 增加一个字段处理背包果实,拿出当前用户背包果实
|
|
|
|
|
- ComPlayerGoods comPlayerGoods = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, comMallSeedVo.getHarvestId(), 1);
|
|
|
|
|
- Double _beforeStealAmount = 0.0;
|
|
|
|
|
- if (comPlayerGoods == null) {
|
|
|
|
|
- //背包增加收取到别的用户对应的类型数量。比如当前是偷取到的果实
|
|
|
|
|
- comPlayerGoods = new ComPlayerGoods();
|
|
|
|
|
- comPlayerGoods.setUserId(userId);
|
|
|
|
|
- comPlayerGoods.setGoodsIndex(comMallSeedVo.getHarvestId());
|
|
|
|
|
- comPlayerGoods.setGoodsType(1);
|
|
|
|
|
- comPlayerGoods.setName(comMallSeedVo.getHarvestName());
|
|
|
|
|
- //用种子的picture
|
|
|
|
|
- comPlayerGoods.setPictureName(comMallSeedVo.getPicture());
|
|
|
|
|
- //amount 设置0
|
|
|
|
|
- comPlayerGoods.setAmount(0);
|
|
|
|
|
- comPlayerGoods.setAmountPart(_finalStealAmount);
|
|
|
|
|
- _beforeStealAmount = 0.0;
|
|
|
|
|
- } else {
|
|
|
|
|
- _beforeStealAmount = comPlayerGoods.getAmountPart();
|
|
|
|
|
- //修改偷取字段
|
|
|
|
|
- comPlayerGoods.setAmountPart(DoubleUtil.add(comPlayerGoods.getAmountPart(), _finalStealAmount));
|
|
|
|
|
- }
|
|
|
|
|
- ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoods, ComPlayerGoodsVo.class);
|
|
|
|
|
- comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
|
|
-
|
|
|
|
|
- //todo 偷窃损失,处理目标用户收取果实时候,减扣一部分被偷取的数量
|
|
|
|
|
- ComPlayerProfit comPlayerProfit = new ComPlayerProfit();
|
|
|
|
|
- comPlayerProfit.setUserId(userId);
|
|
|
|
|
- comPlayerProfit.setTargetId(otherUserId);
|
|
|
|
|
- comPlayerProfit.setPlantFlag(_redisKey);
|
|
|
|
|
- comPlayerProfit.setLandId(otherPlayerLand.getConfigLandId());
|
|
|
|
|
- comPlayerProfit.setLeaseMultiple(otherPlayerLand.getLeaseMultiple());
|
|
|
|
|
- comPlayerProfit.setLeaseDate(otherPlayerLand.getLeaseDate());
|
|
|
|
|
- comPlayerProfit.setHarvest(_otherAmount);
|
|
|
|
|
- comPlayerProfit.setProfit(_profit.doubleValue());//目标用户可偷的初始利润值
|
|
|
|
|
- comPlayerProfit.setStolen(_stolenAmount);//目标用户被偷的数量
|
|
|
|
|
- comPlayerProfit.setFinalSteal(_finalStealAmount);//用户最终偷取的量,是被偷的数量 10%左右
|
|
|
|
|
- comPlayerProfit.setProfitAfter(DoubleUtil.sub(_profit.doubleValue(), DoubleUtil.add(_stolenAmount, _sumStolen))); //可偷的减去被偷的
|
|
|
|
|
- //记录相关比例
|
|
|
|
|
- comPlayerProfit.setProfitRatio(profitConfig);
|
|
|
|
|
- comPlayerProfit.setStealRatio(_stealRatio);
|
|
|
|
|
- comPlayerProfit.setFinalRatio(finallyGetRatioConfig);
|
|
|
|
|
- ComPlayerProfitVo comPlayerProfitVo = CopyUtil.copy(comPlayerProfit, ComPlayerProfitVo.class);
|
|
|
|
|
- comPlayerProfitService.save(comPlayerProfitVo);
|
|
|
|
|
-
|
|
|
|
|
- //todo 记录一个收获的操作日志,这里由于偷取果实是有小数点的,小数点处理成整数,单位 暂定5位 100000
|
|
|
|
|
- // 这里的数量都与偷窃知道相关。amountPart,注意不是果实实际总数 amount
|
|
|
|
|
- ComPlayerLog _playerLog = new ComPlayerLog();
|
|
|
|
|
- _playerLog.setUserId(userId);
|
|
|
|
|
- _playerLog.setTId(comMallSeedVo.getHarvestId());
|
|
|
|
|
- _playerLog.setTName(comMallSeedVo.getHarvestName());
|
|
|
|
|
- _playerLog.setTType(6);//偷取果实时候,type设置6
|
|
|
|
|
- //偷水果时候这部分数据应该是不变的
|
|
|
|
|
- _playerLog.setTAmount(0);
|
|
|
|
|
- _playerLog.setBeforeAmount(comPlayerGoods.getAmount());
|
|
|
|
|
- _playerLog.setAfterAmount(comPlayerGoods.getAmount());
|
|
|
|
|
- //偷取用户果实时候,收取时候信息记录
|
|
|
|
|
- _playerLog.setBeforePart(_beforeStealAmount);
|
|
|
|
|
- _playerLog.setTPart(_finalStealAmount);
|
|
|
|
|
- _playerLog.setTLoss(_lostStealAmount); //损失的部分
|
|
|
|
|
- _playerLog.setAfterPart(comPlayerGoods.getAmountPart());
|
|
|
|
|
- _playerLog.setLMultiple(otherPlayerLand.getLeaseMultiple());
|
|
|
|
|
- ComPlayerLogVo _playerLogVo = CopyUtil.copy(_playerLog, ComPlayerLogVo.class);
|
|
|
|
|
- comPlayerLogService.save(_playerLogVo);
|
|
|
|
|
-
|
|
|
|
|
- //todo 成功收取记录一个土地id
|
|
|
|
|
- Map _landMap = new HashMap();
|
|
|
|
|
- //记录一个id
|
|
|
|
|
- _landMap.put("landId", otherPlayerLand.getConfigLandId());
|
|
|
|
|
- //
|
|
|
|
|
- _landMap.put("stealAmount", _finalStealAmount);
|
|
|
|
|
-
|
|
|
|
|
- //固定成本
|
|
|
|
|
- _landMap.put("cost", otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb());
|
|
|
|
|
- //当前利润
|
|
|
|
|
- _landMap.put("profit", _profit);
|
|
|
|
|
- //打印一个比例
|
|
|
|
|
- _landMap.put("profitRatio", profitConfig);
|
|
|
|
|
- _landMap.put("intervalStealRatio", _stealRatio);
|
|
|
|
|
- _landMap.put("finallyGetRatioConfig", finallyGetRatioConfig);
|
|
|
|
|
-
|
|
|
|
|
- _finalStealAmountSum = DoubleUtil.add(_finalStealAmount, _finalStealAmountSum);
|
|
|
|
|
- _stealLandInfos.add(_landMap);
|
|
|
|
|
- // 需要redis 解锁
|
|
|
|
|
- redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- // 需要redis 解锁
|
|
|
|
|
- redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
|
|
- throw new RuntimeException(e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- map.put("msg", "偷取果实.");
|
|
|
|
|
- map.put("steals", _stealLandInfos);
|
|
|
|
|
- map.put("stealSum", _finalStealAmountSum);
|
|
|
|
|
-
|
|
|
|
|
- if (_stealLandInfos.size() > 0) {
|
|
|
|
|
- //todo 体力值可以后台配置
|
|
|
|
|
- Integer _addStrength = comUsersVo.getSnb() < comSettingVo.getDeductSnb() ? comSettingVo.getSnbUnitStrength() : comSettingVo.getUnitStrength();
|
|
|
|
|
- playersAttribute.setStrength(playersAttribute.getStrength() + _addStrength);
|
|
|
|
|
- comPlayersAttriService.save(playersAttribute);
|
|
|
|
|
- ComPlayersAttriSimpleVo comPlayersAttriSimpleVo = CopyUtil.copy(playersAttribute, ComPlayersAttriSimpleVo.class);
|
|
|
|
|
- //前端的显示,输出一个不小于0的体力值
|
|
|
|
|
- Integer _outEnd = _maxStrength - Math.abs(playersAttribute.getStrength());
|
|
|
|
|
- comPlayersAttriSimpleVo.setCurrentStrength(_outEnd < 0 ? 0 : _outEnd);
|
|
|
|
|
- //最大值是配置的值和链上数据的值相加
|
|
|
|
|
- comPlayersAttriSimpleVo.setMaxStrength(_maxStrength);
|
|
|
|
|
-
|
|
|
|
|
- map.put("playerAttribute", comPlayersAttriSimpleVo);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return Result.of(map);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// @PostMapping("stealAllFruit")
|
|
|
|
|
+// @ResponseBody
|
|
|
|
|
+// @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+// public Result<Map> stealAllFruitFunction(
|
|
|
|
|
+// @RequestParam(value = "userId") String userId,
|
|
|
|
|
+// @RequestParam(value = "otherUserId") String otherUserId) {
|
|
|
|
|
+//
|
|
|
|
|
+// Map map = new HashMap();
|
|
|
|
|
+//
|
|
|
|
|
+// //获取数据库相关配置
|
|
|
|
|
+// ComSettingVo comSettingVo = comSettingService.get("1").getData();
|
|
|
|
|
+// if (comSettingVo.equals(null)) {
|
|
|
|
|
+// return Result.of(null, false, ResultEnum.SETTING_IS_NULL.getMessage(), ResultEnum.SETTING_IS_NULL.getCode());
|
|
|
|
|
+// }
|
|
|
|
|
+// //todo 后台可配置,获取一个链上数据
|
|
|
|
|
+// Integer _configStrength = comSettingVo.getMaxStrength(), _chainStrength = DappUtil.getChildrenCount(userId);
|
|
|
|
|
+// //前端的显示,输出一个不小于0的体力值
|
|
|
|
|
+// Integer _maxStrength = _configStrength + _chainStrength;
|
|
|
|
|
+// //1.先判断用户是否有足够的体力,根据snb判断。2. 收取到果实,扣除用户一个体力值
|
|
|
|
|
+// ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
|
|
|
|
|
+// ComPlayersAttriVo playersAttribute = comPlayersAttriService.findByUserId(userId);
|
|
|
|
|
+// Integer _out = _maxStrength - Math.abs(playersAttribute.getStrength());
|
|
|
|
|
+// if (comUsersVo.getSnb() < comSettingVo.getDeductSnb()) {
|
|
|
|
|
+// //判断是否有双倍体力
|
|
|
|
|
+// if (_out < comSettingVo.getSnbUnitStrength()) {
|
|
|
|
|
+// map.put("msg", "需要双倍体力:" + comSettingVo.getSnbUnitStrength());
|
|
|
|
|
+// return Result.of(map, false, ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getMessage(), ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getCode());
|
|
|
|
|
+// }
|
|
|
|
|
+// } else {
|
|
|
|
|
+// //正常判断体力
|
|
|
|
|
+// if (_out < comSettingVo.getUnitStrength()) {
|
|
|
|
|
+// map.put("msg", "需要单倍体力:" + comSettingVo.getUnitStrength());
|
|
|
|
|
+// return Result.of(map, false, ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getMessage(), ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getCode());
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// List<Map> _stealLandInfos = new ArrayList<>();
|
|
|
|
|
+// Double _finalStealAmountSum = 0d;
|
|
|
|
|
+// //todo 偷取用户的对象信息等id
|
|
|
|
|
+// List<ComPlayerLandAndCanSteal> otherPlayerLandAndCanSteal = comPlayerLandService.findCanStealByUserIdAndOtherUserId(userId, otherUserId);
|
|
|
|
|
+// //List<ComPlayerLand> otherPlayerLands = comPlayerLandService.findAllByCanStealOtherLands(userId, otherUserId);
|
|
|
|
|
+// List<ComPlayerLand> otherPlayerLands = new ArrayList<>();
|
|
|
|
|
+// for (int i = 0; i < otherPlayerLandAndCanSteal.size(); i++) {
|
|
|
|
|
+// if (otherPlayerLandAndCanSteal.get(i).getCanSteal().equals(1)) {
|
|
|
|
|
+// otherPlayerLands.add(CopyUtil.copy(otherPlayerLandAndCanSteal.get(i), ComPlayerLand.class));
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// if (otherPlayerLands.size() == 0) {
|
|
|
|
|
+// return Result.of(null, false, ResultEnum.LAND_CAN_STEAL_IS_ZERO.getMessage(), ResultEnum.LAND_CAN_STEAL_IS_ZERO.getCode());
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// for (int i = 0; i < otherPlayerLands.size(); i++) {
|
|
|
|
|
+// ComPlayerLand otherPlayerLand = otherPlayerLands.get(i);
|
|
|
|
|
+// //获取当前种植的种子
|
|
|
|
|
+// ComMallSeedVo comMallSeedVo = comMallSeedService.findById(otherPlayerLand.getPlantId());
|
|
|
|
|
+// //需要redis 加锁
|
|
|
|
|
+// long time = System.currentTimeMillis() + RedisData.getPlayerGoodsTimeout();
|
|
|
|
|
+// //获取用户的plantFlag,因为之前的用户没有设置这个flag,所以设为第一次,用 userId 和 landId 组合成key
|
|
|
|
|
+// String _redisKey = otherPlayerLand.getPlantFlag();
|
|
|
|
|
+// if (!StringUtils.hasText(_redisKey)) {
|
|
|
|
|
+// //return Result.of(null, false, ResultEnum.LAND_PLANT_FLAG_IS_NULL.getMessage(), ResultEnum.LAND_PLANT_FLAG_IS_NULL.getCode());
|
|
|
|
|
+// _redisKey = otherPlayerLand.getUserId() + "or" + otherPlayerLand.getConfigLandId();
|
|
|
|
|
+// }
|
|
|
|
|
+// try {
|
|
|
|
|
+// if (!redisLock.lock(_redisKey, String.valueOf(time))) {
|
|
|
|
|
+// //如果有冲突锁,跳过
|
|
|
|
|
+// continue;
|
|
|
|
|
+// }
|
|
|
|
|
+// //todo 如果当前人员偷窃水果。记录一个信息,存储当前玩家已偷过的水果的信息
|
|
|
|
|
+// //计算一个偷取的收获量, 租赁倍数* 租赁日期下的产量
|
|
|
|
|
+// Integer _otherAmount = 0;
|
|
|
|
|
+// if (otherPlayerLand.getLeaseDate().equals(1)) {
|
|
|
|
|
+// _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest1();
|
|
|
|
|
+// } else if (otherPlayerLand.getLeaseDate().equals(2)) {
|
|
|
|
|
+// _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest2();
|
|
|
|
|
+// } else if (otherPlayerLand.getLeaseDate().equals(3)) {
|
|
|
|
|
+// _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest3();
|
|
|
|
|
+// }
|
|
|
|
|
+// //todo 拿出计算利润,收获量减去种子的成本(snb)后的百分之30 ,后面需要后台可调整
|
|
|
|
|
+// Integer _profit = _otherAmount - otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb();
|
|
|
|
|
+// // 配置的参数。这里先直接定义
|
|
|
|
|
+// Double profitConfig = comSettingVo.getProfit(), stealRatioMaxConfig = comSettingVo.getStealMaxRatio(), stealRatioMinConfig = comSettingVo.getStealMinRatio(), finallyGetRatioConfig = comSettingVo.getFinalRatio();
|
|
|
|
|
+// Double _stealRatio = new Random().nextDouble() * DoubleUtil.sub(stealRatioMaxConfig, stealRatioMinConfig) + stealRatioMinConfig;// 1%-3%
|
|
|
|
|
+// //todo 被偷取的人扣除 一个损失量,初利润算 _profit
|
|
|
|
|
+// Double _stolenAmount = DoubleUtil.mul(_profit.doubleValue(), _stealRatio);
|
|
|
|
|
+// //这里根据plantFlag判断目标用户当前种植被偷取完,看下是否需要处理更新前端信息,暂不处理
|
|
|
|
|
+// Double _sumStolen = comPlayerProfitService.getStolenSumByOtherUserIdAndPlantFlag(otherUserId, _redisKey);
|
|
|
|
|
+// //todo 这里的可偷利润应该是最大值,用户不能超过这个,需要限制判断
|
|
|
|
|
+// Double _maxAmount = DoubleUtil.mul(_profit.doubleValue(), profitConfig); //可偷取的利润
|
|
|
|
|
+// //1 一键 就是 _sumStolen>_maxAmount 或者 _sumStolen == _maxAmount ,被偷完了
|
|
|
|
|
+// if (!DoubleUtil.compare(_sumStolen, _maxAmount).equals(-1)) {
|
|
|
|
|
+// // 需要redis 解锁
|
|
|
|
|
+// redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
|
|
+// //记录一个不可偷取的状态
|
|
|
|
|
+// otherPlayerLand.setPlantSteal(0);
|
|
|
|
|
+// comPlayerLandService.save(CopyUtil.copy(otherPlayerLand, ComPlayerLandVo.class));
|
|
|
|
|
+// continue;
|
|
|
|
|
+// }
|
|
|
|
|
+// //计算剩下可偷利润的差,防止过多偷取用户利润 _stolenAmount
|
|
|
|
|
+// Double _diff = Math.abs(DoubleUtil.sub(_maxAmount, _sumStolen));
|
|
|
|
|
+// if (DoubleUtil.compare(_stolenAmount, _diff).equals(1)) {
|
|
|
|
|
+// //_stolenAmount>_diff
|
|
|
|
|
+// _stolenAmount = _diff;
|
|
|
|
|
+// }
|
|
|
|
|
+// //最终偷窃人获取的是偷取的是目标用户损失量的10% finallyGetRatioConfig
|
|
|
|
|
+// Double _finalStealAmount = DoubleUtil.mul(_stolenAmount, finallyGetRatioConfig);
|
|
|
|
|
+// //偷窃后,系统回收部分
|
|
|
|
|
+// Double _lostStealAmount = DoubleUtil.sub(1d, finallyGetRatioConfig) * _stolenAmount;
|
|
|
|
|
+// //果实 Type =1
|
|
|
|
|
+// //todo 增加一个字段处理背包果实,拿出当前用户背包果实
|
|
|
|
|
+// ComPlayerGoods comPlayerGoods = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, comMallSeedVo.getHarvestId(), 1);
|
|
|
|
|
+// Double _beforeStealAmount = 0.0;
|
|
|
|
|
+// if (comPlayerGoods == null) {
|
|
|
|
|
+// //背包增加收取到别的用户对应的类型数量。比如当前是偷取到的果实
|
|
|
|
|
+// comPlayerGoods = new ComPlayerGoods();
|
|
|
|
|
+// comPlayerGoods.setUserId(userId);
|
|
|
|
|
+// comPlayerGoods.setGoodsIndex(comMallSeedVo.getHarvestId());
|
|
|
|
|
+// comPlayerGoods.setGoodsType(1);
|
|
|
|
|
+// comPlayerGoods.setName(comMallSeedVo.getHarvestName());
|
|
|
|
|
+// //用种子的picture
|
|
|
|
|
+// comPlayerGoods.setPictureName(comMallSeedVo.getPicture());
|
|
|
|
|
+// //amount 设置0
|
|
|
|
|
+// comPlayerGoods.setAmount(0);
|
|
|
|
|
+// comPlayerGoods.setAmountPart(_finalStealAmount);
|
|
|
|
|
+// _beforeStealAmount = 0.0;
|
|
|
|
|
+// } else {
|
|
|
|
|
+// _beforeStealAmount = comPlayerGoods.getAmountPart();
|
|
|
|
|
+// //修改偷取字段
|
|
|
|
|
+// comPlayerGoods.setAmountPart(DoubleUtil.add(comPlayerGoods.getAmountPart(), _finalStealAmount));
|
|
|
|
|
+// }
|
|
|
|
|
+// ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoods, ComPlayerGoodsVo.class);
|
|
|
|
|
+// comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
|
|
+//
|
|
|
|
|
+// //todo 偷窃损失,处理目标用户收取果实时候,减扣一部分被偷取的数量
|
|
|
|
|
+// ComPlayerProfit comPlayerProfit = new ComPlayerProfit();
|
|
|
|
|
+// comPlayerProfit.setUserId(userId);
|
|
|
|
|
+// comPlayerProfit.setTargetId(otherUserId);
|
|
|
|
|
+// comPlayerProfit.setPlantFlag(_redisKey);
|
|
|
|
|
+// comPlayerProfit.setLandId(otherPlayerLand.getConfigLandId());
|
|
|
|
|
+// comPlayerProfit.setLeaseMultiple(otherPlayerLand.getLeaseMultiple());
|
|
|
|
|
+// comPlayerProfit.setLeaseDate(otherPlayerLand.getLeaseDate());
|
|
|
|
|
+// comPlayerProfit.setHarvest(_otherAmount);
|
|
|
|
|
+// comPlayerProfit.setProfit(_profit.doubleValue());//目标用户可偷的初始利润值
|
|
|
|
|
+// comPlayerProfit.setStolen(_stolenAmount);//目标用户被偷的数量
|
|
|
|
|
+// comPlayerProfit.setFinalSteal(_finalStealAmount);//用户最终偷取的量,是被偷的数量 10%左右
|
|
|
|
|
+// comPlayerProfit.setProfitAfter(DoubleUtil.sub(_profit.doubleValue(), DoubleUtil.add(_stolenAmount, _sumStolen))); //可偷的减去被偷的
|
|
|
|
|
+// //记录相关比例
|
|
|
|
|
+// comPlayerProfit.setProfitRatio(profitConfig);
|
|
|
|
|
+// comPlayerProfit.setStealRatio(_stealRatio);
|
|
|
|
|
+// comPlayerProfit.setFinalRatio(finallyGetRatioConfig);
|
|
|
|
|
+// ComPlayerProfitVo comPlayerProfitVo = CopyUtil.copy(comPlayerProfit, ComPlayerProfitVo.class);
|
|
|
|
|
+// comPlayerProfitService.save(comPlayerProfitVo);
|
|
|
|
|
+//
|
|
|
|
|
+// //todo 记录一个收获的操作日志,这里由于偷取果实是有小数点的,小数点处理成整数,单位 暂定5位 100000
|
|
|
|
|
+// // 这里的数量都与偷窃知道相关。amountPart,注意不是果实实际总数 amount
|
|
|
|
|
+// ComPlayerLog _playerLog = new ComPlayerLog();
|
|
|
|
|
+// _playerLog.setUserId(userId);
|
|
|
|
|
+// _playerLog.setTId(comMallSeedVo.getHarvestId());
|
|
|
|
|
+// _playerLog.setTName(comMallSeedVo.getHarvestName());
|
|
|
|
|
+// _playerLog.setTType(6);//偷取果实时候,type设置6
|
|
|
|
|
+// //偷水果时候这部分数据应该是不变的
|
|
|
|
|
+// _playerLog.setTAmount(0);
|
|
|
|
|
+// _playerLog.setBeforeAmount(comPlayerGoods.getAmount());
|
|
|
|
|
+// _playerLog.setAfterAmount(comPlayerGoods.getAmount());
|
|
|
|
|
+// //偷取用户果实时候,收取时候信息记录
|
|
|
|
|
+// _playerLog.setBeforePart(_beforeStealAmount);
|
|
|
|
|
+// _playerLog.setTPart(_finalStealAmount);
|
|
|
|
|
+// _playerLog.setTLoss(_lostStealAmount); //损失的部分
|
|
|
|
|
+// _playerLog.setAfterPart(comPlayerGoods.getAmountPart());
|
|
|
|
|
+// _playerLog.setLMultiple(otherPlayerLand.getLeaseMultiple());
|
|
|
|
|
+// ComPlayerLogVo _playerLogVo = CopyUtil.copy(_playerLog, ComPlayerLogVo.class);
|
|
|
|
|
+// comPlayerLogService.save(_playerLogVo);
|
|
|
|
|
+//
|
|
|
|
|
+// //todo 成功收取记录一个土地id
|
|
|
|
|
+// Map _landMap = new HashMap();
|
|
|
|
|
+// //记录一个id
|
|
|
|
|
+// _landMap.put("landId", otherPlayerLand.getConfigLandId());
|
|
|
|
|
+// //
|
|
|
|
|
+// _landMap.put("stealAmount", _finalStealAmount);
|
|
|
|
|
+//
|
|
|
|
|
+// //固定成本
|
|
|
|
|
+// _landMap.put("cost", otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb());
|
|
|
|
|
+// //当前利润
|
|
|
|
|
+// _landMap.put("profit", _profit);
|
|
|
|
|
+// //打印一个比例
|
|
|
|
|
+// _landMap.put("profitRatio", profitConfig);
|
|
|
|
|
+// _landMap.put("intervalStealRatio", _stealRatio);
|
|
|
|
|
+// _landMap.put("finallyGetRatioConfig", finallyGetRatioConfig);
|
|
|
|
|
+//
|
|
|
|
|
+// _finalStealAmountSum = DoubleUtil.add(_finalStealAmount, _finalStealAmountSum);
|
|
|
|
|
+// _stealLandInfos.add(_landMap);
|
|
|
|
|
+// // 需要redis 解锁
|
|
|
|
|
+// redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
|
+// // 需要redis 解锁
|
|
|
|
|
+// redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
|
|
+// throw new RuntimeException(e.getMessage());
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// map.put("msg", "偷取果实.");
|
|
|
|
|
+// map.put("steals", _stealLandInfos);
|
|
|
|
|
+// map.put("stealSum", _finalStealAmountSum);
|
|
|
|
|
+//
|
|
|
|
|
+// if (_stealLandInfos.size() > 0) {
|
|
|
|
|
+// //todo 体力值可以后台配置
|
|
|
|
|
+// Integer _addStrength = comUsersVo.getSnb() < comSettingVo.getDeductSnb() ? comSettingVo.getSnbUnitStrength() : comSettingVo.getUnitStrength();
|
|
|
|
|
+// playersAttribute.setStrength(playersAttribute.getStrength() + _addStrength);
|
|
|
|
|
+// comPlayersAttriService.save(playersAttribute);
|
|
|
|
|
+// ComPlayersAttriSimpleVo comPlayersAttriSimpleVo = CopyUtil.copy(playersAttribute, ComPlayersAttriSimpleVo.class);
|
|
|
|
|
+// //前端的显示,输出一个不小于0的体力值
|
|
|
|
|
+// Integer _outEnd = _maxStrength - Math.abs(playersAttribute.getStrength());
|
|
|
|
|
+// comPlayersAttriSimpleVo.setCurrentStrength(_outEnd < 0 ? 0 : _outEnd);
|
|
|
|
|
+// //最大值是配置的值和链上数据的值相加
|
|
|
|
|
+// comPlayersAttriSimpleVo.setMaxStrength(_maxStrength);
|
|
|
|
|
+//
|
|
|
|
|
+// map.put("playerAttribute", comPlayersAttriSimpleVo);
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// return Result.of(map);
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -984,6 +984,10 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
@RequestParam(value = "fruitId") Integer fruitId,
|
|
@RequestParam(value = "fruitId") Integer fruitId,
|
|
|
@RequestParam(value = "amount") Integer amount) {
|
|
@RequestParam(value = "amount") Integer amount) {
|
|
|
|
|
|
|
|
|
|
+ //防止输入负数
|
|
|
|
|
+ if(amount <= 0){
|
|
|
|
|
+ return Result.of(null, false, ResultEnum.FRUIT_AMOUNT_ERROR.getMessage(), ResultEnum.FRUIT_AMOUNT_ERROR.getCode());
|
|
|
|
|
+ }
|
|
|
//
|
|
//
|
|
|
ComFruitVo comFruitVo = comFruitService.findById(fruitId);
|
|
ComFruitVo comFruitVo = comFruitService.findById(fruitId);
|
|
|
|
|
|