Example #1
0
    private void OnRequestedSpawnPoint(byte[] data)
    {
        // Only the master client can provide spawn points
        if (!PhotonNetwork.IsMasterClient)
        {
            return;
        }

        Byterizer byterizer = new Byterizer();

        byterizer.LoadDeep(data);

        GridPosition gridPosition = GetFreeSpawnPoint();

        byterizer.Push(gridPosition.X);
        byterizer.Push(gridPosition.Z);

        data = byterizer.GetBuffer();

        // Raising Net Event
        RaiseEventOptions eventOptions = new RaiseEventOptions {
            Receivers = ReceiverGroup.Others, CachingOption = EventCaching.AddToRoomCache
        };
        SendOptions sendOptions = new SendOptions {
            Reliability = true
        };

        PhotonNetwork.RaiseEvent((byte)NetworkedGameEvents.SEND_SPAWN_POINT, data, eventOptions, sendOptions);
    }
Example #2
0
    private void OnNetworkEvent(EventData eventData)
    {
        byte eventCode = eventData.Code;

        if (eventCode == (byte)NetworkedGameEvents.PICKED_UP_INGREDIENT)
        {
            Byterizer byterizer = new Byterizer();
            byterizer.LoadDeep((byte[])eventData.CustomData);

            int ingredientViewID = byterizer.PopInt32();
            int heroViewID       = byterizer.PopInt32();

            if (heroViewID != GetComponent <PhotonView>().ViewID)
            {
                return;
            }

            PhotonView       ingredientView   = PhotonView.Find(ingredientViewID);
            IngredientMinion ingredientMinion = ingredientView.GetComponent <IngredientMinion>();
            if (ingredientMinion != null)
            {
                PickUpIngredient(ingredientMinion);
            }
        }
    }
Example #3
0
    private void OnNetworkEvent(EventData photonNetworkEvent)
    {
        byte eventCode = photonNetworkEvent.Code;

        if (eventCode == (byte)LobbyNetworkedEvents.PLAYER_READIED_UP)
        {
            Byterizer byterizer = new Byterizer();
            byterizer.LoadDeep((byte[])photonNetworkEvent.CustomData);
            int indexOfChosenHero = byterizer.PopInt32();
            OnPlayerReadiedUp(false, indexOfChosenHero);
        }

        else if (eventCode == (byte)LobbyNetworkedEvents.PLAYER_NOT_READY)
        {
            OnPlayerNotReady(false);
        }

        else if (eventCode == (byte)LobbyNetworkedEvents.CHOOSE_JUDGE_AND_DISH)
        {
            // The master client is the first one to be initialized so it need not initialize again
            if (PhotonNetwork.IsMasterClient)
            {
                return;
            }

            Byterizer byterizer = new Byterizer();
            byterizer.LoadDeep((byte[])photonNetworkEvent.CustomData);

            int judgeIndex = byterizer.PopInt32();
            int dishIndex  = byterizer.PopInt32();

            _LobbyDetails.Reset();
            _LobbyDetails.Initialize(judgeIndex, dishIndex);
        }
    }
