-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDistractionReducerPlugin.java
More file actions
680 lines (570 loc) · 28.2 KB
/
DistractionReducerPlugin.java
File metadata and controls
680 lines (570 loc) · 28.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
package com.distractionreducer;
import com.google.inject.Provides;
import javax.inject.Inject;
import net.runelite.api.*;
import net.runelite.api.coords.WorldPoint; // Add this import
import net.runelite.api.coords.WorldArea;
import net.runelite.api.widgets.Widget;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.events.ConfigChanged;
import java.util.Set;
import java.util.HashSet;
import net.runelite.client.callback.ClientThread;
import lombok.extern.slf4j.Slf4j;
@PluginDescriptor(
name = "Distraction Reducer",
description = "Blacks out the screen while skilling to reduce distractions",
tags = {"woodcutting", "fishing", "mining", "cooking", "herblore", "crafting", "fletching", "smithing", "magic", "sailing", "salvaging", "skilling", "overlay"}
)
@Slf4j
public class DistractionReducerPlugin extends Plugin {
@Inject
private Client client;
@Inject
private ClientThread clientThread;
@Inject
private OverlayManager overlayManager;
@Inject
private DistractionReducerConfig config;
@Inject
private DistractionReducerOverlay distractionReducerOverlay;
private int restoreDelayTicks = 0;
private boolean wasSkilling = false;
// Combat integration fields
private int combatRestoreDelayTicks = 0;
private boolean wasCombating = false;
private Set<Integer> targetMonsterIds = new HashSet<>();
private Set<String> targetMonsterNames = new HashSet<>();
// Interface auto-exit cooldown
private int interfaceExitCooldownTicks = 0;
private static final int WALKING_POSE = 1205;
private static final int RUNNING_POSE = 1210;
private static final Set<Integer> TURNING_POSES = Set.of(1206, 1208);
// TOA Region IDs
private static final int TOA_LOBBY = 14160;
private static final Set<Integer> TOA_REGIONS = Set.of(
14162, // Croc
14164, // Scarab
14166, // Het
14168, // Baba
14170, // Zebak
14172, // Kephri
14160, // Lobby
14674 // Wardens
);
// Duke Sucellus Region ID
private static final int DUKE_SUCELLUS_REGION = 12132;
// POH Region IDs - Player-Owned Houses are instanced and use specific region ranges
private static final Set<Integer> POH_REGIONS = Set.of(
7513, // Rimmington POH
7769, // Taverley POH
7257, // Pollnivneach POH
6457, // Hosidius POH
10553, // Rellekka POH
7499, // Brimhaven POH
8013, // Yanille POH
4919 // Prifddinas POH
);
// Updated Magic Animation IDs
private static final Set<Integer> PLANK_MAKE_ANIMATION_IDS = Set.of(6298);
private static final Set<Integer> ENCHANT_JEWELRY_ANIMATION_IDS = Set.of(
619, // Sapphire
721, // Emerald
724, // Ruby
727, // Diamond
730, // Dragonstone
// Bulk enchantment animations
719, // Sapphire bulk
722, // Emerald bulk
725, // Ruby bulk
728, // Diamond bulk
731, // Dragonstone bulk
// Special item-specific animations
720, // Games necklace (Sapphire)
723, // Ring of dueling (Emerald)
726, // Binding necklace (Ruby)
729, // Ring of life (Diamond)
732, // Combat bracelet (Dragonstone)
// Modern universal animations
7531, // Modern universal
931 // Modern alternative
);
private static final Set<Integer> CHARGE_ORB_ANIMATION_IDS = Set.of(726);
private static final Set<Integer> BAKE_PIE_ANIMATION_IDS = Set.of(4413);
private static final Set<Integer> STRING_JEWELRY_ANIMATION_IDS = Set.of(4412);
private static final Set<Integer> WOODCUTTING_ANIMATION_IDS = Set.of(
AnimationID.WOODCUTTING_BRONZE, AnimationID.WOODCUTTING_IRON, AnimationID.WOODCUTTING_STEEL,
AnimationID.WOODCUTTING_BLACK, AnimationID.WOODCUTTING_MITHRIL, AnimationID.WOODCUTTING_ADAMANT,
AnimationID.WOODCUTTING_RUNE, AnimationID.WOODCUTTING_DRAGON, AnimationID.WOODCUTTING_DRAGON_OR,
AnimationID.WOODCUTTING_INFERNAL, AnimationID.WOODCUTTING_3A_AXE, AnimationID.WOODCUTTING_CRYSTAL,
AnimationID.WOODCUTTING_TRAILBLAZER, AnimationID.WOODCUTTING_2H_BRONZE, AnimationID.WOODCUTTING_2H_IRON,
AnimationID.WOODCUTTING_2H_STEEL, AnimationID.WOODCUTTING_2H_BLACK, AnimationID.WOODCUTTING_2H_MITHRIL,
AnimationID.WOODCUTTING_2H_ADAMANT, AnimationID.WOODCUTTING_2H_RUNE, AnimationID.WOODCUTTING_2H_DRAGON,
AnimationID.WOODCUTTING_2H_CRYSTAL, AnimationID.WOODCUTTING_2H_CRYSTAL_INACTIVE, AnimationID.WOODCUTTING_2H_3A
);
private static final Set<Integer> SMITHING_ANIMATION_IDS = Set.of(
AnimationID.SMITHING_ANVIL, AnimationID.SMITHING_SMELTING, AnimationID.SMITHING_IMCANDO_HAMMER
);
private static final Set<Integer> FISHING_ANIMATION_IDS = Set.of(
AnimationID.FISHING_BARBARIAN_ROD, AnimationID.FISHING_BARBTAIL_HARPOON, AnimationID.FISHING_BAREHAND,
AnimationID.FISHING_BIG_NET, AnimationID.FISHING_CAGE, AnimationID.FISHING_CRYSTAL_HARPOON,
AnimationID.FISHING_DRAGON_HARPOON, AnimationID.FISHING_HARPOON, AnimationID.FISHING_INFERNAL_HARPOON,
AnimationID.FISHING_KARAMBWAN, AnimationID.FISHING_NET, AnimationID.FISHING_OILY_ROD,
AnimationID.FISHING_POLE_CAST, AnimationID.FISHING_PEARL_ROD, AnimationID.FISHING_PEARL_FLY_ROD,
AnimationID.FISHING_PEARL_BARBARIAN_ROD, AnimationID.FISHING_PEARL_ROD_2,
AnimationID.FISHING_PEARL_FLY_ROD_2, AnimationID.FISHING_PEARL_BARBARIAN_ROD_2,
AnimationID.FISHING_TRAILBLAZER_HARPOON, AnimationID.FISHING_PEARL_OILY_ROD
);
private static final Set<Integer> COOKING_ANIMATION_IDS = Set.of(
AnimationID.COOKING_FIRE, AnimationID.COOKING_RANGE, AnimationID.COOKING_WINE
);
private static final Set<Integer> HERBLORE_ANIMATION_IDS = Set.of(
AnimationID.HERBLORE_POTIONMAKING, AnimationID.HERBLORE_MAKE_TAR
);
private static final Set<Integer> CRAFTING_ANIMATION_IDS = Set.of(
AnimationID.CRAFTING_LEATHER, AnimationID.CRAFTING_GLASSBLOWING, AnimationID.CRAFTING_SPINNING,
AnimationID.CRAFTING_POTTERS_WHEEL, AnimationID.CRAFTING_POTTERY_OVEN,
// Gem cutting animations - verified unique IDs
892, // Sapphire
891, // Emerald
890, // Ruby
889, // Diamond
888, // Dragonstone
887, // Opal
886, // Jade
885, // Red topaz
7531, // Battlestaff crafting
7202 // Zeah: Chiseling dark essence blocks into fragments
);
private static final Set<Integer> FLETCHING_ANIMATION_IDS = Set.of(
AnimationID.FLETCHING_BOW_CUTTING, AnimationID.FLETCHING_STRING_NORMAL_SHORTBOW,
AnimationID.FLETCHING_STRING_NORMAL_LONGBOW, AnimationID.FLETCHING_STRING_OAK_SHORTBOW,
AnimationID.FLETCHING_STRING_OAK_LONGBOW, AnimationID.FLETCHING_STRING_WILLOW_SHORTBOW,
AnimationID.FLETCHING_STRING_WILLOW_LONGBOW, AnimationID.FLETCHING_STRING_MAPLE_SHORTBOW,
AnimationID.FLETCHING_STRING_MAPLE_LONGBOW, AnimationID.FLETCHING_STRING_YEW_SHORTBOW,
AnimationID.FLETCHING_STRING_YEW_LONGBOW, AnimationID.FLETCHING_STRING_MAGIC_SHORTBOW,
AnimationID.FLETCHING_STRING_MAGIC_LONGBOW
);
private static final Set<Integer> MINING_ANIMATION_IDS = Set.of(
AnimationID.MINING_BRONZE_PICKAXE, AnimationID.MINING_IRON_PICKAXE, AnimationID.MINING_STEEL_PICKAXE,
AnimationID.MINING_BLACK_PICKAXE, AnimationID.MINING_MITHRIL_PICKAXE, AnimationID.MINING_ADAMANT_PICKAXE,
AnimationID.MINING_RUNE_PICKAXE, AnimationID.MINING_DRAGON_PICKAXE, AnimationID.MINING_DRAGON_PICKAXE_UPGRADED,
AnimationID.MINING_DRAGON_PICKAXE_OR, AnimationID.MINING_INFERNAL_PICKAXE, AnimationID.MINING_3A_PICKAXE,
AnimationID.MINING_CRYSTAL_PICKAXE, AnimationID.MINING_TRAILBLAZER_PICKAXE, AnimationID.MINING_GILDED_PICKAXE,
AnimationID.MINING_MOTHERLODE_BRONZE, AnimationID.MINING_MOTHERLODE_IRON, AnimationID.MINING_MOTHERLODE_STEEL,
AnimationID.MINING_MOTHERLODE_BLACK, AnimationID.MINING_MOTHERLODE_MITHRIL, AnimationID.MINING_MOTHERLODE_ADAMANT,
AnimationID.MINING_MOTHERLODE_RUNE, AnimationID.MINING_MOTHERLODE_DRAGON, AnimationID.MINING_MOTHERLODE_DRAGON_UPGRADED,
AnimationID.MINING_MOTHERLODE_DRAGON_OR, AnimationID.MINING_MOTHERLODE_INFERNAL, AnimationID.MINING_MOTHERLODE_3A,
AnimationID.MINING_MOTHERLODE_CRYSTAL, AnimationID.MINING_MOTHERLODE_TRAILBLAZER,
6747, 6748, 6749, 6108, 6751, 6750, 6746, 8314, 7140, 643, 8349, 4483, 7284, 8350,
8888, // MINING_CRASHEDSTAR_DRAGON_OR_TRAILBLAZER
7201
);
// Forester's campfire animations for all log types
private static final Set<Integer> FIREMAKING_ANIMATION_IDS = Set.of(
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_GENERIC,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_ACHEY_TREE_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_ARCTIC_PINE_LOG,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_BLISTERWOOD_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_MAGIC_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_MAHOGANY_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_MAPLE_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_OAK_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_REDWOOD_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_TEAK_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_WILLOW_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_YEW_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_JATOBA_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_CAMPHOR_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_IRONWOOD_LOGS,
net.runelite.api.gameval.AnimationID.FORESTRY_CAMPFIRE_BURNING_ROSEWOOD_LOGS
);
private static final Set<Integer> SAILING_SALVAGING_ANIMATION_IDS = Set.of(
net.runelite.api.gameval.AnimationID.SAILING_HUMAN_SALVAGE_HOOK_KANDARIN_1X3_DROP01, // Salvaging is beginning
net.runelite.api.gameval.AnimationID.SAILING_HUMAN_SALVAGE_HOOK_KANDARIN_2X5_DROP01,
net.runelite.api.gameval.AnimationID.SAILING_HUMAN_SALVAGE_HOOK_KANDARIN_3X8_DROP01,
net.runelite.api.gameval.AnimationID.HUMAN_SAILING_SALVAGE01_LARGE01_DROP01,
net.runelite.api.gameval.AnimationID.SAILING_HUMAN_SALVAGE_HOOK_KANDARIN_1X3_IDLE01, // We are salvaging
net.runelite.api.gameval.AnimationID.SAILING_HUMAN_SALVAGE_HOOK_KANDARIN_2X5_IDLE01,
net.runelite.api.gameval.AnimationID.SAILING_HUMAN_SALVAGE_HOOK_KANDARIN_3X8_IDLE01,
net.runelite.api.gameval.AnimationID.HUMAN_SAILING_SALVAGE01_LARGE01_IDLE01,
net.runelite.api.gameval.AnimationID.SAILING_HUMAN_SALVAGE_HOOK_KANDARIN_1X3_INTERACT01, // Processing salvages
net.runelite.api.gameval.AnimationID.HUMAN_SAILING_SALVAGE01_LARGE01_INTERACT01
);
@Provides
DistractionReducerConfig provideConfig(ConfigManager configManager) {
return configManager.getConfig(DistractionReducerConfig.class);
}
@Override
protected void startUp() {
overlayManager.add(distractionReducerOverlay);
clientThread.invoke(this::updateOverlayVisibility);
updateTargetMonsterIds();
}
@Override
protected void shutDown() {
overlayManager.remove(distractionReducerOverlay);
}
@Subscribe
public void onConfigChanged(ConfigChanged configChanged) {
if ("distractionreducer".equals(configChanged.getGroup())) {
if ("monsterIds".equals(configChanged.getKey()) ||
"monsterNames".equals(configChanged.getKey()) ||
"enableCombatBlackout".equals(configChanged.getKey())) {
updateTargetMonsterIds();
}
}
}
@Subscribe
public void onGameStateChanged(GameStateChanged gameStateChanged) {
if (gameStateChanged.getGameState() == GameState.LOGGED_IN) {
clientThread.invoke(this::updateOverlayVisibility);
}
}
@Subscribe
public void onGameTick(GameTick event) {
Player player = client.getLocalPlayer();
if (player == null) return;
boolean currentlySkilling = isSkilling();
boolean currentlyCombating = isCombatingTargetMonster();
boolean isMoving = isPlayerMoving(player);
boolean shouldExitForInterface = shouldExitForInterface();
// Immediately clear overlay if moving or interface conditions are met
if (isMoving || shouldExitForInterface) {
wasSkilling = false;
wasCombating = false;
restoreDelayTicks = 0;
combatRestoreDelayTicks = 0;
// Set cooldown if interface auto-exit was triggered
if (shouldExitForInterface) {
interfaceExitCooldownTicks = 3;
}
distractionReducerOverlay.setRenderOverlay(false);
return;
}
// Decrement interface exit cooldown
if (interfaceExitCooldownTicks > 0) {
interfaceExitCooldownTicks--;
}
// Handle skilling logic
if (currentlySkilling) {
wasSkilling = true;
restoreDelayTicks = 0;
} else if (wasSkilling) {
restoreDelayTicks++;
if (restoreDelayTicks >= config.restoreDelay()) {
wasSkilling = false;
restoreDelayTicks = 0;
}
}
// Handle combat logic
if (currentlyCombating) {
wasCombating = true;
combatRestoreDelayTicks = 0;
} else if (wasCombating) {
combatRestoreDelayTicks++;
if (combatRestoreDelayTicks >= config.combatRestoreDelay()) {
wasCombating = false;
combatRestoreDelayTicks = 0;
}
}
updateOverlayVisibility();
}
private boolean isPlayerMoving(Player player) {
int poseAnimation = player.getPoseAnimation();
// Store the current position
if (lastPlayerPosition == null) {
lastPlayerPosition = player.getWorldLocation();
return false;
}
// Check if position changed since last tick
WorldPoint currentPosition = player.getWorldLocation();
boolean moved = !currentPosition.equals(lastPlayerPosition);
lastPlayerPosition = currentPosition;
return poseAnimation == WALKING_POSE ||
poseAnimation == RUNNING_POSE ||
TURNING_POSES.contains(poseAnimation) ||
moved;
}
// Add this field at the class level (with other private fields)
private WorldPoint lastPlayerPosition = null;
private void updateOverlayVisibility() {
Player player = client.getLocalPlayer();
if (player == null) return;
boolean isMoving = isPlayerMoving(player);
boolean shouldRenderFromSkilling = (isSkilling() || wasSkilling) && !isMoving;
boolean shouldRenderFromCombat = (isCombatingTargetMonster() || wasCombating) && !isMoving && !isHealthOrPrayerOverrideActive() && !isWildernessOverrideActive();
// Prevent overlay from showing during interface exit cooldown
boolean shouldRenderOverlay = (shouldRenderFromSkilling || shouldRenderFromCombat) && interfaceExitCooldownTicks == 0;
distractionReducerOverlay.setRenderOverlay(shouldRenderOverlay);
log.debug("Overlay visibility updated. Rendering: {}, Skilling: {}, Combat: {}, Is Moving: {}, HP/Prayer Override: {}, Wilderness Override: {}, Interface Cooldown: {}",
shouldRenderOverlay, shouldRenderFromSkilling, shouldRenderFromCombat, isMoving, isHealthOrPrayerOverrideActive(), isWildernessOverrideActive(), interfaceExitCooldownTicks);
}
private boolean isSkilling() {
Player player = client.getLocalPlayer();
if (player == null) return false;
int animation = player.getAnimation();
// Failsafe for Chambers of Xeric - only disable when actually inside the raid instance
// The IN_RAID varbit can be > 0 in the lobby/bank area, so we also check for instanced region
if (client.getVarbitValue(Varbits.IN_RAID) > 0 && client.isInInstancedRegion()) {
return false;
}
// Failsafe for The Gauntlet & The Corrupted Gauntlet
// Varbit 9178 is for being inside The Gauntlet
if (client.getVarbitValue(9178) > 0) {
return false;
}
// Failsafe for various regions
WorldPoint playerLocation = player.getWorldLocation();
// Check for Duke Sucellus (non-instanced)
if (playerLocation != null && playerLocation.getRegionID() == DUKE_SUCELLUS_REGION) {
return false;
}
// Check for POH (Player-Owned House) - disable overlay if not enabled in config
if (isInPOH() && !config.enableInPOH()) {
return false;
}
// Check for instanced regions (TOA and Duke Sucellus)
if (client.isInInstancedRegion()) {
WorldPoint instancePoint = WorldPoint.fromLocalInstance(client, player.getLocalLocation());
if (instancePoint != null) {
int regionID = instancePoint.getRegionID();
// TOA puzzle rooms
if (TOA_REGIONS.contains(regionID) && !isInToaBank()) {
return false;
}
// Duke Sucellus instanced area
if (regionID == DUKE_SUCELLUS_REGION) {
return false;
}
}
}
return (WOODCUTTING_ANIMATION_IDS.contains(animation) && config.woodcutting()) ||
(FISHING_ANIMATION_IDS.contains(animation) && config.fishing()) ||
(MINING_ANIMATION_IDS.contains(animation) && config.mining()) ||
(COOKING_ANIMATION_IDS.contains(animation) && config.cooking()) ||
(HERBLORE_ANIMATION_IDS.contains(animation) && config.herblore()) ||
(CRAFTING_ANIMATION_IDS.contains(animation) && config.crafting()) ||
(FLETCHING_ANIMATION_IDS.contains(animation) && config.fletching()) ||
(FIREMAKING_ANIMATION_IDS.contains(animation) && config.firemaking()) ||
(SAILING_SALVAGING_ANIMATION_IDS.contains(animation) && config.sailing()) ||
(isSmithing(animation) && config.smithing()) ||
(isMagic(animation) && config.magic());
}
private boolean isInToaBank() {
return client.getLocalPlayer().getWorldLocation().getRegionID() == TOA_LOBBY &&
client.getVarbitValue(Varbits.TOA_RAID_LEVEL) > 0; // Check if in an active raid
}
private boolean isInPOH() {
Player player = client.getLocalPlayer();
if (player == null) {
return false;
}
WorldPoint playerLocation = player.getWorldLocation();
if (playerLocation == null) {
return false;
}
int regionID = playerLocation.getRegionID();
// Check if player is in any POH region
if (POH_REGIONS.contains(regionID)) {
return true;
}
// Check for instanced POH (when visiting other players' houses)
if (client.isInInstancedRegion()) {
WorldPoint instancePoint = WorldPoint.fromLocalInstance(client, player.getLocalLocation());
if (instancePoint != null) {
int instanceRegionID = instancePoint.getRegionID();
return POH_REGIONS.contains(instanceRegionID);
}
}
return false;
}
private boolean isSmithing(int animation) {
if (SMITHING_ANIMATION_IDS.contains(animation)) {
return true;
}
if (animation == AnimationID.SMITHING_CANNONBALL) {
ItemContainer inventory = client.getItemContainer(InventoryID.INVENTORY);
if (inventory == null) {
return false;
}
return inventory.contains(ItemID.AMMO_MOULD) || inventory.contains(ItemID.DOUBLE_AMMO_MOULD);
}
return false;
}
private boolean isMagic(int animation) {
return PLANK_MAKE_ANIMATION_IDS.contains(animation) ||
isEnchantingJewelry(animation) ||
CHARGE_ORB_ANIMATION_IDS.contains(animation) ||
(BAKE_PIE_ANIMATION_IDS.contains(animation) && config.bakePie()) ||
(animation == STRING_JEWELRY_ANIMATION_ID && config.stringJewelry()) ||
(animation == PLANK_MAKE_ANIMATION_ID && config.plankMake());
}
private boolean isEnchantingJewelry(int animation) {
if (!ENCHANT_JEWELRY_ANIMATION_IDS.contains(animation)) {
return false;
}
// Check if the player is using the standard spellbook
return client.getVarbitValue(Varbits.SPELLBOOK) == 0;
}
private boolean isNPCContact() {
Player player = client.getLocalPlayer();
if (player == null) return false;
int animation = player.getAnimation();
if (animation != NPC_CONTACT_ANIMATION_ID) return false;
// Check if the player has the Lunar spellbook active
return client.getVarbitValue(Varbits.SPELLBOOK) == 2;
}
private boolean isInWilderness() {
Player player = client.getLocalPlayer();
if (player == null) return false;
WorldPoint location = player.getWorldLocation();
return location.isInArea2D(WILDERNESS_ABOVE_GROUND, WILDERNESS_UNDERGROUND);
}
private boolean isWildernessOverrideActive() {
// If in wilderness and wilderness is NOT enabled, then override (disable) combat blackout
return isInWilderness() && !config.enableWildernessOverride();
}
// Add this constant with the other animation ID constants
private static final int NPC_CONTACT_ANIMATION_ID = 4413;
private static final int STRING_JEWELRY_ANIMATION_ID = 4412;
private static final int PLANK_MAKE_ANIMATION_ID = 6298;
// Add this constant for the standard spellbook ID
private static final int STANDARD_SPELLBOOK_ID = 0;
// Wilderness area constants for robust detection (from NPC Aggro Area plugin)
private static final WorldArea WILDERNESS_ABOVE_GROUND = new WorldArea(2944, 3523, 448, 448, 0);
private static final WorldArea WILDERNESS_UNDERGROUND = new WorldArea(2944, 9918, 320, 442, 0);
private void updateTargetMonsterIds() {
targetMonsterIds.clear();
targetMonsterNames.clear();
if (config.enableCombatBlackout()) {
// Parse monster IDs
if (!config.monsterIds().trim().isEmpty()) {
String[] ids = config.monsterIds().split(",");
for (String id : ids) {
try {
targetMonsterIds.add(Integer.parseInt(id.trim()));
} catch (NumberFormatException e) {
log.warn("Invalid monster ID: {}", id.trim());
}
}
}
// Parse monster names
if (!config.monsterNames().trim().isEmpty()) {
String[] names = config.monsterNames().split(",");
for (String name : names) {
targetMonsterNames.add(name.trim().toLowerCase());
}
}
}
log.debug("Updated target monster IDs: {}", targetMonsterIds);
log.debug("Updated target monster names: {}", targetMonsterNames);
}
private boolean isCombatingTargetMonster() {
if (!config.enableCombatBlackout() || (targetMonsterIds.isEmpty() && targetMonsterNames.isEmpty())) {
return false;
}
Player player = client.getLocalPlayer();
if (player == null) {
return false;
}
Actor interacting = player.getInteracting();
if (!(interacting instanceof NPC)) {
return false;
}
NPC npc = (NPC) interacting;
int npcId = npc.getId();
String npcName = npc.getName();
// Check by ID
boolean isTargetById = targetMonsterIds.contains(npcId);
// Check by name
boolean isTargetByName = false;
if (npcName != null && !targetMonsterNames.isEmpty()) {
isTargetByName = targetMonsterNames.contains(npcName.toLowerCase());
}
boolean isTargetMonster = isTargetById || isTargetByName;
if (isTargetMonster) {
if (isTargetById) {
log.debug("Player is combating target monster with ID: {}", npcId);
}
if (isTargetByName) {
log.debug("Player is combating target monster with name: {}", npcName);
}
}
return isTargetMonster;
}
private boolean isHealthOrPrayerOverrideActive() {
if (!config.enableCombatBlackout()) {
return false;
}
// Check health override
if (config.enableHealthOverride()) {
int currentHp = client.getBoostedSkillLevel(Skill.HITPOINTS);
if (currentHp <= config.healthThreshold()) {
log.debug("Health override active: {} HP <= {} HP", currentHp, config.healthThreshold());
return true;
}
}
// Check prayer override
if (config.enablePrayerOverride()) {
int currentPrayer = client.getBoostedSkillLevel(Skill.PRAYER);
if (currentPrayer <= config.prayerThreshold()) {
log.debug("Prayer override active: {} Prayer <= {} Prayer", currentPrayer, config.prayerThreshold());
return true;
}
}
return false;
}
private boolean shouldExitForInterface() {
// Check if bank interface is open
if (isBankInterfaceOpen()) {
log.debug("Bank interface detected, exiting overlay");
return true;
}
// Check if Grand Exchange interface is open
if (isGrandExchangeInterfaceOpen()) {
log.debug("Grand Exchange interface detected, exiting overlay");
return true;
}
return false;
}
private boolean isBankInterfaceOpen() {
// Check for various bank interface widget IDs
// Bank interface widget ID is 12 (main bank interface)
Widget bankWidget = client.getWidget(12, 0);
if (bankWidget != null && !bankWidget.isHidden()) {
return true;
}
// Check for deposit box interface (widget ID 192)
Widget depositBoxWidget = client.getWidget(192, 0);
if (depositBoxWidget != null && !depositBoxWidget.isHidden()) {
return true;
}
// Check for bank pin interface (widget ID 213)
Widget bankPinWidget = client.getWidget(213, 0);
if (bankPinWidget != null && !bankPinWidget.isHidden()) {
return true;
}
return false;
}
private boolean isGrandExchangeInterfaceOpen() {
// Grand Exchange interface widget ID is 465
Widget geWidget = client.getWidget(465, 0);
if (geWidget != null && !geWidget.isHidden()) {
return true;
}
// Check for Grand Exchange collection box (widget ID 402)
Widget geCollectionWidget = client.getWidget(402, 0);
if (geCollectionWidget != null && !geCollectionWidget.isHidden()) {
return true;
}
return false;
}
}