Example #1
0
  public void createDependencies(Element dep, Quest quest) {
    if (dep != null) {

      // if there are quests
      if (dep.getChild("Quest") != null) {
        // get the quest dependencies
        quest.setQuestDependencies(loadOneDependencie(dep.getChild("Quest")));
      }

      // if there are itens needed
      if (dep.getChild("Itens") != null) {
        // get the Itens
        Object[] objects;
        objects = loadTwoDependencies(dep.getChild("Itens"));
        // set their places
        quest.setItemDependencies((String[]) objects[0]);
        quest.setItemDependenciesQuantity((int[]) objects[1]);
      }

      // if exists the need for levels
      if (dep.getChild("Level") != null) {
        // get the Level
        quest.setLevelDependencie(Integer.parseInt(dep.getChildText("Level")));
      }
    }
  }
Example #2
0
  /**
   * Method used to create one quest by receiving its information from the XML
   *
   * @param child an object of the class Element
   */
  public void createQuest(Element child) {

    // put the new quest in the hash, need to test if already has a quest
    // with this identifier, if already exists then don´t create the last

    // create the quest
    Quest quest = quests.get(child.getName());

    // test if exists, if doesn´t exists then create it
    if (quest == null) {
      // pass the element of the quest for it to be created

      // get the data for the quest
      quest = new Quest();

      // get the information
      createInformation(child.getChild("Information"), quest);

      // get the dependencies
      createDependencies(child.getChild("Dependencies"), quest);

      // get the objective
      createObjective(child.getChild("Objective"), quest);

      // get the rewards
      createReward(child.getChild("Reward"), quest);

      // put the quest in the hash
      quests.put(quest.getName(), quest);
    }
  }
Example #3
0
 /** Используется для однодневных квестов */
 public void exitCurrentQuest(Quest quest) {
   Player player = getPlayer();
   exitCurrentQuest(true);
   quest.newQuestState(player, Quest.DELAYED);
   QuestState qs = player.getQuestState(quest.getClass());
   qs.setRestartTime();
 }
Example #4
0
 public void createInformation(Element inf, Quest quest) {
   if (inf != null) {
     quest.setName(inf.getChildText("Name"));
     quest.setDescription(inf.getChildText("Description"));
     quest.setObjective(inf.getChildText("Objective"));
   }
 }
Example #5
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++;
        }
      }
    }
  }
 public void CompleteQuest(int Index) {
   Quest qstComp = QUEST_LIST.elementAt(Index);
   qstComp.STATUS = 3;
   qstComp.QUEST_GIVER.QUEST_LIST.elementAt(0).STATUS = 3;
   qstComp.QUEST_GIVER.QUEST_LIST.removeElementAt(0);
   STATS.IncreaseXP(qstComp.XP);
   GOLD += qstComp.GOLD;
 }
