Example #1
0
    public void RequestInstantiate(byte pID)
    {
        Topan.NetworkPlayer player = Topan.Network.GetPlayerByID(pID);
        string teamTag             = ((byte)player.GetPlayerData("team") == 0) ? "RedSpawn" : "BlueSpawn";

        if (!GeneralVariables.gameModeHasTeams)
        {
            teamTag = "UnassignedSpawn";
        }

        GameObject[] spawns = GetSpawnPoints(teamTag);
        if (!GeneralVariables.gameModeHasTeams && spawns.Length <= 0)
        {
            Debug.Log("Consider adding unassigned spawn points for this map...");
            spawns = GetSpawnPoints((UnityEngine.Random.Range(0, 2) == 1) ? "RedSpawn" : "BlueSpawn");
        }

        Vector3 randomPos = new Vector3(UnityEngine.Random.Range(-1f, 1f), 0f, UnityEngine.Random.Range(-1f, 1f));

        if (spawns.Length > 0)
        {
            Transform spawn = spawns[UnityEngine.Random.Range(0, spawns.Length)].transform;
            Topan.Network.Instantiate(player, prefabProxy, prefabOwner, prefabProxy, (spawn.position + randomPos), spawn.rotation, 0);
        }
        else
        {
            Topan.Network.Instantiate(player, prefabProxy, prefabOwner, prefabProxy, randomPos, Quaternion.identity, 0);
        }
    }
Example #2
0
    public void CheckPing()
    {
        for (int i = 1; i < Topan.Network.connectedPlayers.Length; i++)
        {
            Topan.NetworkPlayer player = Topan.Network.GetPlayerByID(i);
            if (player == null)
            {
                continue;
            }

            if (player.HasPlayerData("ping") && (int)player.GetPlayerData("ping", 0) >= pingLimit)
            {
                pingViolations[i]++;
                Debug.Log("Player with ID of " + i + " has violated ping limit [x" + pingViolations[i] + "]");
            }
            else
            {
                pingViolations[i] = 0;
            }

            if (pingViolations[i] >= 5)
            {
                topanNetworkView.RPC(new int[1] {
                    i
                }, "KickPlayer", (byte)2);
                Debug.Log("Kicked player " + i + " because of ping limit violations");
            }
        }
    }
Example #3
0
    private void RefreshPlayers()
    {
        allSuccess = true;

        for (int i = 0; i < playerInfoSlots.Length; i++)
        {
            PlayerLobbyGUI plg = playerInfoSlots[i].GetComponent <PlayerLobbyGUI>();
            plg.usernameLabel.text = "";
            plg.rankLabel.text     = "";
            plg.transform.parent   = transform;
        }

        if (Topan.Network.isConnected)
        {
            for (int p = 0; p < Topan.Network.connectedPlayers.Length; p++)
            {
                Topan.NetworkPlayer player = Topan.Network.connectedPlayers[p];
                byte team = (byte)player.GetPlayerData("team", (byte)0);
                AddPlayerToList(team, player, null);
            }

            if (GeneralVariables.gameModeHasTeams)
            {
                BotPlayer[] redBots = NetworkingGeneral.GetBotParticipants(0);
                for (int i = 0; i < redBots.Length; i++)
                {
                    AddPlayerToList(0, null, redBots[i]);
                }

                BotPlayer[] blueBots = NetworkingGeneral.GetBotParticipants(1);
                for (int i = 0; i < blueBots.Length; i++)
                {
                    AddPlayerToList(0, null, blueBots[i]);
                }
            }
            else if (BotManager.allBotPlayers != null)
            {
                for (int i = 0; i < BotManager.allBotPlayers.Length && i < GeneralVariables.Networking.botCount; i++)
                {
                    AddPlayerToList(2, null, BotManager.allBotPlayers[i]);
                }
            }
        }

        for (int i = 0; i < playerInfoSlots.Length; i++)
        {
            PlayerLobbyGUI plg = playerInfoSlots[i].GetComponent <PlayerLobbyGUI>();
            if (plg.usernameLabel.text == "")
            {
                plg.rankIcon.enabled = false;
            }
        }
    }
Example #4
0
    public void Topan_OnPlayerDisconnected(Topan.NetworkPlayer p)
    {
        NetworkingGeneral.currentGameType.RemovePlayer(p.id);
        CombatantInfo pData = (CombatantInfo)p.GetInitialData("dat");

        if (!connectionBanList.Contains(p.peerObject.UniqueIdentifier.ToString()))
        {
            topanNetworkView.RPC(Topan.RPCMode.All, "LeaveMSG", pData.username);
        }

        Topan.Network.DestroyPlayerViews(p.id);
    }
Example #5
0
    public void SwitchTeams(int team)
    {
        if (!GeneralVariables.gameModeHasTeams)
        {
            return;
        }

        Topan.NetworkPlayer p = Topan.Network.player;
        if (p.HasPlayerData("team") && ((byte)p.GetPlayerData("team") == (byte)team))
        {
            return;
        }

        GeneralVariables.connectionView.RPC(Topan.RPCMode.Server, "SwitchTeams", (byte)Topan.Network.player.id, (byte)team);
    }
Example #6
0
    public void Topan_OnPlayerConnected(Topan.NetworkPlayer p)
    {
        if (p.id > 0 && connectionBanList.Contains(p.peerObject.UniqueIdentifier.ToString()))
        {
            topanNetworkView.RPC(new int[1] {
                p.id
            }, "KickPlayer", (byte)1);
            return;
        }

        p.SetPlayerData("k", (UInt16)0);
        p.SetPlayerData("a", (UInt16)0);
        p.SetPlayerData("d", (UInt16)0);
        p.SetPlayerData("h", (UInt16)0);
        p.SetPlayerData("sc", 0);

        int playerTeam = NetworkingGeneral.currentGameType.GetTeamAssign(p.id);

        p.SetPlayerData("team", (byte)playerTeam);

        CombatantInfo pData = (CombatantInfo)p.GetInitialData("dat");

        topanNetworkView.RPC(Topan.RPCMode.All, "JoinMSG", pData.username);

        if (!p.isServer)
        {
            if (!inLobby)
            {
                topanNetworkView.RPC(new int[1] {
                    p.id
                }, "LoadGame", currentMapHash);
            }
            else
            {
                topanNetworkView.RPC(new int[1] {
                    p.id
                }, "LoadLobby");
            }
        }
    }
