Example #1
0
 public override void OnEvent(NewPlayerEvent evnt)
 {
     if (entity.IsOwner)
     {
         names.Add(evnt.Name);
         state.LeaderboardText = formattedLeaderboard();
     }
 }
 private void RefreshPlayers(object source, NewPlayerEvent e)
 {
     Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal,
                                           (Action) delegate()
     {
         Players = new ListCollectionView(_servicePlayer.AddPlayers(e.Player));
     }
                                           );
     OnPropertyChanged(nameof(Players));
 }
Example #3
0
    // Start is called before the first frame update
    void Start()
    {
        newPlayerEvent    = GetComponent <NewPlayerEvent>();
        outSceneEvent     = GetComponent <OutSceneEvent>();
        syncPositionEvent = GetComponent <SyncPositionEvent>();
        chatEvent         = GetComponent <ChatEvent>();

        PhotonEngine.Instance.AddEvent(newPlayerEvent);
        PhotonEngine.Instance.AddEvent(outSceneEvent);
        PhotonEngine.Instance.AddEvent(chatEvent);
    }
Example #4
0
    public override void Attached()
    {
        text      = GetComponent <Text>();
        debugText = GameObject.FindGameObjectWithTag("DebugText").GetComponent <Text>();
        state.AddCallback("LeaderboardText", LeaderboardTextCallback);
        state.AddCallback("DebugText", DebugTextCallback);
        var newPlayer = NewPlayerEvent.Create(entity);

        playerName = "Name" + (int)Random.Range(1, 10) + "\n";

        newPlayer.Name = playerName;
        newPlayer.Send();
    }
Example #5
0
    public static ServerResponse fromBytes(BitBuffer bitBuffer)
    {
        ResponseType type = (ResponseType)bitBuffer.GetByte();

        switch (type)
        {
        case ResponseType.PLAYER_UPDATE:
            return(PlayerInfoUpdate.FromBytes(bitBuffer));

        case ResponseType.ABILITY:
            return(AbilityResponse.FromBytes(bitBuffer));

        case ResponseType.NEW_PLAYER:
            return(NewPlayerEvent.FromBytes(bitBuffer));

        case ResponseType.PLAYER_INFO_BROADCAST:
            return(PlayerInfoBroadcast.FromBytes(bitBuffer));

        case ResponseType.RESPONSES_CONTAINER:
            return(ResponsesContainer.FromBytes(bitBuffer));
        }

        return(null);
    }
Example #6
0
    private void ProcessResponse(BitBuffer bitBuffer)
    {
        ServerResponse response = ServerResponse.fromBytes(bitBuffer);

        switch (response.GetResponseType())
        {
        case ResponseType.PLAYER_UPDATE: {
            PlayerInfoUpdate playerUpdate = (PlayerInfoUpdate)response;
            PlayerInfo       playerInfo   = playerUpdate.GetPlayerInfo();
            if (_players.ContainsKey(playerInfo.GetId()))
            {
                _players [playerInfo.GetId()].SetTargetPosition(playerInfo.GetPosition());
                _players [playerInfo.GetId()].SetHealth(playerInfo.GetHealth());
            }
            break;
        }

        case ResponseType.ABILITY: {
            AbilityResponse auto = (AbilityResponse)response;
            switch (auto.GetAbilityType())
            {
            case AbilityType.AUTOATTACK:
                SpawnAutoAttack(auto.GetId(), auto.GetStartPosition(), auto.GetPosition());
                break;

            case AbilityType.FREEZE:
                _players[auto.GetId()].SpawnFreeze(auto.GetPosition());
                break;

            case AbilityType.FLASH:
                _players[auto.GetId()].MoveTo(auto.GetPosition());
                _players[auto.GetId()].CancelMovement();
                break;

            case AbilityType.EXPLOSION:
                CreateExplosion(auto.GetPosition());
                break;
            }
            break;
        }

        case ResponseType.NEW_PLAYER: {
            NewPlayerEvent newPlayerEvent = (NewPlayerEvent)response;
            PlayerInfo     playerInfo     = newPlayerEvent.GetPlayerInfo();
            Player         player         = CreatePlayer(playerInfo);
            _players.Add(playerInfo.GetId(), player);
            break;
        }

        case ResponseType.PLAYER_INFO_BROADCAST: {
            PlayerInfoBroadcast playerInfoBroadcast = (PlayerInfoBroadcast)response;
            _localId = playerInfoBroadcast.GetId();
            foreach (PlayerInfo playerInfo in playerInfoBroadcast.getPlayersInfo())
            {
                Player player = CreatePlayer(playerInfo);
                _players.Add(playerInfo.GetId(), player);
            }
            break;
        }

        case ResponseType.RESPONSES_CONTAINER: {
            byte[]    responses       = ((ResponsesContainer)response).GetData();
            BitBuffer containerBuffer = new BitBuffer();
            containerBuffer.PutBytes(responses);
            containerBuffer.Flip();
            int totalResponses = containerBuffer.GetByte();
            for (int i = 0; i < totalResponses; i++)
            {
                ProcessResponse(containerBuffer);
            }
            break;
        }
        }
    }