Package l2p.gameserver.model.entity.residence

Examples of l2p.gameserver.model.entity.residence.Castle


    L2Clan clan = player.getClan();
    if(clan != null && SiegeManager.getSiege(this, true) == clan.getSiege() && clan.isDefender())
    {
      return false;
    }
    Castle castle = getCastle();
    if(player.getTerritorySiege() > -1 && castle != null && player.getTerritorySiege() == castle.getId())
    {
      return false;
    }
    return true;
  }
View Full Code Here


    String val = "";
    if(st.countTokens() >= 1)
    {
      val = st.nextToken();
    }
    Castle castle = getCastle();
    if(actualCommand.equalsIgnoreCase("list_siege_clans"))
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_MANAGE_SIEGE))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      castle.getSiege().listRegisterClan(player);
    }
    else if(actualCommand.equalsIgnoreCase("CastleFunctions"))
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_SET_FUNCTIONS))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/chamberlain-castlefunc.htm");
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("ManageTreasure"))
    {
      if(!player.isClanLeader())
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/chamberlain-castlevault.htm");
      html.replace("%Treasure%", String.valueOf(castle.getTreasury()));
      html.replace("%CollectedShops%", String.valueOf(castle.getCollectedShops()));
      html.replace("%CollectedSeed%", String.valueOf(castle.getCollectedSeed()));
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("TakeTreasure"))
    {
      if(!player.isClanLeader())
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      if(!val.equals(""))
      {
        long treasure = Long.parseLong(val);
        if(castle.getTreasury() < treasure)
        {
          NpcHtmlMessage html = new NpcHtmlMessage(player, this);
          html.setFile("data/html/castle/chamberlain/chamberlain-havenottreasure.htm");
          html.replace("%Treasure%", String.valueOf(castle.getTreasury()));
          html.replace("%Requested%", String.valueOf(treasure));
          player.sendPacket(html);
          return;
        }
        if(treasure > 0)
        {
          castle.addToTreasuryNoTax(-treasure, false, false);
          Log.add(castle.getName() + "|" + -treasure + "|CastleChamberlain", "treasury");
          player.addAdena(treasure);
        }
      }
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/chamberlain-castlevault.htm");
      html.replace("%Treasure%", String.valueOf(castle.getTreasury()));
      html.replace("%CollectedShops%", String.valueOf(castle.getCollectedShops()));
      html.replace("%CollectedSeed%", String.valueOf(castle.getCollectedSeed()));
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("PutTreasure"))
    {
      if(!val.equals(""))
      {
        long treasure = Long.parseLong(val);
        if(treasure > player.getAdena())
        {
          player.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
          return;
        }
        if(treasure > 0)
        {
          castle.addToTreasuryNoTax(treasure, false, false);
          Log.add(castle.getName() + "|" + treasure + "|CastleChamberlain", "treasury");
          player.reduceAdena(treasure, true);
        }
      }
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/chamberlain-castlevault.htm");
      html.replace("%Treasure%", String.valueOf(castle.getTreasury()));
      html.replace("%CollectedShops%", String.valueOf(castle.getCollectedShops()));
      html.replace("%CollectedSeed%", String.valueOf(castle.getCollectedSeed()));
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("manor"))
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_MANOR_ADMIN))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      String filename = "";
      if(CastleManorManager.getInstance().isDisabled())
      {
        filename = "data/html/npcdefault.htm";
      }
      else
      {
        int cmd = Integer.parseInt(val);
        switch(cmd)
        {
          case 0:
            filename = "data/html/castle/chamberlain/manor/manor.htm";
            break;
          // TODO: correct in html's to 1
          case 4:
            filename = "data/html/castle/chamberlain/manor/manor_help00" + st.nextToken() + ".htm";
            break;
          default:
            filename = "data/html/castle/chamberlain/chamberlain-no.htm";
            break;
        }
      }
      if(filename.length() > 0)
      {
        NpcHtmlMessage html = new NpcHtmlMessage(player, this);
        html.setFile(filename);
        html.replace("%objectId%", String.valueOf(getObjectId()));
        html.replace("%npcname%", getName());
        player.sendPacket(html);
      }
    }
    else if(actualCommand.startsWith("manor_menu_select"))
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_MANOR_ADMIN))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      // input string format:
      // manor_menu_select?ask=X&state=Y&time=X
      if(CastleManorManager.getInstance().isUnderMaintenance())
      {
        player.sendPacket(Msg.ActionFail, Msg.THE_MANOR_SYSTEM_IS_CURRENTLY_UNDER_MAINTENANCE);
        return;
      }
      String params = actualCommand.substring(actualCommand.indexOf("?") + 1);
      StringTokenizer str = new StringTokenizer(params, "&");
      int ask = Integer.parseInt(str.nextToken().split("=")[1]);
      int state = Integer.parseInt(str.nextToken().split("=")[1]);
      int time = Integer.parseInt(str.nextToken().split("=")[1]);
      int castleId;
      if(state == -1) // info for current manor
      {
        castleId = castle.getId();
      }
      else
      // info for requested manor
      {
        castleId = state;
      }
      switch(ask)
      { // Main action
        case 3: // Current seeds (Manor info)
          if(time == 1 && !CastleManager.getInstance().getCastleByIndex(castleId).isNextPeriodApproved())
          {
            player.sendPacket(new ExShowSeedInfo(castleId, null));
          }
          else
          {
            player.sendPacket(new ExShowSeedInfo(castleId, CastleManager.getInstance().getCastleByIndex(castleId).getSeedProduction(time)));
          }
          break;
        case 4: // Current crops (Manor info)
          if(time == 1 && !CastleManager.getInstance().getCastleByIndex(castleId).isNextPeriodApproved())
          {
            player.sendPacket(new ExShowCropInfo(castleId, null));
          }
          else
          {
            player.sendPacket(new ExShowCropInfo(castleId, CastleManager.getInstance().getCastleByIndex(castleId).getCropProcure(time)));
          }
          break;
        case 5: // Basic info (Manor info)
          player.sendPacket(new ExShowManorDefaultInfo());
          break;
        case 7: // Edit seed setup
          if(castle.isNextPeriodApproved())
          {
            player.sendPacket(Msg.A_MANOR_CANNOT_BE_SET_UP_BETWEEN_6_AM_AND_8_PM);
          }
          else
          {
            player.sendPacket(new ExShowSeedSetting(castle.getId()));
          }
          break;
        case 8: // Edit crop setup
          if(castle.isNextPeriodApproved())
          {
            player.sendPacket(Msg.A_MANOR_CANNOT_BE_SET_UP_BETWEEN_6_AM_AND_8_PM);
          }
          else
          {
            player.sendPacket(new ExShowCropSetting(castle.getId()));
          }
          break;
      }
    }
    else if(actualCommand.equalsIgnoreCase("operate_door")) // door control
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_ENTRY_EXIT))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      if(!val.equals(""))
      {
        boolean open = Integer.parseInt(val) == 1;
        while(st.hasMoreTokens())
        {
          castle.openCloseDoor(player, Integer.parseInt(st.nextToken()), open);
        }
      }
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/" + getTemplate().npcId + "-d.htm");
      html.replace("%npcname%", getName());
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("tax_set")) // tax rates control
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_TAXES))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      if(!val.equals(""))
      {
        // По умолчанию налог не более 15%
        Integer maxTax = 15;
        // Если печатью SEAL_STRIFE владеют DUSK то налог можно выставлять не более 5%
        if(SevenSigns.getInstance().getSealOwner(SevenSigns.SEAL_STRIFE) == SevenSigns.CABAL_DUSK)
        {
          maxTax = 5;
        }
        // Если печатью SEAL_STRIFE владеют DAWN то налог можно выставлять не более 25%
        else if(SevenSigns.getInstance().getSealOwner(SevenSigns.SEAL_STRIFE) == SevenSigns.CABAL_DAWN)
        {
          maxTax = 25;
        }
        if(Integer.parseInt(val) < 0 || Integer.parseInt(val) > maxTax)
        {
          NpcHtmlMessage html = new NpcHtmlMessage(player, this);
          html.setFile("data/html/castle/chamberlain/chamberlain-hightax.htm");
          html.replace("%CurrentTax%", String.valueOf(castle.getTaxPercent()));
          player.sendPacket(html);
          return;
        }
        castle.setTaxPercent(player, Integer.parseInt(val));
      }
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/chamberlain-settax.htm");
      html.replace("%CurrentTax%", String.valueOf(castle.getTaxPercent()));
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("upgrade_castle"))
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_MANAGE_SIEGE))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/chamberlain-upgrades.htm");
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("reinforce"))
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_MANAGE_SIEGE))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/doorStrengthen-" + castle.getName() + ".htm");
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("door_manage"))
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_ENTRY_EXIT))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/doorManage.htm");
      html.replace("%id%", val);
      html.replace("%type%", st.nextToken());
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("upgrade_door_confirm"))
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_MANAGE_SIEGE))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      int id = Integer.parseInt(val);
      int type = Integer.parseInt(st.nextToken());
      int level = Integer.parseInt(st.nextToken());
      long price = getDoorCost(type, level);
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/doorConfirm.htm");
      html.replace("%id%", String.valueOf(id));
      html.replace("%level%", String.valueOf(level));
      html.replace("%type%", String.valueOf(type));
      html.replace("%price%", String.valueOf(price));
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("upgrade_door"))
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_MANAGE_SIEGE))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      int id = Integer.parseInt(val);
      int type = Integer.parseInt(st.nextToken());
      int level = Integer.parseInt(st.nextToken());
      long price = getDoorCost(type, level);
      L2DoorInstance door = castle.getDoor(id);
      int upgradeHp = (door.getMaxHp() - door.getUpgradeHp()) * level - door.getMaxHp();
      if(price == 0 || upgradeHp < 0)
      {
        player.sendMessage(new CustomMessage("common.Error", player));
        return;
      }
      if(door.getUpgradeHp() >= upgradeHp)
      {
        int oldLevel = door.getUpgradeHp() / (door.getMaxHp() - door.getUpgradeHp()) + 1;
        NpcHtmlMessage html = new NpcHtmlMessage(player, this);
        html.setFile("data/html/castle/chamberlain/doorAlready.htm");
        html.replace("%level%", String.valueOf(oldLevel));
        player.sendPacket(html);
        return;
      }
      if(player.getClan().getAdenaCount() < price)
      {
        player.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
        return;
      }
      player.getClan().getWarehouse().destroyItem(57, price);
      castle.upgradeDoor(id, upgradeHp, true);
    }
    else if(actualCommand.equalsIgnoreCase("report")) // Report page
    {
      if(!isHaveRigths(player, L2Clan.CP_CS_USE_FUNCTIONS))
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      String ssq_period;
      if(SevenSigns.getInstance().getCurrentPeriod() == 1)
      {
        ssq_period = "Competition";
      }
      else if(SevenSigns.getInstance().getCurrentPeriod() == 3)
      {
        ssq_period = "Effective sealing";
      }
      else
      {
        ssq_period = "Ready";
      }
      NpcHtmlMessage html = new NpcHtmlMessage(player, this);
      html.setFile("data/html/castle/chamberlain/chamberlain-report.htm");
      html.replace("%FeudName%", castle.getName());
      html.replace("%CharClan%", player.getClan().getName());
      html.replace("%CharName%", player.getName());
      html.replace("%SSPeriod%", ssq_period);
      html.replace("%Avarice%", getSealOwner(1));
      html.replace("%Revelation%", getSealOwner(2));
      html.replace("%Strife%", getSealOwner(3));
      player.sendPacket(html);
    }
    else if(actualCommand.equalsIgnoreCase("Crown")) // Give Crown to Castle Owner
    {
      if(!player.isClanLeader())
      {
        player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2ResidenceManager.NotAuthorizedToDoThis", player));
        return;
      }
      if(player.getInventory().getItemByItemId(6841) == null)
      {
        player.getInventory().addItem(ItemTable.getInstance().createItem(6841));
        NpcHtmlMessage html = new NpcHtmlMessage(player, this);
        html.setFile("data/html/castle/chamberlain/gavecrown.htm");
        html.replace("%CharName%", String.valueOf(player.getName()));
        html.replace("%FeudName%", castle.getName());
        player.sendPacket(html);
      }
      else
      {
        NpcHtmlMessage html = new NpcHtmlMessage(player, this);
View Full Code Here

    if(ch.getOwner() == null)
    {
      return;
    }
    long lease = ch.getLease();
    Castle castle = CastleManager.getInstance().getCastleByIndex(ch.getZone().getTaxById());
    long tax = lease * castle.getTaxPercent() / 100;
    lease += tax;
    if(ch.getOwner().getAdenaCount() >= lease)
    {
      return;
    }
View Full Code Here

    {
      list.remove(itm);
      activeChar.getInventory().addItem(itm);
    }
    double taxRate = 0;
    Castle castle = null;
    if(npc != null)
    {
      castle = npc.getCastle(activeChar);
      if(castle != null)
      {
        taxRate = castle.getTaxRate();
      }
    }
    activeChar.sendPacket(/*new ExRefundList(activeChar), */new ExBuySellList(TradeController.getInstance().getBuyList(_listId), activeChar, taxRate).done());
    activeChar.updateStats();
  }
View Full Code Here

    }
    else
    {
      for(L2Zone zone : zones)
      {
        Castle castle = new Castle(zone.getIndex());
        castle.init();
        getCastles().put(zone.getIndex(), castle);
      }
    }
    _log.info("Loaded: " + getCastles().size() + " castles.");
  }
View Full Code Here

    catch(ArithmeticException e)
    {
      return;
    }
    L2NpcInstance merchant = activeChar.getLastNpc();
    Castle castle = merchant != null ? merchant.getCastle(activeChar) : null;
    GArray<MultiSellIngredient> productId = entry.getProduction();
    if(_keepenchant)
    {
      for(MultiSellIngredient p : productId)
      {
        _enchant = Math.max(_enchant, p.getItemEnchant());
      }
    }
    boolean logExchange = Config.LOG_MULTISELL_ID_LIST.contains(_listId);
    StringBuffer msgb = new StringBuffer();
    if(logExchange)
    {
      msgb.append("<multisell id=").append(_listId).append(" player=\"").append(activeChar.getName()).append("\" oid=").append(activeChar.getObjectId()).append(">\n");
    }
    synchronized(inv)
    {
      int slots = inv.slotsLeft();
      if(slots == 0)
      {
        activeChar.sendPacket(Msg.THE_WEIGHT_AND_VOLUME_LIMIT_OF_INVENTORY_MUST_NOT_BE_EXCEEDED);
        return;
      }
      int req = 0;
      long totalLoad = 0;
      for(MultiSellIngredient i : productId)
      {
        if(i.getItemId() <= 0)
        {
          continue;
        }
        totalLoad += ItemTable.getInstance().getTemplate(i.getItemId()).getWeight() * _amount;
        if(!ItemTable.getInstance().getTemplate(i.getItemId()).isStackable())
        {
          req += _amount;
        }
        else
        {
          req++;
        }
      }
      if(req > slots || !inv.validateWeight(totalLoad))
      {
        activeChar.sendPacket(Msg.THE_WEIGHT_AND_VOLUME_LIMIT_OF_INVENTORY_MUST_NOT_BE_EXCEEDED);
        return;
      }
      if(entry.getIngredients().size() == 0)
      {
        System.out.println("WARNING Ingredients list = 0 multisell id=:" + _listId + " player:" + activeChar.getName());
        activeChar.sendActionFailed();
        return;
      }
      L2Augmentation augmentation = null;
      // Перебор всех ингридиентов, проверка наличия и создание списка забираемого
      for(MultiSellIngredient ingridient : entry.getIngredients())
      {
        int ingridientItemId = ingridient.getItemId();
        long ingridientItemCount = ingridient.getItemCount();
        long total_amount;
        try
        {
          total_amount = SafeMath.safeMulLong(ingridientItemCount, _amount);
        }
        catch(ArithmeticException e)
        {
          activeChar.sendActionFailed();
          return;
        }
        if(ingridientItemId > 0 && !ItemTable.getInstance().getTemplate(ingridientItemId).isStackable())
        {
          for(int i = 0; i < ingridientItemCount * _amount; i++)
          {
            L2ItemInstance[] list = inv.getAllItemsById(ingridientItemId);
            // Если энчант имеет значение - то ищем вещи с точно таким энчантом
            if(_keepenchant)
            {
              L2ItemInstance itemToTake = null;
              for(L2ItemInstance itm : list)
              {
                if((itm.getEnchantLevel() == _enchant || itm.getItem().getType2() > 2) && !_items.contains(new ItemData(itm.getItemId(), itm.getCount(), itm)) && !itm.isShadowItem() && !itm.isTemporalItem() && (itm.getCustomFlags() & L2ItemInstance.FLAG_NO_TRADE) != L2ItemInstance.FLAG_NO_TRADE)
                {
                  itemToTake = itm;
                  if(itm.getAttributeElement() != L2Item.ATTRIBUTE_NONE)
                  {
                    _enchantAttr = itm.getAttributeElement();
                    _enchantAttrVal = itm.getAttributeElementValue();
                  }
                  break;
                }
              }
              if(itemToTake == null)
              {
                activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
                return;
              }
              if(!checkItem(itemToTake, activeChar))
              {
                activeChar.sendActionFailed();
                return;
              }
              if(itemToTake.getAugmentation() != null)
              {
                augmentation = itemToTake.getAugmentation();
              }
              _items.add(new ItemData(itemToTake.getItemId(), 1, itemToTake));
            }
            // Если энчант не обрабатывается берется вещь с наименьшим энчантом
            else
            {
              L2ItemInstance itemToTake = null;
              for(L2ItemInstance itm : list)
              {
                if(!_items.contains(new ItemData(itm.getItemId(), itm.getCount(), itm)) && (itemToTake == null || itm.getEnchantLevel() < itemToTake.getEnchantLevel()) && !itm.isShadowItem() && !itm.isTemporalItem() && (itm.getCustomFlags() & L2ItemInstance.FLAG_NO_TRADE) != L2ItemInstance.FLAG_NO_TRADE && checkItem(itm, activeChar))
                {
                  itemToTake = itm;
                  if(itemToTake.getEnchantLevel() == 0)
                  {
                    break;
                  }
                }
              }
              if(itemToTake == null)
              {
                activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
                return;
              }
              if(itemToTake.getAugmentation() != null)
              {
                augmentation = itemToTake.getAugmentation();
              }
              _items.add(new ItemData(itemToTake.getItemId(), 1, itemToTake));
            }
          }
        }
        else if(ingridientItemId == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
        {
          if(activeChar.getClan() == null)
          {
            activeChar.sendPacket(Msg.YOU_ARE_NOT_A_CLAN_MEMBER);
            return;
          }
          if(activeChar.getClan().getReputationScore() < total_amount)
          {
            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;
          }
          _items.add(new ItemData(ingridientItemId, total_amount, null));
        }
        else if(ingridientItemId == L2Item.ITEM_ID_PC_BANG_POINTS)
        {
          if(activeChar.getPcBangPoints() < total_amount)
          {
            activeChar.sendPacket(Msg.YOU_ARE_SHORT_OF_ACCUMULATED_POINTS);
            return;
          }
          _items.add(new ItemData(ingridientItemId, total_amount, null));
        }
        else if(ingridientItemId == L2Item.ITEM_ID_FAME)
        {
          if(activeChar.getFame() < total_amount)
          {
            activeChar.sendPacket(Msg.NOT_ENOUGH_FAME_POINTS);
            return;
          }
          _items.add(new ItemData(ingridientItemId, total_amount, null));
        }
        else
        {
          if(ingridientItemId == 57)
          {
            totalAdenaCost += ingridientItemCount * _amount;
          }
          L2ItemInstance item = inv.getItemByItemId(ingridientItemId);
          if(item == null || item.getCount() < total_amount)
          {
            activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
            return;
          }
          _items.add(new ItemData(item.getItemId(), total_amount, item));
        }
        if(activeChar.getAdena() < totalAdenaCost)
        {
          activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
          return;
        }
      }
      for(ItemData id : _items)
      {
        long count = id.getCount();
        if(count > 0)
        {
          L2ItemInstance item = id.getItem();
          if(item != null)
          {
            activeChar.sendPacket(SystemMessage.removeItems(item.getItemId(), count));
            if(logExchange)
            {
              msgb.append("\t<destroy id=").append(item.getItemId()).append(" oid=").append(item.getObjectId()).append(" count=").append(count).append(">\n");
            }
            if(item.isEquipped())
            {
              inv.unEquipItemInSlot(item.getEquipSlot());
            }
            inv.destroyItem(item, count, true);
          }
          else if(id.getId() == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
          {
            activeChar.getClan().incReputation((int) -count, false, "MultiSell" + _listId);
            activeChar.sendPacket(new SystemMessage(SystemMessage.S1_POINTS_HAVE_BEEN_DEDUCTED_FROM_THE_CLAN_REPUTATION_SCORE).addNumber(count));
          }
          else if(id.getId() == L2Item.ITEM_ID_PC_BANG_POINTS)
          {
            activeChar.setPcBangPoints(activeChar.getPcBangPoints() - (int) count);
            activeChar.sendPacket(new SystemMessage(SystemMessage.YOU_ARE_USING_S1_POINT).addNumber(count), new ExPCCafePointInfo(activeChar));
          }
          else if(id.getId() == L2Item.ITEM_ID_FAME)
          {
            activeChar.setFame(activeChar.getFame() - (int) count, "MultiSell" + _listId);
            activeChar.sendPacket(new SystemMessage(SystemMessage.S2_S1_HAS_DISAPPEARED).addNumber(count).addString("Fame"));
          }
        }
      }
      if(tax > 0 && !_notax)
      {
        if(castle != null)
        {
          activeChar.sendMessage("Tax: " + tax);
          if(merchant != null && merchant.getReflection().getId() == 0)
          {
            castle.addToTreasury(tax, true, false);
            Log.add(castle.getName() + "|" + tax + "|Multisell", "treasury");
          }
        }
      }
      for(MultiSellIngredient in : productId)
      {
        if(in.getItemId() <= 0)
        {
          if(in.getItemId() == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
          {
            activeChar.getClan().incReputation((int) (in.getItemCount() * _amount), false, "MultiSell" + _listId);
            activeChar.sendPacket(new SystemMessage(SystemMessage.YOUR_CLAN_HAS_ADDED_1S_POINTS_TO_ITS_CLAN_REPUTATION_SCORE).addNumber(in.getItemCount() * _amount));
          }
          else if(in.getItemId() == L2Item.ITEM_ID_PC_BANG_POINTS)
          {
            activeChar.setPcBangPoints(activeChar.getPcBangPoints() + (int) (in.getItemCount() * _amount));
            activeChar.sendPacket(new SystemMessage(SystemMessage.YOU_ACQUIRED_S1_PC_BANG_POINT).addNumber(in.getItemCount() * _amount), new ExPCCafePointInfo(activeChar));
          }
          else if(in.getItemId() == L2Item.ITEM_ID_FAME)
          {
            activeChar.setFame(activeChar.getFame() + (int) (in.getItemCount() * _amount), "MultiSell" + _listId);
          }
        }
        else if(ItemTable.getInstance().getTemplate(in.getItemId()).isStackable())
        {
          L2ItemInstance product = ItemTable.getInstance().createItem(in.getItemId());
          double total = in.getItemCount() * _amount;
          if(total < 0 || total > Long.MAX_VALUE)
          {
            activeChar.sendActionFailed();
            return;
          }
          product.setCount((long) total);
          activeChar.sendPacket(SystemMessage.obtainItems(product));
          if(logExchange)
          {
            msgb.append("\t<add id=").append(product.getItemId()).append(" count=").append(product.getCount()).append(">\n");
          }
          inv.addItem(product);
        }
        else
        {
          for(int i = 0; i < _amount; i++)
          {
            L2ItemInstance product = inv.addItem(ItemTable.getInstance().createItem(in.getItemId()));
            if(_keepenchant)
            {
              product.setEnchantLevel(_enchant);
              if(_enchantAttr != L2Item.ATTRIBUTE_NONE)
              {
                product.setAttributeElement(_enchantAttr, _enchantAttrVal, true);
              }
            }
            if(in.getElementValue() > 0)
            {
              product.setAttributeElement(in.getElement(), in.getElementValue(), true);
            }
            if(augmentation != null && product.isEquipable() && product.canBeEnchanted() && !product.isRaidAccessory())
            {
              product.setAugmentation(augmentation);
            }
            if(logExchange)
            {
              msgb.append("\t<add id=").append(product.getItemId()).append(" oid=").append(product.getObjectId()).append(" count=").append(product.getCount()).append(">\n");
            }
            activeChar.sendPacket(SystemMessage.obtainItems(product));
          }
        }
      }
    }
    activeChar.sendStatusUpdate(false, StatusUpdate.CUR_LOAD);
    if(logExchange)
    {
      msgb.append("</multisell>\n");
      Log.add(msgb.toString(), "multisell", "");
      msgb = null;
    }
    if(_list == null || !_list.isShowAll()) // Если показывается только то, на что хватает материалов обновить окно у игрока
    {
      L2Multisell.getInstance().SeparateAndSend(_listId, activeChar, castle == null ? 0 : castle.getTaxRate());
    }
  }
View Full Code Here

          }
          break;
        case Castle:
          int caslteIndex = player.getClan().getHasCastle();
          if (caslteIndex > 0) {
            Castle castle = CastleManager.getInstance()
                .getCastleByIndex(caslteIndex);
            if (castle != null && !castle.getSiege().isInProgress()) {
              if (castle
                  .isFunctionActive(ResidenceFunction.RESTORE_HP)) {
                init *= 1. + castle.getFunction(
                    ResidenceFunction.RESTORE_HP)
                    .getLevel() / 100.;
              }
            }
          }
View Full Code Here

            }
            break;
          case Castle:
            int caslteIndex = clan.getHasCastle();
            if (caslteIndex > 0) {
              Castle castle = CastleManager.getInstance()
                  .getCastleByIndex(caslteIndex);
              if (castle != null) {
                if (castle
                    .isFunctionActive(ResidenceFunction.RESTORE_MP)) {
                  init *= 1. + castle.getFunction(
                      ResidenceFunction.RESTORE_MP)
                      .getLevel() / 100.;
                }
              }
            }
