@Override
 public boolean onDialogEvent(QuestCookie env) {
   final Player player = env.getPlayer();
   int targetId = 0;
   if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
   final QuestState qs = player.getQuestStateList().getQuestState(questId);
   QuestTemplate template = questsData.getQuestById(questId);
   if (targetId == 204639) {
     if (qs == null || qs.getStatus() == QuestStatus.NONE) {
       if (env.getDialogId() == 2) {
         PlayerClass playerClass = player.getCommonData().getPlayerClass();
         PlayerClass startPC = null;
         try {
           startPC = PlayerClass.getStartingClassFor(playerClass);
         } catch (IllegalArgumentException e) {
           startPC = playerClass; // already a start class
         }
         if (startPC == PlayerClass.MAGE || startPC == PlayerClass.PRIEST) {
           QuestService.startQuest(env, QuestStatus.START);
           return sendQuestDialog(env, 1011);
         } else {
           return sendQuestDialog(env, 3739);
         }
       }
     } else if (qs != null && qs.getStatus() == QuestStatus.START) {
       if (env.getDialogId() == 2) {
         return sendQuestDialog(env, 1011);
       } else if (env.getDialogId() == 1011) {
         if (player.getInventory().getItemCountByItemId(186000003) >= 16) {
           qs.setQuestVarById(0, 0);
           qs.setStatus(QuestStatus.REWARD);
           updateQuestStatus(env);
           return sendQuestDialog(env, 5);
         } else {
           return sendQuestDialog(env, 1009);
         }
       } else if (env.getDialogId() == 1352) {
         if (player.getInventory().getItemCountByItemId(186000003) >= 32) {
           qs.setQuestVarById(0, 1);
           qs.setStatus(QuestStatus.REWARD);
           updateQuestStatus(env);
           return sendQuestDialog(env, 6);
         } else {
           return sendQuestDialog(env, 1009);
         }
       }
     } else if (qs.getStatus() == QuestStatus.COMPLETE) {
       if (env.getDialogId() == 2) {
         if ((qs.getCompleteCount() <= template.getMaxRepeatCount())) {
           QuestService.startQuest(env, QuestStatus.START);
           return sendQuestDialog(env, 1011);
         } else return sendQuestDialog(env, 1008);
       }
     } else if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
       return defaultQuestEndDialog(env, qs.getQuestVarById(0));
     }
   }
   return false;
 }
Exemple #2
0
  /**
   * Check if a player is doing a quest for the given drop.
   *
   * @param player
   * @param drop
   * @return
   */
  private static boolean hasQuestForDrop(Player player, QuestDrop drop) {
    int questId = drop.getQuestId();
    QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (qs == null || qs.getStatus() != QuestStatus.START) return false;
    QuestTemplate template = questsData.getQuestById(questId);
    CollectItems collectItems = template.getCollectItems();
    if (collectItems == null) return true;

    for (CollectItem collectItem : collectItems.getCollectItem()) {
      int collectItemId = collectItem.getItemId();
      int dropItemId = drop.getItemId();
      if (collectItemId != dropItemId) continue;
      long count = player.getInventory().getItemCountByItemId(collectItemId);
      if (collectItem.getCount() > count) return true;
    }
    return false;
  }
Exemple #3
0
  public static boolean startQuest(QuestCookie env, QuestStatus questStatus) {
    Player player = env.getPlayer();
    int id = env.getQuestId();
    QuestTemplate template = questsData.getQuestById(env.getQuestId());
    if (id < 80000 && questStatus != QuestStatus.LOCKED) {
      if (!canStart(env)) return false;
    }
    PacketSendUtility.sendPacket(player, new SM_QUEST_ACCEPTED(1, id, questStatus, 0));
    QuestState qs = player.getQuestStateList().getQuestState(id);
    if (qs == null) {
      qs = new QuestState(template.getId(), questStatus, 0, 0);
      player.getQuestStateList().addQuest(id, qs);
    } else {
      if (template.getMaxRepeatCount() >= qs.getCompleteCount()) {
        qs.setStatus(questStatus);
        qs.setQuestVar(0);
      }
    }

    player.getController().updateNearbyQuests();
    return true;
  }
