Package lineage2.gameserver.model.items

Examples of lineage2.gameserver.model.items.PcInventory


     * Method runImpl.
     */
    @Override
    public void runImpl()
    {
      final NpcInstance actor = getActor();
      if (actor.getNpcState() == 1)
      {
        actor.setNpcState(2);
      }
      else
      {
        actor.setNpcState(1);
      }
    }
View Full Code Here


    }
    if (!player.getAccountChars().containsKey(_objectId))
    {
      return;
    }
    PcInventory inventory = player.getInventory();
    PcFreight freight = new PcFreight(_objectId);
    freight.restore();
    inventory.writeLock();
    freight.writeLock();
    try
    {
      int slotsleft = 0;
      long adenaDeposit = 0;
      slotsleft = Config.FREIGHT_SLOTS - freight.getSize();
      int items = 0;
      for (int i = 0; i < _count; i++)
      {
        ItemInstance item = inventory.getItemByObjectId(_items[i]);
        if ((item == null) || (item.getCount() < _itemQ[i]) || !item.getTemplate().isFreightable())
        {
          _items[i] = 0;
          _itemQ[i] = 0L;
          continue;
        }
        if (!item.isStackable() || (freight.getItemByItemId(item.getItemId()) == null))
        {
          if (slotsleft <= 0)
          {
            _items[i] = 0;
            _itemQ[i] = 0L;
            continue;
          }
          slotsleft--;
        }
        if (item.getItemId() == ItemTemplate.ITEM_ID_ADENA)
        {
          adenaDeposit = _itemQ[i];
        }
        items++;
      }
      if (slotsleft <= 0)
      {
        player.sendPacket(SystemMsg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
      }
      if (items == 0)
      {
        player.sendPacket(SystemMsg.INCORRECT_ITEM_COUNT);
        return;
      }
      long fee = SafeMath.mulAndCheck(items, _FREIGHT_FEE);
      if ((fee + adenaDeposit) > player.getAdena())
      {
        player.sendPacket(SystemMsg.YOU_LACK_THE_FUNDS_NEEDED_TO_PAY_FOR_THIS_TRANSACTION);
        return;
      }
      if (!player.reduceAdena(fee, true))
      {
        player.sendPacket(SystemMsg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
        return;
      }
      for (int i = 0; i < _count; i++)
      {
        if (_items[i] == 0)
        {
          continue;
        }
        ItemInstance item = inventory.removeItemByObjectId(_items[i], _itemQ[i]);
        Log.LogItem(player, Log.FreightDeposit, item);
        freight.addItem(item);
      }
    }
    catch (ArithmeticException ae)
    {
      player.sendPacket(SystemMsg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
      return;
    }
    finally
    {
      freight.writeUnlock();
      inventory.writeUnlock();
    }
    player.sendChanges();
    player.sendPacket(SystemMsg.THE_TRANSACTION_IS_COMPLETE);
  }
View Full Code Here

    Player activeChar = (getClient()).getActiveChar();
    if (activeChar == null)
    {
      return;
    }
    PcInventory inventory = activeChar.getInventory();
    ItemInstance _item = inventory.getItemByObjectId(_itemObjId);
    ItemFunctions.removeItem(activeChar, _consumeItemId, 1, true);
    boolean equipped = _item.isEquipped();
    if (equipped)
    {
      activeChar.getInventory().isRefresh = true;
View Full Code Here

   
    final boolean keepenchant = list1.isKeepEnchant();
    final boolean notax = list1.isNoTax();
    final List<ItemData> items = new ArrayList<>();
   
    PcInventory inventory = activeChar.getInventory();
   
    long totalPrice = 0;
   
    NpcInstance merchant = activeChar.getLastNpc();
    Castle castle = merchant != null ? merchant.getCastle(activeChar) : null;
   
    inventory.writeLock();
    try
    {
      long tax = SafeMath.mulAndCheck(entry.getTax(), _amount);
     
      long slots = 0;
      long weight = 0;
      for (MultiSellIngredient i : entry.getProduction())
      {
        if (i.getItemId() <= 0)
        {
          continue;
        }
        ItemTemplate item = ItemHolder.getInstance().getTemplate(i.getItemId());
       
        weight = SafeMath.addAndCheck(weight, SafeMath.mulAndCheck(SafeMath.mulAndCheck(i.getItemCount(), _amount), item.getWeight()));
        if (item.isStackable())
        {
          if (inventory.getItemByItemId(i.getItemId()) == null)
          {
            slots++;
          }
        }
        else
        {
          slots = SafeMath.addAndCheck(slots, _amount);
        }
      }
     
      if (!inventory.validateWeight(weight))
      {
        activeChar.sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
        activeChar.sendActionFailed();
        return;
      }
     
      if (!inventory.validateCapacity(slots))
      {
        activeChar.sendPacket(Msg.YOUR_INVENTORY_IS_FULL);
        activeChar.sendActionFailed();
        return;
      }
     
      if (entry.getIngredients().size() == 0)
      {
        activeChar.sendActionFailed();
        activeChar.setMultisell(null);
        return;
      }
     
      for (MultiSellIngredient ingridient : entry.getIngredients())
      {
        int ingridientItemId = ingridient.getItemId();
        long ingridientItemCount = ingridient.getItemCount();
        int ingridientEnchant = ingridient.getItemEnchant();
        long totalAmount = !ingridient.getMantainIngredient() ? SafeMath.mulAndCheck(ingridientItemCount, _amount) : ingridientItemCount;
       
        if (ingridientItemId == ItemTemplate.ITEM_ID_CLAN_REPUTATION_SCORE)
        {
          if (activeChar.getClan() == null)
          {
            activeChar.sendPacket(Msg.YOU_ARE_NOT_A_CLAN_MEMBER);
            return;
          }
         
          if (activeChar.getClan().getReputationScore() < totalAmount)
          {
            activeChar.sendPacket(Msg.THE_CLAN_REPUTATION_SCORE_IS_TOO_LOW);
            return;
          }
         
          if (activeChar.getClan().getLeaderId() != activeChar.getObjectId())
          {
            activeChar.sendPacket(new SystemMessage(SystemMessage.S1_IS_NOT_A_CLAN_LEADER).addString(activeChar.getName()));
            return;
          }
          if (!ingridient.getMantainIngredient())
          {
            items.add(new ItemData(ingridientItemId, totalAmount, null));
          }
        }
        else if (ingridientItemId == ItemTemplate.ITEM_ID_PC_BANG_POINTS)
        {
          if (activeChar.getPcBangPoints() < totalAmount)
          {
            activeChar.sendPacket(Msg.YOU_ARE_SHORT_OF_ACCUMULATED_POINTS);
            return;
          }
          if (!ingridient.getMantainIngredient())
          {
            items.add(new ItemData(ingridientItemId, totalAmount, null));
          }
        }
        else if (ingridientItemId == ItemTemplate.ITEM_ID_FAME)
        {
          if (activeChar.getFame() < totalAmount)
          {
            activeChar.sendPacket(Msg.NOT_ENOUGH_FAME_POINTS);
            return;
          }
          if (!ingridient.getMantainIngredient())
          {
            items.add(new ItemData(ingridientItemId, totalAmount, null));
          }
        }
        else
        {
          ItemTemplate template = ItemHolder.getInstance().getTemplate(ingridientItemId);
         
          if (!template.isStackable())
          {
            for (int i = 0; i < (ingridientItemCount * _amount); i++)
            {
              List<ItemInstance> list = inventory.getItemsByItemId(ingridientItemId);
              if (keepenchant)
              {
                ItemInstance itemToTake = null;
                for (ItemInstance item : list)
                {
                  ItemData itmd = new ItemData(item.getItemId(), item.getCount(), item);
                  if (((item.getEnchantLevel() == ingridientEnchant) || !item.getTemplate().isEquipment()) && !items.contains(itmd) && item.canBeExchanged(activeChar))
                  {
                    itemToTake = item;
                    break;
                  }
                }
               
                if (itemToTake == null)
                {
                  activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
                  return;
                }
               
                if (!ingridient.getMantainIngredient())
                {
                  items.add(new ItemData(itemToTake.getItemId(), 1, itemToTake));
                }
              }
              else
              {
                ItemInstance itemToTake = null;
                for (ItemInstance item : list)
                {
                  if (!items.contains(new ItemData(item.getItemId(), item.getCount(), item)) && ((itemToTake == null) || (item.getEnchantLevel() < itemToTake.getEnchantLevel())) && !item.isShadowItem() && !item.isTemporalItem() && (!item.isAugmented() || Config.ALT_ALLOW_DROP_AUGMENTED) && ItemFunctions.checkIfCanDiscard(activeChar, item))
                  {
                    itemToTake = item;
                    if (itemToTake.getEnchantLevel() == 0)
                    {
                      break;
                    }
                  }
                }
               
                if (itemToTake == null)
                {
                  activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
                  return;
                }
               
                if (!ingridient.getMantainIngredient())
                {
                  items.add(new ItemData(itemToTake.getItemId(), 1, itemToTake));
                }
              }
            }
          }
          else
          {
            if (ingridientItemId == 57)
            {
              totalPrice = SafeMath.addAndCheck(totalPrice, SafeMath.mulAndCheck(ingridientItemCount, _amount));
            }
            ItemInstance item = inventory.getItemByItemId(ingridientItemId);
           
            if ((item == null) || (item.getCount() < totalAmount))
            {
              activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
              return;
            }
           
            if (!ingridient.getMantainIngredient())
            {
              items.add(new ItemData(item.getItemId(), totalAmount, item));
            }
          }
        }
       
        if (activeChar.getAdena() < totalPrice)
        {
          activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
          return;
        }
      }
     
      int enchantLevel = 0;
      ItemAttributes attributes = null;
      int augmentationId = 0;
      for (ItemData id : items)
      {
        long count = id.getCount();
        if (count > 0)
        {
          if (id.getId() == ItemTemplate.ITEM_ID_CLAN_REPUTATION_SCORE)
          {
            activeChar.getClan().incReputation((int) -count, false, "MultiSell");
            activeChar.sendPacket(new SystemMessage(SystemMessage.S1_POINTS_HAVE_BEEN_DEDUCTED_FROM_THE_CLAN_REPUTATION_SCORE).addNumber(count));
          }
          else if (id.getId() == ItemTemplate.ITEM_ID_PC_BANG_POINTS)
          {
            activeChar.reducePcBangPoints((int) count);
          }
          else if (id.getId() == ItemTemplate.ITEM_ID_FAME)
          {
            activeChar.setFame(activeChar.getFame() - (int) count, "MultiSell");
            activeChar.sendPacket(new SystemMessage(SystemMessage.S2_S1_HAS_DISAPPEARED).addNumber(count).addString("Fame"));
          }
          else
          {
            if (inventory.destroyItem(id.getItem(), count))
            {
              if (keepenchant && id.getItem().canBeEnchanted())
              {
                enchantLevel = id.getItem().getEnchantLevel();
                attributes = id.getItem().getAttributes();
                augmentationId = id.getItem().getAugmentationId();
              }
             
              activeChar.sendPacket(SystemMessage2.removeItems(id.getId(), count));
              continue;
            }
            return;
          }
        }
      }
     
      if ((tax > 0) && !notax)
      {
        if (castle != null)
        {
          activeChar.sendMessage(new CustomMessage("trade.HavePaidTax", activeChar).addNumber(tax));
          if ((merchant != null) && (merchant.getReflection() == ReflectionManager.DEFAULT))
          {
            castle.addToTreasury(tax, true, false);
          }
        }
      }
      double rndNum = 100.0D * Rnd.nextDouble();
      double chance = 0.0D;
      double chanceFrom = 0.0D;
      cycle1 :
      for (MultiSellIngredient in : entry.getProduction())
      {
        if (in.getItemId() <= 0)
        {
          if (in.getItemId() == ItemTemplate.ITEM_ID_CLAN_REPUTATION_SCORE)
          {
            activeChar.getClan().incReputation((int) (in.getItemCount() * _amount), false, "MultiSell");
            activeChar.sendPacket(new SystemMessage(SystemMessage.YOUR_CLAN_HAS_ADDED_1S_POINTS_TO_ITS_CLAN_REPUTATION_SCORE).addNumber(in.getItemCount() * _amount));
          }
          else if (in.getItemId() == ItemTemplate.ITEM_ID_PC_BANG_POINTS)
          {
            activeChar.addPcBangPoints((int) (in.getItemCount() * _amount), false);
          }
          else if (in.getItemId() == ItemTemplate.ITEM_ID_FAME)
          {
            activeChar.setFame(activeChar.getFame() + (int) (in.getItemCount() * _amount), "MultiSell");
          }
        }
        else if (ItemHolder.getInstance().getTemplate(in.getItemId()).isStackable())
        {
         
          long total = SafeMath.mulAndLimit(in.getItemCount(), _amount);
          if (in.getChance() >= 0)
          {
            chance = in.getChance();
           
            if ((rndNum >= chanceFrom) && (rndNum <= (chance + chanceFrom)))
            {
              ItemFunctions.addItem(activeChar, in.getItemId(), total, true);
              break;
            }
            chanceFrom += chance;
          }
          else
          {
            ItemFunctions.addItem(activeChar, in.getItemId(), total, true);
          }
         
        }
        else
        {
          for (int i = 0; i < _amount; i++)
          {
            ItemInstance product = ItemFunctions.createItem(in.getItemId());
           
            if (keepenchant && product.canBeEnchanted())
            {
              if (in.getChance() >= 0)
              {
                chance = in.getChance();             
               
                if ((rndNum >= chanceFrom) && (rndNum <= (chance + chanceFrom)))
                {
                  product.setEnchantLevel(enchantLevel);
                  if (attributes != null)
                  {
                    product.setAttributes(attributes.clone());
                  }
                  if (augmentationId != 0)
                  {
                    product.setAugmentationId(augmentationId);
                  }
                  inventory.addItem(product);
                  activeChar.sendPacket(SystemMessage2.obtainItems(product));
                  break cycle1;
                 
                }
                chanceFrom += chance;
              }
              else
              {
                product.setEnchantLevel(enchantLevel);
                if (attributes != null)
                {
                  product.setAttributes(attributes.clone());
                }
                if (augmentationId != 0)
                {
                  product.setAugmentationId(augmentationId);
                }
                inventory.addItem(product);
                activeChar.sendPacket(SystemMessage2.obtainItems(product));
              }
            }
            else
            {
              product.setEnchantLevel(in.getItemEnchant());
              product.setAttributes(in.getItemAttributes().clone());
              if (in.getChance() >= 0)
              {
                chance = in.getChance();
               
                if ((rndNum >= chanceFrom) && (rndNum <= (chance + chanceFrom)))
                {
                  ItemFunctions.addItem(activeChar, in.getItemId(), in.getItemCount(), true);
                  break;
                }
                chanceFrom += chance;
              }
              else
              {
                inventory.addItem(product);
                activeChar.sendPacket(SystemMessage2.obtainItems(product));
              }
            }
          }
        }
      }
    }
    catch (ArithmeticException ae)
    {
      sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
      return;
    }
    finally
    {
      inventory.writeUnlock();
    }
   
    activeChar.sendChanges();
   
    if (!list1.isShowAll())
View Full Code Here

          continue;
        }
        player.getEffectList().stopAllEffects();
        player.setTeam(TeamType.NONE);
        player.setBlockCheckerArena(DEFAULT_ARENA);
        PcInventory inv = player.getInventory();
        inv.destroyItemByItemId(13787, inv.getCountOf(13787));
        inv.destroyItemByItemId(13788, inv.getCountOf(13788));
        broadcastRelationChanged(player);
        player.teleToLocation(-57478, -60367, -2370);
        player.sendPacket(end);
        player.broadcastCharInfo();
      }
View Full Code Here

      int arena = player.getBlockCheckerArena();
      int team = HandysBlockCheckerManager.getInstance().getHolder(arena).getPlayerTeam(player);
      HandysBlockCheckerManager.getInstance().removePlayer(player, arena, team);
      player.setTeam(TeamType.NONE);
      player.broadcastCharInfo();
      PcInventory inv = player.getInventory();
      inv.destroyItemByItemId(13787, inv.getCountOf(13787));
      inv.destroyItemByItemId(13788, inv.getCountOf(13788));
    }
