コード例 #1
0
ファイル: ClanWarehouse.java プロジェクト: karolusw/l2j
  @Override
  public boolean useBypass(String command, L2PcInstance activeChar, L2Character target) {
    if (!(target instanceof L2WarehouseInstance)
        && !(target instanceof L2ClanHallManagerInstance)) {
      return false;
    }

    if (activeChar.hasItemRequest()) {
      return false;
    }

    if (activeChar.getClan() == null) {
      activeChar.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_THE_RIGHT_TO_USE_THE_CLAN_WAREHOUSE);
      return false;
    }

    if (activeChar.getClan().getLevel() == 0) {
      activeChar.sendPacket(
          SystemMessageId.ONLY_CLANS_OF_CLAN_LEVEL_1_OR_ABOVE_CAN_USE_A_CLAN_WAREHOUSE);
      return false;
    }

    try {
      if (command.toLowerCase().startsWith(COMMANDS[0])) // WithdrawC
      {
        if (Config.L2JMOD_ENABLE_WAREHOUSESORTING_CLAN) {
          final NpcHtmlMessage msg = new NpcHtmlMessage(((L2Npc) target).getObjectId());
          msg.setFile(activeChar.getHtmlPrefix(), "html/mods/WhSortedC.htm");
          msg.replace("%objectId%", String.valueOf(((L2Npc) target).getObjectId()));
          activeChar.sendPacket(msg);
        } else {
          showWithdrawWindow(activeChar, null, (byte) 0);
        }
        return true;
      } else if (command.toLowerCase().startsWith(COMMANDS[1])) // WithdrawSortedC
      {
        final String param[] = command.split(" ");

        if (param.length > 2) {
          showWithdrawWindow(
              activeChar,
              WarehouseListType.valueOf(param[1]),
              SortedWareHouseWithdrawalList.getOrder(param[2]));
        } else if (param.length > 1) {
          showWithdrawWindow(
              activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.A2Z);
        } else {
          showWithdrawWindow(activeChar, WarehouseListType.ALL, SortedWareHouseWithdrawalList.A2Z);
        }
        return true;
      } else if (command.toLowerCase().startsWith(COMMANDS[2])) // DepositC
      {
        activeChar.sendPacket(ActionFailed.STATIC_PACKET);
        activeChar.setActiveWarehouse(activeChar.getClan().getWarehouse());
        activeChar.setInventoryBlockingStatus(true);

        if (Config.DEBUG) {
          _log.fine(
              "Source: L2WarehouseInstance.java; Player: "
                  + activeChar.getName()
                  + "; Command: showDepositWindowClan; Message: Showing items to deposit.");
        }

        activeChar.sendPacket(new WareHouseDepositList(activeChar, WareHouseDepositList.CLAN));
        return true;
      }

      return false;
    } catch (Exception e) {
      _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
    }
    return false;
  }