Exemple #4
0
  public static boolean canStart(QuestCookie env) {
    if (!checkNearBy(env, 0)) return false;
    Player player = env.getPlayer();
    QuestTemplate template = questsData.getQuestById(env.getQuestId());

    if (!checkStartConditions(player, template)) return false;

    if (template.getCombineSkill() != null) {
      SkillListEntry skill = player.getSkillList().getSkillEntry(template.getCombineSkill());
      if (skill == null) return false;
      if (skill.getSkillLevel() < template.getCombineSkillPoint()) return false;
      if (template.getCombineSkillPoint() == 449 || template.getCombineSkillPoint() == 499)
        return true;
      if (skill.getSkillLevel() - 40 > template.getCombineSkillPoint()) return false;
      return true;
    }

    QuestState qs = player.getQuestStateList().getQuestState(template.getId());
    if (qs != null && qs.getStatus().value() > 0) {
      return qs.canRepeat(template.getMaxRepeatCount());
    }
    return true;
  }
Exemple #5
0
  public static boolean checkNearBy(QuestCookie env, int levelDiff) {
    Player player = env.getPlayer();
    QuestTemplate template = questsData.getQuestById(env.getQuestId());

    if (template == null) return false;

    if (template.getRacePermitted() != null) {
      if (template.getRacePermitted().ordinal() != player.getCommonData().getRace().ordinal())
        return false;
    }

    // min level - 2 so that the gray quest arrow shows when quest is almost available
    if (player.getLevel() < template.getMinlevelPermitted() - levelDiff) return false;

    if (template.getMaxlevelPermitted() != 0 && player.getLevel() > template.getMaxlevelPermitted())
      return false;

    if (!template.isWeeklyActive()) return false;

    if (template.getClassPermitted().size() != 0) {
      if (!template.getClassPermitted().contains(player.getCommonData().getPlayerClass()))
        return false;
    }

    if (template.getGenderPermitted() != null) {
      if (template.getGenderPermitted().ordinal() != player.getGender().ordinal()) return false;
    }

    QuestState qs = player.getQuestStateList().getQuestState(template.getId());
    if (qs != null) {
      if (qs.canRepeat(template.getMaxRepeatCount())) return true;
      else if (qs.getStatus() != QuestStatus.LOCKED && qs.getStatus() != QuestStatus.NONE)
        return false;
    }
    return true;
  }
