Beispiel #1
0
        public void Initialise(int id, string connectionId, string username, PlayerStateUpdates playerStateUpdates, bool hasAuthority)
        {
            this.id           = id;
            this.connectionId = connectionId;
            this.username     = username;

            if (hasAuthority)
            {
                masterController.clientPlayer.InitialiseClientActor(masterController, connectionId, id);
                masterController.localPlayer.InitialiseClientActor(masterController, connectionId, id);
                masterController.getInputs = masterController.localPlayer.GetHeroInputs;
                CharacterSelectionScreen.instance.clientlocalActor = masterController.localPlayer;

                masterController.serverPlayer.InitialiseClientActor(masterController, connectionId, id);

                masterController.clientPlayer.InitialiseActor(playerStateUpdates);
                masterController.localPlayer.InitialiseActor(playerStateUpdates);
                masterController.serverPlayer.InitialiseActor(playerStateUpdates);
            }
            else
            {
                masterController.clientPlayer.InitialiseClientActor(masterController, connectionId, id);
                masterController.clientPlayer.InitialiseActor(playerStateUpdates);
            }
            masterController.latestPlayerStateUpdate           = playerStateUpdates;
            masterController.hasAuthority                      = hasAuthority;
            masterController.serverSequenceNumberToBeProcessed = playerStateUpdates.playerServerSequenceNumber;
            masterController.isInitialised                     = true;
        }
Beispiel #2
0
 public void AccumulateDataToBePlayedOnClientFromServer(PlayerStateUpdates playerStateUpdates)
 {
     if (!isInitialised)
     {
         return;
     }
     //if(!hasAuthority)
     //{
     //    Debug.Log("<color=blue>sequence number accumulated on client </color>" + sequenceNumberProcessedOnServer);
     //}
     if (playerStateUpdates.playerServerSequenceNumber > serverSequenceNumberToBeProcessed)
     {
         PlayerStateUpdates dataPackage;
         if (playerStateUpdatesDic.TryGetValue(playerStateUpdates.playerServerSequenceNumber, out dataPackage))
         {
             //if (!hasAuthority)
             //    Debug.Log("<color=orange>dataPackage already exists for sequence no. </color>" + positionUpdate.sequenceNumber);
         }
         else
         {
             //if (!hasAuthority)
             //    Debug.Log("<color=green>Added successfully to processing buffer dic </color>" + sequenceNumberProcessedOnServer);
             playerStateUpdatesDic.Add(playerStateUpdates.playerServerSequenceNumber, playerStateUpdates);
         }
     }
     else
     {
         //if (!hasAuthority)
         //    Debug.Log("<color=red>Already processed this sequence no </color>" + sequenceNumberProcessedOnServer);
     }
 }
        public void SpawnPlayer(int id, string connectionId, string username, PlayerStateUpdates playerStateUpdates)
        {
            GameObject player;
            int        hero = playerStateUpdates.playerAuthoratativeStates.hero;

            if (id == Client.instance.myID)
            {
                player = Instantiate(localPlayerPrefab, Vector3.zero, Quaternion.identity);
                Hero localHero           = (Instantiate(Resources.Load("Characters/" + ((EnumData.Heroes)hero).ToString() + "/LocalPlayer-" + ((EnumData.Heroes)hero).ToString()), player.transform, false) as GameObject).GetComponentInChildren <Hero>();
                Hero serverPredictedHero = (Instantiate(Resources.Load("Characters/" + ((EnumData.Heroes)hero).ToString() + "/ServerPredicted-" + ((EnumData.Heroes)hero).ToString()), player.transform, false) as GameObject).GetComponentInChildren <Hero>();
                Hero remoteClientHero    = (Instantiate(Resources.Load("Characters/" + ((EnumData.Heroes)hero).ToString() + "/RemoteClient-" + ((EnumData.Heroes)hero).ToString()), player.transform, false) as GameObject).GetComponentInChildren <Hero>();

                player.GetComponent <InputController>().localPlayer         = localHero;
                player.GetComponent <ClientMasterController>().localPlayer  = localHero;
                player.GetComponent <ClientMasterController>().serverPlayer = serverPredictedHero;
                player.GetComponent <ClientMasterController>().clientPlayer = remoteClientHero;

                player.GetComponent <PlayerManager>().Initialise(id, connectionId, username, playerStateUpdates, true);
            }
            else
            {
                player = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity);

                Hero remoteOtherClient = (Instantiate(Resources.Load("Characters/" + ((EnumData.Heroes)hero).ToString() + "/RemoteClientOther-" + ((EnumData.Heroes)hero).ToString()), player.transform, false) as GameObject).GetComponentInChildren <Hero>();

                player.GetComponent <ClientMasterController>().clientPlayer = remoteOtherClient;
                player.GetComponent <PlayerManager>().Initialise(id, connectionId, username, playerStateUpdates, false);
            }
            CharacterSelectionScreen.instance.PlayerConnected(id);
            CharacterSelectionScreen.instance.AssignCharacterToId(playerStateUpdates.playerAuthoratativeStates.hero, id);
            players.Add(id, player.GetComponent <PlayerManager>());
        }
 public void InitialiseActor(PlayerStateUpdates playerStateUpdates)
 {
     SetActorPositionalState(playerStateUpdates.positionUpdates);
     SetFlyingTickCount(playerStateUpdates.playerFlyData);
     SetActorAnimationState(playerStateUpdates.playerAnimationEvents);
     SetActorEventActionState(playerStateUpdates.playerEvents);
     SetAuthoratativeStates(playerStateUpdates.playerAuthoratativeStates);
 }
