Exemplo n.º 1
0
  @Override
  public boolean useBypass(String command, L2PcInstance player, L2Character bypassOrigin) {
    final QuestState qs = getQuestState(player, false);
    if ((qs != null)
        || (player.getLevel() < MIN_LEVEL)
        || (player.getLevel() > MAX_LEVEL)
        || (player.getRace() == Race.ERTHEIA)
        || !command.equals("Q10390_Teleport")) {
      return false;
    }

    if (player.isInParty()) {
      player.sendPacket(
          new ExShowScreenMessage("You cannot teleport when you are in party.", 5000));
    } else if (player.isInCombat()) {
      player.sendPacket(
          new ExShowScreenMessage("You cannot teleport when you are in combat.", 5000));
    } else if (player.isInDuel()) {
      player.sendPacket(
          new ExShowScreenMessage("You cannot teleport when you are in a duel.", 5000));
    } else if (player.isInOlympiadMode()) {
      player.sendPacket(
          new ExShowScreenMessage("You cannot teleport when you are in Olympiad.", 5000));
    } else if (player.isInVehicle()) {
      player.sendPacket(
          new ExShowScreenMessage(
              "You cannot teleport when you are in any vehicle or mount.", 5000));
    } else {
      player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
      player.teleToLocation(TP_LOCS[player.getRace().ordinal()]);
    }
    return true;
  }
Exemplo n.º 2
0
  @RegisterEvent(EventType.ON_PLAYER_LEVEL_CHANGED)
  @RegisterType(ListenerRegisterType.GLOBAL)
  public void OnPlayerLevelChanged(OnPlayerLevelChanged event) {
    final L2PcInstance player = event.getActiveChar();
    final int oldLevel = event.getOldLevel();
    final int newLevel = event.getNewLevel();

    if (((oldLevel == (newLevel - 1)) && (player.getLevel() >= MIN_LEVEL))
        && (player.getLevel() <= MAX_LEVEL)
        && !(player.getRace() == Race.ERTHEIA)) {
      final QuestState qs = getQuestState(player, false);
      if (qs == null) {
        final NpcHtmlMessage html = new NpcHtmlMessage(0, 0);
        html.setHtml(
            HtmCache.getInstance()
                .getHtm(
                    player.getHtmlPrefix(),
                    "scripts/quests/Q10390_KekropusLetter/"
                        + "Announce_"
                        + player.getRace().name()
                        + ".html"));
        player.sendPacket(html);
        // todo: get proper announce html && handle it
      }
      return;
    }
  }
 @Override
 public String onTalk(L2Npc npc, L2PcInstance player) {
   final QuestState st = player.getQuestState(getName());
   String htmltext = getNoQuestMsg(player);
   if (st != null) {
     switch (st.getState()) {
       case State.CREATED:
         {
           htmltext =
               (player.getRace() == Race.DARK_ELF)
                   ? (player.getLevel() >= MIN_LVL) ? "30348-02.htm" : "30348-01.htm"
                   : "30348-00.htm";
           break;
         }
       case State.STARTED:
         {
           if (st.isCond(2) && (st.getQuestItemsCount(DARK_BEZOAR) >= REQUIRED_COUNT)) {
             st.giveItems(LESSER_HEALING_POTION, 5);
             st.addExpAndSp(1000, 0);
             st.exitQuest(false, true);
             htmltext = "30348-05.html";
           } else {
             htmltext = "30348-04.html";
           }
           break;
         }
       case State.COMPLETED:
         {
           htmltext = getAlreadyCompletedMsg(player);
           break;
         }
     }
   }
   return htmltext;
 }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    String htmltext = getNoQuestMsg(player);
    final QuestState st = getQuestState(player, true);
    if (st == null) {
      return htmltext;
    }

    switch (st.getState()) {
      case State.CREATED:
        {
          htmltext =
              (player.getRace() == Race.DARK_ELF)
                  ? (player.getLevel() >= MIN_LEVEL) ? "30346-03.htm" : "30346-02.htm"
                  : "30346-01.htm";
          break;
        }
      case State.STARTED:
        {
          if (hasAtLeastOneQuestItem(player, getRegisteredItemIds())) {
            final long amulets = st.getQuestItemsCount(ORC_AMULET);
            final long necklaces = st.getQuestItemsCount(ORC_NECKLACE);
            st.giveAdena(
                ((amulets * 20) + (necklaces * 30) + ((amulets + necklaces) >= 10 ? 1100 : 0)),
                true);
            takeItems(player, -1, getRegisteredItemIds());
            htmltext = "30346-06.html";
          } else {
            htmltext = "30346-05.html";
          }
          break;
        }
    }
    return htmltext;
  }
 @Override
 public String onTalk(L2Npc npc, L2PcInstance player) {
   final QuestState st = getQuestState(player, true);
   String htmltext = null;
   if (st != null) {
     switch (st.getState()) {
       case State.CREATED:
         {
           htmltext =
               (player.getRace() == Race.ORC)
                   ? (player.getLevel() >= MIN_LVL)
                       ? (hasAtLeastOneQuestItem(player, NECKLACE_OF_VALOR, NECKLACE_OF_COURAGE))
                           ? "30577-07.htm"
                           : "30577-03.htm"
                       : "30577-02.htm"
                   : "30577-01.htm";
           break;
         }
       case State.STARTED:
         {
           switch (st.getCond()) {
             case 1:
               {
                 htmltext = "30577-05.html";
                 break;
               }
             case 2:
               {
                 if (st.getQuestItemsCount(KASHA_WOLF_FANG) >= 50) {
                   if (getRandom(100) <= 13) {
                     st.rewardItems(NECKLACE_OF_VALOR, 1);
                     st.rewardItems(HEALING_POTION, 10);
                   } else {
                     st.rewardItems(NECKLACE_OF_COURAGE, 1);
                   }
                   st.takeItems(KASHA_WOLF_FANG, -1);
                   st.exitQuest(true, true);
                   htmltext = "30577-06.html";
                 }
                 break;
               }
           }
           break;
         }
     }
   }
   return htmltext;
 }