Exemple #6
0
  @Override
  public void executeCommand(Player admin, String[] params) {
    if (admin.getAccessLevel() < AdminConfig.COMMAND_RELOAD) {
      PacketSendUtility.sendMessage(admin, "You dont have enough rights to execute this command");
      return;
    }

    if (params == null || params.length != 1) {
      sendSyntax(admin);
      return;
    }

    ReloadType reloadType = ReloadType.UNKNOWN;
    try {
      reloadType = ReloadType.valueOf(params[0].toUpperCase());
    } catch (Exception e) {
    }

    switch (reloadType) {
      case COMMAND:
        try {
          ChatHandlers.getInstance().reloadChatHandlers();
          PacketSendUtility.sendMessage(admin, "Admin/user commands reloaded successfully!");
        } catch (GameServerError e) {
          PacketSendUtility.sendMessage(
              admin, "Admin/user commands failed to reload! Keeping last version ...");
        }
        break;
      case NPC:
        File npcXml = new File("./data/static_data/npcs/npc_templates.xml");
        List<NpcTemplate> npcTemplates = new ArrayList<NpcTemplate>();
        try {
          JAXBContext jc = JAXBContext.newInstance(StaticData.class);
          Unmarshaller un = jc.createUnmarshaller();
          un.setSchema(getSchema("./data/static_data/static_data.xsd"));

          NpcData data = (NpcData) un.unmarshal(npcXml);
          if (data != null && data.getTemplates() != null) npcTemplates.addAll(data.getTemplates());
        } catch (Exception e) {
          PacketSendUtility.sendMessage(
              admin, "NPC templates reload failed! Keeping last version ...");
          log.error(e);
          return;
        }

        if (npcTemplates.size() > 0) {
          DataManager.NPC_DATA.setTemplates(npcTemplates);

          PacketSendUtility.sendMessage(
              admin,
              "NPC templates reloaded successfuly, now updating World to reflect changes ...!");

          World.getInstance()
              .doOnAllNpcs(
                  new Executor<Npc>() {

                    @Override
                    public boolean run(Npc object) {
                      NpcTemplate newTemplate =
                          DataManager.NPC_DATA.getNpcTemplate(object.getNpcId());
                      if (newTemplate != null) {
                        object.setObjectTemplate(newTemplate);
                      }
                      return true;
                    }
                  },
                  true);

          PacketSendUtility.sendMessage(admin, "Complete !");

        } else
          PacketSendUtility.sendMessage(
              admin, "NPC templates reload failed! Keeping last version ...");

        break;
      case PORTAL:
        File portalDir = new File("./data/static_data/portals");
        List<PortalTemplate> portalTemplates = new ArrayList<PortalTemplate>();
        try {
          JAXBContext jc = JAXBContext.newInstance(StaticData.class);
          Unmarshaller un = jc.createUnmarshaller();
          un.setSchema(getSchema("./data/static_data/static_data.xsd"));

          for (File file : listFiles(portalDir, true)) {
            PortalData data = (PortalData) un.unmarshal(file);
            if (data != null && data.getPortals() != null)
              portalTemplates.addAll(data.getPortals());
          }

        } catch (Exception e) {
          PacketSendUtility.sendMessage(admin, "Portals reload failed! Keeping last version ...");
          log.error(e);
          return;
        }
        if (portalTemplates.size() > 0) {
          DataManager.PORTAL_DATA.setPortals(portalTemplates);
          PacketSendUtility.sendMessage(admin, "Portals reloaded successfuly!");
        } else
          PacketSendUtility.sendMessage(admin, "Portals reload failed! Keeping last version ...");
        break;
      case QUEST:
        File questXml = new File("./data/static_data/quest_data/quest_data.xml");
        File questDir = new File("./data/static_data/quest_script_data");

        QuestsData newQuestData;
        ArrayList<QuestScriptsData> newScriptData = new ArrayList<QuestScriptsData>();

        try {
          JAXBContext jc = JAXBContext.newInstance(StaticData.class);
          Unmarshaller un = jc.createUnmarshaller();
          un.setSchema(getSchema("./data/static_data/static_data.xsd"));
          newQuestData = (QuestsData) un.unmarshal(questXml);
          for (File file : listFiles(questDir, true)) {
            QuestScriptsData data = ((QuestScriptsData) un.unmarshal(file));
            if (data != null) if (data.getData() != null) newScriptData.add(data);
          }
        } catch (Exception e) {
          PacketSendUtility.sendMessage(admin, "Quests reload failed! Keeping last version ...");
          log.error(e);
          return;
        }

        if (newQuestData != null) {
          try {
            DataManager.QUEST_DATA.setQuestsData(newQuestData.getQuestsData());
            QuestScriptsData questScriptsData = DataManager.QUEST_SCRIPTS_DATA;
            questScriptsData.getData().clear();
            for (QuestScriptsData qsd : newScriptData) {
              questScriptsData.getData().addAll(qsd.getData());
            }
            QuestEngine.getInstance().load(true);
            PacketSendUtility.sendMessage(admin, "Quests reloaded successfuly!");
          } catch (GameServerError e) {
            PacketSendUtility.sendMessage(admin, "Quests reload failed! Keeping last version ...");
            log.error(e);
            return;
          }
        }
        break;
      case SKILL:
        File skillDir = new File("./data/static_data/skills");
        List<SkillTemplate> skillTemplates = new ArrayList<SkillTemplate>();
        try {
          JAXBContext jc = JAXBContext.newInstance(StaticData.class);
          Unmarshaller un = jc.createUnmarshaller();
          un.setSchema(getSchema("./data/static_data/static_data.xsd"));

          for (File file : listFiles(skillDir, true)) {
            SkillData data = (SkillData) un.unmarshal(file);
            if (data != null) skillTemplates.addAll(data.getSkillTemplates());
          }
        } catch (Exception e) {
          PacketSendUtility.sendMessage(admin, "Skills reload failed! Keeping last version ...");
          log.error(e);
          return;
        }

        if (skillTemplates.size() > 0) {
          DataManager.SKILL_DATA.setSkillTemplates(skillTemplates);
          PacketSendUtility.sendMessage(admin, "Skills reloaded successfuly!");
        } else
          PacketSendUtility.sendMessage(admin, "Skills reload failed! Keeping last version ...");
        break;
      case SPAWN:
        File spawnDir = new File("./data/static_data/spawns");
        List<SpawnGroup> spawnTemplates = new ArrayList<SpawnGroup>();
        try {
          JAXBContext jc = JAXBContext.newInstance(StaticData.class);
          Unmarshaller un = jc.createUnmarshaller();
          un.setSchema(getSchema("./data/static_data/static_data.xsd"));

          for (File file : listFiles(spawnDir, true)) {
            SpawnsData data = (SpawnsData) un.unmarshal(file);
            if (data != null && data.getSpawnGroups() != null)
              spawnTemplates.addAll(data.getSpawnGroups());
          }
        } catch (Exception e) {
          PacketSendUtility.sendMessage(admin, "Spawns reload failed! Keeping last version ...");
          log.error(e);
          return;
        }

        if (spawnTemplates.size() > 0) {
          DataManager.SPAWNS_DATA.setSpawns(spawnTemplates);
          PacketSendUtility.sendMessage(admin, "Spawns reloaded successfuly!");
        } else
          PacketSendUtility.sendMessage(
              admin, "Spawns reload failed with empty object! Keeping last version ...");
        break;
      default:
        sendSyntax(admin);
        return;
    }
  }
  @Override
  public boolean onDialogEvent(QuestCookie env) {
    final Player player = env.getPlayer();
    if (player.getLevel() <= 50) return sendQuestDialog(env, 1008);
    int targetId = 0;
    if (env.getVisibleObject() instanceof Npc) targetId = ((Npc) env.getVisibleObject()).getNpcId();
    final QuestState qs = player.getQuestStateList().getQuestState(questId);
    QuestTemplate template = questsData.getQuestById(questId);

    if (targetId == 798914) {
      if (qs == null || qs.getStatus() == QuestStatus.NONE) {
        if (env.getDialogId() == 2) {
          PlayerClass playerClass = player.getCommonData().getPlayerClass();
          if (playerClass == PlayerClass.GLADIATOR
              || playerClass == PlayerClass.TEMPLAR
              || playerClass == PlayerClass.WARRIOR) {
            env.setQuestId(questId);
            QuestService.startQuest(env, QuestStatus.START);
            return true;
          } else {
            return sendQuestDialog(env, 3739);
          }
        }
      } else if (qs != null && qs.getStatus() == QuestStatus.START) {
        if (env.getDialogId() == 2) {
          return sendQuestDialog(env, 1011);
        } else if (env.getDialogId() == 10000) {
          if (player.getInventory().getItemCountByItemId(186000018) >= 1800) {
            qs.setQuestVarById(0, qs.getQuestVarById(0) + 1);
            player.getInventory().removeFromBagByItemId(186000018, 1800);
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return sendQuestDialog(env, 5);
          } else {
            return sendQuestDialog(env, 1009);
          }
        } else if (env.getDialogId() == 10001) {
          if (player.getInventory().getItemCountByItemId(186000018) >= 1200) {
            qs.setQuestVarById(0, qs.getQuestVarById(0) + 2);
            player.getInventory().removeFromBagByItemId(186000018, 1200);
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return sendQuestDialog(env, 6);
          } else {
            return sendQuestDialog(env, 1009);
          }
        } else if (env.getDialogId() == 10002) {
          if (player.getInventory().getItemCountByItemId(186000018) >= 900) {
            qs.setQuestVarById(0, qs.getQuestVarById(0) + 3);
            player.getInventory().removeFromBagByItemId(186000018, 900);
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return sendQuestDialog(env, 7);
          } else {
            return sendQuestDialog(env, 1009);
          }
        } else if (env.getDialogId() == 10003) {
          if (player.getInventory().getItemCountByItemId(186000018) >= 600) {
            qs.setQuestVarById(0, qs.getQuestVarById(0) + 4);
            player.getInventory().removeFromBagByItemId(186000018, 600);
            qs.setStatus(QuestStatus.REWARD);
            updateQuestStatus(env);
            return sendQuestDialog(env, 8);
          } else {
            return sendQuestDialog(env, 1009);
          }
        }
      } else if (qs.getStatus() == QuestStatus.COMPLETE) {
        if (env.getDialogId() == 2) {
          if ((qs.getCompleteCount() <= template.getMaxRepeatCount())) {
            env.setQuestId(questId);
            QuestService.startQuest(env, QuestStatus.START);
            return true;
          } else return sendQuestDialog(env, 1008);
        }
      } else if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
        return defaultQuestEndDialog(env);
      }
    }
    return false;
  }
