コード例 #1
0
 public ExReplySentPost(Message msg) {
   _msg = msg;
   if (msg.hasAttachments()) {
     final ItemContainer attachments = msg.getAttachments();
     if ((attachments != null) && (attachments.getSize() > 0)) {
       _items = attachments.getItems();
     } else {
       _log.warning("Message " + msg.getId() + " has attachments but itemcontainer is empty.");
     }
   }
 }
コード例 #2
0
ファイル: PcRefund.java プロジェクト: zografakos/filemon
 @Override
 protected void addItem(L2ItemInstance item) {
   super.addItem(item);
   try {
     if (getSize() > 12) {
       L2ItemInstance removedItem;
       synchronized (_items) {
         removedItem = _items.remove(0);
       }
       if (removedItem != null) {
         ItemTable.getInstance().destroyItem("ClearRefund", removedItem, getOwner(), null);
         removedItem.updateDatabase(true);
       }
     }
   } catch (Exception e) {
     _log.log(Level.SEVERE, "addItem()", e);
   }
 }
コード例 #3
0
ファイル: ItemContainer.java プロジェクト: zografakos/filemon
  /**
   * Transfers item to another inventory
   *
   * @param process : String Identifier of process triggering this action
   * @param itemId : int Item Identifier of the item to be transfered
   * @param count : int Quantity of items to be transfered
   * @param actor : L2PcInstance Player requesting the item transfer
   * @param reference : Object Object referencing current action like NPC selling item or previous
   *     item in transformation
   * @return L2ItemInstance corresponding to the new item or the updated item in inventory
   */
  public L2ItemInstance transferItem(
      String process,
      int objectId,
      long count,
      ItemContainer target,
      L2PcInstance actor,
      Object reference) {
    if (target == null) {
      return null;
    }

    L2ItemInstance sourceitem = getItemByObjectId(objectId);
    if (sourceitem == null) {
      return null;
    }
    L2ItemInstance targetitem =
        sourceitem.isStackable() ? target.getItemByItemId(sourceitem.getItemId()) : null;

    synchronized (sourceitem) {
      // check if this item still present in this container
      if (getItemByObjectId(objectId) != sourceitem) {
        return null;
      }

      // Check if requested quantity is available
      if (count > sourceitem.getCount()) count = sourceitem.getCount();

      // If possible, move entire item object
      if (sourceitem.getCount() == count && targetitem == null) {
        removeItem(sourceitem);
        target.addItem(process, sourceitem, actor, reference);
        targetitem = sourceitem;
      } else {
        if (sourceitem.getCount() > count) // If possible, only update counts
        {
          sourceitem.changeCount(process, -count, actor, reference);
        } else
        // Otherwise destroy old item
        {
          removeItem(sourceitem);
          ItemTable.getInstance().destroyItem(process, sourceitem, actor, reference);
        }

        if (targetitem != null) // If possible, only update counts
        {
          targetitem.changeCount(process, count, actor, reference);
        } else
        // Otherwise add new item
        {
          targetitem = target.addItem(process, sourceitem.getItemId(), count, actor, reference);
        }
      }

      // Updates database
      sourceitem.updateDatabase(true);
      if (targetitem != sourceitem && targetitem != null) targetitem.updateDatabase();
      if (sourceitem.isAugmented()) sourceitem.getAugmentation().removeBonus(actor);
      refreshWeight();
      target.refreshWeight();
    }
    return targetitem;
  }