Skip to content

Commit

Permalink
feat: Added vial support for potion storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoinkwiz committed Nov 27, 2024
1 parent 5bd1a71 commit 316b6bf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
38 changes: 31 additions & 7 deletions src/main/java/com/questhelper/bank/banktab/PotionStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.*;
import net.runelite.api.events.ClientTick;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.VarbitChanged;
import net.runelite.api.widgets.ComponentID;
import net.runelite.api.widgets.Widget;
Expand All @@ -57,6 +56,7 @@ class Potion
public class PotionStorage
{
static final int TOTAL_POTIONS_VARBIT = 4286;
static final int VIAL_IDX = 514;
static final int COMPONENTS_PER_POTION = 5;

private final Client client;
Expand Down Expand Up @@ -116,7 +116,7 @@ private void rebuildPotions()
{
var potionStorePotions = client.getEnum(EnumID.POTIONSTORE_POTIONS);
var potionStoreUnfinishedPotions = client.getEnum(EnumID.POTIONSTORE_UNFINISHED_POTIONS);
potions = new Potion[potionStorePotions.size() + potionStoreUnfinishedPotions.size()];
potions = new Potion[potionStorePotions.size() + potionStoreUnfinishedPotions.size() + 1];
int potionsIdx = 0;
for (EnumComposition e : new EnumComposition[]{potionStorePotions, potionStoreUnfinishedPotions})
{
Expand All @@ -142,6 +142,14 @@ private void rebuildPotions()
}
}

// Add vial
Potion p = new Potion();
p.potionEnum = null;
p.itemId = ItemID.VIAL;
p.doses = client.getVarpValue(4286);
p.withdrawDoses = 0;
potions[potions.length - 1] = p;

QuestContainerManager.getPotionData().update(client.getTickCount(), getItems());
}

Expand All @@ -158,10 +166,16 @@ public Item[] getItems()
{
if (potion == null) continue;
var potionEnum = potion.potionEnum;
// TODO: An issue due to potentially wanting a specific potion, or to default to full potion
int potionItemId = potionEnum.getIntValue(potion.withdrawDoses);
int quantity = potion.doses / potion.withdrawDoses;
items.add(new Item(potionItemId, quantity));
if (potionEnum != null)
{
int potionItemId = potionEnum.getIntValue(potion.withdrawDoses);
int quantity = potion.doses / potion.withdrawDoses;
items.add(new Item(potionItemId, quantity));
}
else
{
items.add(new Item(potion.itemId, potion.doses));
}
}

return items.toArray(new Item[0]);
Expand All @@ -178,7 +192,12 @@ int count(int itemId)
{
if (potion != null && potion.itemId == itemId)
{
return potion.doses / potion.withdrawDoses;
if (potion.withdrawDoses != 0)
{
return potion.doses / potion.withdrawDoses;
}

return potion.doses;
}
}
return 0;
Expand All @@ -191,6 +210,11 @@ int find(int itemId)
return -1;
}

if (itemId == ItemID.VIAL)
{
return VIAL_IDX;
}

int potionIdx = 0;
for (Potion potion : potions)
{
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/questhelper/bank/banktab/QuestBankTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import net.runelite.client.util.Text;

import static com.questhelper.bank.banktab.PotionStorage.COMPONENTS_PER_POTION;
import static com.questhelper.bank.banktab.PotionStorage.VIAL_IDX;
import static net.runelite.client.plugins.banktags.BankTagsPlugin.*;

@Singleton
Expand Down Expand Up @@ -293,7 +294,13 @@ public void onMenuOptionClicked(MenuOptionClicked event)
}

idx = potionStorage.find(w.getItemId());
if (idx > -1)
if (idx == VIAL_IDX)
{
potionStorage.prepareWidgets();
menu.setParam1(ComponentID.BANK_POTIONSTORE_CONTENT);
menu.setParam0(VIAL_IDX);
}
else if (idx > -1)
{
potionStorage.prepareWidgets();
menu.setParam1(ComponentID.BANK_POTIONSTORE_CONTENT);
Expand Down

0 comments on commit 316b6bf

Please sign in to comment.