Exemplo n.º 6
0
  @Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    String htmltext = null;
    switch (event) {
      case "33978.html":
      case "33977.html":
        {
          htmltext = event;
          break;
        }
      case "open_tutorial":
        {
          player.sendPacket(
              new TutorialShowHtml(
                  npc.getObjectId(), TUTORIAL_LINK, TutorialShowHtml.LARGE_WINDOW));
          htmltext = npc.getId() + "-1.html";
          break;
        }
      case "learn_skill":
        {
          if (player.getRace() == Race.ERTHEIA) {
            final List<L2SkillLearn> alchemySkills =
                SkillTreesData.getInstance().getAvailableAlchemySkills(player);

            if (alchemySkills.isEmpty()) {
              player.sendPacket(SystemMessageId.THERE_ARE_NO_OTHER_SKILLS_TO_LEARN);
            } else {
              player.sendPacket(
                  new ExAcquirableSkillListByClass(alchemySkills, AcquireSkillType.ALCHEMY));
            }
          } else {
            htmltext = npc.getId() + "-2.html";
          }
          break;
        }
    }
    return htmltext;
  }
  @Override
  protected void runImpl() {
    final L2PcInstance activeChar = getClient().getActiveChar();

    if ((activeChar == null) || (activeChar.getRace() != Race.ERTHEIA)) {
      return;
    }

    for (int i = 1; i <= _activeItems; i++) {
      _allPrice =
          _allPrice
              + (_itemCounts[i]
                  * activeChar.getInventory().getItemByObjectId(_objId[i]).getReferencePrice());
      activeChar.getInventory().destroyItem("Alchemy", _objId[i], _itemCounts[i], activeChar, null);
    }

    _stoneCount = _allPrice / 10000; // TODO: formula is not the correct ratio

    activeChar.getInventory().addItem("Alchemy", _stoneID, _stoneCount, activeChar, null);

    activeChar.sendPacket(new ExTryMixCube(_stoneCount, _stoneID, 0));
    activeChar.sendPacket(new ItemList(activeChar, false));
  }
 @Override
 public String onTalk(L2Npc npc, L2PcInstance player) {
   final QuestState st = getQuestState(player, true);
   String htmltext = null;
   if (st != null) {
     switch (st.getState()) {
       case State.CREATED:
         {
           htmltext =
               (player.getRace() == Race.ORC)
                   ? (player.getLevel() >= MIN_LVL) ? "30572-03.htm" : "30572-02.htm"
                   : "30572-01.htm";
           break;
         }
       case State.STARTED:
         {
           switch (st.getCond()) {
             case 1:
               {
                 htmltext = "30572-05.html";
                 break;
               }
             case 2:
               {
                 st.giveAdena(1500, true);
                 st.exitQuest(true, true);
                 htmltext = "30572-06.html";
                 break;
               }
           }
           break;
         }
     }
   }
   return htmltext;
 }
