corp plugin: deprioritize attack option on dark energy core

This commit is contained in:
Adam
2018-08-17 22:07:09 -04:00
parent 510a5c8568
commit 1fb5365e7c
3 changed files with 89 additions and 0 deletions

View File

@@ -269,6 +269,8 @@ public enum MenuAction
*/
UNKNOWN(-1);
public static final int MENU_ACTION_DEPRIORITIZE_OFFSET = 2000;
private static final Map<Integer, MenuAction> map = new HashMap<>();
static

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.corp;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("corp")
public interface CorpConfig extends Config
{
@ConfigItem(
keyName = "leftClickCore",
name = "Left click walk on core",
description = "Prioritizes Walk here over Attack on the Dark energey core",
position = 1
)
default boolean leftClickCore()
{
return true;
}
}

View File

@@ -25,6 +25,7 @@
package net.runelite.client.plugins.corp;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.util.HashSet;
import java.util.Set;
import javax.inject.Inject;
@@ -34,18 +35,23 @@ import net.runelite.api.Actor;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.MenuAction;
import static net.runelite.api.MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
import net.runelite.api.MenuEntry;
import net.runelite.api.NPC;
import net.runelite.api.NpcID;
import net.runelite.api.Varbits;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.HitsplatApplied;
import net.runelite.api.events.InteractingChanged;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
import net.runelite.client.chat.ChatColorType;
import net.runelite.client.chat.ChatMessageBuilder;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.chat.QueuedMessage;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
@@ -57,6 +63,10 @@ import net.runelite.client.ui.overlay.OverlayManager;
)
public class CorpPlugin extends Plugin
{
private static final int NPC_SECTION_ACTION = MenuAction.NPC_SECOND_OPTION.getId();
private static final String ATTACK = "Attack";
private static final String DARK_ENERGY_CORE = "Dark energy core";
@Getter(AccessLevel.PACKAGE)
private NPC corp;
@@ -86,6 +96,15 @@ public class CorpPlugin extends Plugin
@Inject
private CoreOverlay coreOverlay;
@Inject
private CorpConfig config;
@Provides
CorpConfig getConfig(ConfigManager configManager)
{
return configManager.getConfig(CorpConfig.class);
}
@Override
protected void startUp() throws Exception
{
@@ -202,4 +221,28 @@ public class CorpPlugin extends Plugin
players.add(source);
}
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded)
{
if (menuEntryAdded.getType() != NPC_SECTION_ACTION
|| !config.leftClickCore() || !menuEntryAdded.getOption().equals(ATTACK))
{
return;
}
final int npcIndex = menuEntryAdded.getIdentifier();
final NPC npc = client.getCachedNPCs()[npcIndex];
if (npc == null || !npc.getName().equals(DARK_ENERGY_CORE))
{
return;
}
// since this is the menu entry add event, this is the last menu entry
MenuEntry[] menuEntries = client.getMenuEntries();
MenuEntry menuEntry = menuEntries[menuEntries.length - 1];
menuEntry.setType(NPC_SECTION_ACTION + MENU_ACTION_DEPRIORITIZE_OFFSET);
client.setMenuEntries(menuEntries);
}
}