Example #7
0
    public void SwitchTeams(byte pID, byte team)
    {
        Topan.NetworkPlayer p = Topan.Network.GetPlayerByID((int)pID);
        if (p.HasPlayerData("team") && ((byte)p.GetPlayerData("team") == (byte)team))
        {
            return;
        }

        bool autoBalance = true;

        if (NetworkingGeneral.currentGameType.customSettings.ContainsKey("Team Auto-Balance"))
        {
            autoBalance = DarkRef.ConvertStringToBool(NetworkingGeneral.currentGameType.customSettings["Team Auto-Balance"].currentValue);
        }

        if (autoBalance && !NetworkingGeneral.currentGameType.ValidTeamSwitch((int)team))
        {
            return;
        }

        NetworkingGeneral.currentGameType.RemovePlayer((int)pID);
        NetworkingGeneral.currentGameType.AddPlayer((int)pID, (int)team);
        p.SetPlayerData("team", team);
    }
Example #8
0
    void Awake()
    {
        countToNextRound        = 10;
        vignetting.intensity    = 0f;
        blackStuff.alpha        = 0f;
        Screen.lockCursor       = false;
        UICamera.selectedObject = null;

        sortedPlayers = new List <NetPlayerInfo>();

        for (int i = 0; i < Topan.Network.connectedPlayers.Length; i++)
        {
            Topan.NetworkPlayer curPlayer = Topan.Network.connectedPlayers[i];

            NetPlayerInfo npi = new NetPlayerInfo();
            npi.realPlayer = curPlayer;
            npi.myKills    = (int)((UInt16)curPlayer.GetPlayerData("k", (UInt16)0));
            npi.myDeaths   = (int)((UInt16)curPlayer.GetPlayerData("d", (UInt16)0));
            npi.myHeads    = (int)((UInt16)curPlayer.GetPlayerData("h", (UInt16)0));
            npi.myScore    = (int)curPlayer.GetPlayerData("sc", 0);
            sortedPlayers.Add(npi);
        }

        if (GeneralVariables.gameModeHasTeams)
        {
            teamBasedRoot.SetActive(true);
            Destroy(individualBasedRoot);

            int redIndex  = 0;
            int blueIndex = 0;

            sortedPlayers = new List <NetPlayerInfo>();
            for (int i = 0; i < Topan.Network.connectedPlayers.Length; i++)
            {
                Topan.NetworkPlayer curPlayer = Topan.Network.connectedPlayers[i];

                NetPlayerInfo npi = new NetPlayerInfo();
                npi.realPlayer = curPlayer;
                npi.myKills    = (int)((UInt16)curPlayer.GetPlayerData("k", (UInt16)0));
                npi.myDeaths   = (int)((UInt16)curPlayer.GetPlayerData("d", (UInt16)0));
                npi.myHeads    = (int)((UInt16)curPlayer.GetPlayerData("h", (UInt16)0));
                npi.myScore    = (int)curPlayer.GetPlayerData("sc", 0);
                sortedPlayers.Add(npi);
            }

            BotPlayer[] redBots = NetworkingGeneral.GetBotParticipants(0);
            for (int i = 0; i < redBots.Length; i++)
            {
                BotStats hisStats = BotManager.GetBotStats(redBots[i].index);

                NetPlayerInfo npi = new NetPlayerInfo();
                npi.botPlayer = redBots[i];
                npi.myKills   = hisStats.kills;
                npi.myDeaths  = hisStats.deaths;
                npi.myHeads   = hisStats.headshots;
                npi.myScore   = hisStats.score;
                sortedPlayers.Add(npi);
            }

            BotPlayer[] blueBots = NetworkingGeneral.GetBotParticipants(1);
            for (int i = 0; i < blueBots.Length; i++)
            {
                BotStats hisStats = BotManager.GetBotStats(blueBots[i].index);

                NetPlayerInfo npi = new NetPlayerInfo();
                npi.botPlayer = blueBots[i];
                npi.myKills   = hisStats.kills;
                npi.myDeaths  = hisStats.deaths;
                npi.myHeads   = hisStats.headshots;
                npi.myScore   = hisStats.score;
                sortedPlayers.Add(npi);
            }

            if (NetworkingGeneral.currentGameType.sortPlayersBy == SortPlayersBy.Kills)
            {
                sortedPlayers.Sort((p1, p2) => p2.myKills.CompareTo(p1.myKills));
            }
            else if (NetworkingGeneral.currentGameType.sortPlayersBy == SortPlayersBy.Score)
            {
                sortedPlayers.Sort((p1, p2) => p2.myScore.CompareTo(p1.myScore));
            }

            for (int i = 0; i < sortedPlayers.Count; i++)
            {
                NetPlayerInfo current = sortedPlayers[i];
                if (current.botPlayer == null && current.realPlayer == null)
                {
                    continue;
                }

                if (current.myInfo == null)
                {
                    continue;
                }

                int   kills  = current.myKills;
                int   deaths = current.myDeaths;
                int   score  = current.myScore;
                float kd     = (deaths > 0) ? ((float)kills / (float)deaths) : kills;

                UserStatsGUI usg = null;
                if (current.myTeam == 0)
                {
                    UserStatsGUI instance = (UserStatsGUI)Instantiate(scoreboardPrefab);
                    instance.transform.parent        = redStart;
                    instance.transform.localPosition = Vector3.down * (redIndex * statsSpacing);
                    instance.transform.localScale    = Vector3.one;
                    usg = instance;
                    redIndex++;
                }
                else
                {
                    UserStatsGUI instance = (UserStatsGUI)Instantiate(scoreboardPrefab);
                    instance.transform.parent        = blueStart;
                    instance.transform.localPosition = Vector3.down * (blueIndex * statsSpacing);
                    instance.transform.localScale    = Vector3.one;
                    usg = instance;
                    blueIndex++;
                }

                int thisListIndex = (current.myTeam == 0) ? redIndex : blueIndex;

                string clanNameFinal = (current.myInfo.clan != "") ? ((current.thisPlayerIsBot) ? DarkRef.ClanColor(true) + "(" + current.myInfo.clan + ")[-] " : DarkRef.ClanColor(false) + "[" + current.myInfo.clan + "][-] ") : "";
                usg.SetInfo(((current.myInfo != null) ? current.myInfo.rank : 1).ToString(),
                            clanNameFinal + current.myInfo.username,
                            kills.ToString(),
                            deaths.ToString(),
                            kd.ToString("F2"),
                            current.myHeads.ToString(),
                            score.ToString(),
                            ((current.thisPlayerIsBot) ? Topan.Network.server.GetPlayerData("ping", 0).ToString() : current.realPlayer.GetPlayerData("ping", 0)).ToString(),
                            (!current.thisPlayerIsBot && current.realPlayer == Topan.Network.player),
                            (thisListIndex % 2 == 0));
            }
        }
        else
        {
            Destroy(teamBasedRoot);
            individualBasedRoot.SetActive(true);

            int currentIndex = 0;

            for (int i = 0; i < BotManager.allBotPlayers.Length && i < GeneralVariables.Networking.botCount; i++)
            {
                BotStats hisStats = BotManager.GetBotStats(i);

                NetPlayerInfo npi = new NetPlayerInfo();
                npi.botPlayer = BotManager.allBotPlayers[i];
                npi.myKills   = hisStats.kills;
                npi.myDeaths  = hisStats.deaths;
                npi.myHeads   = hisStats.headshots;
                npi.myScore   = hisStats.score;
                sortedPlayers.Add(npi);
            }

            if (NetworkingGeneral.currentGameType.sortPlayersBy == SortPlayersBy.Kills)
            {
                sortedPlayers.Sort((p1, p2) => p2.myKills.CompareTo(p1.myKills));
            }
            else if (NetworkingGeneral.currentGameType.sortPlayersBy == SortPlayersBy.Score)
            {
                sortedPlayers.Sort((p1, p2) => p2.myScore.CompareTo(p1.myScore));
            }

            for (int i = 0; i < sortedPlayers.Count; i++)
            {
                NetPlayerInfo current = sortedPlayers[i];
                if (current.botPlayer == null && current.realPlayer == null)
                {
                    continue;
                }

                if (current.myInfo == null)
                {
                    continue;
                }

                int   kills  = current.myKills;
                int   deaths = current.myDeaths;
                int   score  = current.myScore;
                float kd     = (deaths > 0) ? ((float)kills / (float)deaths) : kills;

                if (currentIndex >= 16)
                {
                    continue;
                }

                UserStatsGUI instance = (UserStatsGUI)Instantiate(scoreboardPrefab);
                instance.transform.parent        = individualStart;
                instance.transform.localPosition = Vector3.down * (currentIndex * statsSpacing);
                instance.transform.localScale    = Vector3.one;

                currentIndex++;

                string clanNameFinal = (current.myInfo.clan != "") ? ((current.thisPlayerIsBot) ? DarkRef.ClanColor(true) + "(" + current.myInfo.clan + ")[-] " : DarkRef.ClanColor(false) + "[" + current.myInfo.clan + "][-] ") : "";
                instance.SetInfo(((current.myInfo != null) ? current.myInfo.rank : 1).ToString(),
                                 clanNameFinal + current.myInfo.username,
                                 kills.ToString(),
                                 deaths.ToString(),
                                 kd.ToString("F2"),
                                 current.myHeads.ToString(),
                                 score.ToString(),
                                 ((current.thisPlayerIsBot) ? Topan.Network.server.GetPlayerData("ping", 0).ToString() : current.realPlayer.GetPlayerData("ping", 0)).ToString(),
                                 (!current.thisPlayerIsBot && current.realPlayer == Topan.Network.player),
                                 (currentIndex % 2 == 0));
            }
        }

        if (GeneralVariables.gameModeHasTeams)
        {
            roundLabel.cachedTrans.localPosition    = new Vector3(0f, 245f, -7f);
            spectatorList.cachedTrans.localPosition = new Vector3(-395f, -316f, 0f);
            panelRoot.localPosition = Vector3.zero;
            statsBackground.SetDimensions(270, 530);
            statsOutline.SetDimensions(278, 540);
        }
        else
        {
            roundLabel.cachedTrans.localPosition    = new Vector3(0f, 225f, -7f);
            spectatorList.cachedTrans.localPosition = new Vector3(-395f, -261f, 0f);
            panelRoot.localPosition = Vector3.up * -20f;
            statsBackground.SetDimensions(270, 440);
            statsOutline.SetDimensions(278, 450);
        }

        int roundScore = (int)Topan.Network.player.GetPlayerData("sc", 0);
        int targetExp  = AccountManager.GetTargetExperienceForRank(AccountManager.profileData.rank);

        startExp             = AccountManager.profileData.curXP;
        currentExpValue      = startExp;
        earnedExp            = roundScore;
        earnedCurrency       = Mathf.RoundToInt(roundScore * UnityEngine.Random.Range(0.95f, 1.05f) * 0.237f);
        expBaseAnimationTime = Mathf.Max(0.01f, expBaseAnimationTime);
        animationSpeed       = (float)earnedExp / expBaseAnimationTime;
        expSlowdownTime      = Mathf.Clamp(expSlowdownTime, 0f, 0.99f);

        expAccumulateSound.volume = 0f;
        expProgressBar.value      = (float)startExp / (float)targetExp;
        xpLabel.text        = startExp.ToString() + " XP / " + targetExp.ToString() + " XP";
        xpLeftLabel.text    = (targetExp - startExp).ToString() + " XP REMAINING";
        currencyLabel.alpha = 0f;
        currencyLabel.text  = "+0 CREDITS";
        rankLabel.text      = "[u]" + AccountManager.profileData.username + "[/u]" + "\n" + "RANK " + AccountManager.profileData.rank.ToString() + " [ROOKIE]";
        nextRankLabel.text  = "RANK " + (AccountManager.profileData.rank + 1).ToString() + " [ROOKIE]";

        StartCoroutine(ProcessData());
    }
Example #9
0
    private void AddPlayerToList(int team, Topan.NetworkPlayer player, BotPlayer bot = null)
    {
        int realTeamNum = team;

        if (player != null && !player.HasPlayerData("team"))
        {
            allSuccess = false;
            return;
        }

        bool thisIsBot = (player == null && bot != null);

        if (thisIsBot && team < 2)
        {
            realTeamNum = (int)bot.team;
        }

        GameObject info = GetAvailableSlot();

        if (info == null)
        {
            return;
        }

        bool showInfo = true;
        int  index    = 0;

        if (!GeneralVariables.gameModeHasTeams)
        {
            index = unassignedIndex;

            if (realTeamNum == 2)
            {
                if (index < 8)
                {
                    info.transform.parent = redPanel;
                }
                else
                {
                    info.transform.parent = bluePanel;
                }
            }
            else
            {
                showInfo = false;
            }

            info.transform.localPosition = new Vector3(0f, -(index % 8) * spacing, 0f);
        }
        else
        {
            if (realTeamNum == 0 && redIndex < 8)
            {
                index = redIndex;
                info.transform.parent = redPanel;
            }
            else if (realTeamNum == 1 && blueIndex < 8)
            {
                index = blueIndex;
                info.transform.parent = bluePanel;
            }
            else
            {
                showInfo = false;
            }

            info.transform.localPosition = new Vector3(0f, -index * spacing, 0f);
        }

        info.SetActive(showInfo);
        info.transform.localRotation = Quaternion.identity;
        info.transform.localScale    = Vector3.one;

        PlayerLobbyGUI plg = info.GetComponent <PlayerLobbyGUI>();

        CombatantInfo pInfo = null;

        if (thisIsBot)
        {
            pInfo = bot.botInfo;
        }
        else
        {
            pInfo = (CombatantInfo)player.GetInitialData("dat");
        }

        plg.rankIcon.enabled   = true;
        plg.usernameLabel.text = ((pInfo.clan != "") ? (((thisIsBot) ? (DarkRef.ClanColor(true) + "(" + pInfo.clan + ")") : (DarkRef.ClanColor(false) + "[" + pInfo.clan + "]")) + "[-] ") : "") + pInfo.username;
        plg.rankLabel.text     = pInfo.rank.ToString();

        index++;
        if (!GeneralVariables.gameModeHasTeams)
        {
            if (realTeamNum == 2)
            {
                unassignedIndex = index;
            }
        }
        else
        {
            if (realTeamNum == 0)
            {
                redIndex = index;
            }
            else if (realTeamNum == 1)
            {
                blueIndex = index;
            }
        }
    }
