Adds an option for hiding quests not currently available

This commit is contained in:
Kristian Knarvik 2022-11-04 00:42:37 +01:00
parent cd35bdc334
commit 5d619cea40
3 changed files with 71 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package net.knarcraft.dynmapcitizens.handler.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.Planner;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPCRegistry; import net.citizensnpcs.api.npc.NPCRegistry;
import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.DynmapCitizens;
@ -23,6 +24,7 @@ import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerIcon; import org.dynmap.markers.MarkerIcon;
import org.dynmap.markers.MarkerSet; import org.dynmap.markers.MarkerSet;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -41,6 +43,7 @@ public class QuestsHandler extends AbstractTraitHandler {
private Map<Icon, MarkerIcon> markerIcons; private Map<Icon, MarkerIcon> markerIcons;
private Map<UUID, NPCQuestInfo> questGiverInfo; private Map<UUID, NPCQuestInfo> questGiverInfo;
private final QuestsSettings settings = new QuestsSettings(); private final QuestsSettings settings = new QuestsSettings();
private List<IQuest> unavailableQuests;
@Override @Override
public void initialize() { public void initialize() {
@ -108,8 +111,16 @@ public class QuestsHandler extends AbstractTraitHandler {
private void generateQuestNPCInfo() { private void generateQuestNPCInfo() {
//Clear any previous information //Clear any previous information
questGiverInfo = new HashMap<>(); questGiverInfo = new HashMap<>();
unavailableQuests = new ArrayList<>();
//Generation information about NPC's parts in each quest //Generation information about NPC's parts in each quest
for (IQuest quest : questsAPI.getLoadedQuests()) { for (IQuest quest : questsAPI.getLoadedQuests()) {
if (isQuestUnavailable(quest)) {
unavailableQuests.add(quest);
//If unavailable quests aren't displayed, there is no point in continuing
if (settings.hideUnavailableQuests()) {
continue;
}
}
if (quest.getNpcStart() != null) { if (quest.getNpcStart() != null) {
getInfo(quest.getNpcStart()).addQuestStart(quest); getInfo(quest.getNpcStart()).addQuestStart(quest);
} }
@ -127,6 +138,49 @@ public class QuestsHandler extends AbstractTraitHandler {
} }
} }
/**
* Checks whether the given quest is unavailable, according to its planner information
*
* @param quest <p>The quest to check for availability</p>
* @return <p>True if the quest is unavailable</p>
*/
private boolean isQuestUnavailable(IQuest quest) {
Planner planner = quest.getPlanner();
long currentTime = System.currentTimeMillis();
if (!planner.hasEnd() && !planner.hasStart()) {
return false;
}
if (!planner.hasStart()) {
//If past the end datetime, the quest is no longer available
return currentTime > planner.getEndInMillis();
}
if (!planner.hasEnd()) {
//If before the start datetime, the quest is not yet available
return currentTime < planner.getStartInMillis();
}
if (!planner.hasRepeat()) {
//If outside the start and end dates, the quest is unavailable
return currentTime < planner.getStartInMillis() || currentTime > planner.getEndInMillis();
}
long startTime = planner.getStartInMillis();
long endTime = planner.getEndInMillis();
do {
if (currentTime > startTime && currentTime < endTime) {
return false;
}
startTime += planner.getRepeat();
endTime += planner.getRepeat();
//If startTime > currentTime, current time cannot be within the interval
} while (startTime < currentTime);
return true;
}
/** /**
* Generates all quest markers based on the previously generated quest NPC info * Generates all quest markers based on the previously generated quest NPC info
*/ */
@ -245,6 +299,10 @@ public class QuestsHandler extends AbstractTraitHandler {
this.killAreaMarkerSet.getCircleMarkers().forEach(GenericMarker::deleteMarker); this.killAreaMarkerSet.getCircleMarkers().forEach(GenericMarker::deleteMarker);
this.reachAreaMarkerSet.getCircleMarkers().forEach(GenericMarker::deleteMarker); this.reachAreaMarkerSet.getCircleMarkers().forEach(GenericMarker::deleteMarker);
for (IQuest quest : questsAPI.getLoadedQuests()) { for (IQuest quest : questsAPI.getLoadedQuests()) {
//Skip marker if quest is unavailable, and unavailable quests are hidden
if (settings.hideUnavailableQuests() && this.unavailableQuests.contains(quest)) {
continue;
}
for (IStage stage : quest.getStages()) { for (IStage stage : quest.getStages()) {
markKillLocations(quest, stage); markKillLocations(quest, stage);
markReachLocations(quest, stage); markReachLocations(quest, stage);

View File

@ -11,6 +11,7 @@ public class QuestsSettings extends AbstractTraitSettings {
private boolean displayPlannerInfo; private boolean displayPlannerInfo;
private boolean displayStageInfo; private boolean displayStageInfo;
private boolean displayRequirementInfo; private boolean displayRequirementInfo;
private boolean displayUnavailableQuests;
private final AreaMarkerSettings killAreaSettings = new AreaMarkerSettings(); private final AreaMarkerSettings killAreaSettings = new AreaMarkerSettings();
private final AreaMarkerSettings reachAreaSettings = new AreaMarkerSettings(); private final AreaMarkerSettings reachAreaSettings = new AreaMarkerSettings();
@ -21,6 +22,7 @@ public class QuestsSettings extends AbstractTraitSettings {
this.displayPlannerInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayPlannerInfo", true); this.displayPlannerInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayPlannerInfo", true);
this.displayStageInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayStageInfo", true); this.displayStageInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayStageInfo", true);
this.displayRequirementInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayRequirementInfo", true); this.displayRequirementInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayRequirementInfo", true);
this.displayUnavailableQuests = configuration.getBoolean(getTraitConfigRoot() + ".displayUnavailableQuests", true);
this.killAreaSettings.load(configuration, getTraitConfigRoot() + ".circleMarker.killMarker"); this.killAreaSettings.load(configuration, getTraitConfigRoot() + ".circleMarker.killMarker");
this.reachAreaSettings.load(configuration, getTraitConfigRoot() + ".circleMarker.reachMarker"); this.reachAreaSettings.load(configuration, getTraitConfigRoot() + ".circleMarker.reachMarker");
} }
@ -66,6 +68,15 @@ public class QuestsSettings extends AbstractTraitSettings {
return this.displayRequirementInfo; return this.displayRequirementInfo;
} }
/**
* Gets whether to hide quests which are currently unavailable according to the planner dates
*
* @return <p>True if unavailable quests should be hidden</p>
*/
public boolean hideUnavailableQuests() {
return !this.displayUnavailableQuests;
}
/** /**
* Gets settings for the kill area markers * Gets settings for the kill area markers
* *

View File

@ -37,6 +37,8 @@ traits:
markerSetName: "Quests" markerSetName: "Quests"
# Whether to hide the quest icon layer by default # Whether to hide the quest icon layer by default
markersHiddenByDefault: false markersHiddenByDefault: false
# Whether to display information about a quest that's currently outside its availability period
displayUnavailableQuests: true
# Whether to add information about a quest's rewards to the marker description # Whether to add information about a quest's rewards to the marker description
displayRewardInfo: true displayRewardInfo: true
# Whether to add information about a quest's start date, stop date and cool-down to the marker description # Whether to add information about a quest's start date, stop date and cool-down to the marker description