Beispiel #5
0
        private void UpdatePredictedGhost(PlayerStateUpdates playerStateUpdates)
        {
            //Discard all previous sequence number records
            List <int> toDiscardSequencesInputs = new List <int>();

            foreach (KeyValuePair <int, InputCommands> kvp in localClientActions)
            {
                if (kvp.Key <= playerStateUpdates.playerProcessedSequenceNumber)
                {
                    toDiscardSequencesInputs.Add(kvp.Key);
                    //Debug.Log("<color=red>Need to discard</color>"+kvp.Key);
                }
            }

            foreach (int i in toDiscardSequencesInputs)
            {
                if (localClientActions.ContainsKey(i))
                {
                    //Debug.Log("<color=red>discarding seq </color>" + i);
                    localClientActions.Remove(i);

                    if (sequenceNoList.Contains(i))
                    {
                        sequenceNoList.Remove(i);
                    }
                }
                else
                {
                    Debug.LogError("Could not find the key: " + i);
                }
            }


            //Accept the current position and reapply input since sequencee number
            //Debug.Log("<color=green>Before localClientCommands to iterate across blockposition </color>" + playerStateUpdates.positionUpdates.updatedBlockActorPosition + "player position" + playerStateUpdates.positionUpdates.updatedActorPosition + "<color=pink> first sequence is  </color>" + (playerStateUpdates.playerProcessedSequenceNumber + 1) + "<color=pink> last sequence no </color>" + latestPacketProcessedLocally);
            //Debug.Break();
            for (int i = playerStateUpdates.playerProcessedSequenceNumber + 1; i <= latestPacketProcessedLocally; i++)
            {
                InputCommands la;
                if (localClientActions.TryGetValue(i, out la))
                {
                    //Debug.Log("<color=yellow>prediction done using sequnce no: </color>" + localClientInputCommands[i].sequenceNumber + "<color=green> inputs: </color>" + localClientInputCommands[i].commands[0] + localClientInputCommands[i].commands[1] + localClientInputCommands[i].commands[2] + localClientInputCommands[i].commands[3] + " Previous commands " + localClientInputCommands[i].previousCommands[0] + localClientInputCommands[i].previousCommands[1] + localClientInputCommands[i].previousCommands[2] + localClientInputCommands[i].previousCommands[3]);
                    //Debug.Log(serverPlayer.movePoint.position + "--" + serverPlayer.currentMovePointCellPosition + "Before" + serverPlayer.actorTransform.position + "<color=yellow>Before prediction done using sequnce no: </color>" + localClientInputCommands[i].sequenceNumber);

                    serverPlayer.ProcessCollisionEnter();
                    serverPlayer.ProcessMovementInputs(la.commands, la.previousCommands);
                    serverPlayer.ProcessInputMovementsControl();
                    serverPlayer.ProcessFlyingControl();
                    //Debug.Log(serverPlayer.movePoint.position + "--" + serverPlayer.currentMovePointCellPosition + "After wards" + serverPlayer.actorTransform.position + "<color=yellow>After prediction done using sequnce no: </color>" + localClientInputCommands[i].sequenceNumber + "<color=green> inputs: </color>" + localClientInputCommands[i].commands[0] + localClientInputCommands[i].commands[1] + localClientInputCommands[i].commands[2] + localClientInputCommands[i].commands[3] + " Previous commands " + localClientInputCommands[i].previousCommands[0] + localClientInputCommands[i].previousCommands[1] + localClientInputCommands[i].previousCommands[2] + localClientInputCommands[i].previousCommands[3]);
                }
                else
                {
                    Debug.LogError("Could not find input commands for sequence no. " + i);
                }
            }
            //Debug.Log("<color=green>After localClientCommands to iterate across </color>" + predictedPositionOfPlayerOnServer);
            //Debug.Log("changing position here");
        }
        public static void SpawnedPlayer(Packet packet)
        {
            int        id                                = packet.ReadInt();
            string     connectionId                      = packet.ReadString();
            string     username                          = packet.ReadString();
            int        hero                              = packet.ReadInt();
            Vector3    position                          = packet.ReadVector3();
            Vector3Int blockposition                     = packet.ReadVector3Int();
            Vector3Int previousBlockposition             = packet.ReadVector3Int();
            int        faceDirection                     = packet.ReadInt();
            int        previousfaceDirection             = packet.ReadInt();
            bool       isFiringPrimaryProjectile         = packet.ReadBool();
            bool       isFiringItemEyeLaserProjectile    = packet.ReadBool();
            bool       isFiringItemFireBallProjectile    = packet.ReadBool();
            bool       isFiringItemStarShowerProjectile  = packet.ReadBool();
            bool       isFiringItemCenaturBowProjectile  = packet.ReadBool();
            bool       isWalking                         = packet.ReadBool();
            bool       isFlying                          = packet.ReadBool();
            bool       isPrimaryMoveAnimationBeingPlayed = packet.ReadBool();
            bool       isPetrified                       = packet.ReadBool();
            bool       isPushed                          = packet.ReadBool();
            bool       isPhysicsControlled               = packet.ReadBool();
            bool       isInputFreezed                    = packet.ReadBool();
            bool       isMovementFreezed                 = packet.ReadBool();
            bool       isInvincible                      = packet.ReadBool();
            bool       isRespawning                      = packet.ReadBool();
            bool       inCharacterSelectionScreen        = packet.ReadBool();
            bool       inGame                            = packet.ReadBool();
            int        currentHP                         = packet.ReadInt();
            int        currentStockLives                 = packet.ReadInt();

            int flyingTickCount = packet.ReadInt();

            int castItemType   = packet.ReadInt();
            int usableItemType = packet.ReadInt();
            int itemCount      = packet.ReadInt();

            int playerProcessingSequenceNumber = packet.ReadInt();
            int playerServerSequenceNumber     = packet.ReadInt();

            Debug.Log(id + "<color=red>Player id Sequence no spawned on: </color>" + playerServerSequenceNumber);

            PositionUpdates           positionUpdates           = new PositionUpdates(position, blockposition, previousBlockposition, faceDirection, previousfaceDirection);
            PlayerEvents              playerEvents              = new PlayerEvents(isFiringPrimaryProjectile, isFiringItemEyeLaserProjectile, isFiringItemFireBallProjectile, isFiringItemStarShowerProjectile, isFiringItemCenaturBowProjectile);
            PlayerAnimationEvents     playerAnimtaionEvents     = new PlayerAnimationEvents(isWalking, isFlying, isPrimaryMoveAnimationBeingPlayed);
            PlayerAuthoratativeStates playerAuthoratativeStates = new PlayerAuthoratativeStates(isPetrified, isPushed, isPhysicsControlled, isInputFreezed, isMovementFreezed, isInvincible, isRespawning, inCharacterSelectionScreen, inGame, currentHP, currentStockLives, hero, new ItemToCast(castItemType, usableItemType, itemCount));
            PlayerFlyData             playerFlyData             = new PlayerFlyData(flyingTickCount);

            PlayerStateUpdates playerStateUpdates = new PlayerStateUpdates(playerServerSequenceNumber, playerProcessingSequenceNumber, playerAuthoratativeStates, positionUpdates, playerEvents, playerAnimtaionEvents, playerFlyData);

            ClientSideGameManager.instance.SpawnPlayer(id, connectionId, username, playerStateUpdates);
        }
        public static void PlayerStateUpdated(Packet packet)
        {
            int dataCount = packet.ReadInt();

            for (int i = 0; i < dataCount; i++)
            {
                int        id                                = packet.ReadInt();
                int        hero                              = packet.ReadInt();
                Vector3    position                          = packet.ReadVector3();
                Vector3Int blockposition                     = packet.ReadVector3Int();
                Vector3Int previousBlockposition             = packet.ReadVector3Int();
                int        Facing                            = packet.ReadInt();
                int        previousFacing                    = packet.ReadInt();
                bool       isFiringPrimaryProjectile         = packet.ReadBool();
                bool       isFiringItemEyeLaserProjectile    = packet.ReadBool();
                bool       isFiringItemFireBallProjectile    = packet.ReadBool();
                bool       isFiringItemStarShowerProjectile  = packet.ReadBool();
                bool       isFiringItemCentaurBowProjectile  = packet.ReadBool();
                bool       isWalking                         = packet.ReadBool();
                bool       isFlying                          = packet.ReadBool();
                bool       isPrimaryMoveAnimationBeingPlayed = packet.ReadBool();
                bool       isPetrified                       = packet.ReadBool();
                bool       isPushed                          = packet.ReadBool();
                bool       isPhysicsControlled               = packet.ReadBool();
                bool       isInputFreezed                    = packet.ReadBool();
                bool       isMovementFreezed                 = packet.ReadBool();
                bool       isInvincible                      = packet.ReadBool();
                bool       isRespawning                      = packet.ReadBool();
                bool       inCharacterSelectionScreen        = packet.ReadBool();
                bool       inGame                            = packet.ReadBool();
                int        currentHP                         = packet.ReadInt();
                int        currentStockLives                 = packet.ReadInt();

                int flyingTickCount = packet.ReadInt();

                int castItemType   = packet.ReadInt();
                int usableItemType = packet.ReadInt();
                int itemCount      = packet.ReadInt();

                int playerProcessedsequenceNumberReceived = packet.ReadInt();
                int playerServerSequenceNumberReceived    = packet.ReadInt();

                PositionUpdates           positionUpdates           = new PositionUpdates(position, blockposition, previousBlockposition, Facing, previousFacing);
                PlayerEvents              playerEvents              = new PlayerEvents(isFiringPrimaryProjectile, isFiringItemEyeLaserProjectile, isFiringItemFireBallProjectile, isFiringItemStarShowerProjectile, isFiringItemCentaurBowProjectile);
                PlayerAnimationEvents     playerAnimtaionEvents     = new PlayerAnimationEvents(isWalking, isFlying, isPrimaryMoveAnimationBeingPlayed);
                PlayerAuthoratativeStates playerAuthoratativeStates = new PlayerAuthoratativeStates(isPetrified, isPushed, isPhysicsControlled, isInputFreezed, isMovementFreezed, isInvincible, isRespawning, inCharacterSelectionScreen, inGame, currentHP, currentStockLives, hero, new ItemToCast(castItemType, usableItemType, itemCount));
                PlayerFlyData             playerFlyData             = new PlayerFlyData(flyingTickCount);

                PlayerStateUpdates playerStateUpdates = new PlayerStateUpdates(playerServerSequenceNumberReceived, playerProcessedsequenceNumberReceived, playerAuthoratativeStates, positionUpdates, playerEvents, playerAnimtaionEvents, playerFlyData);
                //Debug.LogError("<color=blue>Receiving updated position for movement </color>playerUpdatedPositionSequenceNumber: " + sequenceNumberReceived + " position: " + position);
                if (ClientSideGameManager.players.ContainsKey(id))
                {
                    ClientSideGameManager.players[id].masterController.AccumulateDataToBePlayedOnClientFromServer(playerStateUpdates);
                }
                else
                {
                    Debug.LogError("Player of id doesnot exists: " + id);
                }
                //if (!ClientSideGameManager.players[id].masterController.hasAuthority)
                //{
                //    Debug.LogWarning("<color=red>Receiving remote player data</color>"+sequenceNumberReceived);
                //}
                //else
                //{
                //    Debug.LogWarning("<color=green>Receiving my player data</color>"+sequenceNumberReceived);
                //}
            }

            int previousPlayerUpdatedPositionPacks = packet.ReadInt();

            for (int i = 0; i < previousPlayerUpdatedPositionPacks; i++)
            {
                int previousPlayerUpdatedPositionPacksCount = packet.ReadInt();

                for (int j = 0; j < previousPlayerUpdatedPositionPacksCount; j++)
                {
                    int        previousHistoryPlayerId                    = packet.ReadInt();
                    int        previousHistoryPlayerHero                  = packet.ReadInt();
                    Vector3    previousHistoryPositionUpdate              = packet.ReadVector3();
                    Vector3Int previousHistoryBlockPositionUpdate         = packet.ReadVector3Int();
                    Vector3Int previousHistoryPreviousBlockPositionUpdate = packet.ReadVector3Int();
                    int        Facing                            = packet.ReadInt();
                    int        previousFacing                    = packet.ReadInt();
                    bool       isFiringPrimaryProjectile         = packet.ReadBool();
                    bool       isFiringItemEyeLaserProjectile    = packet.ReadBool();
                    bool       isFiringItemFireBallProjectile    = packet.ReadBool();
                    bool       isFiringItemStarShowerProjectile  = packet.ReadBool();
                    bool       isFiringItemCentaurBowProjectile  = packet.ReadBool();
                    bool       isWalking                         = packet.ReadBool();
                    bool       isFlying                          = packet.ReadBool();
                    bool       isPrimaryMoveAnimationBeingPlayed = packet.ReadBool();
                    bool       isPetrified                       = packet.ReadBool();
                    bool       isPushed                          = packet.ReadBool();
                    bool       isPhysicsControlled               = packet.ReadBool();
                    bool       isInputFreezed                    = packet.ReadBool();
                    bool       isMovementFreezed                 = packet.ReadBool();
                    bool       isInvincible                      = packet.ReadBool();
                    bool       isRespawning                      = packet.ReadBool();
                    bool       inCharacterSelectionScreen        = packet.ReadBool();
                    bool       inGame                            = packet.ReadBool();
                    int        currentHP                         = packet.ReadInt();
                    int        currentStockLives                 = packet.ReadInt();

                    int flyingTickCount = packet.ReadInt();

                    int castItemType   = packet.ReadInt();
                    int usableItemType = packet.ReadInt();
                    int itemCount      = packet.ReadInt();

                    int previousHistoryPlayerProcessingSequenceNo = packet.ReadInt();
                    int previousHistoryServerSequenceNo           = packet.ReadInt();

                    PositionUpdates           positionUpdates           = new PositionUpdates(previousHistoryPositionUpdate, previousHistoryBlockPositionUpdate, previousHistoryPreviousBlockPositionUpdate, Facing, previousFacing);
                    PlayerEvents              playerEvents              = new PlayerEvents(isFiringPrimaryProjectile, isFiringItemEyeLaserProjectile, isFiringItemFireBallProjectile, isFiringItemStarShowerProjectile, isFiringItemCentaurBowProjectile);
                    PlayerAnimationEvents     playerAnimtaionEvents     = new PlayerAnimationEvents(isWalking, isFlying, isPrimaryMoveAnimationBeingPlayed);
                    PlayerAuthoratativeStates playerAuthoratativeStates = new PlayerAuthoratativeStates(isPetrified, isPushed, isPhysicsControlled, isInputFreezed, isMovementFreezed, isInvincible, isRespawning, inCharacterSelectionScreen, inGame, currentHP, currentStockLives, previousHistoryPlayerHero, new ItemToCast(castItemType, usableItemType, itemCount));
                    PlayerFlyData             playerFlyData             = new PlayerFlyData(flyingTickCount);

                    PlayerStateUpdates playerStateUpdates = new PlayerStateUpdates(previousHistoryServerSequenceNo, previousHistoryPlayerProcessingSequenceNo, playerAuthoratativeStates, positionUpdates, playerEvents, playerAnimtaionEvents, playerFlyData);
                    if (ClientSideGameManager.players.ContainsKey(previousHistoryPlayerId))
                    {
                        ClientSideGameManager.players[previousHistoryPlayerId].masterController.AccumulateDataToBePlayedOnClientFromServer(playerStateUpdates);
                    }
                    else
                    {
                        Debug.LogError("Player of id doesnot exists: " + previousHistoryPlayerId);
                    }
                }
            }
        }
