Initial commit
This commit is contained in:
121
Util/src/io/reisub/dreambot/util/randomevents/GenieSolver.java
Normal file
121
Util/src/io/reisub/dreambot/util/randomevents/GenieSolver.java
Normal file
@ -0,0 +1,121 @@
|
||||
package io.reisub.dreambot.util.randomevents;
|
||||
|
||||
import org.dreambot.api.methods.Calculations;
|
||||
import org.dreambot.api.methods.MethodContext;
|
||||
import org.dreambot.api.methods.container.impl.Inventory;
|
||||
import org.dreambot.api.methods.interactive.NPCs;
|
||||
import org.dreambot.api.methods.interactive.Players;
|
||||
import org.dreambot.api.methods.widget.Widgets;
|
||||
import org.dreambot.api.randoms.RandomEvent;
|
||||
import org.dreambot.api.randoms.RandomSolver;
|
||||
import org.dreambot.api.wrappers.interactive.NPC;
|
||||
import org.dreambot.api.wrappers.widgets.WidgetChild;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GenieSolver extends RandomSolver {
|
||||
@SuppressWarnings("unused")
|
||||
public enum Skill {
|
||||
ATTACK(2),
|
||||
STRENGTH(3),
|
||||
RANGED(4),
|
||||
MAGIC(5),
|
||||
DEFENSE(6),
|
||||
CONSTITUTION(7),
|
||||
PRAYER(8),
|
||||
AGILITY(9),
|
||||
HERBLORE(10),
|
||||
THIEVING(11),
|
||||
CRAFTING(12),
|
||||
RUNECRAFTING(13),
|
||||
SLAYER(14),
|
||||
FARMING(15),
|
||||
MINING(16),
|
||||
SMITHING(17),
|
||||
FISHING(18),
|
||||
COOKING(19),
|
||||
FIREMAKING(20),
|
||||
WOODCUTTING(21),
|
||||
FLETCHING(22),
|
||||
CONSTRUCTION(23),
|
||||
HUNTING(24);
|
||||
|
||||
private final int index;
|
||||
|
||||
Skill(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
private final Skill skill;
|
||||
|
||||
private NPC playerGenie;
|
||||
|
||||
public GenieSolver(Skill skill) {
|
||||
super(RandomEvent.GENIE);
|
||||
this.skill = skill;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
List<NPC> genies = NPCs.all("Genie");
|
||||
String playerName = Players.localPlayer().getName();
|
||||
|
||||
if (playerGenie != null || Inventory.contains(2528)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (genies.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (NPC genie : genies) {
|
||||
String overheadMsg = genie.getOverhead();
|
||||
|
||||
if (overheadMsg == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (overheadMsg.contains(playerName)) {
|
||||
playerGenie = genie;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onLoop() {
|
||||
WidgetChild lampInterface = Widgets.getChildWidget(240, 0);
|
||||
|
||||
if (lampInterface != null && lampInterface.isVisible()) {
|
||||
MethodContext.log("[GenieSolver] Choosing " + skill.name());
|
||||
WidgetChild skillOption = Widgets.getChildWidget(240, skill.getIndex());
|
||||
skillOption.interact();
|
||||
|
||||
WidgetChild confirm = Widgets.getChildWidget(240, 26);
|
||||
confirm.interact();
|
||||
|
||||
MethodContext.sleepUntil(() -> Widgets.getChildWidget(240, 0) == null, 2000);
|
||||
} else if (Inventory.contains(2528)) {
|
||||
MethodContext.log("[GenieSolver] Rubbing lamp");
|
||||
playerGenie = null;
|
||||
|
||||
Inventory.interact(2528, "Rub");
|
||||
|
||||
MethodContext.sleepUntil(() -> Widgets.getChildWidget(240, 0) != null, 2000);
|
||||
} else {
|
||||
MethodContext.log("[GenieSolver] Interacting with Genie");
|
||||
playerGenie.interact();
|
||||
|
||||
MethodContext.sleepUntil(() -> Inventory.contains(2528), Calculations.random(4000, 5000));
|
||||
}
|
||||
|
||||
return Calculations.random(150, 350);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user