Skip to content

Commit

Permalink
Add TeleportItemRequirement
Browse files Browse the repository at this point in the history
This new class makes it easier to make teleport items auto consider charges in jewellery and such.
  • Loading branch information
Zoinkwiz committed Sep 23, 2023
1 parent 21431b0 commit c458088
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 18 deletions.
36 changes: 29 additions & 7 deletions src/main/java/com/questhelper/ItemWithCharge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://github.com/runelite/runelite/blob/4700013ffbd089899df9cb675ff53b00d381cae5/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemWithCharge.java">ItemWithCharge</a> enum
*/
@AllArgsConstructor
@Getter
public enum ItemWithCharge
{
Expand Down Expand Up @@ -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<Integer> ids;
private final int charges;

private static final Map<Integer, ItemWithCharge> ID_MAP;
ItemWithCharge(int ids, int charges)
{
this.ids = ImmutableList.of(ids);
this.charges = charges;
}

static
ItemWithCharge(List<Integer> 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<Integer, ItemWithCharge> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* * Copyright (c) 2023, 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.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);
}
}

0 comments on commit c458088

Please sign in to comment.