Package lineage2.gameserver.model.items

Examples of lineage2.gameserver.model.items.ItemInstance


      {
        _sellList0.remove(si);
        continue;
      }

      ItemInstance item = seller.getInventory().getItemByObjectId(si.getObjectId());
      if (item == null)
        // вещь недоступна, пробуем найти такую же по itemId
        item = seller.getInventory().getItemByItemId(si.getItemId());

      if (item == null || !item.canBeTraded(seller) || item.getItemId() == ItemTemplate.ITEM_ID_ADENA)
      {
        _sellList0.remove(si);
        continue;
      }

      // корректируем количество
      si.setCount(Math.min(item.getCount(), si.getCount()));
    }

    ItemInstance[] items = seller.getInventory().getItems();
    // Проверяем список вещей в инвентаре, если вещь остутствует в списке
    // продажи, добавляем в список доступных для продажи
    loop: for (ItemInstance item : items)
      if (item.canBeTraded(seller) && item.getItemId() != ItemTemplate.ITEM_ID_ADENA)
      {
        for (TradeItem si : _sellList0)
          if (si.getObjectId() == item.getObjectId())
          {
            if (si.getCount() == item.getCount())
              continue loop;
            // Показывает остаток вещей для продажи
            TradeItem ti = new TradeItem(item);
            ti.setCount(item.getCount() - si.getCount());
            _sellList.add(ti);
            continue loop;
          }
        _sellList.add(new TradeItem(item));
      }
View Full Code Here


    if (activeChar.isInTrade())
    {
      activeChar.sendPacket(new ExVariationCancelResult(0));
      return;
    }
    ItemInstance targetItem = activeChar.getInventory().getItemByObjectId(_targetItemObjId);
    if ((targetItem == null) || !targetItem.isAugmented())
    {
      activeChar.sendPacket(new ExVariationCancelResult(0), Msg.AUGMENTATION_REMOVAL_CAN_ONLY_BE_DONE_ON_AN_AUGMENTED_ITEM);
      return;
    }
    int price = getRemovalPrice(targetItem.getTemplate());
    if (price < 0)
    {
      activeChar.sendPacket(new ExVariationCancelResult(0));
    }
    if (!activeChar.reduceAdena(price, true))
    {
      activeChar.sendPacket(new ExVariationCancelResult(0), Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
      return;
    }
    boolean equipped = targetItem.isEquipped();
    if (equipped)
    {
      activeChar.getInventory().unEquipItem(targetItem);
    }
    targetItem.setAugmentationId(0);
    targetItem.setJdbcState(JdbcEntityState.UPDATED);
    targetItem.update();
    if (equipped)
    {
      activeChar.getInventory().equipItem(targetItem);
    }
    InventoryUpdate iu = new InventoryUpdate().addModifiedItem(targetItem);
    SystemMessage sm = new SystemMessage(SystemMessage.AUGMENTATION_HAS_BEEN_SUCCESSFULLY_REMOVED_FROM_YOUR_S1);
    sm.addItemName(targetItem.getItemId());
    activeChar.sendPacket(new ExVariationCancelResult(1), iu, sm);
    for (ShortCut sc : activeChar.getAllShortCuts())
    {
      if ((sc.getId() == targetItem.getObjectId()) && (sc.getType() == ShortCut.TYPE_ITEM))
      {
        activeChar.sendPacket(new ShortCutRegister(activeChar, sc));
      }
    }
    activeChar.sendChanges();
View Full Code Here

    if ((weaponItem == null) || (weaponItem.getItemType() != WeaponType.ROD))
    {
      player.sendPacket(Msg.FISHING_POLES_ARE_NOT_INSTALLED);
      return false;
    }
    ItemInstance lure = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
    if ((lure == null) || (lure.getCount() < 1))
    {
      player.sendPacket(Msg.BAITS_ARE_NOT_PUT_ON_A_HOOK);
      return false;
    }
    int rnd = Rnd.get(50) + 150;
View Full Code Here

    if ((caster == null) || !caster.isPlayer())
    {
      return;
    }
    Player player = (Player) caster;
    ItemInstance lure = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
    if ((lure == null) || (lure.getCount() < 1))
    {
      player.sendPacket(Msg.BAITS_ARE_NOT_PUT_ON_A_HOOK);
      return;
    }
    Zone zone = player.getZone(ZoneType.FISHING);
    if (zone == null)
    {
      return;
    }
    zone.getParams().getInteger("distribution_id");
    int lureId = lure.getItemId();
    int group = lineage2.gameserver.model.Fishing.getFishGroup(lure.getItemId());
    int type = lineage2.gameserver.model.Fishing.getRandomFishType(lureId);
    int lvl = lineage2.gameserver.model.Fishing.getRandomFishLvl(player);
    List<FishTemplate> fishs = FishTable.getInstance().getFish(group, type, lvl);
    if ((fishs == null) || (fishs.size() == 0))
    {
View Full Code Here

            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)))