Example #10
0
 void Topan_OnPlayerConnected(Topan.NetworkPlayer p)
 {
     //		Topan.Network.Instantiate(p, "NetworkSpeaker", Vector3.zero, Quaternion.identity, 0);
 }
Example #11
0
    public void UpdateSettings()
    {
        if (!serverEditMode)
        {
            return;
        }

        if (!Topan.Network.HasServerInfo("dur") || (byte)Topan.Network.GetServerInfo("dur") != (byte)gameDurationSlider.currentDuration)
        {
            Topan.Network.SetServerInfo("dur", (byte)gameDurationSlider.currentDuration);
        }

        if (!Topan.Network.HasServerInfo("rc") || (byte)Topan.Network.GetServerInfo("rc") != (byte)roundCountSlider.currentRoundAmount)
        {
            Topan.Network.SetServerInfo("rc", (byte)roundCountSlider.currentRoundAmount);
        }

        if (!Topan.Network.HasServerInfo("it") || (byte)Topan.Network.GetServerInfo("it") != (byte)(idleTimeSlider.currentIdleTime / 5))
        {
            Topan.Network.SetServerInfo("dur", (byte)(idleTimeSlider.currentIdleTime / 5));
        }

        if (!Topan.Network.HasServerInfo("bC") || (byte)Topan.Network.GetServerInfo("bC") != (byte)bsMenu.amountSlider.currentValue)
        {
            Topan.Network.SetServerInfo("bC", (byte)bsMenu.amountSlider.currentValue);
        }

        gameDurationSlider.ApplyChanges();
        roundCountSlider.ApplyChanges();
        idleTimeSlider.ApplyChanges();

        int setPingLimit = Mathf.Clamp(int.Parse(pingLimitInput.value), 100, 9999);

        if (!Topan.Network.HasServerInfo("plim") || GeneralVariables.server.pingLimit != setPingLimit)
        {
            Topan.Network.SetServerInfo("plim", setPingLimit);
            GeneralVariables.server.pingLimit = setPingLimit;
        }

        PlayerPrefs.SetString("SavedPingLimit", pingLimitInput.value);
        PlayerPrefs.SetInt("SavedMapIndex", selectedMap);
        PlayerPrefs.SetInt("SavedGameMode", mSettingControl.gameModePopup.selectionIndex);

        if (!Topan.Network.HasServerInfo("m") || selectedMap != oldSelection)
        {
            Topan.Network.SetServerInfo("m", (byte)selectedMap);
        }

        oldSelection = selectedMap;
        Topan.MasterServer.UpdateServerInfo(selectedMap, gameTypeIndexes[mSettingControl.gameTypeName]);

        if (!Topan.Network.HasServerInfo("gm") || Topan.Network.GetServerInfo("gm").ToString() != NetworkingGeneral.currentGameType.typeName)
        {
            Topan.Network.SetServerInfo("gm", NetworkingGeneral.currentGameType.typeName);
        }

        foreach (GM_SettingsControl.SettingInfo sInfo in mSettingControl.settingsList)
        {
            Topan.Network.SetServerInfo(sInfo.settingName, NetworkingGeneral.currentGameType.customSettings[sInfo.settingName].currentValue);
        }

        NetworkingGeneral.currentGameType.ClearPlayerList();
        for (int i = 0; i < Topan.Network.connectedPlayers.Length; i++)
        {
            Topan.NetworkPlayer p = Topan.Network.connectedPlayers[i];
            p.SetPlayerData("team", (byte)NetworkingGeneral.currentGameType.GetTeamAssign(p.id));
        }

        hostServerButton.cachedLabel.text = "";
        moveCam.TargetPos(new Vector3(3840f, -800f, -700f));
        ServerEditMode(false);
    }
Example #12
0
    public void Refresh()
    {
        if (!Topan.Network.isConnected)
        {
            return;
        }

        sortedPlayers = new List <NetPlayerInfo>();

        for (int i = 0; i < Topan.Network.connectedPlayers.Length; i++)
        {
            Topan.NetworkPlayer curPlayer = Topan.Network.connectedPlayers[i];
            NetPlayerInfo       npi       = new NetPlayerInfo();

            npi.realPlayer = curPlayer;
            npi.myKills    = (int)((UInt16)curPlayer.GetPlayerData("k", (UInt16)0));
            npi.myDeaths   = (int)((UInt16)curPlayer.GetPlayerData("d", (UInt16)0));
            npi.myHeads    = (int)((UInt16)curPlayer.GetPlayerData("h", (UInt16)0));
            npi.myScore    = (int)curPlayer.GetPlayerData("sc", 0);
            sortedPlayers.Add(npi);

            if (curPlayer.id == Topan.Network.player.id)
            {
                yourPlayer = npi;
            }
        }

        if (GeneralVariables.gameModeHasTeams)
        {
            int redIndex       = 0;
            int blueIndex      = 0;
            int redTotalScore  = 0;
            int blueTotalScore = 0;

            waitingForRed  = true;
            waitingForBlue = true;

            BotPlayer[] redBots = NetworkingGeneral.GetBotParticipants(0);
            for (int i = 0; i < redBots.Length; i++)
            {
                BotStats hisStats = BotManager.GetBotStats(redBots[i].index);

                NetPlayerInfo npi = new NetPlayerInfo();
                npi.botPlayer = redBots[i];
                npi.myKills   = hisStats.kills;
                npi.myDeaths  = hisStats.deaths;
                npi.myHeads   = hisStats.headshots;
                npi.myScore   = hisStats.score;
                sortedPlayers.Add(npi);
            }

            BotPlayer[] blueBots = NetworkingGeneral.GetBotParticipants(1);
            for (int i = 0; i < blueBots.Length; i++)
            {
                BotStats hisStats = BotManager.GetBotStats(blueBots[i].index);

                NetPlayerInfo npi = new NetPlayerInfo();
                npi.botPlayer = blueBots[i];
                npi.myKills   = hisStats.kills;
                npi.myDeaths  = hisStats.deaths;
                npi.myHeads   = hisStats.headshots;
                npi.myScore   = hisStats.score;
                sortedPlayers.Add(npi);
            }

            if (NetworkingGeneral.currentGameType.sortPlayersBy == SortPlayersBy.Kills)
            {
                sortedPlayers.Sort((p1, p2) => p2.myKills.CompareTo(p1.myKills));
            }
            else if (NetworkingGeneral.currentGameType.sortPlayersBy == SortPlayersBy.Score)
            {
                sortedPlayers.Sort((p1, p2) => p2.myScore.CompareTo(p1.myScore));
            }

            tdmSubheader.text = NetworkingGeneral.currentGameType.typeName + " [" + Topan.Network.GameName + "]";
            for (int i = 0; i < sortedPlayers.Count; i++)
            {
                NetPlayerInfo current = sortedPlayers[i];
                if (current.botPlayer == null && current.realPlayer == null)
                {
                    continue;
                }

                if (current.myInfo == null)
                {
                    continue;
                }

                int   kills  = current.myKills;
                int   deaths = current.myDeaths;
                int   score  = current.myScore;
                float kd     = (deaths > 0) ? ((float)kills / (float)deaths) : kills;

                UserStatsGUI usg = null;
                if (current.myTeam == 0)
                {
                    if (redIndex >= 8)
                    {
                        continue;
                    }

                    waitingForRed = false;
                    usg           = redTeam[redIndex];
                    usg.gameObject.SetActive(true);
                    redTotalScore += score;
                    redIndex++;
                }
                else if (current.myTeam == 1)
                {
                    if (blueIndex >= 8)
                    {
                        continue;
                    }

                    waitingForBlue = false;
                    usg            = blueTeam[blueIndex];
                    usg.gameObject.SetActive(true);
                    blueTotalScore += score;
                    blueIndex++;
                }

                int thisListIndex = (current.myTeam == 0) ? redIndex : blueIndex;

                string clanNameFinal = (current.myInfo.clan != "") ? ((current.thisPlayerIsBot) ? DarkRef.ClanColor(true) + "(" + current.myInfo.clan + ")[-] " : DarkRef.ClanColor(false) + "[" + current.myInfo.clan + "][-] ") : "";
                usg.SetInfo(current.myInfo.rank.ToString(),
                            clanNameFinal + current.myInfo.username,
                            kills.ToString(),
                            deaths.ToString(),
                            kd.ToString("F2"),
                            current.myHeads.ToString(),
                            score.ToString(),
                            ((current.thisPlayerIsBot) ? Topan.Network.server.GetPlayerData("ping", 0).ToString() : current.realPlayer.GetPlayerData("ping", 0)).ToString(),
                            (!current.thisPlayerIsBot && current.realPlayer == Topan.Network.player),
                            (thisListIndex % 2 == 0));
            }

            if (redIndex < 7)
            {
                for (int i = redIndex; i < 8; i++)
                {
                    redTeam[i].gameObject.SetActive(false);
                }
            }

            if (blueIndex < 7)
            {
                for (int i = blueIndex; i < 8; i++)
                {
                    blueTeam[i].gameObject.SetActive(false);
                }
            }

            try
            {
                tkRed  = (UInt16)Topan.Network.GetServerInfo("rTK");
                tkBlue = (UInt16)Topan.Network.GetServerInfo("bTK");
                tdRed  = (UInt16)Topan.Network.GetServerInfo("rTD");
                tdBlue = (UInt16)Topan.Network.GetServerInfo("bTD");
            }
            catch
            {
                tkRed  = 0;
                tkBlue = 0;
                tdRed  = 0;
                tdBlue = 0;
            }

            string redTotal = "Total Kills: " + tkRed;
            redTotal += "\n" + "Total Deaths: " + tdRed;
            float redKD = (tdRed > 0) ? ((float)tkRed / (float)tdRed) : tkRed;
            redTotal += "\n" + "Total K/D: " + redKD.ToString("F2");
            redTotal += "\n" + "Team Score: " + redTotalScore.ToString();
            redTotal += "\n----------------";
            redTotal += "\n" + "Team Captures: 0"; //Placeholder, captures if capture the flag, defuses if demolition.

            string blueTotal = "Total Kills: " + tkBlue;
            blueTotal += "\n" + "Total Deaths: " + tdBlue;
            float blueKD = (tdBlue > 0) ? ((float)tkBlue / (float)tdBlue) : tkBlue;
            blueTotal += "\n" + "Total K/D: " + blueKD.ToString("F2");
            blueTotal += "\n" + "Team Score: " + blueTotalScore.ToString();
            blueTotal += "\n----------------";
            blueTotal += "\n" + "Team Captures: 0"; //Placeholder, captures if capture the flag, defuses if demolition.

            totalStatsRed.text  = redTotal;
            totalStatsBlue.text = blueTotal;

            roundVictoryStats.text = "[CE1C1C](RED)[-] " + (byte)Topan.Network.GetServerInfo("rVic") + " [A0A0A0]|[-] " + (byte)Topan.Network.GetServerInfo("bVic") + " [2546A5](BLUE)[-]";
        }
        else
        {
            int currentIndex = 0;
            int yourIndex    = 1;

            for (int i = 0; i < BotManager.allBotPlayers.Length && i < GeneralVariables.Networking.botCount; i++)
            {
                BotStats hisStats = BotManager.GetBotStats(i);

                NetPlayerInfo npi = new NetPlayerInfo();
                npi.botPlayer = BotManager.allBotPlayers[i];
                npi.myKills   = hisStats.kills;
                npi.myDeaths  = hisStats.deaths;
                npi.myHeads   = hisStats.headshots;
                npi.myScore   = hisStats.score;
                sortedPlayers.Add(npi);
            }

            if (NetworkingGeneral.currentGameType.sortPlayersBy == SortPlayersBy.Kills)
            {
                sortedPlayers.Sort((p1, p2) => p2.myKills.CompareTo(p1.myKills));
            }
            else if (NetworkingGeneral.currentGameType.sortPlayersBy == SortPlayersBy.Score)
            {
                sortedPlayers.Sort((p1, p2) => p2.myScore.CompareTo(p1.myScore));
            }

            dmSubheader.text = NetworkingGeneral.currentGameType.typeName + " [" + Topan.Network.GameName + "]";
            for (int i = 0; i < sortedPlayers.Count; i++)
            {
                NetPlayerInfo current = sortedPlayers[i];
                if (current.botPlayer == null && current.realPlayer == null)
                {
                    continue;
                }

                if (current.myInfo == null)
                {
                    continue;
                }

                int   kills  = current.myKills;
                int   deaths = current.myDeaths;
                int   score  = current.myScore;
                float kd     = (deaths > 0) ? ((float)kills / (float)deaths) : kills;

                UserStatsGUI usg = null;

                if (currentIndex >= 16)
                {
                    continue;
                }

                usg = individuals[currentIndex];
                usg.gameObject.SetActive(true);
                currentIndex++;

                if (!current.thisPlayerIsBot && current.realPlayer == Topan.Network.player)
                {
                    yourIndex = i;
                }

                string clanNameFinal = (current.myInfo.clan != "") ? ((current.thisPlayerIsBot) ? DarkRef.ClanColor(true) + "(" + current.myInfo.clan + ")[-] " : DarkRef.ClanColor(false) + "[" + current.myInfo.clan + "][-] ") : "";
                usg.SetInfo(current.myInfo.rank.ToString(),
                            clanNameFinal + current.myInfo.username,
                            kills.ToString(),
                            deaths.ToString(),
                            kd.ToString("F2"),
                            current.myHeads.ToString(),
                            score.ToString(),
                            ((current.thisPlayerIsBot) ? Topan.Network.server.GetPlayerData("ping", 0).ToString() : current.realPlayer.GetPlayerData("ping", 0)).ToString(),
                            (!current.thisPlayerIsBot && current.realPlayer == Topan.Network.player),
                            (currentIndex % 2 == 0));
            }

            if (currentIndex < 15)
            {
                for (int i = currentIndex; i < 16; i++)
                {
                    individuals[i].gameObject.SetActive(false);
                }
            }

            tkRed  = 0;
            tkBlue = 0;
            tdRed  = 0;
            tdBlue = 0;

            yourPlace.text = "You're in " + DarkRef.OrdinalIndicatorFormat(yourIndex + 1) + " place";
        }

        refreshTimer += refreshTime;
    }
