public void RefreshTargetView(MoveDirection dir) { var offset = MapController.CalculateMoveOffset(dir, Target); Target += offset; if (MapController.ValidCoords(new Vector3Int(Target.x, Target.y, 0))) { var targets = BresenhamUtils.CalculateLine(EntityController.Player.Coords, Target); EntityController.Player.BattleTrait.GetReachableStateForCoords(targets, out List <bool> targetOccluded); var targetPositions = targets.ConvertAll(x => MapController.WorldFromCoords(x)); _viewInstance.RefreshLine(targetPositions, targetOccluded); } else { Target -= offset; } }
public int Update(PlayStateContext contextData, out bool timeWillPass) { if (Input.GetKeyDown(KeyCode.F4)) { SceneManager.LoadScene(0); } PlayerActionStateContext actionData = contextData as PlayerActionStateContext; BaseInputController input = actionData.Input; IMapController map = actionData.Map; IEntityController entityController = actionData.EntityController; Player player = entityController.Player; int nextPlayState = GameController.PlayStates.Action; timeWillPass = false; if (input.IdleTurn) { timeWillPass = true; actionData.Events.Player.SendIdleTurn(); return(GameController.PlayStates.Action); } if (input.RangeStart && player.BattleTrait.RangedAttack) { timeWillPass = false; return(GameController.PlayStates.RangePrepare); } Vector2Int playerCoords = map.CoordsFromWorld(player.transform.position); // GAME SPECIFIC if (HandleExtendedActions(actionData, out timeWillPass, out nextPlayState)) { return(nextPlayState); } Vector2Int offset = map.CalculateMoveOffset(input.MoveDir, playerCoords); if (offset != Vector2Int.zero) { var newPlayerCoords = playerCoords + offset; if (!player.ValidMapCoords(newPlayerCoords)) { timeWillPass = actionData.BumpingWallsWillSpendTurn; } else { timeWillPass = true; // Check interactions bool canMove = true; // Blockers: var blocker = FindBlockingEntityAt(entityController, newPlayerCoords); if (blocker != null) { if (blocker.BlockingTrait.TryUnlock(player)) { player.Coords = newPlayerCoords; } return(nextPlayState); } bool exit = HandleAdditionalMoveInteractions(actionData, newPlayerCoords, ref nextPlayState, ref canMove); if (exit) { if (canMove) { player.Coords = newPlayerCoords; } return(nextPlayState); } if (player.SeesHostilesAtCoords(newPlayerCoords)) { bool allDefeated = player.AttackCoords(newPlayerCoords); canMove = allDefeated; } if (canMove) { player.Coords = newPlayerCoords; } } } // Quick Inventory actions: int inventoryIdx = System.Array.FindIndex(input.NumbersPressed, x => x); if (inventoryIdx != -1) { bool dropModifier = input.ShiftPressed; } return(GameController.PlayStates.Action); }