Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SabongClassification;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEssentials;
- public class PushMatches : Singleton<PushMatches> {
- public List<SocketIOMatch> CurrentMatches;
- public List<MatchSelector> ActiveMatches;
- public List<MatchSelector> OnGoingBets;
- public List<GameObject> ActiveMatchesGO;
- public MatchSelector HistoryMatch;
- string tempStoreID;
- int j = 0;
- int endIndex;
- bool isInitialize;
- bool isLazyLoad;
- bool isHistory;
- public BetMatchesSelector current;
- List<BetMatchesSelector> MatchesWithBets;
- private void Start()
- {
- //subscribe to betting socket
- NetManager.Instance.SocketHandler.OnMatchUpdateEvent += SocketPush;
- }
- //remove currently subscribe to socket
- public void RemoveAllCurrentMatches()
- {
- j = 0;
- endIndex = 0;
- CurrentMatches.Clear();
- ActiveMatches.Clear();
- ActiveMatchesGO.Clear();
- HistoryMatch.MeronBetAmount = 0;
- HistoryMatch.WalaBetAmount = 0;
- HistoryMatch.MeronTotalBets = 0;
- HistoryMatch.WalaTotalBets = 0;
- }
- //remove subscribed
- public void ResetMatches()
- {
- if (ActiveMatchesGO.Count > 0)
- {
- if (MenuManager.Instance.PageMng.model.mState == MenuState.MatchMenu)
- {
- for (int i = 0; i < ActiveMatchesGO.Count; i++)
- {
- ActiveMatchesGO[i].GetComponent<MatchInfo>().isJoined = true;
- }
- RemoveAllCurrentMatches();
- }
- else
- {
- //Other Page
- }
- }
- //else
- // MenuController.Instance.ArenaMapMenu();
- }
- //Join Match to socket
- public void JoinMatch(GameObject CurrentActive, MatchSelector thisMatch, string MatchID, string EventID, string EventName, string CategoryID,
- int MinAmount, int MaxAmount, string MatchNo, string MatchName, string MeronID, string WalaID, string MeronBreed, string WalaBreed,
- string StartDate, string MatchStart, string Duration, string WinnerID, string CreatedDate, string ModifiedDate)
- {
- isHistory = false;
- MenuManager.Instance.MatchMng.view.go_ExpandLoader.SetActive(true);
- NetManager.Instance.SocketHandler.EmitJoinMatch(MatchID, EventID, EventName, CategoryID, MinAmount, MaxAmount, MatchNo, MatchName,
- MeronID, WalaID, MeronBreed, WalaBreed, StartDate, MatchStart, Duration, WinnerID, CreatedDate, ModifiedDate,
- true, false, false,
- (b, s) =>
- {
- //Debug.LogFormat("Success: {0}\nError Message: {1}", b, s);
- UnityMainThreadDispatcher.Instance().Enqueue(() =>
- {
- if (b)
- {
- StartCoroutine(AddToJoined(CurrentActive, MatchID, thisMatch));
- }
- else
- {
- MenuManager.Instance.MatchMng.view.go_ExpandLoader.SetActive(false);
- MenuManager.Instance.view.OpenPopUp("Unable to Join Match!");
- }
- });
- },
- SocketPush);
- StartCoroutine(MenuManager.Instance.MatchMng.controller.LongLoad(true));
- }
- //Wait to successfully joined before joining next match
- IEnumerator AddToJoined(GameObject go, string MatchID, MatchSelector match)
- {
- //yield return new WaitUntil(() => NetManager.Instance.SocketHandler != null && NetManager.Instance.SocketHandler.CurrentMatch != null
- // && NetManager.Instance.SocketHandler.CurrentMatch.EventMatchID != null && NetManager.Instance.SocketHandler.CurrentMatch.EventMatchID != string.Empty
- // && NetManager.Instance.SocketHandler.CurrentMatch.EventMatchID == MatchID);
- yield return new WaitUntil(() => NetManager.Instance.SocketHandler.CurrentMatch.EventMatchID == MatchID);
- MenuManager.Instance.MatchMng.model.notYetLoaded = true;
- ActiveMatches.Add(match);
- CurrentMatches.Add(match.ToSocketIOMatch());
- ActiveMatchesGO.Add(go);
- if (go != null)
- go.GetComponent<MatchInfo>().isJoined = true;
- yield return new WaitForSeconds(0.5f);
- NetManager.Instance.SocketHandler.EmitGetPayout(MatchID);
- MenuManager.Instance.MatchMng.view.go_ExpandLoader.SetActive(false);
- }
- //join match in ongoing menu
- public void JoinOngoingBets()
- {
- if (MenuManager.Instance.PageMng.model.mState == MenuState.BetMatchesMenu)
- {
- isHistory = false;
- if (!OnGoingBets[j].isRewardClaim)
- {
- NetManager.Instance.SocketHandler.EmitJoinMatch(OnGoingBets[j].MatchID, OnGoingBets[j].EventID,
- current.eventName, current.category, current.arenaMin, current.arenaMax,
- OnGoingBets[j].MatchNumber, OnGoingBets[j].Name,
- OnGoingBets[j].MeronID, OnGoingBets[j].WalaID, OnGoingBets[j].MeronBreed, OnGoingBets[j].WalaBreed,
- OnGoingBets[j].StartDate.ToString(), OnGoingBets[j].MatchStart.ToString(),
- OnGoingBets[j].Duration,
- OnGoingBets[j].WinnerSide,
- OnGoingBets[j].DateCreated, OnGoingBets[j].DateModified,
- true, false, false,
- (b, s) =>
- {
- //Debug.LogFormat("Success: {0}\nError Message: {1}", b, s);
- UnityMainThreadDispatcher.Instance().Enqueue(() =>
- {
- if (b)
- {
- NetManager.Instance.SocketHandler.EmitGetPayout(OnGoingBets[j].MatchID);
- StartCoroutine(AddToBetsJoined(OnGoingBets[j].MatchID));
- }
- else
- {
- MenuManager.Instance.view.OpenPopUp("Unable to Join Match!");
- }
- });
- },
- SocketPush);
- }
- else
- {
- if (!OnGoingBets[j].isMeronBet && !OnGoingBets[j].isWalaBet)
- NetManager.Instance.SocketHandler.EmitGetPayout(OnGoingBets[j].MatchID);
- StartCoroutine(AddToBetsJoined(OnGoingBets[j].MatchID));
- }
- }
- }
- //wait to successfully join in ongoing menu before joining next match
- IEnumerator AddToBetsJoined(string MatchID)
- {
- if (!OnGoingBets[j].isRewardClaim)
- yield return new WaitUntil(() => NetManager.Instance.SocketHandler.CurrentMatch.EventMatchID == MatchID);
- else
- yield return new WaitForSeconds(0.3f);
- CurrentMatches.Add(OnGoingBets[j].ToSocketIOMatch());
- j++;
- if (j < OnGoingBets.Count)
- JoinOngoingBets();
- //else
- //Debug.Log("Finished");
- }
- //Get final bet and display
- public void FinalBets(string MatchID, bool history)
- {
- ////Debug.Log("Fetch Final Bets!");
- isHistory = history;
- NetManager.Instance.SocketHandler.EmitGetPayout(MatchID);
- tempStoreID = MatchID;
- }
- //BROADCAST MATCHES from Betting socket
- void SocketPush(SocketIOMatchUpdate match)
- {
- //Debug.Log("push");
- //Debug.Log("Push Socket! " + match.ToJson(true));
- //MenuController.Instance.Matchs.go_ExpandLoader.SetActive(true);
- if (isHistory)
- {
- if (tempStoreID == match.EventMatchID)
- {
- CockMatch.Instance.match.MeronTotalBets = match.GetAllPlayersMeronBet();
- CockMatch.Instance.match.WalaTotalBets = match.GetAllPlayersWalaBet();
- isHistory = false;
- }
- }
- else if (MenuManager.Instance.PageMng.model.mState == MenuState.BetMatchesMenu ||
- MenuManager.Instance.PageMng.model.mState == MenuState.MatchMenu ||
- MenuManager.Instance.PageMng.model.mState == MenuState.InspectMenu)
- {
- //if from match menu, update value and display
- if (!MenuManager.Instance.MatchMng.model.fromOGB)
- {
- for (int i = 0; i < ActiveMatches.Count; i++)
- {
- ////Debug.Log(match.ToJson(true));
- ////Debug.Log(i + " : " + match.DisplayMatchUpdate());
- if (ActiveMatches[i].MatchID == match.EventMatchID)
- {
- ActiveMatches[i].MeronOdds = (int) (match.GetMeronOdds() * 100);
- ActiveMatches[i].WalaOdds = (int) (match.GetWalaOdds() * 100);
- ActiveMatches[i].MeronTotalBets = match.GetAllPlayersMeronBet();
- ActiveMatches[i].WalaTotalBets = match.GetAllPlayersWalaBet();
- if (AccountManager.Instance.AccountID == match.AccountID)
- {
- ActiveMatches[i].MeronBetAmount = match.GetPlayerMeronBet();
- ActiveMatches[i].WalaBetAmount = match.GetPlayerWalaBet();
- }
- ActiveMatches[i].MeronNetPayout = match.GetPlayerPayoutMeron();
- ActiveMatches[i].WalaNetPayout = match.GetPlayerPayoutWala();
- ActiveMatches[i].isMeronBet = ActiveMatches[i].MeronBetAmount > 0;
- ActiveMatches[i].isWalaBet = ActiveMatches[i].WalaBetAmount > 0;
- }
- if (i == (ActiveMatches.Count - 1))
- {
- MenuManager.Instance.MatchMng.controller.UpdateMatches(ActiveMatches);
- break;
- }
- }
- }
- //if from ongoing bets, update and display values
- else if (MenuManager.Instance.MatchMng.model.fromOGB)
- {
- for (int i = 0; i < OnGoingBets.Count; i++)
- {
- if (OnGoingBets[i].MatchID == match.EventMatchID)
- {
- // //Debug.Log(match.ToString());
- ////Debug.Log("OGB Match : " + match.DisplayMatchUpdate());
- OnGoingBets[i].MeronOdds = (int) (match.GetMeronOdds() * 100);
- OnGoingBets[i].WalaOdds = (int) (match.GetWalaOdds() * 100);
- OnGoingBets[i].MeronTotalBets = match.GetAllPlayersMeronBet();
- OnGoingBets[i].WalaTotalBets = match.GetAllPlayersWalaBet();
- if (AccountManager.Instance.AccountID == match.AccountID)
- {
- OnGoingBets[i].MeronBetAmount = match.GetPlayerMeronBet();
- OnGoingBets[i].WalaBetAmount = match.GetPlayerWalaBet();
- }
- OnGoingBets[i].MeronNetPayout = match.GetPlayerPayoutMeron();
- OnGoingBets[i].WalaNetPayout = match.GetPlayerPayoutWala();
- OnGoingBets[i].isMeronBet = OnGoingBets[i].MeronBetAmount > 0;
- OnGoingBets[i].isWalaBet = OnGoingBets[i].WalaBetAmount > 0;
- MenuManager.Instance.BetMatchesMng.controller.UpdateOGBInfo(OnGoingBets);
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement