RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.content.tradingpost.TradingPost Class Reference
Collaboration diagram for com.runehive.content.tradingpost.TradingPost:

Classes

class  TradingPostActiveListingSearch
enum  TradingPostActiveListingSearchType
class  TradingPostActiveListingSort
enum  TradingPostSortType

Public Member Functions

void addSearchResultsAndUpdateInterface (TradingPostActiveListingSearch search)
void addToCoffer (String owner, int amount)
void addToItemHistory (ItemHistory itemHistory)
void buyingDialogueOptions (int amount)
void cleanUp ()
boolean delist (TradingPostListing listing)
CompletableFuture< CoffergetCoffer (final String owner)
void getOrMakeNewCofferIfNotExists (final String owner, final Consumer< Coffer > useCoffer)
List< ItemHistorygetPlayersItemHistory ()
boolean handleButtonClick (int btnId)
void openOverviewInterface ()
void saveCoffer (final Coffer coffer)
void saveListings (final String owner, final List< TradingPostListing > listings)
void selectItemToList (Item item)
void sendItemHistoryData (List< ItemHistory > itemHistories)
void sortQuantity ()
void testData ()
 TradingPost (Player player)
void updateCofferAmountWidget ()
void updatePriceStrings ()
void updateQuantityString ()

Static Public Member Functions

static void createFileAndDirIfNotExists (File file)
static void loadAllListings ()
static void loadItemHistory ()
static void loadRecentItemHistory ()
static void saveAllItemHistory ()
static void saveRecentHistory ()

Static Public Attributes

static final int BUYING_PAGE_INTERFACE_ID = 80174

Private Member Functions

void alertSeller (String sellerName, String item, int amount)
void clearSellingOverlay ()
void confirmToAddListing ()
void displayMostRecentListings ()
void editPriceInputPrompt ()
void editQuantityInputPrompt ()
Item[] getItemArrayFromActiveListings (List< TradingPostListing > list)
Item[] getItemArrayFromItemHistory (List< ItemHistory > list)
List< TradingPostListinggetListingsByName (String name)
List< TradingPostListinggetPageListings (List< TradingPostListing > listings)
List< TradingPostListinggetSearchResults (TradingPostActiveListingSearchType type, String search)
int getSlotSizeByDonatorRank ()
boolean handleBuyingButton (int btnId)
boolean handleDismissListingButton (int btnId)
boolean handleSellingOverlayButtons (int btnId)
void nextPage ()
void openSellingOverlay ()
void previousPage ()
void purchase (int amount)
void refresh ()
void searchExistingItemInput ()
void searchExistingListing (TradingPostActiveListingSearch search)
void searchItemHistoryInput ()
void searchPlayerInput ()
void sendOverviewWidgetVisibility (int i, boolean isHidden)
void sort ()
void sortPrice ()
void toggleBuyingPageWidgetVisibility (int i, boolean isHidden)
void toggleSellingOverlayVisibilityAndOpen (boolean isHidden)
void updateBuyingPageWidgets (List< TradingPostListing > listings)
void updateExistingListingsList ()
void updateExistingListingsWidgets ()
void withdrawFromCoffer ()

Private Attributes

final AhoCorasickDoubleArrayTrie< String > acdat = new AhoCorasickDoubleArrayTrie<>()
List< TradingPostListingdisplayedPageListings = new ArrayList<>()
 The displayed listings on the buying page.
TradingPostListing listingToAdd
 The listing that the player will add to their existing listings.
TradingPostListing listingToBuy
 The listing that the player selects in the buying page.
List< TradingPostListingmyListings = new ArrayList<>()
 List containing the players existing listings/offers.
int page
 The page # of the buying interface.
final Player player
final List< ItemHistoryplayersItemHistory = new ArrayList<>()
 contains last 50 players buying history
List< TradingPostListingsearchedListings = new ArrayList<>()
 The current searched listings.
TradingPostActiveListingSearch tradingPostSearch
 The current item or player search.
TradingPostActiveListingSort tradingPostSort
 The current sort of the buyable listings.

Static Private Attributes

static final Map< String, CofferallCoffers = Collections.synchronizedMap(new HashMap<>())
 Hashmap containing the coffers <PlayerName, Coffer>
static final List< TradingPostListingallListings = new ArrayList<>()
 A list containing all the trading post listings.
static final int CURRENCY_ID = 995
static final int HISTORY_PAGE_INTERFACE_ID = 80616
static final Map< String, List< ItemHistory > > itemHistories = new HashMap<>()
 Contains a list of the last 50 sold of each item.
static final Logger logger = LoggerFactory.getLogger(TradingPost.class)
static final int MAX_LISTING_SIZE = 20
static final int MAX_LISTINGS_SHOWN = 50
static final int OVERVIEW_INTERFACE_ID = 80000
static final List< ItemHistoryrecentlySoldItems = new ArrayList<>()
 contains the last 50 sold items on the trading post
static final int TAX_RATE = 10

Detailed Description

Definition at line 33 of file TradingPost.java.

Constructor & Destructor Documentation

◆ TradingPost()

com.runehive.content.tradingpost.TradingPost.TradingPost ( Player player)

Definition at line 114 of file TradingPost.java.

114 {
115 this.player = player;
116 }

References player.

Member Function Documentation

◆ addSearchResultsAndUpdateInterface()

void com.runehive.content.tradingpost.TradingPost.addSearchResultsAndUpdateInterface ( TradingPostActiveListingSearch search)

Definition at line 426 of file TradingPost.java.

426 {
427 searchedListings.clear();
428 searchedListings.addAll(getSearchResults(search.searchType,search.text));
429 updateBuyingPageWidgets(getPageListings(searchedListings));
430 }

References getPageListings(), getSearchResults(), searchedListings, com.runehive.content.tradingpost.TradingPost.TradingPostActiveListingSearch.searchType, com.runehive.content.tradingpost.TradingPost.TradingPostActiveListingSearch.text, and updateBuyingPageWidgets().

Referenced by displayMostRecentListings(), purchase(), refresh(), and searchExistingListing().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addToCoffer()

void com.runehive.content.tradingpost.TradingPost.addToCoffer ( String owner,
int amount )

Definition at line 784 of file TradingPost.java.

784 {
785 getOrMakeNewCofferIfNotExists(owner, coffer -> {
786 coffer.addAmount((int) (amount - (TAX_RATE/100.0*amount)));
787 saveCoffer(coffer);
788 });
789 }

References getOrMakeNewCofferIfNotExists(), saveCoffer(), and TAX_RATE.

Referenced by purchase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addToItemHistory()

void com.runehive.content.tradingpost.TradingPost.addToItemHistory ( ItemHistory itemHistory)

Definition at line 762 of file TradingPost.java.

762 {
763 List<ItemHistory> itemHistoryList = itemHistories.computeIfAbsent(ItemDefinition.get(itemHistory.getItemId()).getName(), x -> new ArrayList<>());
764
765 if(itemHistoryList.size() == 50) {
766 itemHistoryList.remove(49);
767 }
768
769 itemHistoryList.add(itemHistory);
770
771 if(recentlySoldItems.size() == 50) {
772 recentlySoldItems.remove(49);
773 }
774
775 recentlySoldItems.add(itemHistory);
776
777 if(playersItemHistory.size() == 50) {
778 playersItemHistory.remove(49);
779 }
780
781 playersItemHistory.add(itemHistory);
782 }

References com.runehive.game.world.items.ItemDefinition.get(), com.runehive.content.tradingpost.ItemHistory.getItemId(), com.runehive.game.world.items.ItemDefinition.getName(), itemHistories, playersItemHistory, and recentlySoldItems.

Referenced by purchase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ alertSeller()

void com.runehive.content.tradingpost.TradingPost.alertSeller ( String sellerName,
String item,
int amount )
private

Definition at line 693 of file TradingPost.java.

693 {
694 Optional<Player> playerOptional = World.search(sellerName);
695
696 if(playerOptional.isPresent()) {
697 Player player = playerOptional.get();
698
699 player.send(new SendMessage("@red@Trading post: " + amount + " of your " + item + "s have been sold"));
700
702
703 if(player.interfaceManager.hasAnyOpen(OVERVIEW_INTERFACE_ID)) {
705 }
706 }
707 }
void openOverviewInterface()
void updateExistingListingsList()

References OVERVIEW_INTERFACE_ID, player, and com.runehive.game.world.World.search().

Referenced by purchase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ buyingDialogueOptions()

void com.runehive.content.tradingpost.TradingPost.buyingDialogueOptions ( int amount)

Definition at line 677 of file TradingPost.java.

