@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 != 182201783 || qs == null) return HandlerResult.UNKNOWN;

    int var = qs.getQuestVars().getQuestVars();
    if (var != 0 || qs.getStatus() != QuestStatus.START) return HandlerResult.FAILED;

    if (MathUtil.getDistance(
            1677,
            2520,
            100,
            player.getPosition().getX(),
            player.getPosition().getY(),
            player.getPosition().getZ())
        > 5) return HandlerResult.FAILED;

    int itemId1 = 110100150;
    int itemId2 = 113100144;
    boolean CheckitemId1 = false;
    boolean CheckitemId2 = false;

    List<Item> items1 = player.getEquipment().getEquippedItemsByItemId(itemId1);
    for (@SuppressWarnings("unused") Item ListeCheckitemId1 : items1) {
      CheckitemId1 = true;
    }

    List<Item> items2 = player.getEquipment().getEquippedItemsByItemId(itemId2);
    for (@SuppressWarnings("unused") Item ListeCheckitemId2 : items2) {
      CheckitemId2 = true;
    }

    if (!CheckitemId1 && CheckitemId2
        || CheckitemId1 && !CheckitemId2
        || !CheckitemId1 && !CheckitemId2) 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() {
                PacketSendUtility.broadcastPacket(
                    player,
                    new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 0, 1, 0),
                    true);
                player.getInventory().removeFromBagByObjectId(itemObjId, 1);
                qs.setStatus(QuestStatus.REWARD);
                updateQuestStatus(env);
              }
            },
            3000);
    return HandlerResult.SUCCESS;
  }
 @Override
 public boolean onDialogEvent(QuestCookie env) {
   if (env.getPlayer().getTribe().equals("PC_DARK")) {
     final Player player = env.getPlayer();
     int targetId = 0;
     if (env.getVisibleObject() instanceof Npc)
       targetId = ((Npc) env.getVisibleObject()).getNpcId();
     QuestTemplate template = DataManager.QUEST_DATA.getQuestById(questId);
     QuestState qs = player.getQuestStateList().getQuestState(questId);
     if (targetId == 730330) {
       PlayerClass playerClass = player.getCommonData().getPlayerClass();
       if (playerClass == PlayerClass.RANGER
           || playerClass == PlayerClass.ASSASSIN
           || playerClass == PlayerClass.MAGE
           || playerClass == PlayerClass.PRIEST
           || playerClass == PlayerClass.GLADIATOR
           || playerClass == PlayerClass.WARRIOR
           || playerClass == PlayerClass.SCOUT) {
         if (qs == null
             || qs.getStatus() == QuestStatus.NONE
             || (qs.getStatus() == QuestStatus.COMPLETE
                 && (qs.getCompleteCount() <= template.getMaxRepeatCount()))) {
           if (env.getDialogId() == -1) return sendQuestDialog(env, 1011);
           else return defaultQuestStartDialog(env);
         } else if (qs != null
             && qs.getStatus() == QuestStatus.START
             && qs.getQuestVarById(0) == 0) {
           if (env.getDialogId() == -1) return sendQuestDialog(env, 2375);
           else if (env.getDialogId() == 34) {
             if (player.getInventory().getItemCountByItemId(185000102) >= 1) {
               player.getInventory().removeFromBagByItemId(185000102, 1);
               qs.setStatus(QuestStatus.REWARD);
               qs.setQuestVar(1);
               qs.setCompliteCount(0);
               updateQuestStatus(env);
               return sendQuestDialog(env, 5);
             } else return sendQuestDialog(env, 2716);
           }
         } else if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
           int var = qs.getQuestVarById(0);
           switch (env.getDialogId()) {
             case -1:
               if (var == 1) return sendQuestDialog(env, 5);
             case 17:
               QuestService.questFinish(env, qs.getQuestVars().getQuestVars() - 1);
               PacketSendUtility.sendPacket(
                   player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
               return true;
           }
         }
       }
       return false;
     }
     return false;
   } else {
     return false;
   }
 }
 @Override
 protected void writeImpl(AionConnection con, ByteBuffer buf) {
   writeH(buf, 0x01);
   writeH(buf, (-1 * startedQuestList.size()) & 0xFFFF);
   for (QuestState qs : startedQuestList) // quest list size ( retail max is 30 )
   {
     writeH(buf, qs.getQuestId());
     writeH(buf, 0);
     writeC(buf, qs.getStatus().value());
     writeD(buf, qs.getQuestVars().getQuestVars());
     writeC(buf, 0);
   }
 }
