SelectJogressEffect.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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, _isLocal);
  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(!_card.CanNotEvolve(permanent))
  189. {
  190. if (!selectedEvoRoots.Contains(permanent))
  191. {
  192. if (element.EvoRootCondition != null)
  193. {
  194. if (element.EvoRootCondition(permanent))
  195. {
  196. if (_customPermanentConditions != null)
  197. {
  198. if (_customPermanentConditions.Length == 1)
  199. {
  200. if (_customPermanentConditions[0] != null)
  201. {
  202. if (_card.Owner.GetBattleAreaDigimons().Count(_customPermanentConditions[0]) >= 1)
  203. {
  204. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 0)
  205. {
  206. if (!_customPermanentConditions[0](permanent))
  207. {
  208. if (i == 1)
  209. {
  210. return false;
  211. }
  212. else
  213. {
  214. JogressConditionElement element1 = selectedDNA.elements[1];
  215. if (_card.Owner.GetBattleAreaDigimons().Count((permanent1) => permanent1 != permanent && element1.EvoRootCondition(permanent1) && _customPermanentConditions[0](permanent1)) == 0)
  216. {
  217. return false;
  218. }
  219. }
  220. }
  221. }
  222. }
  223. else
  224. {
  225. return false;
  226. }
  227. }
  228. }
  229. else if (_customPermanentConditions.Length == 2)
  230. {
  231. if (_customPermanentConditions[0] != null && _customPermanentConditions[1] != null)
  232. {
  233. if (_card.Owner.GetBattleAreaDigimons().Count(_customPermanentConditions[0]) >= 1 && _card.Owner.GetBattleAreaDigimons().Count(_customPermanentConditions[1]) >= 1)
  234. {
  235. if (i == 1)
  236. {
  237. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 0 && selectedEvoRoots.Count(_customPermanentConditions[1]) == 0)
  238. {
  239. return false;
  240. }
  241. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 0 && selectedEvoRoots.Count(_customPermanentConditions[1]) == 1)
  242. {
  243. if (!_customPermanentConditions[0](permanent))
  244. {
  245. return false;
  246. }
  247. }
  248. if (selectedEvoRoots.Count(_customPermanentConditions[0]) == 1 && selectedEvoRoots.Count(_customPermanentConditions[1]) == 0)
  249. {
  250. if (!_customPermanentConditions[1](permanent))
  251. {
  252. return false;
  253. }
  254. }
  255. }
  256. else
  257. {
  258. if (_customPermanentConditions[0](permanent) || _customPermanentConditions[1](permanent))
  259. {
  260. JogressConditionElement element1 = selectedDNA.elements[1];
  261. if (_customPermanentConditions[0](permanent))
  262. {
  263. if (_card.Owner.GetBattleAreaDigimons().Count((permanent1) => permanent1 != permanent && element1.EvoRootCondition(permanent1) && _customPermanentConditions[1](permanent1)) == 0)
  264. {
  265. return false;
  266. }
  267. }
  268. if (_customPermanentConditions[1](permanent))
  269. {
  270. if (_card.Owner.GetBattleAreaDigimons().Count((permanent1) => permanent1 != permanent && element1.EvoRootCondition(permanent1) && _customPermanentConditions[0](permanent1)) == 0)
  271. {
  272. return false;
  273. }
  274. }
  275. }
  276. else
  277. {
  278. return false;
  279. }
  280. }
  281. }
  282. else
  283. {
  284. return false;
  285. }
  286. }
  287. }
  288. }
  289. if (i == 0)
  290. {
  291. List<Permanent> nextCandidates = _card.Owner.GetBattleAreaDigimons()
  292. .Filter(permanent1 => permanent1 != permanent);
  293. if (nextCandidates.Count(selectedDNA.elements[1].EvoRootCondition) == 0)
  294. {
  295. return false;
  296. }
  297. }
  298. return true;
  299. }
  300. }
  301. }
  302. }
  303. }
  304. return false;
  305. }
  306. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  307. Permanent selectedPermanent = null;
  308. if (maxCount >= 1)
  309. {
  310. selectPermanentEffect.SetUp(
  311. selectPlayer: _card.Owner,
  312. canTargetCondition: CanSelectPermanentCondition,
  313. canTargetCondition_ByPreSelecetedList: null,
  314. canEndSelectCondition: null,
  315. maxCount: maxCount,
  316. canNoSelect: _canNoSelect,
  317. canEndNotMax: false,
  318. selectPermanentCoroutine: SelectPermanentCoroutine,
  319. afterSelectPermanentCoroutine: null,
  320. mode: SelectPermanentEffect.Mode.Custom,
  321. cardEffect: null);
  322. selectPermanentEffect.SetUpCustomMessage($"Select {element.SelectMessage}.", $"The opponent is selecting {element.SelectMessage}.");
  323. if (this._isLocal)
  324. {
  325. selectPermanentEffect.SetIsLocal();
  326. }
  327. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  328. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  329. {
  330. selectedPermanent = permanent;
  331. yield return null;
  332. }
  333. }
  334. if (selectedPermanent == null)
  335. {
  336. break;
  337. }
  338. else
  339. {
  340. selectedEvoRoots.Add(selectedPermanent);
  341. foreach (Permanent permanent in selectedEvoRoots)
  342. {
  343. permanent.ShowingPermanentCard.SetPermanentIndexText(selectedEvoRoots);
  344. }
  345. }
  346. }
  347. //do not jogress
  348. if (selectedEvoRoots.Count != selectedDNA.elements.Length)
  349. {
  350. if (_noSelectCoroutine != null)
  351. {
  352. yield return ContinuousController.instance.StartCoroutine(_noSelectCoroutine());
  353. }
  354. }
  355. //do jogress
  356. else
  357. {
  358. if (_endSelectCoroutine_SelectDigivolutionRoots != null)
  359. {
  360. yield return ContinuousController.instance.StartCoroutine(_endSelectCoroutine_SelectDigivolutionRoots(selectedEvoRoots));
  361. }
  362. }
  363. foreach (Permanent permanent in _card.Owner.GetBattleAreaDigimons())
  364. {
  365. if (permanent != null)
  366. {
  367. if (permanent.ShowingPermanentCard != null)
  368. {
  369. permanent.ShowingPermanentCard.OffPermanentIndexText();
  370. }
  371. }
  372. }
  373. }
  374. }
  375. }