790 lines
26 KiB
C#
790 lines
26 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using ExitGames.Client.Photon;
|
|
using I2.Loc;
|
|
using Photon;
|
|
using PygmyMonkey.AdvancedBuilder;
|
|
using UnityEngine;
|
|
|
|
public class MultiplayerManager : PunBehaviour
|
|
{
|
|
private static MultiplayerManager instance;
|
|
|
|
public string GameVersionPUN = "1.0";
|
|
|
|
public byte roomMaxPlayers = 10;
|
|
|
|
public bool useSteamNames = true;
|
|
|
|
public GameObject remotePlayersParent;
|
|
|
|
[ReadOnly]
|
|
public string lastRoomName = string.Empty;
|
|
|
|
[ReadOnly]
|
|
public List<string> mutedPlayers = new List<string>();
|
|
|
|
private new PhotonView photonView;
|
|
|
|
[HideInInspector]
|
|
public HUDMultiplayer hudMultiplayer;
|
|
|
|
[HideInInspector]
|
|
public MultiplayerChat multiplayerChat;
|
|
|
|
[HideInInspector]
|
|
public PhotonLagSimulationGui photonLagSimulationGui;
|
|
|
|
[HideInInspector]
|
|
public PhotonStatsGui photonStatsGui;
|
|
|
|
[HideInInspector]
|
|
public GameController gameController;
|
|
|
|
[HideInInspector]
|
|
public FishingPlayerRemote fishingPlayerRemote;
|
|
|
|
public static MultiplayerManager Instance
|
|
{
|
|
get
|
|
{
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
private MultiplayerManager()
|
|
{
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = this;
|
|
}
|
|
multiplayerChat = GetComponent<MultiplayerChat>();
|
|
photonLagSimulationGui = GetComponent<PhotonLagSimulationGui>();
|
|
photonStatsGui = GetComponent<PhotonStatsGui>();
|
|
photonView = GetComponent<PhotonView>();
|
|
photonLagSimulationGui.Visible = false;
|
|
photonStatsGui.statsWindowOn = false;
|
|
photonStatsGui.statsOn = false;
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
hudMultiplayer = HUDManager.Instance.hudMultiplayer;
|
|
gameController = GameController.Instance;
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
if (!GlobalSettings.Instance.turnOnCheats)
|
|
{
|
|
ShowAvatars(false);
|
|
}
|
|
else
|
|
{
|
|
ShowAvatars(GlobalSettings.Instance.playerSettings.showMultiplayerAvatars);
|
|
}
|
|
}
|
|
Connect();
|
|
}
|
|
|
|
public void MakeUpdate()
|
|
{
|
|
if (!GlobalSettings.Instance || GlobalSettings.Instance.turnOnCheats || GlobalSettings.Instance.turnOnMyCheats)
|
|
{
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.F2))
|
|
{
|
|
multiplayerChat.SendFish("FISH/LAKE_TROUT_NAME", 666f);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.F4))
|
|
{
|
|
photonLagSimulationGui.Visible = !photonLagSimulationGui.Visible;
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.F5))
|
|
{
|
|
photonStatsGui.statsWindowOn = !photonStatsGui.statsWindowOn;
|
|
photonStatsGui.statsOn = !photonStatsGui.statsOn;
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.F6))
|
|
{
|
|
Disconnect();
|
|
}
|
|
}
|
|
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.F3))
|
|
{
|
|
multiplayerChat.SendFish("FISH/LAKE_TROUT_NAME", UnityEngine.Random.Range(1f, 100f));
|
|
}
|
|
}
|
|
if (gameController.isTournament && PhotonNetwork.isMasterClient && !gameController.tournamentManager.tournamentStarted && UtilitiesInput.GetButtonDown("START_TOURNAMENT") && !hudMultiplayer.isInInputMode)
|
|
{
|
|
StartTournament();
|
|
}
|
|
hudMultiplayer.SetConnectionState(PhotonNetwork.connectionStateDetailed.ToString());
|
|
if (PhotonNetwork.connectedAndReady)
|
|
{
|
|
PhotonNetwork.SendOutgoingCommands();
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void Connect()
|
|
{
|
|
if (((bool)GlobalSettings.Instance && !GlobalSettings.Instance.turnOnCheats && !GlobalSettings.Instance.turnOnMyCheats && GlobalSettings.Instance.IsMyProfileCracked()) || PhotonNetwork.connected)
|
|
{
|
|
return;
|
|
}
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
if (GlobalSettings.Instance.currentPlatform == GlobalSettings.Platform.ARCADE)
|
|
{
|
|
if (Environment.UserName != null)
|
|
{
|
|
PhotonNetwork.playerName = Environment.UserName;
|
|
}
|
|
else
|
|
{
|
|
PhotonNetwork.playerName = GlobalSettings.Instance.playerSettings.playersName;
|
|
}
|
|
}
|
|
else if (useSteamNames)
|
|
{
|
|
PhotonNetwork.playerName = GlobalSettings.Instance.GetPlatformProfileName();
|
|
}
|
|
else if (GlobalSettings.Instance.turnOnCheats || GlobalSettings.Instance.turnOnMyCheats)
|
|
{
|
|
PhotonNetwork.playerName = "UC";
|
|
}
|
|
else
|
|
{
|
|
PhotonNetwork.playerName = GlobalSettings.Instance.playerSettings.playersName;
|
|
}
|
|
Debug.LogError("PhotonNetwork.playerName: " + PhotonNetwork.playerName);
|
|
}
|
|
else
|
|
{
|
|
PhotonNetwork.playerName = "Editor Player";
|
|
}
|
|
PhotonNetwork.ConnectUsingSettings(GameVersionPUN);
|
|
hudMultiplayer.SetStatusText(Utilities.GetTranslation("MULTIPLAYER/CONNECTING") + "...");
|
|
}
|
|
|
|
public void Disconnect()
|
|
{
|
|
Debug.Log("Network Disconnect");
|
|
PhotonNetwork.Disconnect();
|
|
}
|
|
|
|
public void OnApplicationQuit()
|
|
{
|
|
Disconnect();
|
|
}
|
|
|
|
public void OnDestroy()
|
|
{
|
|
Disconnect();
|
|
}
|
|
|
|
public new void OnConnectedToMaster()
|
|
{
|
|
ConnectedToLobby();
|
|
}
|
|
|
|
public new void OnDisconnectedFromPhoton()
|
|
{
|
|
Debug.Log("OnDisconnectedFromPhoton");
|
|
hudMultiplayer.ShowChat(false);
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("MULTIPLAYER/CONNECTION_LOST"));
|
|
multiplayerChat.ShowSystemMessage(Utilities.GetTranslation("MULTIPLAYER/CONNECTION_LOST"));
|
|
hudMultiplayer.SetStatusText(Utilities.GetTranslation("MULTIPLAYER/CONNECTION_LOST"));
|
|
if (gameController.isTournament)
|
|
{
|
|
gameController.tournamentManager.RemoveAllPlayers(true);
|
|
}
|
|
LeanTween.delayedCall(3f, Connect);
|
|
}
|
|
|
|
public new void OnJoinedRoom()
|
|
{
|
|
ConnectedToGame();
|
|
}
|
|
|
|
public new void OnPhotonJoinRoomFailed(object[] codeAndMsg)
|
|
{
|
|
Debug.Log(string.Concat("OnPhotonJoinRoomFailed ", codeAndMsg[0], " ", codeAndMsg[1]));
|
|
if (lastRoomName != string.Empty)
|
|
{
|
|
lastRoomName = string.Empty;
|
|
if (!gameController.isTournament)
|
|
{
|
|
JoinRandomGame();
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("MULTIPLAYER/NO_PREVIOUS_ROOM"), 5f);
|
|
}
|
|
else
|
|
{
|
|
HUDManager.Instance.ShowMessageWindow(true, Utilities.GetTranslation("MULTIPLAYER/ROOM_NOT_EXIST"));
|
|
}
|
|
}
|
|
else if (GlobalSettings.Instance.levelsManager.multiRoomName != string.Empty)
|
|
{
|
|
HUDManager.Instance.ShowMessageWindow(true, Utilities.GetTranslation("MULTIPLAYER/ROOM_NOT_EXIST"));
|
|
}
|
|
else if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.currentPlatform == GlobalSettings.Platform.ARCADE && GlobalSettings.Instance.levelsManager.multiPrivateRoom)
|
|
{
|
|
CreateGame();
|
|
}
|
|
}
|
|
|
|
public void OnPhotonRandomJoinFailed()
|
|
{
|
|
if (gameController.isTournament)
|
|
{
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("MULTIPLAYER/NO_TOURNAMENT_CREATE"), 10f);
|
|
}
|
|
CreateGame();
|
|
}
|
|
|
|
public new void OnPhotonPlayerConnected(PhotonPlayer player)
|
|
{
|
|
PlayerConnected(player);
|
|
}
|
|
|
|
public new void OnPhotonPlayerDisconnected(PhotonPlayer player)
|
|
{
|
|
PlayerDisconnected(player);
|
|
}
|
|
|
|
public void OnMasterClientSwitched()
|
|
{
|
|
Debug.Log("OnMasterClientSwitched");
|
|
}
|
|
|
|
public new void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged)
|
|
{
|
|
UpdateRoomProperties(propertiesThatChanged);
|
|
}
|
|
|
|
public new void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
|
|
{
|
|
UpdatePlayersProperties(playerAndUpdatedProps);
|
|
}
|
|
|
|
public new void OnReceivedRoomListUpdate()
|
|
{
|
|
ListRooms();
|
|
}
|
|
|
|
[Button]
|
|
public void ListRooms()
|
|
{
|
|
RoomInfo[] roomList = PhotonNetwork.GetRoomList();
|
|
Debug.Log("ListRooms roomsList: " + roomList.Length + " insideLobby " + PhotonNetwork.insideLobby);
|
|
for (int i = 0; i < roomList.Length; i++)
|
|
{
|
|
Debug.Log("Room " + i + ": " + roomList[i].name + " " + roomList[i].maxPlayers);
|
|
Debug.Log(string.Empty + roomList[i].customProperties.ToStringFull());
|
|
}
|
|
}
|
|
|
|
public void ConnectedToLobby()
|
|
{
|
|
Debug.Log(PhotonNetwork.lobby.Type.ToString() + " insideLobby " + PhotonNetwork.insideLobby);
|
|
Debug.Log("PhotonNetwork.countOfRooms: " + PhotonNetwork.countOfRooms);
|
|
Debug.Log("PhotonNetwork.countOfPlayersOnMaster: " + PhotonNetwork.countOfPlayersOnMaster);
|
|
Debug.Log("PhotonNetwork.countOfPlayersInRooms: " + PhotonNetwork.countOfPlayersInRooms);
|
|
Debug.Log("PhotonNetwork.countOfPlayers: " + PhotonNetwork.countOfPlayers);
|
|
ListRooms();
|
|
HUDManager.Instance.ShowMessageWindow(false, string.Empty);
|
|
gameController.fishingPlayer.currentHands.CheckHasHook();
|
|
string text = ((!GlobalSettings.Instance) ? gameController.multiRoomName : GlobalSettings.Instance.levelsManager.multiRoomName);
|
|
if (lastRoomName != string.Empty)
|
|
{
|
|
JoinPrivateGame(lastRoomName);
|
|
}
|
|
else if (gameController.isTournament && (bool)GlobalSettings.Instance && GlobalSettings.Instance.levelsManager.createTournament)
|
|
{
|
|
CreateGame();
|
|
}
|
|
else if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.currentPlatform == GlobalSettings.Platform.ARCADE && GlobalSettings.Instance.levelsManager.multiPrivateRoom && GlobalSettings.Instance.levelsManager.multiRoomNameArcade != string.Empty)
|
|
{
|
|
JoinPrivateGame(GlobalSettings.Instance.levelsManager.multiRoomNameArcade);
|
|
}
|
|
else if (((bool)GlobalSettings.Instance && GlobalSettings.Instance.currentPlatform != GlobalSettings.Platform.ARCADE && GlobalSettings.Instance.levelsManager.multiPrivateRoom) || (!GlobalSettings.Instance && gameController.multiPrivateRoom))
|
|
{
|
|
CreateGame();
|
|
}
|
|
else if (text != string.Empty)
|
|
{
|
|
JoinPrivateGame(text);
|
|
}
|
|
else
|
|
{
|
|
JoinRandomGame();
|
|
}
|
|
}
|
|
|
|
public void ConnectedToGame()
|
|
{
|
|
if (PhotonNetwork.playerList.Length == 1)
|
|
{
|
|
}
|
|
Debug.Log("OnJoinedRoom " + PhotonNetwork.room.Name);
|
|
lastRoomName = PhotonNetwork.room.Name;
|
|
if (gameController.isTournament)
|
|
{
|
|
for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
|
|
{
|
|
}
|
|
}
|
|
Hashtable hashtable = new Hashtable();
|
|
hashtable.Add("steamId", (!GlobalSettings.Instance) ? "0" : GlobalSettings.Instance.GetPlatformProfileID().ToString());
|
|
Debug.Log("steamId " + ((!GlobalSettings.Instance) ? "0" : GlobalSettings.Instance.GetPlatformProfileID().ToString()));
|
|
hashtable.Add("playersLevel", 0);
|
|
hashtable.Add("playersScore", 0);
|
|
hashtable.Add("playersExperience", 0);
|
|
hashtable.Add("totalFishCount", 0);
|
|
hashtable.Add("totalFishWeight", 0);
|
|
hashtable.Add("biggestFishSpecies", -1);
|
|
hashtable.Add("biggestFishWeight", -1);
|
|
hashtable.Add("gameBundleVersion", AppParameters.Get.buildNumber);
|
|
if (gameController.isTournament)
|
|
{
|
|
gameController.fishingPlayer.tournamentPlayer.playerId = PhotonNetwork.player.ID;
|
|
gameController.fishingPlayer.UpdateTournamentPlayerName();
|
|
if (PhotonNetwork.isMasterClient)
|
|
{
|
|
Hashtable hashtable2 = new Hashtable();
|
|
hashtable2.Add("goalType", (int)gameController.tournamentManager.tournamentDefinition.goalType);
|
|
hashtable2.Add("finishCondition", (int)gameController.tournamentManager.tournamentDefinition.finishCondition);
|
|
hashtable2.Add("goalAmount", (int)gameController.tournamentManager.tournamentDefinition.goalAmount);
|
|
hashtable2.Add("currentTime", gameController.tournamentManager.currentTime);
|
|
hashtable2.Add("duration", gameController.tournamentManager.tournamentDefinition.duration);
|
|
PhotonNetwork.room.SetCustomProperties(hashtable2);
|
|
}
|
|
hashtable.Add("score", 0f);
|
|
}
|
|
PhotonNetwork.player.SetCustomProperties(hashtable);
|
|
UpdateMyStats();
|
|
if (gameController.isTournament)
|
|
{
|
|
UpdateMyScore();
|
|
}
|
|
CreateFishingPlayerRemote();
|
|
hudMultiplayer.Reset();
|
|
hudMultiplayer.ShowChat(true);
|
|
hudMultiplayer.SetStatusText(string.Empty);
|
|
multiplayerChat.Initialize();
|
|
multiplayerChat.ShowSystemMessage(PhotonNetwork.playerName + " " + Utilities.GetTranslation("MULTIPLAYER/CONNECTED"));
|
|
int num = 0;
|
|
for (int j = 0; j < PhotonNetwork.playerList.Length; j++)
|
|
{
|
|
if ((bool)GlobalSettings.Instance && !GlobalSettings.Instance.CheckCrackPhotonPlayer(PhotonNetwork.playerList[j]))
|
|
{
|
|
num++;
|
|
}
|
|
}
|
|
multiplayerChat.ShowSystemMessage(Utilities.GetTranslation("MULTIPLAYER/NR_OF_PLAYERS") + ": " + num);
|
|
Debug.LogError("MultiPlayers playersCount: " + num + " PhotonNetwork.room.PlayerCount: " + PhotonNetwork.room.PlayerCount);
|
|
if (!PhotonNetwork.isMasterClient && (bool)GlobalSettings.Instance && (GlobalSettings.Instance.CheckCrackPhotonPlayer(PhotonNetwork.masterClient) || GlobalSettings.Instance.turnOnMyCheats))
|
|
{
|
|
MakeMeMaster();
|
|
}
|
|
}
|
|
|
|
public void CreateGame()
|
|
{
|
|
RoomOptions roomOptions = new RoomOptions();
|
|
roomOptions.isOpen = true;
|
|
roomOptions.isVisible = ((!GlobalSettings.Instance) ? (!gameController.multiPrivateRoom) : (!GlobalSettings.Instance.levelsManager.multiPrivateRoom));
|
|
roomOptions.maxPlayers = ((!gameController.isTournament) ? roomMaxPlayers : ((byte)gameController.tournamentManager.tournamentDefinition.nrOfPlayers));
|
|
string[] customRoomPropertiesForLobby = new string[4] { "map", "mode", "lang", "version" };
|
|
roomOptions.customRoomPropertiesForLobby = customRoomPropertiesForLobby;
|
|
roomOptions.customRoomProperties = GenerateRoomProperties();
|
|
string text = PhotonNetwork.playerName + "_" + UnityEngine.Random.Range(1000, 9999);
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.currentPlatform == GlobalSettings.Platform.ARCADE && GlobalSettings.Instance.levelsManager.multiPrivateRoom)
|
|
{
|
|
if (GlobalSettings.Instance.levelsManager.multiRoomNameArcade != string.Empty)
|
|
{
|
|
text = GlobalSettings.Instance.levelsManager.multiRoomNameArcade;
|
|
}
|
|
else
|
|
{
|
|
roomOptions.isVisible = true;
|
|
}
|
|
}
|
|
Debug.Log("CreateGame " + ((!roomOptions.isVisible) ? text : string.Empty));
|
|
if (roomOptions.isVisible)
|
|
{
|
|
PhotonNetwork.CreateRoom(null, roomOptions, null);
|
|
}
|
|
else
|
|
{
|
|
PhotonNetwork.CreateRoom(text, roomOptions, null);
|
|
}
|
|
}
|
|
|
|
public void JoinRandomGame()
|
|
{
|
|
Debug.Log("Try JoinRandomGame");
|
|
PhotonNetwork.JoinRandomRoom(GenerateRoomProperties(), 0);
|
|
}
|
|
|
|
public void JoinPrivateGame(string roomName)
|
|
{
|
|
Debug.Log("Try JoinPrivateGame");
|
|
PhotonNetwork.JoinRoom(roomName);
|
|
}
|
|
|
|
public Hashtable GenerateRoomProperties()
|
|
{
|
|
Hashtable hashtable = new Hashtable();
|
|
hashtable.Add("map", gameController.GetFisheryId());
|
|
hashtable.Add("mode", gameController.isTournament ? 1 : 0);
|
|
bool flag = ((!GlobalSettings.Instance) ? gameController.multiAnyLanguage : GlobalSettings.Instance.levelsManager.multiAnyLanguage);
|
|
hashtable.Add("lang", (!flag) ? LocalizationManager.CurrentLanguageCode : "any");
|
|
int num = 1;
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
num = ((!GlobalSettings.Instance.IsMyProfileCracked()) ? 1 : 0);
|
|
if (GlobalSettings.Instance.currentPlatform == GlobalSettings.Platform.ARCADE && GlobalSettings.Instance.levelsManager.multiPrivateRoom && GlobalSettings.Instance.levelsManager.multiRoomNameArcade == string.Empty)
|
|
{
|
|
num = 200;
|
|
}
|
|
hashtable.Add("version", num);
|
|
}
|
|
Debug.Log("GenerateRoomProperties: " + gameController.GetFisheryId() + " " + (gameController.isTournament ? 1 : 0) + " " + LocalizationManager.CurrentLanguageCode + " version " + num);
|
|
return hashtable;
|
|
}
|
|
|
|
[Button]
|
|
public void MakeMeMaster()
|
|
{
|
|
if (!PhotonNetwork.isMasterClient)
|
|
{
|
|
PhotonNetwork.SetMasterClient(PhotonNetwork.player);
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void DisconnectCrackPlayers()
|
|
{
|
|
if (!PhotonNetwork.connected || !PhotonNetwork.isMasterClient)
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.CheckCrackPhotonPlayer(PhotonNetwork.playerList[i]))
|
|
{
|
|
PhotonNetwork.CloseConnection(PhotonNetwork.playerList[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void PlayerConnected(PhotonPlayer player)
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.CheckCrackPhotonPlayer(player))
|
|
{
|
|
if (PhotonNetwork.isMasterClient && player.CustomProperties.ContainsKey("gameBundleVersion") && (int)player.CustomProperties["gameBundleVersion"] >= (int)GlobalSettings.Instance.minOnlineBundleVersion)
|
|
{
|
|
}
|
|
return;
|
|
}
|
|
if (PhotonNetwork.isMasterClient)
|
|
{
|
|
UpdateMyTime();
|
|
UpdateWeather();
|
|
if (gameController.tournamentManager.tournamentStarted)
|
|
{
|
|
StartTournament();
|
|
}
|
|
}
|
|
if (gameController.isTournament)
|
|
{
|
|
UpdateMyScore();
|
|
}
|
|
if ((bool)fishingPlayerRemote)
|
|
{
|
|
fishingPlayerRemote.StateChanged();
|
|
fishingPlayerRemote.SetVisible(fishingPlayerRemote.isVisible);
|
|
}
|
|
multiplayerChat.ShowSystemMessage(player.NickName + " " + Utilities.GetTranslation("MULTIPLAYER/CONNECTED"));
|
|
}
|
|
|
|
public void PlayerDisconnected(PhotonPlayer player)
|
|
{
|
|
if (!GlobalSettings.Instance || !GlobalSettings.Instance.CheckCrackPhotonPlayer(player))
|
|
{
|
|
if (PhotonNetwork.isMasterClient)
|
|
{
|
|
}
|
|
if (gameController.isTournament)
|
|
{
|
|
gameController.tournamentManager.RemovePlayer(player.ID);
|
|
}
|
|
multiplayerChat.ShowSystemMessage(player.NickName + " " + Utilities.GetTranslation("MULTIPLAYER/DISCONNECTED"));
|
|
}
|
|
}
|
|
|
|
public void UpdateRoomProperties(Hashtable propertiesThatChanged)
|
|
{
|
|
if (gameController.isTournament && gameController.tournamentManager.tournamentActive && !PhotonNetwork.isMasterClient)
|
|
{
|
|
if (propertiesThatChanged.ContainsKey("goalType"))
|
|
{
|
|
gameController.tournamentManager.tournamentDefinition.goalType = (TournamentManager.TournamentDefinition.GoalType)propertiesThatChanged["goalType"];
|
|
}
|
|
if (propertiesThatChanged.ContainsKey("finishCondition"))
|
|
{
|
|
gameController.tournamentManager.tournamentDefinition.finishCondition = (TournamentManager.TournamentDefinition.FinishCondition)propertiesThatChanged["finishCondition"];
|
|
}
|
|
if (propertiesThatChanged.ContainsKey("goalAmount"))
|
|
{
|
|
gameController.tournamentManager.tournamentDefinition.goalAmount = (int)propertiesThatChanged["goalAmount"];
|
|
}
|
|
if (propertiesThatChanged.ContainsKey("duration"))
|
|
{
|
|
gameController.tournamentManager.tournamentDefinition.duration = (float)propertiesThatChanged["duration"];
|
|
}
|
|
if (propertiesThatChanged.ContainsKey("currentTime"))
|
|
{
|
|
gameController.tournamentManager.currentTime = (float)propertiesThatChanged["currentTime"];
|
|
}
|
|
gameController.tournamentManager.UpdateMultiplayerSettings();
|
|
}
|
|
}
|
|
|
|
public void UpdatePlayersProperties(object[] playerAndUpdatedProps)
|
|
{
|
|
PhotonPlayer photonPlayer = playerAndUpdatedProps[0] as PhotonPlayer;
|
|
Hashtable hashtable = playerAndUpdatedProps[1] as Hashtable;
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.CheckCrackPhotonPlayer(photonPlayer))
|
|
{
|
|
return;
|
|
}
|
|
Debug.Log("Property changed Player " + photonPlayer.NickName + " score: " + ((!hashtable.ContainsKey("score")) ? string.Empty : ((float)hashtable["score"]/*cast due to .constrained prefix*/).ToString()));
|
|
if (gameController.isTournament && gameController.tournamentManager.tournamentActive && photonPlayer.ID != PhotonNetwork.player.ID)
|
|
{
|
|
if (gameController.tournamentManager.GetPlayer(photonPlayer.ID) == null)
|
|
{
|
|
gameController.tournamentManager.AddNetworkPlayer(photonPlayer);
|
|
}
|
|
if (hashtable.ContainsKey("score"))
|
|
{
|
|
gameController.tournamentManager.GetPlayer(photonPlayer.ID).SetScore(gameController.tournamentManager.tournamentDefinition.goalType, (float)hashtable["score"]);
|
|
}
|
|
gameController.tournamentManager.SortPlayers();
|
|
gameController.tournamentManager.hudTournament.UpdatePlayerWidgets();
|
|
if (PhotonNetwork.isMasterClient && gameController.tournamentManager.CheckFinishCondition())
|
|
{
|
|
gameController.tournamentManager.FinishTournament();
|
|
}
|
|
}
|
|
if (hashtable.ContainsKey("steamId") && (bool)SteamStatsManager.Instance)
|
|
{
|
|
Debug.Log("steamId " + Convert.ToUInt64(hashtable["steamId"]));
|
|
SteamStatsManager.SteamUser steamUser = SteamStatsManager.Instance.CreatePlatformUser(Convert.ToUInt64(hashtable["steamId"]));
|
|
SteamStatsManager.Instance.RequestUserStats(steamUser);
|
|
SteamStatsManager.Instance.RequestUserInformation(steamUser, false);
|
|
}
|
|
}
|
|
|
|
public void UpdateMyStats()
|
|
{
|
|
GlobalSettings globalSettings = GlobalSettings.Instance;
|
|
if ((bool)globalSettings)
|
|
{
|
|
bool flag = globalSettings.playerSettings.CheckMyStatsIntegrity();
|
|
PhotonNetwork.player.customProperties["playersLevel"] = ((!globalSettings || !flag) ? 1 : ((int)globalSettings.playerSettings.playersLevel));
|
|
PhotonNetwork.player.customProperties["playersScore"] = (((bool)globalSettings && flag) ? ((int)globalSettings.playerSettings.playersScore) : 0);
|
|
PhotonNetwork.player.customProperties["playersExperience"] = (((bool)globalSettings && flag) ? ((int)globalSettings.playerSettings.playersExperience) : 0);
|
|
PhotonNetwork.player.customProperties["totalFishCount"] = (((bool)globalSettings && flag) ? globalSettings.fishManager.GetTotalFishCount() : 0);
|
|
PhotonNetwork.player.customProperties["totalFishWeight"] = (((bool)globalSettings && flag) ? Mathf.RoundToInt(globalSettings.fishManager.GetTotalFishWeight() * 1000f) : 0);
|
|
FishManager.FishDefinition fishDefinition = null;
|
|
if ((bool)globalSettings)
|
|
{
|
|
fishDefinition = globalSettings.fishManager.GetBiggestFishDefinition();
|
|
}
|
|
if (fishDefinition == null)
|
|
{
|
|
PhotonNetwork.player.customProperties["biggestFishSpecies"] = -1;
|
|
PhotonNetwork.player.customProperties["biggestFishWeight"] = -1;
|
|
}
|
|
else
|
|
{
|
|
PhotonNetwork.player.customProperties["biggestFishSpecies"] = (int)fishDefinition.species;
|
|
PhotonNetwork.player.customProperties["biggestFishWeight"] = Mathf.RoundToInt(fishDefinition.weight * 1000f);
|
|
}
|
|
PhotonNetwork.player.SetCustomProperties(PhotonNetwork.player.customProperties);
|
|
}
|
|
}
|
|
|
|
public void UpdateMyScore()
|
|
{
|
|
PhotonNetwork.player.customProperties["score"] = gameController.tournamentManager.GetMyPlayer().GetScore();
|
|
PhotonNetwork.player.SetCustomProperties(PhotonNetwork.player.customProperties);
|
|
}
|
|
|
|
public void UpdateMyTime()
|
|
{
|
|
if (gameController.isTournament && gameController.tournamentManager.tournamentActive && PhotonNetwork.isMasterClient)
|
|
{
|
|
PhotonNetwork.room.customProperties["currentTime"] = gameController.tournamentManager.currentTime;
|
|
PhotonNetwork.room.SetCustomProperties(PhotonNetwork.room.customProperties);
|
|
Debug.Log("UPDATE NETWORK TIME");
|
|
}
|
|
}
|
|
|
|
public void GetPlayersList()
|
|
{
|
|
for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
|
|
{
|
|
Debug.Log("OnlinePlayer " + PhotonNetwork.playerList[i].ID + " " + PhotonNetwork.playerList[i].NickName + " " + ((!PhotonNetwork.playerList[i].CustomProperties.ContainsKey("steamId")) ? string.Empty : PhotonNetwork.playerList[i].CustomProperties["steamId"]));
|
|
Debug.Log("SteamId test: " + GlobalSettings.Instance.GetPlatformProfileID());
|
|
}
|
|
}
|
|
|
|
public void StartTournament()
|
|
{
|
|
if (gameController.isTournament && PhotonNetwork.isMasterClient)
|
|
{
|
|
gameController.tournamentManager.StartTournament();
|
|
photonView.RPC("TournamentStarted", PhotonTargets.Others);
|
|
}
|
|
}
|
|
|
|
[PunRPC]
|
|
public void TournamentStarted()
|
|
{
|
|
if (gameController.isTournament)
|
|
{
|
|
gameController.tournamentManager.StartTournament();
|
|
Debug.Log("[PunRPC] TournamentStarted");
|
|
}
|
|
}
|
|
|
|
public void FinishTournament()
|
|
{
|
|
if (gameController.isTournament && PhotonNetwork.isMasterClient)
|
|
{
|
|
float[] array = new float[gameController.tournamentManager.sortedPlayers.Count * 2];
|
|
for (int i = 0; i < gameController.tournamentManager.sortedPlayers.Count; i++)
|
|
{
|
|
array[i * 2] = gameController.tournamentManager.sortedPlayers[i].playerId;
|
|
array[i * 2 + 1] = gameController.tournamentManager.sortedPlayers[i].GetScore();
|
|
}
|
|
photonView.RPC("TournamentFinished", PhotonTargets.Others, array);
|
|
PhotonNetwork.room.open = false;
|
|
}
|
|
}
|
|
|
|
[PunRPC]
|
|
public void TournamentFinished(float[] sendTable)
|
|
{
|
|
if (gameController.tournamentManager.tournamentActive)
|
|
{
|
|
for (int i = 0; i < sendTable.Length; i += 2)
|
|
{
|
|
}
|
|
gameController.tournamentManager.FinalSortPlayers(sendTable);
|
|
gameController.tournamentManager.FinishTournament();
|
|
Debug.Log("[PunRPC] TournamentFinished");
|
|
}
|
|
}
|
|
|
|
public void UpdateWeather()
|
|
{
|
|
if (gameController.isTournament && gameController.tournamentManager.tournamentActive && PhotonNetwork.isMasterClient)
|
|
{
|
|
photonView.RPC("WeatherUpdated", PhotonTargets.Others, gameController.azureSkyController.TIME_of_DAY, gameController.weatherLevelManager.GetCloudiness(), gameController.weatherLevelManager.temperatureType, gameController.weatherLevelManager.GetPressure(), 0f, gameController.weatherLevelManager.precipitation, gameController.weatherLevelManager.windStrength, false);
|
|
}
|
|
}
|
|
|
|
[PunRPC]
|
|
public void WeatherUpdated(float hour, float clouds, int temperatureType, int pressure, float dayLength, float precipitation, float windStrength, bool isWinter, PhotonMessageInfo info)
|
|
{
|
|
if ((bool)gameController.weatherLevelManager)
|
|
{
|
|
gameController.weatherLevelManager.SetHour(hour);
|
|
gameController.weatherLevelManager.SetCloudiness(clouds);
|
|
gameController.weatherLevelManager.temperatureType = temperatureType;
|
|
gameController.weatherLevelManager.pressure = Mathf.RoundToInt(pressure);
|
|
gameController.weatherLevelManager.SetPrecipitation(precipitation);
|
|
gameController.weatherLevelManager.SetWindStrength(windStrength);
|
|
gameController.weatherLevelManager.UpdateWeather(false);
|
|
gameController.RenderAllProbes();
|
|
}
|
|
Debug.Log("MULTI WeatherUpdated");
|
|
}
|
|
|
|
public void CreateFishingPlayerRemote()
|
|
{
|
|
fishingPlayerRemote = PhotonNetwork.Instantiate("FishingPlayerRemote", Vector3.zero, Quaternion.identity, 0).GetComponent<FishingPlayerRemote>();
|
|
fishingPlayerRemote.fishingPlayer = gameController.fishingPlayer;
|
|
gameController.fishingPlayer.fishingPlayerRemote = fishingPlayerRemote;
|
|
fishingPlayerRemote.SetVisible(true);
|
|
}
|
|
|
|
public void ShowAvatars(bool show)
|
|
{
|
|
}
|
|
|
|
public void RefreshRemotePlayerSteamStats(ulong platformIdLong, bool onlyAvatar = false)
|
|
{
|
|
FishingPlayerRemote[] componentsInChildren = remotePlayersParent.GetComponentsInChildren<FishingPlayerRemote>();
|
|
for (int i = 0; i < componentsInChildren.Length; i++)
|
|
{
|
|
if (componentsInChildren[i].platformIdLong == platformIdLong)
|
|
{
|
|
if (onlyAvatar)
|
|
{
|
|
componentsInChildren[i].RefreshAvatar();
|
|
}
|
|
else
|
|
{
|
|
componentsInChildren[i].RefreshSteamUser();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public SteamStatsManager.SteamUser FindUserWithId(ulong platformId)
|
|
{
|
|
FishingPlayerRemote[] componentsInChildren = remotePlayersParent.GetComponentsInChildren<FishingPlayerRemote>();
|
|
for (int i = 0; i < componentsInChildren.Length; i++)
|
|
{
|
|
if (componentsInChildren[i].platformIdLong == platformId)
|
|
{
|
|
return componentsInChildren[i].steamUser;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void SendMultiInvite()
|
|
{
|
|
}
|
|
|
|
public void MutePlayer(string playerName, bool mute)
|
|
{
|
|
Debug.Log("MutePlayer " + playerName + " " + mute);
|
|
if (mute && !mutedPlayers.Contains(playerName))
|
|
{
|
|
mutedPlayers.Add(playerName);
|
|
}
|
|
else if (!mute && mutedPlayers.Contains(playerName))
|
|
{
|
|
mutedPlayers.Remove(playerName);
|
|
}
|
|
}
|
|
|
|
public bool IsPlayerMuted(string playerName)
|
|
{
|
|
return mutedPlayers.Contains(playerName);
|
|
}
|
|
}
|