Exemplo n.º 9
0
 @Override
 public String onTalk(L2Npc npc, L2PcInstance talker) {
   final QuestState qs = getQuestState(talker, true);
   String htmltext = getNoQuestMsg(talker);
   switch (npc.getId()) {
     case BLACKSMITH_KAROYD:
       {
         if (qs.isCreated()) {
           if (talker.getRace() != Race.DARK_ELF) {
             htmltext = "30307-01.htm";
           } else if (talker.getLevel() < MIN_LVL) {
             htmltext = "30307-02.htm";
           } else {
             htmltext = "30307-03.htm";
           }
         } else if (qs.isStarted()) {
           if (hasAtLeastOneQuestItem(
               talker, KAROYDS_LETTER, CECKTINONS_VOUCHER1, CECKTINONS_VOUCHER2)) {
             htmltext = "30307-06.html";
           } else if (hasQuestItems(talker, STEELBENDERS_HEAD)) {
             // Q00281_HeadForTheHills.giveNewbieReward(talker);
             addExpAndSp(talker, 46663, 3999);
             giveAdena(talker, 19799, true);
             for (ItemHolder reward : REWARDS) {
               rewardItems(talker, reward);
             }
             rewardItems(talker, BLOODSABER, 1);
             qs.exitQuest(false, true);
             talker.sendPacket(new SocialAction(talker.getObjectId(), 3));
             htmltext = "30307-07.html";
           }
         } else if (qs.isCompleted()) {
           htmltext = getAlreadyCompletedMsg(talker);
           break;
         }
       }
     case CECON:
       {
         if (qs.isStarted()) {
           if (hasQuestItems(talker, KAROYDS_LETTER)) {
             qs.setCond(2, true);
             takeItems(talker, KAROYDS_LETTER, 1);
             giveItems(talker, CECKTINONS_VOUCHER1, 1);
             htmltext = "30132-01.html";
           } else if (hasAtLeastOneQuestItem(talker, CECKTINONS_VOUCHER1, CECKTINONS_VOUCHER2)) {
             htmltext = "30132-02.html";
           } else if (hasQuestItems(talker, SOUL_CATCHER)) {
             qs.setCond(6, true);
             takeItems(talker, SOUL_CATCHER, 1);
             giveItems(talker, PRESERVE_OIL, 1);
             htmltext = "30132-03.html";
           } else if (hasQuestItems(talker, PRESERVE_OIL)
               && !hasQuestItems(talker, ZOMBIE_HEAD, STEELBENDERS_HEAD)) {
             htmltext = "30132-04.html";
           } else if (hasQuestItems(talker, ZOMBIE_HEAD)) {
             qs.setCond(8, true);
             takeItems(talker, ZOMBIE_HEAD, 1);
             giveItems(talker, STEELBENDERS_HEAD, 1);
             htmltext = "30132-05.html";
           } else if (hasQuestItems(talker, STEELBENDERS_HEAD)) {
             htmltext = "30132-06.html";
           }
         }
         break;
       }
     case HARNE:
       {
         if (qs.isStarted()) {
           if (hasQuestItems(talker, CECKTINONS_VOUCHER1)) {
             qs.setCond(3, true);
             takeItems(talker, CECKTINONS_VOUCHER1, 1);
             giveItems(talker, CECKTINONS_VOUCHER2, 1);
             htmltext = "30144-01.html";
           } else if (hasQuestItems(talker, CECKTINONS_VOUCHER2)) {
             if (getQuestItemsCount(talker, BONE_FRAGMENT) >= 10) {
               qs.setCond(5, true);
               takeItems(talker, CECKTINONS_VOUCHER2, 1);
               takeItems(talker, BONE_FRAGMENT, 10);
               giveItems(talker, SOUL_CATCHER, 1);
               htmltext = "30144-03.html";
             } else {
               htmltext = "30144-02.html";
             }
           } else if (hasQuestItems(talker, SOUL_CATCHER)) {
             htmltext = "30144-04.html";
           }
         }
         break;
       }
   }
   return htmltext;
 }
Exemplo n.º 10
0
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    final QuestState qs = getQuestState(player, true);
    String htmltext = getNoQuestMsg(player);

    if (player.getRace() == Race.ERTHEIA) {
      return "30505-noErtheia.html";
    }

    switch (qs.getState()) {
      case State.CREATED:
        {
          switch (npc.getId()) {
            case RAYMOND:
            case RAINS:
            case ELLENIA:
            case ESRANDELL:
            case GERSHWIN:
            case MENDIO:
            case TOBIAS: // TODO: get all race specified texts
              {
                htmltext = "30297-01.htm";
                break;
              }
            case DRIKUS:
              {
                if (player.getRace() == Race.ORC) {
                  htmltext = "30505-01.htm";
                } else {
                  htmltext = getNoQuestMsg(player);
                }
                break;
              }
            default:
              {
                htmltext = getNoQuestMsg(player);
                break;
              }
          }
          break;
        }
      case State.STARTED:
        {
          switch (npc.getId()) {
            case RAYMOND:
            case RAINS:
            case ELLENIA:
            case ESRANDELL:
            case GERSHWIN:
            case MENDIO:
            case TOBIAS: // TODO: get all race specified texts
              {
                if (qs.isCond(1)) {
                  htmltext = "30297-03.html";
                }
                break;
              }
            case DRIKUS:
              {
                if (qs.isCond(1)) {
                  htmltext = "30505-03.html";
                }
                break;
              }
            case BATHIS:
              {
                if (qs.isCond(1)) {
                  htmltext = "30332-01.html";
                } else if (qs.isCond(2)) {
                  htmltext = "30332-04.html";
                }
                break;
              }
            case GOSTA:
              {
                if (qs.isCond(3)) {
                  htmltext = "30916-01.html";
                }
                break;
              }
            case ELI:
              {
                if (qs.isCond(4)) {
                  htmltext = "33858-01.html";
                }
                break;
              }
          }
          break;
        }
      case State.COMPLETED:
        {
          htmltext = getAlreadyCompletedMsg(player);
          break;
        }
    }
    return htmltext;
  }
