SelectJogressEffect.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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.Count > 0)
  134. {
  135. foreach (JogressCondition dnaCondition in _card.jogressCondition)
  136. {
  137. if(dnaCondition != null)
  138. {
  139. if(dnaCondition.elements.Length == 2)
  140. {
  141. if (GManager.instance != null)
  142. {
  143. if (GManager.instance.turnStateMachine != null)
  144. {
  145. if (GManager.instance.turnStateMachine.gameContext != null)
  146. {
  147. if (GManager.instance.turnStateMachine.gameContext.ActiveCardList.Count >= 1)
  148. {
  149. selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  150. if (selectPermanentEffect != null)
  151. {
  152. active = true;
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. if (active)
  165. {
  166. List<Permanent> selectedEvoRoots = new List<Permanent>();
  167. JogressCondition selectedDNA = _card.jogressCondition[0];
  168. if (_card.jogressCondition.Count > 1)
  169. {
  170. #region select DNA condition
  171. SelectDNACondition selectDNACondition = GManager.instance.GetComponent<SelectDNACondition>();
  172. selectDNACondition.SetUp(_card.Owner, _card, SelectDNA);
  173. yield return ContinuousController.instance.StartCoroutine(selectDNACondition.Activate());
  174. IEnumerator SelectDNA(int dnaSelection)
  175. {
  176. selectedDNA = _card.jogressCondition[dnaSelection];
  177. yield return null;
  178. }
  179. #endregion
  180. }
  181. for (int i = 0; i < selectedDNA.elements.Length; i++)
  182. {
  183. JogressConditionElement element = selectedDNA.elements[i];
  184. bool CanSelectPermanentCondition(Permanent permanent)
  185. {
  186. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, _card))
  187. {
  188. if (!selectedEvoRoots.Contains(permanent))
  189. {
  190. if (element.EvoRootCondition != null)
  191. {
  192. if (element.EvoRootCondition(permanent))
  193. {
  194. if (_customPermanentConditions != null)
  195. {
  196. if (_customPermanentConditions.Length == 1)
  197. {
  198. if (_customPermanentConditions[0] != null)
  199. {
  200. if (_card.Owner.GetBattleAreaDigimons().Count(_customPermanentConditions[0]) >= 1)
  201. {
  202. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 0)
  203. {
  204. if (!_customPermanentConditions[0](permanent))
  205. {
  206. if (i == 1)
  207. {
  208. return false;
  209. }
  210. else
  211. {
  212. JogressConditionElement element1 = selectedDNA.elements[1];
  213. if (_card.Owner.GetBattleAreaDigimons().Count((permanent1) => permanent1 != permanent && element1.EvoRootCondition(permanent1) && _customPermanentConditions[0](permanent1)) == 0)
  214. {
  215. return false;
  216. }
  217. }
  218. }
  219. }
  220. }
  221. else
  222. {
  223. return false;
  224. }
  225. }
  226. }
  227. else if (_customPermanentConditions.Length == 2)
  228. {
  229. if (_customPermanentConditions[0] != null && _customPermanentConditions[1] != null)
  230. {
  231. if (_card.Owner.GetBattleAreaDigimons().Count(_customPermanentConditions[0]) >= 1 && _card.Owner.GetBattleAreaDigimons().Count(_customPermanentConditions[1]) >= 1)
  232. {
  233. if (i == 1)
  234. {
  235. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 0 && selectedEvoRoots.Count(_customPermanentConditions[1]) == 0)
  236. {
  237. return false;
  238. }
  239. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 0 && selectedEvoRoots.Count(_customPermanentConditions[1]) == 1)
  240. {
  241. if (!_customPermanentConditions[0](permanent))
  242. {
  243. return false;
  244. }
  245. }
  246. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 1 && selectedEvoRoots.Count(_customPermanentConditions[1]) == 0)
  247. {
  248. if (!_customPermanentConditions[1](permanent))
  249. {
  250. return false;
  251. }
  252. }
  253. }
  254. else
  255. {
  256. if (_customPermanentConditions[0](permanent) || _customPermanentConditions[1](permanent))
  257. {
  258. JogressConditionElement element1 = selectedDNA.elements[1];
  259. if (_customPermanentConditions[0](permanent))
  260. {
  261. if (_card.Owner.GetBattleAreaDigimons().Count((permanent1) => permanent1 != permanent && element1.EvoRootCondition(permanent1) && _customPermanentConditions[1](permanent1)) == 0)
  262. {
  263. return false;
  264. }
  265. }
  266. if (_customPermanentConditions[1](permanent))
  267. {
  268. if (_card.Owner.GetBattleAreaDigimons().Count((permanent1) => permanent1 != permanent && element1.EvoRootCondition(permanent1) && _customPermanentConditions[0](permanent1)) == 0)
  269. {
  270. return false;
  271. }
  272. }
  273. }
  274. else
  275. {
  276. return false;
  277. }
  278. }
  279. }
  280. else
  281. {
  282. return false;
  283. }
  284. }
  285. }
  286. }
  287. if (i == 0)
  288. {
  289. List<Permanent> nextCandidates = _card.Owner.GetBattleAreaDigimons()
  290. .Filter(permanent1 => permanent1 != permanent);
  291. if (nextCandidates.Count(selectedDNA.elements[1].EvoRootCondition) == 0)
  292. {
  293. return false;
  294. }
  295. }
  296. return true;
  297. }
  298. }
  299. }
  300. }
  301. return false;
  302. }
  303. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  304. Permanent selectedPermanent = null;
  305. if (maxCount >= 1)
  306. {
  307. selectPermanentEffect.SetUp(
  308. selectPlayer: _card.Owner,
  309. canTargetCondition: CanSelectPermanentCondition,
  310. canTargetCondition_ByPreSelecetedList: null,
  311. canEndSelectCondition: null,
  312. maxCount: maxCount,
  313. canNoSelect: _canNoSelect,
  314. canEndNotMax: false,
  315. selectPermanentCoroutine: SelectPermanentCoroutine,
  316. afterSelectPermanentCoroutine: null,
  317. mode: SelectPermanentEffect.Mode.Custom,
  318. cardEffect: null);
  319. selectPermanentEffect.SetUpCustomMessage($"Select {element.SelectMessage}.", $"The opponent is selecting {element.SelectMessage}.");
  320. if (this._isLocal)
  321. {
  322. selectPermanentEffect.SetIsLocal();
  323. }
  324. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  325. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  326. {
  327. selectedPermanent = permanent;
  328. yield return null;
  329. }
  330. }
  331. if (selectedPermanent == null)
  332. {
  333. break;
  334. }
  335. else
  336. {
  337. selectedEvoRoots.Add(selectedPermanent);
  338. foreach (Permanent permanent in selectedEvoRoots)
  339. {
  340. permanent.ShowingPermanentCard.SetPermanentIndexText(selectedEvoRoots);
  341. }
  342. }
  343. }
  344. //do not jogress
  345. if (selectedEvoRoots.Count != selectedDNA.elements.Length)
  346. {
  347. if (_noSelectCoroutine != null)
  348. {
  349. yield return ContinuousController.instance.StartCoroutine(_noSelectCoroutine());
  350. }
  351. }
  352. //do jogress
  353. else
  354. {
  355. if (_endSelectCoroutine_SelectDigivolutionRoots != null)
  356. {
  357. yield return ContinuousController.instance.StartCoroutine(_endSelectCoroutine_SelectDigivolutionRoots(selectedEvoRoots));
  358. }
  359. }
  360. foreach (Permanent permanent in _card.Owner.GetBattleAreaDigimons())
  361. {
  362. if (permanent != null)
  363. {
  364. if (permanent.ShowingPermanentCard != null)
  365. {
  366. permanent.ShowingPermanentCard.OffPermanentIndexText();
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }