Adds information about requirements to quest markers

This commit is contained in:
Kristian Knarvik 2022-11-01 14:44:32 +01:00
parent 183db017c0
commit eabcffe878

View File

@ -3,6 +3,7 @@ package net.knarcraft.dynmapcitizens.trait.quests;
import me.blackvein.quests.QuestsAPI; import me.blackvein.quests.QuestsAPI;
import me.blackvein.quests.quests.IQuest; import me.blackvein.quests.quests.IQuest;
import me.blackvein.quests.quests.IStage; import me.blackvein.quests.quests.IStage;
import me.blackvein.quests.quests.Requirements;
import me.blackvein.quests.quests.Rewards; import me.blackvein.quests.quests.Rewards;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -124,11 +125,10 @@ public class QuestsHandler extends AbstractTraitHandler {
for (IQuest quest : questStarts) { for (IQuest quest : questStarts) {
markerDescription.append("<li><h4><b>").append(quest.getName()).append("</b></h4><h5><b>- "); markerDescription.append("<li><h4><b>").append(quest.getName()).append("</b></h4><h5><b>- ");
markerDescription.append(quest.getDescription()).append("</b></h5>").append(getQuestStagesInfo(quest)); markerDescription.append(quest.getDescription()).append("</b></h5>").append(getQuestStagesInfo(quest));
markerDescription.append(getQuestRewardsInfo(quest)).append("</li>"); markerDescription.append(getQuestRewardsInfo(quest)).append(getQuestRequirementsInfo(quest)).append("</li>");
} }
markerDescription.append("</ul>"); markerDescription.append("</ul>");
} }
//TODO: Get information about requirements
//TODO: Get information about the planner (repeatable and/or limited) //TODO: Get information about the planner (repeatable and/or limited)
if (!questKills.isEmpty()) { if (!questKills.isEmpty()) {
@ -150,6 +150,71 @@ public class QuestsHandler extends AbstractTraitHandler {
} }
} }
/**
* Gets information about all requirements for the given quest
*
* @param quest <p>The quest to get requirements for</p>
* @return <p>Information about the quest's requirements</p>
*/
private String getQuestRequirementsInfo(IQuest quest) {
Requirements requirements = quest.getRequirements();
StringBuilder requirementInfo = new StringBuilder();
if (!requirements.hasRequirement()) {
return requirementInfo.toString();
}
requirementInfo.append("<br><b>Requirements: </b><ul>");
if (requirements.getQuestPoints() > 0) {
requirementInfo.append("<li>").append(requirements.getQuestPoints()).append(" quest points</li>");
}
if (requirements.getExp() > 0) {
requirementInfo.append("<li>").append(requirements.getExp()).append(" exp</li>");
}
for (IQuest blockQuest : requirements.getBlockQuests()) {
requirementInfo.append("<li>Blocked by quest: ").append(blockQuest.getName()).append("</li>");
}
for (IQuest neededQuest : requirements.getNeededQuests()) {
requirementInfo.append("<li>Requires quest: ").append(neededQuest.getName()).append("</li>");
}
for (ItemStack item : requirements.getItems()) {
requirementInfo.append("<li>Requires item: ").append(uppercaseFirst(getItemStackString(item))).append("</li>");
}
if (!requirements.getMcmmoSkills().isEmpty()) {
List<String> skills = requirements.getMcmmoSkills();
List<Integer> amounts = requirements.getMcmmoAmounts();
for (int i = 0; i < skills.size(); i++) {
requirementInfo.append("<li>Requires mcMMO skill ").append(skills.get(i)).append(" at level ");
requirementInfo.append(amounts.get(i)).append("</li>");
}
}
for (String permission : requirements.getPermissions()) {
requirementInfo.append("<li>Requires permission: ").append(permission).append("</li>");
}
Map<String, Map<String, Object>> customRequirementPlugins = requirements.getCustomRequirements();
for (String plugin : customRequirementPlugins.keySet()) {
requirementInfo.append("<li>").append(plugin).append(":<ul>");
//Note: The format of custom requirements is kind of weird. First, you have the key for which plugin the
// requirement belongs to. Getting the value of the key gives another map. The map contains as key, the type
// of value, like "Skill Amount" or "Skill Type". The value is the actual value of whatever it is.
Map<String, Object> customRequirementEntry = customRequirementPlugins.get(plugin);
for (String requirementDescription : customRequirementEntry.keySet()) {
requirementInfo.append("<li>").append(requirementDescription).append(" ").append(customRequirementEntry.get(requirementDescription)).append("</li>");
}
requirementInfo.append("</ul></li>");
}
requirementInfo.append("</ul>");
return requirementInfo.toString();
}
/** /**
* Gets information about all rewards for the given quest * Gets information about all rewards for the given quest
* *