Package lineage2.gameserver.data.xml.holder.MultiSellHolder

Examples of lineage2.gameserver.data.xml.holder.MultiSellHolder.MultiSellListContainer


  public void onEvtDead(Creature killer)
  {
    final NpcInstance actor = getActor();
    super.onEvtDead(killer);
    actor.deleteMe();
    ThreadPoolManager.getInstance().schedule(new RunnableImpl()
    {
      @Override
      public void runImpl()
      {
        final NpcTemplate template = NpcHolder.getInstance().getTemplate(18602);
View Full Code Here


          getZone("[soi_hos_attack_attackup_5]").setActive(false);
          spawnRoom(6);
        }
      }
      else if(self.getNpcId() == Yehan)
        ThreadPoolManager.getInstance().schedule(new RunnableImpl(){
          @Override
          public void runImpl() throws Exception
          {
            spawnRoom(7);
            setReenterTime(System.currentTimeMillis());
View Full Code Here

   * @param time String
   * @param shutdownMode int
   */
  public void schedule(String time, int shutdownMode)
  {
    SchedulingPattern cronTime;
    try
    {
      cronTime = new SchedulingPattern(time);
    }
    catch (InvalidPatternException e)
    {
      return;
    }
    int seconds = (int) ((cronTime.next(System.currentTimeMillis()) / 1000L) - (System.currentTimeMillis() / 1000L));
    schedule(seconds, shutdownMode);
  }
View Full Code Here

  {
    _instance = this;
    _serverStarted = time();
    _listeners = new GameServerListenerList();
    new File("./log/").mkdir();
    version = new Version(GameServer.class);
    _log.info("=================================================");
    _log.info("Revision: ................ " + version.getRevisionNumber());
    _log.info("Build date: .............. " + version.getBuildDate());
    _log.info("Compiler version: ........ " + version.getBuildJdk());
    _log.info("=================================================");
View Full Code Here

    {
      synchronized (this)
      {
        if (_ai == null)
        {
          _ai = new ClonePlayerAI(this);
        }
      }
    }
    return (ClonePlayerAI) _ai;
  }
View Full Code Here

    }
    catch (Exception e)
    {
      _log.error("Unable to create ai of doorId " + _id, e);
    }
    return new DoorAI(door);
  }
View Full Code Here

    if ((activeChar == null) || (_amount < 1))
    {
      return;
    }
   
    MultiSellListContainer list1 = activeChar.getMultisell();
    if (list1 == null)
    {
      activeChar.sendActionFailed();
      activeChar.setMultisell(null);
      return;
    }
   
    if (list1.getListId() != _listId)
    {
      activeChar.sendActionFailed();
      activeChar.setMultisell(null);
      return;
    }
   
    if (activeChar.isActionsDisabled())
    {
      activeChar.sendActionFailed();
      return;
    }
   
    if (activeChar.isInStoreMode())
    {
      activeChar.sendPacket(Msg.WHILE_OPERATING_A_PRIVATE_STORE_OR_WORKSHOP_YOU_CANNOT_DISCARD_DESTROY_OR_TRADE_AN_ITEM);
      return;
    }
   
    if (activeChar.isInTrade())
    {
      activeChar.sendActionFailed();
      return;
    }
   
    if (activeChar.isFishing())
    {
      activeChar.sendPacket(Msg.YOU_CANNOT_DO_THAT_WHILE_FISHING);
      return;
    }
   
    if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && (activeChar.getKarma() < 0) && !activeChar.isGM())
    {
      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)
          {
            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())
    {
      MultiSellHolder.getInstance().SeparateAndSend(list1, activeChar, castle == null ? 0 : castle.getTaxRate());
    }
  }
View Full Code Here

  public void doCrystallize()
  {
    Player player = getSelf();
    NpcInstance merchant = player.getLastNpc();
    Castle castle = merchant != null ? merchant.getCastle(player) : null;
    MultiSellListContainer list = new MultiSellListContainer();
    list.setShowAll(false);
    list.setKeepEnchant(true);
    list.setNoTax(false);
    int entry = 0;
    final Inventory inv = player.getInventory();
    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

    String[] SELLPETS = Config.SERVICES_SELLPETS.split(";");
    if (SELLPETS.length == 0)
    {
      return;
    }
    list = new MultiSellListContainer();
    list.setNoTax(true);
    list.setShowAll(true);
    list.setKeepEnchant(false);
    list.setNoKey(true);
    int entId = 1;
View Full Code Here

   * Constructor for UserCommandHandler.
   */
  private UserCommandHandler()
  {
    registerUserCommandHandler(new ClanWarsList());
    registerUserCommandHandler(new ClanPenalty());
    registerUserCommandHandler(new CommandChannel());
    registerUserCommandHandler(new Escape());
    registerUserCommandHandler(new Loc());
    registerUserCommandHandler(new MyBirthday());
    registerUserCommandHandler(new OlympiadStat());
View Full Code Here

TOP

Related Classes of lineage2.gameserver.data.xml.holder.MultiSellHolder.MultiSellListContainer

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.