Fix ending on 1 kc and new task dialog spanning multiple ticks

This commit is contained in:
Davis Cook
2019-02-12 15:05:39 -05:00
parent 9401269715
commit 7a7262d1dc
3 changed files with 55 additions and 30 deletions

View File

@@ -40,6 +40,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.swing.SwingUtilities;
import joptsimple.internal.Strings;
import lombok.AccessLevel;
import lombok.Getter;
@@ -75,6 +76,7 @@ import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ChatInput;
import net.runelite.client.game.AsyncBufferedImage;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.plugins.Plugin;
@@ -331,11 +333,19 @@ public class SlayerPlugin extends Plugin
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
public void onGameTick(GameTick tick)
{
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
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"));
String location = mAssign.group("location");
setTask(name, amount, amount, true, location);
canMatchDialog = false;
}
else if (mAssignFirst.find())
{
int amount = Integer.parseInt(mAssignFirst.group(2));
setTask(mAssignFirst.group(1), amount, amount, true);
canMatchDialog = false;
}
else if (mAssignBoss.find())
{
int amount = Integer.parseInt(mAssignBoss.group(2));
setTask(mAssignBoss.group(1), amount, amount, true);
points = Integer.parseInt(mAssignBoss.group(3).replaceAll(",", ""));
canMatchDialog = false;
}
else if (mCurrent.find())
{
@@ -367,7 +380,10 @@ public class SlayerPlugin extends Plugin
int amount = Integer.parseInt(mCurrent.group("amount"));
String location = mCurrent.group("location");
setTask(name, amount, currentTask.getInitialAmount(), false, location);
canMatchDialog = false;
}
} else if (npcDialog == null) {
canMatchDialog = true;
}
Widget braceletBreakWidget = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT);
@@ -703,16 +719,14 @@ public class SlayerPlugin extends Plugin
rebuildTargetList();
}
public BufferedImage getImageForTask(Task task)
public AsyncBufferedImage getImageForTask(Task task)
{
int itemSpriteId = ItemID.ENCHANTED_GEM;
if (task != null)
{
itemSpriteId = task.getItemSpriteId();
}
BufferedImage taskImg = itemManager.getImage(itemSpriteId);
return taskImg;
return itemManager.getImage(itemSpriteId);
}
private void addCounter()
@@ -723,7 +737,7 @@ public class SlayerPlugin extends Plugin
}
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>";
if (currentTask.getTaskLocation() != null && !currentTask.getTaskLocation().isEmpty())

View File

@@ -265,6 +265,11 @@ public class SlayerTaskPanel extends PluginPanel
return;
}
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.update(true, true, current.getTaskData());
return;

View File

@@ -14,6 +14,7 @@ import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.client.game.AsyncBufferedImage;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.DynamicGridLayout;
import net.runelite.client.ui.FontManager;
@@ -77,35 +78,40 @@ public class TaskBox extends JPanel
container.setLayout(new BorderLayout());
container.setBackground(ColorScheme.DARKER_GRAY_COLOR);
BufferedImage taskImg = slayerPlugin.getImageForTask(Task.getTask(taskData.getTaskName()));
JLabel taskIcon = new JLabel(new ImageIcon(taskImg));
taskIcon.setHorizontalAlignment(SwingConstants.CENTER);
taskIcon.setVerticalAlignment(SwingConstants.CENTER);
taskIcon.setPreferredSize(new Dimension(35, 35));
SwingUtilities.invokeLater(() -> {
BufferedImage taskImg = slayerPlugin.getImageForTask(Task.getTask(taskData.getTaskName()));
JLabel taskIcon = new JLabel(new ImageIcon(taskImg));
taskIcon.setHorizontalAlignment(SwingConstants.CENTER);
taskIcon.setVerticalAlignment(SwingConstants.CENTER);
taskIcon.setPreferredSize(new Dimension(35, 35));
headerPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
headerPanel.setLayout(new BorderLayout());
statsPanel.setLayout(new DynamicGridLayout(3, 2));
statsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
statsPanel.setBorder(new EmptyBorder(9, 2, 9, 2));
statsPanel.setLayout(new DynamicGridLayout(3, 2));
statsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
statsPanel.setBorder(new EmptyBorder(9, 2, 9, 2));
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.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();
progressWrapper.setBackground(ColorScheme.DARKER_GRAY_COLOR);