Example #13
0
    public void KilledPlayer(string data)
    {
        if (!startedMatch)
        {
            return;
        }

        bool isSuicide   = false;
        bool didHeadshot = false;
        bool isGrenade   = false;

        int   victim         = 0;
        int   killerDamageID = 0;
        int   weaponID       = 0;
        float totalDamage    = 0f;

        inflictors.Clear();
        dmgValues.Clear();
        toUpdateBots.Clear();

        string[] splitCateg = data.Split(new string[] { "." }, System.StringSplitOptions.None);

        if (splitCateg.Length == 1)
        {
            string[] playerData = splitCateg[0].Split(new string[] { "," }, System.StringSplitOptions.RemoveEmptyEntries);
            victim = int.Parse(playerData[0]);

            if (playerData.Length == 1)
            {
                isSuicide = true;
            }
        }
        else if (splitCateg.Length >= 2)
        {
            string[] playerData = splitCateg[0].Split(new string[] { "," }, System.StringSplitOptions.RemoveEmptyEntries);
            victim = int.Parse(playerData[0]);

            if (playerData.Length >= 2)
            {
                for (int i = 1; i < playerData.Length; i++)
                {
                    string realID = playerData[i];
                    if (playerData[i].Contains("!"))
                    {
                        realID      = realID.Substring(0, realID.Length - 1);
                        didHeadshot = true;
                    }

                    if (playerData.Length == 2)
                    {
                        killerDamageID = i - 1;
                        inflictors.Insert(0, int.Parse(realID));
                    }
                    else if (playerData[i].Contains("k"))
                    {
                        killerDamageID = i - 1;
                        realID         = realID.Substring(0, realID.Length - 1);
                        inflictors.Insert(0, int.Parse(realID));
                    }
                    else
                    {
                        inflictors.Add(int.Parse(realID));
                    }
                }
            }

            if (playerData.Length > 2)
            {
                string[] dmgData = splitCateg[1].Split(new string[] { "," }, System.StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < dmgData.Length; i++)
                {
                    if (dmgData[i].Contains("-"))
                    {
                        continue;
                    }

                    dmgValues.Add(float.Parse(dmgData[i]));
                    totalDamage += dmgValues[i];
                }

                dmgValues.RemoveAt(killerDamageID);
            }

            if (splitCateg.Length == 3)
            {
                if (splitCateg[2].Contains("*"))
                {
                    isGrenade     = true;
                    splitCateg[2] = splitCateg[2].Substring(0, splitCateg[2].Length - 1);
                }

                weaponID = int.Parse(splitCateg[2]);
            }
        }

        bool killerIsBot = (inflictors.Count > 0 && inflictors[0] >= 64);
        bool victimIsBot = (victim >= 64);

        Topan.NetworkPlayer klr     = null;
        Topan.NetworkPlayer vctm    = null;
        BotPlayer           klrBot  = null;
        BotPlayer           vctmBot = null;

        if (!isSuicide)
        {
            if (killerIsBot)
            {
                klrBot = BotManager.allBotPlayers[inflictors[0] - 64];
            }
            else
            {
                klr = Topan.Network.GetPlayerByID(inflictors[0]);
            }
        }

        if (victimIsBot)
        {
            vctmBot = BotManager.allBotPlayers[victim - 64];
        }
        else
        {
            vctm = Topan.Network.GetPlayerByID(victim);
        }

        byte vctmTeam = ((victimIsBot) ? vctmBot.team : (byte)vctm.GetPlayerData("team"));

        if (!isSuicide)
        {
            byte klrTeam    = ((killerIsBot) ? klrBot.team : (byte)klr.GetPlayerData("team"));
            bool isTeamKill = (klrTeam == vctmTeam);

            if (!(isTeamKill && GeneralVariables.gameModeHasTeams))
            {
                if (!killerIsBot)
                {
                    UInt16 pastKills = (UInt16)klr.GetPlayerData("k");
                    klr.SetPlayerData("k", (UInt16)(pastKills + 1));

                    int pastScore = (int)klr.GetPlayerData("sc");
                    klr.SetPlayerData("sc", pastScore + ((victimIsBot) ? 50 : 100) + ((didHeadshot) ? ((victimIsBot) ? 13 : 25) : 0));

                    if (klr == Topan.Network.server)
                    {
                        nGeneral.AddToActionFeed(didHeadshot, victimIsBot, 0f);
                    }
                    else
                    {
                        topanNetworkView.RPC(new Topan.NetworkPlayer[] { klr }, "AddToActionFeed", didHeadshot, victimIsBot, (TopanFloat)0f);
                    }
                }
                else
                {
                    klrBot.botStats.kills++;
                    klrBot.botStats.score += (victimIsBot) ? 50 : 100;

                    if (!toUpdateBots.Contains(klrBot.index))
                    {
                        toUpdateBots.Add(klrBot.index);
                    }
                }

                if (klrTeam == 0)
                {
                    UInt16 prevRedTotal = (UInt16)Topan.Network.GetServerInfo("rTK");
                    Topan.Network.SetServerInfo("rTK", (UInt16)(prevRedTotal + 1));
                }
                else if (klrTeam == 1)
                {
                    UInt16 prevBlueTotal = (UInt16)Topan.Network.GetServerInfo("bTK");
                    Topan.Network.SetServerInfo("bTK", (UInt16)(prevBlueTotal + 1));
                }

                if (didHeadshot)
                {
                    if (!killerIsBot)
                    {
                        UInt16 pastHS = (UInt16)klr.GetPlayerData("h");
                        klr.SetPlayerData("h", (UInt16)(pastHS + 1));
                    }
                    else
                    {
                        klrBot.botStats.headshots++;
                        klrBot.botStats.score += (victimIsBot) ? 13 : 25;
                    }
                }
            }
        }

        for (int i = 1; i < inflictors.Count; i++)
        {
            bool assistorIsBot        = (inflictors[i] >= 64);
            Topan.NetworkPlayer asstr = null;

            if (!assistorIsBot)
            {
                asstr = Topan.Network.GetPlayerByID(inflictors[i]);

                UInt16 pastAssists = (UInt16)asstr.GetPlayerData("a", (UInt16)0);
                asstr.SetPlayerData("a", (UInt16)(pastAssists + 1));

                if (asstr == Topan.Network.server)
                {
                    nGeneral.AddToActionFeed(false, victimIsBot, dmgValues[i - 1] / totalDamage);
                }
                else
                {
                    topanNetworkView.RPC(new Topan.NetworkPlayer[] { asstr }, "AddToActionFeed", false, victimIsBot, (TopanFloat)(dmgValues[i - 1] / totalDamage));
                }
            }
            else
            {
                BotPlayer iBot = BotManager.allBotPlayers[inflictors[i] - 64];
                iBot.botStats.score += Mathf.RoundToInt((dmgValues[i - 1] / totalDamage) * 100 * ((victimIsBot) ? 0.5f : 1f));

                if (!toUpdateBots.Contains(iBot.index))
                {
                    toUpdateBots.Add(iBot.index);
                }
            }
        }

        if (!victimIsBot)
        {
            UInt16 pastDeaths = (UInt16)vctm.GetPlayerData("d");
            vctm.SetPlayerData("d", (UInt16)(pastDeaths + 1));
        }
        else
        {
            vctmBot.botStats.deaths++;

            if (!toUpdateBots.Contains(vctmBot.index))
            {
                toUpdateBots.Add(vctmBot.index);
            }
        }

        if (vctmTeam == 0)
        {
            UInt16 prevRedTotal = (UInt16)Topan.Network.GetServerInfo("rTD");
            Topan.Network.SetServerInfo("rTD", (UInt16)(prevRedTotal + 1));
        }
        else if (vctmTeam == 1)
        {
            UInt16 prevBlueTotal = (UInt16)Topan.Network.GetServerInfo("bTD");
            Topan.Network.SetServerInfo("bTD", (UInt16)(prevBlueTotal + 1));
        }

        for (int i = 0; i < toUpdateBots.Count; i++)
        {
            BotPlayer upd = BotManager.allBotPlayers[toUpdateBots[i]];
            Topan.Network.SetServerInfo("bS" + upd.index.ToString(), BotManager.ParseToBotFormat(upd.botStats));
        }

        if (GeneralVariables.multiplayerGUI != null)
        {
            GeneralVariables.multiplayerGUI.AddToKillFeed((isSuicide) ? (byte)victim : (byte)inflictors[0], (byte)victim, (byte)Mathf.Clamp(weaponID + ((isGrenade) ? 200 : 0), 0, 255));
            GeneralVariables.multiplayerGUI.topanNetworkView.RPC(Topan.RPCMode.Others, "AddToKillFeed", (isSuicide) ? (byte)victim : (byte)inflictors[0], (byte)victim, (byte)Mathf.Clamp(weaponID + ((isGrenade) ? 200 : 0), 0, 255));
        }

        int winner = NetworkingGeneral.currentGameType.GetWinner();

        if (winner != -1)
        {
            FinishGame(winner);
            return;
        }
    }
