Fix ending on 1 kc and new task dialog spanning multiple ticks
This commit is contained in:
@@ -40,6 +40,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import joptsimple.internal.Strings;
|
import joptsimple.internal.Strings;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -75,6 +76,7 @@ import net.runelite.client.config.ConfigManager;
|
|||||||
import net.runelite.client.eventbus.EventBus;
|
import net.runelite.client.eventbus.EventBus;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.events.ChatInput;
|
import net.runelite.client.events.ChatInput;
|
||||||
|
import net.runelite.client.game.AsyncBufferedImage;
|
||||||
import net.runelite.client.game.ItemManager;
|
import net.runelite.client.game.ItemManager;
|
||||||
import net.runelite.client.game.SpriteManager;
|
import net.runelite.client.game.SpriteManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
@@ -331,11 +333,19 @@ public class SlayerPlugin extends Plugin
|
|||||||
highlightedTargets.remove(npc);
|
highlightedTargets.remove(npc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// b/c dialog can stay up on screen for multiple ticks in a row we want to make sure we only set a task once
|
||||||
|
// for the dialog that appears so we need to basically do a rising edge detection that only allows for a dialog
|
||||||
|
// check to be performed if in the previous ticks there was a period of no dialog
|
||||||
|
// i.e. once a dialog has been matched dialog cannot be matched again until npc dialog goes away for a tick
|
||||||
|
// this will work because in order for a new slayer task to happen the player either has to go complete the assignment
|
||||||
|
// (and close npc dialog) or go into the rewards screen which also closes npc dialog
|
||||||
|
private boolean canMatchDialog = true;
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameTick(GameTick tick)
|
public void onGameTick(GameTick tick)
|
||||||
{
|
{
|
||||||
Widget npcDialog = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
|
Widget npcDialog = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
|
||||||
if (npcDialog != null)
|
if (npcDialog != null && canMatchDialog)
|
||||||
{
|
{
|
||||||
String npcText = Text.sanitizeMultilineText(npcDialog.getText()); //remove color and linebreaks
|
String npcText = Text.sanitizeMultilineText(npcDialog.getText()); //remove color and linebreaks
|
||||||
final Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(npcText); // amount, name, (location)
|
final Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(npcText); // amount, name, (location)
|
||||||
@@ -349,17 +359,20 @@ public class SlayerPlugin extends Plugin
|
|||||||
int amount = Integer.parseInt(mAssign.group("amount"));
|
int amount = Integer.parseInt(mAssign.group("amount"));
|
||||||
String location = mAssign.group("location");
|
String location = mAssign.group("location");
|
||||||
setTask(name, amount, amount, true, location);
|
setTask(name, amount, amount, true, location);
|
||||||
|
canMatchDialog = false;
|
||||||
}
|
}
|
||||||
else if (mAssignFirst.find())
|
else if (mAssignFirst.find())
|
||||||
{
|
{
|
||||||
int amount = Integer.parseInt(mAssignFirst.group(2));
|
int amount = Integer.parseInt(mAssignFirst.group(2));
|
||||||
setTask(mAssignFirst.group(1), amount, amount, true);
|
setTask(mAssignFirst.group(1), amount, amount, true);
|
||||||
|
canMatchDialog = false;
|
||||||
}
|
}
|
||||||
else if (mAssignBoss.find())
|
else if (mAssignBoss.find())
|
||||||
{
|
{
|
||||||
int amount = Integer.parseInt(mAssignBoss.group(2));
|
int amount = Integer.parseInt(mAssignBoss.group(2));
|
||||||
setTask(mAssignBoss.group(1), amount, amount, true);
|
setTask(mAssignBoss.group(1), amount, amount, true);
|
||||||
points = Integer.parseInt(mAssignBoss.group(3).replaceAll(",", ""));
|
points = Integer.parseInt(mAssignBoss.group(3).replaceAll(",", ""));
|
||||||
|
canMatchDialog = false;
|
||||||
}
|
}
|
||||||
else if (mCurrent.find())
|
else if (mCurrent.find())
|
||||||
{
|
{
|
||||||
@@ -367,7 +380,10 @@ public class SlayerPlugin extends Plugin
|
|||||||
int amount = Integer.parseInt(mCurrent.group("amount"));
|
int amount = Integer.parseInt(mCurrent.group("amount"));
|
||||||
String location = mCurrent.group("location");
|
String location = mCurrent.group("location");
|
||||||
setTask(name, amount, currentTask.getInitialAmount(), false, location);
|
setTask(name, amount, currentTask.getInitialAmount(), false, location);
|
||||||
|
canMatchDialog = false;
|
||||||
}
|
}
|
||||||
|
} else if (npcDialog == null) {
|
||||||
|
canMatchDialog = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget braceletBreakWidget = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT);
|
Widget braceletBreakWidget = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT);
|
||||||
@@ -703,16 +719,14 @@ public class SlayerPlugin extends Plugin
|
|||||||
rebuildTargetList();
|
rebuildTargetList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage getImageForTask(Task task)
|
public AsyncBufferedImage getImageForTask(Task task)
|
||||||
{
|
{
|
||||||
int itemSpriteId = ItemID.ENCHANTED_GEM;
|
int itemSpriteId = ItemID.ENCHANTED_GEM;
|
||||||
if (task != null)
|
if (task != null)
|
||||||
{
|
{
|
||||||
itemSpriteId = task.getItemSpriteId();
|
itemSpriteId = task.getItemSpriteId();
|
||||||
}
|
}
|
||||||
|
return itemManager.getImage(itemSpriteId);
|
||||||
BufferedImage taskImg = itemManager.getImage(itemSpriteId);
|
|
||||||
return taskImg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCounter()
|
private void addCounter()
|
||||||
@@ -723,7 +737,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
Task task = Task.getTask(currentTask.getTaskName());
|
Task task = Task.getTask(currentTask.getTaskName());
|
||||||
BufferedImage taskImg = getImageForTask(task);
|
AsyncBufferedImage taskImg = getImageForTask(task);
|
||||||
String taskTooltip = ColorUtil.wrapWithColorTag("%s", new Color(255, 119, 0)) + "</br>";
|
String taskTooltip = ColorUtil.wrapWithColorTag("%s", new Color(255, 119, 0)) + "</br>";
|
||||||
|
|
||||||
if (currentTask.getTaskLocation() != null && !currentTask.getTaskLocation().isEmpty())
|
if (currentTask.getTaskLocation() != null && !currentTask.getTaskLocation().isEmpty())
|
||||||
|
|||||||
@@ -265,6 +265,11 @@ public class SlayerTaskPanel extends PluginPanel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TaskBox current = tasks.get(0);
|
TaskBox current = tasks.get(0);
|
||||||
|
// current task has ended even though it should still have 1 amount remaining b/c the ending chat message
|
||||||
|
// pops before the slayer xp drop so we need to force the remaining kc to zero and add the last kc to
|
||||||
|
// the elapsed kc
|
||||||
|
current.getTaskData().setAmount(0);
|
||||||
|
current.getTaskData().setElapsedKills(current.getTaskData().getElapsedKills() + 1);
|
||||||
// current task has ended so it should be paused
|
// current task has ended so it should be paused
|
||||||
current.update(true, true, current.getTaskData());
|
current.update(true, true, current.getTaskData());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import javax.swing.SwingUtilities;
|
|||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.runelite.client.game.AsyncBufferedImage;
|
||||||
import net.runelite.client.ui.ColorScheme;
|
import net.runelite.client.ui.ColorScheme;
|
||||||
import net.runelite.client.ui.DynamicGridLayout;
|
import net.runelite.client.ui.DynamicGridLayout;
|
||||||
import net.runelite.client.ui.FontManager;
|
import net.runelite.client.ui.FontManager;
|
||||||
@@ -77,35 +78,40 @@ public class TaskBox extends JPanel
|
|||||||
container.setLayout(new BorderLayout());
|
container.setLayout(new BorderLayout());
|
||||||
container.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
container.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
|
|
||||||
BufferedImage taskImg = slayerPlugin.getImageForTask(Task.getTask(taskData.getTaskName()));
|
SwingUtilities.invokeLater(() -> {
|
||||||
JLabel taskIcon = new JLabel(new ImageIcon(taskImg));
|
BufferedImage taskImg = slayerPlugin.getImageForTask(Task.getTask(taskData.getTaskName()));
|
||||||
taskIcon.setHorizontalAlignment(SwingConstants.CENTER);
|
JLabel taskIcon = new JLabel(new ImageIcon(taskImg));
|
||||||
taskIcon.setVerticalAlignment(SwingConstants.CENTER);
|
taskIcon.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
taskIcon.setPreferredSize(new Dimension(35, 35));
|
taskIcon.setVerticalAlignment(SwingConstants.CENTER);
|
||||||
|
taskIcon.setPreferredSize(new Dimension(35, 35));
|
||||||
|
|
||||||
headerPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
statsPanel.setLayout(new DynamicGridLayout(3, 2));
|
||||||
headerPanel.setLayout(new BorderLayout());
|
statsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
|
statsPanel.setBorder(new EmptyBorder(9, 2, 9, 2));
|
||||||
|
|
||||||
statsPanel.setLayout(new DynamicGridLayout(3, 2));
|
currentDuration.setFont(FontManager.getRunescapeSmallFont());
|
||||||
statsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
remainingDuration.setFont(FontManager.getRunescapeSmallFont());
|
||||||
statsPanel.setBorder(new EmptyBorder(9, 2, 9, 2));
|
currentKills.setFont(FontManager.getRunescapeSmallFont());
|
||||||
|
remainingKills.setFont(FontManager.getRunescapeSmallFont());
|
||||||
|
currentXp.setFont(FontManager.getRunescapeSmallFont());
|
||||||
|
remainingXp.setFont(FontManager.getRunescapeSmallFont());
|
||||||
|
|
||||||
|
statsPanel.add(currentDuration);
|
||||||
|
statsPanel.add(remainingDuration);
|
||||||
|
statsPanel.add(currentKills);
|
||||||
|
statsPanel.add(remainingKills);
|
||||||
|
statsPanel.add(currentXp);
|
||||||
|
statsPanel.add(remainingXp);
|
||||||
|
|
||||||
|
headerPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
|
headerPanel.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
headerPanel.add(statsPanel, BorderLayout.CENTER);
|
||||||
|
headerPanel.add(taskIcon, BorderLayout.WEST);
|
||||||
|
});
|
||||||
|
|
||||||
currentDuration.setFont(FontManager.getRunescapeSmallFont());
|
|
||||||
remainingDuration.setFont(FontManager.getRunescapeSmallFont());
|
|
||||||
currentKills.setFont(FontManager.getRunescapeSmallFont());
|
|
||||||
remainingKills.setFont(FontManager.getRunescapeSmallFont());
|
|
||||||
currentXp.setFont(FontManager.getRunescapeSmallFont());
|
|
||||||
remainingXp.setFont(FontManager.getRunescapeSmallFont());
|
|
||||||
|
|
||||||
statsPanel.add(currentDuration);
|
|
||||||
statsPanel.add(remainingDuration);
|
|
||||||
statsPanel.add(currentKills);
|
|
||||||
statsPanel.add(remainingKills);
|
|
||||||
statsPanel.add(currentXp);
|
|
||||||
statsPanel.add(remainingXp);
|
|
||||||
|
|
||||||
headerPanel.add(taskIcon, BorderLayout.WEST);
|
|
||||||
headerPanel.add(statsPanel, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
JPanel progressWrapper = new JPanel();
|
JPanel progressWrapper = new JPanel();
|
||||||
progressWrapper.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
progressWrapper.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
|
|||||||
Reference in New Issue
Block a user