blackjack: Swap blackjack back to priority system. (#1265)

blackjack: Swap blackjack back to priority system.
This commit is contained in:
Owain van Brakel
2019-08-05 19:32:58 +02:00
committed by GitHub
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 public interface BlackjackConfig extends Config
{ {
@ConfigItem( @ConfigItem(
keyName = "pickpocketOnAggro", keyName = "pickpocketOnAggro",
name = "Pickpocket when aggro\'d", name = "Pickpocket when aggro\'d",
description = "Switches to \"Pickpocket\" when bandit is aggro\'d. Saves food at the cost of slight xp/h." description = "Switches to \"Pickpocket\" when bandit is aggro\'d. Saves food at the cost of slight xp/h.",
position = 0
) )
default boolean pickpocketOnAggro() default boolean pickpocketOnAggro()
{ {
return false; 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.ChatMessageType;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.GameState; import net.runelite.api.GameState;
import net.runelite.api.Varbits;
import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigChanged; 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.config.ConfigManager;
import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.EventBus;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginType; import net.runelite.client.plugins.PluginType;
import net.runelite.client.util.MenuUtil; import org.apache.commons.lang3.ArrayUtils;
import net.runelite.client.util.Text;
import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.RandomUtils;
/** /**
* Authors gazivodag longstreet * Authors gazivodag longstreet
*/ */
@PluginDescriptor( @PluginDescriptor(
name = "Blackjack", name = "Blackjack",
description = "Allows for one-click blackjacking, both knocking out and pickpocketing", description = "Allows for one-click blackjacking, both knocking out and pickpocketing",
tags = {"blackjack", "thieving"}, tags = {"blackjack", "thieving"},
type = PluginType.SKILLING, type = PluginType.SKILLING,
enabledByDefault = false enabledByDefault = false
) )
@Singleton @Singleton
@Slf4j @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 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 String FAILED_BLACKJACK = "Your blow only glances off the bandit's head.";
private static final int POLLNIVNEACH_REGION = 13358; 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 @Inject
private Client client; private Client client;
@Inject @Inject
private BlackjackConfig config; private BlackjackConfig config;
@Inject @Inject
private EventBus eventBus; private EventBus eventBus;
@Inject
private MenuManager menuManager;
private boolean pickpocketOnAggro; private boolean pickpocketOnAggro;
private boolean random;
private long nextKnockOutTick = 0;
@Provides @Provides
BlackjackConfig getConfig(ConfigManager configManager) BlackjackConfig getConfig(ConfigManager configManager)
@@ -82,22 +88,34 @@ public class BlackjackPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception 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(); this.pickpocketOnAggro = config.pickpocketOnAggro();
} }
@Override @Override
protected void shutDown() throws Exception 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(this);
eventBus.unregister("poll");
} }
private void addSubscriptions() private void onGameStateChanged(GameStateChanged event)
{ {
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged); if (event.getGameState() != GameState.LOGGED_IN || !ArrayUtils.contains(client.getMapRegions(), POLLNIVNEACH_REGION))
eventBus.subscribe(MenuEntryAdded.class, this, this::onMenuEntryAdded); {
eventBus.subscribe(ChatMessage.class, this, this::onChatMessage); eventBus.unregister("poll");
return;
}
eventBus.subscribe(GameTick.class, "poll", this::onGameTick);
eventBus.subscribe(ChatMessage.class, "poll", this::onChatMessage);
} }
private void onConfigChanged(ConfigChanged event) private void onConfigChanged(ConfigChanged event)
@@ -105,35 +123,33 @@ public class BlackjackPlugin extends Plugin
if (event.getGroup().equals("blackjack")) if (event.getGroup().equals("blackjack"))
{ {
this.pickpocketOnAggro = config.pickpocketOnAggro(); this.pickpocketOnAggro = config.pickpocketOnAggro();
this.random = config.random();
} }
} }
private void onMenuEntryAdded(MenuEntryAdded event) private void onGameTick(GameTick event)
{ {
if (client.getGameState() != GameState.LOGGED_IN || if (client.getTickCount() >= nextKnockOutTick)
client.getVar(Varbits.QUEST_THE_FEUD) < 13 ||
client.getLocalPlayer().getWorldLocation().getRegionID() != POLLNIVNEACH_REGION)
{ {
return; menuManager.removePriorityEntry(PICKPOCKET, BANDIT);
} menuManager.removePriorityEntry(PICKPOCKET, MENAPHITE);
menuManager.addPriorityEntry(KNOCK_OUT, BANDIT).setPriority(100);
String option = Text.removeTags(event.getOption().toLowerCase()); menuManager.addPriorityEntry(KNOCK_OUT, MENAPHITE).setPriority(100);
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);
} }
} }
private void onChatMessage(ChatMessage event) 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;
} }
} }
} }