Example #14
0
    public void AddToKillFeed(byte kID, byte vID, byte wepIndex)
    {
        Topan.NetworkPlayer killer    = null;
        Topan.NetworkPlayer victim    = null;
        BotPlayer           killerBot = null;
        BotPlayer           victimBot = null;

        bool killerIsBot = (kID >= 64);
        bool victimIsBot = (vID >= 64);

        if (killerIsBot)
        {
            killerBot = BotManager.allBotPlayers[kID - 64];
        }
        else
        {
            killer = Topan.Network.GetPlayerByID(kID);
        }

        if (victimIsBot)
        {
            victimBot = BotManager.allBotPlayers[vID - 64];
        }
        else
        {
            victim = Topan.Network.GetPlayerByID(vID);
        }

        if ((killerIsBot) ? killerBot == null : killer == null || (victimIsBot) ? victimBot == null : victim == null)
        {
            return;
        }

        byte killerTeam = (killerIsBot) ? killerBot.team : (byte)killer.GetPlayerData("team");
        byte victimTeam = (victimIsBot) ? victimBot.team : (byte)victim.GetPlayerData("team");

        string klrColor  = (killerTeam == 0) ? "[D75216]" : "[407499]";
        string vctmColor = (victimTeam == 0) ? "[D75216]" : "[407499]";

        if (!GeneralVariables.gameModeHasTeams)
        {
            klrColor  = (kID == Topan.Network.player.id) ? "[B05C25]" : "[707070]";
            vctmColor = (vID == Topan.Network.player.id) ? "[B05C25]" : "[707070]";
        }

        CombatantInfo kInfo = (killerIsBot) ? killerBot.botInfo : (CombatantInfo)killer.GetInitialData("dat");
        CombatantInfo vInfo = (victimIsBot) ? victimBot.botInfo : (CombatantInfo)victim.GetInitialData("dat");

        bool suicide = (kID == vID);

        if (suicide)
        {
            kfManager.AddToFeed(vctmColor + vInfo.username + "[-]", "himself", -1);

            if (GeneralVariables.spawnController != null && inSpawnScreen)
            {
                GeneralVariables.spawnController.AddToFeed(vctmColor + vInfo.username + "[-]", "himself", -1);
            }
        }
        else
        {
            kfManager.AddToFeed(klrColor + kInfo.username + "[-]", vctmColor + vInfo.username + "[-]", wepIndex);

            if (GeneralVariables.spawnController != null && inSpawnScreen)
            {
                GeneralVariables.spawnController.AddToFeed(klrColor + kInfo.username + "[-]", vctmColor + vInfo.username + "[-]", wepIndex);
            }
        }
    }