/** * delOrUpList:(). <br> * TODO().<br> * * @author yxd * @param sumNumber * @param configId * @param forderNum * @return */ public List<PackItem> delOrUpList(int sumNumber, int configId, int forderNum, EntityDAO dao) { List<PackItem> resultLongAL = new ArrayList<PackItem>(); // 最后格子 物品数量 int lastNumber = sumNumber % forderNum; // 中间新开的格子数量 为 配置折叠数 int openGridNumber = sumNumber / forderNum; for (int i = 0; i < this.cells.size() && openGridNumber >= 0; i++) { if (this.cells.get(i) != null && this.cells.get(i).getItem() != null && this.cells.get(i).getItem().getItemData() != null && this.cells.get(i).getItem().getItemData().getConfigId() == configId) { // 表示找到 Item item = this.cells.get(i).getItem(); if (openGridNumber == 0) { // 更新 this.getCells() .get(i) .getItem() .getItemData() .setNumber(this.getCells().get(i).getItem().getItemData().getNumber() - lastNumber); dao.saveOrUpdate(item.getItemData()); PackItem pi = new PackItem(ItemStaticConfig.BAG_ADD_TYPE_UPDATE, -lastNumber, item); resultLongAL.add(pi); } else { // 删除 // 首先就是删除item this.getCells().get(item.getItemData().getIndexInBag()).setItem(null); // 删掉数据库 dao.delete(item.getItemData()); PackItem pi = new PackItem(ItemStaticConfig.BAG_ADD_TYPE_DEL, 0, item); resultLongAL.add(pi); } openGridNumber--; } } return resultLongAL; }
/** * 修改背包数据 updateItemBag:(). <br> * TODO().<br> * * @author yxd * @param ItemDataId * @param roleId * @return -2表示异常 ;-1 表示使用减少量小于0 不够用;1表示需要购买格子数 ;111表示不需要添加格子直接修改数量 */ public List<PackItem> updateItemBag(Item item, int count, long roleId, EntityDAO dao) { List<PackItem> resultLongAL = new ArrayList<PackItem>(); byte result = -2; if (item == null || roleId <= 0) { log.debug("物品编号不存在" + "角色编号:" + roleId); result = -2; PackItem pi = new PackItem(result, 0, null); resultLongAL.add(pi); return resultLongAL; } if (item != null && item.getItemData() != null && item.getProperty() != null) { if (this.getCells().get(item.getItemData().getIndexInBag()) != null && this.getCells().get(item.getItemData().getIndexInBag()).getItem() != null) { ItemData itemData = this.getCells().get(item.getItemData().getIndexInBag()).getItem().getItemData(); int folderableNum = item.getProperty().getFolderableNum(); if (itemData != null && itemData.getId() == item.getItemData().getId()) { // 找到该物品 if (this.summerItemDataByConfigId(itemData.getConfigId()) + count < 0) { // 数量不够 result = -1; PackItem pi = new PackItem(result, 0, null); resultLongAL.add(pi); return resultLongAL; } else if (itemData.getNumber() + count >= 0 && itemData.getNumber() + count <= folderableNum) { // 修改数量 dao.saveOrUpdate(itemData); this.getCells() .get(item.getItemData().getIndexInBag()) .getItem() .getItemData() .setNumber(itemData.getNumber() + count); result = 111; PackItem pi0 = new PackItem(result, 0, null); resultLongAL.add(pi0); PackItem pi = new PackItem( ItemStaticConfig.BAG_ADD_TYPE_UPDATE, count, this.cells.get(itemData.getIndexInBag()).getItem()); resultLongAL.add(pi); if (itemData.getNumber() == 0) { this.getCells().get(item.getItemData().getIndexInBag()).setItem(null); // 删掉数据库 dao.delete(itemData); PackItem pi2 = new PackItem(ItemStaticConfig.BAG_ADD_TYPE_DEL, 0, item); resultLongAL.add(pi2); } } else if (itemData.getNumber() + count > folderableNum) { boolean isCanfolderable = false; if (folderableNum > 1) { isCanfolderable = true; } else { isCanfolderable = false; } byte addItemType = this.addGridNumber(item.getProperty(), itemData, count, isCanfolderable); if (addItemType == -1) { // 表示添加失败 需要买格子 result = -1; PackItem pi = new PackItem(result, 0, null); resultLongAL.add(pi); return resultLongAL; } else { result = 111; PackItem pi = new PackItem(result, 0, null); resultLongAL.add(pi); resultLongAL.addAll(addItem(addItemType, item, itemData, count, roleId, dao)); return resultLongAL; } } else if (this.summerItemDataByConfigId(itemData.getConfigId()) + count > 0 && itemData.getNumber() + count < 0) { // 这种就是要计算删除和修改 result = 111; PackItem pi0 = new PackItem(result, 0, null); resultLongAL.add(pi0); int delNumner = item.getItemData().getNumber(); // 首先就是删除item this.getCells().get(item.getItemData().getIndexInBag()).setItem(null); // 删掉数据库 dao.delete(itemData); PackItem pi = new PackItem(ItemStaticConfig.BAG_ADD_TYPE_DEL, 0, item); resultLongAL.add(pi); // 计算剩下的数量与格子删除关系 resultLongAL.addAll( delOrUpList(-(count + delNumner), itemData.getConfigId(), folderableNum, dao)); } } else { log.error("itemdata 不存在"); } } else { log.error("itemData不存在"); } } else { log.error("数据异常"); } return resultLongAL; }