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);
        }
        public void SetActorAnimationState(PlayerAnimationEvents playerAnimationEvents)
        {
            if (isUsingPrimaryMove != playerAnimationEvents.isPrimaryMoveAnimationBeingPlayed)
            {
                isUsingPrimaryMove = playerAnimationEvents.isPrimaryMoveAnimationBeingPlayed;
                UpdateFrameSprites();
            }

            if (isWalking != playerAnimationEvents.isWalking)
            {
                isWalking = playerAnimationEvents.isWalking;
                UpdateFrameSprites();
            }

            if (isFlying != playerAnimationEvents.isFlying)
            {
                isFlying = playerAnimationEvents.isFlying;
                UpdateFrameSprites();
            }
        }
        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);
                    }
                }
            }
        }