Beispiel #1
0
  /**
   * 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;
  }
Beispiel #2
0
  /**
   * 创建一个新的格子对象数据
   *
   * <p>addOrUpdate 0表示添加 1表示是新增进来的 openNewGrid:(). <br>
   * TODO().<br>
   *
   * @author yxd
   * @return
   */
  public Item openNewGrid(
      Item temporaryItem1, int count, long roleId, EntityDAO dao, int addOrUpdate) {
    ItemData itemTemporaryData = new ItemData();
    // 根据模板编号创建新道具
    Item item = null;
    int itemDateCellIndex = -1;
    if (isHasNullCell() == -1) {
      itemDateCellIndex = index;
    } else {
      itemDateCellIndex = isHasNullCell();
    }
    long id = 0;
    if (temporaryItem1 instanceof EquitItem) { // 如果是装备
      EquitItem equitItem = (EquitItem) temporaryItem1;

      if (addOrUpdate == 0) { // 普通添加
        item = temporaryItem1;
        id = temporaryItem1.getId();
      } else if (addOrUpdate == 1) { // 超过格子添加
        item = ItemManage.createItem(equitItem.getProperty().getId());
        id = item.getId();
      }

      itemTemporaryData.setId(id);
      itemTemporaryData.setConfigId(equitItem.getProperty().getId());
      itemTemporaryData.setItemType(equitItem.getProperty().getBagClass());
      itemTemporaryData.setNumber(count);
      itemTemporaryData.setQuality(equitItem.getProperty().getQuality());
      itemTemporaryData.setIndexInBag(itemDateCellIndex);
      itemTemporaryData.setRoleId(roleId);
      // 设置装备的固有属性
      itemTemporaryData.setPos(-1); // 装备绑定位
      itemTemporaryData.setScore(equitItem.getScore()); // 初始化分数
      itemTemporaryData.setSocket(equitItem.getBornSocket()); // 初始化孔
      item.setItemData(itemTemporaryData);
      cells.get(itemDateCellIndex).setItem(item);
      if (isHasNullCell() == -1) {
        index++;
      }
      dao.saveOrUpdate(item.getItemData());

    } else if (temporaryItem1 instanceof CommonToolItem) { // 如果是普通道具
      CommonToolItem temporaryItem = (CommonToolItem) temporaryItem1;

      if (addOrUpdate == 0) { // 普通添加
        item = temporaryItem1;
        id = temporaryItem1.getId();
      } else if (addOrUpdate == 1) { // 超过格子添加
        item = ItemManage.createItem(temporaryItem.getProperty().getId());
        id = item.getId();
      }

      itemTemporaryData.setId(id);
      itemTemporaryData.setConfigId(temporaryItem.getProperty().getId());
      itemTemporaryData.setItemType(temporaryItem.getProperty().getBagClass());
      itemTemporaryData.setNumber(count);
      itemTemporaryData.setQuality(temporaryItem.getProperty().getQuality());
      itemTemporaryData.setIndexInBag(itemDateCellIndex);
      itemTemporaryData.setRoleId(roleId);
      item.setItemData(itemTemporaryData);
      cells.get(itemDateCellIndex).setItem(item);
      if (isHasNullCell() == -1) {
        index++;
      }
      dao.saveOrUpdate(item.getItemData());
    }

    return item;
  }
Beispiel #3
0
  /**
   * 修改背包数据 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;
  }
Beispiel #4
0
  /**
   * addItem:(). <br>
   * TODO().<br>
   *
   * @author yxd
   * @param itemId 道具编号
   * @param count 道具数量
   * @return
   */
  public List<PackItem> addItem(
      long addItemType,
      Item temporaryItem,
      ItemData itemData,
      int count,
      long roleId,
      EntityDAO dao) {
    List<PackItem> resultLongAL = new ArrayList<PackItem>();
    if (addItemType == 0) { // 不需要添加 直接修改数字
      if (itemData != null) {
        if (this.cells.get(itemData.getIndexInBag()) != null
            && this.cells.get(itemData.getIndexInBag()).getItem() != null
            && this.cells.get(itemData.getIndexInBag()).getItem().getItemData() != null) {
          this.cells
              .get(itemData.getIndexInBag())
              .getItem()
              .getItemData()
              .setNumber(itemData.getNumber() + count);
          dao.saveOrUpdate(itemData);
          PackItem pi =
              new PackItem(
                  ItemStaticConfig.BAG_ADD_TYPE_UPDATE,
                  count,
                  this.cells.get(itemData.getIndexInBag()).getItem());
          resultLongAL.add(pi);
        }
      }
    } else {
      // 都先填满第一个格子
      Item item = null;
      if (itemData != null) {
        int teapNumber = itemData.getNumber();
        if (this.cells.get(itemData.getIndexInBag()) != null
            && this.cells.get(itemData.getIndexInBag()).getItem() != null
            && this.cells.get(itemData.getIndexInBag()).getItem().getItemData() != null) {
          this.cells
              .get(itemData.getIndexInBag())
              .getItem()
              .getItemData()
              .setNumber(temporaryItem.getProperty().getFolderableNum());
          dao.saveOrUpdate(itemData);
          PackItem pi =
              new PackItem(
                  ItemStaticConfig.BAG_ADD_TYPE_UPDATE,
                  temporaryItem.getProperty().getFolderableNum() - teapNumber,
                  this.cells.get(itemData.getIndexInBag()).getItem());
          resultLongAL.add(pi);
        }

        // 最后格子 物品数量
        int lastNumber =
            (teapNumber + count - temporaryItem.getProperty().getFolderableNum())
                % temporaryItem.getProperty().getFolderableNum();
        lastNumber = lastNumber == 0 ? temporaryItem.getProperty().getFolderableNum() : lastNumber;

        for (int j = 0; j < addItemType; j++) {

          if (j == addItemType - 1) { // 最后一个给子
            item = openNewGrid(temporaryItem, lastNumber, roleId, dao, 1);
            PackItem pi = new PackItem(ItemStaticConfig.BAG_ADD_TYPE_ADD, 0, item);
            resultLongAL.add(pi);
          } else {
            item =
                openNewGrid(
                    temporaryItem, temporaryItem.getProperty().getFolderableNum(), roleId, dao, 1);
            PackItem pi = new PackItem(ItemStaticConfig.BAG_ADD_TYPE_ADD, 0, item);
            resultLongAL.add(pi);
          }
        }
      } else {
        // 最后格子 物品数量
        int lastNumber = count % temporaryItem.getProperty().getFolderableNum();
        lastNumber = lastNumber == 0 ? temporaryItem.getProperty().getFolderableNum() : lastNumber;
        long id = 0;
        for (int j = 0; j < addItemType; j++) {

          if (j == addItemType - 1) { // 最后一个给子
            item = openNewGrid(temporaryItem, lastNumber, roleId, dao, 1);
            PackItem pi = new PackItem(ItemStaticConfig.BAG_ADD_TYPE_ADD, 0, item);
            resultLongAL.add(pi);
          } else {
            item =
                openNewGrid(
                    temporaryItem, temporaryItem.getProperty().getFolderableNum(), roleId, dao, 1);
            PackItem pi = new PackItem(ItemStaticConfig.BAG_ADD_TYPE_ADD, 0, item);
            resultLongAL.add(pi);
          }
        }
      }
    }
    return resultLongAL;
  }