Adds reward info to quest markers, and improves marker description

This commit is contained in:
Kristian Knarvik 2022-11-01 12:52:13 +01:00
parent b10dacab52
commit 183db017c0

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.Rewards;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry; import net.citizensnpcs.api.npc.NPCRegistry;
@ -116,17 +117,19 @@ public class QuestsHandler extends AbstractTraitHandler {
List<IQuest> questDeliveries = info.getQuestDeliveries(); List<IQuest> questDeliveries = info.getQuestDeliveries();
StringBuilder markerDescription = new StringBuilder(); StringBuilder markerDescription = new StringBuilder();
markerDescription.append("<b>Quest NPC Name:</b> ").append(registry.getByUniqueId(npcId).getName()); markerDescription.append("<h2>").append(registry.getByUniqueId(npcId).getName()).append("</h2>");
if (!questStarts.isEmpty()) { if (!questStarts.isEmpty()) {
markerDescription.append("<br><h3>Quests offered:</h3><ul>"); markerDescription.append("<br><h3>Quests offered:</h3><ul>");
for (IQuest quest : questStarts) { for (IQuest quest : questStarts) {
markerDescription.append("<li><b>Quest name:</b> ").append(quest.getName()).append( markerDescription.append("<li><h4><b>").append(quest.getName()).append("</b></h4><h5><b>- ");
"<br><b>Quest description:</b> ").append(quest.getDescription()).append( markerDescription.append(quest.getDescription()).append("</b></h5>").append(getQuestStagesInfo(quest));
getQuestStagesInfo(quest)).append("</li>"); markerDescription.append(getQuestRewardsInfo(quest)).append("</li>");
} }
markerDescription.append("</ul>"); markerDescription.append("</ul>");
} }
//TODO: Get information about requirements
//TODO: Get information about the planner (repeatable and/or limited)
if (!questKills.isEmpty()) { if (!questKills.isEmpty()) {
markerDescription.append("<h3>Kill target for quests:</h3>"); markerDescription.append("<h3>Kill target for quests:</h3>");
@ -147,6 +150,42 @@ public class QuestsHandler extends AbstractTraitHandler {
} }
} }
/**
* Gets information about all rewards for the given quest
*
* @param quest <p>The quest to get reward information for</p>
* @return <p>Information about the quest's rewards</p>
*/
private String getQuestRewardsInfo(IQuest quest) {
Rewards reward = quest.getRewards();
StringBuilder rewardInfo = new StringBuilder();
rewardInfo.append("<br><b>Rewards:</b><ul>");
if (reward.getMoney() > 0) {
//TODO: Get the currency from Vault
rewardInfo.append("<li>").append(reward.getMoney()).append(" money").append("</li>");
}
if (reward.getExp() > 0) {
rewardInfo.append("<li>").append(reward.getMoney()).append(" exp").append("</li>");
}
for (String permission : reward.getPermissions()) {
rewardInfo.append("<li>").append("Permission: ").append(permission).append("</li>");
}
for (ItemStack item : reward.getItems()) {
rewardInfo.append("<li>").append(uppercaseFirst(getItemStackString(item))).append("</li>");
}
for (String command : reward.getCommands()) {
rewardInfo.append("<li>Command: ").append(command).append("</li>");
}
rewardInfo.append("</ul>");
return rewardInfo.toString();
}
/** /**
* Gets a comma-separated list of the given quests' names * Gets a comma-separated list of the given quests' names
* *
@ -292,6 +331,16 @@ public class QuestsHandler extends AbstractTraitHandler {
return normalizeName(itemStack.getType().name()) + " X " + itemStack.getAmount(); return normalizeName(itemStack.getType().name()) + " X " + itemStack.getAmount();
} }
/**
* Makes the first character in a string uppercase
*
* @param string <p>The string to run on</p>
* @return <p>The same string, with the first character converted to uppercase</p>
*/
private String uppercaseFirst(String string) {
return string.substring(0, 1).toUpperCase() + string.substring(1);
}
/** /**
* Normalizes an internal name to make it human-readable * Normalizes an internal name to make it human-readable
* *