Skip to content

Commit db19b09

Browse files
committed
Add fix Tormented Demons plugin
1 parent 04b9120 commit db19b09

2 files changed

Lines changed: 97 additions & 40 deletions

File tree

runelite-client/src/main/java/net/runelite/client/plugins/microbot/zerozero/tormenteddemons/TormentedDemonPlugin.java

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import com.google.inject.Provides;
44
import lombok.extern.slf4j.Slf4j;
5-
import net.runelite.api.GraphicsObject;
6-
import net.runelite.api.InventoryID;
7-
import net.runelite.api.Item;
8-
import net.runelite.api.ItemComposition;
5+
import net.runelite.api.*;
6+
import net.runelite.api.coords.WorldPoint;
7+
import net.runelite.api.events.AnimationChanged;
8+
import net.runelite.api.events.GameTick;
99
import net.runelite.api.events.GraphicsObjectCreated;
10+
import net.runelite.api.events.ProjectileMoved;
1011
import net.runelite.client.config.ConfigManager;
1112
import net.runelite.client.eventbus.Subscribe;
1213
import net.runelite.client.events.ConfigChanged;
@@ -15,16 +16,30 @@
1516
import net.runelite.client.plugins.microbot.Microbot;
1617

1718
import java.awt.datatransfer.StringSelection;
19+
import java.util.HashMap;
20+
import java.util.Map;
1821
import java.util.StringJoiner;
1922
import java.util.concurrent.Executors;
23+
24+
import net.runelite.client.plugins.microbot.util.inventory.Rs2Inventory;
25+
import net.runelite.client.plugins.microbot.util.magic.Rs2Magic;
26+
import net.runelite.client.plugins.microbot.util.npc.Rs2Npc;
27+
import net.runelite.client.plugins.microbot.util.npc.Rs2NpcModel;
28+
import net.runelite.client.plugins.microbot.util.player.Rs2Player;
29+
import net.runelite.client.plugins.microbot.util.prayer.Rs2Prayer;
30+
import net.runelite.client.plugins.microbot.util.prayer.Rs2PrayerEnum;
31+
import net.runelite.client.plugins.microbot.util.tabs.Rs2Tab;
2032
import net.runelite.client.plugins.microbot.util.tile.Rs2Tile;
33+
import net.runelite.client.plugins.microbot.util.widget.Rs2Widget;
2134
import net.runelite.client.ui.overlay.OverlayManager;
2235

2336
import javax.inject.Inject;
2437
import java.awt.*;
2538
import java.util.concurrent.ScheduledExecutorService;
2639
import java.util.concurrent.TimeUnit;
2740

