internal void UpdatePlayerRemainingMovement(ActorData actor, bool send = true) { ActorTurnSM turnSm = actor.gameObject.GetComponent <ActorTurnSM>(); ActorController actorController = actor.gameObject.GetComponent <ActorController>(); ActorMovement actorMovement = actor.GetActorMovement(); float movementCost = GetActorMovementCost(actor, out float lastStepCost); bool cannotExceedMaxMovement = GameplayData.Get()?.m_movementMaximumType == GameplayData.MovementMaximumType.CannotExceedMax; List <ActorTargeting.AbilityRequestData> abilityRequest = actor.TeamSensitiveData_authority.GetAbilityRequestData(); bool abilitySet = !abilityRequest.IsNullOrEmpty() && abilityRequest[0].m_actionType != AbilityData.ActionType.INVALID_ACTION; actor.RemainingHorizontalMovement = actorMovement.CalculateMaxHorizontalMovement() - movementCost; actor.RemainingMovementWithQueuedAbility = abilitySet ? actor.RemainingHorizontalMovement : actorMovement.CalculateMaxHorizontalMovement(true) - movementCost; actor.QueuedMovementAllowsAbility = abilitySet || (cannotExceedMaxMovement ? actor.RemainingMovementWithQueuedAbility >= 0 : actor.RemainingMovementWithQueuedAbility + lastStepCost > 0); Log.Info($"UpdatePlayerMovement: Basic: {actor.m_postAbilityHorizontalMovement}/{actor.m_maxHorizontalMovement}, +", $"Remaining: {actor.RemainingMovementWithQueuedAbility}/{actor.RemainingHorizontalMovement}, " + $"Movement cost: {movementCost}, Ability set: {abilitySet}, Ability allowed: {actor.QueuedMovementAllowsAbility}, " + $"Movement max type: {GameplayData.Get()?.m_movementMaximumType}"); actorMovement.UpdateSquaresCanMoveTo(); if (send) { actorController.CallRpcUpdateRemainingMovement(actor.RemainingHorizontalMovement, actor.RemainingMovementWithQueuedAbility); } }
private BoardSquarePathInfo BackOff(ActorData actor, BoardSquarePathInfo pathEnd, HashSet <GridPos> occupiedSquares) { if (actor == null) { Log.Error($"Backoff failed because actor is null!"); return(null); } Log.Info($"Calculating backoff for {actor.DisplayName}"); BoardSquare dest = pathEnd.prev?.square ?? pathEnd.square; if (occupiedSquares.Contains(dest.GetGridPosition())) { bool diagMovementAllowed = GameplayData.Get().m_diagonalMovement != GameplayData.DiagonalMovement.Disabled; List <BoardSquare> neighbours = new List <BoardSquare>(8); Queue <BoardSquare> candidates = new Queue <BoardSquare>(); candidates.Enqueue(pathEnd.square); while (candidates.Count > 0) { BoardSquare s = candidates.Dequeue(); if (!occupiedSquares.Contains(s.GetGridPosition())) { dest = s; break; } neighbours.Clear(); if (!diagMovementAllowed) { Board.Get().GetStraightAdjacentSquares(s.x, s.y, ref neighbours); } else { Board.Get().GetAllAdjacentSquares(s.x, s.y, ref neighbours); } neighbours.Sort(delegate(BoardSquare a, BoardSquare b) { return(dest.HorizontalDistanceInWorldTo(a).CompareTo(dest.HorizontalDistanceInWorldTo(b))); }); foreach (var n in neighbours) { if (n.IsBoardHeight()) { candidates.Enqueue(n); } } } } if (occupiedSquares.Contains(dest.GetGridPosition())) { Log.Error($"Backoff failed to find a free square for {actor.DisplayName}!"); } occupiedSquares.Add(dest.GetGridPosition()); BoardSquarePathInfo result = actor.GetActorMovement().BuildPathTo_IgnoreBarriers(pathEnd.square, dest); result.heuristicCost += pathEnd.heuristicCost; // not actually correct but shouldn't matter result.moveCost += pathEnd.moveCost; result.m_moverBumpedFromClash = true; return(result); }