Skip to content

Commit

Permalink
kourendlibrary: Show a hint arrow above target book
Browse files Browse the repository at this point in the history
This commit adds a configuration to the Kourend library plugin to
display a hint arrow above the target bookcase. (when it is known)

Co-authored-by: Jordan Atwood <[email protected]>
  • Loading branch information
rfick and Nightfirecat committed Mar 19, 2020
1 parent 931cb7a commit 4369d8b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ default boolean showTutorialOverlay()
{
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ else if (ev.getKey().equals("hideButton"))
}
});
}
else if (ev.getKey().equals("showTargetHintArrow"))
{
if (client.getLocalPlayer() == null || client.getLocalPlayer().getWorldLocation().getRegionID() != REGION)
{
return;
}

updateBookcaseHintArrow();
}
}

@Subscribe
Expand Down Expand Up @@ -227,7 +236,7 @@ public void onChatMessage(ChatMessage event)
if (event.getMessage().equals("You don't find anything useful here."))
{
library.mark(lastBookcaseAnimatedOn, null);
panel.update();
updateBooksPanel();
lastBookcaseAnimatedOn = null;
}
}
Expand Down Expand Up @@ -277,7 +286,7 @@ public void onGameTick(GameTick tick)
if (book != null)
{
library.mark(lastBookcaseAnimatedOn, book);
panel.update();
updateBooksPanel();
lastBookcaseAnimatedOn = null;
}
}
Expand All @@ -302,12 +311,12 @@ public void onGameTick(GameTick tick)
}

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."))
{
library.setCustomer(-1, null);
panel.update();
updateBooksPanel();
}
}
}
Expand Down Expand Up @@ -361,6 +370,49 @@ private void updatePlayerBooks()
}
}

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)
{
return npcId == NpcID.VILLIA || npcId == NpcID.PROFESSOR_GRACKLEBONE || npcId == NpcID.SAM_7049;
Expand Down

0 comments on commit 4369d8b

Please sign in to comment.