@Override
  protected void runImpl() {
    final L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) {
      return;
    }

    final EnchantItemRequest request = activeChar.getRequest(EnchantItemRequest.class);
    if ((request == null) || request.isProcessing()) {
      return;
    }

    request.setEnchantingItem(_objectId);

    final L2ItemInstance item = request.getEnchantingItem();
    final L2ItemInstance scroll = request.getEnchantingScroll();
    if ((item == null) || (scroll == null)) {
      return;
    }

    final EnchantScroll scrollTemplate = EnchantItemData.getInstance().getEnchantScroll(scroll);
    if ((scrollTemplate == null) || !scrollTemplate.isValid(item, null)) {
      activeChar.sendPacket(SystemMessageId.DOES_NOT_FIT_STRENGTHENING_CONDITIONS_OF_THE_SCROLL);
      activeChar.removeRequest(request.getClass());
      activeChar.sendPacket(new ExPutEnchantTargetItemResult(0));
      if (scrollTemplate == null) {
        _log.log(
            Level.WARNING,
            getClass().getSimpleName() + ": Undefined scroll have been used id: " + scroll.getId());
      }
      return;
    }
    request.setTimestamp(System.currentTimeMillis());
    activeChar.sendPacket(new ExPutEnchantTargetItemResult(_objectId));
  }
  @Override
  protected void runImpl() {
    final L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) {
      return;
    }

    final EnchantItemRequest request = activeChar.getRequest(EnchantItemRequest.class);
    if ((request == null) || request.isProcessing()) {
      return;
    }

    final L2ItemInstance supportItem = request.getSupportItem();
    if ((supportItem == null) || (supportItem.getCount() < 1)) {
      request.setSupportItem(L2PcInstance.ID_NONE);
    }

    request.setTimestamp(System.currentTimeMillis());
    activeChar.sendPacket(ExRemoveEnchantSupportItemResult.STATIC_PACKET);
  }
Exemplo n.º 3
0
  @Override
  public boolean testImpl(L2Character effector, L2Character effected, Skill skill, L2Item item) {
    if ((effector == null) || !effector.isPlayer()) {
      return false;
    }

    final Inventory inv = effector.getInventory();
    // If ConditionUsingItemType is one between Light, Heavy or Magic
    if (_armor) {
      // Get the itemMask of the weared chest (if exists)
      final L2ItemInstance chest = inv.getPaperdollItem(Inventory.PAPERDOLL_CHEST);
      if (chest == null) {
        return false;
      }
      final int chestMask = chest.getItem().getItemMask();

      // If chest armor is different from the condition one return false
      if ((_mask & chestMask) == 0) {
        return false;
      }

      // So from here, chest armor matches conditions

      final int chestBodyPart = chest.getItem().getBodyPart();
      // return True if chest armor is a Full Armor
      if (chestBodyPart == L2Item.SLOT_FULL_ARMOR) {
        return true;
      }
      // check legs armor
      final L2ItemInstance legs = inv.getPaperdollItem(Inventory.PAPERDOLL_LEGS);
      if (legs == null) {
        return false;
      }
      final int legMask = legs.getItem().getItemMask();
      // return true if legs armor matches too
      return (_mask & legMask) != 0;
    }
    return (_mask & inv.getWearedMask()) != 0;
  }
