Class DraftContext

java.lang.Object
com.hiddenswitch.spellsource.draft.DraftContext
All Implemented Interfaces:
Consumer<io.vertx.core.Handler<io.vertx.core.AsyncResult<DraftContext>>>

public class DraftContext extends Object implements Consumer<io.vertx.core.Handler<io.vertx.core.AsyncResult<DraftContext>>>
Stores data and logic relating to drafting cards.

This context does not itself start a game. Use a GameContext for that.

Create a draft context using DraftContext(), then set its behaviour using setBehaviour(DraftBehaviour). The default behaviour never replies to any choices.

To start the draft, call accept(Handler) with a handler when the draft is done.

Retrieve the current state of the draft using getPublicState().

See Also:
  • Constructor Details

    • DraftContext

      public DraftContext()
      Creates a new draft context with a NullDraftBehaviour as the default.
  • Method Details

    • accept

      public void accept(io.vertx.core.Handler<io.vertx.core.AsyncResult<DraftContext>> done)
      Starts a draft.
      Specified by:
      accept in interface Consumer<io.vertx.core.Handler<io.vertx.core.AsyncResult<DraftContext>>>
      Parameters:
      done - Called when all the draft choices have been made and the deck the player has been constructing is ready to play.
    • selectHero

      protected void selectHero()
    • onHeroSelected

      public void onHeroSelected(io.vertx.core.AsyncResult<String> choice)
      This handler should be called with the player's champion selection.
      Parameters:
      choice - The champion selected by the player.
    • selectCard

      protected void selectCard()
    • onCardSelected

      public void onCardSelected(io.vertx.core.AsyncResult<Integer> selectedCardResult)
      This handler should be called whenever the player makes a card choice.
      Parameters:
      selectedCardResult - The index of the card chosen in PublicDraftState.getCurrentCardChoices().
    • getLogic

      public DraftLogic getLogic()
      Gets the draft logic.
      Returns:
    • setLogic

      public void setLogic(DraftLogic logic)
    • getPublicState

      public PublicDraftState getPublicState()
      Gets the public draft state. This state is safe to share with the end user and does not leak any information that would advantage the player unfairly in the drafting process.
      Returns:
    • setPublicState

      public void setPublicState(PublicDraftState publicState)
    • getPrivateState

      public PrivateDraftState getPrivateState()
      Gets the private draft state. In practice, this is the pre-generated list of cards the player will see, according to the current rules in DraftLogic. This should never be shared with an end-user, since it can be used to cheat.
      Returns:
    • setPrivateState

      public void setPrivateState(PrivateDraftState privateState)
    • getBehaviour

      public DraftBehaviour getBehaviour()
      Gets the behaviour to which draft requests are delegated.
      Returns:
    • setBehaviour

      public void setBehaviour(DraftBehaviour behaviour)
      Sets the behaviour. Beware of the NullDraftBehaviour--it does not ever call its callbacks, so the DraftContext is never completed by it.
      Parameters:
      behaviour -
    • withLogic

      public DraftContext withLogic(DraftLogic logic)
    • withPublicState

      public DraftContext withPublicState(PublicDraftState publicState)
    • withPrivateState

      public DraftContext withPrivateState(PrivateDraftState privateState)
    • withBehaviour

      public DraftContext withBehaviour(DraftBehaviour behaviour)
    • notifyPublicStateChanged

      protected void notifyPublicStateChanged()