Example #1
0
  @Override
  public void act(final Player player, final Item parentItem, Item targetItem) {
    PacketSendUtility.sendPacket(
        player,
        new SM_ITEM_USAGE_ANIMATION(
            player.getObjectId(),
            parentItem.getObjectId(),
            parentItem.getItemTemplate().getTemplateId(),
            5000,
            0,
            0));
    player.getController().cancelTask(TaskId.ITEM_USE);
    player
        .getController()
        .addNewTask(
            TaskId.ITEM_USE,
            ThreadPoolManager.getInstance()
                .schedule(
                    new Runnable() {
                      @Override
                      public void run() {
                        PacketSendUtility.sendPacket(
                            player,
                            new SM_ITEM_USAGE_ANIMATION(
                                player.getObjectId(),
                                parentItem.getObjectId(),
                                parentItem.getItemTemplate().getTemplateId(),
                                0,
                                1,
                                0));

                        Storage inventory = player.getInventory();
                        inventory.removeFromBagByObjectId(parentItem.getObjectId(), 1);
                        int decomposedId = parentItem.getItemId() - 1;
                        switch (parentItem.getItemId()) {
                          case 152000112:
                          case 152000328:
                            decomposedId -= 2;
                            break;
                          case 152000213:
                          case 152000327:
                            decomposedId -= 3;
                            break;
                          case 152000326:
                            decomposedId -= 4;
                        }
                        ItemService.addItem(player, decomposedId, 3);
                      }
                    },
                    5000));
  }
  @Override
  public HandlerResult onItemUseEvent(final QuestCookie env, Item item) {
    final Player player = env.getPlayer();
    final QuestState qs = player.getQuestStateList().getQuestState(questId);
    final int id = item.getItemTemplate().getTemplateId();
    final int itemObjId = item.getObjectId();

    if (id == 186000107) {
      if (!ZoneService.getInstance().isInsideZone(player, ZoneName.DEBILKARIM_FORGE_300160000))
        return HandlerResult.FAILED;
      if (qs == null) return HandlerResult.UNKNOWN;
      if (qs.getQuestVarById(0) != 0) return HandlerResult.FAILED;
      if (player.getInventory().getItemCountByItemId(100900716) == 0
          || player.getInventory().getItemCountByItemId(186000099) == 0
          || player.getInventory().getItemCountByItemId(186000106) < 20
          || player.getInventory().getItemCountByItemId(186000107) == 0)
        return HandlerResult.FAILED;
      PacketSendUtility.broadcastPacket(
          player,
          new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 3000, 0, 0),
          true);
      ThreadPoolManager.getInstance()
          .schedule(
              new Runnable() {
                @Override
                public void run() {
                  ItemService.addItems(
                      player, Collections.singletonList(new QuestItems(182209634, 1)));
                  PacketSendUtility.broadcastPacket(
                      player,
                      new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 0, 1, 0),
                      true);
                  player.getInventory().removeFromBagByItemId(186000099, 1);
                  player.getInventory().removeFromBagByItemId(186000106, 20);
                  player.getInventory().removeFromBagByItemId(186000107, 1);
                  qs.setStatus(QuestStatus.REWARD);
                  updateQuestStatus(env);
                }
              },
              3000);
      return HandlerResult.SUCCESS;
    }
    return HandlerResult.UNKNOWN;
  }
 @Override
 public boolean onDialogEvent(QuestCookie env) {
   final Player player = env.getPlayer();
   final QuestState qs = player.getQuestStateList().getQuestState(questId);
   int targetId = 0;
   if (player.getCommonData().getLevel() < 21) return false;
   if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
   if (targetId == 798125) {
     if (qs == null || qs.getStatus() == QuestStatus.NONE) {
       if (env.getDialogId() == 26) return sendQuestDialog(env, 1011);
       else return defaultQuestStartDialog(env);
     } else if (qs.getStatus() == QuestStatus.START) {
       long itemCount;
       long itemCount1;
       long itemCount2;
       if (env.getDialogId() == 26 && qs.getQuestVarById(0) == 0) {
         return sendQuestDialog(env, 2375);
       } else if (env.getDialogId() == 34 && qs.getQuestVarById(0) == 0) {
         itemCount = player.getInventory().getItemCountByItemId(182204227);
         itemCount1 = player.getInventory().getItemCountByItemId(182204228);
         itemCount2 = player.getInventory().getItemCountByItemId(182204229);
         if (itemCount > 4 && itemCount1 > 4 && itemCount2 > 4) {
           player.getInventory().removeFromBagByItemId(182204227, 5);
           player.getInventory().removeFromBagByItemId(182204228, 5);
           player.getInventory().removeFromBagByItemId(182204229, 5);
           qs.setStatus(QuestStatus.REWARD);
           updateQuestStatus(env);
           return sendQuestDialog(env, 5);
         } else {
           return sendQuestDialog(env, 2716);
         }
       } else return defaultQuestEndDialog(env);
     } else if (qs.getStatus() == QuestStatus.REWARD) {
       if (env.getDialogId() == 26 && qs.getQuestVarById(0) == 5) {
         return sendQuestDialog(env, 5);
       } else if (env.getDialogId() == 26 && qs.getQuestVarById(0) == 6) {
         return sendQuestDialog(env, 6);
       } else if (env.getDialogId() == 26 && qs.getQuestVarById(0) == 7) {
         return sendQuestDialog(env, 7);
       } else {
         return defaultQuestEndDialog(env);
       }
     } else {
       return defaultQuestEndDialog(env);
     }
   } else if (targetId == 700317) {
     long itemCount;
     itemCount = player.getInventory().getItemCountByItemId(182204227);
     if (qs != null
         && qs.getStatus() == QuestStatus.START
         && qs.getQuestVarById(0) == 0
         && itemCount < 5) {
       final int targetObjectId = env.getVisibleObject().getObjectId();
       PacketSendUtility.broadcastPacket(
           player, new SM_EMOTION(player, EmotionType.NEUTRALMODE2, 0, targetObjectId), true);
       ThreadPoolManager.getInstance()
           .schedule(
               new Runnable() {
                 @Override
                 public void run() {
                   PacketSendUtility.broadcastPacket(
                       player,
                       new SM_EMOTION(player, EmotionType.START_LOOT, 0, targetObjectId),
                       true);
                 }
               },
               3000);
       return true;
     } else {
       return defaultQuestEndDialog(env);
     }
   } else if (targetId == 700318) {
     long itemCount1;
     itemCount1 = player.getInventory().getItemCountByItemId(182204228);
     if (qs != null
         && qs.getStatus() == QuestStatus.START
         && qs.getQuestVarById(0) == 0
         && itemCount1 < 5) {
       final int targetObjectId = env.getVisibleObject().getObjectId();
       PacketSendUtility.broadcastPacket(
           player, new SM_EMOTION(player, EmotionType.NEUTRALMODE2, 0, targetObjectId), true);
       ThreadPoolManager.getInstance()
           .schedule(
               new Runnable() {
                 @Override
                 public void run() {
                   PacketSendUtility.broadcastPacket(
                       player,
                       new SM_EMOTION(player, EmotionType.START_LOOT, 0, targetObjectId),
                       true);
                 }
               },
               3000);
       return true;
     } else {
       return defaultQuestEndDialog(env);
     }
   } else if (targetId == 700319) {
     long itemCount2;
     itemCount2 = player.getInventory().getItemCountByItemId(182204229);
     if (qs != null
         && qs.getStatus() == QuestStatus.START
         && qs.getQuestVarById(0) == 0
         && itemCount2 < 5) {
       final int targetObjectId = env.getVisibleObject().getObjectId();
       PacketSendUtility.broadcastPacket(
           player, new SM_EMOTION(player, EmotionType.NEUTRALMODE2, 0, targetObjectId), true);
       ThreadPoolManager.getInstance()
           .schedule(
               new Runnable() {
                 @Override
                 public void run() {
                   PacketSendUtility.broadcastPacket(
                       player,
                       new SM_EMOTION(player, EmotionType.START_LOOT, 0, targetObjectId),
                       true);
                 }
               },
               3000);
       return true;
     } else {
       return defaultQuestEndDialog(env);
     }
   } else {
     return defaultQuestEndDialog(env);
   }
 }