| 
					
				 | 
			
			
				@@ -0,0 +1,498 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.td.boss.game.complayergoods.controller; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.TypeReference; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.common.controller.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.common.pojo.Result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.config.enums.ResultEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.game.comequipattributes.pojo.ComEquipAttributes; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.game.comequipattributes.service.ComEquipAttributesService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.game.comequipchest.pojo.ComEquipChest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.game.comequipchest.service.ComEquipChestService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.game.comequiptype.pojo.ComEquipType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.game.comequiptype.service.ComEquipTypeService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.game.complayergoods.pojo.ComPlayerGoods; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.game.complayergoods.vo.ComPlayerGoodsVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.game.complayergoods.service.ComPlayerGoodsService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.game.complayergoods.vo.PlayerGoodsVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.util.JsonUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.util.KeyUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.td.boss.util.NumUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.web.bind.annotation.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import oshi.json.util.JsonUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Slf4j 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@RestController 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@RequestMapping("/game/comPlayerGoods/") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo, ComPlayerGoods, String> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ComPlayerGoodsService comPlayerGoodsService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ComEquipChestService comEquipChestService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ComEquipTypeService comEquipTypeService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ComEquipAttributesService comEquipAttributesService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 获取宝箱,存入背包 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 如果参数不存在type,就random一个宝箱返回 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param playerId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @GetMapping("getChest") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public Result<Map> getChest(@RequestParam("playerId") Integer playerId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                @RequestParam(value = "type",required = false)Integer type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //todo 查询全部宝箱出来后,暂时先随机返回一个宝箱奖励 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ComEquipChest> comEquipChests = comEquipChestService.findAllEquipChest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (comEquipChests.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(null, false, ResultEnum.PLAYER_NO_CHEST_INFO.getMessage(), ResultEnum.PLAYER_NO_CHEST_INFO.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComEquipChest comEquipChest = new ComEquipChest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //如果type存在,生成type类型宝箱 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(type != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for(ComEquipChest tempChest : comEquipChests){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(type == tempChest.getType()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    comEquipChest = tempChest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comEquipChest =  comEquipChests.get(new Random().nextInt(comEquipChests.size())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map resultMap = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("name",comEquipChest.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("type",comEquipChest.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //先获取玩家全部背包数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ComPlayerGoods> comPlayerGoodsList = comPlayerGoodsService.findAllByPlayerId(playerId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //1.背包不存在物品,直接添加 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (comPlayerGoodsList.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //背包没有数据,创建一个新宝箱存储到背包 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ComPlayerGoods comPlayerGoods = new ComPlayerGoods(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setGoodsId(KeyUtil.genUniqueKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setPlayerId(playerId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setAmount(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setGoodsType(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setGoodsIndex(comEquipChest.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setName(comEquipChest.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setPosition(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoodsService.addComPlayerGoods(comPlayerGoods); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //返回给前端展示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            resultMap.put("goodsId",comPlayerGoods.getGoodsId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(resultMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //如果背包不为空,先获取position 背包位置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Integer> posList = comPlayerGoodsList.stream().map(e -> e.getPosition()).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int limit = 100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (posList.size() > limit) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //超过预设格子的长度 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(null, false, ResultEnum.PLAYER_GOODS_LIMIT_ERROR.getMessage(), ResultEnum.PLAYER_GOODS_LIMIT_ERROR.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //从背包数据获取对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComPlayerGoods getComPlayerGoods = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (ComPlayerGoods temp : comPlayerGoodsList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (temp.getGoodsIndex() == comEquipChest.getType() && temp.getGoodsType() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                getComPlayerGoods = temp; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //2.如果背包匹配不到数据,添加 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (getComPlayerGoods == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //背包没有数据,创建一个新宝箱存储到背包 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            getComPlayerGoods = new ComPlayerGoods(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            getComPlayerGoods.setGoodsId(KeyUtil.genUniqueKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            getComPlayerGoods.setPlayerId(playerId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            getComPlayerGoods.setAmount(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            getComPlayerGoods.setGoodsType(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            getComPlayerGoods.setGoodsIndex(comEquipChest.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            getComPlayerGoods.setName(comEquipChest.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //需要判断添加位置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //todo 暂时设定 100 个格子,用于存放物品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int addPos = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (int i = 0; i < limit; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //获取第一个匹配的空位置,返回addPos 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!posList.contains(i)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    addPos = i; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.info("占用的位置addPos:" + addPos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            getComPlayerGoods.setPosition(addPos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoodsService.addComPlayerGoods(getComPlayerGoods); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //返回给前端展示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            resultMap.put("goodsId",getComPlayerGoods.getGoodsId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(resultMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //3.如果存在物品,更新对应物品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setAmount(getComPlayerGoods.getAmount() + 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        comPlayerGoodsService.addComPlayerGoods(getComPlayerGoods); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //返回给前端展示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("goodsId",getComPlayerGoods.getGoodsId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Result.of(resultMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 获取装备,存入背包 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param playerId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @GetMapping("getRandomEquip") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public Result<Map> getEquip(@RequestParam(value = "userId") String userId,@RequestParam("playerId") Integer playerId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //todo 查询全部装备出来后,暂时先随机返回一个装备奖励 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ComEquipType> comEquipTypeList = comEquipTypeService.findAllComEquipType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (comEquipTypeList.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(null, false, ResultEnum.PLAYER_NO_EQUIP_TYPE.getMessage(), ResultEnum.PLAYER_NO_EQUIP_TYPE.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComEquipType comEquipType = comEquipTypeList.get(new Random().nextInt(comEquipTypeList.size())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //获取装备属性计算方式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComEquipAttributes mainEquipAttributes = comEquipAttributesService.findByType(comEquipType.getProperty()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //过滤主属性 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ComEquipAttributes> comEquipAttributesList = comEquipAttributesService.findAll().stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .filter(e -> !e.getType().equals(mainEquipAttributes.getType())).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Random random = new Random(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map resultMap = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String mainPro, addonPro = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //计算主属性 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int max = mainEquipAttributes.getMax(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int min = mainEquipAttributes.getMin(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int randomMainPro = random.nextInt(max - min + 1) + min; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map mainMap = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mainMap.put(mainEquipAttributes.getName(),randomMainPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mainPro = JSONObject.toJSONString(mainMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map addonMap = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer randomIndex = new Random().nextInt(100); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer level = 0;//装备等级(0 白色 ,1 绿色, 2 蓝色 ,3黄色,4红色 ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (randomIndex <= 20) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //红色装备:随机三条副属性1-4 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonMap =  getAddonProperty(comEquipAttributesList, 4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonPro = JSONObject.toJSONString(addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            level = 4; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else if (randomIndex <= 40) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //黄色装备:随机两条副属性1-3 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonMap =  getAddonProperty(comEquipAttributesList, 3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonPro = JSONObject.toJSONString(addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            level = 3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else if (randomIndex <= 60) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //蓝色装备:随机一条副属性1-2 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonMap =  getAddonProperty(comEquipAttributesList, 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonPro = JSONObject.toJSONString(addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            level = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else if (randomIndex <= 80) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //绿色装备:随机一条副属性1-1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonMap =  getAddonProperty(comEquipAttributesList, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonPro = JSONObject.toJSONString(addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            level = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //白色装备:主属性1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //先获取玩家全部背包数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ComPlayerGoods> comPlayerGoodsList = comPlayerGoodsService.findAllByPlayerId(playerId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //1.背包不存在物品,直接添加 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (comPlayerGoodsList.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //背包没有数据,创建一个新宝箱存储到背包 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ComPlayerGoods comPlayerGoods = new ComPlayerGoods(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setGoodsId(KeyUtil.genUniqueKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setPlayerId(playerId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setAmount(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setGoodsType(1); //设置装备类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setGoodsIndex(comEquipType.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setName(comEquipType.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setPosition(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setMainProperty(mainPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setAddonProperty(addonPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoods.setLevel(level); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoodsService.addComPlayerGoods(comPlayerGoods); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //返回给前端展示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            resultMap.put("name",comPlayerGoods.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            resultMap.put("amount",comPlayerGoods.getAmount()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            resultMap.put("position",comPlayerGoods.getPosition()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            resultMap.put("mainProperty",mainMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            resultMap.put("addonProperty",addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            resultMap.put("level",level); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(resultMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //如果背包不为空,先获取position 背包位置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Integer> posList = comPlayerGoodsList.stream().map(e -> e.getPosition()).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int limit = 100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (posList.size() > limit) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //超过预设格子的长度 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(null, false, ResultEnum.PLAYER_GOODS_LIMIT_ERROR.getMessage(), ResultEnum.PLAYER_GOODS_LIMIT_ERROR.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //从背包数据获取对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComPlayerGoods getComPlayerGoods = new ComPlayerGoods(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setGoodsId(KeyUtil.genUniqueKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setPlayerId(playerId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setAmount(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setGoodsType(1);//装备设置1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setGoodsIndex(comEquipType.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setName(comEquipType.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //需要判断添加位置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //todo 暂时设定 100 个格子,用于存放物品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int addPos = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < limit; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //获取第一个匹配的空位置,返回addPos 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (!posList.contains(i)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                addPos = i; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                log.info("占用的位置addPos:" + addPos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setPosition(addPos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setMainProperty(mainPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setAddonProperty(addonPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getComPlayerGoods.setLevel(level); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        comPlayerGoodsService.addComPlayerGoods(getComPlayerGoods); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //返回给前端展示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("name",getComPlayerGoods.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("amount",getComPlayerGoods.getAmount()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("position",getComPlayerGoods.getPosition()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("mainProperty",mainMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("addonProperty",addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("level",level); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Result.of(resultMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 开启宝箱,获取装备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param playerId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param goodsId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param openType 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @GetMapping("openChest") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public Result<Map> openChest( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @RequestParam("playerId") Integer playerId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @RequestParam("goodsId") String goodsId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @RequestParam(value = "openType",defaultValue = "limit") String openType 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map resultMap = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //先获取玩家全部背包数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ComPlayerGoods> comPlayerGoodsList = comPlayerGoodsService.findAllByPlayerId(playerId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //先判断背包是否存对应宝箱对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComPlayerGoods comPlayerGoodsChest = comPlayerGoodsList.stream().filter(e->e.getGoodsId().equals(goodsId)).findFirst().orElse(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (comPlayerGoodsChest == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(null, false, ResultEnum.PLAYER_GOODS_NO_CHEST.getMessage(), ResultEnum.PLAYER_GOODS_NO_CHEST.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(comPlayerGoodsChest.getGoodsType() !=0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //如果不是chest类型,返回错误提示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(null, false, ResultEnum.PLAYER_GOODS_NOT_CHEST_TYPE.getMessage(), ResultEnum.PLAYER_GOODS_NOT_CHEST_TYPE.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //1.获取宝箱对应的概率 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComEquipChest comEquipChest = comEquipChestService.findByType(comPlayerGoodsChest.getGoodsIndex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (comEquipChest == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(null, false, ResultEnum.PLAYER_NO_CHEST_INFO.getMessage(), ResultEnum.PLAYER_NO_CHEST_INFO.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Random random =  new Random(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //2.获取随机的的装备,并设置属性.属性根据不同装备计算 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //todo  根据条件区分 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComEquipType comEquipType = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ComEquipType> comEquipTypeList = comEquipTypeService.findAllComEquipType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(openType.equals("noLimit")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //随机装备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comEquipType = comEquipTypeList.get(random.nextInt(comEquipTypeList.size())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //获取背包的装备,随机返回剩余的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<Integer>  goodsIndexList =  comPlayerGoodsList.stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .filter(e->e.getGoodsType().equals(1)).map(e->e.getGoodsIndex()).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<ComEquipType> otherComEquipTypeList = comEquipTypeList.stream().filter(e->!goodsIndexList.contains(e.getType())).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(otherComEquipTypeList.size() == 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // todo 如果已经获取完装备,暂时返回一个提示,理论上宝箱不应该发放10个。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return Result.of(null,false,ResultEnum.PLAYER_GOODS_NO_QUIP_REQUIRED.getMessage(),ResultEnum.PLAYER_GOODS_NO_QUIP_REQUIRED.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comEquipType = otherComEquipTypeList.get(random.nextInt(otherComEquipTypeList.size())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //3.获取装备属性计算方式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComEquipAttributes mainEquipAttributes = comEquipAttributesService.findByType(comEquipType.getProperty()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //过滤主属性 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ComEquipAttributes> comEquipAttributesList = comEquipAttributesService.findAll().stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .filter(e -> !e.getType().equals(mainEquipAttributes.getType())).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String mainPro, addonPro = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //计算主属性 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int max = mainEquipAttributes.getMax(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int min = mainEquipAttributes.getMin(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int randomMainPro = random.nextInt(max - min + 1) + min; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map mainMap = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mainMap.put(mainEquipAttributes.getName(),randomMainPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mainPro = JSONObject.toJSONString(mainMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map addonMap = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer randomIndex = new Random().nextInt(100); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer level = 0;//装备等级(0 白色 ,1 绿色, 2 蓝色 ,3黄色,4红色 ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (randomIndex <= comEquipChest.getRed()) { //5 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //红色装备:随机三条副属性1-4 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonMap =  getAddonProperty(comEquipAttributesList, 4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonPro = JSONObject.toJSONString(addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            level = 4; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else if (randomIndex <= comEquipChest.getRed()+comEquipChest.getYellow()) { //10 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //黄色装备:随机两条副属性1-3 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonMap =  getAddonProperty(comEquipAttributesList, 3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonPro = JSONObject.toJSONString(addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            level = 3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else if (randomIndex <= comEquipChest.getRed()+comEquipChest.getYellow()+comEquipChest.getBlue()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //蓝色装备:随机一条副属性1-2 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonMap =  getAddonProperty(comEquipAttributesList, 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonPro = JSONObject.toJSONString(addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            level = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else if (randomIndex <= comEquipChest.getRed()+comEquipChest.getYellow()+comEquipChest.getBlue()+comEquipChest.getGreen()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //绿色装备:随机一条副属性1-1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonMap =  getAddonProperty(comEquipAttributesList, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addonPro = JSONObject.toJSONString(addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            level = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //白色装备:主属性1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //开箱子,背包定不为空,先获取position 背包位置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Integer> posList = comPlayerGoodsList.stream().map(e -> e.getPosition()).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int limit = 100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (posList.size() > limit) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //超过预设格子的长度 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(null, false, ResultEnum.PLAYER_GOODS_LIMIT_ERROR.getMessage(), ResultEnum.PLAYER_GOODS_LIMIT_ERROR.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //直接存储新的装备,装备由于属性随机,不用添加Amount 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComPlayerGoods getEquip = new ComPlayerGoods(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getEquip.setGoodsId(KeyUtil.genUniqueKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getEquip.setPlayerId(comPlayerGoodsChest.getPlayerId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getEquip.setAmount(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getEquip.setGoodsType(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getEquip.setGoodsIndex(comEquipType.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getEquip.setName(comEquipType.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //需要判断添加位置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //todo 暂时设定 100 个格子,用于存放物品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int addPos = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < limit; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //获取第一个匹配的空位置,返回addPos 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (!posList.contains(i)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                addPos = i; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                log.info("占用的位置addPos:" + addPos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getEquip.setPosition(addPos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getEquip.setMainProperty(mainPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getEquip.setAddonProperty(addonPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        getEquip.setLevel(level); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        comPlayerGoodsService.addComPlayerGoods(getEquip); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //添加装备成功,处理宝箱 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int amount = comPlayerGoodsChest.getAmount(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (amount - 1 > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoodsChest.setAmount(amount - 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoodsService.addComPlayerGoods(comPlayerGoodsChest); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //删除 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            comPlayerGoodsService.delete(comPlayerGoodsChest.getGoodsId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //返回给前端展示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("name",getEquip.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("amount",getEquip.getAmount()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("position",getEquip.getPosition()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("mainProperty",mainMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("addonProperty",addonMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        resultMap.put("level",level); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Result.of(resultMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Map getAddonProperty(List<ComEquipAttributes> comEquipAttributesList, Integer Number) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int[] randomArray = NumUtil.randomArray(0, comEquipAttributesList.size()-1, Number); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, Object> map = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int index : randomArray) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ComEquipAttributes comEquipAttributes = comEquipAttributesList.get(index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int max = comEquipAttributes.getMax(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int min = comEquipAttributes.getMin(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int randomAddonPro = new Random().nextInt(max - min + 1) + min; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            map.put(comEquipAttributes.getName(), randomAddonPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 获取用户背包 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param playerId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @GetMapping("getPlayerGoods") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public Result<List<PlayerGoodsVo>> getPlayerGoods(@RequestParam("playerId") Integer playerId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //todo 先获取玩家全部背包数据,暂时不做分页处理,因为玩家数据最多 100 条 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<PlayerGoodsVo> playerGoodsList = comPlayerGoodsService.findAllByPlayerId(playerId).stream().map(e->{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PlayerGoodsVo playerGoodsVo = new PlayerGoodsVo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            playerGoodsVo.setGoodsId(e.getGoodsId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            playerGoodsVo.setGoodsIndex(e.getGoodsIndex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            playerGoodsVo.setGoodsType(e.getGoodsType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            playerGoodsVo.setName(e.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            playerGoodsVo.setAmount(e.getAmount()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            playerGoodsVo.setPosition(e.getPosition()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            playerGoodsVo.setLevel(e.getLevel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<String,Integer> mainPro = JSONObject.parseObject(e.getMainProperty(),new TypeReference<Map<String,Integer>>(){}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            playerGoodsVo.setMainProperty(mainPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<String,Integer> addonPro = JSONObject.parseObject(e.getAddonProperty(),new TypeReference<Map<String,Integer>>(){}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            playerGoodsVo.setAddonProperty(addonPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            playerGoodsVo.setIsWear(e.getIsWear()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return  playerGoodsVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //返回给前端展示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Result.of(playerGoodsList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 穿戴装备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param goodsId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param isWear 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @PostMapping("wearableEquip") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public Result<PlayerGoodsVo> WearableEquip(@RequestParam("goodsId") String goodsId, @RequestParam("isWear") Integer isWear 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(isWear != 0 && isWear != 1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Result.of(null,false,ResultEnum.PLAYER_GOODS_WEAR_NUM_ERROR.getMessage(),ResultEnum.PLAYER_GOODS_WEAR_NUM_ERROR.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ComPlayerGoods wearableEquip =  comPlayerGoodsService.findById(goodsId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        wearableEquip.setIsWear(isWear); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        wearableEquip =  comPlayerGoodsService.addComPlayerGoods(wearableEquip); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        PlayerGoodsVo playerGoodsVo = new PlayerGoodsVo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        playerGoodsVo.setGoodsId(wearableEquip.getGoodsId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        playerGoodsVo.setGoodsIndex(wearableEquip.getGoodsIndex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        playerGoodsVo.setGoodsType(wearableEquip.getGoodsType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        playerGoodsVo.setName(wearableEquip.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        playerGoodsVo.setAmount(wearableEquip.getAmount()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        playerGoodsVo.setPosition(wearableEquip.getPosition()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        playerGoodsVo.setLevel(wearableEquip.getLevel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String,Integer> mainPro = JSONObject.parseObject(wearableEquip.getMainProperty(),new TypeReference<Map<String,Integer>>(){}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        playerGoodsVo.setMainProperty(mainPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String,Integer> addonPro = JSONObject.parseObject(wearableEquip.getAddonProperty(),new TypeReference<Map<String,Integer>>(){}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        playerGoodsVo.setAddonProperty(addonPro); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        playerGoodsVo.setIsWear(wearableEquip.getIsWear()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //返回给前端展示 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Result.of(playerGoodsVo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |