Exemplo n.º 1
0
 /**
  * Fills the community board's multiedit window with text. Must send after sendCBHtml
  *
  * @param activeChar
  * @param text
  */
 public static void fillMultiEditContent(L2PcInstance activeChar, String text) {
   text = text.replaceAll("<br>", Config.EOL);
   List<String> arg = new FastList<>();
   arg.add("0");
   arg.add("0");
   arg.add("0");
   arg.add("0");
   arg.add("0");
   arg.add("0");
   arg.add(activeChar.getName());
   arg.add(Integer.toString(activeChar.getObjectId()));
   arg.add(activeChar.getAccountName());
   arg.add("9");
   arg.add(" ");
   arg.add(" ");
   arg.add(text);
   arg.add("0");
   arg.add("0");
   arg.add("0");
   arg.add("0");
   activeChar.sendPacket(new ShowBoard(arg));
 }
  @Override
  protected void runImpl() {
    L2PcInstance player = getClient().getActiveChar();
    if (player == null) {
      return;
    }

    if (_items == null) {
      player.setPrivateStoreType(PrivateStoreType.NONE);
      player.broadcastUserInfo();
      return;
    }

    if (!player.getAccessLevel().allowTransaction()) {
      player.sendPacket(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
      return;
    }

    if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player) || player.isInDuel()) {
      player.sendPacket(
          SystemMessageId
              .WHILE_YOU_ARE_ENGAGED_IN_COMBAT_YOU_CANNOT_OPERATE_A_PRIVATE_STORE_OR_PRIVATE_WORKSHOP);
      player.sendPacket(new PrivateStoreManageListBuy(player));
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    if (player.isInsideZone(ZoneId.NO_STORE)) {
      player.sendPacket(new PrivateStoreManageListBuy(player));
      player.sendPacket(SystemMessageId.YOU_CANNOT_OPEN_A_PRIVATE_STORE_HERE);
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    if (!player.canOpenPrivateStore()) {
      player.sendPacket(new PrivateStoreManageListBuy(player));
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    TradeList tradeList = player.getBuyList();
    tradeList.clear();

    // Check maximum number of allowed slots for pvt shops
    if (_items.length > player.getPrivateBuyStoreLimit()) {
      player.sendPacket(new PrivateStoreManageListBuy(player));
      player.sendPacket(SystemMessageId.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
      return;
    }

    long totalCost = 0;
    for (Item i : _items) {
      if (!i.addToTradeList(tradeList)) {
        Util.handleIllegalPlayerAction(
            player,
            "Warning!! Character "
                + player.getName()
                + " of account "
                + player.getAccountName()
                + " tried to set price more than "
                + MAX_ADENA
                + " adena in Private Store - Buy.",
            Config.DEFAULT_PUNISH);
        return;
      }

      totalCost += i.getCost();
      if (totalCost > MAX_ADENA) {
        Util.handleIllegalPlayerAction(
            player,
            "Warning!! Character "
                + player.getName()
                + " of account "
                + player.getAccountName()
                + " tried to set total price more than "
                + MAX_ADENA
                + " adena in Private Store - Buy.",
            Config.DEFAULT_PUNISH);
        return;
      }
    }

    // Check for available funds
    if (totalCost > player.getAdena()) {
      player.sendPacket(new PrivateStoreManageListBuy(player));
      player.sendPacket(
          SystemMessageId
              .THE_PURCHASE_PRICE_IS_HIGHER_THAN_THE_AMOUNT_OF_MONEY_THAT_YOU_HAVE_AND_SO_YOU_CANNOT_OPEN_A_PERSONAL_STORE);
      return;
    }

    player.sitDown();
    player.setPrivateStoreType(PrivateStoreType.BUY);
    player.broadcastUserInfo();
    player.broadcastPacket(new PrivateStoreMsgBuy(player));
  }
  @Override
  protected void runImpl() {
    L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    if (_items == null) {
      player.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_NONE);
      player.broadcastUserInfo();
      return;
    }

    if (AttackStanceTaskManager.getInstance().getAttackStanceTask(player) || player.isInDuel()) {
      player.sendPacket(
          SystemMessage.getSystemMessage(SystemMessageId.CANT_OPERATE_PRIVATE_STORE_DURING_COMBAT));
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    if (player.isInsideZone(L2Character.ZONE_NOSTORE)) {
      player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_PRIVATE_WORKSHOP_HERE));
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    L2ManufactureList createList = new L2ManufactureList();

    List<L2RecipeList> dwarfRecipes = Arrays.asList(player.getDwarvenRecipeBook());
    List<L2RecipeList> commonRecipes = Arrays.asList(player.getCommonRecipeBook());

    for (Recipe i : _items) {
      L2RecipeList list = RecipeController.getInstance().getRecipeList(i.getRecipeId());

      if (!dwarfRecipes.contains(list) && !commonRecipes.contains(list)) {
        Util.handleIllegalPlayerAction(
            player,
            "Warning!! Player "
                + player.getName()
                + " of account "
                + player.getAccountName()
                + " tried to set recipe which he dont have.",
            Config.DEFAULT_PUNISH);
        return;
      }

      if (!i.addToList(createList)) {
        Util.handleIllegalPlayerAction(
            player,
            "Warning!! Character "
                + player.getName()
                + " of account "
                + player.getAccountName()
                + " tried to set price more than "
                + MAX_ADENA
                + " adena in Private Manufacture.",
            Config.DEFAULT_PUNISH);
        return;
      }
    }

    createList.setStoreName(
        player.getCreateList() != null ? player.getCreateList().getStoreName() : "");
    player.setCreateList(createList);

    player.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_MANUFACTURE);
    player.sitDown();
    player.broadcastUserInfo();
    player.sendPacket(new RecipeShopMsg(player));
    player.broadcastPacket(new RecipeShopMsg(player));
  }
Exemplo n.º 4
0
  @Override
  protected void runImpl() {
    if (_items == null) {
      return;
    }

    // Get the current player and return if null
    L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) {
      return;
    }

    if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("buy")) {
      activeChar.sendMessage("You are buying too fast.");
      return;
    }

    // If Alternate rule Karma punishment is set to true, forbid Wear to player with Karma
    if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && (activeChar.getKarma() > 0)) {
      return;
    }

    // Check current target of the player and the INTERACTION_DISTANCE
    L2Object target = activeChar.getTarget();
    if (!activeChar.isGM()
        && ((target == null // No target (i.e. GM Shop)
            )
            || !((target instanceof L2MerchantInstance)) // Target not a merchant
            || !activeChar.isInsideRadius(
                target, L2Npc.INTERACTION_DISTANCE, false, false) // Distance is too far
        )) {
      return;
    }

    if ((_count < 1) || (_listId >= 4000000)) {
      sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    // Get the current merchant targeted by the player
    final L2MerchantInstance merchant =
        (target instanceof L2MerchantInstance) ? (L2MerchantInstance) target : null;
    if (merchant == null) {
      _log.warning(getClass().getName() + " Null merchant!");
      return;
    }

    final L2BuyList buyList = BuyListData.getInstance().getBuyList(_listId);
    if (buyList == null) {
      Util.handleIllegalPlayerAction(
          activeChar,
          "Warning!! Character "
              + activeChar.getName()
              + " of account "
              + activeChar.getAccountName()
              + " sent a false BuyList list_id "
              + _listId,
          Config.DEFAULT_PUNISH);
      return;
    }

    long totalPrice = 0;
    Map<Integer, Integer> itemList = new HashMap<>();

    for (int i = 0; i < _count; i++) {
      int itemId = _items[i];

      final Product product = buyList.getProductByItemId(itemId);
      if (product == null) {
        Util.handleIllegalPlayerAction(
            activeChar,
            "Warning!! Character "
                + activeChar.getName()
                + " of account "
                + activeChar.getAccountName()
                + " sent a false BuyList list_id "
                + _listId
                + " and item_id "
                + itemId,
            Config.DEFAULT_PUNISH);
        return;
      }

      L2Item template = product.getItem();
      if (template == null) {
        continue;
      }

      int slot = Inventory.getPaperdollIndex(template.getBodyPart());
      if (slot < 0) {
        continue;
      }

      if (template instanceof L2Weapon) {
        if (activeChar.getRace().ordinal() == 5) {
          if (template.getItemType() == WeaponType.NONE) {
            continue;
          } else if ((template.getItemType() == WeaponType.RAPIER)
              || (template.getItemType() == WeaponType.CROSSBOW)
              || (template.getItemType() == WeaponType.ANCIENTSWORD)) {
            continue;
          }
        }
      } else if (template instanceof L2Armor) {
        if (activeChar.getRace().ordinal() == 5) {
          if ((template.getItemType() == ArmorType.HEAVY)
              || (template.getItemType() == ArmorType.MAGIC)) {
            continue;
          }
        }
      }

      if (itemList.containsKey(slot)) {
        activeChar.sendPacket(SystemMessageId.YOU_CAN_NOT_TRY_THOSE_ITEMS_ON_AT_THE_SAME_TIME);
        return;
      }

      itemList.put(slot, itemId);
      totalPrice += Config.WEAR_PRICE;
      if (totalPrice > Inventory.MAX_ADENA) {
        Util.handleIllegalPlayerAction(
            activeChar,
            "Warning!! Character "
                + activeChar.getName()
                + " of account "
                + activeChar.getAccountName()
                + " tried to purchase over "
                + Inventory.MAX_ADENA
                + " adena worth of goods.",
            Config.DEFAULT_PUNISH);
        return;
      }
    }

    // Charge buyer and add tax to castle treasury if not owned by npc clan because a Try On is not
    // Free
    if ((totalPrice < 0)
        || !activeChar.reduceAdena("Wear", totalPrice, activeChar.getLastFolkNPC(), true)) {
      activeChar.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
      return;
    }

    if (!itemList.isEmpty()) {
      activeChar.sendPacket(new ShopPreviewInfo(itemList));
      // Schedule task
      ThreadPoolManager.getInstance()
          .scheduleGeneral(new RemoveWearItemsTask(activeChar), Config.WEAR_DELAY * 1000);
    }
  }