Class Shop


  • public class Shop
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Shop()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean buy​(int itemId, int option)
      Buys an item based on its ID.
      boolean buy​(java.lang.String itemName, int option)
      Buys an item based on its name.
      boolean buy​(java.util.function.Predicate<KSItem> filter, int option)
      Attempts to buy an item from the shop that matches a given filter.
      boolean buy​(KSItem item, int option)
      Buys an item based on the provided KSItem object.
      void close()
      Closes the shop interface by simulating the pressing of the ESC key.
      boolean isOpen()
      Checks if the shop interface is currently open.
      ItemQuery query()
      Searches for items in the shop.
      boolean sell​(int itemId, int option)
      Sells an item based on its ID.
      boolean sell​(java.lang.String itemName, int option)
      Sells an item based on its name.
      boolean sell​(java.util.function.Predicate<KSItem> filter, int option)
      Attempts to sell an item from the inventory that matches a given filter.
      boolean sell​(KSItem item, int option)
      Sells an item based on the provided KSItem object.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Shop

        public Shop()
    • Method Detail

      • query

        public ItemQuery query()
        Searches for items in the shop. If the shop interface has been updated since the last search, it refreshes the item list to ensure accuracy.
        Returns:
        an ItemQuery containing the shop's items.
      • isOpen

        public boolean isOpen()
        Checks if the shop interface is currently open.
        Returns:
        true if the shop interface is open, false otherwise.
      • buy

        public boolean buy​(java.util.function.Predicate<KSItem> filter,
                           int option)
        Attempts to buy an item from the shop that matches a given filter.
        Parameters:
        filter - - Predicate to match the item to buy
        option - - The buy option (e.g., Buy 1, Buy 10)
        Returns:
        true if the item is bought successfully, false otherwise
      • buy

        public boolean buy​(KSItem item,
                           int option)
        Buys an item based on the provided KSItem object.
        Parameters:
        item - the KSItem object representing the item to buy.
        option - the menu option to use for the purchase.
        Returns:
        true if the item was successfully purchased; false otherwise.
      • buy

        public boolean buy​(java.lang.String itemName,
                           int option)
        Buys an item based on its name.
        Parameters:
        itemName - the name of the item to buy (case-insensitive).
        option - the menu option to use for the purchase.
        Returns:
        true if the item was successfully purchased; false otherwise.
      • buy

        public boolean buy​(int itemId,
                           int option)
        Buys an item based on its ID.
        Parameters:
        itemId - the ID of the item to buy.
        option - the menu option to use for the purchase.
        Returns:
        true if the item was successfully purchased; false otherwise.
      • sell

        public boolean sell​(java.util.function.Predicate<KSItem> filter,
                            int option)
        Attempts to sell an item from the inventory that matches a given filter.
        Parameters:
        filter - - Predicate to match the item to sell
        option - - The sell option (e.g., Sell 1, Sell 10)
        Returns:
        true if the item is sold successfully, false otherwise
      • sell

        public boolean sell​(KSItem item,
                            int option)
        Sells an item based on the provided KSItem object.
        Parameters:
        item - the KSItem object representing the item to sell.
        option - the menu option to use for the sale.
        Returns:
        true if the item was successfully sold; false otherwise.
      • sell

        public boolean sell​(java.lang.String itemName,
                            int option)
        Sells an item based on its name.
        Parameters:
        itemName - the name of the item to sell (case-insensitive).
        option - the menu option to use for the sale.
        Returns:
        true if the item was successfully sold; false otherwise.
      • sell

        public boolean sell​(int itemId,
                            int option)
        Sells an item based on its ID.
        Parameters:
        itemId - the ID of the item to sell.
        option - the menu option to use for the sale.
        Returns:
        true if the item was successfully sold; false otherwise.
      • close

        public void close()
        Closes the shop interface by simulating the pressing of the ESC key.