using System; using System.Collections.Generic; using Steamworks; using UnityEngine; using UnityEngine.UI; public class RankingManager : MonoBehaviour { private class PlayerInLeaderboard { public int pos; public string uuid; public string name; public string profilemode; } [Serializable] public class Ranking { public string name; public float totalWeight; public int biggestFishName; public float biggestFishWeight; public int amountOfFish; public int rankingPoints; } [SerializeField] private Image mainContentMaskImage; [SerializeField] private Camera mCamera; [SerializeField] private PlayerHeader playerHeader; public Transform rankingContainer; public Transform rewardrankingContainer; public GameObject rankingPrefab; public GameObject rewardRanking; public Text cantLoadRankingText; public ScrollRect scrollBar; public Text locationName; public int loadedRankings; public int maxplayersIndex; private bool checkloadrank; private int currentLocationID; public void CheckValue() { if (scrollBar.verticalNormalizedPosition <= 0.02f && !checkloadrank) { checkloadrank = true; ServerManager.Instance.GetRankingPlayersLocation(loadedRankings + 15, loadedRankings, currentLocationID); } } public void ShowPlayerLead(ServerManager.GetRankingOwnData data) { int num = data.POSITION - 1; if (num <= GameManager.Instance.rankingReward.Length) { GameManager.TruncateContainer(rewardrankingContainer); RewardRankItem component = UnityEngine.Object.Instantiate(rewardRanking, rewardrankingContainer).GetComponent(); component.cash.text = GameManager.Instance.rankingReward[num].cash.ToString(); component.exp.text = GameManager.Instance.rankingReward[num].exp.ToString("F0"); component.questPoints.text = GameManager.Instance.rankingReward[num].questPoints.ToString(); component.points.text = data.POINTS.ToString(); } } public void ShowPlayerLead(ServerManager.GetRankingOwnLocationData data) { int num = data.POSITION - 1; if (num <= GameManager.Instance.rankingReward.Length) { GameManager.TruncateContainer(rewardrankingContainer); RewardRankItem component = UnityEngine.Object.Instantiate(rewardRanking, rewardrankingContainer).GetComponent(); component.cash.text = GameManager.Instance.rankingReward[num].cash.ToString(); component.exp.text = GameManager.Instance.rankingReward[num].exp.ToString("F0"); component.questPoints.text = GameManager.Instance.rankingReward[num].questPoints.ToString(); component.points.text = data.POINTS.ToString(); } } public void ShowRankingData(List table) { cantLoadRankingText.gameObject.SetActive(value: false); for (int i = 0; i < table.Count; i++) { RankingItem component = UnityEngine.Object.Instantiate(rankingPrefab, rankingContainer).GetComponent(); component.position = loadedRankings + (i + 1); component.posText.text = (loadedRankings + (i + 1)).ToString(); component.nameText.text = table[i].PLAYER_NAME; component.totalWeightText.text = GameManager.Instance.ConvertWeight(table[i].TOTAL_FISH_WEIGHT); if (table[i].BEST_FISH_ID == -1) { component.biggestfishText.text = "-"; } else { component.biggestfishText.text = GameManager.GetFishNameFromSpecies((GameManager.FishSpecies)table[i].BEST_FISH_ID) + " " + GameManager.Instance.ConvertWeight(table[i].BEST_FISH_WEIGHT); } component.amountOfFishText.text = table[i].TOTAL_FISH.ToString(); component.rankingPointsText.text = table[i].POINTS.ToString(); CheckOwnPosition(table[i], component); } loadedRankings += 15; checkloadrank = false; Debug.Log("Loaded players to ranking"); } public void ShowOwnRankingData(ServerManager.GetRankingOwnData data) { if (data.POSITION <= 10) { ShowPlayerLead(data); return; } RankingItem component = UnityEngine.Object.Instantiate(rankingPrefab, rankingContainer).GetComponent(); component.position = data.POSITION; component.posText.text = data.POSITION.ToString(); component.nameText.text = data.PLAYER_NAME; component.totalWeightText.text = GameManager.Instance.ConvertWeight(data.TOTAL_FISH_WEIGHT); if (data.BEST_FISH_ID == -1) { component.biggestfishText.text = "-"; } else { component.biggestfishText.text = GameManager.GetFishNameFromSpecies((GameManager.FishSpecies)data.BEST_FISH_ID) + " " + GameManager.Instance.ConvertWeight(data.BEST_FISH_WEIGHT); } component.amountOfFishText.text = data.TOTAL_FISH.ToString(); component.rankingPointsText.text = data.POINTS.ToString(); component.transform.SetAsFirstSibling(); component.gameObject.GetComponent().color = new Color32(103, 253, byte.MaxValue, byte.MaxValue); } public void ShowRankingLocationData(List table) { checkloadrank = false; if (table.Count == 0 || table[0].MAP_ID != currentLocationID) { return; } cantLoadRankingText.gameObject.SetActive(value: false); foreach (ServerManager.RankingPlayersLocationData item in table) { RankingItem component = UnityEngine.Object.Instantiate(rankingPrefab, rankingContainer).GetComponent(); component.position = loadedRankings + table.IndexOf(item) + 1; component.posText.text = component.position.ToString(); component.nameText.text = item.PLAYER_NAME; component.totalWeightText.text = GameManager.Instance.ConvertWeight(item.TOTAL_FISH_WEIGHT); component.biggestfishText.text = ((item.BEST_FISH_ID == -1) ? "-" : (GameManager.GetFishNameFromSpecies((GameManager.FishSpecies)item.BEST_FISH_ID) + " " + GameManager.Instance.ConvertWeight(item.BEST_FISH_WEIGHT))); component.amountOfFishText.text = item.TOTAL_FISH.ToString(); component.rankingPointsText.text = item.POINTS.ToString(); CheckOwnPosition(item, component); } loadedRankings += table.Count; } public void ShowOwnRankingLocationData(ServerManager.GetRankingOwnLocationData data) { if (data.MAP_ID == currentLocationID) { if (data.POSITION <= 10) { ShowPlayerLead(data); return; } RankingItem component = UnityEngine.Object.Instantiate(rankingPrefab, rankingContainer).GetComponent(); component.position = data.POSITION; component.posText.text = data.POSITION.ToString(); component.nameText.text = data.PLAYER_NAME; component.totalWeightText.text = GameManager.Instance.ConvertWeight(data.TOTAL_FISH_WEIGHT); component.biggestfishText.text = ((data.BEST_FISH_ID == -1) ? "-" : (GameManager.GetFishNameFromSpecies((GameManager.FishSpecies)data.BEST_FISH_ID) + " " + GameManager.Instance.ConvertWeight(data.BEST_FISH_WEIGHT))); component.amountOfFishText.text = data.TOTAL_FISH.ToString(); component.rankingPointsText.text = data.POINTS.ToString(); component.transform.SetAsFirstSibling(); component.gameObject.GetComponent().color = new Color32(103, 253, byte.MaxValue, byte.MaxValue); } } private void CheckOwnPosition(ServerManager.RankingPlayersData playerData, RankingItem item) { if (item.position <= 10 && playerData.PLAYER_ID == SteamUser.GetSteamID().m_SteamID.ToString() && playerData.PROFILE_INDEX == GameManager.Instance._playerData.currentPlayerProfileIndex) { item.gameObject.GetComponent().color = new Color32(103, 253, byte.MaxValue, byte.MaxValue); } } private void CheckOwnPosition(ServerManager.RankingPlayersLocationData playerData, RankingItem item) { if (item.position <= 10 && playerData.PLAYER_ID == SteamUser.GetSteamID().m_SteamID.ToString() && playerData.PROFILE_INDEX == GameManager.Instance._playerData.currentPlayerProfileIndex) { item.gameObject.GetComponent().color = new Color32(103, 253, byte.MaxValue, byte.MaxValue); } } public void OnLocationPreviousClick() { int num = currentLocationID; do { num = ((num > 0) ? (num - 1) : (GameManager.Instance.gameLocations.Length - 1)); if (num == currentLocationID) { return; } } while (!GameManager.Instance.gameLocations[num].isEnabled || GameManager.Instance.gameLocations[num].name == "Tutorial" || GameManager.Instance.gameLocations[num].name == "Residence"); currentLocationID = num; UpdateLocationRanking(); } public void OnLocationNextClick() { int num = currentLocationID; do { num = ((num < GameManager.Instance.gameLocations.Length - 1) ? (num + 1) : 0); if (num == currentLocationID) { return; } } while (!GameManager.Instance.gameLocations[num].isEnabled || GameManager.Instance.gameLocations[num].name == "Tutorial" || GameManager.Instance.gameLocations[num].name == "Residence"); currentLocationID = num; UpdateLocationRanking(); } private void UpdateLocationRanking() { locationName.text = GameManager.Instance.gameLocations[currentLocationID].name; GameManager.TruncateContainer(rankingContainer); loadedRankings = 0; checkloadrank = false; ServerManager.Instance.GetRankingPlayersLocation(15, loadedRankings, currentLocationID); ServerManager.Instance.GetOwnRankingPositionLocation(currentLocationID); } private void OnEnable() { if (ServerManager.Instance.socket.Instance.IsConnected()) { cantLoadRankingText.gameObject.SetActive(value: false); } UpdateLocationRanking(); } private void OnDisable() { GameManager.TruncateContainer(rankingContainer); GameManager.TruncateContainer(rewardrankingContainer); loadedRankings = 0; checkloadrank = false; } private void Start() { if ((bool)FScriptsHandler.Instance) { playerHeader.gameObject.SetActive(value: true); mainContentMaskImage.enabled = true; FScriptsHandler.Instance.m_Canvas.gameObject.SetActive(value: false); } else if (UnityEngine.Object.FindObjectOfType() != null) { playerHeader.gameObject.SetActive(value: true); mainContentMaskImage.enabled = true; } else { playerHeader.gameObject.SetActive(value: false); mainContentMaskImage.enabled = false; } } private void Update() { } private void OnDestroy() { if (FScriptsHandler.Instance != null) { FScriptsHandler.Instance.m_Canvas.gameObject.SetActive(value: true); } } }