private void SendPendingAction()
    {
        IAction action = null;

        if (actionsToSend.Count > 0)
        {
            action = actionsToSend.Dequeue();
        }

        if (action == null)
        {
            action = new NoAction();
        }
        pendingActions.AddAction(action, this.virtualClient.ID, LockStepTurnID, LockStepTurnID);
        SendActionToOtherPlayers(LockStepTurnID, this.virtualClient.ID, action);
    }
예제 #2
0
    public void RecieveAction(int lockStepTurn, int playerID, byte[] actionAsBytes)
    {
        //Debug.Log("Recieved Player " + playerID + "'s action for turn " + lockStepTurn + " on turn " + _lockStepTurnID);
        Action action = BinarySerialization.DeserializeObject <Action>(actionAsBytes);

        if (action == null)
        {
            Debug.Log("Sending action failed");
            //TODO: Error handle invalid actions recieve
        }
        else
        {
            _pendingActions.AddAction(action, Convert.ToInt32(playerID), _lockStepTurnID, lockStepTurn);

            //send confirmation
            if (_confirmedActions.IsConfirmedActionsEnabled())
            {
                if (Network.isServer)
                {
                    //we don't need an rpc call if we are the server
                    ConfirmActionServer(lockStepTurn, _localPlayerIndex, playerID);
                }
                else
                {
                    _networkInterface.CallConfirmActionServer(lockStepTurn, _localPlayerIndex, playerID);
                }
            }
        }
    }
예제 #3
0
    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);
    }
예제 #4
0
    private void SendPendingAction()
    {
        IAction action = null;

        if (actionsToSync.Count > 0)
        {
            action = actionsToSync.Dequeue();
        }
        //if no action for this turn, send the NoAction action
        if (action == null)
        {
            action = new NoAction();
        }
        //add action to our own list of actions to process
        pendingActions.AddAction(action, 1, TurnID, TurnID);
        //confirm our own action
        confirmedActions.playersConfirmedCurrentAction.Add(RoleMgr.Instance.RoleId);
        //send action to all other players
        //		nv.RPC("RecieveAction", RPCMode.Others, LockStepTurnID, Network.player.ToString(), BinarySerialization.SerializeObjectToByteArray(action));

        ActionController.Instance.SyncAction(TurnID, RoleMgr.Instance.RoleId, BinarySerialization.SerializeObjectToByteArray(action));
    }
    private void SendPendingAction()
    {
        IAction 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();
        }
        //add action to our own list of actions to process
        pendingActions.AddAction(action, Convert.ToInt32(Network.player.ToString()), LockStepTurnID, LockStepTurnID);
        //confirm our own action
        confirmedActions.playersConfirmedCurrentAction.Add(Network.player);
        //send action to all other players
        nv.RPC("RecieveAction", RPCMode.Others, LockStepTurnID, Network.player.ToString(), BinarySerialization.SerializeObjectToByteArray(action));

        log.Debug("Sent " + (action.GetType().Name) + " action for turn " + LockStepTurnID);
    }