View Full Code Here

      return;
    }
    Player player = (Player) actor;
    if (item.getItemType() == WeaponType.BOW)
    {
      ItemInstance arrow = player.getInventory().findArrowForBow(item.getTemplate());
      if (arrow != null)
      {
        player.getInventory().setPaperdollItem(Inventory.PAPERDOLL_LHAND, arrow);
      }
    }
    if (item.getItemType() == WeaponType.CROSSBOW)
    {
      ItemInstance bolt = player.getInventory().findArrowForCrossbow(item.getTemplate());
      if (bolt != null)
      {
        player.getInventory().setPaperdollItem(Inventory.PAPERDOLL_LHAND, bolt);
      }
    }
    if (item.getItemType() == WeaponType.ROD)
    {
      ItemInstance bait = player.getInventory().findEquippedLure();
      if (bait != null)
      {
        player.getInventory().setPaperdollItem(Inventory.PAPERDOLL_LHAND, bait);
      }
    }
View Full Code Here

   * @param env Env
   */
  @Override
  public void calc(Env env)
  {
    ItemInstance item = (ItemInstance) owner;
    int enchant = item.getEnchantLevel();
    if(enchant == 0)
    {
      return;
    }
    ItemType itemType = item.getItemType();
    boolean isBlessed = item.getTemplate().isBlessedEquipment();
    boolean isTopGrade = false;
    int crystal = item.getTemplate().getCrystalType().cry;
    Integer bodyPart = item.getBodyPart();
    if(crystal == ItemTemplate.CRYSTAL_R)
    {
      isTopGrade = true;
    }
    switch (stat)
    {
      case SHIELD_DEFENCE:
        double defenseBonus = EnchantStatBonusTable.getInstance().getDefenseBonus(crystal,enchant,_limit1);
        env.value += (int)calcStatBonus(enchant, defenseBonus,isBlessed, false,isTopGrade,false);
        break;
      case MAGIC_DEFENCE:
      {
        defenseBonus = EnchantStatBonusTable.getInstance().getDefenseBonus(crystal,enchant,_limit1);
        env.value += (int)calcStatBonus(enchant, defenseBonus,isBlessed, false,isTopGrade,false);
        break;       
      }
      case POWER_DEFENCE:
     
        defenseBonus = EnchantStatBonusTable.getInstance().getDefenseBonus(crystal,enchant,_limit1);
        env.value += (int)calcStatBonus(enchant, defenseBonus,isBlessed, false,isTopGrade,false);
        break;
      }
      case MAX_HP:
      {
        env.value += EnchantHPBonusTable.getInstance().getHPBonus(item);
        break;
      }
      case RUN_SPEED:
          if(item.isArmor() && enchant > _limit1)
          {
            double runSpdBonus = EnchantStatBonusTable.getInstance().getStatBonus(bodyPart, false);
            if(runSpdBonus == 0)
            {
              _log.info("FuncEnchant: Error, item: " + item.getItemId() + " - " + item.getName() + " has no run speed bonus for the body part." );
              break;
            }
            env.value += (int)calcStatBonus(enchant,runSpdBonus,isBlessed,true,isTopGrade,false);
          }
          break;
      case CRITICAL_RATE:
        if(item.isArmor() && enchant > _limit1)
        {
          double critRateBonus = EnchantStatBonusTable.getInstance().getStatBonus(bodyPart, false);
          if(critRateBonus == 0)
          {
            _log.info("FuncEnchant: Error, item: " + item.getItemId() + " - " + item.getName() + " has no critical rate bonus for the body part." );
            break;
          }
          env.value += (Math.round(calcStatBonus(enchant,critRateBonus,isBlessed,true,isTopGrade,false)*Math.pow(10,1))/Math.pow(10,1)* 2);
        }
        return;
      case MCRITICAL_RATE:
        if(item.isArmor() && enchant > _limit1)
        {
          double mcritRateBonus = EnchantStatBonusTable.getInstance().getStatBonus(bodyPart,true);
          if(mcritRateBonus == 0)
          {
            _log.info("FuncEnchant: Error, item: " + item.getItemId() + " - " + item.getName() + " has no magic Critical rate bonus for the body part." );
            break;
          }
          env.value += calcStatBonus(enchant,mcritRateBonus,isBlessed,true,isTopGrade,false);
        }
        return;
      case ACCURACY_COMBAT:
        if(item.isArmor() && enchant > _limit1)
        {
          double accCombatBonus = EnchantStatBonusTable.getInstance().getStatBonus(bodyPart, false);
          if(accCombatBonus == 0)
          {
            _log.info("FuncEnchant: Error, item: " + item.getItemId() + " - " + item.getName() + " has no accuracy bonus for the body part." );
            break;
          }
          env.value += (int)calcStatBonus(enchant,accCombatBonus,isBlessed,true,isTopGrade,false);
        }
        return;
      case MACCURACY_COMBAT:
        if(item.isArmor() && enchant > _limit1)
        {
          double maccCombatBonus = EnchantStatBonusTable.getInstance().getStatBonus(bodyPart,true);
          if(maccCombatBonus == 0)
          {
            _log.info("FuncEnchant: Error, item: " + item.getItemId() + " - " + item.getName() + " has no Magic Accuracy bonus for the body part." );
            break;
          }
          env.value += (int)calcStatBonus(enchant,maccCombatBonus,isBlessed,true,isTopGrade,false);
        }
        return;
      case EVASION_RATE:
        if(item.isArmor() && enchant > _limit1)
        {
          double evasionBonus = EnchantStatBonusTable.getInstance().getStatBonus(bodyPart,false);
          if(evasionBonus == 0)
          {
            _log.info("FuncEnchant: Error, item: " + item.getItemId() + " - " + item.getName() + " has no evasion bonus for the body part." );
            break;
          }
          env.value += (int)calcStatBonus(enchant,evasionBonus,isBlessed,true,isTopGrade,false);
        }
        return;
      case MEVASION_RATE:
        if(item.isArmor() && enchant > _limit1)
        {
          double mevasionBonus = EnchantStatBonusTable.getInstance().getStatBonus(bodyPart,false);
          if(mevasionBonus == 0)
          {
            _log.info("FuncEnchant: Error, item: " + item.getItemId() + " - " + item.getName() + " has no Magic Evasion bonus for the body part." );
            break;
          }
          env.value += (int)calcStatBonus(enchant,mevasionBonus,isBlessed,true,isTopGrade,false);
        }
        return;
      case MAGIC_ATTACK:
      {
        if(item.isWeapon())
        {
          double mAtkWeaponEnchant = EnchantStatBonusTable.getInstance().getWeaponStatBonus((WeaponType) itemType, crystal,true);
          env.value += (int)calcStatBonus(enchant,mAtkWeaponEnchant,isBlessed,false,isTopGrade,true);
        }
        else if(item.isArmor() && enchant > _limit1)
        {
          double mAtkArmorBonus = EnchantStatBonusTable.getInstance().getStatBonus(bodyPart,true);
          if(mAtkArmorBonus == 0)
          {
            _log.info("FuncEnchant: Error, item: " + item.getItemId() + " - " + item.getName() + " has no Magic Attack bonus for the body part." );
            break;
          }
          env.value += (int)calcStatBonus(enchant,mAtkArmorBonus,isBlessed,true,isTopGrade,false);
        }
        return;
      }
      case POWER_ATTACK:
      {
        if(item.isWeapon())
        {
          double pAtkWeaponEnchant = EnchantStatBonusTable.getInstance().getWeaponStatBonus((WeaponType) itemType, crystal,false);
          env.value += (int)calcStatBonus(enchant,pAtkWeaponEnchant,isBlessed,false,isTopGrade,true);         
        }
        else if(item.isArmor() && enchant > _limit1)
        {
          double pAtkArmorBonus = EnchantStatBonusTable.getInstance().getStatBonus(bodyPart,false);
          if(pAtkArmorBonus == 0)
          {
            _log.info("FuncEnchant: Error, item: " + item.getItemId() + " - " + item.getName() + " has no Physical Attack bonus for the body part." );
            break;
          }
          env.value += (int)calcStatBonus(enchant,pAtkArmorBonus,isBlessed, true,isTopGrade,false);         
        }
        return;
View Full Code Here

    ClanHallMiniGameEvent event = getEvent(ClanHallMiniGameEvent.class);
    if (event == null)
    {
      return;
    }
    ItemInstance item = ItemFunctions.createItem(itemId);
    item.addEvent(event);
    player.getInventory().addItem(item);
    player.sendPacket(SystemMessage2.obtainItems(item));
  }
View Full Code Here

    Iterator<IntObjectMap.Entry<ItemInstance>> iterator = _banishedItems.entrySet().iterator();
    while (iterator.hasNext())
    {
      IntObjectMap.Entry<ItemInstance> entry = iterator.next();
      iterator.remove();
      ItemInstance item = ItemsDAO.getInstance().load(entry.getKey());
      if (item != null)
      {
        if (item.getOwnerId() > 0)
        {
          GameObject object = GameObjectsStorage.findObject(item.getOwnerId());
          if ((object != null) && object.isPlayable())
          {
            ((Playable) object).getInventory().destroyItem(item);
            object.getPlayer().sendPacket(SystemMessage2.removeItems(item));
          }
        }
        item.delete();
      }
      else
      {
        item = entry.getValue();
      }
      item.deleteMe();
    }
  }
View Full Code Here

    expertise = Math.max(expertise, 1);
    expertise--;
    removeItem(player, 20107, 1);
    int item_id = WEAPONS[expertise][num];
    int enchant = Rnd.get(4, 16);
    ItemInstance item = ItemFunctions.createItem(item_id);
    item.setEnchantLevel(enchant);
    player.getInventory().addItem(item);
    player.sendPacket(SystemMessage2.obtainItems(item_id, 1, enchant));
  }
View Full Code Here

TOP

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

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.