scalata.application.usecases.playerusecases
Members list
Type members
Classlikes
Executes a player attack in the chosen direction.
Executes a player attack in the chosen direction.
==== Algorithm ====
-
Compute a reach vector whose length equals the player’s
reachstat. -
Build the inclusive line of points from the player’s position to the target tile (
rangeTo). -
For every enemy in the current room:
-
If the enemy is alive and its position lies on the line, apply
player.attack. -
Return an updated
GameSessionwrapped inGameResult.success.
Failure modes If the room referenced by GameState.currentRoom is missing, an IllegalStateException is thrown (world corruption guard).
Attributes
- Supertypes
Handles the “interact” command (pick up / open / read whatever lies on the tile immediately in front of the player).
Handles the “interact” command (pick up / open / read whatever lies on the tile immediately in front of the player).
==== Flow ====
- Compute the target coordinate by adding
direction.vectorto the player’s current position. - If an item is present, delegate to its
interact(GameSession)method and propagate the result. - If the tile is empty, return
GameResult.error(GameError.ItemNotPresent).
The method is pure: all updates are returned in a new GameSession; no in-place mutation occurs.
Attributes
- Supertypes
Handles the “use item” command.
Handles the “use item” command.
- Looks up the item by
itemNamein the player’s inventory. - Delegates to the
Usabletype-class to apply the effect (Potion, Weapon, Dust, …). - Updates the player inside the
Worldand returns aGameResult.successwrapping the newGameSession. - If the player does not own the item, returns
GameResult.Error(GameError.ItemNotOwned).
Attributes
- Supertypes
Handles a single movement command issued by the player.
Handles a single movement command issued by the player.
==== Decision tree ====
-
Simple step – if the target tile lies inside the current room and is free of living enemies/items, update the player’s position.
-
Door transition – when the tile matches the current door and the room contains an exit in that direction, move the player to the neighbouring room, advance
GameState.currentRoomand push any enemy standing on the entrance one tile inward. -
Invalid – in all other cases return
GameError.InvalidInput.
Attributes
- Supertypes