Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        //authoratatively is performed
        public void SetAuthoratativeStates(PlayerAuthoratativeStates playerAuthoratativeStates)
        {
            if (statusSprite != null)
            {
                if (playerAuthoratativeStates.isPetrified && isPetrified != playerAuthoratativeStates.isPetrified)
                {
                    statusSprite.enabled = true;
                    statusSprite.color   = petrificationColor;
                }
                if (!playerAuthoratativeStates.isPetrified && isPetrified != playerAuthoratativeStates.isPetrified)
                {
                    statusSprite.enabled = false;
                }
                if (playerAuthoratativeStates.isInvincible && isInvincible != playerAuthoratativeStates.isInvincible)
                {
                    statusSprite.enabled = true;
                    statusSprite.color   = invincibleColor;
                }
                if (!playerAuthoratativeStates.isInvincible && isInvincible != playerAuthoratativeStates.isInvincible)
                {
                    statusSprite.enabled = false;
                }
            }

            if (playerAuthoratativeStates.inCharacterSelectionScreen && inCharacterSelectionScreen != playerAuthoratativeStates.inCharacterSelectionScreen)
            {
                //turn off model
                //turn on character selection screen
                //Debug.LogError("Turn off model");
                gameObject.transform.parent.gameObject.SetActive(false);
            }
            if (playerAuthoratativeStates.inGame && inGame != playerAuthoratativeStates.inGame)
            {
                //turn on model
                //turn off character selection screen
                //Debug.LogError("Turn on model");
                gameObject.transform.parent.gameObject.SetActive(true);
                if (CharacterSelectionScreen.instance.gameObject.activeSelf)
                {
                    CharacterSelectionScreen.instance.gameObject.SetActive(false);
                }
            }

            inCharacterSelectionScreen = playerAuthoratativeStates.inCharacterSelectionScreen;
            inGame              = playerAuthoratativeStates.inGame;
            hero                = playerAuthoratativeStates.hero;
            isInputFreezed      = playerAuthoratativeStates.inputFreezed;
            isMovementFreezed   = playerAuthoratativeStates.isMovementFreezed;
            isPetrified         = playerAuthoratativeStates.isPetrified;
            isPushed            = playerAuthoratativeStates.isPushed;
            isPhysicsControlled = playerAuthoratativeStates.isPhysicsControlled;
            isInvincible        = playerAuthoratativeStates.isInvincible;

            if (!isRespawnningPlayer && isRespawnningPlayer != playerAuthoratativeStates.isRespawnningPlayer)
            {
                //enable crosshair locally
                //disable collider
                if (statusSprite != null)
                {
                    statusSprite.gameObject.SetActive(false);
                }
                SetRespawnState();
            }
            if (isRespawnningPlayer && isRespawnningPlayer != playerAuthoratativeStates.isRespawnningPlayer)
            {
                //disable crosshair locally
                //enable back collider
                if (statusSprite != null)
                {
                    statusSprite.gameObject.SetActive(true);
                }
                SetSpawnState();
            }
            if (!isPhysicsControlled && isPhysicsControlled != playerAuthoratativeStates.isPhysicsControlled)
            {
                SetActorCollider(false);
            }
            if (isPhysicsControlled && isPhysicsControlled != playerAuthoratativeStates.isPhysicsControlled)
            {
                SetActorCollider(true);
            }

            isRespawnningPlayer = playerAuthoratativeStates.isRespawnningPlayer;

            currentHP         = playerAuthoratativeStates.currentHP;
            currentStockLives = playerAuthoratativeStates.currentStockLives;

            itemToCast = new CastItem((EnumData.CastItemTypes)playerAuthoratativeStates.itemToCast.castItemType
                                      , (EnumData.UsableItemTypes)playerAuthoratativeStates.itemToCast.usableItemType
                                      , playerAuthoratativeStates.itemToCast.itemCount);

            if (healthFillImage != null)
            {
                healthFillImage.fillAmount = (1f * currentHP) / maxHP;
                currentLifeStockText.text  = currentStockLives.ToString();
            }
        }
        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);
                    }
                }
            }
        }