Ejemplo n.º 1
0
  public boolean beginQuest(String name) {
    // temporary object
    Quest quest;

    // gets the quest
    quest = quests.get(name);

    // test if exists and is inactive
    if (quest != null && quest.getState() == 'I') {
      // test the dependencies, if can apply then begin the quest
      if (hasRequisites(quest)) {
        // begin the quest
        quest.setState('A');
        // the quest is active
        return true;
      }
    }

    // not able to begin the quest
    return false;
  }
Ejemplo n.º 2
0
  /**
   * Method used to test if the quest was completed, by receiving the identifier of the quest
   *
   * @param name the identifier of the quest
   * @return true or false according to if the quest was completed or not
   */
  public boolean completeQuest(String name) {
    // temporary object
    Quest quest;

    // get the quest in question
    quest = quests.get(name);
    // test the quest, if exist and if its complete
    if (quest != null && quest.getState() == 'C') {
      // validate the quest by removing what needs to be removed
      removeQuestNeeds(quest);
      // receive the reward
      receiveReward(quest);
      // set the quest as finished
      quest.setState('F');
      // the quest was completed
      return true;
    } else {
      // the quest wasn´t completed
      return false;
    }

    // the quest wasn´t completed
    // return false;
  }
Ejemplo n.º 3
0
  /**
   * Method used to check if a quest was completed
   *
   * @param quest the quest in question
   */
  public void checkQuest(Quest quest) {

    // to test if the quest was completed
    boolean complete = true;

    // test if the quest exists and is active
    if (quest != null && quest.getState() == 'A') {

      // if has monster to kill
      if (quest.getMonsterKill() != null) {
        // if the quantity is equal to zero then don´t need to kill anymore

        // temporary
        int i = 0;

        // loop to know if every monster needed to kill was killed
        while (complete == true && i < quest.getMonsterKilled().length) {
          // test the quantity
          if (quest.getMonsterKilled()[i] == 0) {
            // was killed goes to next
            i++;
          } else {
            // there´s some left
            complete = false;
          }
        }
      }

      // if an item has been found
      if (quest.getGetItem() != null) {
        // test if the quantity that the player has in the bag is the quantity needed

        // must find where to search, characters and/or group

        // one search for the characters belongings and another for the group

        // temporary
        int i = 0;

        // used to put together the quantity between characters and the bag
        int sum = 0;

        // loop to test the quantity of all itens needed
        while (complete == true && i < quest.getGetItem().length) {
          // search the player or the group bag, if player must search all bags
          // System.out.println(quest.getGetItem()[i]);
          // test the quantity
          sum = 0;

          // 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.getGetItem()[i])
                  != null) {

                // has the item, then put together to make the test
                sum =
                    sum
                        + RPGSystem.getRPGSystem()
                            .getPlayerGroup()
                            .getCharacter(p)
                            .getBag()
                            .getItemEntry(quest.getGetItem()[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.getGetItem()[i])
                != null) {

              // put together the item
              sum =
                  sum
                      + RPGSystem.getRPGSystem()
                          .getPlayerGroup()
                          .getBag()
                          .getItemEntry(quest.getGetItem()[i])
                          .getQtd();
            }
          }

          // test the quantity
          if (sum <= quest.getNumberItemGot()[i]) {
            complete = false;

          } else {
            i++;
          }
        }
      }

      // if has money to get
      if (quest.getMoneyNeeded() != -1) {
        // the money is with the player group

        // test the quantity needed
        if (RPGSystem.getRPGSystem().getPlayerGroup().getMoneyValue() < quest.getMoneyNeeded()) {
          complete = false;
        }
      }

      // if talked with everyone needed to
      if (quest.getNPCTalk() != null) {

        // test if all the NPC needed to talk were found

        // temporary
        int i = 0;

        // loop to test if they were all found
        while (complete == true && i < quest.getNPCTalk().length) {
          // test
          if (quest.getNPCTalked()[i]) {
            // was talked
            i++;
          } else {
            // one is missing
            complete = false;
          }
        }
      }
    } else {
      complete = false;
    }

    // teste if the quest has been completed
    if (quest != null && complete) {
      // was completed
      quest.setState('C');
    }
  }