From c458088fd9897d9d48c3593d016f22150bfc5055 Mon Sep 17 00:00:00 2001 From: Zoinkwiz Date: Sat, 23 Sep 2023 13:22:33 +0100 Subject: [PATCH] Add TeleportItemRequirement This new class makes it easier to make teleport items auto consider charges in jewellery and such. --- .../java/com/questhelper/ItemWithCharge.java | 36 +++++++++++++--- .../quests/deserttreasure/DesertTreasure.java | 25 ++++++----- .../item/TeleportItemRequirement.java | 43 +++++++++++++++++++ 3 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/questhelper/requirements/item/TeleportItemRequirement.java diff --git a/src/main/java/com/questhelper/ItemWithCharge.java b/src/main/java/com/questhelper/ItemWithCharge.java index af81f4df59..370562ed4b 100644 --- a/src/main/java/com/questhelper/ItemWithCharge.java +++ b/src/main/java/com/questhelper/ItemWithCharge.java @@ -25,19 +25,19 @@ */ package com.questhelper; +import java.util.AbstractMap; import java.util.Arrays; +import java.util.List; import java.util.Map; -import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; -import lombok.AllArgsConstructor; +import com.google.common.collect.ImmutableList; import lombok.Getter; import static net.runelite.api.ItemID.*; /** * Based off of RuneLite's ItemWithCharge enum */ -@AllArgsConstructor @Getter public enum ItemWithCharge { @@ -129,16 +129,38 @@ public enum ItemWithCharge TCRYSTAL3(TELEPORT_CRYSTAL_3, 3), TCRYSTAL4(TELEPORT_CRYSTAL_4, 4), TCRYSTAL5(TELEPORT_CRYSTAL_5, 5), + + // Infinite charges + FAIRY_RING_STAFF(ItemCollections.FAIRY_STAFF, 10000000) ; - private final int id; + private final List ids; private final int charges; - private static final Map ID_MAP; + ItemWithCharge(int ids, int charges) + { + this.ids = ImmutableList.of(ids); + this.charges = charges; + } - static + ItemWithCharge(List ids, int charges) { - ID_MAP = Arrays.stream(values()).collect(Collectors.toMap(ItemWithCharge::getId, Function.identity())); + this.ids = ids; + this.charges = charges; + } + + ItemWithCharge(ItemCollections ids, int charges) + { + this.ids = ids.getItems(); + this.charges = charges; + } + + private static final Map ID_MAP; + + static { + ID_MAP = Arrays.stream(values()) + .flatMap(item -> item.ids.stream().map(id -> new AbstractMap.SimpleEntry<>(id, item))) + .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue, (e1, e2) -> e1)); } @Nullable diff --git a/src/main/java/com/questhelper/helpers/quests/deserttreasure/DesertTreasure.java b/src/main/java/com/questhelper/helpers/quests/deserttreasure/DesertTreasure.java index fccdda37f2..b9510afd8b 100644 --- a/src/main/java/com/questhelper/helpers/quests/deserttreasure/DesertTreasure.java +++ b/src/main/java/com/questhelper/helpers/quests/deserttreasure/DesertTreasure.java @@ -33,6 +33,8 @@ import com.questhelper.questhelpers.BasicQuestHelper; import com.questhelper.requirements.ComplexRequirement; import com.questhelper.requirements.item.ItemRequirement; +import com.questhelper.requirements.item.TeleportItemRequirement; +import com.questhelper.requirements.npc.NpcInteractingRequirement; import com.questhelper.requirements.quest.QuestRequirement; import com.questhelper.requirements.Requirement; import com.questhelper.requirements.player.SkillRequirement; @@ -306,20 +308,20 @@ public void setupRequirements() energyOrStaminas = new ItemRequirement("Energy/Stamina potions", ItemCollections.RUN_RESTORE_ITEMS); // Teleports - canifisTeleport = new ItemRequirement("Teleport to Canifis. Fairy Ring (CKS), Fenkenstrain's teleport", ItemCollections.FAIRY_STAFF); + canifisTeleport = new TeleportItemRequirement("Teleport to Canifis. Fairy Ring (CKS), Fenkenstrain's teleport", ItemCollections.FAIRY_STAFF); canifisTeleport.addAlternates(ItemID.FENKENSTRAINS_CASTLE_TELEPORT); - bedabinTeleport = new ItemRequirement("Teleport to Bedabin Camp. Fairy Ring (BIQ), Camulet", ItemCollections.FAIRY_STAFF); + bedabinTeleport = new TeleportItemRequirement("Teleport to Bedabin Camp. Fairy Ring (BIQ), Camulet", ItemCollections.FAIRY_STAFF); bedabinTeleport.addAlternates(ItemID.CAMULET); - pollnivneachTeleport = new ItemRequirement("Teleport to Pollnivneach. Pollnivneach house teleport", ItemID.POLLNIVNEACH_TELEPORT); - waterfallTeleport = new ItemRequirement("Teleport to the Waterfall. Skills necklace (Fishing Guild [1]), Games necklace (Barbarian Outpost [2])", ItemCollections.SKILLS_NECKLACES); + pollnivneachTeleport = new TeleportItemRequirement("Teleport to Pollnivneach. Pollnivneach house teleport", ItemID.POLLNIVNEACH_TELEPORT); + waterfallTeleport = new TeleportItemRequirement("Teleport to the Waterfall. Skills necklace (Fishing Guild [1]), Games necklace (Barbarian Outpost [2])", ItemCollections.SKILLS_NECKLACES); waterfallTeleport.addAlternates(ItemCollections.GAMES_NECKLACES); - banditCampTeleport = new ItemRequirement("Teleport to Bandit Camp (desert). Fairy Ring (BIQ), Camulet", ItemCollections.FAIRY_STAFF); + banditCampTeleport = new TeleportItemRequirement("Teleport to Bandit Camp (desert). Fairy Ring (BIQ), Camulet", ItemCollections.FAIRY_STAFF); banditCampTeleport.addAlternates(ItemID.CAMULET); - draynorTeleport = new ItemRequirement("Teleport to Draynor Village. Amulet of Glory (Draynor Village [3]), Draynor Manor Teleport", ItemCollections.AMULET_OF_GLORIES); + draynorTeleport = new TeleportItemRequirement("Teleport to Draynor Village. Amulet of Glory (Draynor Village [3]), Draynor Manor Teleport", ItemCollections.AMULET_OF_GLORIES); draynorTeleport.addAlternates(ItemID.DRAYNOR_MANOR_TELEPORT); - trollheimTeleport = new ItemRequirement("Teleport to Trollheim. Trollheim teleport, Ghommal's hilt (any tier)", ItemID.TROLLHEIM_TELEPORT); + trollheimTeleport = new TeleportItemRequirement("Teleport to Trollheim. Trollheim teleport, Ghommal's hilt (any tier)", ItemID.TROLLHEIM_TELEPORT); trollheimTeleport.addAlternates(ItemCollections.GHOMMALS_HILT); - pyramidTeleport = new ItemRequirement("Teleport to Jaldraocht Pyramid. Camulet, Pollnivneach house teleport", ItemID.CAMULET); + pyramidTeleport = new TeleportItemRequirement("Teleport to Jaldraocht Pyramid. Camulet, Pollnivneach house teleport", ItemID.CAMULET); pyramidTeleport.addAlternates(ItemID.POLLNIVNEACH_TELEPORT); } @@ -364,8 +366,9 @@ public void setupConditions() inShadowDungeon = new ZoneRequirement(shadowDungeon); - damis1Nearby = new NpcCondition(NpcID.DAMIS); - damis2Nearby = new NpcCondition(NpcID.DAMIS_683); + damis1Nearby = new NpcInteractingRequirement(NpcID.DAMIS); + damis2Nearby = new NpcInteractingRequirement(NpcID.DAMIS_683); + // 385 0->1, in Damis spawn area? talkedToMalak = new VarbitRequirement(373, 1); askedAboutKillingDessous = new VarbitRequirement(373, 2); @@ -473,8 +476,8 @@ public void setupSteps() killFareed = new NpcStep(this, NpcID.FAREED, new WorldPoint(3315, 9375, 0), "Kill Fareed. Either use melee with ice gloves, or water spells.", iceGloves, waterSpellOrMelee); talkToRasolo = new NpcStep(this, NpcID.RASOLO, new WorldPoint(2531, 3420, 0), "Talk to Rasolo south of Baxtorian Falls."); - talkToRasolo.addDialogStep("Ask about the Diamonds of Azzanadra"); talkToRasolo.addDialogStepWithExclusion("Yes", "Ask about the Diamonds of Azzanadra"); + talkToRasolo.addDialogStep("Ask about the Diamonds of Azzanadra"); talkToRasolo.addTeleport(waterfallTeleport); getCross = new ObjectStep(this, ObjectID.SECURE_CHEST, new WorldPoint(3169, 2967, 0), "Bring antipoison, food, and as many lockpicks as you can to the Bandit Camp, and try opening the chest in the south of the Bandit Camp. Keep trying until you succeed.", manyLockpicks, antipoison); diff --git a/src/main/java/com/questhelper/requirements/item/TeleportItemRequirement.java b/src/main/java/com/questhelper/requirements/item/TeleportItemRequirement.java new file mode 100644 index 0000000000..1dbb3b9113 --- /dev/null +++ b/src/main/java/com/questhelper/requirements/item/TeleportItemRequirement.java @@ -0,0 +1,43 @@ +/* + * * Copyright (c) 2023, 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.requirements.item; + +import com.questhelper.ItemCollections; + +public class TeleportItemRequirement extends ItemRequirement +{ + public TeleportItemRequirement(String name, int id) + { + super(name, id); + setChargedItem(true); + } + + public TeleportItemRequirement(String name, ItemCollections itemCollection) + { + super(name, itemCollection); + setChargedItem(true); + } +}