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

341 lines
7.8 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
public class TournamentManager : MonoBehaviour
{
[Serializable]
public class CTournament
{
[Serializable]
public class TournamentParticipant
{
public int position;
public string playerId;
public string playerName = "";
public int profile_index;
public int player_level;
public int tournaments_won;
public int rankings_points;
public int bestFishId;
public float value;
public int joined_timeleft;
public string status = "WAITING";
}
public enum TournamentMethod
{
All = 0,
Spinning = 1,
Float = 2,
Feeder = 3
}
public enum TournamentTask
{
Amount_fish = 0,
Amount_fish_weight = 1,
Best_fish_weight = 2
}
public TournamentContentType tournamentType;
public int id;
public int mapId;
public int duration = 30;
public int participantMaximum = 10;
public int entryFee = 50;
public TournamentTask tournamentTask;
public TournamentMethod tournamentMethod;
public long timeStart;
public int timeLeft;
public int timeToEnd;
public int timeCreate;
public string creatorPlayerId;
public string creatorPlayerName;
public int creatorProfileIndex;
public Vector2 levelRange = new Vector2(0f, 5f);
public List<TournamentParticipant> tournamentParticipants = new List<TournamentParticipant>();
public List<TournamentParticipant> tournamentInvitedParticipants = new List<TournamentParticipant>();
public string tournamentName = "Player tournament";
public TournamentType type;
}
[Serializable]
public class CInvite
{
public int tournamentId;
public string tournamentName = "";
public string playerSenderName = "";
public bool isMessaged;
}
[Serializable]
public class CInviteSend
{
public string TOURNAMENT_NAME = "";
public string PLAYER_ID = "";
public string SEND_PLAYER_NAME = "";
}
[Serializable]
public class TournamentPrizes
{
public TournamentContentType tournamentType;
public int Position;
public int PrizepoolPercent;
public int RankingPoints;
}
public enum TournamentContentType
{
Cyclic = 0,
Daily = 1,
Players = 2,
MyTournaments = 3,
CreatorTournament = 4
}
public enum TournamentType
{
Public = 0,
Private = 1
}
private static TournamentManager instance;
public CTournament currentPlayTournament = new CTournament();
public CTournament currentCreatorTournament = new CTournament();
public List<CTournament> tournaments = new List<CTournament>();
public List<int> myTournamentsIds = new List<int>();
public List<CInvite> myTournamentInvites = new List<CInvite>();
public TournamentPrizes[] tournamentPrizes;
public Sprite[] mapImagesBg;
public GameObject TournamentPlayPanelPrefab;
public static TournamentManager Instance => instance;
private void Awake()
{
UnityEngine.Object.DontDestroyOnLoad(this);
if (instance == null)
{
instance = this;
}
else if (instance != this)
{
UnityEngine.Object.Destroy(base.gameObject);
}
}
private void Start()
{
InvokeRepeating("CheckMyInvites", 2f, 2f);
}
private void Update()
{
}
public static int SortParticipantsList(CTournament.TournamentParticipant p1, CTournament.TournamentParticipant p2)
{
return p2.value.CompareTo(p1.value);
}
public bool CheckIsTournamentJoined(CTournament tournament)
{
for (int i = 0; i < myTournamentsIds.Count; i++)
{
if (myTournamentsIds[i] == tournament.id)
{
return true;
}
}
return false;
}
public bool CheckIsTournamentInvite(CTournament tournament)
{
for (int i = 0; i < myTournamentInvites.Count; i++)
{
if (myTournamentInvites[i].tournamentId == tournament.id)
{
return true;
}
}
return false;
}
private void CheckMyInvites()
{
if ((bool)ServerManager.Instance)
{
if (UnityEngine.Object.FindObjectOfType<SteamManager>() != null && SteamManager.Initialized)
{
ServerManager.Instance.GetTournamentInvites();
}
MessageForNewInvite();
}
}
private void MessageForNewInvite()
{
for (int i = 0; i < myTournamentInvites.Count; i++)
{
if (!myTournamentInvites[i].isMessaged)
{
Transform transform = null;
MainGameScene mainGameScene = UnityEngine.Object.FindObjectOfType<MainGameScene>();
if ((bool)mainGameScene)
{
transform = mainGameScene.transform;
}
else if ((bool)FScriptsHandler.Instance)
{
transform = FScriptsHandler.Instance.m_Canvas.transform;
}
if ((bool)transform)
{
string msgText = LanguageManager.Instance.GetText("TOURNAMENT_INVITE_MESSAGE").Replace("{TOURNAMENT_NAME}", "<b>" + myTournamentInvites[i].tournamentName + "</b>");
GameManager.Instance.ShowMessagePopup(msgText, transform);
myTournamentInvites[i].isMessaged = true;
}
break;
}
}
}
public void LoadTournamentMap(CTournament tournament)
{
currentPlayTournament = tournament;
GameManager.Instance.currentSceneLoadedType = GameManager.SceneLoadedType.Tournament;
GameManager.Instance.UnloadAddectiveScene();
GameManager.Instance.LoadScene(GameManager.Instance.gameLocations[currentPlayTournament.mapId].sceneName);
}
public string GetTournamentNameText(CTournament tournament)
{
if (tournament.tournamentName != "None")
{
return tournament.tournamentName;
}
return tournament.tournamentType switch
{
TournamentContentType.Cyclic => LanguageManager.Instance.GetText("CYCLIC_TOURNAMENT") + " #" + tournament.id,
TournamentContentType.Daily => LanguageManager.Instance.GetText("DAILY_TOURNAMENT") + " #" + tournament.id,
TournamentContentType.Players => LanguageManager.Instance.GetText("PLAYERS_TOURNAMENT") + " #" + tournament.id,
_ => "GET_TOURNAMENT_NAME_ERROR",
};
}
public string GetTournamentTaskText(CTournament tournament)
{
return LanguageManager.Instance.GetText("TOURNAMENT_TASK_" + tournament.tournamentTask.ToString().ToUpper());
}
public string GetTournamentMethodText(CTournament tournament)
{
return tournament.tournamentMethod switch
{
CTournament.TournamentMethod.All => LanguageManager.Instance.GetText("ALLOWED_METHOD") + ": " + LanguageManager.Instance.GetText("ANY"),
CTournament.TournamentMethod.Spinning => LanguageManager.Instance.GetText("ALLOWED_METHOD") + ": " + LanguageManager.Instance.GetText("SPINNING"),
CTournament.TournamentMethod.Float => LanguageManager.Instance.GetText("ALLOWED_METHOD") + ": " + LanguageManager.Instance.GetText("FLOAT"),
CTournament.TournamentMethod.Feeder => LanguageManager.Instance.GetText("ALLOWED_METHOD") + ": " + LanguageManager.Instance.GetText("FEEDER"),
_ => "GET_TOURNAMENT_METHOD_ERROR",
};
}
public TournamentPrizes GetPlayerPrizes(int playerPosition)
{
for (int i = 0; i < tournamentPrizes.Length; i++)
{
if (tournamentPrizes[i].tournamentType == currentPlayTournament.tournamentType && tournamentPrizes[i].Position == playerPosition)
{
return tournamentPrizes[i];
}
}
return null;
}
public void AddFishTournament(GameManager.FishSpecies fishSpecies, float weight, FPlayer player = null, int mapId = 0)
{
bool flag = false;
switch (currentPlayTournament.tournamentMethod)
{
case CTournament.TournamentMethod.All:
flag = true;
break;
case CTournament.TournamentMethod.Spinning:
if (player.currentRod.currentLure != null)
{
flag = true;
}
break;
case CTournament.TournamentMethod.Float:
if (player.currentRod.currentFloat != null)
{
flag = true;
}
break;
case CTournament.TournamentMethod.Feeder:
if (player.currentRod.currentFeeder != null)
{
flag = true;
}
break;
}
if (flag)
{
ServerManager.Instance.TournamentSendFish((int)fishSpecies, weight, currentPlayTournament, mapId);
}
else if ((bool)FScriptsHandler.Instance)
{
string text = LanguageManager.Instance.GetText("TOURNAMENT_INVALID_METHOD_MESSAGE");
GameManager.Instance.ShowMessagePopup(text, FScriptsHandler.Instance.m_Canvas.transform);
}
}
}