Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ItemRequirement rework #1847

Merged
merged 12 commits into from
Nov 23, 2024
29 changes: 13 additions & 16 deletions src/main/java/com/questhelper/QuestHelperPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.questhelper.bank.banktab.BankTabItems;
import com.questhelper.managers.NewVersionManager;
import com.questhelper.managers.QuestBankManager;
import com.questhelper.managers.QuestManager;
import com.questhelper.managers.QuestMenuHandler;
import com.questhelper.managers.QuestOverlayManager;
import com.questhelper.managers.*;
import com.questhelper.panel.QuestHelperPanel;
import com.questhelper.questhelpers.QuestHelper;
import com.questhelper.questinfo.QuestHelperQuest;
Expand All @@ -45,7 +41,6 @@
import com.questhelper.runeliteobjects.extendedruneliteobjects.RuneliteObjectManager;
import com.google.inject.Module;
import com.questhelper.util.worldmap.WorldMapAreaManager;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -182,14 +177,6 @@ public class QuestHelperPlugin extends Plugin

boolean profileChanged;


// TODO: Use this for item checks
@Getter
private int lastTickInventoryUpdated = -1;

@Getter
private int lastTickBankUpdated = -1;

private final Collection<String> configEvents = Arrays.asList("orderListBy", "filterListBy", "questDifficulty", "showCompletedQuests");
private final Collection<String> configItemEvents = Arrays.asList("highlightNeededQuestItems", "highlightNeededMiniquestItems", "highlightNeededAchievementDiaryItems");