Example #4
0
    private void OnRecievedSpawnPoint(byte[] data)
    {
        Byterizer byterizer = new Byterizer();

        byterizer.LoadDeep(data);

        // Checking if this spawn point is met for this player
        string playerID = byterizer.PopString();

        if (playerID != PhotonNetwork.LocalPlayer.UserId)
        {
            return;
        }

        GridPosition chosenHeroSpawn = new GridPosition(byterizer.PopByte(), byterizer.PopByte());

        SpawnHero(chosenHeroSpawn);
    }
    private void OnNetworkEvent(EventData eventData)
    {
        byte eventCode = eventData.Code;

        // On Node Selected
        if (eventCode == (byte)NetworkedGameEvents.ON_SELECTED_NODE)
        {
            // Extracting data
            byte[]    data      = (byte[])eventData.CustomData;
            Byterizer byterizer = new Byterizer();
            byterizer.LoadDeep(data);

            int playerControllerViewID = byterizer.PopInt32();

            // Checking if the event is for this player controller
            if (_PhotonView.ViewID != playerControllerViewID)
            {
                // Event not meant for this player controller
                return;
            }

            // Loading the left over data
            int   nodeViewID = byterizer.PopInt32();
            ANode node       = PhotonView.Find(nodeViewID).GetComponent <ANode>();

            OnSelectedNode(node);
        }

        // On Ingredient selected
        else if (eventCode == (byte)NetworkedGameEvents.ON_SELECTED_INGREDIENT)
        {
            // Extracting data
            byte[]    data      = (byte[])eventData.CustomData;
            Byterizer byterizer = new Byterizer();
            byterizer.LoadDeep(data);

            int playerControllerViewID = byterizer.PopInt32();

            // Checking if the event is for this player controller
            if (_PhotonView.ViewID != playerControllerViewID)
            {
                // Event not meant for this player controller
                return;
            }

            // Loading the left over data
            int ingredientViewID        = byterizer.PopInt32();
            IngredientMinion ingredient = PhotonView.Find(ingredientViewID).GetComponent <IngredientMinion>();
            OnSelectedIngredient(ingredient);
        }

        // On heroes collided
        else if (eventCode == (byte)NetworkedGameEvents.ON_HEROES_COLLIDED_EVENT)
        {
            if (PhotonNetwork.IsMasterClient)
            {
                return;
            }
            _CombatData.HeroesCollidedEvent.Invoke(null);
        }

        else if (eventCode == (byte)NetworkedGameEvents.ON_COMBAT_SEQUENCE_RESTARTED)
        {
            if (PhotonNetwork.IsMasterClient)
            {
                return;
            }
            _CombatData.CombatSequenceRestartedEvent.Invoke(null);
        }

        else if (eventCode == (byte)NetworkedGameEvents.ON_START_COMBAT_TIMER)
        {
            if (PhotonNetwork.IsMasterClient)
            {
                return;
            }

            // Extracting data
            byte[]    data      = (byte[])eventData.CustomData;
            Byterizer byterizer = new Byterizer();
            byterizer.LoadDeep(data);

            float time = byterizer.PopFloat();

            _CombatData.CombatTimerStartedEvent.Invoke(time);
        }

        // On combat option chosen
        else if (eventCode == (byte)NetworkedGameEvents.ON_SELECTED_COMBAT_OPTION)
        {
            /*  Combat validation only takes place in master client so the others need not be
             *  updated when someone choses. Its enough if they see the results */
            if (!PhotonNetwork.IsMasterClient)
            {
                return;
            }

            byte[]    data      = (byte[])eventData.CustomData;
            Byterizer byterizer = new Byterizer();
            byterizer.LoadDeep(data);

            int   playerViewID = byterizer.PopInt32();
            byte  chosenOption = (byte)byterizer.PopByte();
            int[] combatData   = { playerViewID, chosenOption };

            _CombatData.CombatOptionChosenEvent.Invoke(combatData);
        }

        // On show combat results event
        else if (eventCode == (byte)NetworkedGameEvents.ON_COMBAT_SEQUENCE_RESULT)
        {
            // This event is already triggered in the master client so it needs to be triggered only on other clients
            if (PhotonNetwork.IsMasterClient)
            {
                return;
            }

            byte[]    data      = (byte[])eventData.CustomData;
            Byterizer byterizer = new Byterizer();
            byterizer.LoadDeep(data);

            int playerViewID = byterizer.PopInt32();

            byte  chosenOption = (byte)byterizer.PopByte();
            int   winnerID     = byterizer.PopInt32();
            int[] combatData   = { playerViewID, chosenOption, winnerID };
            _CombatData.ShowCombatResultsEvent.Invoke(combatData);
        }

        // On combat sequence ended event
        else if (eventCode == (byte)NetworkedGameEvents.ON_COMBAT_SEQUENCE_ENDED)
        {
            if (PhotonNetwork.IsMasterClient)
            {
                return;
            }

            _CombatData.CombatSequenceCompletedEvent.Invoke((int)eventData.CustomData);
        }
    }