Exemple #1
0
 @Override
 protected void writeImpl() {
   writeC(0xFE);
   writeH(0x6C);
   writeD(_item.getObjectId());
   writeD(_item.getDisplayId());
   writeD(_item.getLocationSlot());
   writeQ(_item.getCount());
   writeH(_item.getItem().getType2());
   writeH(_item.getCustomType1());
   writeH(_item.isEquipped() ? 0x01 : 0x00);
   writeD(_item.getItem().getBodyPart());
   writeH(_item.getEnchantLevel());
   writeH(_item.getCustomType2());
   if (_item.isAugmented()) {
     writeD(_item.getAugmentation().getAugmentationId());
   } else {
     writeD(0x00);
   }
   writeD(_item.getMana());
   writeD(_item.isTimeLimitedItem() ? (int) (_item.getRemainingTime() / 1000) : -9999);
   writeH(_item.getAttackElementType());
   writeH(_item.getAttackElementPower());
   for (byte i = 0; i < 6; i++) {
     writeH(_item.getElementDefAttr(i));
   }
   // Enchant Effects
   for (int op : _item.getEnchantOptions()) {
     writeH(op);
   }
 }
  @Override
  protected void readImpl() {
    L2PcInstance player = getClient().getActiveChar();
    if (player == null) {
      return;
    }
    int count = readD();
    if ((count < 1)
        || (count > Config.MAX_ITEM_IN_PACKET)
        || ((count * BATCH_LENGTH) != _buf.remaining())) {
      return;
    }

    _items = new Item[count];
    for (int i = 0; i < count; i++) {
      int itemId = readD();
      int enchantLevel = readD();

      long cnt = readQ();
      long price = readQ();

      if ((itemId < 1) || (cnt < 1) || (price < 0)) {
        _items = null;
        return;
      }
      int attackAttribute = readH(); // Attack Attribute Type
      int attackAttributeValue = readH(); // Attack Attribute Value
      int defenseAttributes[] = new int[6];
      for (int h = 0; h < 6; h++) {
        defenseAttributes[i] = readH(); // Defense attributes
      }
      int appearanceId = readD(); // Appearance ID
      boolean canUse = false;
      for (L2ItemInstance item : player.getInventory().getItemsByItemId(itemId)) {
        if ((enchantLevel == item.getEnchantLevel())
            && (attackAttribute == item.getAttackElementType())
            && (attackAttributeValue == item.getAttackElementPower())
            && (appearanceId == item.getVisualId())
            && (item.getElementDefAttr((byte) 0) == defenseAttributes[0])
            && (item.getElementDefAttr((byte) 1) == defenseAttributes[1])
            && (item.getElementDefAttr((byte) 2) == defenseAttributes[2])
            && (item.getElementDefAttr((byte) 3) == defenseAttributes[3])
            && (item.getElementDefAttr((byte) 4) == defenseAttributes[4])
            && (item.getElementDefAttr((byte) 5) == defenseAttributes[5])) {
          canUse = true;
          break;
        }
      }
      if (!canUse) {
        enchantLevel = 0;
        attackAttribute = -1;
        attackAttributeValue = 0;
        defenseAttributes[0] = 0;
        defenseAttributes[1] = 0;
        defenseAttributes[2] = 0;
        defenseAttributes[3] = 0;
        defenseAttributes[4] = 0;
        defenseAttributes[5] = 0;
        appearanceId = 0;
      }
      _items[i] =
          new Item(
              itemId,
              cnt,
              price,
              enchantLevel,
              attackAttribute,
              attackAttributeValue,
              defenseAttributes,
              appearanceId);
    }
  }