using System.Collections.Generic; using Steamworks; using UnityEngine; using UnityEngine.UI; public class TournamentPlayerCreator : MonoBehaviour { [SerializeField] private InputField tournamentNameInputField; [SerializeField] private Dropdown tournamentTaskDropdown; [SerializeField] private Dropdown tournamentTypeDropdown; [SerializeField] private Dropdown tournamentLocationDropdown; [SerializeField] private Dropdown tournamentDurationDropdown; [SerializeField] private Dropdown tournamentEntryfeeDropdown; [SerializeField] private Dropdown tournamentMinLevelDropdown; [SerializeField] private Dropdown tournamentMaxLevelDropdown; [SerializeField] private Dropdown tournamentMethodDropdown; public Dropdown tournamentNumParticipantsDropdown; [SerializeField] private Image tournamentNumParticipantsDropdownArrow; [SerializeField] private Button createButon; [SerializeField] private GameObject InvitesPanel; public Transform InvitePlayerContent; public Transform FriendsContent; [SerializeField] private GameObject InviteFriendItemPrefab; private List mapsIDs = new List(); private List minLevelsD = new List(); private List maxLevelsD = new List(); [SerializeField] private int[] durationList; [SerializeField] private int[] entryFeeList; public int[] numOfParticipantsList; public int numOfParticipantsInvited; private int maximumEquipmentLevel = 50; private void Start() { Setup(); } private void Update() { if (!tournamentTypeDropdown.interactable) { return; } if (tournamentTypeDropdown.value == 1) { if (InvitePlayerContent.childCount < 1) { createButon.interactable = false; } else { createButon.interactable = true; } } else { createButon.interactable = true; } } private void Setup() { _ = GameManager.Instance._playerData.currentPlayerProfileIndex; tournamentNameInputField.text = Singleton.Instance.GetCurrentPlayerData().PlayerName + " " + LanguageManager.Instance.GetText("PLAYERS_TOURNAMENT"); tournamentTaskDropdown.ClearOptions(); tournamentTaskDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("TOURNAMENT_TASK_AMOUNT_FISH"))); tournamentTaskDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("TOURNAMENT_TASK_AMOUNT_FISH_WEIGHT"))); tournamentTaskDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("TOURNAMENT_TASK_BEST_FISH_WEIGHT"))); tournamentTaskDropdown.RefreshShownValue(); tournamentTypeDropdown.ClearOptions(); tournamentTypeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("PUBLIC"))); tournamentTypeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("PRIVATE"))); tournamentTypeDropdown.RefreshShownValue(); tournamentLocationDropdown.ClearOptions(); for (int i = 0; i < GameManager.Instance.gameLocations.Length; i++) { if (GameManager.Instance.gameLocations[i].isEnabled && GameManager.Instance.gameLocations[i].levelrequired > 0 && GameManager.Instance.gameLocations[i].levelrequired <= Singleton.Instance.GetCurrentPlayerData().PlayerLevel) { tournamentLocationDropdown.options.Add(new Dropdown.OptionData(GameManager.Instance.gameLocations[i].name)); mapsIDs.Add(i); } } tournamentLocationDropdown.RefreshShownValue(); SetMapLocationDropdown(); tournamentDurationDropdown.ClearOptions(); for (int j = 0; j < durationList.Length; j++) { tournamentDurationDropdown.options.Add(new Dropdown.OptionData(durationList[j] + " " + LanguageManager.Instance.GetText("MINUTES_SHORT"))); } tournamentDurationDropdown.RefreshShownValue(); tournamentEntryfeeDropdown.ClearOptions(); for (int k = 0; k < entryFeeList.Length; k++) { tournamentEntryfeeDropdown.options.Add(new Dropdown.OptionData("$ " + entryFeeList[k])); } tournamentEntryfeeDropdown.RefreshShownValue(); SetMinimumLevelDropdown(); SetMaximumLevelDropdown(); tournamentMethodDropdown.ClearOptions(); tournamentMethodDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("ANY"))); tournamentMethodDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("SPINNING"))); tournamentMethodDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("FLOAT"))); tournamentMethodDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("FEEDER"))); tournamentMethodDropdown.RefreshShownValue(); tournamentNumParticipantsDropdown.ClearOptions(); for (int l = 0; l < numOfParticipantsList.Length; l++) { tournamentNumParticipantsDropdown.options.Add(new Dropdown.OptionData(numOfParticipantsList[l].ToString())); } tournamentNumParticipantsDropdown.RefreshShownValue(); SetParticipantsNum(); } public void SetParticipantsNum() { if (tournamentTypeDropdown.value != 1) { numOfParticipantsInvited = numOfParticipantsList[tournamentNumParticipantsDropdown.value]; } } public void SetTypeDropdown() { switch (tournamentTypeDropdown.value) { case 0: InvitesPanel.SetActive(value: false); tournamentNumParticipantsDropdown.interactable = true; tournamentNumParticipantsDropdown.value = 0; tournamentNumParticipantsDropdown.RefreshShownValue(); numOfParticipantsInvited = numOfParticipantsList[tournamentNumParticipantsDropdown.value]; tournamentNumParticipantsDropdownArrow.enabled = true; GameManager.TruncateContainer(InvitePlayerContent); break; case 1: tournamentNumParticipantsDropdownArrow.enabled = false; InvitesPanel.SetActive(value: true); tournamentNumParticipantsDropdown.interactable = false; numOfParticipantsInvited = 1; GetSteamFriendsList(); break; } } public void SetMinimumLevelDropdown() { int num = maximumEquipmentLevel - 1; tournamentMinLevelDropdown.ClearOptions(); minLevelsD.Clear(); for (int i = 1; i < num + 1; i++) { tournamentMinLevelDropdown.options.Add(new Dropdown.OptionData(i.ToString())); minLevelsD.Add(i); } tournamentMinLevelDropdown.RefreshShownValue(); } public void SetMaximumLevelDropdown() { int num = maximumEquipmentLevel; tournamentMaxLevelDropdown.ClearOptions(); maxLevelsD.Clear(); for (int i = 2; i < num + 1; i++) { tournamentMaxLevelDropdown.options.Add(new Dropdown.OptionData(i.ToString())); maxLevelsD.Add(i); } tournamentMaxLevelDropdown.value = tournamentMaxLevelDropdown.options.Count - 1; tournamentMaxLevelDropdown.RefreshShownValue(); } public void TournamentLevelDropdown_OnChange() { int value = tournamentMinLevelDropdown.value; int value2 = tournamentMaxLevelDropdown.value; if (value > value2) { tournamentMinLevelDropdown.value = value2; tournamentMinLevelDropdown.RefreshShownValue(); } } public void SetMapLocationDropdown() { int num = mapsIDs[tournamentLocationDropdown.value]; GetComponent().sprite = GameManager.Instance.gameLocations[num].GetScreenMapImage(0); } private void UpdateCreatorTournament() { TournamentManager.Instance.currentCreatorTournament.id = -1; TournamentManager.Instance.currentCreatorTournament.tournamentName = tournamentNameInputField.text; TournamentManager.Instance.currentCreatorTournament.tournamentTask = (TournamentManager.CTournament.TournamentTask)tournamentTaskDropdown.value; TournamentManager.Instance.currentCreatorTournament.tournamentType = TournamentManager.TournamentContentType.Players; TournamentManager.Instance.currentCreatorTournament.type = (TournamentManager.TournamentType)tournamentTypeDropdown.value; TournamentManager.Instance.currentCreatorTournament.mapId = mapsIDs[tournamentLocationDropdown.value]; TournamentManager.Instance.currentCreatorTournament.duration = durationList[tournamentDurationDropdown.value]; TournamentManager.Instance.currentCreatorTournament.entryFee = entryFeeList[tournamentEntryfeeDropdown.value]; TournamentManager.Instance.currentCreatorTournament.levelRange = new Vector2(minLevelsD[tournamentMinLevelDropdown.value], maxLevelsD[tournamentMaxLevelDropdown.value]); TournamentManager.Instance.currentCreatorTournament.tournamentMethod = (TournamentManager.CTournament.TournamentMethod)tournamentMethodDropdown.value; TournamentManager.Instance.currentCreatorTournament.participantMaximum = numOfParticipantsInvited; } public void Create() { UpdateCreatorTournament(); if (!GameManager.Instance._playerData.AddSubPlayerCashValue(-TournamentManager.Instance.currentCreatorTournament.entryFee)) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("NOT_ENOUGH_MONEY_TO_CREATE"), Object.FindObjectOfType().transform, deleteLast: true); return; } List list = new List(); InviteFriendItem[] componentsInChildren = InvitePlayerContent.GetComponentsInChildren(); _ = GameManager.Instance._playerData.currentPlayerProfileIndex; for (int i = 0; i < componentsInChildren.Length; i++) { TournamentManager.CInviteSend cInviteSend = new TournamentManager.CInviteSend(); cInviteSend.PLAYER_ID = componentsInChildren[i].Player_id.m_SteamID.ToString(); cInviteSend.TOURNAMENT_NAME = tournamentNameInputField.text; cInviteSend.SEND_PLAYER_NAME = Singleton.Instance.GetCurrentPlayerData().PlayerName; list.Add(cInviteSend); } Debug.Log(JsonHelper.ToJson(list.ToArray())); ServerManager.Instance.CreateTournament(TournamentManager.Instance.currentCreatorTournament, list); createButon.interactable = false; tournamentTaskDropdown.interactable = false; tournamentTypeDropdown.interactable = false; tournamentLocationDropdown.interactable = false; tournamentDurationDropdown.interactable = false; tournamentEntryfeeDropdown.interactable = false; tournamentMinLevelDropdown.interactable = false; tournamentMaxLevelDropdown.interactable = false; tournamentMethodDropdown.interactable = false; tournamentNumParticipantsDropdown.interactable = false; } private void GetSteamFriendsList() { GameManager.TruncateContainer(FriendsContent); int num = SteamFriends.GetFriendCount(EFriendFlags.k_EFriendFlagImmediate); if (num == -1) { Debug.Log("GetFriendCount returned -1, the current user is not logged in.\n"); num = 0; } for (int i = 0; i < num; i++) { CSteamID friendByIndex = SteamFriends.GetFriendByIndex(i, EFriendFlags.k_EFriendFlagImmediate); string friendPersonaName = SteamFriends.GetFriendPersonaName(friendByIndex); CSteamID cSteamID = friendByIndex; Debug.Log("Friend " + cSteamID.ToString() + " name: " + friendPersonaName); InviteFriendItem component = Object.Instantiate(InviteFriendItemPrefab, FriendsContent).GetComponent(); component.tournamentPlayerCreator = this; component.Player_id = friendByIndex; component.PlayerNameText.text = friendPersonaName; } } public void CreateSuccess() { createButon.gameObject.SetActive(value: false); tournamentNameInputField.interactable = false; ServerManager.Instance.JoinToTournament(TournamentManager.Instance.currentCreatorTournament); InvokeRepeating("Refresh", 1f, 1f); } private void Refresh() { Debug.Log("Refresh creator"); Object.FindObjectOfType().ShowTournament(); } }