Package net.sf.l2j.gameserver.model

Examples of net.sf.l2j.gameserver.model.L2ItemInstance


  public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  {
    if (!(playable instanceof L2PcInstance)) return;

    L2PcInstance activeChar = (L2PcInstance)playable;
    L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
    L2Weapon weaponItem = activeChar.getActiveWeaponItem();
        int itemId = item.getItemId();

        // Check if Soulshot can be used
    if (weaponInst == null || weaponItem.getSoulShotCount() == 0)
    {
            if(!activeChar.getAutoSoulShot().containsKey(itemId))
                activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_SOULSHOTS));
      return;
    }

    // Check for correct grade
        int weaponGrade = weaponItem.getCrystalType();
        if ((weaponGrade == L2Item.CRYSTAL_NONE && itemId != 5789 && itemId != 1835) ||
      (weaponGrade == L2Item.CRYSTAL_D && itemId != 1463) ||
      (weaponGrade == L2Item.CRYSTAL_C && itemId != 1464) ||
      (weaponGrade == L2Item.CRYSTAL_B && itemId != 1465) ||
      (weaponGrade == L2Item.CRYSTAL_A && itemId != 1466) ||
      (weaponGrade == L2Item.CRYSTAL_S && itemId != 1467))
    {
            if(!activeChar.getAutoSoulShot().containsKey(itemId))
                activeChar.sendPacket(new SystemMessage(SystemMessageId.SOULSHOTS_GRADE_MISMATCH));
      return;
    }

        activeChar.soulShotLock.lock();
        try
        {
          // Check if Soulshot is already active
          if (weaponInst.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE)
            return;

          // Consume Soulshots if player has enough of them
          int saSSCount = (int)activeChar.getStat().calcStat(Stats.SOULSHOT_COUNT, 0, null, null);
          int SSCount = saSSCount == 0 ? weaponItem.getSoulShotCount() : saSSCount;

          if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), SSCount, null, false))
          {
            if(activeChar.getAutoSoulShot().containsKey(itemId))
            {
              activeChar.removeAutoSoulShot(itemId);
              activeChar.sendPacket(new ExAutoSoulShot(itemId, 0));

              SystemMessage sm = new SystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED);
              sm.addString(item.getItem().getName());
              activeChar.sendPacket(sm);
            }
            else activeChar.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_SOULSHOTS));
            return;
          }

          // Charge soulshot
          weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_SOULSHOT);
        }
        finally
        {
          activeChar.soulShotLock.unlock();
        }
View Full Code Here


    pet.updateEffectIcons(true);

    // set the flag on the control item to say that the pet has a name
    if (pet instanceof L2PetInstance)
    {
      L2ItemInstance controlItem = pet.getOwner().getInventory().getItemByObjectId(pet.getControlItemId());
      if (controlItem != null)
      {
        controlItem.setCustomType2(1);
        controlItem.updateDatabase();
        InventoryUpdate iu = new InventoryUpdate();
        iu.addModifiedItem(controlItem);
        activeChar.sendPacket(iu);
      }
    }
