Track progress through int, part 3. See #2250

This commit is contained in:
PikaMug 2024-07-13 17:26:50 -04:00
parent 0d79f5fbc1
commit 7e4f1ea561
3 changed files with 81 additions and 116 deletions

View File

@ -15,26 +15,48 @@ import java.util.LinkedList;
public interface QuestProgress {
LinkedList<Integer> getBlocksBroken();
void setBlocksBroken(final LinkedList<Integer> blocksBroken);
LinkedList<Integer> getBlocksDamaged();
void setBlocksDamaged(final LinkedList<Integer> blocksDamaged);
LinkedList<Integer> getBlocksPlaced();
void setBlocksPlaced(final LinkedList<Integer> blocksPlaced);
LinkedList<Integer> getBlocksUsed();
void setBlocksUsed(final LinkedList<Integer> blocksUsed);
LinkedList<Integer> getBlocksCut();
void setBlocksCut(final LinkedList<Integer> blocksCut);
LinkedList<Integer> getItemsCrafted();
void setItemsCrafted(final LinkedList<Integer> itemsCrafted);
LinkedList<Integer> getItemsSmelted();
void setItemsSmelted(final LinkedList<Integer> itemsSmelted);
LinkedList<Integer> getItemsEnchanted();
void setItemsEnchanted(final LinkedList<Integer> itemsEnchanted);
LinkedList<Integer> getItemsBrewed();
void setItemsBrewed(final LinkedList<Integer> itemsBrewed);
LinkedList<Integer> getItemsConsumed();
void setItemsConsumed(final LinkedList<Integer> itemsConsumed);
LinkedList<Integer> getItemsDelivered();
void setItemsDelivered(final LinkedList<Integer> itemsDelivered);
LinkedList<Boolean> getNpcsInteracted();
void setNpcsInteracted(final LinkedList<Boolean> npcsInteracted);

View File

@ -2868,78 +2868,61 @@ public class BukkitQuester implements Quester {
* @param location The location being reached
*/
public void reachLocation(final Quest quest, final Location location) {
// TODO - redo this method
final BukkitQuestProgress bukkitQuestData = (BukkitQuestProgress) getQuestDataOrDefault(quest);
if (bukkitQuestData == null || bukkitQuestData.locationsReached == null || getCurrentStage(quest) == null
|| getCurrentStage(quest).getLocationsToReach() == null) {
return;
}
int locationsReached = 0;
for (final Boolean b : bukkitQuestData.locationsReached) {
if (b) {
locationsReached++;
final LinkedList<Location> locationsToReach = ((BukkitStage) getCurrentStage(quest)).getLocationsToReach();
final int goal = locationsToReach.size();
for (int i = 0; i < goal; i++) {
final Location toReach = locationsToReach.get(i);
if (location.getWorld() == null || toReach.getWorld() == null
|| !location.getWorld().getName().equals(toReach.getWorld().getName())) {
continue;
}
}
final int locationsToReach = getCurrentStage(quest).getLocationsToReach().size();
int index = 0;
try {
for (final Location toReach : ((BukkitStage) getCurrentStage(quest)).getLocationsToReach()) {
if (location.getWorld() == null || toReach.getWorld() == null) {
index++;
continue;
}
if (!location.getWorld().getName().equals(toReach.getWorld().getName())) {
index++;
continue;
}
final double radius = getCurrentStage(quest).getRadiiToReachWithin().get(index);
if (toReach.distanceSquared(location) <= radius * radius) {
if (!bukkitQuestData.locationsReached.get(index)) {
final ObjectiveType type = ObjectiveType.REACH_LOCATION;
final Set<String> dispatchedQuestIDs = new HashSet<>();
final BukkitQuesterPreUpdateObjectiveEvent preEvent
= new BukkitQuesterPreUpdateObjectiveEvent(this, quest,
new BukkitObjective(type, null, locationsReached, locationsToReach));
plugin.getServer().getPluginManager().callEvent(preEvent);
bukkitQuestData.locationsReached.set(index, true);
finishObjective(quest, new BukkitObjective(type, null, new ItemStack(Material.AIR, 1),
new ItemStack(Material.AIR, 1)), null, null, null, toReach, null, null, null);
int finalIndex = index;
dispatchedQuestIDs.addAll(dispatchMultiplayerEverything(quest, type,
(final Quester q, final Quest cq) -> {
if (!dispatchedQuestIDs.contains(cq.getId())) {
((BukkitQuestProgress) q.getQuestDataOrDefault(quest)).locationsReached
.set(finalIndex, true);
if (q.testComplete(quest)) {
quest.nextStage(q, false);
}
}
return null;
}));
final BukkitQuesterPostUpdateObjectiveEvent postEvent
= new BukkitQuesterPostUpdateObjectiveEvent(this, quest,
new BukkitObjective(type, null, locationsReached + 1, locationsToReach));
plugin.getServer().getPluginManager().callEvent(postEvent);
break;
final double radius = getCurrentStage(quest).getRadiiToReachWithin().get(i);
if (toReach.distanceSquared(location) <= radius * radius) {
if (!bukkitQuestData.locationsReached.get(i)) {
int progress = 0;
for (final Boolean b : bukkitQuestData.locationsReached) {
if (b) {
progress++;
}
}
final ObjectiveType type = ObjectiveType.REACH_LOCATION;
final Set<String> dispatchedQuestIDs = new HashSet<>();
final BukkitQuesterPreUpdateObjectiveEvent preEvent
= new BukkitQuesterPreUpdateObjectiveEvent(this, quest,
new BukkitObjective(type, null, progress, goal));
plugin.getServer().getPluginManager().callEvent(preEvent);
bukkitQuestData.locationsReached.set(i, true);
finishObjective(quest, new BukkitObjective(type, null, new ItemStack(Material.AIR, 1),
new ItemStack(Material.AIR, 1)), null, null, null, toReach, null, null, null);
int finalIndex = i;
dispatchedQuestIDs.addAll(dispatchMultiplayerEverything(quest, type,
(final Quester q, final Quest cq) -> {
if (!dispatchedQuestIDs.contains(cq.getId())) {
((BukkitQuestProgress) q.getQuestDataOrDefault(quest)).locationsReached
.set(finalIndex, true);
if (q.testComplete(quest)) {
quest.nextStage(q, false);
}
}
return null;
}));
final BukkitQuesterPostUpdateObjectiveEvent postEvent
= new BukkitQuesterPostUpdateObjectiveEvent(this, quest,
new BukkitObjective(type, null, progress + 1, goal));
plugin.getServer().getPluginManager().callEvent(postEvent);
break;
}
index++;
}
} catch (final Exception e) {
plugin.getLogger().severe("An error has occurred with Quests. Please report on Github with info below");
plugin.getLogger().warning("quest = " + quest.getId());
plugin.getLogger().warning("index = " + index);
plugin.getLogger().warning("location = " + location.toString());
plugin.getLogger().warning("locationsToReach = " + getCurrentStage(quest).getLocationsToReach().size());
plugin.getLogger().warning("locationsReached = " + bukkitQuestData.locationsReached.size());
plugin.getLogger().warning("hasReached = " + bukkitQuestData.locationsReached.size());
e.printStackTrace();
}
}

View File

@ -174,69 +174,47 @@ public class BukkitQuesterYamlStorage implements QuesterStorageImpl {
final BukkitQuestProgress bukkitQuestData = (BukkitQuestProgress) quester.getQuestDataOrDefault(quest);
if (questSec.contains("blocks-broken-amounts")) {
final List<Integer> brokenAmounts = questSec.getIntegerList("blocks-broken-amounts");
for (int i = 0; i < brokenAmounts.size(); i++) {
bukkitQuestData.blocksBroken.set(i, brokenAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setBlocksBroken(new LinkedList<>(brokenAmounts));
}
if (questSec.contains("blocks-damaged-amounts")) {
final List<Integer> damagedAmounts = questSec.getIntegerList("blocks-damaged-amounts");
for (int i = 0; i < damagedAmounts.size(); i++) {
bukkitQuestData.blocksDamaged.set(i, damagedAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setBlocksDamaged(new LinkedList<>(damagedAmounts));
}
if (questSec.contains("blocks-placed-amounts")) {
final List<Integer> placedAmounts = questSec.getIntegerList("blocks-placed-amounts");
for (int i = 0; i < placedAmounts.size(); i++) {
bukkitQuestData.blocksPlaced.set(i, placedAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setBlocksPlaced(new LinkedList<>(placedAmounts));
}
if (questSec.contains("blocks-used-amounts")) {
final List<Integer> usedAmounts = questSec.getIntegerList("blocks-used-amounts");
for (int i = 0; i < usedAmounts.size(); i++) {
bukkitQuestData.blocksUsed.set(i, usedAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setBlocksUsed(new LinkedList<>(usedAmounts));
}
if (questSec.contains("blocks-cut-amounts")) {
final List<Integer> cutAmounts = questSec.getIntegerList("blocks-cut-amounts");
for (int i = 0; i < cutAmounts.size(); i++) {
bukkitQuestData.blocksCut.set(i, cutAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setBlocksCut(new LinkedList<>(cutAmounts));
}
if (questSec.contains("item-craft-amounts")) {
final List<Integer> craftAmounts = questSec.getIntegerList("item-craft-amounts");
for (int i = 0; i < craftAmounts.size(); i++) {
bukkitQuestData.itemsCrafted.set(i, craftAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setItemsCrafted(new LinkedList<>(craftAmounts));
}
if (questSec.contains("item-smelt-amounts")) {
final List<Integer> smeltAmounts = questSec.getIntegerList("item-smelt-amounts");
for (int i = 0; i < smeltAmounts.size(); i++) {
bukkitQuestData.itemsSmelted.set(i, smeltAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setItemsSmelted(new LinkedList<>(smeltAmounts));
}
if (questSec.contains("item-enchant-amounts")) {
final List<Integer> enchantAmounts = questSec.getIntegerList("item-enchant-amounts");
for (int i = 0; i < enchantAmounts.size(); i++) {
bukkitQuestData.itemsEnchanted.set(i, enchantAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setItemsEnchanted(new LinkedList<>(enchantAmounts));
}
if (questSec.contains("item-brew-amounts")) {
final List<Integer> brewAmounts = questSec.getIntegerList("item-brew-amounts");
for (int i = 0; i < brewAmounts.size(); i++) {
bukkitQuestData.itemsBrewed.set(i, brewAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setItemsBrewed(new LinkedList<>(brewAmounts));
}
if (questSec.contains("item-consume-amounts")) {
final List<Integer> consumeAmounts = questSec.getIntegerList("item-consume-amounts");
for (int i = 0; i < consumeAmounts.size(); i++) {
bukkitQuestData.itemsConsumed.set(i, consumeAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setItemsConsumed(new LinkedList<>(consumeAmounts));
}
if (questSec.contains("item-delivery-amounts")) {
final List<Integer> deliveryAmounts = questSec.getIntegerList("item-delivery-amounts");
for (int i = 0; i < deliveryAmounts.size(); i++) {
bukkitQuestData.itemsDelivered.set(i, deliveryAmounts.get(i));
}
quester.getQuestDataOrDefault(quest).setItemsDelivered(new LinkedList<>(deliveryAmounts));
}
if (questSec.contains("has-talked-to")) {
final List<Boolean> talkAmount = questSec.getBooleanList("has-talked-to");
@ -244,23 +222,11 @@ public class BukkitQuesterYamlStorage implements QuesterStorageImpl {
}
if (questSec.contains("npc-killed-amounts")) {
final List<Integer> npcAmounts = questSec.getIntegerList("npc-killed-amounts");
int index = 0;
for (final int amt : npcAmounts) {
if (!bukkitQuestData.getNpcsNumKilled().isEmpty()) {
bukkitQuestData.npcsNumKilled.set(index, amt);
}
index++;
}
quester.getQuestDataOrDefault(quest).setNpcsNumKilled(new LinkedList<>(npcAmounts));
} else if (questSec.contains("citizen-amounts-killed")) {
// Legacy
final List<Integer> npcAmounts = questSec.getIntegerList("citizen-amounts-killed");
int index = 0;
for (final int amt : npcAmounts) {
if (!bukkitQuestData.getNpcsNumKilled().isEmpty()) {
bukkitQuestData.npcsNumKilled.set(index, amt);
}
index++;
}
quester.getQuestDataOrDefault(quest).setNpcsNumKilled(new LinkedList<>(npcAmounts));
}
if (questSec.contains("cows-milked")) {
quester.getQuestDataOrDefault(quest).setCowsMilked(questSec.getInt("cows-milked"));
@ -273,13 +239,7 @@ public class BukkitQuesterYamlStorage implements QuesterStorageImpl {
}
if (questSec.contains("mobs-killed-amounts")) {
final List<Integer> mobAmounts = questSec.getIntegerList("mobs-killed-amounts");
int index = 0;
for (final int amt : mobAmounts) {
if (!quester.getQuestDataOrDefault(quest).getMobNumKilled().isEmpty()) {
bukkitQuestData.mobNumKilled.set(index, amt);
}
index++;
}
quester.getQuestDataOrDefault(quest).setMobNumKilled(new LinkedList<>(mobAmounts));
}
if (questSec.contains("has-reached-location")) {
final List<Boolean> hasReached = questSec.getBooleanList("has-reached-location");