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 void CmdGUITurnMessage(ActorTurnSM actorTurnSM, int msgEnum, int extraData) { ActorData actor = actorTurnSM.gameObject.GetComponent <ActorData>(); TurnMessage msg = (TurnMessage)msgEnum; if (!GameFlowData.Get().IsInDecisionState()) { Log.Info($"Recieved CmdGuiTurnMessage not in desicion state! {actor.DisplayName} {msg} ({extraData})"); return; } Log.Info($"CmdGuiTurnMessage {actor.DisplayName} {msg} ({extraData})"); if (msg == TurnMessage.CANCEL_BUTTON_CLICKED) { // TODO distinguish CANCEL button and ability cancelling // actor.TeamSensitiveData_authority.SetToggledAction(actionType, false); // if (DONE) make undone // else if (targeting action) set toggled action(false) actorTurnSM.CallRpcTurnMessage((int)TurnMessage.CANCEL_BUTTON_CLICKED, 0); } else if (msg == TurnMessage.DONE_BUTTON_CLICKED) { actorTurnSM.CallRpcTurnMessage((int)TurnMessage.DONE_BUTTON_CLICKED, 0); } // TODO: Timebanks. Notice that client sends CANCEL msg when selecting ability after confirmed // (but we still should have a fallback if it doesn't) but doesn't send one when updating movement. }
protected virtual void OnDestroy() { if (instance == this) { instance = null; } if (GameFlowData.Get() != null) { foreach (var player in GameFlowData.Get().GetPlayers()) { ActorTurnSM actorTurnSM = player.GetComponent <ActorTurnSM>(); actorTurnSM.OnCmdSetSquareCallback -= CmdSetSquare; } } }
protected virtual void Awake() { if (instance == null) { instance = this; } foreach (var player in GameFlowData.Get().GetPlayers()) { ActorTurnSM actorTurnSM = player.GetComponent <ActorTurnSM>(); actorTurnSM.OnCmdGUITurnMessageCallback += CmdGUITurnMessage; actorTurnSM.OnCmdRequestCancelActionCallback += CmdRequestCancelAction; ActorController actorController = player.GetComponent <ActorController>(); actorController.OnCmdSelectAbilityRequestCallback += CmdSelectAbilityRequest; } }
private void CmdRequestCancelAction(ActorTurnSM actorTurnSM, int actionTypeInt, bool hasIncomingRequest) { ActorData actor = actorTurnSM.gameObject.GetComponent <ActorData>(); AbilityData.ActionType actionType = (AbilityData.ActionType)actionTypeInt; if (!GameFlowData.Get().IsInDecisionState()) { Log.Info($"Recieved CmdRequestCancelAction not in desicion state! {actor.DisplayName} {actionType} ({hasIncomingRequest})"); return; } Log.Info($"CmdRequestCancelAction {actor.DisplayName} {actionType} ({hasIncomingRequest})"); ClearAbilityRequest(actor, actionType); ArtemisServerMovementManager.Get().UpdatePlayerRemainingMovement(actor, !hasIncomingRequest); }
protected virtual void OnDestroy() { if (instance == this) { instance = null; } if (GameFlowData.Get() != null) { foreach (var player in GameFlowData.Get().GetPlayers()) { ActorTurnSM actorTurnSM = player.GetComponent <ActorTurnSM>(); if (actorTurnSM != null) { actorTurnSM.OnCmdGUITurnMessageCallback -= CmdGUITurnMessage; } ActorController actorController = player.GetComponent <ActorController>(); if (actorController != null) { actorController.OnCmdSelectAbilityRequestCallback -= CmdSelectAbilityRequest; } } } }
internal void OnCastAbility(NetworkConnection conn, int casterIndex, int actionTypeInt, List <AbilityTarget> targets) { Player player = GameFlow.Get().GetPlayerFromConnectionId(conn.connectionId); ActorData actor = GameFlowData.Get().FindActorByActorIndex(casterIndex); ActorTurnSM turnSm = actor.gameObject.GetComponent <ActorTurnSM>(); AbilityData.ActionType actionType = (AbilityData.ActionType)actionTypeInt; if (actor.gameObject.GetComponent <PlayerData>().m_player.m_connectionId != conn.connectionId) { Log.Error($"Illegal OnCastAbility: {actor.DisplayName} does not belong to player {player.m_accountId}!"); turnSm.CallRpcTurnMessage((int)TurnMessage.ABILITY_REQUEST_REJECTED, 0); ClearAbilityRequest(actor, actionType); return; } Log.Info($"OnCastAbility {actor.DisplayName} {actionType} ({targets.Count} targets)"); // TODO AbilityData.ValidateAbilityOnTarget turnSm.CallRpcTurnMessage((int)TurnMessage.ABILITY_REQUEST_ACCEPTED, 0); SetAbilityRequest(actor, actionType, targets); ArtemisServerMovementManager.Get().UpdatePlayerRemainingMovement(actor); }
public void CmdSetSquare(ActorTurnSM actorTurnSM, int x, int y, bool setWaypoint) { ActorData actor = actorTurnSM.gameObject.GetComponent <ActorData>(); if (!GameFlowData.Get().IsInDecisionState()) { Log.Info($"Recieved CmdSetSquare not in desicion state! {actor.DisplayName} [{x}, {y}] (setWaypoint = {setWaypoint})"); actorTurnSM.CallRpcTurnMessage((int)TurnMessage.MOVEMENT_REJECTED, 0); return; } Log.Info($"CmdSetSquare {actor.DisplayName} [{x}, {y}] (setWaypoint = {setWaypoint})"); BoardSquare boardSquare = Board.Get().GetSquare(x, y); ActorMovement actorMovement = actor.GetActorMovement(); if (!setWaypoint) { ClearMovementRequest(actor, false); } actorMovement.UpdateSquaresCanMoveTo(); if (!actor.CanMoveToBoardSquare(boardSquare)) { boardSquare = actorMovement.GetClosestMoveableSquareTo(boardSquare, false); } if (actor.TeamSensitiveData_authority.MovementLine == null) { actor.TeamSensitiveData_authority.MovementLine = new LineData.LineInstance(); } if (actor.TeamSensitiveData_authority.MovementLine.m_positions.Count == 0) { actor.TeamSensitiveData_authority.MovementLine.m_positions.Add(actor.InitialMoveStartSquare.GetGridPosition()); } BoardSquarePathInfo path = actorMovement.BuildPathTo(actor.TeamSensitiveData_authority.MoveFromBoardSquare, boardSquare); if (path == null) // TODO check cost { Log.Info($"CmdSetSquare: Movement rejected"); UpdatePlayerRemainingMovement(actor); // TODO updating because we cancelled movement - perhaps we should not cancel in this case actorTurnSM.CallRpcTurnMessage((int)TurnMessage.MOVEMENT_REJECTED, 0); return; } //List<GridPos> posList = path.ToGridPosPath(); List <GridPos> posList = new List <GridPos>(); for (var pathNode = path; pathNode.next != null; pathNode = pathNode.next) { posList.Add(pathNode.next.square.GetGridPosition()); // TODO why doesnt path.ToGridPosPath() work? } actor.TeamSensitiveData_authority.MovementLine.m_positions.AddRange(posList); actor.TeamSensitiveData_authority.MoveFromBoardSquare = boardSquare; actor.MoveFromBoardSquare = boardSquare; UpdatePlayerRemainingMovement(actor); actorTurnSM.CallRpcTurnMessage((int)TurnMessage.MOVEMENT_ACCEPTED, 0); }