View Full Code Here

 
  @Override
  protected void runImpl()
  {
    L2PcInstance activeChar = getClient().getActiveChar();
    L2ItemInstance targetItem = (L2ItemInstance)L2World.getInstance().findObject(_targetItemObjId);

    if (activeChar == null) return;
    if (targetItem == null)
    {
      activeChar.sendPacket(new ExVariationCancelResult(0));
      return;
    }

    // cannot remove augmentation from a not augmented item
    if (!targetItem.isAugmented())
    {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.AUGMENTATION_REMOVAL_CAN_ONLY_BE_DONE_ON_AN_AUGMENTED_ITEM));
      activeChar.sendPacket(new ExVariationCancelResult(0));
      return;
    }

    // get the price
    int price=0;
    switch (targetItem.getItem().getItemGrade())
    {
      case L2Item.CRYSTAL_C:
        if (targetItem.getCrystalCount() < 1720)
          price = 95000;
        else if (targetItem.getCrystalCount() < 2452)
          price = 150000;
        else
          price = 210000;
        break;
      case L2Item.CRYSTAL_B:
        if (targetItem.getCrystalCount() < 1746)
          price = 240000;
        else
          price = 270000;
        break;
      case L2Item.CRYSTAL_A:
        if (targetItem.getCrystalCount() < 2160)
          price = 330000;
        else if (targetItem.getCrystalCount() < 2824)
          price = 390000;
        else
          price = 420000;
        break;
      case L2Item.CRYSTAL_S:
        price = 480000;
        break;
      // any other item type is not augmentable
      default:
        activeChar.sendPacket(new ExVariationCancelResult(0));
        return;
    }

    // try to reduce the players adena
    if (!activeChar.reduceAdena("RequestRefineCancel", price, null, true)) return;

    // unequip item
    if (targetItem.isEquipped()) activeChar.disarmWeapons();

    // remove the augmentation
    targetItem.removeAugmentation();

    // send ExVariationCancelResult
    activeChar.sendPacket(new ExVariationCancelResult(1));

    // send inventory update
    InventoryUpdate iu = new InventoryUpdate();
    iu.addModifiedItem(targetItem);
    activeChar.sendPacket(iu);

    // send system message
    SystemMessage sm = new SystemMessage(SystemMessageId.AUGMENTATION_HAS_BEEN_SUCCESSFULLY_REMOVED_FROM_YOUR_S1);
    sm.addString(targetItem.getItemName());
    activeChar.sendPacket(sm);
  }
View Full Code Here

    {
      int order = tradeList.getItems().size() + 1; // last item order + 1
      int itemID = Integer.parseInt(args[2]);
      int price = Integer.parseInt(args[3]);

      L2ItemInstance newItem = ItemTable.getInstance().createDummyItem(itemID);
      newItem.setPriceToSell(price);
      newItem.setCount(-1);
      tradeList.addItem(newItem);
      storeTradeList(itemID, price, tradeListID, order);

      activeChar.sendMessage("Added "+newItem.getItem().getName()+" to Trade List "+tradeList.getListId());
      showShopList(activeChar, tradeListID, 1);
      return;
    }

    NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