677 {
678 if((long)amount + listingToBuy.getPrice() > Integer.MAX_VALUE) {
679 player.send(new SendMessage("Cannot buy this quantity for this price."));
680 return;
681 }
682
683 if(amount > listingToBuy.getAmountLeft()) {
684 amount = listingToBuy.getAmountLeft();
685 }
686
687 int finalAmount = amount;
688 player.dialogueFactory.sendStatement("Purchase " + amount + " of " + ItemDefinition.get(listingToBuy.getItemId()).getName(),
689 "for <col=A52929>" + Utility.formatDigits(listingToBuy.getPrice()*amount) + " " + ItemDefinition.get(CURRENCY_ID).getName() + "?")
690 .sendOption("Yes", () -> purchase(finalAmount), "Nevermind", () -> player.dialogueFactory.clear()).execute();
691 }

References CURRENCY_ID, com.runehive.util.Utility.formatDigits(), com.runehive.game.world.items.ItemDefinition.get(), com.runehive.game.world.items.ItemDefinition.getName(), listingToBuy, player, and purchase().

Referenced by handleBuyingButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanUp()

void com.runehive.content.tradingpost.TradingPost.cleanUp ( )

Definition at line 847 of file TradingPost.java.

847 {
848 displayedPageListings.clear();
849 searchedListings.clear();
850 tradingPostSearch = null;
851 tradingPostSort = null;
852 listingToAdd = null;
853 listingToBuy = null;
854 page = 0;
855 }

References displayedPageListings, listingToAdd, listingToBuy, page, searchedListings, tradingPostSearch, and tradingPostSort.

Referenced by openOverviewInterface(), and searchExistingListing().

Here is the caller graph for this function:

◆ clearSellingOverlay()

void com.runehive.content.tradingpost.TradingPost.clearSellingOverlay ( )
private

Definition at line 555 of file TradingPost.java.

555 {
556 player.send(new SendItemOnInterface(80153, new Item(-1,0)));
557 player.send(new SendString("",80160));
558 player.send(new SendString("",80161));
559 player.send(new SendString("",80162));
560 player.send(new SendString("",80163));
561 player.send(new SendString("",80173));
562 }

References player.

Referenced by openSellingOverlay().

Here is the caller graph for this function:

◆ confirmToAddListing()

void com.runehive.content.tradingpost.TradingPost.confirmToAddListing ( )
private

Definition at line 572 of file TradingPost.java.

572 {
573 if(listingToAdd.getPrice() == 0) {
574 player.send(new SendMessage("Unable to add listing with a price of zero."));
575 return;
576 }
577 if(myListings.size() > getSlotSizeByDonatorRank()) {
578 player.send(new SendMessage("Unable to add listing with max number listings listed."));
579 return;
580 }
581
582 if(player.inventory.remove(listingToAdd.getItemId(), listingToAdd.getInitialQuantity())) {
583 allListings.add(listingToAdd);
584 updateExistingListingsList();
585 openSellingOverlay();
586 updateExistingListingsWidgets();
587 saveListings(player.getName(),getListingsByName(player.getName()));
588 } else {
589 player.send(new SendMessage("Unable to list this item. Please try again."));
590 }
591 }

References allListings, getListingsByName(), getSlotSizeByDonatorRank(), listingToAdd, myListings, openSellingOverlay(), player, saveListings(), updateExistingListingsList(), and updateExistingListingsWidgets().

Referenced by handleSellingOverlayButtons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createFileAndDirIfNotExists()

void com.runehive.content.tradingpost.TradingPost.createFileAndDirIfNotExists ( File file)
static

Definition at line 1061 of file TradingPost.java.

1061 {
1062 if (!file.getParentFile().exists() || !file.exists()) {
1063 try {
1064 file.getParentFile().mkdirs();
1065 file.createNewFile();
1066 } catch (SecurityException e) {
1067 System.out.println("Unable to create directory");
1068 } catch (IOException e) {
1069 throw new RuntimeException(e);
1070 }
1071 }
1072 }

Referenced by loadItemHistory(), and loadRecentItemHistory().

Here is the caller graph for this function:

◆ delist()

boolean com.runehive.content.tradingpost.TradingPost.delist ( TradingPostListing listing)

Definition at line 831 of file TradingPost.java.

831 {
832 if(myListings.isEmpty()) {
833 return false;
834 }
835
836 if(!myListings.contains(listing)) {
837 return false;
838 }
839
840 if(!allListings.contains(listing)) {
841 return false;
842 }
843
844 return allListings.remove(listing) && myListings.remove(listing);
845 }

References allListings, and myListings.

Referenced by handleDismissListingButton().

Here is the caller graph for this function:

◆ displayMostRecentListings()

void com.runehive.content.tradingpost.TradingPost.displayMostRecentListings ( )
private

Definition at line 404 of file TradingPost.java.

404 {
405 if(!player.interfaceManager.isInterfaceOpen(BUYING_PAGE_INTERFACE_ID)) {
406 player.interfaceManager.open(BUYING_PAGE_INTERFACE_ID);
407 }
408 player.send(new SendString("Search: Most recent",80176));
409
410 tradingPostSearch = new TradingPostActiveListingSearch(TradingPostActiveListingSearchType.MOST_RECENT, "");
411 addSearchResultsAndUpdateInterface(tradingPostSearch);
412 }

References addSearchResultsAndUpdateInterface(), BUYING_PAGE_INTERFACE_ID, com.runehive.content.tradingpost.TradingPost.TradingPostActiveListingSearchType.MOST_RECENT, player, and tradingPostSearch.

Referenced by handleButtonClick(), purchase(), refresh(), and searchExistingListing().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ editPriceInputPrompt()

void com.runehive.content.tradingpost.TradingPost.editPriceInputPrompt ( )
private

Definition at line 568 of file TradingPost.java.

568 {
569 player.send(new SendInputAmount("How much would you like sell this for?", 10, input -> listingToAdd.setPrice(player, Integer.parseInt(input))));
570 }

References listingToAdd, and player.

Referenced by handleSellingOverlayButtons().

Here is the caller graph for this function:

◆ editQuantityInputPrompt()

void com.runehive.content.tradingpost.TradingPost.editQuantityInputPrompt ( )
private

Definition at line 564 of file TradingPost.java.

564 {
565 player.send(new SendInputAmount("How many would you like to sell?", 10, input -> listingToAdd.setQuantity(player,Integer.parseInt(input))));
566 }

References listingToAdd, and player.

Referenced by handleSellingOverlayButtons().

Here is the caller graph for this function:

◆ getCoffer()

CompletableFuture< Coffer > com.runehive.content.tradingpost.TradingPost.getCoffer ( final String owner)

Definition at line 896 of file TradingPost.java.

896 {
897 final Coffer cachedCoffer = allCoffers.get(owner);
898 if (cachedCoffer != null) {
899 return CompletableFuture.completedFuture(cachedCoffer);
900 }
901
902 // retrieve coffer if coffer hasn't been retrieved since server start
903 return CompletableFuture.supplyAsync(() -> {
904 final Path path = Path.of("./data/profile/save/tradingpost/coffers/", owner, ".json");
905 if (!Files.exists(path)) {
906 return null;
907 }
908
909 final Gson gson = GsonUtils.JSON_ALLOW_NULL.get();
910 try (final BufferedReader reader = Files.newBufferedReader(path)) {
911 final Coffer coffer = gson.fromJson(reader, Coffer.class);
912 if (coffer != null) {
913 allCoffers.put(coffer.getOwner(), coffer);
914 return coffer;
915 }
916 } catch (final IOException e) {
917 logger.error("Failed reading coffer for \"" + owner + "\"", e);
918 }
919 return null;
920 });
921 }
val object_examines.json val gson

References allCoffers, com.runehive.content.tradingpost.Coffer.getOwner(), com.runehive.util.GsonUtils.JSON_ALLOW_NULL, and logger.

Referenced by getOrMakeNewCofferIfNotExists().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getItemArrayFromActiveListings()

Item[] com.runehive.content.tradingpost.TradingPost.getItemArrayFromActiveListings ( List< TradingPostListing > list)
private

Definition at line 604 of file TradingPost.java.

604 {
605 return list
606 .stream()
607 .map(tradingPostListing -> new Item(ItemDefinition.get(tradingPostListing.getItemId()).isNoted()
608 ? ItemDefinition.get(tradingPostListing.getItemId()).getUnnotedId()
609 : tradingPostListing.getItemId(), tradingPostListing.getAmountLeft()))
610 .toArray(Item[]::new);
611 }

References com.runehive.game.world.items.ItemDefinition.get(), and com.runehive.game.world.items.ItemDefinition.isNoted().

Referenced by updateBuyingPageWidgets(), and updateExistingListingsWidgets().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getItemArrayFromItemHistory()

Item[] com.runehive.content.tradingpost.TradingPost.getItemArrayFromItemHistory ( List< ItemHistory > list)
private

Definition at line 613 of file TradingPost.java.

613 {
614 return list
615 .stream()
616 .map(ih -> new Item(ItemDefinition.get(ih.getItemId()).isNoted()
617 ? ItemDefinition.get(ih.getItemId()).getUnnotedId()
618 : ih.getItemId(), ih.getQuantity()))
619 .toArray(Item[]::new);
620 }

References com.runehive.game.world.items.ItemDefinition.get(), and com.runehive.game.world.items.ItemDefinition.isNoted().

Referenced by sendItemHistoryData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getListingsByName()

List< TradingPostListing > com.runehive.content.tradingpost.TradingPost.getListingsByName ( String name)
private

Definition at line 597 of file TradingPost.java.

597 {
598 return allListings
599 .stream()
600 .filter(tradingPostListing -> tradingPostListing.getSeller().equals(name))
601 .collect(Collectors.toList());
602 }

References allListings.

Referenced by confirmToAddListing(), handleDismissListingButton(), purchase(), and updateExistingListingsList().

Here is the caller graph for this function:

◆ getOrMakeNewCofferIfNotExists()

void com.runehive.content.tradingpost.TradingPost.getOrMakeNewCofferIfNotExists ( final String owner,
final Consumer< Coffer > useCoffer )

Definition at line 791 of file TradingPost.java.

792 {
793 getCoffer(owner).thenAccept(coffer -> {
794 if (coffer == null) {
795 coffer = allCoffers.compute(owner, (k, v) -> new Coffer(owner));
796 saveCoffer(coffer);
797 }
798
799 useCoffer.accept(coffer);
800 });
801 }

References allCoffers, getCoffer(), and saveCoffer().

Referenced by addToCoffer(), updateCofferAmountWidget(), and withdrawFromCoffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPageListings()

List< TradingPostListing > com.runehive.content.tradingpost.TradingPost.getPageListings ( List< TradingPostListing > listings)
private

Definition at line 450 of file TradingPost.java.

450 {
451 return listings.subList(
452 Math.min(listings.size(), page * MAX_LISTINGS_SHOWN),
453 Math.min(listings.size(), (page * MAX_LISTINGS_SHOWN + MAX_LISTINGS_SHOWN))).
454 stream()
455 .filter(tradingPostListing -> !tradingPostListing.getSeller().equalsIgnoreCase(player.getName()))
456 .limit(MAX_LISTINGS_SHOWN)
457 .collect(Collectors.toList());
458 }

References MAX_LISTINGS_SHOWN, page, and player.

Referenced by addSearchResultsAndUpdateInterface(), nextPage(), previousPage(), and sort().

Here is the caller graph for this function:

◆ getPlayersItemHistory()

List< ItemHistory > com.runehive.content.tradingpost.TradingPost.getPlayersItemHistory ( )

Definition at line 1074 of file TradingPost.java.

1074 {
1075 return playersItemHistory;
1076 }

References playersItemHistory.

◆ getSearchResults()

List< TradingPostListing > com.runehive.content.tradingpost.TradingPost.getSearchResults ( TradingPostActiveListingSearchType type,
String search )
private

Definition at line 432 of file TradingPost.java.

432 {
433 if(type == TradingPostActiveListingSearchType.MOST_RECENT) {
434 return Lists.reverse(allListings);
435 }
436 List<TradingPostListing> temp = new ArrayList<>();
437 TreeMap<String, String> map = new TreeMap<>();
438 map.put(search,search);
439 tradingPostSearch.acdat.build(map);
440 for(TradingPostListing listing : allListings) {
441 tradingPostSearch.acdat.parseText(type == TradingPostActiveListingSearchType.ITEM ? ItemDefinition.get(listing.getItemId()).getName().toLowerCase() : listing.getSeller().toLowerCase(), (begin, end, value) -> {
442 if(!temp.contains(listing)) {
443 temp.add(listing);
444 }
445 });
446 }
447 return temp;
448 }

References allListings, com.runehive.game.world.items.ItemDefinition.get(), com.runehive.game.world.items.ItemDefinition.getName(), com.runehive.content.tradingpost.TradingPost.TradingPostActiveListingSearchType.ITEM, com.runehive.content.tradingpost.TradingPost.TradingPostActiveListingSearchType.MOST_RECENT, and tradingPostSearch.

Referenced by addSearchResultsAndUpdateInterface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSlotSizeByDonatorRank()

int com.runehive.content.tradingpost.TradingPost.getSlotSizeByDonatorRank ( )
private

Definition at line 499 of file TradingPost.java.

499 {
500 switch (player.right) {
501 case KING_DONATOR -> {
502 return MAX_LISTING_SIZE;
503 }
504 case ELITE_DONATOR -> {
505 return 18;
506
507 }
508 case EXTREME_DONATOR -> {
509 return 15;
510 }
511 case SUPER_DONATOR -> {
512 return 12;
513 }
514 case DONATOR -> {
515 return 10;
516 }
517 default -> {
518 return 5;
519 }
520 }
521 }

References MAX_LISTING_SIZE, and player.

Referenced by confirmToAddListing().

Here is the caller graph for this function:

◆ handleButtonClick()

boolean com.runehive.content.tradingpost.TradingPost.handleButtonClick ( int btnId)

Definition at line 133 of file TradingPost.java.

133 {
134 if(!player.interfaceManager.hasAnyOpen(OVERVIEW_INTERFACE_ID, BUYING_PAGE_INTERFACE_ID,HISTORY_PAGE_INTERFACE_ID)) {
135 return false;
136 }
137
138 switch (btnId) {
139 case 14650:
140 case 15418:
141 openOverviewInterface();
142 return true;
143 case 15091:
144 case 14597:
145 searchItemHistoryInput();
146 return true;
147 case 14600:
148 searchPlayerInput();
149 return true;
150 case 14603:
151 displayMostRecentListings();
152 return true;
153 case 14662:
154 player.dialogueFactory.sendOption("Search item", this::searchExistingItemInput, "Search player", this::searchPlayerInput, "Nevermind", () -> player.dialogueFactory.clear()).execute();
155 return true;
156 case 14474:
157 searchExistingItemInput();
158 return true;
159 case 14477:
160 openSellingOverlay();
161 return true;
162 case 14484:
163 sendItemHistoryData(playersItemHistory);
164 return true;
165 case 14487:
166 sendItemHistoryData(recentlySoldItems);
167 return true;
168 case 14614:
169 toggleSellingOverlayVisibilityAndOpen(true);
170 return true;
171 case 14659:
172 nextPage();
173 return true;
174 case 14653:
175 previousPage();
176 return true;
177 case 14656:
178 refresh();
179 return true;
180 case 14466:
181 withdrawFromCoffer();
182 return true;
183 case 14649:
184 sortPrice();
185 return true;
186 case 14648:
187 sortQuantity();
188 return true;
189 default: {
190 /*
191 * Returns true or false based on button ids
192 */
193 if(handleBuyingButton(btnId) || handleDismissListingButton(btnId) || handleSellingOverlayButtons(btnId)) {
194 return true;
195 }
196 }
197 }
198
199 return false;
200 }

References BUYING_PAGE_INTERFACE_ID, displayMostRecentListings(), handleBuyingButton(), handleDismissListingButton(), handleSellingOverlayButtons(), HISTORY_PAGE_INTERFACE_ID, nextPage(), openOverviewInterface(), openSellingOverlay(), OVERVIEW_INTERFACE_ID, player, playersItemHistory, previousPage(), recentlySoldItems, refresh(), searchExistingItemInput(), searchItemHistoryInput(), searchPlayerInput(), sendItemHistoryData(), sortPrice(), sortQuantity(), toggleSellingOverlayVisibilityAndOpen(), and withdrawFromCoffer().

Here is the call graph for this function:

◆ handleBuyingButton()

boolean com.runehive.content.tradingpost.TradingPost.handleBuyingButton ( int btnId)
private

Definition at line 647 of file TradingPost.java.

647 {
648 if(btnId >= 14878 && btnId <= 14927) {
649 int index = btnId - 14878;
650
651 if(displayedPageListings.size() < index) {
652 return true;
653 }
654
655 TradingPostListing temp = displayedPageListings.get(index);
656
657 if(temp == null) {
658 return true;
659 }
660
661 if(!allListings.contains(temp)) {
662 return true;
663 }
664
665 listingToBuy = temp;
666
667 if(listingToBuy.getAmountLeft() > 1) {
668 player.send(new SendInputAmount("How many of " + ItemDefinition.get(listingToBuy.getItemId()).getName() + "?", 10, input -> buyingDialogueOptions(Integer.parseInt(input))));
669 } else {
670 buyingDialogueOptions(1);
671 }
672 }
673
674 return false;
675 }
val index

References allListings, buyingDialogueOptions(), displayedPageListings, com.runehive.game.world.items.ItemDefinition.get(), com.runehive.game.world.items.ItemDefinition.getName(), listingToBuy, and player.

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleDismissListingButton()

boolean com.runehive.content.tradingpost.TradingPost.handleDismissListingButton ( int btnId)
private

Definition at line 803 of file TradingPost.java.

803 {
804 if(btnId >= 14516 && btnId <= 14535) {
805 int index = btnId - 14516;
806
807 if(myListings.isEmpty()) {
808 return true;
809 }
810
811 if(myListings.size() < index) {
812 return true;
813 }
814
815 TradingPostListing listing = myListings.get(index);
816
817 if(!delist(listing)) {
818 player.send(new SendMessage("Unable to delist this item. Please try again."));
819 } else {
820 saveListings(player.getName(),getListingsByName(player.getName()));
821 player.inventory.addOrBank(new Item(listing.getItemId(),listing.getAmountLeft()));
822 openOverviewInterface();
823 }
824
825 return true;
826 }
827
828 return false;
829 }

References delist(), com.runehive.content.tradingpost.TradingPostListing.getAmountLeft(), com.runehive.content.tradingpost.TradingPostListing.getItemId(), getListingsByName(), myListings, openOverviewInterface(), player, and saveListings().

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleSellingOverlayButtons()

boolean com.runehive.content.tradingpost.TradingPost.handleSellingOverlayButtons ( int btnId)
private

Definition at line 380 of file TradingPost.java.

380 {
381 if(listingToAdd == null) return false;
382
383 switch (btnId) {
384 case 14618:
385 listingToAdd.addQuantity(player,1);
386 return true;
387 case 14621:
388 listingToAdd.removeQuantity(player,1);
389 return true;
390 case 14636:
391 editQuantityInputPrompt();
392 return true;
393 case 14628:
394 editPriceInputPrompt();
395 return true;
396 case 14631:
397 confirmToAddListing();
398 return true;
399 }
400
401 return false;
402 }

References confirmToAddListing(), editPriceInputPrompt(), editQuantityInputPrompt(), listingToAdd, and player.

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadAllListings()

void com.runehive.content.tradingpost.TradingPost.loadAllListings ( )
static

Definition at line 948 of file TradingPost.java.

948 {
949 try {
950 File folder = new File("./data/profile/save/tradingpost/listings/");
951 File[] files = folder.listFiles();
952 if (files == null) return;
953 for(File f : files) {
954 File toRead = null;
955 if(f.isDirectory()) {
956 toRead = Objects.requireNonNull(f.getAbsoluteFile().listFiles())[0];
957 }
958 try {
959 assert toRead != null;
960 final Gson gson = GsonUtils.JSON_ALLOW_NULL.get();
961 try (final BufferedReader reader = Files.newBufferedReader(Path.of(toRead.getPath()))) {
962 final List<TradingPostListing> listings = List.of(gson.fromJson(reader, TradingPostListing[].class));
963 allListings.addAll(listings);
964 } catch (final IOException e) {
965 logger.error("Failed reading listings", e);
966 }
967 } catch (Exception e) {
968 e.printStackTrace();
969 }
970 }
971 } catch (Exception e) {
972 e.printStackTrace();
973 }
974 }

References allListings, com.runehive.util.GsonUtils.JSON_ALLOW_NULL, and logger.

Referenced by com.runehive.RuneHive.processParallelStartupTasks().

Here is the caller graph for this function:

◆ loadItemHistory()

void com.runehive.content.tradingpost.TradingPost.loadItemHistory ( )
static

Definition at line 1020 of file TradingPost.java.

1020 {
1021 Path path = Paths.get("./data/profile/save/tradingpost/itemhistory.json");
1022 File file = path.toFile();
1023
1024 createFileAndDirIfNotExists(file);
1025 if(file.length() == 0) return;
1026
1027 try (FileReader fileReader = new FileReader(file)) {
1028 JsonParser fileParser = new JsonParser();
1029 Gson builder = new GsonBuilder()
1030 .create();
1031 JsonObject reader = (JsonObject) fileParser.parse(fileReader);
1032
1033 HashMap<String, List<ItemHistory>> itemHistory = builder.fromJson(reader.get("itemhistory"),
1034 new TypeToken<HashMap<String, List<ItemHistory>>>() {
1035 }.getType());
1036 itemHistories.putAll(itemHistory);
1037 } catch (Exception e) {
1038 e.printStackTrace();
1039 }
1040 }

References createFileAndDirIfNotExists(), and itemHistories.

Referenced by com.runehive.RuneHive.processParallelStartupTasks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadRecentItemHistory()

void com.runehive.content.tradingpost.TradingPost.loadRecentItemHistory ( )
static

Definition at line 1042 of file TradingPost.java.

1042 {
1043 Path path = Paths.get("./data/profile/save/tradingpost/itemhistoryrecent.json");
1044 File file = path.toFile();
1045
1046 createFileAndDirIfNotExists(file);
1047 if(file.length() == 0) return;
1048
1049 try (FileReader fileReader = new FileReader(file)) {
1050 JsonParser fileParser = new JsonParser();
1051 Gson builder = new GsonBuilder()
1052 .create();
1053 JsonObject reader = (JsonObject) fileParser.parse(fileReader);
1054 ItemHistory[] temp = builder.fromJson(reader.get("recentitemhistory").getAsJsonArray(), ItemHistory[].class);
1055 recentlySoldItems.addAll(Arrays.asList(temp));
1056 } catch (Exception e) {
1057 e.printStackTrace();
1058 }
1059 }

References createFileAndDirIfNotExists(), and recentlySoldItems.

Referenced by com.runehive.RuneHive.processParallelStartupTasks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nextPage()

void com.runehive.content.tradingpost.TradingPost.nextPage ( )
private

Definition at line 362 of file TradingPost.java.

362 {
363 page++;
364 List<TradingPostListing> temp;
365 temp = getPageListings(searchedListings);
366 if(temp.isEmpty()) {
367 page--;
368 player.send(new SendMessage("No more results on the next page"));
369 } else {
370 updateBuyingPageWidgets(temp);
371 }
372 }

References getPageListings(), page, player, searchedListings, and updateBuyingPageWidgets().

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openOverviewInterface()

void com.runehive.content.tradingpost.TradingPost.openOverviewInterface ( )

Definition at line 118 of file TradingPost.java.

118 {
119 cleanUp();
120 updateExistingListingsList();
121 updateExistingListingsWidgets();
122 updateCofferAmountWidget();
123 toggleSellingOverlayVisibilityAndOpen(true);
124 player.interfaceManager.open(OVERVIEW_INTERFACE_ID);
125 }

References cleanUp(), OVERVIEW_INTERFACE_ID, player, toggleSellingOverlayVisibilityAndOpen(), updateCofferAmountWidget(), updateExistingListingsList(), and updateExistingListingsWidgets().

Referenced by handleButtonClick(), and handleDismissListingButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openSellingOverlay()

void com.runehive.content.tradingpost.TradingPost.openSellingOverlay ( )
private

Definition at line 523 of file TradingPost.java.

523 {
524 clearSellingOverlay();
525 toggleSellingOverlayVisibilityAndOpen(false);
526 listingToAdd = null;
527 player.send(new SendInventoryInterface(OVERVIEW_INTERFACE_ID, 65300));
528 player.send(new SendItemOnInterface(65301, player.inventory.toArray()));
529 }

References clearSellingOverlay(), listingToAdd, OVERVIEW_INTERFACE_ID, player, and toggleSellingOverlayVisibilityAndOpen().

Referenced by confirmToAddListing(), and handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ previousPage()

void com.runehive.content.tradingpost.TradingPost.previousPage ( )
private

Definition at line 374 of file TradingPost.java.

374 {
375 if(page == 0) return;
376 page--;
377 updateBuyingPageWidgets(getPageListings(searchedListings));
378 }

References getPageListings(), page, searchedListings, and updateBuyingPageWidgets().

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ purchase()

void com.runehive.content.tradingpost.TradingPost.purchase ( int amount)
private

Definition at line 709 of file TradingPost.java.

709 {
710 if(listingToBuy == null) {
711 return;
712 }
713
714 int getPlayerCurrencyAmount = player.inventory.computeAmountForId(CURRENCY_ID);
715 int totalPrice = listingToBuy.getPrice()*amount;
716
717 if(totalPrice > getPlayerCurrencyAmount) {
718 player.send(new SendMessage("Insufficient " + ItemDefinition.get(CURRENCY_ID).getName() + " to complete your transaction."));
719 return;
720 }
721
722 if(amount > listingToBuy.getAmountLeft()) {
723 amount = listingToBuy.getAmountLeft();
724 player.send(new SendMessage("Your purchase amount has been lowered to " + amount));
725 }
726
727 if(!allListings.contains(listingToBuy)) {
728 player.send(new SendMessage("This item does not exist in the trading post anymore."));
729 return;
730 }
731
732 if(player.inventory.add(listingToBuy.getItemId(), amount)) {
733 player.inventory.remove(CURRENCY_ID,totalPrice);
734 listingToBuy.addToAmountSold(amount);
735
736 if(listingToBuy.getAmountLeft() == 0) {
737 allListings.remove(listingToBuy);
738 displayedPageListings.remove(listingToBuy);
739 searchedListings.remove(listingToBuy);
740 }
741
742 if(tradingPostSearch != null) {
743 addSearchResultsAndUpdateInterface(tradingPostSearch);
744 } else {
745 displayMostRecentListings();
746 }
747
748 addToCoffer(listingToBuy.getSeller(),listingToBuy.getPrice()*amount);
749 alertSeller(listingToBuy.getSeller(),ItemDefinition.get(listingToBuy.getItemId()).getName(), amount);
750
751 String seller = listingToBuy.getSeller();
752 saveListings(seller,getListingsByName(seller));
753
754 addToItemHistory(new ItemHistory(amount, listingToBuy.getItemId(), listingToBuy.getPrice()*amount, listingToBuy.getSeller(), player.getName()));
755
756 } else {
757 player.send(new SendMessage("You do not have enough inventory spaces to complete this transaction"));
758 }
759
760 }

References addSearchResultsAndUpdateInterface(), addToCoffer(), addToItemHistory(), alertSeller(), allListings, CURRENCY_ID, displayedPageListings, displayMostRecentListings(), com.runehive.game.world.items.ItemDefinition.get(), getListingsByName(), com.runehive.game.world.items.ItemDefinition.getName(), listingToBuy, player, saveListings(), searchedListings, and tradingPostSearch.

Referenced by buyingDialogueOptions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refresh()

void com.runehive.content.tradingpost.TradingPost.refresh ( )
private

Definition at line 354 of file TradingPost.java.

354 {
355 if(tradingPostSearch != null) {
356 addSearchResultsAndUpdateInterface(tradingPostSearch);
357 } else {
358 displayMostRecentListings();
359 }
360 }

References addSearchResultsAndUpdateInterface(), displayMostRecentListings(), and tradingPostSearch.

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveAllItemHistory()

void com.runehive.content.tradingpost.TradingPost.saveAllItemHistory ( )
static

Definition at line 976 of file TradingPost.java.

976 {
977 Path path = Paths.get("./data/profile/save/tradingpost/itemhistory.json");
978 File file = path.toFile();
979 file.getParentFile().setWritable(true);
980
981 if(!file.getParentFile().exists()) {
982 try {
983 file.getParentFile().mkdirs();
984 } catch (SecurityException e) {
985 System.out.println("Error while creating item history directory");
986 }
987 }
988 try(FileWriter writer = new FileWriter(file)) {
989 Gson builder = new GsonBuilder().setPrettyPrinting().create();
990 JsonObject object = new JsonObject();
991 object.add("itemhistory",builder.toJsonTree(itemHistories));
992 writer.write(builder.toJson(object));
993 } catch (Exception e) {
994 e.printStackTrace();
995 }
996 }

References itemHistories.

Referenced by com.runehive.game.world.World.save().

Here is the caller graph for this function:

◆ saveCoffer()

void com.runehive.content.tradingpost.TradingPost.saveCoffer ( final Coffer coffer)

Definition at line 872 of file TradingPost.java.

872 {
873 Thread.startVirtualThread(() -> {
874 try {
875 final String json = GsonUtils.JSON_PRETTY_ALLOW_NULL.get().toJson(coffer);
876
877 final Path path = Path.of("./data/profile/save/tradingpost/coffers/", coffer.getOwner(), ".json");
878 Path parent = path.getParent();
879 if (parent == null) {
880 throw new UnsupportedOperationException("Path must have a parent " + path);
881 }
882 if (!Files.exists(parent)) {
883 parent = Files.createDirectories(parent);
884 }
885
886 final Path tempFile = Files.createTempFile(parent, path.getFileName().toString(), ".tmp");
887 Files.writeString(tempFile, json, StandardCharsets.UTF_8);
888
889 Files.move(tempFile, path, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
890 } catch (final Exception ex) {
891 logger.error(String.format("Error while saving player=%s", player.getName()), ex);
892 }
893 });
894 }

References com.runehive.content.tradingpost.Coffer.getOwner(), com.runehive.util.GsonUtils.JSON_PRETTY_ALLOW_NULL, logger, and player.

Referenced by addToCoffer(), getOrMakeNewCofferIfNotExists(), and withdrawFromCoffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveListings()

void com.runehive.content.tradingpost.TradingPost.saveListings ( final String owner,
final List< TradingPostListing > listings )

Definition at line 923 of file TradingPost.java.

923 {
924 Thread.startVirtualThread(() -> {
925 try {
926 final String json = GsonUtils.JSON_PRETTY_ALLOW_NULL.get().toJson(listings);
927
928 final Path path = Path.of("./data/profile/save/tradingpost/listings/", owner, ".json");
929 Path parent = path.getParent();
930 if (parent == null) {
931 throw new UnsupportedOperationException("Path must have a parent " + path);
932 }
933 if (!Files.exists(parent)) {
934 parent = Files.createDirectories(parent);
935 }
936
937 final Path tempFile = Files.createTempFile(parent, path.getFileName().toString(), ".tmp");
938 Files.writeString(tempFile, json, StandardCharsets.UTF_8);
939
940 Files.move(tempFile, path, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
941
942 } catch (final Exception ex) {
943 logger.error(String.format("Error while saving player=%s", player.getName()), ex);
944 }
945 });
946 }

References com.runehive.util.GsonUtils.JSON_PRETTY_ALLOW_NULL, logger, and player.

Referenced by confirmToAddListing(), handleDismissListingButton(), and purchase().

Here is the caller graph for this function:

◆ saveRecentHistory()

void com.runehive.content.tradingpost.TradingPost.saveRecentHistory ( )
static

Definition at line 998 of file TradingPost.java.

998 {
999 Path path = Paths.get("./data/profile/save/tradingpost/itemhistoryrecent.json");
1000 File file = path.toFile();
1001 file.getParentFile().setWritable(true);
1002
1003 if(!file.getParentFile().exists()) {
1004 try {
1005 file.getParentFile().mkdirs();
1006 } catch (SecurityException e) {
1007 System.out.println("Error while creating recent item history directory");
1008 }
1009 }
1010 try(FileWriter writer = new FileWriter(file)) {
1011 Gson builder = new GsonBuilder().setPrettyPrinting().create();
1012 JsonObject object = new JsonObject();
1013 object.add("recentitemhistory",builder.toJsonTree(recentlySoldItems));
1014 writer.write(builder.toJson(object));
1015 } catch (Exception e) {
1016 e.printStackTrace();
1017 }
1018 }

References recentlySoldItems.

Referenced by com.runehive.game.world.World.save().

Here is the caller graph for this function:

◆ searchExistingItemInput()

void com.runehive.content.tradingpost.TradingPost.searchExistingItemInput ( )
private

Definition at line 256 of file TradingPost.java.

256 {
257 World.schedule(new Task(1) { // task added so input prompt shows after dialogue
258 @Override
259 protected void execute() {
260 player.send(new SendInputMessage("Enter item name to search for:", 16, input -> {
261 searchExistingListing(new TradingPostActiveListingSearch(TradingPostActiveListingSearchType.ITEM, String.valueOf(input)));
262 player.interfaceManager.open(BUYING_PAGE_INTERFACE_ID);
263 }));
264 this.cancel();
265 }
266 });
267 }

References BUYING_PAGE_INTERFACE_ID, com.runehive.content.tradingpost.TradingPost.TradingPostActiveListingSearchType.ITEM, player, com.runehive.game.world.World.schedule(), and searchExistingListing().

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ searchExistingListing()

void com.runehive.content.tradingpost.TradingPost.searchExistingListing ( TradingPostActiveListingSearch search)
private

Definition at line 414 of file TradingPost.java.

414 {
415 if(search.text.length() == 0) {
416 cleanUp();
417 displayMostRecentListings();
418 return;
419 }
420 tradingPostSearch = search;
421 this.page = 0;
422 addSearchResultsAndUpdateInterface(search);
423 player.send(new SendString("Search: " + tradingPostSearch.text,80176));
424 }

References addSearchResultsAndUpdateInterface(), cleanUp(), displayMostRecentListings(), player, com.runehive.content.tradingpost.TradingPost.TradingPostActiveListingSearch.text, and tradingPostSearch.

Referenced by searchExistingItemInput(), and searchPlayerInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ searchItemHistoryInput()

void com.runehive.content.tradingpost.TradingPost.searchItemHistoryInput ( )
private

Definition at line 202 of file TradingPost.java.

202 {
203 player.send(new SendInputMessage("Enter item name to search history for:", 16, input -> {
204
205 if(Objects.equals(input, "")) {
206 sendItemHistoryData(recentlySoldItems);
207 return;
208 }
209
210 List<ItemHistory> historyItems = new ArrayList<>();
211 TreeMap<String, String> map = new TreeMap<>();
212 map.put(input,input);
213 acdat.build(map);
214
215 for(Map.Entry<String, List<ItemHistory>> lf : itemHistories.entrySet()) {
216 acdat.parseText(lf.getKey().toLowerCase(), (b,e,v) -> {
217 List<ItemHistory> temp = lf.getValue();
218
219 for(ItemHistory h : temp) {
220 if(!historyItems.contains(h)) {
221 historyItems.add(h);
222 }
223
224 if(historyItems.size() == 50) {
225 break;
226 }
227
228 }
229 });
230 }
231
232 sendItemHistoryData(historyItems);
233 }));
234 }

References acdat, itemHistories, player, recentlySoldItems, and sendItemHistoryData().

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ searchPlayerInput()

void com.runehive.content.tradingpost.TradingPost.searchPlayerInput ( )
private

Definition at line 269 of file TradingPost.java.

269 {
270 World.schedule(new Task(1) { // task added so input prompt shows after dialogue
271 @Override
272 protected void execute() {
273 player.send(new SendInputMessage("Enter player name to search for:", 16, input -> {
274 searchExistingListing(new TradingPostActiveListingSearch(TradingPostActiveListingSearchType.PLAYER, String.valueOf(input)));
275 player.interfaceManager.open(BUYING_PAGE_INTERFACE_ID);
276 }));
277 this.cancel();
278 }
279 });
280 }

References BUYING_PAGE_INTERFACE_ID, com.runehive.content.tradingpost.TradingPost.TradingPostActiveListingSearchType.PLAYER, player, com.runehive.game.world.World.schedule(), and searchExistingListing().

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selectItemToList()

void com.runehive.content.tradingpost.TradingPost.selectItemToList ( Item item)

Definition at line 531 of file TradingPost.java.

531 {
532 if(!item.isTradeable() || item.getId() == 995) {
533 player.send(new SendMessage("You cannot list this item."));
534 return;
535 }
536 listingToAdd = new TradingPostListing(item.getId(), player.getName());
537 player.send(new SendItemOnInterface(80153,item));
538 player.send(new SendString(item.getDefinition().getName(),80160));
539 updatePriceStrings();
540 updateQuantityString();
541 }
final int getId()
Gets the identification of this item.
Definition Item.java:324
ItemDefinition getDefinition()
Gets the item definition for the item identifier.
Definition Item.java:315

References com.runehive.game.world.items.Item.getDefinition(), com.runehive.game.world.items.Item.getId(), com.runehive.game.world.items.ItemDefinition.getName(), com.runehive.game.world.items.Item.isTradeable(), listingToAdd, player, updatePriceStrings(), and updateQuantityString().

Here is the call graph for this function:

◆ sendItemHistoryData()

void com.runehive.content.tradingpost.TradingPost.sendItemHistoryData ( List< ItemHistory > itemHistories)

Definition at line 236 of file TradingPost.java.

236 {
237 for(int i = 0; i < MAX_LISTINGS_SHOWN; i++) {
238 if(itemHistories.size() > i) {
239 ItemHistory ih = itemHistories.get(i);
240 player.send(new SendString(ItemDefinition.get(ih.getItemId()).getName(),80753+i));
241 player.send(new SendString(Utility.formatDigits(ih.getPrice()),80803+i));
242 player.send(new SendString(ih.getSeller(),80853+i));
243 player.send(new SendString(ih.getBuyer(),80903+i));
244 } else {
245 player.send(new SendString("",80753+i));
246 player.send(new SendString("",80803+i));
247 player.send(new SendString("",80853+i));
248 player.send(new SendString("",80903+i));
249 }
250 }
251
252 player.send(new SendItemOnInterface(80953, getItemArrayFromItemHistory(itemHistories)));
253 player.interfaceManager.open(HISTORY_PAGE_INTERFACE_ID);
254 }

References com.runehive.util.Utility.formatDigits(), com.runehive.game.world.items.ItemDefinition.get(), com.runehive.content.tradingpost.ItemHistory.getBuyer(), getItemArrayFromItemHistory(), com.runehive.content.tradingpost.ItemHistory.getItemId(), com.runehive.game.world.items.ItemDefinition.getName(), com.runehive.content.tradingpost.ItemHistory.getPrice(), com.runehive.content.tradingpost.ItemHistory.getSeller(), HISTORY_PAGE_INTERFACE_ID, itemHistories, MAX_LISTINGS_SHOWN, and player.

Referenced by handleButtonClick(), and searchItemHistoryInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendOverviewWidgetVisibility()

void com.runehive.content.tradingpost.TradingPost.sendOverviewWidgetVisibility ( int i,
boolean isHidden )
private

Definition at line 639 of file TradingPost.java.

639 {
640 player.send(new SendInterfaceVisibility(80032+i,isHidden));
641 player.send(new SendInterfaceVisibility(80052+i,isHidden));
642 player.send(new SendInterfaceVisibility(80072+i,isHidden));
643 player.send(new SendInterfaceVisibility(80112+i,isHidden));
644 }

References player.

Referenced by updateExistingListingsWidgets().

Here is the caller graph for this function:

◆ sort()

void com.runehive.content.tradingpost.TradingPost.sort ( )
private

Definition at line 282 of file TradingPost.java.

282 {
283 if(displayedPageListings == null) return;
284 if(tradingPostSort == null) return;
285
286 page = 0;
287
288 searchedListings = searchedListings
289 .stream()
290 .sorted(Comparator.comparingInt(
291 (tradingPostSort.postSortType == TradingPostSortType.HIGHEST_PRICE || tradingPostSort.postSortType == TradingPostSortType.LOWEST_PRICE)
292 ? TradingPostListing::getPrice
293 : TradingPostListing::getAmountLeft))
294 .collect(Collectors.toList());
295
296
297 if(tradingPostSort.postSortType == TradingPostSortType.HIGHEST_QUANTITY || tradingPostSort.postSortType == TradingPostSortType.HIGHEST_PRICE) {
298 Collections.reverse(searchedListings);
299 }
300
301 updateBuyingPageWidgets(getPageListings(searchedListings));
302 }

References displayedPageListings, com.runehive.content.tradingpost.TradingPostListing.getAmountLeft(), getPageListings(), com.runehive.content.tradingpost.TradingPostListing.getPrice(), com.runehive.content.tradingpost.TradingPost.TradingPostSortType.HIGHEST_PRICE, com.runehive.content.tradingpost.TradingPost.TradingPostSortType.HIGHEST_QUANTITY, com.runehive.content.tradingpost.TradingPost.TradingPostSortType.LOWEST_PRICE, page, searchedListings, tradingPostSort, and updateBuyingPageWidgets().

Referenced by sortPrice(), and sortQuantity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sortPrice()

void com.runehive.content.tradingpost.TradingPost.sortPrice ( )
private

Definition at line 304 of file TradingPost.java.

304 {
305 tradingPostSort = tradingPostSort != null ? tradingPostSort.setPostSortType(
306 tradingPostSort.postSortType == TradingPostSortType.HIGHEST_PRICE
307 ? TradingPostSortType.LOWEST_PRICE
308 : TradingPostSortType.HIGHEST_PRICE
309 ) : new TradingPostActiveListingSort(TradingPostSortType.LOWEST_PRICE);
310
311 sort();
312 }

References com.runehive.content.tradingpost.TradingPost.TradingPostSortType.HIGHEST_PRICE, com.runehive.content.tradingpost.TradingPost.TradingPostSortType.LOWEST_PRICE, sort(), and tradingPostSort.

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sortQuantity()

void com.runehive.content.tradingpost.TradingPost.sortQuantity ( )

Definition at line 314 of file TradingPost.java.

314 {
315 tradingPostSort = tradingPostSort != null ? tradingPostSort.setPostSortType(
316 tradingPostSort.postSortType == TradingPostSortType.HIGHEST_QUANTITY
317 ? TradingPostSortType.LOWEST_QUANTITY
318 : TradingPostSortType.HIGHEST_QUANTITY
319 ) : new TradingPostActiveListingSort(TradingPostSortType.HIGHEST_QUANTITY);
320
321 sort();
322 }

References com.runehive.content.tradingpost.TradingPost.TradingPostSortType.HIGHEST_QUANTITY, com.runehive.content.tradingpost.TradingPost.TradingPostSortType.LOWEST_QUANTITY, sort(), and tradingPostSort.

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ testData()

void com.runehive.content.tradingpost.TradingPost.testData ( )

Definition at line 857 of file TradingPost.java.

857 {
858 int addCounter = 0;
859 for(int i = 0; i < 1000; i++) {
860 ItemDefinition def = ItemDefinition.DEFINITIONS[new Random().nextInt(ItemDefinition.DEFINITIONS.length)];
861 if(def != null) {
862 TradingPostListing listing = new TradingPostListing(def.getId(), "John"+i);
863 listing.setInitialQuantity(i+1);
864 listing.setPrice(i+1);
865 allListings.add(listing);
866 addCounter++;
867 System.out.println("Adding listing: " + addCounter);
868 }
869 }
870 }

References allListings, com.runehive.game.world.items.ItemDefinition.DEFINITIONS, com.runehive.content.tradingpost.TradingPostListing.setInitialQuantity(), and com.runehive.content.tradingpost.TradingPostListing.setPrice().

Here is the call graph for this function:

◆ toggleBuyingPageWidgetVisibility()

void com.runehive.content.tradingpost.TradingPost.toggleBuyingPageWidgetVisibility ( int i,
boolean isHidden )
private

Definition at line 481 of file TradingPost.java.

481 {
482 player.send(new SendInterfaceVisibility(80214+i, isHidden));
483 player.send(new SendInterfaceVisibility(80264+i, isHidden));
484 player.send(new SendInterfaceVisibility(80314+i, isHidden));
485 player.send(new SendInterfaceVisibility(80364+i, isHidden));
486 player.send(new SendInterfaceVisibility(80414+i, isHidden));
487 player.send(new SendInterfaceVisibility(80464+i, isHidden));
488 player.send(new SendInterfaceVisibility(80564+i, isHidden));
489 }

References player.

Referenced by updateBuyingPageWidgets().

Here is the caller graph for this function:

◆ toggleSellingOverlayVisibilityAndOpen()

void com.runehive.content.tradingpost.TradingPost.toggleSellingOverlayVisibilityAndOpen ( boolean isHidden)
private

Definition at line 491 of file TradingPost.java.

491 {
492 if(isHidden) {
493 player.interfaceManager.close();
494 }
495 player.interfaceManager.open(OVERVIEW_INTERFACE_ID);
496 player.send(new SendInterfaceVisibility(80146, isHidden));
497 }

References OVERVIEW_INTERFACE_ID, and player.

Referenced by handleButtonClick(), openOverviewInterface(), and openSellingOverlay().

Here is the caller graph for this function:

◆ updateBuyingPageWidgets()

void com.runehive.content.tradingpost.TradingPost.updateBuyingPageWidgets ( List< TradingPostListing > listings)
private

Definition at line 460 of file TradingPost.java.

460 {
461 displayedPageListings = listings;
462
463 for(int i = 0; i < MAX_LISTINGS_SHOWN; i++) {
464 if(displayedPageListings.size() > i) {
465 TradingPostListing listing = displayedPageListings.get(i);
466 player.send(new SendString(ItemDefinition.get(listing.getItemId()).getName(),80214+i));
467 player.send(new SendString(Utility.formatDigits(listing.getAmountLeft()*listing.getPrice()),80264+i));
468 player.send(new SendString("= " + Utility.formatDigits(listing.getPrice()) + " (ea)",80314+i));
469 player.send(new SendString(listing.getSeller(),80364+i));
470 toggleBuyingPageWidgetVisibility(i,false);
471 } else {
472 toggleBuyingPageWidgetVisibility(i, true);
473 }
474 }
475
476 player.send(new SendString("Page: " + (page+1),80615));
477 player.send(new SendItemOnInterface(80614, getItemArrayFromActiveListings(displayedPageListings)));
478 player.send(new SendScrollbar(80211, Math.max(238, displayedPageListings.size()*34)));
479 }

References displayedPageListings, com.runehive.util.Utility.formatDigits(), com.runehive.game.world.items.ItemDefinition.get(), com.runehive.content.tradingpost.TradingPostListing.getAmountLeft(), getItemArrayFromActiveListings(), com.runehive.content.tradingpost.TradingPostListing.getItemId(), com.runehive.game.world.items.ItemDefinition.getName(), com.runehive.content.tradingpost.TradingPostListing.getPrice(), com.runehive.content.tradingpost.TradingPostListing.getSeller(), MAX_LISTINGS_SHOWN, page, player, and toggleBuyingPageWidgetVisibility().

Referenced by addSearchResultsAndUpdateInterface(), nextPage(), previousPage(), and sort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateCofferAmountWidget()

void com.runehive.content.tradingpost.TradingPost.updateCofferAmountWidget ( )

Definition at line 127 of file TradingPost.java.

127 {
128 getOrMakeNewCofferIfNotExists(player.getName(), coffer -> {
129 player.send(new SendString(Utility.formatDigits(coffer.getAmount()), 80005));
130 });
131 }

References getOrMakeNewCofferIfNotExists(), and player.

Referenced by openOverviewInterface(), and withdrawFromCoffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateExistingListingsList()

void com.runehive.content.tradingpost.TradingPost.updateExistingListingsList ( )
private

Definition at line 593 of file TradingPost.java.

593 {
594 myListings = getListingsByName(player.getName());
595 }

References getListingsByName(), myListings, and player.

Referenced by confirmToAddListing(), and openOverviewInterface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateExistingListingsWidgets()

void com.runehive.content.tradingpost.TradingPost.updateExistingListingsWidgets ( )
private

Definition at line 622 of file TradingPost.java.

622 {
623 player.send(new SendItemOnInterface(80132, getItemArrayFromActiveListings(myListings)));
624
625 for(int i = 0; i < MAX_LISTING_SIZE; i++) {
626 if(myListings.size() > i) {
627 TradingPostListing tradingPostListing = myListings.get(i);
628 sendOverviewWidgetVisibility(i,false);
629 player.send(new SendString(tradingPostListing.getAmountSold() + "/" + tradingPostListing.getInitialQuantity(), 80112+i));
630 player.send(new SendProgressBar(80032+i, ((tradingPostListing.getAmountSold() * 100) / tradingPostListing.getInitialQuantity())));
631 } else {
632 sendOverviewWidgetVisibility(i,true);
633 }
634 }
635
636 player.send(new SendScrollbar(80029, Math.max(38*myListings.size(), 157)));
637 }

References com.runehive.content.tradingpost.TradingPostListing.getAmountSold(), com.runehive.content.tradingpost.TradingPostListing.getInitialQuantity(), getItemArrayFromActiveListings(), MAX_LISTING_SIZE, myListings, player, and sendOverviewWidgetVisibility().

Referenced by confirmToAddListing(), and openOverviewInterface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updatePriceStrings()

void com.runehive.content.tradingpost.TradingPost.updatePriceStrings ( )

Definition at line 543 of file TradingPost.java.

543 {
544 if(listingToAdd == null) return;
545 player.send(new SendString("Price: @gre@" + Utility.formatDigits(listingToAdd.getPrice()), 80161));
546 player.send(new SendString("Total: @gre@" + Utility.formatDigits(listingToAdd.getPrice()*listingToAdd.getInitialQuantity()), 80163));
547 }

References com.runehive.util.Utility.formatDigits(), listingToAdd, and player.

Referenced by com.runehive.content.tradingpost.TradingPostListing.checkAndUpdate(), com.runehive.content.tradingpost.TradingPostListing.removeQuantity(), selectItemToList(), and com.runehive.content.tradingpost.TradingPostListing.setPrice().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateQuantityString()

void com.runehive.content.tradingpost.TradingPost.updateQuantityString ( )

Definition at line 549 of file TradingPost.java.

549 {
550 if(listingToAdd == null) return;
551 player.send(new SendString("Quantity: @gre@" + listingToAdd.getInitialQuantity(), 80162));
552 player.send(new SendString(listingToAdd.getInitialQuantity(), 80173));
553 }

References listingToAdd, and player.

Referenced by com.runehive.content.tradingpost.TradingPostListing.checkAndUpdate(), com.runehive.content.tradingpost.TradingPostListing.removeQuantity(), and selectItemToList().

Here is the caller graph for this function:

◆ withdrawFromCoffer()

void com.runehive.content.tradingpost.TradingPost.withdrawFromCoffer ( )
private

Definition at line 325 of file TradingPost.java.

325 {
326 getOrMakeNewCofferIfNotExists(player.getName(), coffer -> {
327 if (coffer.getAmount() == 0) {
328 return;
329 }
330
331 player.send(new SendInputAmount("How much gold would you like to withdraw?", 10, input -> {
332 int amount = Integer.parseInt(input);
333
334 if (amount > coffer.getAmount()) {
335 amount = (int) coffer.getAmount();
336 }
337
338 if (amount > coffer.getAmount()) {
339 return;
340 }
341
342 if (player.inventory.add(CURRENCY_ID, amount)) {
343 coffer.subtractAmount(amount);
344 updateCofferAmountWidget();
345 saveCoffer(coffer);
346 } else {
347 player.send(new SendMessage("You do not have enough inventory spaces to withdraw this gold"));
348 }
349
350 }));
351 });
352 }

References CURRENCY_ID, getOrMakeNewCofferIfNotExists(), player, saveCoffer(), and updateCofferAmountWidget().

Referenced by handleButtonClick().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ acdat

final AhoCorasickDoubleArrayTrie<String> com.runehive.content.tradingpost.TradingPost.acdat = new AhoCorasickDoubleArrayTrie<>()
private

Definition at line 45 of file TradingPost.java.

Referenced by searchItemHistoryInput().

◆ allCoffers

final Map<String, Coffer> com.runehive.content.tradingpost.TradingPost.allCoffers = Collections.synchronizedMap(new HashMap<>())
staticprivate

Hashmap containing the coffers <PlayerName, Coffer>

Definition at line 55 of file TradingPost.java.

Referenced by getCoffer(), and getOrMakeNewCofferIfNotExists().

◆ allListings

final List<TradingPostListing> com.runehive.content.tradingpost.TradingPost.allListings = new ArrayList<>()
staticprivate

A list containing all the trading post listings.

Definition at line 50 of file TradingPost.java.

Referenced by confirmToAddListing(), delist(), getListingsByName(), getSearchResults(), handleBuyingButton(), loadAllListings(), purchase(), and testData().

◆ BUYING_PAGE_INTERFACE_ID

final int com.runehive.content.tradingpost.TradingPost.BUYING_PAGE_INTERFACE_ID = 80174
static

◆ CURRENCY_ID

final int com.runehive.content.tradingpost.TradingPost.CURRENCY_ID = 995
staticprivate

Definition at line 42 of file TradingPost.java.

Referenced by buyingDialogueOptions(), purchase(), and withdrawFromCoffer().

◆ displayedPageListings

List<TradingPostListing> com.runehive.content.tradingpost.TradingPost.displayedPageListings = new ArrayList<>()
private

The displayed listings on the buying page.

Definition at line 90 of file TradingPost.java.

Referenced by cleanUp(), handleBuyingButton(), purchase(), sort(), and updateBuyingPageWidgets().

◆ HISTORY_PAGE_INTERFACE_ID

final int com.runehive.content.tradingpost.TradingPost.HISTORY_PAGE_INTERFACE_ID = 80616
staticprivate

Definition at line 39 of file TradingPost.java.

Referenced by handleButtonClick(), and sendItemHistoryData().

◆ itemHistories

final Map<String, List<ItemHistory> > com.runehive.content.tradingpost.TradingPost.itemHistories = new HashMap<>()
staticprivate

Contains a list of the last 50 sold of each item.

Definition at line 95 of file TradingPost.java.

Referenced by addToItemHistory(), loadItemHistory(), saveAllItemHistory(), searchItemHistoryInput(), and sendItemHistoryData().

◆ listingToAdd

TradingPostListing com.runehive.content.tradingpost.TradingPost.listingToAdd
private

◆ listingToBuy

TradingPostListing com.runehive.content.tradingpost.TradingPost.listingToBuy
private

The listing that the player selects in the buying page.

Definition at line 70 of file TradingPost.java.

Referenced by buyingDialogueOptions(), cleanUp(), handleBuyingButton(), and purchase().

◆ logger

final Logger com.runehive.content.tradingpost.TradingPost.logger = LoggerFactory.getLogger(TradingPost.class)
staticprivate

Definition at line 35 of file TradingPost.java.

Referenced by getCoffer(), loadAllListings(), saveCoffer(), and saveListings().

◆ MAX_LISTING_SIZE

final int com.runehive.content.tradingpost.TradingPost.MAX_LISTING_SIZE = 20
staticprivate

Definition at line 41 of file TradingPost.java.

Referenced by getSlotSizeByDonatorRank(), and updateExistingListingsWidgets().

◆ MAX_LISTINGS_SHOWN

final int com.runehive.content.tradingpost.TradingPost.MAX_LISTINGS_SHOWN = 50
staticprivate

Definition at line 40 of file TradingPost.java.

Referenced by getPageListings(), sendItemHistoryData(), and updateBuyingPageWidgets().

◆ myListings

List<TradingPostListing> com.runehive.content.tradingpost.TradingPost.myListings = new ArrayList<>()
private

List containing the players existing listings/offers.

Definition at line 60 of file TradingPost.java.

Referenced by confirmToAddListing(), delist(), handleDismissListingButton(), updateExistingListingsList(), and updateExistingListingsWidgets().

◆ OVERVIEW_INTERFACE_ID

final int com.runehive.content.tradingpost.TradingPost.OVERVIEW_INTERFACE_ID = 80000
staticprivate

◆ page

int com.runehive.content.tradingpost.TradingPost.page
private

The page # of the buying interface.

Definition at line 110 of file TradingPost.java.

Referenced by cleanUp(), getPageListings(), nextPage(), previousPage(), sort(), and updateBuyingPageWidgets().

◆ player

◆ playersItemHistory

final List<ItemHistory> com.runehive.content.tradingpost.TradingPost.playersItemHistory = new ArrayList<>()
private

contains last 50 players buying history

Definition at line 105 of file TradingPost.java.

Referenced by addToItemHistory(), getPlayersItemHistory(), and handleButtonClick().

◆ recentlySoldItems

final List<ItemHistory> com.runehive.content.tradingpost.TradingPost.recentlySoldItems = new ArrayList<>()
staticprivate

contains the last 50 sold items on the trading post

Definition at line 100 of file TradingPost.java.

Referenced by addToItemHistory(), handleButtonClick(), loadRecentItemHistory(), saveRecentHistory(), and searchItemHistoryInput().

◆ searchedListings

List<TradingPostListing> com.runehive.content.tradingpost.TradingPost.searchedListings = new ArrayList<>()
private

The current searched listings.

Definition at line 85 of file TradingPost.java.

Referenced by addSearchResultsAndUpdateInterface(), cleanUp(), nextPage(), previousPage(), purchase(), and sort().

◆ TAX_RATE

final int com.runehive.content.tradingpost.TradingPost.TAX_RATE = 10
staticprivate

Definition at line 43 of file TradingPost.java.

Referenced by addToCoffer().

◆ tradingPostSearch

TradingPostActiveListingSearch com.runehive.content.tradingpost.TradingPost.tradingPostSearch
private

The current item or player search.

Definition at line 75 of file TradingPost.java.

Referenced by cleanUp(), displayMostRecentListings(), getSearchResults(), purchase(), refresh(), and searchExistingListing().

◆ tradingPostSort

TradingPostActiveListingSort com.runehive.content.tradingpost.TradingPost.tradingPostSort
private

The current sort of the buyable listings.

Definition at line 80 of file TradingPost.java.

Referenced by cleanUp(), sort(), sortPrice(), and sortQuantity().


The documentation for this class was generated from the following file: