Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.14 KB | None | 0 0
  1. using SabongClassification;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEssentials;
  6.  
  7. public class PushMatches : Singleton<PushMatches> {
  8.  
  9.     public List<SocketIOMatch> CurrentMatches;
  10.     public List<MatchSelector> ActiveMatches;
  11.     public List<MatchSelector> OnGoingBets;
  12.     public List<GameObject> ActiveMatchesGO;
  13.     public MatchSelector HistoryMatch;
  14.  
  15.     string tempStoreID;
  16.     int j = 0;
  17.     int endIndex;
  18.  
  19.     bool isInitialize;
  20.     bool isLazyLoad;
  21.     bool isHistory;
  22.  
  23.     public BetMatchesSelector current;
  24.     List<BetMatchesSelector> MatchesWithBets;
  25.  
  26.     private void Start()
  27.     {
  28.         //subscribe to betting socket
  29.         NetManager.Instance.SocketHandler.OnMatchUpdateEvent += SocketPush;
  30.     }
  31.  
  32.     //remove currently subscribe to socket
  33.     public void RemoveAllCurrentMatches()
  34.     {
  35.         j = 0;
  36.         endIndex = 0;
  37.         CurrentMatches.Clear();
  38.         ActiveMatches.Clear();
  39.         ActiveMatchesGO.Clear();
  40.         HistoryMatch.MeronBetAmount = 0;
  41.         HistoryMatch.WalaBetAmount = 0;
  42.         HistoryMatch.MeronTotalBets = 0;
  43.         HistoryMatch.WalaTotalBets = 0;
  44.     }
  45.  
  46.     //remove subscribed
  47.     public void ResetMatches()
  48.     {
  49.         if (ActiveMatchesGO.Count > 0)
  50.         {
  51.             if (MenuManager.Instance.PageMng.model.mState == MenuState.MatchMenu)
  52.             {
  53.                 for (int i = 0; i < ActiveMatchesGO.Count; i++)
  54.                 {
  55.                     ActiveMatchesGO[i].GetComponent<MatchInfo>().isJoined = true;
  56.                 }
  57.  
  58.                 RemoveAllCurrentMatches();
  59.             }
  60.             else
  61.             {
  62.                 //Other Page
  63.             }
  64.         }
  65.         //else
  66.         //    MenuController.Instance.ArenaMapMenu();
  67.     }
  68.  
  69.     //Join Match to socket
  70.     public void JoinMatch(GameObject CurrentActive, MatchSelector thisMatch, string MatchID, string EventID, string EventName, string CategoryID,
  71.         int MinAmount, int MaxAmount, string MatchNo, string MatchName, string MeronID, string WalaID, string MeronBreed, string WalaBreed,
  72.         string StartDate, string MatchStart, string Duration, string WinnerID, string CreatedDate, string ModifiedDate)
  73.     {
  74.         isHistory = false;
  75.         MenuManager.Instance.MatchMng.view.go_ExpandLoader.SetActive(true);
  76.  
  77.         NetManager.Instance.SocketHandler.EmitJoinMatch(MatchID, EventID, EventName, CategoryID, MinAmount, MaxAmount, MatchNo, MatchName,
  78.                     MeronID, WalaID, MeronBreed, WalaBreed, StartDate, MatchStart, Duration, WinnerID, CreatedDate, ModifiedDate,
  79.                         true, false, false,
  80.                         (b, s) =>
  81.                         {
  82.                             //Debug.LogFormat("Success: {0}\nError Message: {1}", b, s);
  83.  
  84.                             UnityMainThreadDispatcher.Instance().Enqueue(() =>
  85.                             {
  86.                                 if (b)
  87.                                 {
  88.                                     StartCoroutine(AddToJoined(CurrentActive, MatchID, thisMatch));
  89.                                 }
  90.                                 else
  91.                                 {
  92.                                     MenuManager.Instance.MatchMng.view.go_ExpandLoader.SetActive(false);
  93.                                     MenuManager.Instance.view.OpenPopUp("Unable to Join Match!");
  94.                                 }
  95.  
  96.                             });
  97.                         },
  98.                         SocketPush);
  99.  
  100.         StartCoroutine(MenuManager.Instance.MatchMng.controller.LongLoad(true));
  101.     }
  102.  
  103.     //Wait to successfully joined before joining next match
  104.     IEnumerator AddToJoined(GameObject go, string MatchID, MatchSelector match)
  105.     {
  106.         //yield return new WaitUntil(() => NetManager.Instance.SocketHandler != null && NetManager.Instance.SocketHandler.CurrentMatch != null
  107.         //      && NetManager.Instance.SocketHandler.CurrentMatch.EventMatchID != null && NetManager.Instance.SocketHandler.CurrentMatch.EventMatchID != string.Empty
  108.         //      && NetManager.Instance.SocketHandler.CurrentMatch.EventMatchID == MatchID);
  109.  
  110.         yield return new WaitUntil(() => NetManager.Instance.SocketHandler.CurrentMatch.EventMatchID == MatchID);
  111.  
  112.         MenuManager.Instance.MatchMng.model.notYetLoaded = true;
  113.  
  114.         ActiveMatches.Add(match);
  115.         CurrentMatches.Add(match.ToSocketIOMatch());
  116.         ActiveMatchesGO.Add(go);
  117.  
  118.         if (go != null)
  119.             go.GetComponent<MatchInfo>().isJoined = true;
  120.  
  121.         yield return new WaitForSeconds(0.5f);
  122.         NetManager.Instance.SocketHandler.EmitGetPayout(MatchID);
  123.         MenuManager.Instance.MatchMng.view.go_ExpandLoader.SetActive(false);
  124.     }
  125.  
  126.     //join match in ongoing menu
  127.     public void JoinOngoingBets()
  128.     {
  129.         if (MenuManager.Instance.PageMng.model.mState == MenuState.BetMatchesMenu)
  130.         {
  131.             isHistory = false;
  132.  
  133.             if (!OnGoingBets[j].isRewardClaim)
  134.             {
  135.                 NetManager.Instance.SocketHandler.EmitJoinMatch(OnGoingBets[j].MatchID, OnGoingBets[j].EventID,
  136.                                current.eventName, current.category, current.arenaMin, current.arenaMax,
  137.                                OnGoingBets[j].MatchNumber, OnGoingBets[j].Name,
  138.                                OnGoingBets[j].MeronID, OnGoingBets[j].WalaID, OnGoingBets[j].MeronBreed, OnGoingBets[j].WalaBreed,
  139.                                OnGoingBets[j].StartDate.ToString(), OnGoingBets[j].MatchStart.ToString(),
  140.                                OnGoingBets[j].Duration,
  141.                                OnGoingBets[j].WinnerSide,
  142.                                OnGoingBets[j].DateCreated, OnGoingBets[j].DateModified,
  143.                                true, false, false,
  144.                                (b, s) =>
  145.                                {
  146.                                    //Debug.LogFormat("Success: {0}\nError Message: {1}", b, s);
  147.  
  148.                                    UnityMainThreadDispatcher.Instance().Enqueue(() =>
  149.                                    {
  150.                                        if (b)
  151.                                        {
  152.                                            NetManager.Instance.SocketHandler.EmitGetPayout(OnGoingBets[j].MatchID);
  153.                                            StartCoroutine(AddToBetsJoined(OnGoingBets[j].MatchID));
  154.                                        }
  155.                                        else
  156.                                        {
  157.                                            MenuManager.Instance.view.OpenPopUp("Unable to Join Match!");
  158.                                        }
  159.  
  160.                                    });
  161.                                },
  162.                                SocketPush);
  163.             }
  164.             else
  165.             {
  166.                 if (!OnGoingBets[j].isMeronBet && !OnGoingBets[j].isWalaBet)
  167.                     NetManager.Instance.SocketHandler.EmitGetPayout(OnGoingBets[j].MatchID);
  168.  
  169.                 StartCoroutine(AddToBetsJoined(OnGoingBets[j].MatchID));
  170.             }
  171.         }
  172.     }
  173.  
  174.     //wait to successfully join in ongoing menu before joining next match
  175.     IEnumerator AddToBetsJoined(string MatchID)
  176.     {
  177.         if (!OnGoingBets[j].isRewardClaim)
  178.             yield return new WaitUntil(() => NetManager.Instance.SocketHandler.CurrentMatch.EventMatchID == MatchID);
  179.         else
  180.             yield return new WaitForSeconds(0.3f);
  181.  
  182.         CurrentMatches.Add(OnGoingBets[j].ToSocketIOMatch());
  183.         j++;
  184.  
  185.         if (j < OnGoingBets.Count)
  186.             JoinOngoingBets();
  187.         //else
  188.             //Debug.Log("Finished");
  189.     }
  190.  
  191.     //Get final bet and display
  192.     public void FinalBets(string MatchID, bool history)
  193.     {
  194.         ////Debug.Log("Fetch Final Bets!");
  195.         isHistory = history;
  196.         NetManager.Instance.SocketHandler.EmitGetPayout(MatchID);
  197.         tempStoreID = MatchID;
  198.     }
  199.  
  200.     //BROADCAST MATCHES from Betting socket
  201.     void SocketPush(SocketIOMatchUpdate match)
  202.     {
  203.         //Debug.Log("push");
  204.         //Debug.Log("Push Socket! " + match.ToJson(true));
  205.         //MenuController.Instance.Matchs.go_ExpandLoader.SetActive(true);
  206.  
  207.         if (isHistory)
  208.         {
  209.             if (tempStoreID == match.EventMatchID)
  210.             {
  211.                 CockMatch.Instance.match.MeronTotalBets = match.GetAllPlayersMeronBet();
  212.                 CockMatch.Instance.match.WalaTotalBets = match.GetAllPlayersWalaBet();
  213.                 isHistory = false;
  214.             }
  215.         }
  216.         else if (MenuManager.Instance.PageMng.model.mState == MenuState.BetMatchesMenu ||
  217.             MenuManager.Instance.PageMng.model.mState == MenuState.MatchMenu ||
  218.             MenuManager.Instance.PageMng.model.mState == MenuState.InspectMenu)
  219.         {
  220.             //if from match menu, update value and display
  221.             if (!MenuManager.Instance.MatchMng.model.fromOGB)
  222.             {
  223.                 for (int i = 0; i < ActiveMatches.Count; i++)
  224.                 {
  225.                     ////Debug.Log(match.ToJson(true));
  226.                     ////Debug.Log(i + " : " + match.DisplayMatchUpdate());
  227.  
  228.                     if (ActiveMatches[i].MatchID == match.EventMatchID)
  229.                     {
  230.                         ActiveMatches[i].MeronOdds = (int) (match.GetMeronOdds() * 100);
  231.                         ActiveMatches[i].WalaOdds = (int) (match.GetWalaOdds() * 100);
  232.                         ActiveMatches[i].MeronTotalBets = match.GetAllPlayersMeronBet();
  233.                         ActiveMatches[i].WalaTotalBets = match.GetAllPlayersWalaBet();
  234.  
  235.                         if (AccountManager.Instance.AccountID == match.AccountID)
  236.                         {
  237.                             ActiveMatches[i].MeronBetAmount = match.GetPlayerMeronBet();
  238.                             ActiveMatches[i].WalaBetAmount = match.GetPlayerWalaBet();
  239.                         }
  240.  
  241.                         ActiveMatches[i].MeronNetPayout = match.GetPlayerPayoutMeron();
  242.                         ActiveMatches[i].WalaNetPayout = match.GetPlayerPayoutWala();
  243.                         ActiveMatches[i].isMeronBet = ActiveMatches[i].MeronBetAmount > 0;
  244.                         ActiveMatches[i].isWalaBet = ActiveMatches[i].WalaBetAmount > 0;
  245.                     }
  246.  
  247.                     if (i == (ActiveMatches.Count - 1))
  248.                     {
  249.                         MenuManager.Instance.MatchMng.controller.UpdateMatches(ActiveMatches);
  250.                         break;
  251.                     }
  252.                 }
  253.             }
  254.             //if from ongoing bets, update and display values
  255.             else if (MenuManager.Instance.MatchMng.model.fromOGB)
  256.             {
  257.                 for (int i = 0; i < OnGoingBets.Count; i++)
  258.                 {
  259.                     if (OnGoingBets[i].MatchID == match.EventMatchID)
  260.                     {
  261.                         // //Debug.Log(match.ToString());
  262.                         ////Debug.Log("OGB Match : " + match.DisplayMatchUpdate());
  263.  
  264.                         OnGoingBets[i].MeronOdds = (int) (match.GetMeronOdds() * 100);
  265.                         OnGoingBets[i].WalaOdds = (int) (match.GetWalaOdds() * 100);
  266.                         OnGoingBets[i].MeronTotalBets = match.GetAllPlayersMeronBet();
  267.                         OnGoingBets[i].WalaTotalBets = match.GetAllPlayersWalaBet();
  268.  
  269.                         if (AccountManager.Instance.AccountID == match.AccountID)
  270.                         {
  271.                             OnGoingBets[i].MeronBetAmount = match.GetPlayerMeronBet();
  272.                             OnGoingBets[i].WalaBetAmount = match.GetPlayerWalaBet();
  273.                         }
  274.  
  275.                         OnGoingBets[i].MeronNetPayout = match.GetPlayerPayoutMeron();
  276.                         OnGoingBets[i].WalaNetPayout = match.GetPlayerPayoutWala();
  277.                         OnGoingBets[i].isMeronBet = OnGoingBets[i].MeronBetAmount > 0;
  278.                         OnGoingBets[i].isWalaBet = OnGoingBets[i].WalaBetAmount > 0;
  279.  
  280.                         MenuManager.Instance.BetMatchesMng.controller.UpdateOGBInfo(OnGoingBets);
  281.                         break;
  282.                     }
  283.                 }
  284.             }
  285.         }
  286.     }
  287.  
  288.  
  289.  
  290.  
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement