Class DirectInput


  • public final class DirectInput
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void send​(MenuAction action)
      Sends an action directly to the game, performing no validation as it does, to be processed in the next game cycle.
      static void sendItemUseOn​(@NonNull SpriteItem item, @NonNull Interactable target)
      Utility method that combines setSelectedItem(SpriteItem) and then send(MenuAction).
      static void sendMovement​(int localX, int localY)
      Sends a movement action directly to the client where the parameters are the x-offset and y-offset relative to the scene base (not to be confused with the current map region base).
      static void sendMovement​(Locatable locatable)  
      static void sendMovement​(Coordinate.RegionOffset offset)  
      static void sendSpellCastOn​(@NonNull Spell spell, @NonNull Interactable target)
      Utility method that combines setSelectedSpell(Spell) and then send(MenuAction).
      static boolean setSelectedItem​(SpriteItem item)
      Directly sets the selected InterfaceComponent for the provided SpriteItem, without verifying that the InterfaceComponent currently contains the item. Be careful when performing subsequent actions, as there is no guarantee the item will still exist once it is selected.
      static boolean setSelectedSpell​(Spell spell)
      Directly selects the InterfaceComponent for the provided Spell, without verifying that the Spell can actually be cast.
      • Methods inherited from class java.lang.Object

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

      • send

        public static void send​(MenuAction action)
        Sends an action directly to the game, performing no validation as it does, to be processed in the next game cycle.

        Care should be taken when constructing MenuActions to ensure that they are valid, for example by comparing against "real" actions using the MenuInteractionListener. Failure to do so could result in instability in the game client.

        The resulting red-click visible in-game for entity interactions is purely visual, and does not represent an actual mouse event in-game, and will be drawn in the top-left of the screen if the entity is not visible within the viewport.

        Examples:

             //Sends the "Drop" action for a SpriteItem
             final SpriteItem item = ...;
             final var action = MenuAction.forSpriteItem(item, "Drop");
             if (action != null) {
                 DirectInput.send(action);
             }
        
             //Sends the "top" action for an InterfaceComponent
             final InterfaceComponent component = ...;
             final var action = MenuAction.forInterfaceComponent(component, 0);
             if (action != null) {
                 DirectInput.send(action);
             }
         
      • sendMovement

        public static void sendMovement​(Locatable locatable)
      • sendMovement

        public static void sendMovement​(int localX,
                                        int localY)
        Sends a movement action directly to the client where the parameters are the x-offset and y-offset relative to the scene base (not to be confused with the current map region base).

        It is almost certainly a better option to use sendMovement(Locatable) and allowing the API to do the offset calculations.

        See Also:
        Region.getBase()
      • setSelectedItem

        public static boolean setSelectedItem​(SpriteItem item)
        Directly sets the selected InterfaceComponent for the provided SpriteItem, without verifying that the InterfaceComponent currently contains the item. Be careful when performing subsequent actions, as there is no guarantee the item will still exist once it is selected.
      • setSelectedSpell

        public static boolean setSelectedSpell​(Spell spell)
        Directly selects the InterfaceComponent for the provided Spell, without verifying that the Spell can actually be cast.