DealQueue.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. [Serializable]
  6. public class DealQueue
  7. {
  8. public DealQueue.CardAnimeData nCardAnimData
  9. {
  10. get
  11. {
  12. if (this.m_CardAnimeDic.ContainsKey(BjMotionControl.Instance.nMotionName))
  13. {
  14. return this.m_CardAnimeDic[BjMotionControl.Instance.nMotionName];
  15. }
  16. return null;
  17. }
  18. }
  19. public void Init()
  20. {
  21. string text = "cardanime_data.nei";
  22. if (!GameUty.FileSystem.IsExistentFile(text))
  23. {
  24. NDebug.Assert("表がありません。" + text, false);
  25. }
  26. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  27. {
  28. using (CsvParser csvParser = new CsvParser())
  29. {
  30. bool condition = csvParser.Open(afileBase);
  31. NDebug.Assert(condition, text + "\nopen failed.");
  32. for (int i = 1; i < csvParser.max_cell_y; i++)
  33. {
  34. if (csvParser.IsCellToExistData(0, i))
  35. {
  36. string cellAsString = csvParser.GetCellAsString(0, i);
  37. for (int j = 0; j < csvParser.max_cell_x; j++)
  38. {
  39. switch (j)
  40. {
  41. case 0:
  42. this.m_CardAnimeDic.Add(cellAsString, new DealQueue.CardAnimeData());
  43. this.m_CardAnimeDic[cellAsString].MotionName = cellAsString;
  44. break;
  45. case 1:
  46. this.m_CardAnimeDic[cellAsString].StartTime = (from ch in csvParser.GetCellAsString(j, i).Split(new char[]
  47. {
  48. '\n'
  49. })
  50. select GameUty.MillisecondToSecond(int.Parse(ch))).ToList<float>();
  51. break;
  52. case 2:
  53. this.m_CardAnimeDic[cellAsString].CardSetTime = (from ch in csvParser.GetCellAsString(j, i).Split(new char[]
  54. {
  55. '\n'
  56. })
  57. select GameUty.MillisecondToSecond(int.Parse(ch))).ToList<float>();
  58. break;
  59. case 3:
  60. if (csvParser.IsCellToExistData(j, i))
  61. {
  62. this.m_CardAnimeDic[cellAsString].SwitchTime = (from ch in csvParser.GetCellAsString(j, i).Split(new char[]
  63. {
  64. '\n'
  65. })
  66. select GameUty.MillisecondToSecond(int.Parse(ch))).ToList<float>();
  67. }
  68. break;
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
  76. private Card GetCard(GameObject card_obj)
  77. {
  78. if (!this.m_CardobjPair.ContainsKey(card_obj))
  79. {
  80. Card component = card_obj.GetComponent<Card>();
  81. NDebug.Assert(component, string.Format("オブジェクト:{0}にCardコンポーネントが付いてません", card_obj.name));
  82. this.m_CardobjPair.Add(card_obj, component);
  83. }
  84. return this.m_CardobjPair[card_obj];
  85. }
  86. public void DealCard(GameObject card)
  87. {
  88. if (this.m_ProcessList.Any((GameObject obj) => !obj))
  89. {
  90. this.m_ProcessList.Clear();
  91. }
  92. this.Queue(card);
  93. if (this.m_ProcessList.Count == 1)
  94. {
  95. this.ProcessNow(card);
  96. }
  97. }
  98. private void ProcessNow(GameObject card)
  99. {
  100. card.SetActive(true);
  101. this.CardMove(card);
  102. }
  103. private void Queue(GameObject card)
  104. {
  105. if (this.nCardAnimData != null)
  106. {
  107. int value = (!BjPlayer.Instance.IsturnEnd) ? this.m_ProcessList.Count : (Dealer.Instance.CardNum - 3);
  108. Card card2 = this.GetCard(card);
  109. card2.StartTime = this.nCardAnimData.StartTime[Mathf.Clamp(value, 0, this.nCardAnimData.StartTime.Count - 1)];
  110. card2.CardSetTime = this.nCardAnimData.CardSetTime[Mathf.Clamp(value, 0, this.nCardAnimData.CardSetTime.Count - 1)];
  111. if (this.nCardAnimData.SwitchTime.Count > 0)
  112. {
  113. card2.SwitchTime = this.nCardAnimData.SwitchTime[Mathf.Clamp(value, 0, this.nCardAnimData.SwitchTime.Count - 1)];
  114. }
  115. }
  116. this.m_ProcessList.Add(card);
  117. }
  118. public void CardOpen(GameObject cardGameObject)
  119. {
  120. Card card = this.GetCard(cardGameObject);
  121. card.InitTime = this.CardTimer;
  122. this.DealCard(cardGameObject);
  123. card.Open(new Card.FinishedOpen(this.OnFinishedMoving));
  124. }
  125. private void CardMove(GameObject cardGameobject)
  126. {
  127. Card card = this.GetCard(cardGameobject);
  128. if (card.IsMoveend)
  129. {
  130. return;
  131. }
  132. card.InitTime = this.CardTimer;
  133. card.MoveToPosition(new Card.FinishedMoving(this.OnFinishedMoving));
  134. }
  135. private void OnFinishedMoving(GameObject card)
  136. {
  137. this.DistributeCard();
  138. }
  139. public void DistributeCard()
  140. {
  141. if (this.m_ProcessList.Count > 0)
  142. {
  143. this.m_ProcessList.RemoveAt(0);
  144. }
  145. if (this.m_ProcessList.Count > 0)
  146. {
  147. this.ProcessNow(this.m_ProcessList[0]);
  148. }
  149. else
  150. {
  151. this.CardTimer = 0f;
  152. this.m_CardobjPair.Clear();
  153. }
  154. }
  155. public List<GameObject> m_ProcessList = new List<GameObject>();
  156. private Dictionary<string, DealQueue.CardAnimeData> m_CardAnimeDic = new Dictionary<string, DealQueue.CardAnimeData>();
  157. public float CardTimer;
  158. private Dictionary<GameObject, Card> m_CardobjPair = new Dictionary<GameObject, Card>();
  159. public class CardAnimeData
  160. {
  161. public string MotionName = string.Empty;
  162. public List<float> StartTime = new List<float>();
  163. public List<float> CardSetTime = new List<float>();
  164. public List<float> SwitchTime = new List<float>();
  165. }
  166. }