/** * 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); } }
/** * 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'); } }