Examples of CropProcure


Examples of lineage2.gameserver.templates.manor.CropProcure

  {
    List<CropProcure> crops = new ArrayList<>();
    List<Integer> cropsIds = Manor.getInstance().getCropsForCastle(castleId);
    for (int cr : cropsIds)
    {
      crops.add(new CropProcure(cr));
    }
    return crops;
  }
View Full Code Here

Examples of lineage2.gameserver.templates.manor.CropProcure

   * @param buy long
   * @return CropProcure
   */
  public CropProcure getNewCropProcure(int id, long amount, int type, long price, long buy)
  {
    return new CropProcure(id, amount, type, buy, price);
  }
View Full Code Here

Examples of lineage2.gameserver.templates.manor.CropProcure

      _cropData[i * 14 + 3] = Manor.getInstance().getRewardItem(cr, 2);
      _cropData[i * 14 + 4] = Manor.getInstance().getCropPuchaseLimit(cr);
      _cropData[i * 14 + 5] = 0; // Looks like not used
      _cropData[i * 14 + 6] = Manor.getInstance().getCropBasicPrice(cr) * 60 / 100;
      _cropData[i * 14 + 7] = Manor.getInstance().getCropBasicPrice(cr) * 10;
      CropProcure cropPr = c.getCrop(cr, CastleManorManager.PERIOD_CURRENT);
      if (cropPr != null)
      {
        _cropData[i * 14 + 8] = cropPr.getStartAmount();
        _cropData[i * 14 + 9] = cropPr.getPrice();
        _cropData[i * 14 + 10] = cropPr.getReward();
      }
      else
      {
        _cropData[i * 14 + 8] = 0;
        _cropData[i * 14 + 9] = 0;
        _cropData[i * 14 + 10] = 0;
      }
      cropPr = c.getCrop(cr, CastleManorManager.PERIOD_NEXT);
      if (cropPr != null)
      {
        _cropData[i * 14 + 11] = cropPr.getStartAmount();
        _cropData[i * 14 + 12] = cropPr.getPrice();
        _cropData[i * 14 + 13] = cropPr.getReward();
      }
      else
      {
        _cropData[i * 14 + 11] = 0;
        _cropData[i * 14 + 12] = 0;
View Full Code Here

Examples of lineage2.gameserver.templates.manor.CropProcure

        Castle castle = ResidenceHolder.getInstance().getResidence(Castle.class, manorId);
        if (castle == null)
        {
          return;
        }
        CropProcure crop = castle.getCrop(cropId, CastleManorManager.PERIOD_CURRENT);
        if ((crop == null) || (crop.getId() == 0) || (crop.getPrice() == 0))
        {
          return;
        }
        if (count > crop.getAmount())
        {
          return;
        }
        long price = SafeMath.mulAndCheck(count, crop.getPrice());
        long fee = 0;
        if ((currentManorId != 0) && (manorId != currentManorId))
        {
          fee = (price * 5) / 100;
        }
        totalFee = SafeMath.addAndCheck(totalFee, fee);
        int rewardItemId = Manor.getInstance().getRewardItem(cropId, crop.getReward());
        ItemTemplate template = ItemHolder.getInstance().getTemplate(rewardItemId);
        if (template == null)
        {
          return;
        }
        weight = SafeMath.addAndCheck(weight, SafeMath.mulAndCheck(count, template.getWeight()));
        if (!template.isStackable() || (activeChar.getInventory().getItemByItemId(cropId) == null))
        {
          slots++;
        }
      }
    }
    catch (ArithmeticException ae)
    {
      sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
      return;
    }
    activeChar.getInventory().writeLock();
    try
    {
      if (!activeChar.getInventory().validateWeight(weight))
      {
        sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
        return;
      }
      if (!activeChar.getInventory().validateCapacity(slots))
      {
        sendPacket(Msg.YOUR_INVENTORY_IS_FULL);
        return;
      }
      if (activeChar.getInventory().getAdena() < totalFee)
      {
        activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
        return;
      }
      for (int i = 0; i < _count; i++)
      {
        int objId = _items[i];
        int cropId = _crop[i];
        int manorId = _manor[i];
        long count = _itemQ[i];
        ItemInstance item = activeChar.getInventory().getItemByObjectId(objId);
        if ((item == null) || (item.getCount() < count) || (item.getItemId() != cropId))
        {
          continue;
        }
        Castle castle = ResidenceHolder.getInstance().getResidence(Castle.class, manorId);
        if (castle == null)
        {
          continue;
        }
        CropProcure crop = castle.getCrop(cropId, CastleManorManager.PERIOD_CURRENT);
        if ((crop == null) || (crop.getId() == 0) || (crop.getPrice() == 0))
        {
          continue;
        }
        if (count > crop.getAmount())
        {
          continue;
        }
        int rewardItemId = Manor.getInstance().getRewardItem(cropId, crop.getReward());
        long sellPrice = count * crop.getPrice();
        long rewardPrice = ItemHolder.getInstance().getTemplate(rewardItemId).getReferencePrice();
        if (rewardPrice == 0)
        {
          continue;
        }
        double reward = (double) sellPrice / rewardPrice;
        long rewardItemCount = (long) reward + (Rnd.nextDouble() <= (reward % 1) ? 1 : 0);
        if (rewardItemCount < 1)
        {
          SystemMessage sm = new SystemMessage(SystemMessage.FAILED_IN_TRADING_S2_OF_CROP_S1);
          sm.addItemName(cropId);
          sm.addNumber(count);
          activeChar.sendPacket(sm);
          continue;
        }
        long fee = 0;
        if ((currentManorId != 0) && (manorId != currentManorId))
        {
          fee = (sellPrice * 5) / 100;
        }
        if (!activeChar.getInventory().destroyItemByObjectId(objId, count))
        {
          continue;
        }
        if (!activeChar.reduceAdena(fee, false))
        {
          SystemMessage sm = new SystemMessage(SystemMessage.FAILED_IN_TRADING_S2_OF_CROP_S1);
          sm.addItemName(cropId);
          sm.addNumber(count);
          activeChar.sendPacket(sm, Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
          continue;
        }
        crop.setAmount(crop.getAmount() - count);
        castle.updateCrop(crop.getId(), crop.getAmount(), CastleManorManager.PERIOD_CURRENT);
        castle.addToTreasuryNoTax(fee, false, false);
        if (activeChar.getInventory().addItem(rewardItemId, rewardItemCount) == null)
        {
          continue;
        }
View Full Code Here

Examples of lineage2.gameserver.templates.manor.CropProcure

      long sales = _items[(i * 4) + 1];
      long price = _items[(i * 4) + 2];
      int type = (int) _items[(i * 4) + 3];
      if (id > 0)
      {
        CropProcure s = CastleManorManager.getInstance().getNewCropProcure(id, sales, type, price, sales);
        crops.add(s);
      }
    }
    caslte.setCropProcure(crops, CastleManorManager.PERIOD_NEXT);
    caslte.saveCropData(CastleManorManager.PERIOD_NEXT);
View Full Code Here

Examples of net.sf.l2j.gameserver.instancemanager.CastleManorManager.CropProcure

      writeD(L2Manor.getInstance().getRewardItem(item.getItemId(),1));      // reward 1 id
      writeC(1);
      writeD(L2Manor.getInstance().getRewardItem(item.getItemId(),2));      // reward 2 id

      if (_castleCrops.containsKey(item.getItemId())) {
        CropProcure crop = _castleCrops.get(item.getItemId());
        writeD(_manorId);                // manor
        writeD(crop.getAmount());        // buy residual
        writeD(crop.getPrice());         // buy price
        writeC(crop.getReward());        // reward
      } else {
        writeD(0xFFFFFFFF); // manor
        writeD(0);          // buy residual
        writeD(0);          // buy price
        writeC(0);          // reward
View Full Code Here

Examples of net.sf.l2j.gameserver.instancemanager.CastleManorManager.CropProcure

      _cropData[i*14 + 3] = L2Manor.getInstance().getRewardItem(cr, 2);
      _cropData[i*14 + 4] = L2Manor.getInstance().getCropPuchaseLimit(cr);
      _cropData[i*14 + 5] = 0; // Looks like not used
      _cropData[i*14 + 6] = L2Manor.getInstance().getCropBasicPrice(cr) * 60 / 100;
      _cropData[i*14 + 7] = L2Manor.getInstance().getCropBasicPrice(cr) * 10;
      CropProcure cropPr = c.getCrop(cr, CastleManorManager.PERIOD_CURRENT);
      if (cropPr != null) {
        _cropData[i*14 + 8] = cropPr.getStartAmount();
        _cropData[i*14 + 9] = cropPr.getPrice();
        _cropData[i*14 + 10] = cropPr.getReward();
      } else {
        _cropData[i*14 + 8] = 0;
        _cropData[i*14 + 9] = 0;
        _cropData[i*14 + 10] = 0;
      }
      cropPr = c.getCrop(cr, CastleManorManager.PERIOD_NEXT);
      if (cropPr != null) {
        _cropData[i*14 + 11] = cropPr.getStartAmount();
        _cropData[i*14 + 12] = cropPr.getPrice();
        _cropData[i*14 + 13] = cropPr.getReward();
      } else {
        _cropData[i*14 + 11] = 0;
        _cropData[i*14 + 12] = 0;
        _cropData[i*14 + 13] = 0;
      }
View Full Code Here

Examples of net.sf.l2j.gameserver.instancemanager.CastleManorManager.CropProcure

  public ExShowProcureCropDetail(int cropId) {
    _cropId = cropId;
    _castleCrops = new FastMap<Integer, CropProcure>();

    for (Castle c : CastleManager.getInstance().getCastles()) {
      CropProcure cropItem = c.getCrop(_cropId, CastleManorManager.PERIOD_CURRENT);
      if (cropItem != null && cropItem.getAmount() > 0) {
        _castleCrops.put(c.getCastleId(), cropItem);
      }
    }
  }
View Full Code Here

Examples of net.sf.l2j.gameserver.instancemanager.CastleManorManager.CropProcure

    writeD(_cropId); // crop id
    writeD(_castleCrops.size());       // size

    for (int manorId : _castleCrops.keySet()) {
      CropProcure crop = _castleCrops.get(manorId);
      writeD(manorId);          // manor name
      writeD(crop.getAmount()); // buy residual
      writeD(crop.getPrice())// buy price
      writeC(crop.getReward()); // reward type
    }
  }
View Full Code Here

Examples of net.sf.l2j.gameserver.instancemanager.CastleManorManager.CropProcure

        return;
      }

      try
      {
        CropProcure crop = CastleManager.getInstance().getCastleById(manorId).getCrop(itemId, CastleManorManager.PERIOD_CURRENT);
        int rewardItemId = L2Manor.getInstance().getRewardItem(itemId,crop.getReward());
        L2Item template = ItemTable.getInstance().getTemplate(rewardItemId);
        weight += count * template.getWeight();

        if (!template.isStackable())
          slots += count;
        else if (player.getInventory().getItemByItemId(itemId) == null)
          slots++;
      }
      catch (NullPointerException e)
      {
        continue;
      }
    }

    if (!player.getInventory().validateWeight(weight))
    {
      sendPacket(new SystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
      return;
    }

    if (!player.getInventory().validateCapacity(slots))
    {
      sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
      return;
    }

    // Proceed the purchase
    InventoryUpdate playerIU = new InventoryUpdate();

    for (int i = 0; i < _size; i++)
    {
      int objId   = _items[i * 4 + 0];
      int cropId  = _items[i * 4 + 1];
      int manorId = _items[i * 4 + 2];
      int count   = _items[i * 4 + 3];

      if (objId == 0 || cropId == 0 || manorId == 0 || count == 0)
        continue;

      if (count < 1)
        continue;

      CropProcure crop = null;

            try
            {
              crop = CastleManager.getInstance().getCastleById(manorId).getCrop(cropId, CastleManorManager.PERIOD_CURRENT);
            }
            catch (NullPointerException e)
            {
              continue;
            }
      if (crop == null || crop.getId() == 0 || crop.getPrice() == 0)
        continue;

      int fee = 0; // fee for selling to other manors

      int rewardItem = L2Manor.getInstance().getRewardItem(cropId,
          crop.getReward());

      if (count > crop.getAmount())
        continue;

      int sellPrice = (count * L2Manor.getInstance().getCropBasicPrice(
          cropId));
      int rewardPrice = ItemTable.getInstance().getTemplate(rewardItem)
          .getReferencePrice();

      if (rewardPrice == 0)
        continue;

      int rewardItemCount = sellPrice / rewardPrice;
      if (rewardItemCount < 1)
      {
        SystemMessage sm = new SystemMessage(SystemMessageId.FAILED_IN_TRADING_S2_OF_CROP_S1);
        sm.addItemName(cropId);
        sm.addNumber(count);
        player.sendPacket(sm);
        continue;
      }


      if (manorId != currentManorId)
        fee = sellPrice * 5 / 100; // 5% fee for selling to other manor

      if (player.getInventory().getAdena() < fee)
      {
        SystemMessage sm = new SystemMessage(SystemMessageId.FAILED_IN_TRADING_S2_OF_CROP_S1);
        sm.addItemName(cropId);
        sm.addNumber(count);
        player.sendPacket(sm);
        sm = new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
        player.sendPacket(sm);
        continue;
      }

      // Add item to Inventory and adjust update packet
      L2ItemInstance itemDel = null;
      L2ItemInstance itemAdd = null;
      if (player.getInventory().getItemByObjectId(objId) != null)
      {
        // check if player have correct items count
        L2ItemInstance item = player.getInventory().getItemByObjectId(objId);
        if (item.getCount() < count)
          continue;

        itemDel = player.getInventory().destroyItem("Manor", objId, count, player, manorManager);
        if (itemDel == null)
          continue;
        if (fee > 0)
          player.getInventory().reduceAdena("Manor", fee, player,manorManager);
        crop.setAmount(crop.getAmount() - count);
        if (Config.ALT_MANOR_SAVE_ALL_ACTIONS)
          CastleManager.getInstance().getCastleById(manorId).updateCrop(crop.getId(), crop.getAmount(), CastleManorManager.PERIOD_CURRENT);
        itemAdd = player.getInventory().addItem("Manor", rewardItem,rewardItemCount, player, manorManager);
      }
      else
      {
        continue;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.