private void SendPendingAction() { Action action = null; if (actionsToSend.Count > 0) { action = actionsToSend.Dequeue(); } //if no action for this turn, send the NoAction action if (action == null) { action = new NoAction(); } //action.NetworkAverage = Network.GetLastPing (Network.connections[0/*host player*/]); if (LockStepTurnID > FirstLockStepTurnID + 1) { action.NetworkAverage = confirmedActions.GetPriorTime(); } else { action.NetworkAverage = initialLockStepTurnLength; } action.RuntimeAverage = Convert.ToInt32(currentGameFrameRuntime); //clear the current runtime average currentGameFrameRuntime = 0; //add action to our own list of actions to process pendingActions.AddAction(action, Convert.ToInt32(Network.player.ToString()), LockStepTurnID, LockStepTurnID); //start the confirmed action timer for network average confirmedActions.StartTimer(); //confirm our own action confirmedActions.ConfirmAction(Convert.ToInt32(Network.player.ToString()), LockStepTurnID, LockStepTurnID); //send action to all other players //nv.RPC("RecieveAction", RPCMode.Others, LockStepTurnID, Network.player.ToString(), BinarySerialization.SerializeObjectToByteArray(action)); RecieveActionMessage recieveActionMessage = new RecieveActionMessage(); recieveActionMessage.LockStepTurnID = LockStepTurnID; recieveActionMessage.value = BinarySerialization.SerializeObjectToByteArray(action); manager.client.Send(LockstepMsgType.RecieveAction, recieveActionMessage); UnityEngine.Debug.Log("Sent " + (action.GetType().Name) + " action for turn " + LockStepTurnID); }
public void RecieveAction(int lockStepTurn, string playerID, byte[] actionAsBytes) { //UnityEngine.Debug.Log ("Recieved Player " + playerID + "'s action for turn " + lockStepTurn + " on turn " + LockStepTurnID); Action action = BinarySerialization.DeserializeObject <Action>(actionAsBytes); if (action == null) { UnityEngine.Debug.Log("Sending action failed"); //TODO: Error handle invalid actions recieve } else { pendingActions.AddAction(action, Convert.ToInt32(playerID), LockStepTurnID, lockStepTurn); //send confirmation //nv.RPC("ConfirmActionServer", RPCMode.Server, lockStepTurn, Network.player.ToString(), playerID); RecieveActionMessage recieveActionMessage = new RecieveActionMessage(); recieveActionMessage.LockStepTurnID = lockStepTurn; recieveActionMessage.playerID = playerID; manager.client.Send(LockstepMsgType.ConfirmAction, recieveActionMessage); } }
private void OnClientRecieveAction(NetworkMessage netMsg) { RecieveActionMessage recieveActionMessage = netMsg.ReadMessage <RecieveActionMessage>(); clientHudScript.RecieveAction(recieveActionMessage.LockStepTurnID, netMsg.conn.connectionId.ToString(), recieveActionMessage.value); }