SelectJogressEffect.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using System.Linq;
  6. public class SelectJogressEffect : MonoBehaviour
  7. {
  8. public void SetUp_SelectWheterToJogress
  9. (CardSource card,
  10. CardSource evoRoot,
  11. bool canNoSelect,
  12. Func<IEnumerator> endSelectCoroutine_Digivolve,
  13. Func<IEnumerator> endSelectCoroutine_Jogress,
  14. Func<IEnumerator> noSelectCoroutine)
  15. {
  16. _card = card;
  17. _evoRoot = evoRoot;
  18. _canNoSelect = canNoSelect;
  19. _endSelectCoroutine_Digivolve = endSelectCoroutine_Digivolve;
  20. _endSelectCoroutine_Jogress = endSelectCoroutine_Jogress;
  21. _noSelectCoroutine = noSelectCoroutine;
  22. }
  23. public void SetUp_SelectDigivolutionRoots
  24. (CardSource card,
  25. bool isLocal,
  26. bool isPayCost,
  27. bool canNoSelect,
  28. Func<List<Permanent>, IEnumerator> endSelectCoroutine_SelectDigivolutionRoots,
  29. Func<IEnumerator> noSelectCoroutine)
  30. {
  31. _card = card;
  32. _isLocal = isLocal;
  33. _isPayCost = isPayCost;
  34. _canNoSelect = canNoSelect;
  35. _endSelectCoroutine_SelectDigivolutionRoots = endSelectCoroutine_SelectDigivolutionRoots;
  36. _noSelectCoroutine = noSelectCoroutine;
  37. _customPermanentConditions = null;
  38. }
  39. public void SetUpCustomPermanentConditions(Func<Permanent, bool>[] customPermanentConditions)
  40. {
  41. _customPermanentConditions = customPermanentConditions.CloneArray();
  42. }
  43. CardSource _card = null;
  44. CardSource _evoRoot = null;
  45. bool _isLocal = false;
  46. bool _isPayCost = false;
  47. bool _canNoSelect = false;
  48. Func<IEnumerator> _endSelectCoroutine_Digivolve = null;
  49. Func<IEnumerator> _endSelectCoroutine_Jogress = null;
  50. Func<List<Permanent>, IEnumerator> _endSelectCoroutine_SelectDigivolutionRoots = null;
  51. Func<IEnumerator> _noSelectCoroutine = null;
  52. Func<Permanent, bool>[] _customPermanentConditions = null;
  53. public IEnumerator SelectWheterToJogress()
  54. {
  55. if (_card != null)
  56. {
  57. if (_evoRoot != null)
  58. {
  59. CardSource anotherEvoRootCard = null;
  60. List<Permanent> anotherEvoRootPermanentCandidates = new List<Permanent>();
  61. foreach (Permanent permanent in _card.Owner.GetBattleAreaDigimons())
  62. {
  63. if (permanent != _evoRoot.PermanentOfThisCard())
  64. {
  65. if (_card.CanJogressFromTargetPermanent(permanent, false))
  66. {
  67. if (_card.CanJogressFromTargetPermanents(new List<Permanent>() { _evoRoot.PermanentOfThisCard(), permanent }, false))
  68. {
  69. if (anotherEvoRootPermanentCandidates.Count((permanent1) => permanent1.TopCard.CardID == permanent.TopCard.CardID) == 0)
  70. {
  71. anotherEvoRootPermanentCandidates.Add(permanent);
  72. }
  73. }
  74. }
  75. }
  76. }
  77. if (anotherEvoRootPermanentCandidates.Count == 1)
  78. {
  79. anotherEvoRootCard = anotherEvoRootPermanentCandidates[0].TopCard;
  80. }
  81. yield return StartCoroutine(GManager.instance.selectCardPanel.OpenSelectCardPanel(
  82. Message: "With which method would you like to Digivolve?",
  83. RootCardSources: new List<CardSource>() { _card, _card },
  84. _CanTargetCondition: (cardSource) => true,
  85. _CanTargetCondition_ByPreSelecetedList: null,
  86. _CanEndSelectCondition: null,
  87. _MaxCount: 1,
  88. _CanEndNotMax: false,
  89. _CanNoSelect: () => _canNoSelect,
  90. CanLookReverseCard: true,
  91. skillInfos: null,
  92. root: SelectCardEffect.Root.None,
  93. isCenter: true,
  94. evoRootsArray: new CardSource[][] { new CardSource[] { _evoRoot }, new CardSource[] { _evoRoot, anotherEvoRootCard } },
  95. titleStrings: new List<string>() { "Normal Digivolution", "<color=#FF633E>DNA</color> Digivollution" }));
  96. if (GManager.instance.selectCardPanel.SelectedIndex.Count > 0)
  97. {
  98. int index = GManager.instance.selectCardPanel.SelectedIndex[0];
  99. switch (index)
  100. {
  101. case 0:
  102. if (_endSelectCoroutine_Digivolve != null)
  103. {
  104. yield return ContinuousController.instance.StartCoroutine(_endSelectCoroutine_Digivolve());
  105. }
  106. break;
  107. case 1:
  108. if (_endSelectCoroutine_Jogress != null)
  109. {
  110. yield return ContinuousController.instance.StartCoroutine(_endSelectCoroutine_Jogress());
  111. }
  112. break;
  113. }
  114. }
  115. else
  116. {
  117. if (_noSelectCoroutine != null)
  118. {
  119. yield return ContinuousController.instance.StartCoroutine(_noSelectCoroutine());
  120. }
  121. }
  122. }
  123. }
  124. }
  125. public IEnumerator SelectDigivolutionRoots()
  126. {
  127. bool active = false;
  128. SelectPermanentEffect selectPermanentEffect = null;
  129. if (_card != null)
  130. {
  131. if (_card.CanPlayJogress(_isPayCost))
  132. {
  133. if (_card.jogressCondition != null)
  134. {
  135. if (_card.jogressCondition.elements != null)
  136. {
  137. if (_card.jogressCondition.elements.Length == 2)
  138. {
  139. if (GManager.instance != null)
  140. {
  141. if (GManager.instance.turnStateMachine != null)
  142. {
  143. if (GManager.instance.turnStateMachine.gameContext != null)
  144. {
  145. if (GManager.instance.turnStateMachine.gameContext.ActiveCardList.Count >= 1)
  146. {
  147. selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  148. if (selectPermanentEffect != null)
  149. {
  150. active = true;
  151. }
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. if (active)
  162. {
  163. List<Permanent> selectedEvoRoots = new List<Permanent>();
  164. for (int i = 0; i < _card.jogressCondition.elements.Length; i++)
  165. {
  166. JogressConditionElement element = _card.jogressCondition.elements[i];
  167. bool CanSelectPermanentCondition(Permanent permanent)
  168. {
  169. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, _card))
  170. {
  171. if (!selectedEvoRoots.Contains(permanent))
  172. {
  173. if (element.EvoRootCondition != null)
  174. {
  175. if (element.EvoRootCondition(permanent))
  176. {
  177. if (_customPermanentConditions != null)
  178. {
  179. if (_customPermanentConditions.Length == 1)
  180. {
  181. if (_customPermanentConditions[0] != null)
  182. {
  183. if (_card.Owner.GetBattleAreaDigimons().Count(_customPermanentConditions[0]) >= 1)
  184. {
  185. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 0)
  186. {
  187. if (!_customPermanentConditions[0](permanent))
  188. {
  189. if (i == 1)
  190. {
  191. return false;
  192. }
  193. else
  194. {
  195. JogressConditionElement element1 = _card.jogressCondition.elements[1];
  196. if (_card.Owner.GetBattleAreaDigimons().Count((permanent1) => permanent1 != permanent && element1.EvoRootCondition(permanent1) && _customPermanentConditions[0](permanent1)) == 0)
  197. {
  198. return false;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. else
  205. {
  206. return false;
  207. }
  208. }
  209. }
  210. else if (_customPermanentConditions.Length == 2)
  211. {
  212. if (_customPermanentConditions[0] != null && _customPermanentConditions[1] != null)
  213. {
  214. if (_card.Owner.GetBattleAreaDigimons().Count(_customPermanentConditions[0]) >= 1 && _card.Owner.GetBattleAreaDigimons().Count(_customPermanentConditions[1]) >= 1)
  215. {
  216. if (i == 1)
  217. {
  218. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 0 && selectedEvoRoots.Count(_customPermanentConditions[1]) == 0)
  219. {
  220. return false;
  221. }
  222. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 0 && selectedEvoRoots.Count(_customPermanentConditions[1]) == 1)
  223. {
  224. if (!_customPermanentConditions[0](permanent))
  225. {
  226. return false;
  227. }
  228. }
  229. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 1 && selectedEvoRoots.Count(_customPermanentConditions[1]) == 0)
  230. {
  231. if (!_customPermanentConditions[1](permanent))
  232. {
  233. return false;
  234. }
  235. }
  236. }
  237. else
  238. {
  239. if (_customPermanentConditions[0](permanent) || _customPermanentConditions[1](permanent))
  240. {
  241. JogressConditionElement element1 = _card.jogressCondition.elements[1];
  242. if (_customPermanentConditions[0](permanent))
  243. {
  244. if (_card.Owner.GetBattleAreaDigimons().Count((permanent1) => permanent1 != permanent && element1.EvoRootCondition(permanent1) && _customPermanentConditions[1](permanent1)) == 0)
  245. {
  246. return false;
  247. }
  248. }
  249. if (_customPermanentConditions[1](permanent))
  250. {
  251. if (_card.Owner.GetBattleAreaDigimons().Count((permanent1) => permanent1 != permanent && element1.EvoRootCondition(permanent1) && _customPermanentConditions[0](permanent1)) == 0)
  252. {
  253. return false;
  254. }
  255. }
  256. }
  257. else
  258. {
  259. return false;
  260. }
  261. }
  262. }
  263. else
  264. {
  265. return false;
  266. }
  267. }
  268. }
  269. }
  270. if (i == 0)
  271. {
  272. List<Permanent> nextCandidates = _card.Owner.GetBattleAreaDigimons()
  273. .Filter(permanent1 => permanent1 != permanent);
  274. if (nextCandidates.Count(_card.jogressCondition.elements[1].EvoRootCondition) == 0)
  275. {
  276. return false;
  277. }
  278. }
  279. return true;
  280. }
  281. }
  282. }
  283. }
  284. return false;
  285. }
  286. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  287. Permanent selectedPermanent = null;
  288. if (maxCount >= 1)
  289. {
  290. selectPermanentEffect.SetUp(
  291. selectPlayer: _card.Owner,
  292. canTargetCondition: CanSelectPermanentCondition,
  293. canTargetCondition_ByPreSelecetedList: null,
  294. canEndSelectCondition: null,
  295. maxCount: maxCount,
  296. canNoSelect: _canNoSelect,
  297. canEndNotMax: false,
  298. selectPermanentCoroutine: SelectPermanentCoroutine,
  299. afterSelectPermanentCoroutine: null,
  300. mode: SelectPermanentEffect.Mode.Custom,
  301. cardEffect: null);
  302. selectPermanentEffect.SetUpCustomMessage($"Select {element.SelectMessage}.", $"The opponent is selecting {element.SelectMessage}.");
  303. if (this._isLocal)
  304. {
  305. selectPermanentEffect.SetIsLocal();
  306. }
  307. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  308. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  309. {
  310. selectedPermanent = permanent;
  311. yield return null;
  312. }
  313. }
  314. if (selectedPermanent == null)
  315. {
  316. break;
  317. }
  318. else
  319. {
  320. selectedEvoRoots.Add(selectedPermanent);
  321. foreach (Permanent permanent in selectedEvoRoots)
  322. {
  323. permanent.ShowingPermanentCard.SetPermanentIndexText(selectedEvoRoots);
  324. }
  325. }
  326. }
  327. //do not jogress
  328. if (selectedEvoRoots.Count != _card.jogressCondition.elements.Length)
  329. {
  330. if (_noSelectCoroutine != null)
  331. {
  332. yield return ContinuousController.instance.StartCoroutine(_noSelectCoroutine());
  333. }
  334. }
  335. //do jogress
  336. else
  337. {
  338. if (_endSelectCoroutine_SelectDigivolutionRoots != null)
  339. {
  340. yield return ContinuousController.instance.StartCoroutine(_endSelectCoroutine_SelectDigivolutionRoots(selectedEvoRoots));
  341. }
  342. }
  343. foreach (Permanent permanent in _card.Owner.GetBattleAreaDigimons())
  344. {
  345. if (permanent != null)
  346. {
  347. if (permanent.ShowingPermanentCard != null)
  348. {
  349. permanent.ShowingPermanentCard.OffPermanentIndexText();
  350. }
  351. }
  352. }
  353. }
  354. }
  355. }