Merge pull request #11035 from rfick/kourend-library-features

This commit is contained in:
Abex
2020-04-04 18:31:51 -06:00
committed by GitHub
4 changed files with 83 additions and 7 deletions

View File

@@ -77,6 +77,14 @@ class BookPanel extends JPanel
void setIsTarget(boolean target) void setIsTarget(boolean target)
{ {
location.setForeground(target ? Color.GREEN : Color.WHITE); location.setForeground(target ? Color.GREEN : Color.ORANGE);
}
void setIsHeld(boolean held)
{
if (held)
{
location.setForeground(Color.WHITE);
}
} }
} }

View File

@@ -72,4 +72,14 @@ public interface KourendLibraryConfig extends Config
{ {
return true; return true;
} }
@ConfigItem(
keyName = "showTargetHintArrow",
name = "Show target book arrow",
description = "Show a hint arrow pointing to the target bookcase"
)
default boolean showTargetHintArrow()
{
return true;
}
} }

View File

@@ -52,6 +52,7 @@ class KourendLibraryPanel extends PluginPanel
private static final ImageIcon RESET_ICON; private static final ImageIcon RESET_ICON;
private static final ImageIcon RESET_HOVER_ICON; private static final ImageIcon RESET_HOVER_ICON;
private final KourendLibraryPlugin plugin;
private final KourendLibraryConfig config; private final KourendLibraryConfig config;
private final Library library; private final Library library;
@@ -65,10 +66,11 @@ class KourendLibraryPanel extends PluginPanel
} }
@Inject @Inject
KourendLibraryPanel(KourendLibraryConfig config, Library library) KourendLibraryPanel(KourendLibraryPlugin plugin, KourendLibraryConfig config, Library library)
{ {
super(); super();
this.plugin = plugin;
this.config = config; this.config = config;
this.library = library; this.library = library;
} }
@@ -117,7 +119,11 @@ class KourendLibraryPanel extends PluginPanel
Book customerBook = library.getCustomerBook(); Book customerBook = library.getCustomerBook();
for (Map.Entry<Book, BookPanel> b : bookPanels.entrySet()) for (Map.Entry<Book, BookPanel> b : bookPanels.entrySet())
{ {
b.getValue().setIsTarget(customerBook == b.getKey()); final Book book = b.getKey();
final BookPanel panel = b.getValue();
panel.setIsTarget(customerBook == book);
panel.setIsHeld(plugin.doesPlayerContainBook(book));
} }
HashMap<Book, HashSet<String>> bookLocations = new HashMap<>(); HashMap<Book, HashSet<String>> bookLocations = new HashMap<>();

View File

@@ -199,6 +199,15 @@ public class KourendLibraryPlugin extends Plugin
} }
}); });
} }
else if (ev.getKey().equals("showTargetHintArrow"))
{
if (client.getLocalPlayer() == null || client.getLocalPlayer().getWorldLocation().getRegionID() != REGION)
{
return;
}
updateBookcaseHintArrow();
}
} }
@Subscribe @Subscribe
@@ -227,7 +236,7 @@ public class KourendLibraryPlugin extends Plugin
if (event.getMessage().equals("You don't find anything useful here.")) if (event.getMessage().equals("You don't find anything useful here."))
{ {
library.mark(lastBookcaseAnimatedOn, null); library.mark(lastBookcaseAnimatedOn, null);
panel.update(); updateBooksPanel();
lastBookcaseAnimatedOn = null; lastBookcaseAnimatedOn = null;
} }
} }
@@ -277,7 +286,7 @@ public class KourendLibraryPlugin extends Plugin
if (book != null) if (book != null)
{ {
library.mark(lastBookcaseAnimatedOn, book); library.mark(lastBookcaseAnimatedOn, book);
panel.update(); updateBooksPanel();
lastBookcaseAnimatedOn = null; lastBookcaseAnimatedOn = null;
} }
} }
@@ -302,12 +311,12 @@ public class KourendLibraryPlugin extends Plugin
} }
library.setCustomer(npcHead.getModelId(), book); library.setCustomer(npcHead.getModelId(), book);
panel.update(); updateBooksPanel();
} }
else if (text.contains("You can have this other book") || text.contains("please accept a token of my thanks.") || text.contains("Thanks, I'll get on with reading it.")) else if (text.contains("You can have this other book") || text.contains("please accept a token of my thanks.") || text.contains("Thanks, I'll get on with reading it."))
{ {
library.setCustomer(-1, null); library.setCustomer(-1, null);
panel.update(); updateBooksPanel();
} }
} }
} }
@@ -361,6 +370,49 @@ public class KourendLibraryPlugin extends Plugin
} }
} }
private void updateBooksPanel()
{
panel.update();
updateBookcaseHintArrow();
}
private void updateBookcaseHintArrow()
{
final Book customerBook = library.getCustomerBook();
final SolvedState state = library.getState();
// Clear the hint arrow if the player has no book requested of them
// or if the player is already holding the correct book
// or if this plugin is configured not to show the target book hint arrow
if (customerBook == null || doesPlayerContainBook(customerBook) || !config.showTargetHintArrow())
{
client.clearHintArrow();
}
else if (state == SolvedState.COMPLETE && client.getHintArrowPoint() == null)
{
// Show a hint arrow pointing toward the target book if all book locations are known
// and a hint arrow is not already being displayed
for (Bookcase bookcase : library.getBookcases())
{
final Set<Book> books = bookcase.getPossibleBooks();
if (!books.isEmpty())
{
final Book book = books.iterator().next();
// Each bookcase in a complete solved state will contain only one book. If that book is the book
// the customer wants, mark the bookcase which contains it with a hint arrow.
if (book == customerBook)
{
WorldPoint correctLocation = bookcase.getLocation();
client.setHintArrow(correctLocation);
break;
}
}
}
}
}
static boolean isLibraryCustomer(int npcId) static boolean isLibraryCustomer(int npcId)
{ {
return npcId == NpcID.VILLIA || npcId == NpcID.PROFESSOR_GRACKLEBONE || npcId == NpcID.SAM_7049; return npcId == NpcID.VILLIA || npcId == NpcID.PROFESSOR_GRACKLEBONE || npcId == NpcID.SAM_7049;