public void ExecuteAttack(Player player) { if (IsAcceptingAttacks) { ShowdownAttack showdownAttack = new ShowdownAttack(); showdownAttack.Player = player; showdownAttack.StateWhenExecuted = stateMachine.CurrentState.StateType; showdownAttack.TimeOfExecution = timer; if (!attackMap.ContainsKey(player.playerName)) { attackMap.Add(player.playerName, showdownAttack); } stateMachine.TransitionToState(ShowdownState.ShowdownStateType.ShowdownResolveState); } }
public Player ProcessAttacks() { ShowdownAttack player1Attack = null; ShowdownAttack player2Attack = null; toggleCams(); HUD.SetActive(true); if (attackMap.TryGetValue(player1.playerName, out player1Attack)) { if (attackMap.TryGetValue(player2.playerName, out player2Attack)) { // Both players registered an attack, let's compare. if (player1Attack.TimeOfExecution < player2Attack.TimeOfExecution) { if (player1Attack.StateWhenExecuted.Equals(ShowdownState.ShowdownStateType.ShowdownSuspenseState)) { return(player2); } else { return(player1); } } else { if (player2Attack.StateWhenExecuted.Equals(ShowdownState.ShowdownStateType.ShowdownSuspenseState)) { return(player1); } else { return(player2); } } } else { // Only player1 registered an attack, see if it is in suspense state or not. if (player1Attack.StateWhenExecuted.Equals(ShowdownState.ShowdownStateType.ShowdownSuspenseState)) { // Player 1 Attacked too early, Player 2 is the winner. return(player2); } else { // Player 1 Attacked during the right time, Player 1 is the winner. return(player1); } } } else { if (attackMap.TryGetValue(player2.playerName, out player2Attack)) { // Only player1 registered an attack, see if it is in suspense state or not. if (player2Attack.StateWhenExecuted.Equals(ShowdownState.ShowdownStateType.ShowdownSuspenseState)) { // Player 2 Attacked too early, Player 1 is the winner. return(player1); } else { // Player 2 Attacked during the right time, Player 2 is the winner. return(player2); } } else { Debug.LogError("this should never happen..."); return(null); } } }