Beispiel #8
0
        private void FixedUpdate()
        {
            if (isInitialised)
            {
                //Remote clients
                for (int i = 0; i < (int)currentStateProcessingModeOnClient; i++)
                {
                    PlayerStateUpdates updateCorrespondingToSeq;
                    if (playerStateUpdatesDic.TryGetValue(serverSequenceNumberToBeProcessed + 1, out updateCorrespondingToSeq))
                    {
                        //if(clientPlayer.ownerId==2)
                        //{
                        //    Debug.LogError("Processing : "+ updateCorrespondingToSeq.playerServerSequenceNumber);
                        //}
                        //Debug.Log("<color=yellow>Remote Client of id " + id + " is Processing seqence no </color>" + updateCorrespondingToSeq.playerServerSequenceNumber + " and the processed sequence no: " + updateCorrespondingToSeq.playerProcessedSequenceNumber);
                        playerStateUpdatesDic.Remove(updateCorrespondingToSeq.playerServerSequenceNumber);
                        serverSequenceNumberToBeProcessed = updateCorrespondingToSeq.playerServerSequenceNumber;
                        playerSequenceNumberProcessed     = updateCorrespondingToSeq.playerProcessedSequenceNumber;
                        latestPlayerStateUpdate           = updateCorrespondingToSeq;


                        PlayerStateUpdates playerStateUpdates = new PlayerStateUpdates(serverSequenceNumberToBeProcessed
                                                                                       , playerSequenceNumberProcessed
                                                                                       , updateCorrespondingToSeq.playerAuthoratativeStates
                                                                                       , updateCorrespondingToSeq.positionUpdates
                                                                                       , updateCorrespondingToSeq.playerEvents
                                                                                       , updateCorrespondingToSeq.playerAnimationEvents
                                                                                       , updateCorrespondingToSeq.playerFlyData);

                        SetPlayerStateUpdatesReceivedFromServer(playerStateUpdates);
                    }
                    else
                    {
                        Debug.LogError(id + " latestPlayerStateUpdate.playerServerSequenceNumber " + latestPlayerStateUpdate.playerServerSequenceNumber);
                        Debug.LogError(id + " Could not find any posudates for  seq: " + (serverSequenceNumberToBeProcessed + 1));
                        if (latestPlayerStateUpdate.playerServerSequenceNumber != 0)
                        {
                            serverSequenceNumberToBeProcessed = serverSequenceNumberToBeProcessed + 1;
                            PlayerStateUpdates playerStateUpdates = new PlayerStateUpdates(serverSequenceNumberToBeProcessed
                                                                                           , latestPlayerStateUpdate.playerProcessedSequenceNumber
                                                                                           , latestPlayerStateUpdate.playerAuthoratativeStates
                                                                                           , latestPlayerStateUpdate.positionUpdates
                                                                                           , latestPlayerStateUpdate.playerEvents
                                                                                           , latestPlayerStateUpdate.playerAnimationEvents
                                                                                           , latestPlayerStateUpdate.playerFlyData);
                            SetPlayerStateUpdatesReceivedFromServer(playerStateUpdates);
                        }
                    }
                }

                if (hasAuthority)
                {
                    bool[] inputs = getInputs();
                    localSequenceNumber++;

                    ProcessInputsLocally(inputs, previousInputs);
                    RecordLocalClientActions(localSequenceNumber, inputs, previousInputs);

                    //////Debug.Log("<color=blue>inputsequence </color>"+ playerMovingCommandSequenceNumber + "<color=blue>inputs </color> "+ inputs[0]+" "+inputs[1]+" "+inputs[2]+" "+inputs[3]);

                    inputCommandsToBeSentToServerCollection.Add(new InputCommands(inputs, previousInputs, localSequenceNumber));
                    previousInputs = inputs;

                    //Local client sending data
                    if (inputCommandsToBeSentToServerCollection.Count >= snapShotsInOnePacket)
                    {
                        if (previousHistoryForInputCommandsToBeSentToServerCollection.Count > packetHistorySize)
                        {
                            previousHistoryForInputCommandsToBeSentToServerCollection.RemoveAt(0);
                        }
                        ClientSend.PlayerInput(inputCommandsToBeSentToServerCollection, previousHistoryForInputCommandsToBeSentToServerCollection);

                        previousHistoryForInputCommandsToBeSentToServerCollection.Add(new PreviousInputPacks(inputCommandsToBeSentToServerCollection.ToArray()));

                        inputCommandsToBeSentToServerCollection.Clear();

                        //Debug.Log("<color=red>--------------------------------------------------------------------</color>");
                    }
                }

                UpdateProcessMode();
                snapShotBufferSize = GetTheLastestSequenceNoInDic() - serverSequenceNumberToBeProcessed;
            }

            //Debug.Log("<color=cyan>Dic Count </color>" + positionUpdates.Count);
        }
