Exemplo n.º 1
0
  /**
   * Method used to give the player group the reward for the quest that was completed
   *
   * @param quest an object of the class Quest
   */
  public void receiveReward(Quest quest) {

    // test if the reward has money
    if (quest.getMoneyRewarded() != -1) {
      RPGSystem.getRPGSystem().getPlayerGroup().setMoneyValue(quest.getMoneyRewarded());
    }

    // test if has one or more itens to receive
    if (quest.getRewardItem() != null) {
      // will pass throught all itens and say to give them to the player
      for (int i = 0; i < quest.getRewardedItem().length; i++) {
        // say to put the item in the player inventory
        RPGSystem.getRPGSystem()
            .getPlayerGroup()
            .addItem(quest.getRewardItem()[i], quest.getRewardedItem()[i]);
      }
    }

    // test if has one or more features to increase
    if (quest.getFeatureName() != null) {
      // will pass throught all the features and increase all the groups features
      for (int i = 0; i < quest.getFeatureName().length; i++) {
        // needs to increase for the entire group
        RPGSystem.getRPGSystem()
            .getPlayerGroup()
            .increaseGroupFeature(
                quest.getFeatureName()[i], quest.getFeatureType()[i], quest.getFeatureValue()[i]);
      }
    }
  }
Exemplo n.º 2
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;
  }
Exemplo 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');
    }
  }
Exemplo n.º 4
0
  /**
   * Method used to remove what was asked at a quest
   *
   * @param quest an object of the class Quest
   */
  public void removeQuestNeeds(Quest quest) {

    // remove the money from the group, if has money to remove
    if (quest.getMoneyNeeded() != -1) {
      // remove it
      RPGSystem.getRPGSystem().getPlayerGroup().setMoneyValue(-quest.getMoneyNeeded());
    }

    // if has itens to remove
    if (quest.getGetItem() != null) {

      // the quantity to remove
      int sum;

      // must remove all the itens needed
      for (int i = 0; i < quest.getGetItem().length; i++) {

        // receive the quantity that needs to remove
        sum = quest.getNumberItemGot()[i];

        // remove the itens, first try to remove from the bag and then from the characters
        // 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) {

            // remove the quantity
            if (RPGSystem.getRPGSystem()
                    .getPlayerGroup()
                    .getBag()
                    .getItemEntry(quest.getGetItem()[i])
                    .getQtd()
                >= sum) {
              // remove the quantity needed
              RPGSystem.getRPGSystem()
                  .getPlayerGroup()
                  .getBag()
                  .removeItem(quest.getGetItem()[i], sum);
              // removed all the quantity needed
              sum = 0;
            } else {
              // remove from the sum the quantity
              sum =
                  sum
                      - RPGSystem.getRPGSystem()
                          .getPlayerGroup()
                          .getBag()
                          .getItemEntry(quest.getGetItem()[i])
                          .getQtd();
              // remove the quantity that has
              RPGSystem.getRPGSystem()
                  .getPlayerGroup()
                  .getBag()
                  .removeItem(
                      quest.getGetItem()[i],
                      RPGSystem.getRPGSystem()
                          .getPlayerGroup()
                          .getBag()
                          .getItemEntry(quest.getGetItem()[i])
                          .getQtd());
            }
          }
        }

        // if there´s the possibility of finding in the characters belongings
        if (FactoryManager.getFactoryManager().getRulesManager().getRulesSet().isCharacterBag()
            && sum > 0) {
          // 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) {

              // remove the quantity according to how much can remove
              if (RPGSystem.getRPGSystem()
                      .getPlayerGroup()
                      .getCharacter(p)
                      .getBag()
                      .getItemEntry(quest.getGetItem()[i])
                      .getQtd()
                  >= sum) {
                // remove the quantity needed
                RPGSystem.getRPGSystem()
                    .getPlayerGroup()
                    .getCharacter(p)
                    .getBag()
                    .removeItem(quest.getGetItem()[i], sum);
                // removed all the quantity needed
                sum = 0;
              } else {
                // remove from the sum the quantity
                sum =
                    sum
                        - RPGSystem.getRPGSystem()
                            .getPlayerGroup()
                            .getCharacter(p)
                            .getBag()
                            .getItemEntry(quest.getGetItem()[i])
                            .getQtd();
                // remove the quantity that has
                RPGSystem.getRPGSystem()
                    .getPlayerGroup()
                    .getCharacter(p)
                    .getBag()
                    .removeItem(
                        quest.getGetItem()[i],
                        RPGSystem.getRPGSystem()
                            .getPlayerGroup()
                            .getCharacter(p)
                            .getBag()
                            .getItemEntry(quest.getGetItem()[i])
                            .getQtd());
              }
            }
          }
        }
      }
    }
  }