Esempio n. 1
0
  /**
   * 仅仅判断能不能添加物品 onlyCanAddItem:(). <br>
   * TODO().<br>
   *
   * @author yxd
   * @param itemTypeId
   * @param count
   * @return
   */
  public byte onlyCanAddBuyItem(int itemTypeId, int count) {
    byte addItemType = -1;
    Property property = ItemConfigLoad.getPrototype(itemTypeId);
    ItemData itemData = null;
    if (property.getFolderableNum() > 1) { // 表示可以折叠
      for (int i = 0; i < this.cells.size(); 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() == itemTypeId
            && this.cells.get(i).getItem().getItemData().getNumber()
                < property.getFolderableNum()) { // 表示找到
          itemData = this.cells.get(i).getItem().getItemData();
          addItemType = this.addGridNumber(property, itemData, count, true);

          break;
        }
        itemData = null;
        // 没有找到的情况下
        if (this.cells.size() - 1 == i) {
          // itemData = this.cells.get(this.index).getItem().getItemData();
          addItemType = this.addGridNumber(property, itemData, count, true);
        }
      }
    } else { // 表示不能被折叠

      addItemType = this.addGridNumber(property, itemData, count, false);
    }

    return addItemType;
  }
Esempio n. 2
0
  /**
   * addGridNumber:(). <br>
   * TODO().<br>
   *
   * @author yxd
   * @param item
   * @param itemData
   * @param count
   * @param canFolderable
   * @return -1 表示格子数不够需要添加格子;0 表示不需要添加
   */
  public byte addGridNumber(Property item, ItemData itemData, int count, boolean canFolderable) {
    byte gridNumber = -1;
    if (canFolderable) { // 可以折叠
      if (itemData != null) {
        if (itemData.getNumber() + count > item.getFolderableNum()) { // 开始计算格子数
          // 最后格子 物品数量
          int lastNumber =
              (itemData.getNumber() + count - item.getFolderableNum()) % item.getFolderableNum();
          // 中间新开的格子数量 为 配置折叠数
          int openGridNumber =
              (itemData.getNumber() + count - item.getFolderableNum()) / item.getFolderableNum();
          gridNumber = (byte) ((lastNumber == 0) ? openGridNumber : openGridNumber + 1);
          gridNumber = (gridNumber + index <= capacity) ? gridNumber : -1;
        } else if (itemData.getNumber() + count <= item.getFolderableNum()) {
          // 表示不需要格子
          gridNumber = 0;
        }
      } else {
        // 不存在该物品 直接新增一个
        // 最后格子 物品数量
        int lastNumber = count % item.getFolderableNum();
        // 中间新开的格子数量 为 配置折叠数
        int openGridNumber = count / item.getFolderableNum();
        gridNumber = (byte) ((lastNumber == 0) ? openGridNumber : openGridNumber + 1);
        gridNumber = (gridNumber + index <= capacity) ? gridNumber : -1;
      }

    } else { // 不能被折叠的情况
      gridNumber = (byte) ((count + index <= capacity) ? count : -1);
    }
    return gridNumber;
  }