コード例 #2
0
  @Override
  public void runImpl() {
    final L2PcInstance activeChar = getClient().getActiveChar();
    if ((activeChar == null) || !Config.ALLOW_MAIL || !Config.ALLOW_ATTACHMENTS) {
      return;
    }

    if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("cancelpost")) {
      return;
    }

    final Message msg = MailManager.getInstance().getMessage(_msgId);
    if (msg == null) {
      return;
    }
    if (msg.getSenderId() != activeChar.getObjectId()) {
      Util.handleIllegalPlayerAction(
          activeChar,
          "Player " + activeChar.getName() + " tried to cancel not own post!",
          Config.DEFAULT_PUNISH);
      return;
    }

    if (!activeChar.isInsideZone(ZoneId.PEACE)) {
      activeChar.sendPacket(SystemMessageId.YOU_CANNOT_CANCEL_IN_A_NON_PEACE_ZONE_LOCATION);
      return;
    }

    if (activeChar.getActiveTradeList() != null) {
      activeChar.sendPacket(SystemMessageId.YOU_CANNOT_CANCEL_DURING_AN_EXCHANGE);
      return;
    }

    if (activeChar.hasItemRequest()) {
      activeChar.sendPacket(
          SystemMessageId.YOU_CANNOT_CANCEL_DURING_AN_ITEM_ENHANCEMENT_OR_ATTRIBUTE_ENHANCEMENT);
      return;
    }

    if (activeChar.getPrivateStoreType() != PrivateStoreType.NONE) {
      activeChar.sendPacket(
          SystemMessageId.YOU_CANNOT_CANCEL_BECAUSE_THE_PRIVATE_STORE_OR_WORKSHOP_IS_IN_PROGRESS);
      return;
    }

    if (!msg.hasAttachments()) {
      activeChar.sendPacket(
          SystemMessageId.YOU_CANNOT_CANCEL_SENT_MAIL_SINCE_THE_RECIPIENT_RECEIVED_IT);
      return;
    }

    final ItemContainer attachments = msg.getAttachments();
    if ((attachments == null) || (attachments.getSize() == 0)) {
      activeChar.sendPacket(
          SystemMessageId.YOU_CANNOT_CANCEL_SENT_MAIL_SINCE_THE_RECIPIENT_RECEIVED_IT);
      return;
    }

    int weight = 0;
    int slots = 0;

    for (L2ItemInstance item : attachments.getItems()) {
      if (item == null) {
        continue;
      }

      if (item.getOwnerId() != activeChar.getObjectId()) {
        Util.handleIllegalPlayerAction(
            activeChar,
            "Player "
                + activeChar.getName()
                + " tried to get not own item from cancelled attachment!",
            Config.DEFAULT_PUNISH);
        return;
      }

      if (item.getItemLocation() != ItemLocation.MAIL) {
        Util.handleIllegalPlayerAction(
            activeChar,
            "Player " + activeChar.getName() + " tried to get items not from mail !",
            Config.DEFAULT_PUNISH);
        return;
      }

      if (item.getLocationSlot() != msg.getId()) {
        Util.handleIllegalPlayerAction(
            activeChar,
            "Player " + activeChar.getName() + " tried to get items from different attachment!",
            Config.DEFAULT_PUNISH);
        return;
      }

      weight += item.getCount() * item.getItem().getWeight();
      if (!item.isStackable()) {
        slots += item.getCount();
      } else if (activeChar.getInventory().getItemByItemId(item.getId()) == null) {
        slots++;
      }
    }

    if (!activeChar.getInventory().validateCapacity(slots)) {
      activeChar.sendPacket(
          SystemMessageId.YOU_COULD_NOT_CANCEL_RECEIPT_BECAUSE_YOUR_INVENTORY_IS_FULL);
      return;
    }

    if (!activeChar.getInventory().validateWeight(weight)) {
      activeChar.sendPacket(
          SystemMessageId.YOU_COULD_NOT_CANCEL_RECEIPT_BECAUSE_YOUR_INVENTORY_IS_FULL);
      return;
    }

    // Proceed to the transfer
    final InventoryUpdate playerIU = Config.FORCE_INVENTORY_UPDATE ? null : new InventoryUpdate();
    for (L2ItemInstance item : attachments.getItems()) {
      if (item == null) {
        continue;
      }

      final long count = item.getCount();
      final L2ItemInstance newItem =
          attachments.transferItem(
              attachments.getName(),
              item.getObjectId(),
              count,
              activeChar.getInventory(),
              activeChar,
              null);
      if (newItem == null) {
        return;
      }

      if (playerIU != null) {
        if (newItem.getCount() > count) {
          playerIU.addModifiedItem(newItem);
        } else {
          playerIU.addNewItem(newItem);
        }
      }
      final SystemMessage sm =
          SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_ACQUIRED_S2_S1);
      sm.addItemName(item.getId());
      sm.addLong(count);
      activeChar.sendPacket(sm);
    }

    msg.removeAttachments();

    // Send updated item list to the player
    if (playerIU != null) {
      activeChar.sendPacket(playerIU);
    } else {
      activeChar.sendPacket(new ItemList(activeChar, false));
    }

    // Update current load status on player
    activeChar.sendPacket(new ExUserInfoInvenWeight(activeChar));

    final L2PcInstance receiver = L2World.getInstance().getPlayer(msg.getReceiverId());
    if (receiver != null) {
      final SystemMessage sm =
          SystemMessage.getSystemMessage(SystemMessageId.S1_CANCELED_THE_SENT_MAIL);
      sm.addCharName(activeChar);
      receiver.sendPacket(sm);
      receiver.sendPacket(new ExChangePostState(true, _msgId, Message.DELETED));
    }

    MailManager.getInstance().deleteMessageInDb(_msgId);

    activeChar.sendPacket(new ExChangePostState(false, _msgId, Message.DELETED));
    activeChar.sendPacket(SystemMessageId.MAIL_SUCCESSFULLY_CANCELLED);
  }