Files
UltimateFishing2020/Assets/Scripts/Assembly-CSharp/PlayerTournamentItem.cs
2026-03-04 10:03:45 +08:00

247 lines
7.9 KiB
C#

using System.Collections.Generic;
using Steamworks;
using UnityEngine;
using UnityEngine.UI;
public class PlayerTournamentItem : MonoBehaviour
{
public TournamentManager.CTournament tournament;
[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;
[SerializeField]
private Dropdown tournamentNumParticipantsDropdown;
[SerializeField]
private Transform tournamentParticipantsContent;
[SerializeField]
private GameObject creatorParticipantsItemPrefab;
[SerializeField]
private GameObject tournamentCounterPrefab;
[SerializeField]
private GameObject tournamentDeleteButton;
private TournamentCounter tournamentCounter;
public List<CreatorParticipantItem> creatorParticipantItems = new List<CreatorParticipantItem>();
public Animator animator;
private bool isTournamentStarting;
private void Start()
{
Setup();
}
private void OnDestroy()
{
MultiplayerManager.Instance.LeaveRoom();
}
private void FixedUpdate()
{
CheckIsAllReady();
ConnectToPUNRoom();
}
private void Setup()
{
tournamentNameInputField.text = tournament.tournamentName;
tournamentTaskDropdown.ClearOptions();
switch (tournament.tournamentTask)
{
case TournamentManager.CTournament.TournamentTask.Amount_fish:
tournamentTaskDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("TOURNAMENT_TASK_AMOUNT_FISH")));
break;
case TournamentManager.CTournament.TournamentTask.Amount_fish_weight:
tournamentTaskDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("TOURNAMENT_TASK_AMOUNT_FISH_WEIGHT")));
break;
case TournamentManager.CTournament.TournamentTask.Best_fish_weight:
tournamentTaskDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("TOURNAMENT_TASK_BEST_FISH_WEIGHT")));
break;
}
tournamentTaskDropdown.RefreshShownValue();
tournamentTypeDropdown.ClearOptions();
switch (tournament.type)
{
case TournamentManager.TournamentType.Public:
tournamentTypeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("PUBLIC")));
break;
case TournamentManager.TournamentType.Private:
tournamentTypeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("PRIVATE")));
break;
}
tournamentTypeDropdown.RefreshShownValue();
tournamentLocationDropdown.ClearOptions();
tournamentLocationDropdown.options.Add(new Dropdown.OptionData(GameManager.Instance.gameLocations[tournament.mapId].name));
tournamentLocationDropdown.RefreshShownValue();
tournamentDurationDropdown.ClearOptions();
tournamentDurationDropdown.options.Add(new Dropdown.OptionData(tournament.duration + " " + LanguageManager.Instance.GetText("MINUTES_SHORT")));
tournamentDurationDropdown.RefreshShownValue();
tournamentEntryfeeDropdown.ClearOptions();
tournamentEntryfeeDropdown.options.Add(new Dropdown.OptionData("$ " + tournament.entryFee));
tournamentEntryfeeDropdown.RefreshShownValue();
tournamentMinLevelDropdown.ClearOptions();
tournamentMinLevelDropdown.options.Add(new Dropdown.OptionData(tournament.levelRange.x.ToString()));
tournamentMinLevelDropdown.RefreshShownValue();
tournamentMaxLevelDropdown.ClearOptions();
tournamentMaxLevelDropdown.options.Add(new Dropdown.OptionData(tournament.levelRange.y.ToString()));
tournamentMaxLevelDropdown.RefreshShownValue();
tournamentMethodDropdown.ClearOptions();
switch (tournament.tournamentMethod)
{
case TournamentManager.CTournament.TournamentMethod.All:
tournamentMethodDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("ANY")));
break;
case TournamentManager.CTournament.TournamentMethod.Spinning:
tournamentMethodDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("SPINNING")));
break;
case TournamentManager.CTournament.TournamentMethod.Float:
tournamentMethodDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("FLOAT")));
break;
case TournamentManager.CTournament.TournamentMethod.Feeder:
tournamentMethodDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetText("FEEDER")));
break;
}
tournamentMethodDropdown.RefreshShownValue();
tournamentNumParticipantsDropdown.ClearOptions();
tournamentNumParticipantsDropdown.options.Add(new Dropdown.OptionData(tournament.participantMaximum.ToString()));
tournamentNumParticipantsDropdown.RefreshShownValue();
GameManager.TruncateContainer(tournamentParticipantsContent);
for (int i = 0; i < tournament.participantMaximum; i++)
{
CreatorParticipantItem component = Object.Instantiate(creatorParticipantsItemPrefab, tournamentParticipantsContent).GetComponent<CreatorParticipantItem>();
component.tournament = tournament;
component.index = i;
component.playerTournamentItem = this;
creatorParticipantItems.Add(component);
}
GetRefreshParticipants();
InvokeRepeating("GetRefreshParticipants", 1f, 1f);
if (tournament.creatorPlayerId != SteamUser.GetSteamID().m_SteamID.ToString() || tournament.timeStart > 0)
{
tournamentDeleteButton.SetActive(value: false);
}
}
private void GetRefreshParticipants()
{
if (tournament != null)
{
ServerManager.Instance.GetTournamentParticipants(tournament.id);
}
}
private void CheckIsAllReady()
{
if (!TournamentManager.Instance.CheckIsTournamentJoined(tournament))
{
return;
}
if (isTournamentStarting)
{
if (tournament.timeStart > 0)
{
StartCounter();
}
return;
}
bool flag = true;
for (int i = 0; i < creatorParticipantItems.Count; i++)
{
if (creatorParticipantItems[i].status != CreatorParticipantItem.Status.READY)
{
flag = false;
}
}
bool flag2 = false;
MultiplayerManager.RoomInfoData? currentRoom = MultiplayerManager.Instance.CurrentRoom;
if (currentRoom.HasValue)
{
flag2 = currentRoom.Value.name == $"0_t_{tournament.id}";
}
if (flag && flag2)
{
ServerManager.Instance.StartPlayerTournament(tournament.id);
isTournamentStarting = true;
}
}
private void ConnectToPUNRoom()
{
MultiplayerManager.RoomInfoData? currentRoom = MultiplayerManager.Instance.CurrentRoom;
if (currentRoom.HasValue && currentRoom.Value.name != $"0_t_{tournament.id}")
{
MultiplayerManager.Instance.LeaveRoom();
}
else if (MultiplayerManager.Instance.CurrentState == MultiplayerManager.State.Disconnected)
{
MultiplayerManager.Instance.Connect();
}
else if (MultiplayerManager.Instance.CurrentState == MultiplayerManager.State.InLobby)
{
MultiplayerManager.Instance.JoinOrCreateRoomTournament(tournament);
}
}
private void StartCounter()
{
if (!tournamentCounter)
{
tournamentCounter = Object.Instantiate(tournamentCounterPrefab, Object.FindObjectOfType<TournamentScene>().transform).GetComponent<TournamentCounter>();
tournamentCounter.playerTournament = this;
}
}
public void StartTournament()
{
Debug.Log("Uruchamianie turnieju...");
MultiplayerManager.Instance.EnterRoomLocation(isTournament: true);
TournamentManager.Instance.LoadTournamentMap(tournament);
}
public void DeleteTournament()
{
if (tournament.timeStart == 0L)
{
GameManager.Instance.CreateMessageBox("DELETE_MY_TOURNAMENT", Object.FindObjectOfType<MainGameScene>().transform, 10);
}
}
public void DeleteConfirmYes()
{
ServerManager.Instance.DeletePlayerTournament(tournament.id);
GameManager.Instance._playerData.AddSubPlayerCashValue(tournament.entryFee);
Object.Destroy(base.gameObject);
}
}