Example #7
0
 public void addTaskData(Quest quest) {
   try {
     if (HardcoreQuesting.getPlayer() != null) {
       addTaskData.invoke(quest, quest.getQuestData(HardcoreQuesting.getPlayer()));
     } else {
       addTaskData.invoke(quest, quest.getQuestData("lorddusk"));
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #8
0
 @Override
 public QuestSet read(JsonReader in) throws IOException {
   String name = null, description = null;
   requirementMapping.clear();
   optionMapping.clear();
   List<Quest> quests = new ArrayList<Quest>();
   in.beginObject();
   while (in.hasNext()) {
     String next = in.nextName();
     if (next.equalsIgnoreCase(NAME)) {
       name = in.nextString();
     } else if (next.equalsIgnoreCase(DESCRIPTION)) {
       description = in.nextString();
     } else if (next.equalsIgnoreCase(QUESTS)) {
       in.beginArray();
       QUEST_ID = Quest.size();
       while (in.hasNext()) {
         Quest quest = QUEST_ADAPTER.read(in);
         if (quest != null) {
           quests.add(quest);
         }
       }
       in.endArray();
     }
   }
   in.endObject();
   for (QuestSet set : Quest.getQuestSets()) {
     if (set.getName().equals(name)) {
       return removeQuests(quests);
     }
   }
   if (name != null && description != null) {
     QuestSet set = new QuestSet(name, description);
     Quest.getQuestSets().add(set);
     SaveHelper.add(SaveHelper.EditType.SET_CREATE);
     for (Quest quest : quests) {
       quest.setQuestSet(set);
     }
     for (Map.Entry<Quest, List<Integer>> entry : requirementMapping.entrySet()) {
       for (int i : entry.getValue()) entry.getKey().addRequirement(i);
     }
     for (Map.Entry<Quest, List<Integer>> entry : optionMapping.entrySet()) {
       for (int i : entry.getValue()) entry.getKey().addOptionLink(i);
     }
     return set;
   }
   return removeQuests(quests);
 }
Example #9
0
 /**
  * Test if the quest can be checked or not
  *
  * @param quest an object of the class Quest
  */
 public void testQuest(Quest quest) {
   // test if the quest is active or not
   if (quest != null && quest.getState() == 'A') {
     // check the quest
     checkQuest(quest);
   }
 }
Example #10
0
 public QuestTask addTask(Quest quest) {
   QuestTask prev =
       quest.getTasks().size() > 0 ? quest.getTasks().get(quest.getTasks().size() - 1) : null;
   try {
     Constructor ex = clazz.getConstructor(Quest.class, String.class, String.class);
     QuestTask task = (QuestTask) ex.newInstance(quest, name, description);
     if (prev != null) {
       task.addRequirement(prev);
     }
     quest.getTasks().add(task);
     SaveHelper.add(SaveHelper.EditType.TASK_CREATE);
     return task;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #11
0
  public void createReward(Element rew, Quest quest) {
    if (rew != null) {

      // if there´s money to be rewarded
      if (rew.getChild("Money") != null) {
        quest.setMoneyRewarded(Integer.parseInt(rew.getChildText("Money")));
      } else {
        // if there´s no money reward
        quest.setMoneyRewarded(-1);
      }

      // if there´s one or more itens to be rewarded
      if (rew.getChild("Itens") != null) {
        // get the Itens
        Object[] objects;
        objects = loadTwoDependencies(rew.getChild("Itens"));
        // set their places
        quest.setRewardItem((String[]) objects[0]);
        quest.setRewardedItem((int[]) objects[1]);
      }

      // if there´s something of the character that increases
      if (rew.getChild("Features") != null) {
        // get the Itens
        Object[] objects;
        objects = loadThreeDependencies(rew.getChild("Features"));
        // set their places
        quest.setFeatureName((String[]) objects[0]);
        quest.setFeatureType((String[]) objects[1]);
        quest.setFeatureValue((int[]) objects[2]);
      }
    }
  }
Example #12
0
  /**
   * Method used to count a monster that was killed
   *
   * @param monster the name of the monster
   */
  public void monsterKilled(String monster) {
    // temporary object
    Quest temp;

    // must test in all the active quests if the monster killed has to be counted
    for (int i = 0; i < quests.size(); i++) {
      // get the quest
      temp = quests.get(i);

      // test if is active and has monster to kill
      if (temp.getState() == 'A' && temp.getMonsterKill() != null) {
        // test if has the monster to decrease the needed amount
        for (int l = 0; l < temp.getMonsterKill().length; i++) {
          // test if has the monster
          if (temp.getMonsterKill()[i].equals(monster)) {
            // decrease only if can
            if (temp.getMonsterKilled()[i] > 0) {
              temp.getMonsterKilled()[i]--;
            }
          }
        }
      }

      // test if the quest was completed
      checkQuest(temp);
    }
  }
Example #13
0
  /**
   * Destroy element used by quest when quest is exited
   *
   * @param repeatable
   * @return QuestState
   */
  public QuestState exitCurrentQuest(boolean repeatable) {
    Player player = getPlayer();
    if (player == null) {
      return this;
    }

    removePlayerOnKillListener();
    // Clean drops
    for (int itemId : _quest.getItems()) {
      // Get [item from] / [presence of the item in] the inventory of the player
      ItemInstance item = player.getInventory().getItemByItemId(itemId);
      if ((item == null) || (itemId == 57)) {
        continue;
      }
      long count = item.getCount();
      // If player has the item in inventory, destroy it (if not gold)
      player.getInventory().destroyItemByItemId(itemId, count);
      player.getWarehouse().destroyItemByItemId(itemId, count); // TODO [G1ta0] analyze this
    }

    // If quest is repeatable, delete quest from list of quest of the player and from database
    // (quest CAN be created again => repeatable)
    if (repeatable) {
      player.removeQuestState(_quest.getName());
      Quest.deleteQuestInDb(this);
      _vars.clear();
    } else { // Otherwise, delete variables for quest and update database (quest CANNOT be created
             // again => not repeatable)
      for (String var : _vars.keySet()) {
        if (var != null) {
          unset(var);
        }
      }
      setState(Quest.COMPLETED);
      Quest.updateQuestInDb(this); // FIXME: оно вроде не нужно?
    }
    if (isCompleted()) {
      // WorldStatisticsManager.getInstance().updateStat(player, CategoryType.QUESTS_COMPLETED,0,
      // 1);
    }
    player.sendPacket(new QuestList(player));
    return this;
  }
Example #14
0
 /**
  * Remove the variable of quest from the list of variables for the quest.<br>
  * <br>
  * <U><I>Concept : </I></U> Remove the variable of quest represented by "var" from the class
  * variable FastMap "vars" and from the database.
  *
  * @param var : String designating the variable for the quest to be deleted
  * @return String pointing out the previous value associated with the variable "var"
  */
 public String unset(String var) {
   if (var == null) {
     return null;
   }
   String old = _vars.remove(var);
   if (old != null) {
     Quest.deleteQuestVarInDb(this, var);
   }
   return old;
 }
Example #15
0
  /**
   * Constructor<?> of the QuestState : save the quest in the list of quests of the player.<br>
   * <br>
   *
   * <p><U><I>Actions :</U></I><br>
   * <LI>Save informations in the object QuestState created (Quest, Player, Completion, State)
   * <LI>Add the QuestState in the player's list of quests by using setQuestState()
   * <LI>Add drops gotten by the quest <br>
   *
   * @param quest : quest associated with the QuestState
   * @param player : L2Player pointing out the player
   * @param state : state of the quest
   */
  public QuestState(Quest quest, Player player, int state) {
    _quest = quest;
    _player = player;

    // Save the state of the quest for the player in the player's list of quest onwed
    player.setQuestState(this);

    // set the state of the quest
    _state = state;
    quest.notifyCreate(this);
  }
Example #16
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;
  }
Example #17
0
  /**
   * <font color=red>Использовать осторожно! Служебная функция!</font><br>
   * <br>
   *
   * <p>Устанавливает переменную и сохраняет в базу, если установлен флаг. Если получен cond
   * обновляет список квестов игрока (только с флагом).
   *
   * @param var : String pointing out the name of the variable for quest
   * @param val : String pointing out the value of the variable for quest
   * @param store : Сохраняет в базу и если var это cond обновляет список квестов игрока.
   * @return String (equal to parameter "val")
   */
  public String set(String var, String val, boolean store) {
    if (val == null) {
      val = StringUtils.EMPTY;
    }

    _vars.put(var, val);

    if (store) {
      Quest.updateQuestVarInDb(this, var, val);
    }

    return val;
  }
Example #18
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;
  }
Example #19
0
  /**
   * Return state of the quest after its initialization.<br>
   * <br>
   * <U><I>Actions :</I></U>
   * <LI>Remove drops from previous state
   * <LI>Set new state of the quest
   * <LI>Add drop for new state
   * <LI>Update information in database
   * <LI>Send packet QuestList to client
   *
   * @param state
   * @return object
   */
  public Object setState(int state) {
    Player player = getPlayer();
    if (player == null) {
      return null;
    }

    _state = state;

    if (getQuest().isVisible(player) && isStarted()) {
      player.sendPacket(new ExShowQuestMark(getQuest().getQuestIntId()));
    }

    Quest.updateQuestInDb(this);
    player.sendPacket(new QuestList(player));
    return state;
  }
Example #20
0
  public String dungeonStatus() {
    String s = "Player Status";

    s += "\n\nName: " + getName();
    s += "\nLevel: " + getLevel();
    s += "\nHealth: " + getCurrentHealth() + "/" + getMaxHealth();
    s += "\nExp: " + getExp();
    s += "\nGold: " + getGold();

    s += "\n\nPhysical Damage: " + getPhysicalDamage();
    s += "\nPhysical Defence :" + getPhysicalDefence();
    s += "\nMagical Damage: " + getMagicalDamage();
    s += "\nMagical Defence " + getMagicalDamage();

    s += "\n\nCurrent Quest " + Quest.info(getQuest());

    return s;
  }
Example #21
0
  public void createObjective(Element obj, Quest quest) {
    if (obj != null) {

      // if needs to get money
      if (obj.getChild("Money") != null) {
        quest.setMoneyNeeded(Integer.parseInt(obj.getChildText("Money")));
      }

      // if needs itens
      if (obj.getChild("Itens") != null) {
        // get the Itens
        Object[] objects;
        objects = loadTwoDependencies(obj.getChild("Itens"));
        // set their places
        quest.setGetItem((String[]) objects[0]);
        quest.setNumberItemGot((int[]) objects[1]);
      }

      // if needs monsters kills
      if (obj.getChild("Monsters") != null) {
        // get the Itens
        Object[] objects;
        objects = loadTwoDependencies(obj.getChild("Monsters"));
        // set their places
        quest.setMonsterKill((String[]) objects[0]);
        quest.setMonsterKilled((int[]) objects[1]);
      }

      // if needs talk to
      if (obj.getChild("Talk") != null) {
        // get the order
        quest.setOrder(Boolean.parseBoolean(obj.getChildText("Order")));
        // get the NPCs
        quest.setNPCTalk(loadOneDependencie(obj.getChild("Talk").getChild("NPC")));
        // create the controller for this
        quest.createNPCTalkControl();
      }
    }
  }
Example #22
0
  /** Runs the event and stops itself from running again */
  public void run() {
    super.matchRunning = false;

    final Thread t =
        new Thread(
            new Runnable() {
              public void run() {
                try {
                  quest.handleAction(action, args, owner);
                } catch (java.util.ConcurrentModificationException cme) {
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            },
            new String("qt-" + getIdentifier()));

    quest.setThread(t);
    t.start();
  }
Example #23
0
  public String setCond(int newCond, boolean store) {
    if (newCond == getCond()) {
      return String.valueOf(newCond);
    }

    int oldCond = getInt(VAR_COND);
    _cond = newCond;

    if ((oldCond & 0x80000000) != 0) {
      // уже используется второй формат
      if (newCond > 2) // Если этап меньше 3 то возвращаемся к первому варианту.
      {
        oldCond &= 0x80000001 | ((1 << newCond) - 1);
        newCond = oldCond | (1 << (newCond - 1));
      }
    } else {
      // Второй вариант теперь используется всегда если этап больше 2
      if (newCond > 2) {
        newCond = 0x80000001 | (1 << (newCond - 1)) | ((1 << oldCond) - 1);
      }
    }

    final String sVal = String.valueOf(newCond);
    final String result = set(VAR_COND, sVal, false);
    if (store) {
      Quest.updateQuestVarInDb(this, VAR_COND, sVal);
    }

    final Player player = getPlayer();
    if (player != null) {
      player.sendPacket(new QuestList(player));
      if ((newCond != 0) && getQuest().isVisible(player) && isStarted()) {
        player.sendPacket(new ExShowQuestMark(getQuest().getQuestIntId()));
      }
    }
    return result;
  }
Example #24
0
  /** @return this event's identifer */
  public Object getIdentifier() {
    if (quest == null || action == null) return null;

    return new String(quest.getUniqueID() + "-" + action.getID() + "-" + owner.getUsernameHash());
  }
Example #25
0
 private QuestSet removeQuests(List<Quest> quests) {
   for (Quest quest : quests) {
     QuestLine.getActiveQuestLine().quests.remove(quest.getId());
   }
   return null;
 }
Example #26
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;
  }
 public void embarkOnQuest() {
   quest.embark();
 }
Example #28
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]);
      }
    }
  }
Example #29
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());
              }
            }
          }
        }
      }
    }
  }
Example #30
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');
    }
  }