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()
.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(io.vertx.core.Handler<io.vertx.core.AsyncResult<DraftContext>> done) Starts a draft.Gets the behaviour to which draft requests are delegated.getLogic()
Gets the draft logic.Gets the private draft state.Gets the public draft state.protected void
void
onCardSelected
(io.vertx.core.AsyncResult<Integer> selectedCardResult) This handler should be called whenever the player makes a card choice.void
onHeroSelected
(io.vertx.core.AsyncResult<String> choice) This handler should be called with the player's champion selection.protected void
protected void
void
setBehaviour
(DraftBehaviour behaviour) Sets the behaviour.void
setLogic
(DraftLogic logic) void
setPrivateState
(PrivateDraftState privateState) void
setPublicState
(PublicDraftState publicState) withBehaviour
(DraftBehaviour behaviour) withLogic
(DraftLogic logic) withPrivateState
(PrivateDraftState privateState) withPublicState
(PublicDraftState publicState)
-
Constructor Details
-
DraftContext
public DraftContext()Creates a new draft context with aNullDraftBehaviour
as the default.
-
-
Method Details
-
accept
Starts a draft.- Specified by:
accept
in interfaceConsumer<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
This handler should be called with the player's champion selection.- Parameters:
choice
- The champion selected by the player.
-
selectCard
protected void selectCard() -
onCardSelected
This handler should be called whenever the player makes a card choice.- Parameters:
selectedCardResult
- The index of the card chosen inPublicDraftState.getCurrentCardChoices()
.
-
getLogic
Gets the draft logic.- Returns:
-
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:
-
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 inDraftLogic
. This should never be shared with an end-user, since it can be used to cheat.- Returns:
-
getBehaviour
Gets the behaviour to which draft requests are delegated.- Returns:
-
notifyPublicStateChanged
protected void notifyPublicStateChanged()
-