Exemple #8
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;
    }
  }
Exemple #9
0
 /**
  * @param id
  * @param playerLevel
  * @return false if player is 2 or more levels below quest level
  */
 public static boolean checkLevelRequirement(int questId, int playerLevel) {
   QuestTemplate template = questsData.getQuestById(questId);
   return (playerLevel >= template.getMinlevelPermitted()
       && (template.getMaxlevelPermitted() == 0
           || playerLevel <= template.getMaxlevelPermitted()));
 }
Exemple #10
0
  public static boolean collectItemCheck(QuestCookie env, boolean removeItem) {
    Player player = env.getPlayer();
    int id = env.getQuestId();
    QuestState qs = player.getQuestStateList().getQuestState(id);
    if (qs == null) return false;

    QuestTemplate template = questsData.getQuestById(env.getQuestId());
    CollectItems collectItems = template.getCollectItems();
    if (collectItems == null) return true;

    for (CollectItem collectItem : collectItems.getCollectItem()) {
      int itemId = collectItem.getItemId();
      long count =
          itemId == ItemId.KINAH.value()
              ? player.getInventory().getKinahCount()
              : player.getInventory().getItemCountByItemId(itemId);
      if (collectItem.getCount() > count) return false;
    }
    if (removeItem) {
      BonusTemplate bonusTemplate = bonusData.getBonusInfoByQuestId(id);
      List<SimpleCheckItemBonus> appliedBonuses = null;
      if (bonusTemplate != null) {
        List<AbstractInventoryBonus> bi = bonusTemplate.getItemBonuses();
        int checks = 0;
        for (int i = 0; i < bi.size(); i++) {
          AbstractInventoryBonus bonus = bi.get(i);
          if (!(bonus instanceof SimpleCheckItemBonus)) continue;
          checks++;
          SimpleCheckItemBonus scb = (SimpleCheckItemBonus) bonus;
          HandlerResult result = QuestEngine.getInstance().onBonusApply(env, i, bonus);
          if (result == HandlerResult.UNKNOWN) {
            if (scb.canApply(player, env.getQuestId())) {
              if (appliedBonuses == null) appliedBonuses = new ArrayList<SimpleCheckItemBonus>();
              appliedBonuses.add(scb);
            }
          } else if (result == HandlerResult.SUCCESS) {
            if (appliedBonuses == null) appliedBonuses = new ArrayList<SimpleCheckItemBonus>();
            appliedBonuses.add(scb);
          }
        }
        // If check constraints added (like in redeems), returns no bonus
        if (checks > 0 && appliedBonuses == null) return false;
      }

      for (CollectItem collectItem : collectItems.getCollectItem()) {
        if (collectItem.getItemId() == 182400001)
          player.getInventory().decreaseKinah(collectItem.getCount());
        else {
          boolean removeResult =
              player
                  .getInventory()
                  .removeFromBagByItemId(collectItem.getItemId(), collectItem.getCount());
          if (!removeResult) return false;
        }
      }

      if (appliedBonuses != null) {
        for (AbstractInventoryBonus bonus : appliedBonuses) {
          // TODO: we can not check if the inventory is full
          // when called from the script
          bonus.apply(player, null);
        }
      }
    }
    return true;
  }