View Full Code Here

     * @return L2ItemInstance corresponding to the new item
   */
  public L2ItemInstance createItem(String process, int itemId, int count, L2PcInstance actor, L2Object reference)
  {
        // Create and Init the L2ItemInstance corresponding to the Item Identifier
    L2ItemInstance item = new L2ItemInstance(IdFactory.getInstance().getNextId(), itemId);

        if (process.equalsIgnoreCase("loot") && !Config.AUTO_LOOT)
        {
          ScheduledFuture<?> itemLootShedule;
          long delay = 0;
          // if in CommandChannel and was killing a World/RaidBoss
            if (reference != null && reference instanceof L2BossInstance || reference instanceof L2RaidBossInstance)
            {
              if(((L2Attackable)reference).getFirstCommandChannelAttacked() != null
                  && ((L2Attackable)reference).getFirstCommandChannelAttacked().meetRaidWarCondition(reference))
              {
                item.setOwnerId(((L2Attackable)reference).getFirstCommandChannelAttacked().getChannelLeader().getObjectId());
                delay = 300000;
              }
              else
              {
              delay = 15000;
              item.setOwnerId(actor.getObjectId());
              }
            }
            else
            {
              item.setOwnerId(actor.getObjectId());
            delay = 15000;
            }
            itemLootShedule  = ThreadPoolManager.getInstance().scheduleGeneral(new resetOwner(item), delay);
            item.setItemLootShedule(itemLootShedule);
        }

    if (Config.DEBUG) _log.fine("ItemTable: Item created  oid:" + item.getObjectId()+ " itemid:" + itemId);

    // Add the L2ItemInstance object to _allObjects of L2world
    L2World.getInstance().storeObject(item);

    // Set Item parameters
    if (item.isStackable() && count > 1) item.setCount(count);

    if (Config.LOG_ITEMS)
    {
      LogRecord record = new LogRecord(Level.INFO, "CREATE:" + process);
      record.setLoggerName("item");
View Full Code Here

  public L2ItemInstance createDummyItem(int itemId)
  {
    L2Item item = getTemplate(itemId);
    if (item == null)
      return null;
    L2ItemInstance temp = new L2ItemInstance(0, item);
    try
    {
      temp = new L2ItemInstance(0, itemId);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      // this can happen if the item templates were not initialized
    }

    if (temp.getItem() == null)
    {
      _log.warning("ItemTable: Item Template missing for Id: "+ itemId);
    }

    return temp;
View Full Code Here

  @Override
  protected
  void runImpl()
  {
    L2PcInstance activeChar = getClient().getActiveChar();
    L2ItemInstance item = (L2ItemInstance)L2World.getInstance().findObject(_itemId);

    if (activeChar == null || item == null) return;
    if (!item.isAugmented())
    {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.AUGMENTATION_REMOVAL_CAN_ONLY_BE_DONE_ON_AN_AUGMENTED_ITEM));
      return;
    }

    int price=0;
    switch (item.getItem().getItemGrade())
    {
      case L2Item.CRYSTAL_C:
        if (item.getCrystalCount() < 1720)
          price = 95000;
        else if (item.getCrystalCount() < 2452)
          price = 150000;
        else
          price = 210000;
        break;
      case L2Item.CRYSTAL_B:
        if (item.getCrystalCount() < 1746)
          price = 240000;
        else
          price = 270000;
        break;
      case L2Item.CRYSTAL_A:
        if (item.getCrystalCount() < 2160)
          price = 330000;
        else if (item.getCrystalCount() < 2824)
          price = 390000;
        else
          price = 420000;
        break;
      case L2Item.CRYSTAL_S:
View Full Code Here

    }

    PcInventory inventory = activeChar.getInventory();
    if (inventory != null)
    {
      L2ItemInstance item = inventory.getItemByObjectId(_objectId);
      if (item == null || item.isWear())
      {
        ActionFailed af = new ActionFailed();
        activeChar.sendPacket(af);
        return;
      }

      int itemId = item.getItemId();
      if ((itemId >= 6611 && itemId <= 6621) || itemId == 6842)
        return;

      if (_count > item.getCount())
      {
        _count = activeChar.getInventory().getItemByObjectId(_objectId)
            .getCount();
      }
    }

    L2ItemInstance itemToRemove = activeChar.getInventory()
        .getItemByObjectId(_objectId);
    if (itemToRemove == null || itemToRemove.isWear())
    {
      return;
    }
    if (!itemToRemove.getItem().isCrystallizable()
        || (itemToRemove.getItem().getCrystalCount() <= 0)
        || (itemToRemove.getItem().getCrystalType() == L2Item.CRYSTAL_NONE))
    {
      _log.warning("" + activeChar.getObjectId()
          + " tried to crystallize "
          + itemToRemove.getItem().getItemId());
      return;
    }

    // Check if the char can crystallize C items and return if false;
    if (itemToRemove.getItem().getCrystalType() == L2Item.CRYSTAL_C
        && skillLevel <= 1)
    {
      SystemMessage sm = new SystemMessage(
          SystemMessageId.CRYSTALLIZE_LEVEL_TOO_LOW);
      activeChar.sendPacket(sm);
      sm = null;
      ActionFailed af = new ActionFailed();
      activeChar.sendPacket(af);
      return;
    }

    // Check if the user can crystallize B items and return if false;
    if (itemToRemove.getItem().getCrystalType() == L2Item.CRYSTAL_B
        && skillLevel <= 2)
    {
      SystemMessage sm = new SystemMessage(
          SystemMessageId.CRYSTALLIZE_LEVEL_TOO_LOW);
      activeChar.sendPacket(sm);
      sm = null;
      ActionFailed af = new ActionFailed();
      activeChar.sendPacket(af);
      return;
    }

    // Check if the user can crystallize A items and return if false;
    if (itemToRemove.getItem().getCrystalType() == L2Item.CRYSTAL_A
        && skillLevel <= 3)
    {
      SystemMessage sm = new SystemMessage(
          SystemMessageId.CRYSTALLIZE_LEVEL_TOO_LOW);
      activeChar.sendPacket(sm);
      sm = null;
      ActionFailed af = new ActionFailed();
      activeChar.sendPacket(af);
      return;
    }

    // Check if the user can crystallize S items and return if false;
    if (itemToRemove.getItem().getCrystalType() == L2Item.CRYSTAL_S
        && skillLevel <= 4)
    {
      SystemMessage sm = new SystemMessage(
          SystemMessageId.CRYSTALLIZE_LEVEL_TOO_LOW);
      activeChar.sendPacket(sm);
      sm = null;
      ActionFailed af = new ActionFailed();
      activeChar.sendPacket(af);
      return;
    }

    activeChar.setInCrystallize(true);

    // unequip if needed
    if (itemToRemove.isEquipped())
    {
      L2ItemInstance[] unequiped = activeChar.getInventory()
          .unEquipItemInSlotAndRecord(itemToRemove.getEquipSlot());
      InventoryUpdate iu = new InventoryUpdate();
      for (int i = 0; i < unequiped.length; i++)
      {
        iu.addModifiedItem(unequiped[i]);
      }
      activeChar.sendPacket(iu);
      // activeChar.updatePDef();
      // activeChar.updatePAtk();
      // activeChar.updateMDef();
      // activeChar.updateMAtk();
      // activeChar.updateAccuracy();
      // activeChar.updateCriticalChance();
    }

    // remove from inventory
    L2ItemInstance removedItem = activeChar.getInventory().destroyItem(
        "Crystalize", _objectId, _count, activeChar, null);

    // add crystals
    int crystalId = itemToRemove.getItem().getCrystalItemId();
    int crystalAmount = itemToRemove.getCrystalCount();
    L2ItemInstance createditem = activeChar.getInventory().addItem(
        "Crystalize", crystalId, crystalAmount, activeChar,
        itemToRemove);

    SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
    sm.addItemName(crystalId);
    sm.addNumber(crystalAmount);
    activeChar.sendPacket(sm);
    sm = null;

    // send inventory update
    if (!Config.FORCE_INVENTORY_UPDATE)
    {
      InventoryUpdate iu = new InventoryUpdate();
      if (removedItem.getCount() == 0)
        iu.addRemovedItem(removedItem);
      else
        iu.addModifiedItem(removedItem);

      if (createditem.getCount() != crystalAmount)
        iu.addModifiedItem(createditem);
      else
        iu.addNewItem(createditem);

      activeChar.sendPacket(iu);
View Full Code Here

                    // Remove all buffs from all participants on entry. Works like the skill Cancel.
                    participant.stopAllEffects();

                    // Remove any stray blood offerings in inventory
                    L2ItemInstance bloodOfferings = participant.getInventory().getItemByItemId(FESTIVAL_OFFERING_ID);
                    if (bloodOfferings != null)
                      participant.destroyItem("SevenSigns", bloodOfferings, null, true);
                 }
              } catch (NullPointerException e)
              {
View Full Code Here

                    if((castle != null) && !(castle.getSiege().getIsInProgress()))
                    {
                      itemId = ITEM_IDS[i];
                    // create the ticket in the gameworld
                  L2ItemInstance dropticket = new L2ItemInstance(IdFactory.getInstance().getNextId(), itemId);
                  dropticket.setLocation(L2ItemInstance.ItemLocation.INVENTORY);
                  dropticket.dropMe(null, x, y, z);
                      dropticket.setDropTime(0); //avoids it from beeing removed by the auto item destroyer
                      L2World.getInstance().storeObject(dropticket);
                      getDroppedTickets().add(dropticket);
                    }
                    break;
                  }
View Full Code Here

TOP

Related Classes of net.sf.l2j.gameserver.model.L2ItemInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.