View Full Code Here

      player.sendPacket(ExShapeShiftingResult.FAIL);
      player.setAppearanceStone(null);
      return;
    }

    PcInventory inventory = player.getInventory();
    ItemInstance targetItem = inventory.getItemByObjectId(_targetItemObjId);
    ItemInstance stone = player.getAppearanceStone();
    if(targetItem == null || stone == null)
    {
      player.sendPacket(ExShapeShiftingResult.FAIL);
      player.setAppearanceStone(null);
      return;
    }

    if(!targetItem.canBeAppearance())
    {
      player.sendPacket(ExPutShapeShiftingTargetItemResult.FAIL);
      return;
    }

    if(targetItem.getLocation() != ItemInstance.ItemLocation.INVENTORY && targetItem.getLocation() != ItemInstance.ItemLocation.PAPERDOLL)
    {
      player.sendPacket(ExShapeShiftingResult.FAIL);
      player.setAppearanceStone(null);
      return;
    }

    if((stone = inventory.getItemByObjectId(stone.getObjectId())) == null)
    {
      player.sendPacket(ExShapeShiftingResult.FAIL);
      player.setAppearanceStone(null);
      return;
    }
View Full Code Here

    if (player == null)
    {
      return 0;
    }
    final int player_id = player.getObjectId();
    final PcInventory inv = player.getInventory();
    if (inv == null)
    {
      return 0;
    }
    int restored_counter = 0;
    Connection con = null;
    PreparedStatement st = null, st_delete = null;
    ResultSet rset = null;
    synchronized (_lock)
    {
      try
      {
        con = DatabaseFactory.getInstance().getConnection();
        st = con.prepareStatement("SELECT * FROM items_delayed WHERE owner_id=? AND payment_status=0");
        st.setInt(1, player_id);
        rset = st.executeQuery();
        ItemInstance item, newItem;
        st_delete = con.prepareStatement("UPDATE items_delayed SET payment_status=1 WHERE payment_id=?");
        while (rset.next())
        {
          final int ITEM_ID = rset.getInt("item_id");
          final long ITEM_COUNT = rset.getLong("count");
          final int ITEM_ENCHANT = rset.getInt("enchant_level");
          final int PAYMENT_ID = rset.getInt("payment_id");
          final int FLAGS = rset.getInt("flags");
          rset.getInt("attribute");
          rset.getInt("attribute_level");
          boolean stackable = ItemHolder.getInstance().getTemplate(ITEM_ID).isStackable();
          boolean success = false;
          for (int i = 0; i < (stackable ? 1 : ITEM_COUNT); i++)
          {
            item = ItemFunctions.createItem(ITEM_ID);
            if (item.isStackable())
            {
              item.setCount(ITEM_COUNT);
            }
            else
            {
              item.setEnchantLevel(ITEM_ENCHANT);
            }
            item.setLocation(ItemLocation.INVENTORY);
            item.setCustomFlags(FLAGS);
            if (ITEM_COUNT > 0)
            {
              newItem = inv.addItem(item);
              if (newItem == null)
              {
                _log.warn("Unable to delayed create item " + ITEM_ID + " request " + PAYMENT_ID);
                continue;
              }
View Full Code Here

        }
        String name = hero.getString(Olympiad.CHAR_NAME);
        Player player = World.getPlayer(name);
        if (player != null)
        {
          PcInventory inventory = player.getInventory();
          inventory.writeLock();
          try
          {
            for (ItemInstance item : player.getInventory().getItems())
            {
              if (item.isHeroWeapon())
              {
                player.getInventory().destroyItem(item);
              }
            }
          }
          finally
          {
            inventory.writeUnlock();
          }
          player.setHero(false);
          player.updatePledgeClass();
          player.broadcastUserInfo();
        }
View Full Code Here

   * @param count long
   * @param sale_days int
   */
  public void registerItem(Player player, int objectId, String item_name, long price, long count, int sale_days)
  {
    PcInventory inventory = player.getInventory();
    ItemInstance item = inventory.getItemByObjectId(objectId);
    if ((item == null) || (item.getCount() < count) || !item.canBeSold(player))
    {
      return;
    }
    int days = (sale_days * 2) + 1;
    if ((days <= 0) || (days > 7))
    {
      return;
    }
    inventory.writeLock();
    container.writeLock();
    try
    {
      long total = SafeMath.mulAndCheck(price, count);
      long fee = Math.round(SafeMath.mulAndCheck(total, days) * REGISTRATION_FEE);
      fee = Math.max(fee, MIN_FEE);
      if ((fee > player.getAdena()) || !player.reduceAdena(fee, false))
      {
        player.sendPacket(new SystemMessage2(SystemMsg.YOU_DO_NOT_HAVE_ENOUGH_ADENA_TO_REGISTER_THE_ITEM));
        return;
      }
      ItemInstance cItem = inventory.removeItemByObjectId(objectId, count);
      container.addItem(cItem);
      String item_type = cItem.getTemplate().getExItemType().name();
      CommissionShopDAO.getInstance().saveNewItem(cItem.getObjectId(), player.getObjectId(), item_name, price, item_type, sale_days, System.currentTimeMillis() + (days * 86400000), player.getName());
      Log.LogItem(player, Log.CommissionItemRegister, cItem);
    }
    catch (ArithmeticException ae)
    {
      _log.info("CommissionShopManager.registerItem: " + ae, ae);
    }
    finally
    {
      inventory.writeUnlock();
      container.writeUnlock();
    }
    showRegistrableItems(player);
    showPlayerRegisteredItems(player);
  }
View Full Code Here

TOP

Related Classes of lineage2.gameserver.model.items.PcInventory

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.