Expand All @@ -203,6 +190,7 @@ QuestHelperConfig getConfig(ConfigManager configManager)
protected void startUp() throws IOException
{
questBankManager.startUp(injector, eventBus);
QuestContainerManager.getBankData().setMethodToObtainItems(() -> questBankManager.getBankItems().toArray(new Item[0]));
eventBus.register(worldMapAreaManager);

injector.injectMembers(playerStateManager);
Expand Down Expand Up @@ -267,15 +255,24 @@ public void onGameTick(GameTick event)
@Subscribe
public void onItemContainerChanged(ItemContainerChanged event)
{
Item[] items = event.getItemContainer().getItems();
if (event.getItemContainer() == client.getItemContainer(InventoryID.BANK))
{
lastTickBankUpdated = client.getTickCount();
ItemAndLastUpdated bankData = QuestContainerManager.getBankData();
bankData.update(client.getTickCount(), items);
questBankManager.updateLocalBank(event.getItemContainer());
}

if (event.getItemContainer() == client.getItemContainer(InventoryID.INVENTORY))
{
lastTickInventoryUpdated = client.getTickCount();
ItemAndLastUpdated inventoryData = QuestContainerManager.getInventoryData();
inventoryData.update(client.getTickCount(), items);
}

if (event.getItemContainer() == client.getItemContainer(InventoryID.EQUIPMENT))
{
ItemAndLastUpdated equippedData = QuestContainerManager.getEquippedData();
equippedData.update(client.getTickCount(), items);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.questhelper.bank.QuestBank;
import com.questhelper.QuestHelperPlugin;
import com.questhelper.managers.QuestContainerManager;
import com.questhelper.panel.PanelDetails;
import com.questhelper.requirements.item.ItemRequirement;
import com.questhelper.requirements.item.ItemRequirements;
Expand Down Expand Up @@ -88,7 +89,7 @@ public ArrayList<BankTabItems> getPluginBankTagItemsForSections(boolean onlyGetM
recommendedItems = recommendedItems.stream()
.filter(Objects::nonNull)
.filter(i -> (!onlyGetMissingItems
|| !i.check(plugin.getClient(), false, questBank.getBankItems()))
|| !i.checkWithBank(plugin.getClient()))
&& i.shouldDisplayText(plugin.getClient()))
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -116,7 +117,7 @@ public ArrayList<BankTabItems> getPluginBankTagItemsForSections(boolean onlyGetM
.filter(ItemRequirement.class::isInstance)
.map(ItemRequirement.class::cast)
.filter(i -> (!onlyGetMissingItems
|| !i.check(plugin.getClient(), false, questBank.getBankItems()))
|| !i.checkWithBank(plugin.getClient()))
&& i.shouldDisplayText(plugin.getClient()))
.collect(Collectors.toList());
}
Expand All @@ -128,7 +129,7 @@ public ArrayList<BankTabItems> getPluginBankTagItemsForSections(boolean onlyGetM
.filter(ItemRequirement.class::isInstance)
.map(ItemRequirement.class::cast)
.filter(i -> (!onlyGetMissingItems
|| !i.check(plugin.getClient(), false, questBank.getBankItems()))
|| !i.checkWithBank(plugin.getClient()))
&& i.shouldDisplayText(plugin.getClient()))
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -167,7 +168,7 @@ private void getItemsFromRequirement(List<BankTabItem> pluginItems, ItemRequirem
else
{
ItemRequirement match = itemsWhichPassReq.stream()
.filter(r -> r.checkBank(plugin.getClient()))
.filter(r -> r.checkWithBank(plugin.getClient()))
.findFirst()
.orElse(itemsWhichPassReq.get(0).named(itemRequirements.getName()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.questhelper.helpers.quests.ragandboneman;

import com.questhelper.collections.ItemCollections;
import com.questhelper.managers.QuestContainerManager;
import com.questhelper.tools.QuestTile;
import com.questhelper.requirements.zone.Zone;
import com.questhelper.panel.PanelDetails;
Expand Down Expand Up @@ -180,7 +181,7 @@ public void onGameTick(GameTick event)
potOfVinegarNeeded.setQuantity(winesNeededQuantity.get());

int jugsNeeded = winesNeededQuantity.get();
jugsNeeded -= potOfVinegar.alsoCheckBank(questBank).getMatches(client);
jugsNeeded -= potOfVinegar.checkTotalMatchesInContainers(client, QuestContainerManager.getEquippedData(), QuestContainerManager.getInventoryData(), QuestContainerManager.getBankData());
potNeeded.setQuantity(jugsNeeded);
jugOfVinegarNeeded.setQuantity(jugsNeeded);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.questhelper.collections.ItemCollections;
import com.questhelper.collections.KeyringCollection;
import com.questhelper.managers.QuestContainerManager;
import com.questhelper.questinfo.QuestHelperQuest;
import com.questhelper.tools.QuestTile;
import com.questhelper.questinfo.QuestVarPlayer;
Expand Down Expand Up @@ -301,7 +302,7 @@ public void onGameTick(GameTick event)
potOfVinegarNeeded.setQuantity(winesNeededQuantity.get());

int jugsNeeded = winesNeededQuantity.get();
jugsNeeded -= potOfVinegar.alsoCheckBank(questBank).getMatches(client);
jugsNeeded -= potOfVinegar.checkTotalMatchesInContainers(client, QuestContainerManager.getEquippedData(), QuestContainerManager.getInventoryData(), QuestContainerManager.getBankData());
potNeeded.setQuantity(jugsNeeded);
jugOfVinegarNeeded.setQuantity(jugsNeeded);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void load(Client client, List<Item> items, int puzzle1SolutionValue, int
puzzleNeeds.clear();
toExchange.clear();

if (!puzzle1Requirement.check(client, false, items))
if (!puzzle1Requirement.checkItems(client, items))
{
puzzleNeeds.add(puzzle1Requirement);
var singleDiscExchange = valuePossibleSingleDiscExchangesRequirements.get(puzzle1SolutionValue).stream().filter(requirement -> inventoryHas(items, requirement.getId())).collect(Collectors.toUnmodifiableList());
Expand Down Expand Up @@ -131,7 +131,7 @@ public void load(Client client, List<Item> items, int puzzle1SolutionValue, int
item2 = possiblePuzzle2Solution.getItemRequirements().get(1);
}

if (possiblePuzzle2Solution.check(client, false, itemsAfterPuzzle1))
if (possiblePuzzle2Solution.checkItems(client, itemsAfterPuzzle1))
{
// Found a valid puzzle2 solution
puzzle2UpperRequirement = item1;
Expand All @@ -141,7 +141,7 @@ public void load(Client client, List<Item> items, int puzzle1SolutionValue, int

// Some goal values only have one possible solution
// Let's check if we have one of these
if (item1.check(client, false, itemsAfterPuzzle1))
if (item1.checkItems(client, itemsAfterPuzzle1))
{
// Found a partial solution
partialPuzzle2Solution = possiblePuzzle2Solution;
Expand All @@ -150,7 +150,7 @@ public void load(Client client, List<Item> items, int puzzle1SolutionValue, int
break;
}

if (item2.check(client, false, itemsAfterPuzzle1))
if (item2.checkItems(client, itemsAfterPuzzle1))
{
// Found a partial solution
partialPuzzle2Solution = possiblePuzzle2Solution;
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/com/questhelper/managers/ItemAndLastUpdated.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2024, Zoinkwiz <https://github.com/Zoinkwiz>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.questhelper.managers;

import com.questhelper.requirements.item.TrackedContainers;
import lombok.Getter;
import lombok.Setter;
import net.runelite.api.Item;

import java.util.concurrent.Callable;

public class ItemAndLastUpdated
{
@Getter
TrackedContainers containerType;
Zoinkwiz marked this conversation as resolved.
Show resolved Hide resolved

@Getter
private int lastUpdated = -1;
Zoinkwiz marked this conversation as resolved.
Show resolved Hide resolved
private Item[] items;

@Setter
private Callable<Item[]> methodToObtainItems;

public ItemAndLastUpdated(TrackedContainers containerType)
{
this.containerType = containerType;
}

public void update(int updateTick, Item[] items)
{
this.lastUpdated = updateTick;
this.items = items;
}

public Item[] getItems()
Zoinkwiz marked this conversation as resolved.
Show resolved Hide resolved
{
if (methodToObtainItems != null)
{
try
{
return methodToObtainItems.call();
} catch (Exception e)
{
System.out.println("Failed to load container from method");
Zoinkwiz marked this conversation as resolved.
Show resolved Hide resolved
}
}

return items;
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/questhelper/managers/QuestContainerManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024, Zoinkwiz <https://github.com/Zoinkwiz>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.questhelper.managers;

import com.questhelper.requirements.item.TrackedContainers;
import lombok.Getter;

public class QuestContainerManager
{
@Getter
private final static ItemAndLastUpdated equippedData = new ItemAndLastUpdated(TrackedContainers.EQUIPPED);

@Getter
private final static ItemAndLastUpdated inventoryData = new ItemAndLastUpdated(TrackedContainers.INVENTORY);

@Getter
private final static ItemAndLastUpdated bankData = new ItemAndLastUpdated(TrackedContainers.BANK);
}
4 changes: 2 additions & 2 deletions src/main/java/com/questhelper/managers/QuestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private void handleSelectedQuest()
}
if (panel.questActive)
{
clientThread.invokeLater(() -> panel.updateItemRequirements(client, questBankManager.getBankItems()));
clientThread.invokeLater(() -> panel.updateItemRequirements(client));
}
panel.updateLocks();
}
Expand Down Expand Up @@ -310,7 +310,7 @@ private void initializeNewQuest(QuestHelper questHelper, boolean shouldOpenSideb
panel.addQuest(questHelper, true);

// Force an extra update immediately after starting a quest
clientThread.invokeLater(() -> panel.updateItemRequirements(client, questBankManager.getBankItems()));
clientThread.invokeLater(() -> panel.updateItemRequirements(client));
});
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/questhelper/panel/QuestHelperPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,9 @@ public void emptyBar()
searchBar.setText("");
}

public void updateItemRequirements(Client client, List<Item> bankItems)
public void updateItemRequirements(Client client)
{
questOverviewPanel.updateRequirements(client, bankItems);
questOverviewPanel.updateRequirements(client);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/questhelper/panel/QuestOverviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,15 @@ public Dimension getPreferredSize()
return new Dimension(PANEL_WIDTH, super.getPreferredSize().height);
}

public void updateRequirements(Client client, List<Item> bankItems)
public void updateRequirements(Client client)
{
questGeneralRequirementsPanel.update(client, questHelperPlugin, bankItems);
questGeneralRecommendedPanel.update(client, questHelperPlugin, bankItems);
questItemRequirementsPanel.update(client, questHelperPlugin, bankItems);
questItemRecommendedPanel.update(client, questHelperPlugin, bankItems);
questGeneralRequirementsPanel.update(client, questHelperPlugin);
questGeneralRecommendedPanel.update(client, questHelperPlugin);
questItemRequirementsPanel.update(client, questHelperPlugin);
questItemRecommendedPanel.update(client, questHelperPlugin);

questStepPanelList.forEach((questStepPanel) -> {
questStepPanel.updateRequirements(client, bankItems);
questStepPanel.updateRequirements(client);
});
revalidate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package com.questhelper.panel;

import com.questhelper.QuestHelperPlugin;
import com.questhelper.bank.QuestBank;
import com.questhelper.managers.QuestManager;
import com.questhelper.questhelpers.QuestHelper;
import com.questhelper.requirements.Requirement;
Expand All @@ -37,7 +38,6 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import net.runelite.api.Client;
import net.runelite.api.Item;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.util.LinkBrowser;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -235,7 +235,7 @@ else if (showEvenIfEmpty)
revalidate();
}

public void update(Client client, QuestHelperPlugin questHelperPlugin, List<Item> bankItems)
public void update(Client client, QuestHelperPlugin questHelperPlugin)
{
int numActive = 0;

Expand Down Expand Up @@ -281,7 +281,7 @@ public void update(Client client, QuestHelperPlugin questHelperPlugin, List<Item
}
else
{
newColor = itemRequirement.getColorConsideringBank(client, false, bankItems, questHelperPlugin.getConfig());
newColor = itemRequirement.getColorConsideringBank(client, questHelperPlugin.getConfig());
}
}
else
Expand Down
Loading
Loading