View Full Code Here

    }
    if(!(target instanceof L2ManorManagerInstance))
    {
      return;
    }
    Castle castle = CastleManager.getInstance().getCastleByIndex(_manorId);
    for(int i = 0; i < _count; i++)
    {
      int seedId = (int) _items[i * 2 + 0];
      long count = _items[i * 2 + 1];
      long price = 0;
      long residual = 0;
      SeedProduction seed = castle.getSeed(seedId, CastleManorManager.PERIOD_CURRENT);
      price = seed.getPrice();
      residual = seed.getCanProduce();
      if(price <= 0)
      {
        return;
      }
      if(residual < count)
      {
        return;
      }
      try
      {
        totalPrice = SafeMath.safeAddLong(totalPrice, SafeMath.safeMulLong(count, price));
      }
      catch(ArithmeticException e)
      {
        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + Long.MAX_VALUE + " adena worth of goods.\r\n" + e.getMessage(), "", Config.DEFAULT_PUNISH);
        return;
      }
      L2Item template = ItemTable.getInstance().getTemplate(seedId);
      totalWeight += count * template.getWeight();
      if(!template.isStackable())
      {
        slots += count;
      }
      else if(player.getInventory().getItemByItemId(seedId) == null)
      {
        slots++;
      }
    }
    if(!player.getInventory().validateWeight(totalWeight))
    {
      sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
      return;
    }
    if(!player.getInventory().validateCapacity(slots))
    {
      sendPacket(Msg.YOUR_INVENTORY_IS_FULL);
      return;
    }
    // Charge buyer
    if(totalPrice < 0 || player.getAdena() < totalPrice)
    {
      sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
      return;
    }
    player.reduceAdena(totalPrice, true);
    // Adding to treasury for Manor Castle
    castle.addToTreasuryNoTax((int) totalPrice, false, true);
    Log.add(castle.getName() + "|" + (int) totalPrice + "|BuySeed", "treasury");
    // Proceed the purchase
    for(int i = 0; i < _count; i++)
    {
      int seedId = (int) _items[i * 2 + 0];
      long count = _items[i * 2 + 1];
      if(count < 0)
      {
        count = 0;
      }
      // Update Castle Seeds Amount
      SeedProduction seed = castle.getSeed(seedId, CastleManorManager.PERIOD_CURRENT);
      seed.setCanProduce(seed.getCanProduce() - count);
      CastleManager.getInstance().getCastleByIndex(_manorId).updateSeed(seed.getId(), seed.getCanProduce(), CastleManorManager.PERIOD_CURRENT);
      // Add item to Inventory and adjust update packet
      player.getInventory().addItem(seedId, count);
      player.sendPacket(SystemMessage.obtainItems(seedId, count, 0));
View Full Code Here

    int weight;
    long currentMoney = activeChar.getAdena();
    int itemId;
    long cnt, price, tax = 0, totalCost = 0, subTotal = 0;
    double taxRate = 0;
    Castle castle = null;
    if(merchant != null)
    {
      castle = merchant.getCastle(activeChar);
      if(castle != null)
      {
        taxRate = castle.getTaxRate();
      }
    }
    for(int i = 0; i < items.size(); i++)
    {
      itemId = items.get(i).getItemId();
      cnt = items.get(i).getCount();
      needsSpace = 2;
      if(items.get(i).getItem().isStackable())
      {
        needsSpace = 1;
        if(activeChar.getInventory().getItemByItemId(itemId) != null)
        {
          needsSpace = 0;
        }
      }
      NpcTradeList list = TradeController.getInstance().getBuyList(_listId);
      if(list == null)
      {
        Log.add("tried to buy from non-exist list " + _listId, "errors", activeChar);
        activeChar.sendActionFailed();
        return;
      }
      TradeItem ti = getItemByItemId(itemId, list);
      price = ti == null ? 0 : ti.getOwnersPrice();
      if(itemId >= 3960 && itemId <= 4921)
      {
        price *= Config.RATE_SIEGE_GUARDS_PRICE;
      }
      if(price == 0 && !activeChar.getPlayerAccess().UseGMShop)
      {
        Util.handleIllegalPlayerAction(activeChar, "RequestBuyItem[191]", "Tried to buy zero price item, list " + _listId + " item " + itemId, 0);
        for(L2ItemInstance item : items)
        {
          item.deleteMe();
        }
        activeChar.sendMessage("Error: zero-price item! Please notify GM.");
        activeChar.sendActionFailed();
        return;
      }
      weight = items.get(i).getItem().getWeight();
      if(price < 0)
      {
        _log.warning("ERROR, no price found. Wrong buylist?");
        for(L2ItemInstance item : items)
        {
          item.deleteMe();
        }
        activeChar.sendActionFailed();
        return;
      }
      try
      {
        if(cnt < 0)
        {
          throw new ArithmeticException("cnt < 0");
        }
        subTotal = SafeMath.safeAddLong(subTotal, SafeMath.safeMulLong(cnt, price)); // Before tax
        tax = SafeMath.safeMulLong(subTotal, taxRate);
        totalCost = SafeMath.safeAddLong(subTotal, tax);
        if(totalCost < 0)
        {
          throw new ArithmeticException("213: Tried to purchase negative " + totalCost + " adena worth of goods.");
        }
        finalLoad = SafeMath.safeAddLong(finalLoad, SafeMath.safeMulLong(cnt, weight));
        if(finalLoad < 0)
        {
          throw new ArithmeticException("254: Tried to purchase negative " + finalLoad + " adena worth of goods.");
        }
      }
      catch(ArithmeticException e)
      {
        Util.handleIllegalPlayerAction(activeChar, "RequestBuyItem[157]", "merchant: " + merchant + ": " + e.getMessage(), 1);
        for(L2ItemInstance item : items)
        {
          item.deleteMe();
        }
        sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED, Msg.ActionFail);
        return;
      }
      if(needsSpace == 2)
      {
        finalCount += cnt;
      }
      else if(needsSpace == 1)
      {
        finalCount += 1;
      }
    }
    if(totalCost > currentMoney || subTotal < 0 || currentMoney <= 0)
    {
      for(L2ItemInstance item : items)
      {
        item.deleteMe();
      }
      sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA, Msg.ActionFail);
      return;
    }
    if(!activeChar.getInventory().validateWeight(finalLoad))
    {
      for(L2ItemInstance item : items)
      {
        item.deleteMe();
      }
      sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT, Msg.ActionFail);
      return;
    }
    if(!activeChar.getInventory().validateCapacity(finalCount))
    {
      for(L2ItemInstance item : items)
      {
        item.deleteMe();
      }
      sendPacket(Msg.YOUR_INVENTORY_IS_FULL, Msg.ActionFail);
      return;
    }
    // Для магазинов с ограниченным количеством товара число продаваемых предметов уменьшаем после всех проверок
    NpcTradeList list = TradeController.getInstance().getBuyList(_listId);
    for(int i = 0; i < items.size(); i++)
    {
      itemId = items.get(i).getItemId();
      cnt = items.get(i).getCount();
      TradeItem ic = getItemByItemId(itemId, list);
      if(ic != null && ic.isCountLimited())
      {
        if(cnt > ic.getCurrentValue())
        {
          int t = (int) (System.currentTimeMillis() / 60000);
          if(ic.getLastRechargeTime() + ic.getRechargeTime() <= t)
          {
            ic.setLastRechargeTime(t);
            ic.setCurrentValue(ic.getCount());
          }
          else
          {
            continue;
          }
        }
        else
        {
          ic.setCurrentValue(ic.getCurrentValue() - cnt);
        }
      }
    }
    activeChar.reduceAdena(totalCost, true);
    for(L2ItemInstance item : items)
    {
      Log.LogItem(activeChar, merchant, Log.BuyItem, item);
      activeChar.getInventory().addItem(item);
    }
    // Add tax to castle treasury if not owned by npc clan
    if(castle != null && castle.getOwnerId() > 0 && activeChar.getReflection().getId() == 0)
    {
      castle.addToTreasury(tax, true, false);
      Log.add(castle.getName() + "|" + tax + "|BuyItem", "treasury");
    }
    sendPacket(new ExBuySellList(list, activeChar, taxRate).done());
    activeChar.updateStats();
  }
View Full Code Here

TOP

Related Classes of l2p.gameserver.model.entity.residence.Castle

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.