Package lineage2.gameserver.model.base

Examples of lineage2.gameserver.model.base.MultiSellEntry


  @Override
  public void onReload()
  {
    for (String element : ZONES)
    {
      Zone zone = ReflectionUtils.getZone(element);
      zone.removeListener(_zoneListener);
    }
    if (_buffTask != null)
    {
      _buffTask.cancel(false);
      _buffTask = null;
View Full Code Here


    @Override
    public void runImpl()
    {
      for (String element : ZONES)
      {
        Zone zone = ReflectionUtils.getZone(element);
        NpcInstance npc = getKasha(zone);
        if ((npc != null) && (zone != null))
        {
          int curseLvl = 0;
          int yearningLvl = 0;
          int despairLvl = 0;
          for (Creature c : zone.getObjects())
          {
            if (c.isMonster() && !c.isDead())
            {
              if (getRealNpcId((NpcInstance) c) == mobs[0])
              {
                curseLvl++;
              }
              else if (getRealNpcId((NpcInstance) c) == mobs[1])
              {
                yearningLvl++;
              }
              else if (getRealNpcId((NpcInstance) c) == mobs[2])
              {
                despairLvl++;
              }
            }
          }
          if ((yearningLvl > 0) || (curseLvl > 0) || (despairLvl > 0))
          {
            for (Creature cha : zone.getInsidePlayables())
            {
              boolean casted = false;
              if (curseLvl > 0)
              {
                addEffect(npc, cha.getPlayer(), SkillTable.getInstance().getInfo(_buffs[0], curseLvl), true);
View Full Code Here

  private void init()
  {
    _zoneListener = new ZoneListener();
    for (String s : zones)
    {
      Zone zone = ReflectionUtils.getZone(s);
      zone.addListener(_zoneListener);
    }
  }
View Full Code Here

   * Method init.
   */
  private void init()
  {
    _zoneListener = new ZoneListener();
    Zone zone = ReflectionUtils.getZone(ZONE_NAME);
    if (zone != null)
    {
      zone.addListener(_zoneListener);
    }
  }
View Full Code Here

    {
      activeChar.sendActionFailed();
      return;
    }
   
    MultiSellEntry entry = null;
    for (MultiSellEntry $entry : list1.getEntries())
    {
      if ($entry.getEntryId() == _entryId)
      {
        entry = $entry;
        break;
      }
    }
   
    if (entry == null)
    {
      return;
    }
   
    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)
          {
View Full Code Here

      {
        for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
        {
          if ("item".equalsIgnoreCase(d.getNodeName()))
          {
            MultiSellEntry e = parseEntry(d, id);
            if (e != null)
            {
              e.setEntryId(entId++);
              list.addEntry(e);
            }
          }
          else if ("config".equalsIgnoreCase(d.getNodeName()))
          {
View Full Code Here

   * @param multiSellId int
   * @return MultiSellEntry
   */
  protected MultiSellEntry parseEntry(Node n, int multiSellId)
  {
    MultiSellEntry entry = new MultiSellEntry();
    for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
    {
      if (NODE_INGRIDIENT.equalsIgnoreCase(d.getNodeName()))
      {
        int id = Integer.parseInt(d.getAttributes().getNamedItem("id").getNodeValue());
        long count = Long.parseLong(d.getAttributes().getNamedItem("count").getNodeValue());
        MultiSellIngredient mi = new MultiSellIngredient(id, count);
        if (d.getAttributes().getNamedItem("enchant") != null)
        {
          mi.setItemEnchant(Integer.parseInt(d.getAttributes().getNamedItem("enchant").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("mantainIngredient") != null)
        {
          mi.setMantainIngredient(Boolean.parseBoolean(d.getAttributes().getNamedItem("mantainIngredient").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("fireAttr") != null)
        {
          mi.getItemAttributes().setFire(Integer.parseInt(d.getAttributes().getNamedItem("fireAttr").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("waterAttr") != null)
        {
          mi.getItemAttributes().setWater(Integer.parseInt(d.getAttributes().getNamedItem("waterAttr").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("earthAttr") != null)
        {
          mi.getItemAttributes().setEarth(Integer.parseInt(d.getAttributes().getNamedItem("earthAttr").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("windAttr") != null)
        {
          mi.getItemAttributes().setWind(Integer.parseInt(d.getAttributes().getNamedItem("windAttr").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("holyAttr") != null)
        {
          mi.getItemAttributes().setHoly(Integer.parseInt(d.getAttributes().getNamedItem("holyAttr").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("unholyAttr") != null)
        {
          mi.getItemAttributes().setUnholy(Integer.parseInt(d.getAttributes().getNamedItem("unholyAttr").getNodeValue()));
        }
        entry.addIngredient(mi);
      }
      else if (NODE_PRODUCTION.equalsIgnoreCase(d.getNodeName()))
      {
        int id = Integer.parseInt(d.getAttributes().getNamedItem("id").getNodeValue());
        long count = Long.parseLong(d.getAttributes().getNamedItem("count").getNodeValue());
        MultiSellIngredient mi = new MultiSellIngredient(id, count);
        if (d.getAttributes().getNamedItem("enchant") != null)
        {
          mi.setItemEnchant(Integer.parseInt(d.getAttributes().getNamedItem("enchant").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("chance") != null)
        {
          mi.setChance(Integer.parseInt(d.getAttributes().getNamedItem("chance").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("fireAttr") != null)
        {
          mi.getItemAttributes().setFire(Integer.parseInt(d.getAttributes().getNamedItem("fireAttr").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("waterAttr") != null)
        {
          mi.getItemAttributes().setWater(Integer.parseInt(d.getAttributes().getNamedItem("waterAttr").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("earthAttr") != null)
        {
          mi.getItemAttributes().setEarth(Integer.parseInt(d.getAttributes().getNamedItem("earthAttr").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("windAttr") != null)
        {
          mi.getItemAttributes().setWind(Integer.parseInt(d.getAttributes().getNamedItem("windAttr").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("holyAttr") != null)
        {
          mi.getItemAttributes().setHoly(Integer.parseInt(d.getAttributes().getNamedItem("holyAttr").getNodeValue()));
        }
        if (d.getAttributes().getNamedItem("unholyAttr") != null)
        {
          mi.getItemAttributes().setUnholy(Integer.parseInt(d.getAttributes().getNamedItem("unholyAttr").getNodeValue()));
        }
        if (!Config.ALT_ALLOW_SHADOW_WEAPONS && (id > 0))
        {
          ItemTemplate item = ItemHolder.getInstance().getTemplate(id);
          if ((item != null) && item.isShadowItem() && item.isWeapon() && !Config.ALT_ALLOW_SHADOW_WEAPONS)
          {
            return null;
          }
        }
        entry.addProduct(mi);
      }
    }
    if (entry.getIngredients().isEmpty() || entry.getProduction().isEmpty())
    {
      _log.warn("MultiSell [" + multiSellId + "] is empty!");
      return null;
    }
    if ((entry.getIngredients().size() == 1) && (entry.getProduction().size() == 1) && (entry.getIngredients().get(0).getItemId() == 57))
    {
      ItemTemplate item = ItemHolder.getInstance().getTemplate(entry.getProduction().get(0).getItemId());
      if (item == null)
      {
        _log.warn("MultiSell [" + multiSellId + "] Production [" + entry.getProduction().get(0).getItemId() + "] not found!");
        return null;
      }
      if ((entry.getIngredients().get(0).getItemId() == 57 &&  item.getReferencePrice() > entry.getIngredients().get(0).getItemCount()) && !Config.LOGIN_SERVER_IS_PVP)
      {
        _log.warn("MultiSell [" + multiSellId + "] Production '" + item.getName() + "' [" + entry.getProduction().get(0).getItemId() + "] price is lower than referenced | " + item.getReferencePrice() + " > " + entry.getIngredients().get(0).getItemCount());
      }
    }
    return entry;
  }
View Full Code Here

    long[] ingredient, production;
    if (((ingredient = parseItemIdAndCount(a[0])) == null) || ((production = parseItemIdAndCount(a[1])) == null))
    {
      return null;
    }
    MultiSellEntry entry = new MultiSellEntry();
    entry.addIngredient(new MultiSellIngredient((int) ingredient[0], ingredient[1]));
    entry.addProduct(new MultiSellIngredient((int) production[0], production[1]));
    return entry;
  }
View Full Code Here

    list.setNoTax(notax);
    list.setNoKey(nokey);
    ItemInstance[] items = player.getInventory().getItems();
    for (MultiSellEntry origEntry : container.getEntries())
    {
      MultiSellEntry ent = origEntry.clone();
      List<MultiSellIngredient> ingridients;
      if (!notax && (taxRate > 0.))
      {
        double tax = 0;
        long adena = 0;
        ingridients = new ArrayList<>(ent.getIngredients().size() + 1);
        for (MultiSellIngredient i : ent.getIngredients())
        {
          if (i.getItemId() == 57)
          {
            adena += i.getItemCount();
            tax += i.getItemCount() * taxRate;
            continue;
          }
          ingridients.add(i);
          if (i.getItemId() == ItemTemplate.ITEM_ID_CLAN_REPUTATION_SCORE)
          {
            tax += (i.getItemCount() / 120) * 1000 * taxRate * 100;
          }
          if (i.getItemId() < 1)
          {
            continue;
          }
          ItemTemplate item = ItemHolder.getInstance().getTemplate(i.getItemId());
          if (item.isStackable())
          {
            tax += item.getReferencePrice() * i.getItemCount() * taxRate;
          }
        }
        adena = Math.round(adena + tax);
        if (adena > 0)
        {
          ingridients.add(new MultiSellIngredient(57, adena));
        }
        ent.setTax(Math.round(tax));
        ent.getIngredients().clear();
        ent.getIngredients().addAll(ingridients);
      }
      else
      {
        ingridients = ent.getIngredients();
      }
      if (showall)
      {
        list.entries.add(ent);
      }
      else
      {
        List<Integer> itms = new ArrayList<>();
        for (MultiSellIngredient ingredient : ingridients)
        {
          ItemTemplate template = ingredient.getItemId() <= 0 ? null : ItemHolder.getInstance().getTemplate(ingredient.getItemId());
          if ((ingredient.getItemId() <= 0) || nokey || template.isEquipment())
          {
            if (ingredient.getItemId() == 12374)
            {
              continue;
            }
            if (ingredient.getItemId() == ItemTemplate.ITEM_ID_CLAN_REPUTATION_SCORE)
            {
              if (!itms.contains(ingredient.getItemId()) && (player.getClan() != null) && (player.getClan().getReputationScore() >= ingredient.getItemCount()))
              {
                itms.add(ingredient.getItemId());
              }
              continue;
            }
            else if (ingredient.getItemId() == ItemTemplate.ITEM_ID_PC_BANG_POINTS)
            {
              if (!itms.contains(ingredient.getItemId()) && (player.getPcBangPoints() >= ingredient.getItemCount()))
              {
                itms.add(ingredient.getItemId());
              }
              continue;
            }
            else if (ingredient.getItemId() == ItemTemplate.ITEM_ID_FAME)
            {
              if (!itms.contains(ingredient.getItemId()) && (player.getFame() >= ingredient.getItemCount()))
              {
                itms.add(ingredient.getItemId());
              }
              continue;
            }
            for (final ItemInstance item : items)
            {
              if ((item.getItemId() == ingredient.getItemId()) && item.canBeExchanged(player))
              {
                if (itms.contains(enchant ? ingredient.getItemId() + (ingredient.getItemEnchant() * 100000L) : ingredient.getItemId()))
                {
                  continue;
                }
                if (item.getEnchantLevel() < ingredient.getItemEnchant())
                {
                  continue;
                }
                if (item.isStackable() && (item.getCount() < ingredient.getItemCount()))
                {
                  break;
                }
                itms.add(enchant ? ingredient.getItemId() + (ingredient.getItemEnchant() * 100000) : ingredient.getItemId());
                MultiSellEntry possibleEntry = new MultiSellEntry(enchant ? ent.getEntryId() + (item.getEnchantLevel() * 100000) : ent.getEntryId());
                for (MultiSellIngredient p : ent.getProduction())
                {
                  if (enchant && template.canBeEnchanted())
                  {
                    p.setItemEnchant(item.getEnchantLevel());
                    p.setItemAttributes(item.getAttributes().clone());
                  }
                  possibleEntry.addProduct(p);
                }
                for (MultiSellIngredient ig : ingridients)
                {
                  if (enchant && (ig.getItemId() > 0) && ItemHolder.getInstance().getTemplate(ig.getItemId()).canBeEnchanted())
                  {
                    ig.setItemEnchant(item.getEnchantLevel());
                    ig.setItemAttributes(item.getAttributes().clone());
                  }
                  possibleEntry.addIngredient(ig);
                }
                list.entries.add(possibleEntry);
                break;
              }
            }
View Full Code Here

    for (final ItemInstance itm : inv.getItems())
    {
      if (itm.canBeCrystallized(player))
      {
        final ItemTemplate crystal = ItemHolder.getInstance().getTemplate(itm.getTemplate().getCrystalType().cry);
        MultiSellEntry possibleEntry = new MultiSellEntry(++entry, crystal.getItemId(), itm.getTemplate().getCrystalCount(), 0);
        possibleEntry.addIngredient(new MultiSellIngredient(itm.getItemId(), 1, itm.getEnchantLevel()));
        possibleEntry.addIngredient(new MultiSellIngredient(ItemTemplate.ITEM_ID_ADENA, Math.round(itm.getTemplate().getCrystalCount() * crystal.getReferencePrice() * 0.05), 0));
        list.addEntry(possibleEntry);
      }
    }
    MultiSellHolder.getInstance().SeparateAndSend(list, player, castle == null ? 0. : castle.getTaxRate());
  }
View Full Code Here

TOP

Related Classes of lineage2.gameserver.model.base.MultiSellEntry

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.