Example #4
0
  public boolean questComplite(QuestCookie env) {
    Player player = env.getPlayer();
    int id = env.getQuestId();
    QuestState qs = player.getQuestStateList().getQuestState(id);
    if (qs == null || qs.getStatus() != QuestStatus.START) return false;

    qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
    qs.setStatus(QuestStatus.REWARD);
    PacketSendUtility.sendPacket(
        player, new SM_QUEST_ACCEPTED(2, id, qs.getStatus(), qs.getQuestVars().getQuestVars()));
    player.getController().updateNearbyQuests();
    return true;
  }
Example #5
0
  public static boolean questFinish(QuestCookie env, int reward) {
    Player player = env.getPlayer();
    synchronized (player) {
      int id = env.getQuestId();

      QuestState qs = player.getQuestStateList().getQuestState(id);
      if (qs == null || qs.getStatus() != QuestStatus.REWARD) return false;

      QuestTemplate template = questsData.getQuestById(id);
      Storage inventory = player.getInventory();

      BonusTemplate bonusTemplate = bonusData.getBonusInfoByQuestId(id);
      List<SimpleCheckItemBonus> appliedBonuses = null;

      if (bonusTemplate != null) {
        int failedChecks = 0;
        QuestTemplate questTemplate = questsData.getQuestById(env.getQuestId());
        // if collectItems not null, the bonus for SimpleCheckItemBonus classes
        // was already applied, then skip them.
        boolean useCheckItems = questTemplate.getCollectItems() == null;

        List<AbstractInventoryBonus> bi = bonusTemplate.getItemBonuses();

        for (int i = 0; i < bi.size(); i++) {
          AbstractInventoryBonus bonus = bi.get(i);
          HandlerResult result = QuestEngine.getInstance().onBonusApply(env, i, bonus);
          if (result == HandlerResult.FAILED)
            continue; // bonus can not be applied (reason: not that bonus or failed)

          if (bonus instanceof SimpleCheckItemBonus) {
            if (!useCheckItems) continue;

            SimpleCheckItemBonus scb = (SimpleCheckItemBonus) bonus;
            if (!scb.canApply(player, env.getQuestId())) {
              // inventory full or other reasons
              failedChecks++;
              break;
            }

            if (appliedBonuses == null) appliedBonuses = new ArrayList<SimpleCheckItemBonus>();
            appliedBonuses.add(scb);
          } else {
            bonus.apply(player, null);
          }
        }
        if (failedChecks > 0) return false;
        else if (appliedBonuses != null) {
          for (SimpleCheckItemBonus scb : appliedBonuses) {
            player.getInventory().removeFromBagByItemId(scb.getCheckedItemId(), scb.getCount());
            scb.apply(player, null);
          }
        }
      }

      Rewards rewards = null;
      if (reward < template.getRewards().size()) rewards = template.getRewards().get(reward);
      else rewards = new Rewards();

      Rewards extRewards = null;
      if (template.getExtRewards() != null
          && qs.getCompleteCount() == template.getMaxRepeatCount() - 1)
        extRewards = template.getExtRewards().get(0);

      List<QuestItems> questItems = new ArrayList<QuestItems>();
      questItems.addAll(rewards.getRewardItem());
      if (extRewards != null) questItems.addAll(extRewards.getRewardItem());

      int dialogId = env.getDialogId();
      if (dialogId != 17 && dialogId != 0) {
        if (template.isUseClassReward() == 1) {
          QuestItems classRewardItem = null;
          PlayerClass playerClass = player.getCommonData().getPlayerClass();
          switch (playerClass) {
            case ASSASSIN:
              classRewardItem = template.getAssassinSelectableReward().get(dialogId - 8);
              break;
            case CHANTER:
              classRewardItem = template.getChanterSelectableReward().get(dialogId - 8);
              break;
            case CLERIC:
              classRewardItem = template.getPriestSelectableReward().get(dialogId - 8);
              break;
            case GLADIATOR:
              classRewardItem = template.getFighterSelectableReward().get(dialogId - 8);
              break;
            case RANGER:
              classRewardItem = template.getRangerSelectableReward().get(dialogId - 8);
              break;
            case SORCERER:
              classRewardItem = template.getWizardSelectableReward().get(dialogId - 8);
              break;
            case SPIRIT_MASTER:
              classRewardItem = template.getElementalistSelectableReward().get(dialogId - 8);
              break;
            case TEMPLAR:
              classRewardItem = template.getKnightSelectableReward().get(dialogId - 8);
              break;
          }
          if (classRewardItem != null) questItems.add(classRewardItem);
        } else {
          QuestItems selectebleRewardItem = null;
          if (rewards != null && !rewards.getSelectableRewardItem().isEmpty()) {
            selectebleRewardItem = rewards.getSelectableRewardItem().get(dialogId - 8);
            if (selectebleRewardItem != null) questItems.add(selectebleRewardItem);
          }
          if (extRewards != null && !extRewards.getSelectableRewardItem().isEmpty()) {
            selectebleRewardItem = extRewards.getSelectableRewardItem().get(dialogId - 8);
            if (selectebleRewardItem != null) questItems.add(selectebleRewardItem);
          }
        }
      }
      if (ItemService.addItems(player, questItems)) {
        if (rewards.getGold() != null) {
          inventory.increaseKinah((player.getRates().getQuestKinahRate() * rewards.getGold()));
        }
        if (rewards.getExp() != null && !player.isNoExperienceGain()) {
          int rewardExp = (player.getRates().getQuestXpRate() * rewards.getExp());
          if (rewardExp > Integer.MAX_VALUE || rewardExp < 0) rewardExp = Integer.MAX_VALUE;
          player.getCommonData().addExp(rewardExp);
        }

        if (rewards.getTitle() != null) {
          player.getTitleList().addTitle(rewards.getTitle());
        }

        if (rewards.getRewardAbyssPoint() != null) {
          player.getCommonData().addAp(rewards.getRewardAbyssPoint());
        }

        if (rewards.getExtendInventory() != null) {
          if (rewards.getExtendInventory() == 1) CubeExpandService.expand(player);
          else if (rewards.getExtendInventory() == 2) WarehouseService.expand(player);
        }

        if (rewards.getExtendStigma() != null) {
          PlayerCommonData pcd = player.getCommonData();
          pcd.setAdvencedStigmaSlotSize(pcd.getAdvencedStigmaSlotSize() + 1);
          PacketSendUtility.sendPacket(
              player, new SM_CUBE_UPDATE(player, 6, pcd.getAdvencedStigmaSlotSize()));
        }

        if (extRewards != null) {
          if (extRewards.getGold() != null) {
            inventory.increaseKinah((player.getRates().getQuestKinahRate() * extRewards.getGold()));
          }
          if (extRewards.getExp() != null) {
            int rewardExp = (player.getRates().getQuestXpRate() * extRewards.getExp());
            player.getCommonData().addExp(rewardExp);
          }

          if (extRewards.getTitle() != null) {
            player.getTitleList().addTitle(extRewards.getTitle());
          }
        }

        // remove all worker list item if finished.
        QuestWorkItems qwi = questsData.getQuestById(id).getQuestWorkItems();

        if (qwi != null) {
          long count = 0;
          for (QuestItems qi : qwi.getQuestWorkItem()) {
            if (qi != null) {
              count = player.getInventory().getItemCountByItemId(qi.getItemId());
              if (count > 0)
                if (!player.getInventory().removeFromBagByItemId(qi.getItemId(), count))
                  return false;
            }
          }
        }

        QuestEngine.getInstance().onQuestFinish(env);
        qs.setStatus(QuestStatus.COMPLETE);
        // save the rewardNo which is used to check quest start conditions
        qs.setQuestVarById(0, reward + 1);
        qs.setCompliteCount(qs.getCompleteCount() + 1);
        qs.setQuestVarById(0, reward + 1);
        PacketSendUtility.sendPacket(
            player, new SM_QUEST_ACCEPTED(2, id, qs.getStatus(), qs.getQuestVars().getQuestVars()));
        player.getController().updateNearbyQuests();
        QuestEngine.getInstance().onLvlUp(env);
        GuildService.getInstance().deleteDaily(player, id);
        return true;
      }
      return true;
    }
  }