Example #1
0
  /**
   * Method used to set one NPC as talked to, giving the name of the NPC and the quest identifier
   *
   * @param name the name of the NPC
   * @param questName the identifier of the quest
   */
  public void NPCTalkedTo(String name, String questName) {
    // temporary object
    Quest quest;

    // get the quest
    quest = quests.get(questName);

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

      // temporary object
      boolean found = false;
      int i = 0;

      // loop to search for the NPC wanted
      while (i < quest.getNPCTalk().length && found == false) {
        // make the test
        if (quest.getNPCTalk()[i].equals(name)) {
          // the NPC that was looking for
          quest.getNPCTalked()[i] = true;
        } else {
          // keep looking for
          i++;
        }
      }
    }
  }
Example #2
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');
    }
  }