Updates and rework to use CScript

This commit is contained in:
2022-01-19 12:35:50 +01:00
parent 78786709eb
commit 7efda7494a
79 changed files with 1295 additions and 818 deletions

View File

@ -26,7 +26,7 @@
version = "1.1.0"
project.extra["PluginName"] = "Chaos Prayer Flicking" // This is the name that is used in the external plugin manager panel
project.extra["PluginDescription"] = "Flicks prayer" // This is the description that is used in the external plugin manager panel
project.extra["PluginDescription"] = "Infinite power!" // This is the description that is used in the external plugin manager panel
dependencies {
compileOnly(project(":util"))

View File

@ -28,19 +28,20 @@ import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Keybind;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
@ConfigGroup("ChaosPrayerflickConfig")
@ConfigGroup("chaosprayerflicking")
public interface Config extends net.runelite.client.config.Config {
@ConfigItem(
keyName = "hotkey",
keyName = "prayerFlickHotkey",
name = "Flick hotkey",
description = "When you press this key prayer flicking will start",
position = 0
)
default Keybind hotkey() {
return new Keybind(KeyEvent.VK_BACK_SLASH, 0);
default Keybind prayerFlickHotkey() {
return new Keybind(KeyEvent.VK_BACK_QUOTE, 0);
}
@ConfigItem(
@ -60,7 +61,7 @@ public interface Config extends net.runelite.client.config.Config {
position = 20
)
default Keybind hotkeyMelee() {
return new Keybind(KeyEvent.VK_1, 0);
return new Keybind(KeyEvent.VK_1, InputEvent.CTRL_DOWN_MASK);
}
@ConfigItem(
@ -70,7 +71,7 @@ public interface Config extends net.runelite.client.config.Config {
position = 21
)
default Keybind hotkeyMissiles() {
return new Keybind(KeyEvent.VK_2, 0);
return new Keybind(KeyEvent.VK_2, InputEvent.CTRL_DOWN_MASK);
}
@ConfigItem(
@ -80,7 +81,7 @@ public interface Config extends net.runelite.client.config.Config {
position = 22
)
default Keybind hotkeyMagic() {
return new Keybind(KeyEvent.VK_3, 0);
return new Keybind(KeyEvent.VK_3, InputEvent.CTRL_DOWN_MASK);
}
@ConfigItem(
@ -90,4 +91,76 @@ public interface Config extends net.runelite.client.config.Config {
position = 23
)
default boolean openInventory() { return true; }
@ConfigItem(
keyName = "allowToggleOff",
name = "Allow toggling off",
description = "Will allow turning the protect prayer off when pressing the hotkey for the current one.",
position = 24
)
default boolean allowToggleOff() { return true; }
@ConfigItem(
keyName = "jadPrayerFlick",
name = "Jad Auto Prayer Flick",
description = "Automatically swap prayers against Jad.",
position = 30
)
default boolean jadPrayerFlick() { return true; }
@ConfigItem(
keyName = "hesporiPrayerFlick",
name = "Hespori Auto Prayer Flick",
description = "Automatically swap prayers against Hespori.",
position = 31
)
default boolean hesporiPrayerFlick() { return true; }
@ConfigItem(
keyName = "showDebugOptions",
name = "Show debug options",
description = "Show debug options. Probably shouldn't touch these.",
position = 90
)
default boolean showDebugOptions() { return false; }
@ConfigItem(
keyName = "onDelayMin",
name = "On delay minimum",
description = "Minimum wait time for toggling on quickprayers.",
hidden = true,
unhide = "showDebugOptions",
position = 91
)
default int onDelayMin() { return 5; }
@ConfigItem(
keyName = "onDelayMax",
name = "On delay maximum",
description = "Maximum wait time for toggling on quickprayers.",
hidden = true,
unhide = "showDebugOptions",
position = 92
)
default int onDelayMax() { return 10; }
@ConfigItem(
keyName = "offDelayMin",
name = "Off delay minimum",
description = "Minimum wait time for toggling off quickprayers.",
hidden = true,
unhide = "showDebugOptions",
position = 93
)
default int offDelayMin() { return 70; }
@ConfigItem(
keyName = "offDelayMax",
name = "Off delay maximum",
description = "Maximum wait time for toggling off quickprayers.",
hidden = true,
unhide = "showDebugOptions",
position = 94
)
default int offDelayMax() { return 80; }
}

View File

@ -4,11 +4,10 @@ import com.google.inject.Provides;
import io.reisub.openosrs.util.Calculations;
import io.reisub.openosrs.util.Util;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.MenuAction;
import net.runelite.api.*;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.widgets.Widget;
import net.runelite.api.events.VarbitChanged;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
@ -34,7 +33,7 @@ import java.util.concurrent.TimeUnit;
@PluginDependency(iUtils.class)
@PluginDescriptor(
name = "Chaos Prayer Flicking",
description = "",
description = "Infinite power!",
enabledByDefault = false
)
@Slf4j
@ -62,10 +61,16 @@ public class Prayerflick extends Plugin implements KeyListener {
return configManager.getConfig(Config.class);
}
private final int JALTOK_JAD_MAGE_ATTACK = 7592;
private final int JALTOK_JAD_RANGE_ATTACK = 7593;
private final int HESPORI_MAGE_ATTACK = 8223;
private final int HESPORI_RANGE_ATTACK = 8224;
private ScheduledExecutorService executor;
private boolean toggleFlicking;
private boolean firstFlick;
private boolean toggledOff;
private volatile ProtectFrom currently;
@Override
protected void startUp() {
@ -94,19 +99,51 @@ public class Prayerflick extends Plugin implements KeyListener {
boolean active = quickPrayers.actions().get(0).equals("Deactivate");
if (!active && !firstFlick) {
toggle(calc.random(1, 15), quickPrayers);
toggle(calc.random(config.onDelayMin(), config.onDelayMax()), quickPrayers);
return;
}
toggle(calc.random(1, 9), quickPrayers);
toggle(calc.random(90, 100), quickPrayers);
toggle(calc.random(config.onDelayMin(), config.offDelayMax()), quickPrayers);
toggle(calc.random(config.offDelayMin(), config.offDelayMax()), quickPrayers);
if (firstFlick) {
firstFlick = false;
}
} else if (!toggleFlicking && toggledOff && config.deactivateAfterStopping()) {
toggledOff = false;
toggle(calc.random(90, 110), quickPrayers);
toggle(calc.random(config.offDelayMin() + 10, config.offDelayMax() + 10), quickPrayers);
}
}
@Subscribe
private void onAnimationChanged(AnimationChanged event) {
Actor actor = event.getActor();
if (actor == null) return;
if (config.jadPrayerFlick()) {
switch (actor.getAnimation()) {
case AnimationID.TZTOK_JAD_MAGIC_ATTACK:
case JALTOK_JAD_MAGE_ATTACK:
setPrayer(ProtectFrom.MAGIC, false);
game.utils.sendGameMessage("Pray against magic!");
break;
case AnimationID.TZTOK_JAD_RANGE_ATTACK:
case JALTOK_JAD_RANGE_ATTACK:
setPrayer(ProtectFrom.MISSILES, false);
game.utils.sendGameMessage("Pray against missiles!");
break;
}
}
if (config.hesporiPrayerFlick()) {
switch (actor.getAnimation()) {
case HESPORI_MAGE_ATTACK:
setPrayer(ProtectFrom.MAGIC, false);
break;
case HESPORI_RANGE_ATTACK:
setPrayer(ProtectFrom.MISSILES, false);
break;
}
}
}
@ -121,7 +158,7 @@ public class Prayerflick extends Plugin implements KeyListener {
@Override
public void keyPressed(KeyEvent e) {
if (config.hotkey().matches(e)) {
if (config.prayerFlickHotkey().matches(e)) {
if (toggleFlicking) {
toggledOff = true;
} else {
@ -130,18 +167,26 @@ public class Prayerflick extends Plugin implements KeyListener {
toggleFlicking = !toggleFlicking;
} else if (config.hotkeyMelee().matches(e)) {
setPrayer(14);
setPrayer(ProtectFrom.MELEE, config.allowToggleOff());
} else if (config.hotkeyMissiles().matches(e)) {
setPrayer(13);
setPrayer(ProtectFrom.MISSILES, config.allowToggleOff());
} else if (config.hotkeyMagic().matches(e)) {
setPrayer(12);
setPrayer(ProtectFrom.MAGIC, config.allowToggleOff());
}
}
@Override
public void keyReleased(KeyEvent e) {}
private void setPrayer(int childId) {
private void setPrayer(ProtectFrom protectFrom, boolean allowToggleOff) {
if (!allowToggleOff && protectFrom == currently) return;
if (currently == protectFrom) {
currently = ProtectFrom.NONE;
} else {
currently = protectFrom;
}
executor.schedule(() -> {
iWidget quickPrayers = game.widget(WidgetInfo.MINIMAP_QUICK_PRAYER_ORB);
if (quickPrayers == null) return;
@ -152,7 +197,7 @@ public class Prayerflick extends Plugin implements KeyListener {
return w != null && !w.hidden();
});
iWidget protection = game.widget(77, 4, childId);
iWidget protection = game.widget(77, 4, protectFrom.getChildId());
if (protection == null) return;
protection.interact(0);

View File

@ -0,0 +1,15 @@
package io.reisub.openosrs.prayerflick;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public enum ProtectFrom {
NONE(0),
MAGIC(12),
MISSILES(13),
MELEE(14);
private final int childId;
}