Ejemplo n.º 1
0
    public void InitPlayers()
    {
        var aps = this.GetAllPlayers();
        Dictionary <int, int> playerPosDic = new Dictionary <int, int>();

        var poses = new TNet.List <int>();

        foreach (var m in _cellStyleDic)
        {
            var style = (MapStyle)m.Value;
            if (style == MapStyle.CANYON || style == MapStyle.HILL)
            {
                continue;
            }

            poses.Add(m.Key);
        }

        foreach (var p in aps)
        {
            var idx = Random.Range(0, poses.Count);

            playerPosDic.Add(p.id, poses[idx]);
            poses.Remove(idx);
        }

        tno.Send("RFC_SyncPlayersPosInfoAndCreatePlayer", Target.All, playerPosDic.ToJsonString());
    }
Ejemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     if (Export)
     {
         var obbjs = new TNet.List <TNObject>();
         obbjs.Add(gameObject.GetComponent <TNObject>());
         TNManager.ExportObjects(obbjs, delegate(DataNode n){
             Debug.Log("exported" + n.ToString());
         });
         Export = false;
     }
 }
Ejemplo n.º 3
0
    private void InitMapByHoset()
    {
        // Let's not try to create objects unless we are in this channel
        if (TNManager.isConnected && !TNManager.IsInChannel(GameCtr.Instance.ChannelID))
        {
            return;
        }
        if (!TNManager.isHosting)
        {
            return;
        }

        var aps         = this.GetAllPlayers();
        var mapStyleDic = new Dictionary <int, int> ();

        var poses = new TNet.List <int>();

        for (int i = 0; i < MapMgr.Instance.MapCellCount; i++)
        {
            poses.Add(i);
        }

        for (int i = 0; i < aps.Count; i++)
        {
            var posIdx = Random.Range(0, poses.Count);
            mapStyleDic.Add(posIdx, (int)MapStyle.PLAIN);
            poses.Remove(posIdx);
        }

        foreach (var p in poses)
        {
            mapStyleDic.Add(p, Random.Range(0, System.Enum.GetNames(typeof(MapStyle)).Length));
        }

        tno.Send("RFC_InitMap", Target.All, mapStyleDic.ToJsonString());
    }
Ejemplo n.º 4
0
    IEnumerator UpdatePlayerList()
    {
        while (true)
        {
            var playerTeam = TNManager.player.dataNode.GetChild <int>(NetworkManager.NODE_TeamId);

            var players = new TNet.List <PlayerListModel>();
            foreach (var p in TNManager.players)
            {
                players.Add(GetPlayerListModel(p));
            }
            players.Add(GetPlayerListModel(TNManager.player));

            int lastTeamId = -2;
            int teamLcv    = 0;
            int playerLcv  = 0;
            foreach (var pr in players.ToArray()
                     .OrderBy(p => p.TeamID)
                     .ThenByDescending(p => p.Kills)
                     .ThenBy(p => p.Name))
            {
                if (lastTeamId != pr.TeamID)
                {
                    lastTeamId = pr.TeamID;
                    GameObject teamRow = null;
                    if (TeamLines.Count <= teamLcv)
                    {
                        teamRow = GameObject.Instantiate(TeamRow) as GameObject;
                        teamRow.transform.SetParent(TeamPanel.transform);
                        teamRow.SetActive(false);
                        TeamLines.Add(teamRow);
                    }
                    teamRow = TeamLines[teamLcv];
                    teamRow.transform.SetParent(TeamListPanel.transform);
                    teamRow.SetActive(true);
                    var tr = teamRow.GetComponent <TeamRow>();
                    if (playerTeam == -1)
                    {
                        tr.Name.text = "Not yet picked a team.";
                    }
                    else
                    {
                        tr.Name.text = "Team " + lastTeamId.ToString();
                    }
                    teamLcv++;
                }

                GameObject playerRow = null;
                if (PlayerLines.Count <= playerLcv)
                {
                    playerRow = GameObject.Instantiate(PlayerRow) as GameObject;
                    playerRow.transform.SetParent(TeamPanel.transform);
                    playerRow.SetActive(false);
                    PlayerLines.Add(playerRow);
                }
                playerRow = PlayerLines[playerLcv];
                playerRow.transform.SetParent(TeamListPanel.transform);
                playerRow.SetActive(true);
                var prScript = playerRow.GetComponent <PlayerRow>();
                prScript.Name.text  = pr.Name;
                prScript.Score.text = string.Format("K: {0} D: {1}", pr.Kills, pr.Deaths);
                prScript.Info.text  = "stuff..";
                playerLcv++;
            }
            // hide and move any unused panels until needed
            for (int lcv = teamLcv; lcv < TeamLines.Count; lcv++)
            {
                TeamLines[lcv].transform.SetParent(TeamPanel.transform);
                TeamLines[lcv].SetActive(false);
            }
            for (int lcv = playerLcv; lcv < PlayerLines.Count; lcv++)
            {
                PlayerLines[lcv].transform.SetParent(TeamPanel.transform);
                PlayerLines[lcv].SetActive(false);
            }

            yield return(new WaitForSeconds(refreshTime));
        }
    }
Ejemplo n.º 5
0
 public void AddPlayerGo(PlayerGo p)
 {
     _playerGos.Add(p);
     Debug.Log("player go count = " + _playerGos.Count);
 }