Example #1
0
 public PlayerStateUpdates(int playerServerSequenceNumber, int playerProcessedSequenceNumber, PlayerAuthoratativeStates playerAuthoratativeStates, PositionUpdates positionUpdates, PlayerEvents playerEvents, PlayerAnimationEvents playerAnimationEvents, PlayerFlyData playerFlyData)
 {
     this.playerServerSequenceNumber    = playerServerSequenceNumber;
     this.playerProcessedSequenceNumber = playerProcessedSequenceNumber;
     this.positionUpdates           = positionUpdates;
     this.playerEvents              = playerEvents;
     this.playerAuthoratativeStates = playerAuthoratativeStates;
     this.playerAnimationEvents     = playerAnimationEvents;
     this.playerFlyData             = playerFlyData;
 }
        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);
        }
Example #3
0
        public void SetCharacter(int hero, PlayerFlyData playerFlyData, PositionUpdates positionUpdates)
        {
            if (id == Client.instance.myID)
            {
                Hero localHero           = (Instantiate(Resources.Load("Characters/" + ((EnumData.Heroes)hero).ToString() + "/LocalPlayer-" + ((EnumData.Heroes)hero).ToString()), transform, false) as GameObject).GetComponentInChildren <Hero>();
                Hero serverPredictedHero = (Instantiate(Resources.Load("Characters/" + ((EnumData.Heroes)hero).ToString() + "/ServerPredicted-" + ((EnumData.Heroes)hero).ToString()), transform, false) as GameObject).GetComponentInChildren <Hero>();
                Hero remoteClientHero    = (Instantiate(Resources.Load("Characters/" + ((EnumData.Heroes)hero).ToString() + "/RemoteClient-" + ((EnumData.Heroes)hero).ToString()), transform, false) as GameObject).GetComponentInChildren <Hero>();

                GetComponent <InputController>().localPlayer = localHero;

                localPlayer  = localHero;
                serverPlayer = serverPredictedHero;
                clientPlayer = remoteClientHero;

                localPlayer.SetActorPositionalState(positionUpdates);
                serverPlayer.SetActorPositionalState(positionUpdates);
                clientPlayer.SetActorPositionalState(positionUpdates);

                localPlayer.SetFlyingTickCount(playerFlyData);
                serverPlayer.SetFlyingTickCount(playerFlyData);
                clientPlayer.SetFlyingTickCount(playerFlyData);


                localPlayer.InitialiseClientActor(this, connectionId, id);
                serverPlayer.InitialiseClientActor(this, connectionId, id);
                clientPlayer.InitialiseClientActor(this, connectionId, id);

                getInputs = localPlayer.GetHeroInputs;
                CharacterSelectionScreen.instance.clientlocalActor = localPlayer;
            }
            else
            {
                Hero remoteOtherClient = (Instantiate(Resources.Load("Characters/" + ((EnumData.Heroes)hero).ToString() + "/RemoteClientOther-" + ((EnumData.Heroes)hero).ToString()), transform, false) as GameObject).GetComponentInChildren <Hero>();
                clientPlayer = remoteOtherClient;
                clientPlayer.SetActorPositionalState(positionUpdates);
                clientPlayer.SetFlyingTickCount(playerFlyData);
                clientPlayer.InitialiseClientActor(this, connectionId, id);
            }
        }
 //authoratatively is performed(but is locally is also done)-correction happens
 public void SetFlyingTickCount(PlayerFlyData playerFlyData)
 {
     flyingTickCountTemp = playerFlyData.flyingTickCount;
 }
        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);
                    }
                }
            }
        }