Example #1
0
  public boolean hasRequisites(Quest quest) {

    // test if has the necessary level
    if (quest.getLevelDependencie() != -1) {
      if (!RPGSystem.getRPGSystem().getPlayerGroup().hasLevelNeeded(quest.getLevelDependencie())) {
        return false;
      }
    }

    // test if has the necessary quest needed
    if (quest.getQuestDependencies() != null) {
      for (int i = 0; i < quest.getQuestDependencies().length; i++) {
        // test if all quests are completed
        if (quests.get(quest.getQuestDependencies()[i]) != null
            && quests.get(quest.getQuestDependencies()[i]).getState() != 'F') {
          return false;
        }
      }
    }

    // test if has the necessary item needed
    if (quest.getItemDependencies() != null) {
      // temporary objects
      int i = 0;
      int sum = 0;

      while (i < quest.getItemDependencies().length) {
        System.out.println(quest.getItemDependencies()[i]);
        // if thereĀ“s the possibility of finding in the characters belongings
        if (FactoryManager.getFactoryManager().getRulesManager().getRulesSet().isCharacterBag()) {
          // there are characters bags

          // must search in all of the characters bags and sum up the amount
          for (int p = 0;
              p < RPGSystem.getRPGSystem().getPlayerGroup().getCharacter().length;
              p++) {

            // must test all the characters
            if (RPGSystem.getRPGSystem()
                    .getPlayerGroup()
                    .getCharacter(p)
                    .getBag()
                    .getItemEntry(quest.getItemDependencies()[i])
                != null) {

              // has the item, then put together to make the test
              sum =
                  sum
                      + RPGSystem.getRPGSystem()
                          .getPlayerGroup()
                          .getCharacter(p)
                          .getBag()
                          .getItemEntry(quest.getItemDependencies()[i])
                          .getQtd();
            }
          }
        }

        // if exists a bag for the group
        if (FactoryManager.getFactoryManager().getRulesManager().getRulesSet().isGroupBag()) {
          // there is a bag for the group

          // test the quantity
          if (RPGSystem.getRPGSystem()
                  .getPlayerGroup()
                  .getBag()
                  .getItemEntry(quest.getItemDependencies()[i])
              != null) {
            System.out.println("Found the item");
            // put together the item
            sum =
                sum
                    + RPGSystem.getRPGSystem()
                        .getPlayerGroup()
                        .getBag()
                        .getItemEntry(quest.getItemDependencies()[i])
                        .getQtd();
          }
        }

        // test the quantity
        if (sum < quest.getItemDependenciesQuantity()[i]) {
          return false;
        } else {
          i++;
        }
      }
    }

    // all the requisites are OK
    return true;
  }