Exemplo n.º 11
0
  @Override
  protected void runImpl() {
    L2PcInstance activeChar = getClient().getActiveChar();

    if (activeChar == null) {
      _log.fine("RequestCrystalizeItem: activeChar was null");
      return;
    }

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

    if (_count <= 0) {
      Util.handleIllegalPlayerAction(
          activeChar,
          "[RequestCrystallizeItem] count <= 0! ban! oid: "
              + _objectId
              + " owner: "
              + activeChar.getName(),
          Config.DEFAULT_PUNISH);
      return;
    }

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

    int skillLevel = activeChar.getSkillLevel(CommonSkill.CRYSTALLIZE.getId());
    if (skillLevel <= 0) {
      activeChar.sendPacket(
          SystemMessageId
              .YOU_MAY_NOT_CRYSTALLIZE_THIS_ITEM_YOUR_CRYSTALLIZATION_SKILL_LEVEL_IS_TOO_LOW);
      activeChar.sendPacket(ActionFailed.STATIC_PACKET);
      if ((activeChar.getRace() != Race.DWARF)
          && (activeChar.getClassId().ordinal() != 117)
          && (activeChar.getClassId().ordinal() != 55)) {
        _log.info(
            "Player "
                + activeChar.getClient()
                + " used crystalize with classid: "
                + activeChar.getClassId().ordinal());
      }
      return;
    }

    PcInventory inventory = activeChar.getInventory();
    if (inventory != null) {
      L2ItemInstance item = inventory.getItemByObjectId(_objectId);
      if (item == null) {
        activeChar.sendPacket(ActionFailed.STATIC_PACKET);
        return;
      }

      if (item.isHeroItem()) {
        return;
      }

      if (_count > item.getCount()) {
        _count = activeChar.getInventory().getItemByObjectId(_objectId).getCount();
      }
    }

    final L2ItemInstance itemToRemove = activeChar.getInventory().getItemByObjectId(_objectId);
    if ((itemToRemove == null) || itemToRemove.isShadowItem() || itemToRemove.isTimeLimitedItem()) {
      return;
    }

    if (!itemToRemove.getItem().isCrystallizable()
        || (itemToRemove.getItem().getCrystalCount() <= 0)
        || (itemToRemove.getItem().getCrystalType() == CrystalType.NONE)) {
      _log.warning(
          activeChar.getName()
              + " ("
              + activeChar.getObjectId()
              + ") tried to crystallize "
              + itemToRemove.getItem().getId());
      return;
    }

    if (!activeChar.getInventory().canManipulateWithItemId(itemToRemove.getId())) {
      activeChar.sendMessage("You cannot use this item.");
      return;
    }

    // Check if the char can crystallize items and return if false;
    boolean canCrystallize = true;

    switch (itemToRemove.getItem().getCrystalTypePlus()) {
      case D:
        {
          if (skillLevel < 1) {
            canCrystallize = false;
          }
          break;
        }
      case C:
        {
          if (skillLevel < 2) {
            canCrystallize = false;
          }
          break;
        }
      case B:
        {
          if (skillLevel < 3) {
            canCrystallize = false;
          }
          break;
        }
      case A:
        {
          if (skillLevel < 4) {
            canCrystallize = false;
          }
          break;
        }
      case S:
        {
          if (skillLevel < 5) {
            canCrystallize = false;
          }
          break;
        }
      case R:
        {
          if (skillLevel < 6) {
            canCrystallize = false;
          }
          break;
        }
    }

    if (!canCrystallize) {
      activeChar.sendPacket(
          SystemMessageId
              .YOU_MAY_NOT_CRYSTALLIZE_THIS_ITEM_YOUR_CRYSTALLIZATION_SKILL_LEVEL_IS_TOO_LOW);
      activeChar.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    // activeChar.setInCrystallize(true);

    // unequip if needed
    SystemMessage sm;
    if (itemToRemove.isEquipped()) {
      L2ItemInstance[] unequiped =
          activeChar.getInventory().unEquipItemInSlotAndRecord(itemToRemove.getLocationSlot());
      InventoryUpdate iu = new InventoryUpdate();
      for (L2ItemInstance item : unequiped) {
        iu.addModifiedItem(item);
      }
      activeChar.sendPacket(iu);

      if (itemToRemove.getEnchantLevel() > 0) {
        sm = SystemMessage.getSystemMessage(SystemMessageId.THE_EQUIPMENT_S1_S2_HAS_BEEN_REMOVED);
        sm.addInt(itemToRemove.getEnchantLevel());
        sm.addItemName(itemToRemove);
      } else {
        sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_BEEN_UNEQUIPPED);
        sm.addItemName(itemToRemove);
      }
      activeChar.sendPacket(sm);
    }

    // remove from inventory
    final L2ItemInstance removedItem =
        activeChar.getInventory().destroyItem("Crystalize", _objectId, _count, activeChar, null);

    final InventoryUpdate iu = new InventoryUpdate();
    iu.addRemovedItem(removedItem);
    activeChar.sendPacket(iu);

    final int crystalId = itemToRemove.getItem().getCrystalItemId();
    final int crystalAmount = itemToRemove.getCrystalCount();

    final List<ItemChanceHolder> items = new ArrayList<>();
    items.add(new ItemChanceHolder(crystalId, 100, crystalAmount));

    final CrystalizationData data =
        ItemCrystalizationData.getInstance().getCrystalization(itemToRemove.getId());
    if (data != null) {
      data.getItems().stream().filter(holder -> (holder.getId() != crystalId)).forEach(items::add);
    }

    for (ItemChanceHolder holder : items) {
      final double rand = Rnd.nextDouble() * 100;
      if (rand < holder.getChance()) {
        // add crystals
        final L2ItemInstance createdItem =
            activeChar
                .getInventory()
                .addItem("Crystalize", holder.getId(), holder.getCount(), activeChar, activeChar);

        sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S);
        sm.addItemName(createdItem);
        sm.addLong(holder.getCount());
        activeChar.sendPacket(sm);
      }
    }

    sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_BEEN_CRYSTALLIZED);
    sm.addItemName(removedItem);
    activeChar.sendPacket(sm);

    activeChar.broadcastUserInfo();

    L2World.getInstance().removeObject(removedItem);

    activeChar.setInCrystallize(false);
  }
 @Override
 public String onTalk(L2Npc npc, L2PcInstance player) {
   final QuestState st = player.getQuestState(getName());
   String htmltext = getNoQuestMsg(player);
   if (st != null) {
     switch (npc.getId()) {
       case JENNA:
         {
           switch (st.getState()) {
             case State.CREATED:
               {
                 htmltext =
                     (player.getRace() == Race.DARK_ELF)
                         ? (player.getLevel() >= MIN_LVL) ? "30349-02.htm" : "30349-01.htm"
                         : "30349-00.htm";
                 break;
               }
             case State.STARTED:
               {
                 switch (st.getCond()) {
                   case 1:
                     {
                       if (st.hasQuestItems(JENNAS_LETTER)) {
                         htmltext = "30349-04.html";
                       }
                       break;
                     }
                   case 2:
                     {
                       if (st.hasQuestItems(SENTRY_BLADE1, SENTRY_BLADE2, SENTRY_BLADE3)) {
                         st.takeItems(SENTRY_BLADE1, -1);
                         st.setCond(3, true);
                         htmltext = "30349-05.html";
                       }
                       break;
                     }
                   case 3:
                     {
                       if (hasAtLeastOneQuestItem(player, SENTRY_BLADE2, SENTRY_BLADE3)) {
                         htmltext = "30349-07.html";
                       }
                       break;
                     }
                   case 4:
                     {
                       if (st.getQuestItemsCount(OLD_BRONZE_SWORD) >= 2) {
                         st.giveAdena(820, true);
                         st.exitQuest(false, true);
                         htmltext = "30349-07.html";
                       }
                       break;
                     }
                 }
                 break;
               }
             case State.COMPLETED:
               {
                 htmltext = getAlreadyCompletedMsg(player);
                 break;
               }
           }
           break;
         }
       case HARANT:
         {
           if (st.isCond(1) && st.hasQuestItems(JENNAS_LETTER)) {
             st.takeItems(JENNAS_LETTER, -1);
             st.giveItems(SENTRY_BLADE1, 1);
             st.giveItems(SENTRY_BLADE2, 1);
             st.giveItems(SENTRY_BLADE3, 1);
             st.setCond(2, true);
             htmltext = "30360-01.html";
           } else if (st.isCond(2)) {
             htmltext = "30360-02.html";
           }
           break;
         }
       case ROSELYN:
       case KRISTIN:
         {
           if (st.isCond(3) && st.hasQuestItems(SENTRIES.get(npc.getId()))) {
             st.takeItems(SENTRIES.get(npc.getId()), -1);
             st.giveItems(OLD_BRONZE_SWORD, 1);
             if (st.getQuestItemsCount(OLD_BRONZE_SWORD) >= 2) {
               st.setCond(4, true);
             }
             htmltext = npc.getId() + "-01.html";
           } else if (!st.hasQuestItems(SENTRIES.get(npc.getId()))
               && st.hasQuestItems(OLD_BRONZE_SWORD)) {
             htmltext = npc.getId() + "-02.html";
           }
           break;
         }
     }
   }
   return htmltext;
 }
Exemplo n.º 13
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);
    }
  }