41+
import static net.runelite.client.plugins.microbot.util.Global.sleep;
42+
2843
@PluginDescriptor(
2944
name = PluginDescriptor.zerozero + "Tormented Demons",
3045
description = "Automates restocking, prayer flicking, and gear switching during Tormented Demon",
@@ -34,6 +49,11 @@
3449
@Slf4j
3550
public class TormentedDemonPlugin extends Plugin {
3651

52+
private static final int CHANGE_ATTACK_STYLE_ANIMATION = 11387;
53+
private static final int MELEE_ATTACK_ANIMATION = 11392;
54+
private static final int MAGIC_ATTACK_ANIMATION = 11388;
55+
private static final int RANGE_ATTACK_ANIMATION = 11389;
56+
3757
private ScheduledExecutorService scheduledExecutorService;
3858

3959
@Inject
@@ -107,6 +127,8 @@ private void onConfigChanged(ConfigChanged event) {
107127
}
108128
}
109129

130+
131+
110132
@Subscribe
111133
public void onGraphicsObjectCreated(GraphicsObjectCreated event) {
112134
final GraphicsObject graphicsObject = event.getGraphicsObject();
@@ -133,5 +155,46 @@ public void onGraphicsObjectCreated(GraphicsObjectCreated event) {
133155
}
134156

135157

158+
@Subscribe
159+
public void onAnimationChanged(AnimationChanged event) {
160+
if (event.getActor() instanceof NPC) {
161+
NPC npc = (NPC) event.getActor();
162+
163+
Player localPlayer = Microbot.getClient().getLocalPlayer();
164+
if (localPlayer == null || localPlayer.getInteracting() != npc) {
165+
return;
166+
}
167+
168+
int animationId = npc.getAnimation();
169+
170+
if (animationId == CHANGE_ATTACK_STYLE_ANIMATION) {
171+
// Check which prayer is currently active
172+
boolean isMeleeActive = Rs2Prayer.isPrayerActive(Rs2PrayerEnum.PROTECT_MELEE);
173+
boolean isRangeActive = Rs2Prayer.isPrayerActive(Rs2PrayerEnum.PROTECT_RANGE);
174+
boolean isMagicActive = Rs2Prayer.isPrayerActive(Rs2PrayerEnum.PROTECT_MAGIC);
175+
176+
// Toggle the opposite prayer based on currently active prayer
177+
if (isMeleeActive) {
178+
Rs2Prayer.toggle(Rs2PrayerEnum.PROTECT_RANGE, true);
179+
} else if (isRangeActive) {
180+
Rs2Prayer.toggle(Rs2PrayerEnum.PROTECT_MAGIC, true);
181+
} else if (isMagicActive) {
182+
Rs2Prayer.toggle(Rs2PrayerEnum.PROTECT_MELEE, true);
183+
} else {
184+
Rs2Prayer.toggle(Rs2PrayerEnum.PROTECT_MELEE, true);
185+
}
186+
}
187+
188+
if (animationId == MELEE_ATTACK_ANIMATION && !Rs2Prayer.isPrayerActive(Rs2PrayerEnum.PROTECT_MELEE)) {
189+
Rs2Prayer.toggle(Rs2PrayerEnum.PROTECT_MELEE, true);
190+
}
191+
if (animationId == RANGE_ATTACK_ANIMATION && !Rs2Prayer.isPrayerActive(Rs2PrayerEnum.PROTECT_RANGE)) {
192+
Rs2Prayer.toggle(Rs2PrayerEnum.PROTECT_RANGE, true);
193+
}
194+
if (animationId == MAGIC_ATTACK_ANIMATION && !Rs2Prayer.isPrayerActive(Rs2PrayerEnum.PROTECT_MAGIC)) {
195+
Rs2Prayer.toggle(Rs2PrayerEnum.PROTECT_MAGIC, true);
196+
}
197+
}
198+
}
136199

137200
}

runelite-client/src/main/java/net/runelite/client/plugins/microbot/zerozero/tormenteddemons/TormentedDemonScript.java

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
import net.runelite.client.plugins.microbot.util.grounditem.LootingParameters;
1515
import net.runelite.client.plugins.microbot.util.grounditem.Rs2GroundItem;
1616
import net.runelite.client.plugins.microbot.util.inventory.Rs2Inventory;
17+
import net.runelite.client.plugins.microbot.util.magic.Rs2Magic;
1718
import net.runelite.client.plugins.microbot.util.npc.Rs2Npc;
1819
import net.runelite.client.plugins.microbot.util.npc.Rs2NpcModel;
1920
import net.runelite.client.plugins.microbot.util.player.Rs2Player;
2021
import net.runelite.client.plugins.microbot.util.prayer.Rs2Prayer;
2122
import net.runelite.client.plugins.microbot.util.prayer.Rs2PrayerEnum;
2223
import net.runelite.client.plugins.microbot.util.reflection.Rs2Reflection;
24+
import net.runelite.client.plugins.microbot.util.tabs.Rs2Tab;
2325
import net.runelite.client.plugins.microbot.util.walker.Rs2Walker;
26+
import net.runelite.client.plugins.microbot.util.widget.Rs2Widget;
2427
import net.runelite.client.plugins.microbot.zerozero.tormenteddemons.TormentedDemonConfig.CombatPotionType;
2528
import net.runelite.client.plugins.microbot.zerozero.tormenteddemons.TormentedDemonConfig.MODE;
2629
import net.runelite.client.plugins.microbot.zerozero.tormenteddemons.TormentedDemonConfig.RangingPotionType;
@@ -38,25 +41,23 @@ public class TormentedDemonScript extends Script {
3841
private Rs2PrayerEnum currentDefensivePrayer = null;
3942
private Rs2PrayerEnum currentOffensivePrayer = null;
4043
private HeadIcon currentOverheadIcon = null;
41-
private Rs2NpcModel currentTarget;
44+
public Rs2NpcModel currentTarget;
4245
private boolean lootAttempted = false;
4346
private String lastChatMessage = "";
4447
private boolean isRestocking = false;
4548

46-
47-
private static final int MAGIC_ATTACK_ANIMATION = 11388;
48-
private static final int RANGE_ATTACK_ANIMATION = 11389;
49-
private static final int MELEE_ATTACK_ANIMATION = 11392;
50-
5149
private static final WorldPoint SAFE_LOCATION = new WorldPoint(3150, 3634, 0);
5250

53-
private enum State { BANKING, TRAVEL_TO_TORMENTED, FIGHTING }
51+
private enum State {BANKING, TRAVEL_TO_TORMENTED, FIGHTING}
52+
5453
public static State BOT_STATUS = State.BANKING;
5554

56-
private enum TravelStep { LOCATION_ONE, CLIMB_FIRST_STAIRS, CLIMB_SECOND_STAIRS, CLIMB_THROUGH, LOCATION_THREE }
55+
private enum TravelStep {LOCATION_ONE, CLIMB_FIRST_STAIRS, CLIMB_SECOND_STAIRS, CLIMB_THROUGH, LOCATION_THREE}
56+
5757
private TravelStep travelStep = TravelStep.LOCATION_ONE;
5858

59-
private enum BankingStep { DRINK, BANK, LOAD_INVENTORY }
59+
private enum BankingStep {DRINK, BANK, LOAD_INVENTORY}
60+
6061
private BankingStep bankingStep = BankingStep.DRINK;
6162

6263
public boolean run(TormentedDemonConfig config) {
@@ -95,6 +96,9 @@ public boolean run(TormentedDemonConfig config) {
9596

9697

9798
private void handleTravel(TormentedDemonConfig config) {
99+
if (Rs2Bank.isOpen()) {
100+
Rs2Bank.closeBank();
101+
}
98102
WorldPoint targetLocationOne = new WorldPoint(4062, 4558, 0);
99103
WorldPoint targetFinalLocation = new WorldPoint(4073, 4432, 0);
100104
WorldPoint playerLocation = Microbot.getClient().getLocalPlayer().getWorldLocation();
@@ -203,6 +207,7 @@ private void handleBanking(TormentedDemonConfig config) {
203207
break;
204208
}
205209
}
210+
206211
private void handleFighting(TormentedDemonConfig config) {
207212
if (currentTarget == null || currentTarget.isDead()) {
208213
disableAllPrayers();
@@ -217,6 +222,9 @@ private void handleFighting(TormentedDemonConfig config) {
217222
}
218223

219224
currentTarget = findNewTarget(config);
225+
if (currentTarget.getInteracting() != Microbot.getClient().getLocalPlayer()) {
226+
currentTarget = findNewTarget(config);
227+
}
220228
if (currentTarget != null) {
221229
currentOverheadIcon = Rs2Reflection.getHeadIcon(currentTarget);
222230
if (currentOverheadIcon == null) {
@@ -245,6 +253,7 @@ private void handleFighting(TormentedDemonConfig config) {
245253
}
246254

247255
if (currentTarget != null && !currentTarget.isDead()) {
256+
248257
Rs2Player.eatAt(config.minEatPercent());
249258
Rs2Player.drinkPrayerPotionAt(config.minPrayerPercent());
250259

@@ -257,7 +266,7 @@ private void handleFighting(TormentedDemonConfig config) {
257266

258267
if (attackSuccessful) {
259268
Rs2Player.waitForAnimation();
260-
sleepUntil(() -> Rs2Player.getInteracting() != null && ((Rs2NpcModel) Rs2Player.getInteracting()).getIndex() == currentTarget.getIndex(), 3000);
269+
sleepUntil(() -> Rs2Player.getInteracting() != null && ((Rs2NpcModel) Rs2Player.getInteracting()).getIndex() == currentTarget.getIndex(), 3000);
261270
} else {
262271
logOnceToChat("Attack failed for target: " + (currentTarget != null ? currentTarget.getName() : "null"));
263272
currentTarget = null;
@@ -279,23 +288,6 @@ private void handleFighting(TormentedDemonConfig config) {
279288

280289
if (currentTarget == null) return;
281290

282-
int npcAnimation = currentTarget.getAnimation();
283-
if (config.enableDefensivePrayer()) {
284-
System.out.println(npcAnimation);
285-
Rs2PrayerEnum newDefensivePrayer = null;
286-
if (npcAnimation == MAGIC_ATTACK_ANIMATION) {
287-
newDefensivePrayer = Rs2PrayerEnum.PROTECT_MAGIC;
288-
} else if (npcAnimation == RANGE_ATTACK_ANIMATION) {
289-
newDefensivePrayer = Rs2PrayerEnum.PROTECT_RANGE;
290-
} else if (npcAnimation == MELEE_ATTACK_ANIMATION) {
291-
newDefensivePrayer = Rs2PrayerEnum.PROTECT_MELEE;
292-
}
293-
if (newDefensivePrayer != null && newDefensivePrayer != currentDefensivePrayer) {
294-
logOnceToChat("Changing defensive prayer to " + newDefensivePrayer);
295-
switchDefensivePrayer(newDefensivePrayer);
296-
}
297-
}
298-
299291
if (config.enableOffensivePrayer()) {
300292
activateOffensivePrayer(config);
301293
}
@@ -312,14 +304,19 @@ private void switchDefensivePrayer(Rs2PrayerEnum newDefensivePrayer) {
312304

313305
private void activateOffensivePrayer(TormentedDemonConfig config) {
314306
Rs2PrayerEnum newOffensivePrayer = null;
315-
if (config.useMagicStyle() && isGearEquipped(parseGear(config.magicGear()))) {
307+
if (config.useMagicStyle() && isGearEquipped(parseGear(config.magicGear())) && Rs2Player.getBoostedSkillLevel(Skill.PRAYER) >= 77) {
316308
newOffensivePrayer = Rs2PrayerEnum.AUGURY;
317-
} else if (config.useRangeStyle() && isGearEquipped(parseGear(config.rangeGear()))) {
318-
newOffensivePrayer = Rs2PrayerEnum.RIGOUR;
319-
} else if (config.useMeleeStyle() && isGearEquipped(parseGear(config.meleeGear()))) {
309+
} else if (config.useMagicStyle() && isGearEquipped(parseGear(config.magicGear()))) {
310+
newOffensivePrayer = Rs2PrayerEnum.MYSTIC_LORE;
311+
} else if (config.useMeleeStyle() && isGearEquipped(parseGear(config.meleeGear())) && Rs2Player.getBoostedSkillLevel(Skill.PRAYER) >= 70) {
320312
newOffensivePrayer = Rs2PrayerEnum.PIETY;
313+
} else if (config.useMeleeStyle() && isGearEquipped(parseGear(config.meleeGear()))) {
314+
newOffensivePrayer = Rs2PrayerEnum.ULTIMATE_STRENGTH;
315+
} else if (config.useRangeStyle() && isGearEquipped(parseGear(config.rangeGear())) && Rs2Player.getBoostedSkillLevel(Skill.PRAYER) >= 70) {
316+
newOffensivePrayer = Rs2PrayerEnum.RIGOUR;
317+
} else if (config.useRangeStyle() && isGearEquipped(parseGear(config.rangeGear()))) {
318+
newOffensivePrayer = Rs2PrayerEnum.HAWK_EYE;
321319
}
322-
323320
if (newOffensivePrayer != null && newOffensivePrayer != currentOffensivePrayer) {
324321
logOnceToChat("Changing offensive prayer to " + newOffensivePrayer);
325322
switchOffensivePrayer(newOffensivePrayer);
@@ -421,7 +418,7 @@ private boolean shouldRetreat(TormentedDemonConfig config) {
421418
boolean noPrayerPotions = Rs2Inventory.items().stream()
422419
.noneMatch(item -> item != null && item.getName() != null && item.getName().toLowerCase().contains("prayer potion"));
423420

424-
return (noFood && currentHealth <= config.healthThreshold()) || (noPrayerPotions && currentPrayer < 10);
421+
return (noFood || currentHealth <= config.healthThreshold()) || (noPrayerPotions && currentPrayer < 10);
425422
}
426423

427424
public void disableAllPrayers() {
@@ -589,7 +586,4 @@ public void shutdown() {
589586
}
590587
logOnceToChat("Shutting down Tormented Demon script");
591588
}
592-
593-
594-
595589
}

0 commit comments

Comments
 (0)