Esempio n. 1
0
    public void OnPlayerDataChanged(LobbyPlayerData playerData)
    {
        var existingPlayer = GetOrCreatePlayer(playerData.Id);

        bool availableCharactersChanged = existingPlayer.Character != playerData.Character;

        if (availableCharactersChanged)
        {
            _availableCharacters.Add(existingPlayer.Character);
            _availableCharacters.Remove(playerData.Character);
        }

        existingPlayer.Character = playerData.Character;
        existingPlayer.IsReady   = playerData.IsReady;

        int readyPlayers = 0;

        for (int i = 0; i < Players.Count; i++)
        {
            readyPlayers += Players [i].IsReady ? 1 : 0;
        }

        IsGameReadyToStart = readyPlayers >= NeedReadyPlayers;

        OnModelChanged();

        if (availableCharactersChanged)
        {
            OnModelAvailableCharactersChanged();
        }
    }
Esempio n. 2
0
    public void ApplyModel(LobbyPlayerData playerData, CharacterVisualData visualData)
    {
        _model      = playerData;
        _visualData = visualData;

        RefreshView();
    }
Esempio n. 3
0
 public GlobalPlayer(int deviceId, CharacterType characterTypeAssigned)
 {
     LobbyPlayerData = new LobbyPlayerData
     {
         Id        = deviceId,
         Character = characterTypeAssigned,
         IsReady   = false
     };
 }
Esempio n. 4
0
    public void AddPlayer(LobbyPlayerData playerData)
    {
        var existingPlayer = GetOrCreatePlayer(playerData.Id);

        existingPlayer.Character = playerData.Character;
        _availableCharacters.Remove(playerData.Character);

        OnModelChanged();
        OnModelAvailableCharactersChanged();
    }
Esempio n. 5
0
    public LobbyModel(int playerAmount, int waitingForReadyPlayers)
    {
        NeedReadyPlayers = waitingForReadyPlayers;
        Players          = new List <LobbyPlayerData>(playerAmount);

        for (int i = 0; i < playerAmount; i++)
        {
            Players.Add(LobbyPlayerData.CreateEmpty());
        }
    }
Esempio n. 6
0
    public void OnLobbyPlayerDataChanged(LobbyPlayerData player)
    {
        var existingPlayer = Model.GetOrCreatePlayer(player.Id);

        if (existingPlayer == null)
        {
            throw new PlayerDoesntExistException(player.Id);
        }

        Debug.LogFormat("OnLobbyPlayerDataChanged: {0} -> {1}", existingPlayer, player);
        Model.OnPlayerDataChanged(player);
    }
Esempio n. 7
0
    public void OnLobbyPlayerConnected(LobbyPlayerData playerData)
    {
        var existingPlayer = Model.GetPlayerByCharacter(playerData.Character);

        if (existingPlayer != null)
        {
            throw new CharacterAlreadyUsedException(playerData.Character);
        }

        Debug.LogFormat("OnLobbyPlayerConnected: {0}", playerData);
        Model.AddPlayer(playerData);
    }
Esempio n. 8
0
    void UpdateView(RoomInfo[] infos)
    {
        if (infos == null)
        {
            return;
        }
        Debug.LogError("UpdateView infos.Length=" + infos.Length);

        LobbyPlayerData[] datas = new LobbyPlayerData[0];
        for (int i = 0, length = infos.Length; i < length; i++)
        {
            var info = infos[i];
            if (info._ownerAccountName == _ownerAccountName)
            {
                datas = info._lobbyPlayerDatas.ToArray();
                break;
            }
        }

        for (int i = 0, length = _rooms.Count; i < length; i++)
        {
            Destroy(_rooms[i].gameObject);
        }
        _rooms.Clear();

        for (int i = 0, length = datas.Length; i < length; i++)
        {
            var go = Instantiate(_itemPrefab);
            go.gameObject.SetActive(true);
            go.transform.SetParent(_itemContent);
            go.transform.localScale = Vector3.one;
            go.data = datas[i];
            go._ownerAccountName = _ownerAccountName;
            _rooms.Add(go);
        }
    }