Exemplo n.º 4
0
  private static final void showWithdrawWindow(
      L2PcInstance player, WarehouseListType itemtype, byte sortorder) {
    player.sendPacket(ActionFailed.STATIC_PACKET);

    if (!player.hasClanPrivilege(ClanPrivilege.CL_VIEW_WAREHOUSE)) {
      player.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_THE_RIGHT_TO_USE_THE_CLAN_WAREHOUSE);
      return;
    }

    player.setActiveWarehouse(player.getClan().getWarehouse());

    if (player.getActiveWarehouse().getSize() == 0) {
      player.sendPacket(SystemMessageId.YOU_HAVE_NOT_DEPOSITED_ANY_ITEMS_IN_YOUR_WAREHOUSE);
      return;
    }

    for (L2ItemInstance i : player.getActiveWarehouse().getItems()) {
      if (i.isTimeLimitedItem() && (i.getRemainingTime() <= 0)) {
        player.getActiveWarehouse().destroyItem("L2ItemInstance", i, player, null);
      }
    }
    if (itemtype != null) {
      player.sendPacket(
          new SortedWareHouseWithdrawalList(
              player, WareHouseWithdrawalList.CLAN, itemtype, sortorder));
    } else {
      player.sendPacket(new WareHouseWithdrawalList(player, WareHouseWithdrawalList.CLAN));
    }

    if (Config.DEBUG) {
      _log.fine(
          "Source: L2WarehouseInstance.java; Player: "
              + player.getName()
              + "; Command: showRetrieveWindowClan; Message: Showing stored items.");
    }
  }
  @Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    if ("DESPAWN_GUARDIAN".equals(event)) {
      if (npc != null) {
        npc.deleteMe();
      }
      return super.onAdvEvent(event, npc, player);
    }

    final QuestState qs = getQuestState(player, false);
    String htmltext = null;
    if (qs == null) {
      return htmltext;
    }

    switch (event) {
      case "30610-05.htm":
        {
          if (qs.isCreated()) {
            if (getQuestItemsCount(
                    player, DRAGONFLUTE_OF_WIND, DRAGONFLUTE_OF_STAR, DRAGONFLUTE_OF_TWILIGHT)
                == 1) {
              final L2ItemInstance flute = getFlute(player);

              if (flute.getEnchantLevel() < MIN_HACHLING_LVL) {
                htmltext = "30610-06.html";
              } else {
                qs.startQuest();
                qs.setMemoState(100);
                qs.set("fluteObjectId", flute.getObjectId());
                htmltext = event;
              }
            } else {
              htmltext = "30610-06.html";
            }
          }
          break;
        }
      case "30747-04.html":
        {
          final L2Summon summon = player.getPet();

          if (summon == null) {
            htmltext = "30747-02.html";
          } else if (summon.getControlObjectId() != qs.getInt("fluteObjectId")) {
            htmltext = "30747-03.html";
          } else {
            htmltext = event;
          }
          break;
        }
      case "30747-05.html":
        {
          final L2Summon summon = player.getPet();

          if (summon == null) {
            htmltext = "30747-06.html";
          } else if (summon.getControlObjectId() != qs.getInt("fluteObjectId")) {
            htmltext = "30747-06.html";
          } else {
            giveItems(player, FAIRY_LEAF, 4);
            qs.setCond(2, true);
            qs.setMemoState(0);
            htmltext = event;
          }
          break;
        }
      case "30747-07.html":
      case "30747-08.html":
      case "30747-09.html":
      case "30747-10.html":
        {
          htmltext = event;
          break;
        }
    }
    return htmltext;
  }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance talker) {
    final QuestState qs = getQuestState(talker, true);
    String htmltext = getNoQuestMsg(talker);

    switch (npc.getId()) {
      case CRONOS:
        {
          switch (qs.getState()) {
            case State.CREATED:
              {
                final long fluteCount =
                    getQuestItemsCount(
                        talker, DRAGONFLUTE_OF_WIND, DRAGONFLUTE_OF_STAR, DRAGONFLUTE_OF_TWILIGHT);
                if (fluteCount == 0) {
                  break; // this quest does not show up if no flute in inventory
                }

                if (talker.getLevel() < MIN_PLAYER_LVL) {
                  htmltext = "30610-01.htm";
                } else if (fluteCount > 1) {
                  htmltext = "30610-02.htm";
                } else if (getFlute(talker).getEnchantLevel() < MIN_HACHLING_LVL) {
                  htmltext = "30610-03.html";
                } else {
                  htmltext = "30610-04.htm";
                }
                break;
              }
            case State.STARTED:
              {
                htmltext = "30610-07.html";
                break;
              }
            case State.COMPLETED:
              {
                htmltext = getAlreadyCompletedMsg(talker);
                break;
              }
          }
          break;
        }
      case MIMYU:
        {
          switch (qs.getMemoState()) {
            case 100:
              {
                qs.setMemoState(200);
                htmltext = "30747-01.html";
                break;
              }
            case 200:
              {
                final L2Summon summon = talker.getPet();

                if (summon == null) {
                  htmltext = "30747-02.html";
                } else if (summon.getControlObjectId() != qs.getInt("fluteObjectId")) {
                  htmltext = "30747-03.html";
                } else {
                  htmltext = "30747-04.html";
                }
                break;
              }
            case 0:
              {
                htmltext = "30747-07.html";
                break;
              }
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
              {
                if (hasQuestItems(talker, FAIRY_LEAF)) {
                  htmltext = "30747-11.html";
                }
                break;
              }
            case 15:
              {
                if (!hasQuestItems(talker, FAIRY_LEAF)) {
                  final L2Summon summon = talker.getPet();

                  if (summon == null) {
                    htmltext = "30747-12.html";
                  } else if (summon.getControlObjectId() == qs.getInt("fluteObjectId")) {
                    qs.setMemoState(16);
                    htmltext = "30747-13.html";
                  } else {
                    htmltext = "30747-14.html";
                  }
                }
                break;
              }
            case 16:
              {
                if (!hasQuestItems(talker, FAIRY_LEAF)) {
                  if (talker.hasSummon()) {
                    htmltext = "30747-15.html";
                  } else {
                    final long fluteCount =
                        getQuestItemsCount(
                            talker,
                            DRAGONFLUTE_OF_WIND,
                            DRAGONFLUTE_OF_STAR,
                            DRAGONFLUTE_OF_TWILIGHT);

                    if (fluteCount > 1) {
                      htmltext = "30747-17.html";
                    } else if (fluteCount == 1) {
                      final L2ItemInstance flute = getFlute(talker);

                      if (flute.getObjectId() == qs.getInt("fluteObjectId")) {
                        // TODO what if the hatchling has items in his inventory?
                        // Should they be transfered to the strider or given to the player?
                        switch (flute.getId()) {
                          case DRAGONFLUTE_OF_WIND:
                            takeItems(talker, DRAGONFLUTE_OF_WIND, -1);
                            giveItems(talker, DRAGON_BUGLE_OF_WIND, 1);
                            break;
                          case DRAGONFLUTE_OF_STAR:
                            takeItems(talker, DRAGONFLUTE_OF_STAR, -1);
                            giveItems(talker, DRAGON_BUGLE_OF_STAR, 1);
                            break;
                          case DRAGONFLUTE_OF_TWILIGHT:
                            takeItems(talker, DRAGONFLUTE_OF_TWILIGHT, -1);
                            giveItems(talker, DRAGON_BUGLE_OF_TWILIGHT, 1);
                            break;
                        }

                        qs.exitQuest(true, true);
                        htmltext = "30747-16.html";
                      } else {
                        npc.setTarget(talker);
                        npc.doCast(CURSE_OF_MIMYU.getSkill());
                        htmltext = "30747-18.html";
                      }
                    }
                  }
                }
                break;
              }
          }
          break;
        }
    }
    return htmltext;
  }
  @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);
  }