blackjack: Swap blackjack back to priority system.

This commit is contained in:
Ganom
2019-08-04 20:56:47 -04:00
parent 769ed02ba4
commit 6f8fd0ecd0
2 changed files with 67 additions and 38 deletions

View File

@@ -32,12 +32,25 @@ import net.runelite.client.config.ConfigItem;
public interface BlackjackConfig extends Config
{
@ConfigItem(
keyName = "pickpocketOnAggro",
name = "Pickpocket when aggro\'d",
description = "Switches to \"Pickpocket\" when bandit is aggro\'d. Saves food at the cost of slight xp/h."
keyName = "pickpocketOnAggro",
name = "Pickpocket when aggro\'d",
description = "Switches to \"Pickpocket\" when bandit is aggro\'d. Saves food at the cost of slight xp/h.",
position = 0
)
default boolean pickpocketOnAggro()
{
return false;
}
@ConfigItem(
keyName = "random",
name = "Randomly Miss 1 Pickpocket",
description = "If enabled, this will randomly miss 1 pickpocket every so often." +
"<br> Not sure why'd you want to do that, but you can.",
position = 1
)
default boolean random()
{
return false;
}
}

View File

@@ -33,28 +33,28 @@ import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.Varbits;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginType;
import net.runelite.client.util.MenuUtil;
import net.runelite.client.util.Text;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RandomUtils;
/**
* Authors gazivodag longstreet
*/
@PluginDescriptor(
name = "Blackjack",
description = "Allows for one-click blackjacking, both knocking out and pickpocketing",
tags = {"blackjack", "thieving"},
type = PluginType.SKILLING,
enabledByDefault = false
name = "Blackjack",
description = "Allows for one-click blackjacking, both knocking out and pickpocketing",
tags = {"blackjack", "thieving"},
type = PluginType.SKILLING,
enabledByDefault = false
)
@Singleton
@Slf4j
@@ -63,15 +63,21 @@ public class BlackjackPlugin extends Plugin
private static final String SUCCESS_BLACKJACK = "You smack the bandit over the head and render them unconscious.";
private static final String FAILED_BLACKJACK = "Your blow only glances off the bandit's head.";
private static final int POLLNIVNEACH_REGION = 13358;
private long nextKnockOutTick = 0;
private static final String PICKPOCKET = "Pickpocket";
private static final String KNOCK_OUT = "Knock-out";
private static final String BANDIT = "Bandit";
private static final String MENAPHITE = "Menaphite Thug";
@Inject
private Client client;
@Inject
private BlackjackConfig config;
@Inject
private EventBus eventBus;
@Inject
private MenuManager menuManager;
private boolean pickpocketOnAggro;
private boolean random;
private long nextKnockOutTick = 0;
@Provides
BlackjackConfig getConfig(ConfigManager configManager)
@@ -82,22 +88,34 @@ public class BlackjackPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
addSubscriptions();
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged);
menuManager.addPriorityEntry(KNOCK_OUT, BANDIT).setPriority(100);
menuManager.addPriorityEntry(KNOCK_OUT, MENAPHITE).setPriority(100);
this.pickpocketOnAggro = config.pickpocketOnAggro();
}
@Override
protected void shutDown() throws Exception
{
menuManager.removePriorityEntry(PICKPOCKET, BANDIT);
menuManager.removePriorityEntry(PICKPOCKET, MENAPHITE);
menuManager.removePriorityEntry(KNOCK_OUT, BANDIT);
menuManager.removePriorityEntry(KNOCK_OUT, MENAPHITE);
eventBus.unregister(this);
eventBus.unregister("poll");
}
private void addSubscriptions()
private void onGameStateChanged(GameStateChanged event)
{
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
eventBus.subscribe(MenuEntryAdded.class, this, this::onMenuEntryAdded);
eventBus.subscribe(ChatMessage.class, this, this::onChatMessage);
if (event.getGameState() != GameState.LOGGED_IN || !ArrayUtils.contains(client.getMapRegions(), POLLNIVNEACH_REGION))
{
eventBus.unregister("poll");
return;
}
eventBus.subscribe(GameTick.class, "poll", this::onGameTick);
eventBus.subscribe(ChatMessage.class, "poll", this::onChatMessage);
}
private void onConfigChanged(ConfigChanged event)
@@ -105,35 +123,33 @@ public class BlackjackPlugin extends Plugin
if (event.getGroup().equals("blackjack"))
{
this.pickpocketOnAggro = config.pickpocketOnAggro();
this.random = config.random();
}
}
private void onMenuEntryAdded(MenuEntryAdded event)
private void onGameTick(GameTick event)
{
if (client.getGameState() != GameState.LOGGED_IN ||
client.getVar(Varbits.QUEST_THE_FEUD) < 13 ||
client.getLocalPlayer().getWorldLocation().getRegionID() != POLLNIVNEACH_REGION)
if (client.getTickCount() >= nextKnockOutTick)
{
return;
}
String option = Text.removeTags(event.getOption().toLowerCase());
String target = Text.removeTags(event.getTarget().toLowerCase());
if (nextKnockOutTick >= client.getTickCount())
{
MenuUtil.swap(client, "pickpocket", option, target);
}
else
{
MenuUtil.swap(client, "knock-out", option, target);
menuManager.removePriorityEntry(PICKPOCKET, BANDIT);
menuManager.removePriorityEntry(PICKPOCKET, MENAPHITE);
menuManager.addPriorityEntry(KNOCK_OUT, BANDIT).setPriority(100);
menuManager.addPriorityEntry(KNOCK_OUT, MENAPHITE).setPriority(100);
}
}
private void onChatMessage(ChatMessage event)
{
if (event.getType() == ChatMessageType.SPAM && event.getMessage().equals(SUCCESS_BLACKJACK) ^ (event.getMessage().equals(FAILED_BLACKJACK) && this.pickpocketOnAggro))
final String msg = event.getMessage();
if (event.getType() == ChatMessageType.SPAM && msg.equals(SUCCESS_BLACKJACK) ^ (msg.equals(FAILED_BLACKJACK) && this.pickpocketOnAggro))
{
nextKnockOutTick = client.getTickCount() + RandomUtils.nextInt(3, 4);
menuManager.removePriorityEntry(KNOCK_OUT, BANDIT);
menuManager.removePriorityEntry(KNOCK_OUT, MENAPHITE);
menuManager.addPriorityEntry(PICKPOCKET, BANDIT).setPriority(100);
menuManager.addPriorityEntry(PICKPOCKET, MENAPHITE).setPriority(100);
final int ticks = this.random ? RandomUtils.nextInt(3, 4) : 4;
nextKnockOutTick = client.getTickCount() + ticks;
}
}
}