361 lines
13 KiB
C#
361 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Steamworks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class TournamentPlay : MonoBehaviour
|
|
{
|
|
private Animator animator;
|
|
|
|
[SerializeField]
|
|
private Text TournamentNameStartPanelText;
|
|
|
|
[SerializeField]
|
|
private Text TournamentTaskStartPanelText;
|
|
|
|
[SerializeField]
|
|
private Text TournamentPrizepoolStartPanelText;
|
|
|
|
[SerializeField]
|
|
private AudioSource StartPanelAudioSource;
|
|
|
|
[SerializeField]
|
|
private GameObject GamePanel;
|
|
|
|
[SerializeField]
|
|
private Image TournamentTimerFillImage;
|
|
|
|
[SerializeField]
|
|
private Text TournamentTimerDigitalText;
|
|
|
|
[SerializeField]
|
|
private Text TournamentNameGamePanelText;
|
|
|
|
[SerializeField]
|
|
private Text TournamentTaskGamePanelText;
|
|
|
|
[SerializeField]
|
|
private Text TournamentMethodGamePanelText;
|
|
|
|
[SerializeField]
|
|
private Text TournamentPrizepoolGamePanelText;
|
|
|
|
[SerializeField]
|
|
private Text TournamentNameDonePanelText;
|
|
|
|
[SerializeField]
|
|
private Text TournamentResultDonePanelText;
|
|
|
|
[SerializeField]
|
|
private Text TournamentPrizeCashDonePanelText;
|
|
|
|
[SerializeField]
|
|
private Text TournamentPrizeRankingPointsDonePanelText;
|
|
|
|
[SerializeField]
|
|
private Transform WinnerListContent;
|
|
|
|
[SerializeField]
|
|
private Transform ParticipantsListContent;
|
|
|
|
[SerializeField]
|
|
private GameObject ParticipantsGameItemPrefab;
|
|
|
|
[SerializeField]
|
|
private GameObject ShowMorePanel;
|
|
|
|
[SerializeField]
|
|
private bool showMoreParticipants;
|
|
|
|
private List<TournamentPlayParticipantItem> participantsList = new List<TournamentPlayParticipantItem>();
|
|
|
|
private ulong playerId;
|
|
|
|
private int lastParticipantsNum;
|
|
|
|
private bool isTournamentDone;
|
|
|
|
private bool isAnimationStartDone;
|
|
|
|
[SerializeField]
|
|
private AudioSource audioSourceDone;
|
|
|
|
[SerializeField]
|
|
private AudioClip[] audioClipDone;
|
|
|
|
private bool isDonePanelSets;
|
|
|
|
private void Start()
|
|
{
|
|
playerId = SteamUser.GetSteamID().m_SteamID;
|
|
GameManager.TruncateContainer(ParticipantsListContent);
|
|
animator = GetComponent<Animator>();
|
|
StartPanelSetup();
|
|
StartGamePanel();
|
|
InvokeRepeating("GetTournament", 1f, 1f);
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (!isTournamentDone)
|
|
{
|
|
TournamentTimer();
|
|
UpdateTextsGamePanel();
|
|
UpdateParticipantsList();
|
|
if (lastParticipantsNum == 0)
|
|
{
|
|
lastParticipantsNum = TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count;
|
|
}
|
|
else if (lastParticipantsNum < TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count)
|
|
{
|
|
GetComponent<AudioSource>().clip = audioClipDone[4];
|
|
GetComponent<AudioSource>().Play();
|
|
lastParticipantsNum = TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (GameManager.Instance.player.GetButtonDown("F6"))
|
|
{
|
|
ShowMoreLessParticipantsList();
|
|
}
|
|
if (isTournamentDone && GameManager.Instance.player.GetAnyButtonDown())
|
|
{
|
|
GameManager.Instance.PlayOnClickSound();
|
|
GameManager.Instance.UnloadAddectiveScene();
|
|
GameManager.Instance.LoadScene("Startowa");
|
|
}
|
|
}
|
|
|
|
private void StartPanelSetup()
|
|
{
|
|
TournamentNameStartPanelText.text = TournamentManager.Instance.GetTournamentNameText(TournamentManager.Instance.currentPlayTournament);
|
|
TournamentTaskStartPanelText.text = TournamentManager.Instance.GetTournamentTaskText(TournamentManager.Instance.currentPlayTournament);
|
|
TournamentPrizepoolStartPanelText.text = LanguageManager.Instance.GetText("PRIZEPOOL") + " $" + TournamentManager.Instance.currentPlayTournament.entryFee * TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count;
|
|
}
|
|
|
|
private void DonePanelSetup()
|
|
{
|
|
TournamentNameDonePanelText.text = TournamentManager.Instance.GetTournamentNameText(TournamentManager.Instance.currentPlayTournament);
|
|
TournamentResultDonePanelText.text = LanguageManager.Instance.GetText("FIRST_PLACE_RESULT");
|
|
GameManager.TruncateContainer(WinnerListContent);
|
|
TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Sort(TournamentManager.SortParticipantsList);
|
|
int num = 0;
|
|
for (int i = 0; i < TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count; i++)
|
|
{
|
|
if (i < 3 || TournamentManager.Instance.currentPlayTournament.tournamentParticipants[i].playerId == playerId.ToString())
|
|
{
|
|
TournamentPlayParticipantItem component = UnityEngine.Object.Instantiate(ParticipantsGameItemPrefab, WinnerListContent).GetComponent<TournamentPlayParticipantItem>();
|
|
component.participant = TournamentManager.Instance.currentPlayTournament.tournamentParticipants[i];
|
|
if (TournamentManager.Instance.currentPlayTournament.tournamentParticipants[i].playerId == playerId.ToString())
|
|
{
|
|
component.isOwnerPlayer = true;
|
|
num = TournamentManager.Instance.currentPlayTournament.tournamentParticipants[i].position;
|
|
}
|
|
}
|
|
}
|
|
TournamentManager.TournamentPrizes playerPrizes = TournamentManager.Instance.GetPlayerPrizes(num);
|
|
int num2 = 0;
|
|
int num3 = 0;
|
|
int num4 = 0;
|
|
int count = TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count;
|
|
if (playerPrizes != null)
|
|
{
|
|
num2 = playerPrizes.PrizepoolPercent;
|
|
num3 = Mathf.RoundToInt((float)(TournamentManager.Instance.currentPlayTournament.entryFee * TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count) * ((float)num2 * 0.01f));
|
|
num4 = playerPrizes.RankingPoints;
|
|
}
|
|
switch (num)
|
|
{
|
|
case 0:
|
|
TournamentResultDonePanelText.text = LanguageManager.Instance.GetText("FIRST_PLACE_RESULT").Replace("{PRIZEPOOL_PERCENT}", num2.ToString());
|
|
GetComponent<AudioSource>().clip = audioClipDone[0];
|
|
GetComponent<AudioSource>().PlayDelayed(2f);
|
|
break;
|
|
case 1:
|
|
TournamentResultDonePanelText.text = LanguageManager.Instance.GetText("SECOND_PLACE_RESULT").Replace("{PRIZEPOOL_PERCENT}", num2.ToString());
|
|
GetComponent<AudioSource>().clip = audioClipDone[1];
|
|
GetComponent<AudioSource>().PlayDelayed(2f);
|
|
break;
|
|
case 2:
|
|
TournamentResultDonePanelText.text = LanguageManager.Instance.GetText("THIRD_PLACE_RESULT").Replace("{PRIZEPOOL_PERCENT}", num2.ToString());
|
|
GetComponent<AudioSource>().clip = audioClipDone[2];
|
|
GetComponent<AudioSource>().PlayDelayed(2f);
|
|
break;
|
|
default:
|
|
if (num + 1 < count)
|
|
{
|
|
TournamentResultDonePanelText.text = LanguageManager.Instance.GetText("OTHER_PLACE_RESULT").Replace("{POSITION}", (num + 1).ToString()).Replace("{PARTICIPANTS_NUM}", count.ToString());
|
|
}
|
|
else
|
|
{
|
|
TournamentResultDonePanelText.text = LanguageManager.Instance.GetText("LAST_PLACE_RESULT");
|
|
}
|
|
GetComponent<AudioSource>().clip = audioClipDone[3];
|
|
GetComponent<AudioSource>().PlayDelayed(2f);
|
|
break;
|
|
}
|
|
TournamentPrizeCashDonePanelText.text = "$ " + num3;
|
|
TournamentPrizeRankingPointsDonePanelText.text = LanguageManager.Instance.GetText("RANKING_POINTS") + ": " + num4;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if ((bool)animator)
|
|
{
|
|
animator.SetBool("IsStarted", isAnimationStartDone);
|
|
}
|
|
}
|
|
|
|
private void TournamentTimer()
|
|
{
|
|
float num = TournamentManager.Instance.currentPlayTournament.duration * 60;
|
|
float num2 = Mathf.Clamp(TournamentManager.Instance.currentPlayTournament.timeToEnd, 0f, num);
|
|
float value = 1f - (float)TournamentManager.Instance.currentPlayTournament.timeToEnd / num;
|
|
value = Mathf.Clamp01(value);
|
|
TournamentTimerFillImage.fillAmount = value;
|
|
bool num3 = TournamentManager.Instance.tournaments.Contains(TournamentManager.Instance.currentPlayTournament);
|
|
TimeSpan timeSpan = TimeSpan.FromSeconds(num2);
|
|
TournamentTimerDigitalText.text = $"{timeSpan.Hours:D1}:{timeSpan.Minutes:D2}:{timeSpan.Seconds:D2}";
|
|
if (num2 <= 60f)
|
|
{
|
|
if (num2 < 11f && !TournamentTimerFillImage.GetComponentInParent<AudioSource>().isPlaying)
|
|
{
|
|
TournamentTimerFillImage.GetComponentInParent<AudioSource>().Play();
|
|
}
|
|
TournamentTimerDigitalText.color = Color.red;
|
|
}
|
|
if (!num3 && !isDonePanelSets)
|
|
{
|
|
DonePanelSetup();
|
|
animator.SetBool("isDone", value: true);
|
|
isDonePanelSets = true;
|
|
}
|
|
}
|
|
|
|
private void StartGamePanel()
|
|
{
|
|
ShowMorePanel.GetComponentInChildren<Text>().text = "F6 " + LanguageManager.Instance.GetText("SHOW_MORE");
|
|
TournamentNameGamePanelText.text = TournamentManager.Instance.GetTournamentNameText(TournamentManager.Instance.currentPlayTournament);
|
|
TournamentTaskGamePanelText.text = TournamentManager.Instance.GetTournamentTaskText(TournamentManager.Instance.currentPlayTournament);
|
|
TournamentMethodGamePanelText.text = TournamentManager.Instance.GetTournamentMethodText(TournamentManager.Instance.currentPlayTournament);
|
|
TournamentPrizepoolGamePanelText.text = LanguageManager.Instance.GetText("PRIZEPOOL") + " $" + TournamentManager.Instance.currentPlayTournament.entryFee * TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count;
|
|
}
|
|
|
|
private void UpdateTextsGamePanel()
|
|
{
|
|
if (GamePanel.activeSelf)
|
|
{
|
|
TournamentPrizepoolGamePanelText.text = LanguageManager.Instance.GetText("PRIZEPOOL") + " $" + TournamentManager.Instance.currentPlayTournament.entryFee * TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count;
|
|
}
|
|
}
|
|
|
|
private void UpdateParticipantsList()
|
|
{
|
|
TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Sort(TournamentManager.SortParticipantsList);
|
|
for (int i = 0; i < TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count; i++)
|
|
{
|
|
TournamentManager.Instance.currentPlayTournament.tournamentParticipants[i].position = i;
|
|
}
|
|
for (int j = 0; j < TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count; j++)
|
|
{
|
|
bool flag = false;
|
|
for (int k = 0; k < participantsList.Count; k++)
|
|
{
|
|
if (participantsList[k].participant == TournamentManager.Instance.currentPlayTournament.tournamentParticipants[j])
|
|
{
|
|
flag = true;
|
|
if (!showMoreParticipants && participantsList[k].participant.position > 2 && TournamentManager.Instance.currentPlayTournament.tournamentParticipants[j].playerId != playerId.ToString())
|
|
{
|
|
UnityEngine.Object.Destroy(participantsList[k].gameObject);
|
|
participantsList.RemoveAt(k);
|
|
}
|
|
}
|
|
}
|
|
if (flag)
|
|
{
|
|
continue;
|
|
}
|
|
if (showMoreParticipants)
|
|
{
|
|
TournamentPlayParticipantItem component = UnityEngine.Object.Instantiate(ParticipantsGameItemPrefab, ParticipantsListContent).GetComponent<TournamentPlayParticipantItem>();
|
|
component.participant = TournamentManager.Instance.currentPlayTournament.tournamentParticipants[j];
|
|
if (TournamentManager.Instance.currentPlayTournament.tournamentParticipants[j].playerId == playerId.ToString() && TournamentManager.Instance.currentPlayTournament.tournamentParticipants[j].profile_index == GameManager.Instance._playerData.currentPlayerProfileIndex)
|
|
{
|
|
component.isOwnerPlayer = true;
|
|
}
|
|
participantsList.Add(component);
|
|
}
|
|
else if (j < 3 || TournamentManager.Instance.currentPlayTournament.tournamentParticipants[j].playerId == playerId.ToString())
|
|
{
|
|
TournamentPlayParticipantItem component2 = UnityEngine.Object.Instantiate(ParticipantsGameItemPrefab, ParticipantsListContent).GetComponent<TournamentPlayParticipantItem>();
|
|
component2.participant = TournamentManager.Instance.currentPlayTournament.tournamentParticipants[j];
|
|
if (TournamentManager.Instance.currentPlayTournament.tournamentParticipants[j].playerId == playerId.ToString() && TournamentManager.Instance.currentPlayTournament.tournamentParticipants[j].profile_index == GameManager.Instance._playerData.currentPlayerProfileIndex)
|
|
{
|
|
component2.isOwnerPlayer = true;
|
|
}
|
|
participantsList.Add(component2);
|
|
}
|
|
}
|
|
if (TournamentManager.Instance.currentPlayTournament.tournamentParticipants.Count > 3)
|
|
{
|
|
ShowMorePanel.SetActive(value: true);
|
|
}
|
|
else
|
|
{
|
|
ShowMorePanel.SetActive(value: false);
|
|
}
|
|
}
|
|
|
|
private void GetTournament()
|
|
{
|
|
Debug.Log("Getting tournament data");
|
|
ServerManager.Instance.GetTournament(TournamentManager.Instance.currentPlayTournament.id);
|
|
ServerManager.Instance.GetTournamentParticipants(TournamentManager.Instance.currentPlayTournament.id);
|
|
}
|
|
|
|
private void ShowMoreLessParticipantsList()
|
|
{
|
|
if (ShowMorePanel.activeSelf)
|
|
{
|
|
showMoreParticipants = !showMoreParticipants;
|
|
participantsList.Clear();
|
|
GameManager.TruncateContainer(ParticipantsListContent);
|
|
if (showMoreParticipants)
|
|
{
|
|
ShowMorePanel.GetComponentInChildren<Text>().text = "F6 " + LanguageManager.Instance.GetText("SHOW_LESS");
|
|
}
|
|
else
|
|
{
|
|
ShowMorePanel.GetComponentInChildren<Text>().text = "F6 " + LanguageManager.Instance.GetText("SHOW_MORE");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DonePanelReady()
|
|
{
|
|
isTournamentDone = true;
|
|
}
|
|
|
|
public void TournamentReady()
|
|
{
|
|
isAnimationStartDone = true;
|
|
animator.SetBool("IsStarted", value: true);
|
|
}
|
|
|
|
public void PlayGongSound()
|
|
{
|
|
if (!Singleton<SaveDataManager>.Instance.IsCurrentlySandbox())
|
|
{
|
|
StartPanelAudioSource.Play();
|
|
if (SteamUserStats.GetAchievement("PLAY_TOURNAMENT_ACHIEVEMENT", out var pbAchieved) && !pbAchieved && SteamUserStats.SetAchievement("PLAY_TOURNAMENT_ACHIEVEMENT"))
|
|
{
|
|
SteamUserStats.StoreStats();
|
|
}
|
|
}
|
|
}
|
|
}
|