Skip to content

Commit

Permalink
feat: Create VarComparisonRequirement for Lumbridge Elite quests comp…
Browse files Browse the repository at this point in the history
…lete check (#1766)

* feat: Added VarComparisonRequirement

This makes it easier to compare values between various varbits and varps. The initial usage will be for seeing if the player has all quests completed.

* feat: Make use of var 1782 to check all quests completed

This is used in Lumbridge Elite diary.

* fix: Added missing header to VarType

* fix: Update docs on VarComparisonRequirement
  • Loading branch information
Zoinkwiz authored Sep 27, 2024
1 parent 45c096e commit d46bb21
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@

import com.questhelper.collections.ItemCollections;
import com.questhelper.questinfo.QuestHelperQuest;
import com.questhelper.requirements.util.Operation;
import com.questhelper.requirements.var.VarComparisonRequirement;
import com.questhelper.requirements.var.VarType;
import com.questhelper.requirements.zone.Zone;
import com.questhelper.questhelpers.ComplexStateQuestHelper;
import com.questhelper.questhelpers.QuestDetails;
import com.questhelper.requirements.ComplexRequirement;
import com.questhelper.requirements.Requirement;
import com.questhelper.requirements.zone.ZoneRequirement;
Expand All @@ -50,17 +52,12 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.runelite.api.Client;
import net.runelite.api.ItemID;
import net.runelite.api.NpcID;
import net.runelite.api.ObjectID;
import net.runelite.api.QuestState;
import net.runelite.api.Skill;

import net.runelite.api.*;
import net.runelite.api.coords.WorldPoint;
import com.questhelper.requirements.item.ItemRequirement;
import com.questhelper.panel.PanelDetails;
import com.questhelper.steps.QuestStep;
import javax.annotation.Nonnull;

public class LumbridgeElite extends ComplexStateQuestHelper
{
Expand Down Expand Up @@ -134,35 +131,7 @@ protected void setupRequirements()
notWaterRunes = new VarplayerRequirement(1195, false, 8);
notQCEmote = new VarplayerRequirement(1195, false, 9);

allQuests = new Requirement()
{
@Override
public boolean check(Client client)
{
boolean allQuestsCompleted = true;
for (QuestHelperQuest quest : QuestHelperQuest.values())
{
if (quest.getQuestType() == QuestDetails.Type.F2P
|| quest.getQuestType() == QuestDetails.Type.P2P)
{
if (quest.getState(client, configManager) != QuestState.FINISHED)
{
allQuestsCompleted = false;
break;
}
}
}

return allQuestsCompleted;
}

@Nonnull
@Override
public String getDisplayText()
{
return "All Quests are Completed";
}
};
allQuests = new VarComparisonRequirement(VarType.VARP, VarPlayer.QUEST_POINTS, VarType.VARBIT, 1782, Operation.EQUAL, "All quests completed");

lockpick = new ItemRequirement("Lockpick", ItemID.LOCKPICK).showConditioned(notRichChest).isNotConsumed();
crossbow = new ItemRequirement("Crossbow", ItemCollections.CROSSBOWS).showConditioned(notMovario).isNotConsumed();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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.requirements.var;

import com.questhelper.questhelpers.QuestHelper;
import com.questhelper.requirements.AbstractRequirement;
import com.questhelper.requirements.util.Operation;
import java.math.BigInteger;
import java.util.Locale;
import java.util.function.Predicate;
import java.util.function.ToIntBiFunction;

import com.questhelper.util.Utils;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.Varbits;
import net.runelite.client.util.Text;

import javax.annotation.Nonnull;

/**
* Checks if a player's varbit value is meets the required value as determined by the
* {@link Operation}
*/
@Getter
@Slf4j
public class VarComparisonRequirement extends AbstractRequirement
{
private final VarType v1Type;
private final int v1Id;

private final VarType v2Type;
private final int v2Id;
private final Operation operation;
private final String displayText;

private boolean hasFiredWarning = false;

/**
* Compares the varbit/varp of a player to another varbit/varp of the player
* {@link Operation}.
*
* @param v1Type the {@link VarType} to use for the first id
* @param v1Id the {@link Varbits} or {@link net.runelite.api.annotations.Varp} id to use for the first id
* @param v2Type the {@link VarType} to use for the second id
* @param v2Id the {@link Varbits} or {@link net.runelite.api.annotations.Varp} id to use for the second id
* @param operation the {@link Operation} to check with
* @param displayText the display text
*/
public VarComparisonRequirement(VarType v1Type, int v1Id, VarType v2Type, int v2Id, Operation operation, String displayText)
{
this.v1Type = v1Type;
this.v1Id = v1Id;
this.v2Type = v2Type;
this.v2Id = v2Id;
this.operation = operation;
this.displayText = displayText;
shouldCountForFilter = true;
}

@Override
public boolean check(Client client)
{
try {
int v1Value = v1Type.getValue(client, v1Id);
int v2Value = v2Type.getValue(client, v2Id);

return operation.check(v1Value, v2Value);
} catch (IndexOutOfBoundsException e) {
if (!hasFiredWarning) {
var message = String.format("Error reading varbit %d or %d, please report this in the Quest Helper discord.", v1Id, v2Id);
log.warn(message);
Utils.addChatMessage(client, message);
hasFiredWarning = true;
}
return false;
}
}

@Nonnull
@Override
public String getDisplayText()
{
if (displayText != null)
{
return displayText;
}

return v1Type.name() + " " + v1Id + " must be + " + operation.name().toLowerCase(Locale.ROOT) + " to " + v2Type.name() + " " + v2Id;
}
}
46 changes: 46 additions & 0 deletions src/main/java/com/questhelper/requirements/var/VarType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.requirements.var;

import net.runelite.api.Client;

import java.util.function.ToIntBiFunction;

public enum VarType {
VARBIT(Client::getVarbitValue),
VARP(Client::getVarpValue);

private final ToIntBiFunction<Client, Integer> getter;

VarType(ToIntBiFunction<Client, Integer> getter)
{
this.getter = getter;
}

public int getValue(Client client, int id)
{
return getter.applyAsInt(client, id);
}
}

0 comments on commit d46bb21

Please sign in to comment.