@Immutable public final class PlayerUtils extends Object
Modifier and Type | Method | Description |
---|---|---|
static boolean |
canPickup(Player player,
Food food,
Player.Hand hand) |
Determines whether the given player can pick up the given food piece,
with the given hand.
|
static Direction |
getArmDirection(Player player,
Player.Hand hand) |
Gets the direction of a player's arm.
|
static Vector |
getArmLocation(Player player,
Player.Hand hand) |
Gets the location of the player's arm.
|
static double |
getMoveMultiplier(double energy) |
Gets the multiplier for a player's movement, based on their energy.
|
static boolean |
isAgainstTable(Player player,
Table table,
boolean movingForward) |
Determines whether the given player is against the table.
|
static boolean |
isValidAction(Field field,
Player player,
Controller.Action action) |
Determines whether the given action is currently valid for the given
player.
|
public static boolean isValidAction(Field field, Player player, Controller.Action action)
There is one special case in which the result of this method can be misleading. If two players attempt to pick up the same food on the same turn, turn order is randomized, so one of them will be able to grab it and the other won't. Thus, if a controller returns one of the "pickup" actions because this method returns true, it may actually end up being an invalid action if another player picks up the food.
field
- the field that the player is playing onplayer
- the player on the field potentially performing the actionaction
- the action in questionNullPointerException
- if field or player is nullpublic static boolean canPickup(Player player, Food food, Player.Hand hand)
Player.REACH_DISTANCE
and an angle measurement of
Player.REACH_RANGE
, centered on the direction returned by
getArmDirection(Player, Hand)
.player
- the player attempting a "pickup" actionfood
- the food that the player may pick uphand
- the hand with which the player is attempting the pickupNullPointerException
- if player, food, or hand is nullpublic static boolean isAgainstTable(Player player, Table table, boolean movingForward)
Controller.Action.MOVE_FORWARD
, and if movingForward is false, this method
returns true if and only if the table would prevent the player from
performing and Controller.Action.MOVE_BACKWARD
.player
- the player in questiontable
- the table that the player may be againstmovingForward
- true if the player is moving forward, false if backwardNullPointerException
- if player or table is nullpublic static final Direction getArmDirection(Player player, Player.Hand hand)
Player.LEFT_ARM_DIRECTION
or
Player.RIGHT_ARM_DIRECTION
. The arm direction of a player is used
to determine where they can pickup food (see
canPickup(Player, Food, Hand)
) and where thrown food is spawened
(see getArmLocation(Player, Hand)
).player
- the player in questionhand
- the side of the player to checkNullPointerException
- if player or hand is nullpublic static final Vector getArmLocation(Player player, Player.Hand hand)
Player.REACH_DISTANCE
away from the player's center, in the
direction of getArmDirection(Player, Hand)
. Equivalently, this
is the location at which thrown food is spawned.player
- the player whose arm to checkhand
- the side of the player to checkNullPointerException
- if player or hand is nullpublic static double getMoveMultiplier(double energy)
Player.MAX_ENERGY
- 1energy
- the player's energy