Beispiel #9
0
        public void SetPlayerStateUpdatesReceivedFromServer(PlayerStateUpdates playerStateUpdates)
        {
            if (hasAuthority)
            {
                if (localPlayer.hero != playerStateUpdates.playerAuthoratativeStates.hero)
                {
                    Hero previousServerHero = serverPlayer;
                    Hero previousClientHero = clientPlayer;
                    Hero previousLocalHero  = localPlayer;
                    SetCharacter(playerStateUpdates.playerAuthoratativeStates.hero, playerStateUpdates.playerFlyData, playerStateUpdates.positionUpdates);

                    CharacterSelectionScreen.instance.AssignCharacterToId(playerStateUpdates.playerAuthoratativeStates.hero, id);

                    Destroy(previousServerHero.transform.parent.gameObject);
                    Destroy(previousClientHero.transform.parent.gameObject);
                    Destroy(previousLocalHero.transform.parent.gameObject);
                }
            }
            else
            {
                if (clientPlayer.hero != playerStateUpdates.playerAuthoratativeStates.hero)
                {
                    Hero previousClientHero = clientPlayer;

                    SetCharacter(playerStateUpdates.playerAuthoratativeStates.hero, playerStateUpdates.playerFlyData, playerStateUpdates.positionUpdates);

                    CharacterSelectionScreen.instance.AssignCharacterToId(playerStateUpdates.playerAuthoratativeStates.hero, id);

                    Destroy(previousClientHero.transform.parent.gameObject);
                }
            }

            clientPlayer.SetActorPositionalState(playerStateUpdates.positionUpdates);
            clientPlayer.SetFlyingTickCount(playerStateUpdates.playerFlyData);
            clientPlayer.SetActorEventActionState(playerStateUpdates.playerEvents);
            clientPlayer.SetActorAnimationState(playerStateUpdates.playerAnimationEvents);
            clientPlayer.SetAuthoratativeStates(playerStateUpdates.playerAuthoratativeStates);
            if (hasAuthority)
            {
                if (playerStateUpdates.playerAuthoratativeStates.isRespawnningPlayer && localPlayer.isRespawnningPlayer != playerStateUpdates.playerAuthoratativeStates.isRespawnningPlayer)
                {
                    localPlayer.SetActorPositionalState(playerStateUpdates.positionUpdates);
                    localPlayer.SetFlyingTickCount(playerStateUpdates.playerFlyData);
                }
                localPlayer.SetAuthoratativeStates(playerStateUpdates.playerAuthoratativeStates);

                if (localPlayer.isPetrified || localPlayer.isPushed || localPlayer.isPhysicsControlled)
                {
                    localPlayer.SetActorPositionalState(playerStateUpdates.positionUpdates);
                    localPlayer.SetFlyingTickCount(playerStateUpdates.playerFlyData);
                }

                serverPlayer.SetActorPositionalState(playerStateUpdates.positionUpdates);
                serverPlayer.SetFlyingTickCount(playerStateUpdates.playerFlyData);

                serverPlayer.SetActorEventActionState(playerStateUpdates.playerEvents);
                serverPlayer.SetActorAnimationState(playerStateUpdates.playerAnimationEvents);
                serverPlayer.SetAuthoratativeStates(playerStateUpdates.playerAuthoratativeStates);


                UpdatePredictedGhost(playerStateUpdates);
                if (Vector3.Distance(serverPlayer.actorTransform.position, localPlayer.actorTransform.position) >= positionThreshold)
                {
                    Debug.Log("Correction regarding position difference " + serverPlayer.actorTransform.position + "local---server" + localPlayer.actorTransform.position + "<color=red>Corrected player position</color>" + playerStateUpdates.playerProcessedSequenceNumber);
                    PositionUpdates positionUpdates = new PositionUpdates(serverPlayer.actorTransform.position, serverPlayer.currentMovePointCellPosition, serverPlayer.previousMovePointCellPosition,
                                                                          (int)serverPlayer.Facing, (int)serverPlayer.PreviousFacingDirection);
                    localPlayer.SetActorPositionalState(positionUpdates);
                    localPlayer.SetFlyingTickCount(new PlayerFlyData(serverPlayer.flyingTickCountTemp));
                }
            }
            else
            {
                clientPlayer.ProcessRemoteClientInputEventControl();
                clientPlayer.ProcessInputAnimationControl();
            }
        }