SelectCardEffect.cs 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Linq;
  5. using Photon.Pun;
  6. using System;
  7. public class SelectCardEffect : MonoBehaviourPunCallbacks
  8. {
  9. public void SetUp(
  10. Func<CardSource, bool> canTargetCondition,
  11. Func<List<CardSource>, CardSource, bool> canTargetCondition_ByPreSelecetedList,
  12. Func<List<CardSource>, bool> canEndSelectCondition,
  13. Func<bool> canNoSelect,
  14. Func<CardSource, IEnumerator> selectCardCoroutine,
  15. Func<List<CardSource>, IEnumerator> afterSelectCardCoroutine,
  16. string message,
  17. int maxCount,
  18. bool canEndNotMax,
  19. bool isShowOpponent,
  20. Mode mode,
  21. Root root,
  22. List<CardSource> customRootCardList,
  23. bool canLookReverseCard,
  24. Player selectPlayer,
  25. ICardEffect cardEffect)
  26. {
  27. _canTargetCondition = canTargetCondition;
  28. _canTargetCondition_ByPreSelecetedList = canTargetCondition_ByPreSelecetedList;
  29. _canEndSelectCondition = canEndSelectCondition;
  30. _canNoSelect = canNoSelect;
  31. _selectCardCoroutine = selectCardCoroutine;
  32. _afterSelectCardCoroutine = afterSelectCardCoroutine;
  33. _message = message;
  34. _maxCount = maxCount;
  35. _canEndNotMax = canEndNotMax;
  36. _isShowOpponent = isShowOpponent;
  37. _mode = mode;
  38. _root = root;
  39. _customRootCardList = customRootCardList;
  40. _canLookReverseCard = canLookReverseCard;
  41. _selectPlayer = selectPlayer;
  42. _cardEffect = cardEffect;
  43. _isLocal = false;
  44. _customMessage = null;
  45. _customMessage_Enemy = null;
  46. _customMessage_ShowCard = null;
  47. _customCountText = null;
  48. _showReverseCard = true;
  49. _showCard = true;
  50. _isDigiXros = false;
  51. _isAssembly = false;
  52. _isDeckBottom = false;
  53. _isDeckTop = false;
  54. _notAddLog = false;
  55. _isSecurity = false;
  56. _allowFaceDown = false;
  57. _skillInfos = new List<SkillInfo>();
  58. _afterSelectIndexCoroutine = null;
  59. _endSelect = false;
  60. }
  61. public void SetIsLocal()
  62. {
  63. _isLocal = true;
  64. }
  65. public void SetIsDeckBottom()
  66. {
  67. _isDeckBottom = true;
  68. }
  69. public void SetIsDeckTop()
  70. {
  71. _isDeckTop = true;
  72. }
  73. public void SetNotShowCard()
  74. {
  75. _showCard = false;
  76. }
  77. public void SetNotAddLog()
  78. {
  79. _notAddLog = true;
  80. }
  81. public void SetDigiXros()
  82. {
  83. _isDigiXros = true;
  84. }
  85. public void SetAssembly()
  86. {
  87. _isAssembly = true;
  88. }
  89. public void SetIsSecurity()
  90. {
  91. _isSecurity = true;
  92. }
  93. public void SetUseFaceDown()
  94. {
  95. _allowFaceDown = true;
  96. }
  97. public void SetUpSkillInfos(List<SkillInfo> skillInfos)
  98. {
  99. _skillInfos = skillInfos.Clone();
  100. }
  101. public void SetReducedCostTuple((int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple)
  102. {
  103. _reduceCostTuple = reduceCostTuple;
  104. }
  105. public void SetFixedCostTuple((int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple)
  106. {
  107. _fixedCostTuple = fixedCostTuple;
  108. }
  109. public void SetUpCustomMessage(string CustomMessage, string CustomMessage_Enemy)
  110. {
  111. _customMessage = CustomMessage;
  112. _customMessage_Enemy = CustomMessage_Enemy;
  113. }
  114. public void SetUpCustomMessage_ShowCard(string CustomMessage_ShowCard)
  115. {
  116. _customMessage_ShowCard = CustomMessage_ShowCard;
  117. }
  118. public void SetUpCustomCountText(string CustomCountText)
  119. {
  120. _customCountText = CustomCountText;
  121. }
  122. public void SetShowReverseCard()
  123. {
  124. _showReverseCard = false;
  125. }
  126. Func<CardSource, bool> _canTargetCondition = null;
  127. Func<List<CardSource>, CardSource, bool> _canTargetCondition_ByPreSelecetedList = null;
  128. Func<List<CardSource>, bool> _canEndSelectCondition = null;
  129. Func<bool> _canNoSelect = null;
  130. List<CardSource> _targetCards = new List<CardSource>();
  131. Func<CardSource, IEnumerator> _selectCardCoroutine = null;
  132. Func<List<CardSource>, IEnumerator> _afterSelectCardCoroutine = null;
  133. string _message = "";
  134. int _maxCount = 0;
  135. bool _canEndNotMax = false;
  136. bool _isShowOpponent = false;
  137. bool _canLookReverseCard = false;
  138. List<CardSource> _customRootCardList { get; set; } = new List<CardSource>();
  139. Player _selectPlayer = null;
  140. ICardEffect _cardEffect = null;
  141. bool _isLocal = false;
  142. bool _showReverseCard = true;
  143. bool _showCard = true;
  144. bool _notAddLog = false;
  145. bool _isDigiXros = false;
  146. bool _isAssembly = false;
  147. bool _isSecurity = false;
  148. bool _allowFaceDown = false;
  149. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? _reduceCostTuple = null;
  150. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? _fixedCostTuple = null;
  151. public enum Mode
  152. {
  153. AddHand,
  154. Discard,
  155. // PutLibraryTop,
  156. // PutLibraryBottom,
  157. PlayForFree,
  158. PlayForCost,
  159. Custom,
  160. }
  161. Mode _mode;
  162. public enum Root
  163. {
  164. Library,
  165. Trash,
  166. Clock,
  167. Security,
  168. Custom,
  169. Hand,
  170. Recollection,
  171. Execution,
  172. DigivolutionCards,
  173. LinkedCards,
  174. None,
  175. }
  176. Root _root;
  177. bool _endSelect = false;
  178. bool _isDeckBottom = false;
  179. bool _isDeckTop = false;
  180. string _customMessage = null;
  181. string _customMessage_Enemy = null;
  182. string _customMessage_ShowCard = null;
  183. string _customCountText = null;
  184. List<SkillInfo> _skillInfos = new List<SkillInfo>();
  185. List<int> _slectedInexesInList = new List<int>();
  186. Func<List<int>, IEnumerator> _afterSelectIndexCoroutine = null;
  187. public void SetUpAfterSelectIndexCoroutine(Func<List<int>, IEnumerator> AfterSelectIndexCoroutine)
  188. {
  189. _afterSelectIndexCoroutine = AfterSelectIndexCoroutine;
  190. }
  191. public virtual List<CardSource> RootCardList()
  192. {
  193. List<CardSource> RootCardList = new List<CardSource>();
  194. if (_customRootCardList == null)
  195. {
  196. switch (_root)
  197. {
  198. case Root.Library:
  199. foreach (CardSource cardSource in _selectPlayer.LibraryCards)
  200. {
  201. RootCardList.Add(cardSource);
  202. }
  203. break;
  204. case Root.Trash:
  205. foreach (CardSource cardSource in _selectPlayer.TrashCards)
  206. {
  207. RootCardList.Add(cardSource);
  208. }
  209. break;
  210. case Root.Security:
  211. foreach (CardSource cardSource in _selectPlayer.SecurityCards)
  212. {
  213. RootCardList.Add(cardSource);
  214. }
  215. break;
  216. case Root.Recollection:
  217. foreach (CardSource cardSource in _selectPlayer.LostCards)
  218. {
  219. RootCardList.Add(cardSource);
  220. }
  221. break;
  222. }
  223. }
  224. else
  225. {
  226. foreach (CardSource cardSource in _customRootCardList)
  227. {
  228. RootCardList.Add(cardSource);
  229. }
  230. }
  231. return RootCardList;
  232. }
  233. private bool CanSelectCard(CardSource cardSource)
  234. {
  235. if (_root != Root.Library && _root != Root.Security && _root != Root.Custom)
  236. {
  237. if (cardSource.IsFlipped)
  238. return false;
  239. }
  240. if (_canTargetCondition != null)
  241. {
  242. if (_canTargetCondition(cardSource))
  243. {
  244. if (!_allowFaceDown)
  245. {
  246. if (cardSource.IsFlipped)
  247. return false;
  248. }
  249. return true;
  250. }
  251. }
  252. return false;
  253. }
  254. public bool active()
  255. {
  256. if (RootCardList().Count > 0)
  257. {
  258. if (_root != Root.Library && _root != Root.Security)
  259. {
  260. if (RootCardList().Count(CanSelectCard) > 0)
  261. {
  262. return true;
  263. }
  264. }
  265. else
  266. {
  267. if (_root == Root.Library)
  268. SetUseFaceDown();
  269. if(_root == Root.Security)
  270. {
  271. if (_canLookReverseCard)
  272. SetUseFaceDown();
  273. }
  274. return true;
  275. }
  276. }
  277. return false;
  278. }
  279. public virtual IEnumerator Activate()
  280. {
  281. bool oldIsSelecting = GManager.instance.turnStateMachine.IsSelecting;
  282. List<CardSource> handCards = new List<CardSource>();
  283. _targetCards = new List<CardSource>();
  284. _slectedInexesInList = new List<int>();
  285. if (!_isLocal)
  286. {
  287. yield return GManager.instance.photonWaitController.StartWait("SelectCardEffect");
  288. }
  289. bool oldIsActiveOutline_AttackingPermanent = false;
  290. if (GManager.instance.attackProcess.AttackingPermanent != null)
  291. {
  292. if (GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard != null)
  293. {
  294. oldIsActiveOutline_AttackingPermanent = GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard.Outline_Select.gameObject.activeSelf;
  295. }
  296. }
  297. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  298. {
  299. GManager.instance.turnStateMachine.OffFieldCardTarget(player);
  300. GManager.instance.turnStateMachine.OffHandCardTarget(player);
  301. }
  302. if (GManager.instance.attackProcess.AttackingPermanent != null)
  303. {
  304. if (GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard != null)
  305. {
  306. GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard.Outline_Select.gameObject.SetActive(oldIsActiveOutline_AttackingPermanent);
  307. }
  308. }
  309. if (_maxCount == 0)
  310. {
  311. _canNoSelect = () => true;
  312. }
  313. if (_root == Root.Security)
  314. {
  315. SetIsSecurity();
  316. }
  317. if (active())
  318. {
  319. if (_isSecurity)
  320. {
  321. GManager.instance.turnStateMachine.gameContext.IsSecurityLooking = true;
  322. }
  323. if (_selectPlayer.isYou)
  324. {
  325. if ((_isDeckBottom && ContinuousController.instance.autoDeckBottomOrder)
  326. || (_isDeckTop && ContinuousController.instance.autoDeckTopOrder))
  327. {
  328. AutoSelect();
  329. }
  330. else
  331. {
  332. List<int> targetCardIDs = new List<int>();
  333. GManager.instance.turnStateMachine.IsSelecting = true;
  334. #region Message Display
  335. if (!string.IsNullOrEmpty(_customMessage))
  336. {
  337. GManager.instance.commandText.OpenCommandText(_customMessage, _isDigiXros, _isAssembly);
  338. }
  339. else
  340. {
  341. string message = "";
  342. switch (_mode)
  343. {
  344. case Mode.AddHand:
  345. message = "Select cards to add to your hand.";
  346. break;
  347. case Mode.Discard:
  348. message = "Select cards to trash.";
  349. break;
  350. case Mode.PlayForFree:
  351. message = "Select cards to play without paying the cost.";
  352. break;
  353. case Mode.PlayForCost:
  354. message = "Select cards to play.";
  355. break;
  356. case Mode.Custom:
  357. message = "Select cards.";
  358. break;
  359. }
  360. if (!string.IsNullOrEmpty(message))
  361. {
  362. GManager.instance.commandText.OpenCommandText(message, _isDigiXros, _isAssembly);
  363. }
  364. }
  365. #endregion
  366. List<CardSource> RootCards = new List<CardSource>();
  367. foreach (CardSource cardSource in RootCardList())
  368. {
  369. RootCards.Add(cardSource);
  370. }
  371. #region Sort
  372. if (_root == Root.Library || _root == Root.Trash)
  373. {
  374. RootCards = DeckData.SortedCardsList(RootCards);
  375. List<CardSource> matchConditionCards = new List<CardSource>();
  376. List<CardSource> notMatchConditionCards = new List<CardSource>();
  377. foreach (CardSource cardSource in RootCards)
  378. {
  379. if (CanSelectCard(cardSource))
  380. {
  381. matchConditionCards.Add(cardSource);
  382. }
  383. else
  384. {
  385. notMatchConditionCards.Add(cardSource);
  386. }
  387. }
  388. RootCards = new List<CardSource>();
  389. foreach (CardSource cardSource in matchConditionCards)
  390. {
  391. RootCards.Add(cardSource);
  392. }
  393. foreach (CardSource cardSource in notMatchConditionCards)
  394. {
  395. RootCards.Add(cardSource);
  396. }
  397. }
  398. #endregion
  399. #region Effect in progress/waiting to be activated
  400. if (_cardEffect != null)
  401. {
  402. if (_cardEffect.EffectSourceCard != null)
  403. {
  404. if (_skillInfos.Count == 0)
  405. {
  406. if (_root == Root.Trash || _root == Root.DigivolutionCards || _root == Root.LinkedCards)
  407. {
  408. SkillInfo[] skillInfoArray = new SkillInfo[RootCards.Count];
  409. for (int i = 0; i < skillInfoArray.Length; i++)
  410. {
  411. if (0 <= i && i <= RootCards.Count - 1)
  412. {
  413. if (RootCards[i] == _cardEffect.EffectSourceCard)
  414. {
  415. ICardEffect cardEffect = new ChangeBaseDPClass();
  416. cardEffect.SetUpICardEffect("Effect Processing", null, RootCards[i]);
  417. skillInfoArray[i] = new SkillInfo(cardEffect, null, EffectTiming.None);
  418. }
  419. else
  420. {
  421. if (GManager.instance.autoProcessing.executingMultipleSkills != null)
  422. {
  423. bool isEffectWaiting(SkillInfo skillInfo)
  424. {
  425. if (skillInfo != null)
  426. {
  427. if (skillInfo.CardEffect != null)
  428. {
  429. if (skillInfo.CardEffect.EffectSourceCard != null)
  430. {
  431. if (skillInfo.CardEffect.EffectSourceCard == RootCards[i])
  432. {
  433. return true;
  434. }
  435. }
  436. }
  437. }
  438. return false;
  439. }
  440. if (GManager.instance.autoProcessing.executingMultipleSkills.StackedSkillInfos.Count(isEffectWaiting) >= 1)
  441. {
  442. ICardEffect cardEffect = new ChangeBaseDPClass();
  443. cardEffect.SetUpICardEffect("Effect Waiting", null, RootCards[i]);
  444. skillInfoArray[i] = new SkillInfo(cardEffect, null, EffectTiming.None);
  445. }
  446. }
  447. }
  448. }
  449. }
  450. _skillInfos = skillInfoArray.ToList();
  451. }
  452. }
  453. }
  454. }
  455. #endregion
  456. GManager.instance.selectCardPanel._customCountText = _customCountText;
  457. yield return StartCoroutine(GManager.instance.selectCardPanel.OpenSelectCardPanel(
  458. Message: _message,
  459. RootCardSources: RootCards,
  460. _CanTargetCondition: CanSelectCard,
  461. _CanTargetCondition_ByPreSelecetedList: _canTargetCondition_ByPreSelecetedList,
  462. _CanEndSelectCondition: _canEndSelectCondition,
  463. _MaxCount: _maxCount,
  464. _CanEndNotMax: _canEndNotMax,
  465. _CanNoSelect: _canNoSelect,
  466. CanLookReverseCard: _canLookReverseCard,
  467. skillInfos: _skillInfos,
  468. root: _root));
  469. foreach (CardSource selectedCard in GManager.instance.selectCardPanel.SelectedList)
  470. {
  471. targetCardIDs.Add(selectedCard.CardIndex);
  472. }
  473. foreach (int selectedIndex in GManager.instance.selectCardPanel.SelectedIndex)
  474. {
  475. _slectedInexesInList.Add(selectedIndex);
  476. }
  477. photonView.RPC("SetTargetIndicies", RpcTarget.All, _slectedInexesInList.ToArray());
  478. photonView.RPC("SetTargetCard", RpcTarget.All, targetCardIDs.ToArray());
  479. }
  480. }
  481. else
  482. {
  483. if (!string.IsNullOrEmpty(_customMessage_Enemy))
  484. {
  485. GManager.instance.commandText.OpenCommandText(_customMessage_Enemy, _isDigiXros, _isAssembly);
  486. }
  487. else
  488. {
  489. GManager.instance.commandText.OpenCommandText("The opponent is selecting cards.", _isDigiXros, _isAssembly);
  490. }
  491. #region AI
  492. if (GManager.instance.IsAI)
  493. {
  494. AutoSelect();
  495. }
  496. #endregion
  497. }
  498. void AutoSelect()
  499. {
  500. List<CardSource> ValidCards = new List<CardSource>();
  501. foreach (CardSource cardSource in RootCardList())
  502. {
  503. if (CanSelectCard(cardSource))
  504. {
  505. ValidCards.Add(cardSource);
  506. }
  507. }
  508. IList<int> indexList = Enumerable.Range(0, ValidCards.Count).ToList();
  509. if (ValidCards.Count >= _maxCount)
  510. {
  511. for (int i = 0; i < 1000; i++)
  512. {
  513. List<int> GetIndexes = indexList.GetRandom(_maxCount).ToList();
  514. List<CardSource> GetCards = new List<CardSource>();
  515. foreach (int index in GetIndexes)
  516. {
  517. GetCards.Add(ValidCards[index]);
  518. }
  519. if (_canEndSelectCondition != null)
  520. {
  521. if (!_canEndSelectCondition(GetCards))
  522. {
  523. continue;
  524. }
  525. }
  526. List<int> CardIDs = new List<int>();
  527. foreach (CardSource cardSource in GetCards)
  528. {
  529. CardIDs.Add(cardSource.CardIndex);
  530. }
  531. if (GManager.instance.IsAI)
  532. {
  533. SetTargetCard(CardIDs.ToArray());
  534. }
  535. else
  536. {
  537. photonView.RPC("SetTargetCard", RpcTarget.All, CardIDs.ToArray());
  538. }
  539. break;
  540. }
  541. }
  542. if (GManager.instance.IsAI)
  543. {
  544. _endSelect = true;
  545. }
  546. }
  547. yield return new WaitWhile(() => !_endSelect);
  548. _endSelect = false;
  549. GManager.instance.commandText.CloseCommandText();
  550. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  551. #region Show selected card
  552. if (_targetCards.Count > 0 && _showCard)
  553. {
  554. if (_targetCards.Count((cardSource) => cardSource.IsFlipped) > 0 && !_showReverseCard)
  555. {
  556. //表示しない
  557. }
  558. else
  559. {
  560. if (_isShowOpponent || (_selectPlayer.isYou && _targetCards.Count((cardSource) => cardSource.Owner == _selectPlayer) > 0))
  561. {
  562. if (!string.IsNullOrEmpty(_customMessage_ShowCard))
  563. {
  564. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, _customMessage_ShowCard, true, true));
  565. }
  566. else
  567. {
  568. switch (_mode)
  569. {
  570. case Mode.AddHand:
  571. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Cards added to hand", true, true));
  572. break;
  573. case Mode.Discard:
  574. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Cards put on the trash", true, true));
  575. break;
  576. case Mode.PlayForFree:
  577. case Mode.PlayForCost:
  578. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Played cards", true, true));
  579. break;
  580. case Mode.Custom:
  581. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Selected Cards", true, true));
  582. break;
  583. }
  584. }
  585. }
  586. }
  587. }
  588. #endregion
  589. Hashtable hashtable = CardEffectCommons.CardEffectHashtable(_cardEffect);
  590. string log = "";
  591. if (_mode == Mode.AddHand)
  592. {
  593. log += $"\nCard{Utils.PluralFormSuffix(_targetCards.Count)} added to hand:";
  594. }
  595. else if (_mode == Mode.AddHand)
  596. {
  597. log += $"\nTrash Card{Utils.PluralFormSuffix(_targetCards.Count)}:";
  598. }
  599. else
  600. {
  601. log += $"\nSelected Card{Utils.PluralFormSuffix(_targetCards.Count)}:";
  602. }
  603. if (_root == Root.Library)
  604. {
  605. //yield return ContinuousController.instance.StartCoroutine(CardObjectController.Shuffle(_selectPlayer));
  606. }
  607. foreach (CardSource cardSource in _targetCards)
  608. {
  609. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  610. }
  611. switch (_mode)
  612. {
  613. case Mode.AddHand:
  614. foreach (CardSource cardSource in _targetCards)
  615. {
  616. cardSource.SetFace();
  617. if (cardSource.IsDigiEgg) yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource> { cardSource }));
  618. else
  619. {
  620. if (cardSource.PermanentOfThisCard() != null)
  621. {
  622. if (cardSource.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  623. {
  624. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
  625. }
  626. }
  627. handCards.Add(cardSource);
  628. }
  629. }
  630. break;
  631. case Mode.Discard:
  632. foreach (CardSource cardSource in _targetCards)
  633. {
  634. if (CardEffectCommons.IsExistOnHand(cardSource))
  635. {
  636. List<IDiscardHand> discardHands = _targetCards.Map(cardSource => new IDiscardHand(cardSource, hashtable));
  637. yield return ContinuousController.instance.StartCoroutine(new IDiscardHands(discardHands, _cardEffect).DiscardHands());
  638. }
  639. else if (CardEffectCommons.IsExistLinked(cardSource))
  640. {
  641. yield return ContinuousController.instance.StartCoroutine(new ITrashLinkCards(
  642. cardSource.PermanentOfThisCard(),
  643. new List<CardSource> { cardSource },
  644. _cardEffect).TrashLinkCards());
  645. }
  646. //After IsExistLinked, this would be digivolution cards, or topcard which should have been disbarred by selection condition.
  647. //ITrashDigiviolutionCards also refuses to do anything with a TopCard
  648. else if (CardEffectCommons.IsExistOnBattleArea(cardSource))
  649. {
  650. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  651. cardSource.PermanentOfThisCard(),
  652. new List<CardSource> { cardSource },
  653. _cardEffect).TrashDigivolutionCards());
  654. }
  655. else
  656. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  657. }
  658. break;
  659. case Mode.PlayForFree:
  660. yield return ContinuousController.instance.StartCoroutine(
  661. CardEffectCommons.PlayPermanentCards(
  662. cardSources: _targetCards,
  663. activateClass: _cardEffect,
  664. payCost: false,
  665. isTapped: false,
  666. root: _root,
  667. activateETB: true));
  668. break;
  669. case Mode.PlayForCost:
  670. {
  671. bool PermanentsCondition(List<Permanent> targetPermanents)
  672. {
  673. if (targetPermanents == null)
  674. {
  675. return true;
  676. }
  677. else
  678. {
  679. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  680. {
  681. return true;
  682. }
  683. }
  684. return false;
  685. }
  686. bool SharedCardCondition(CardSource cardSource) => _targetCards.Contains(cardSource);
  687. bool RootCondition(SelectCardEffect.Root root) => true;
  688. bool CanUseCondition(Hashtable hashtable) => true;
  689. #region reduce cost
  690. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  691. if (_reduceCostTuple != null)
  692. {
  693. bool CardCondition(CardSource cardSource)
  694. {
  695. return SharedCardCondition(cardSource)
  696. && (_reduceCostTuple.Value.reduceCostCardCondition == null || _reduceCostTuple.Value.reduceCostCardCondition(cardSource));
  697. }
  698. int ChangeCost(CardSource cardSource, int Cost, Root root, List<Permanent> targetPermanents)
  699. {
  700. if (PermanentsCondition(targetPermanents))
  701. {
  702. Cost -= _reduceCostTuple.Value.reduceCost;
  703. }
  704. return Cost;
  705. }
  706. bool isUpDown() => true;
  707. ChangeCostClass changeCostClass = new ChangeCostClass();
  708. changeCostClass.SetUpICardEffect($"Play Cost -{_reduceCostTuple.Value.reduceCost}", CanUseCondition, _cardEffect.EffectSourceCard);
  709. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  710. getChangeCostEffect = GetCardEffect;
  711. ICardEffect GetCardEffect(EffectTiming _timing)
  712. {
  713. if (_timing == EffectTiming.None)
  714. {
  715. return changeCostClass;
  716. }
  717. return null;
  718. }
  719. if (getChangeCostEffect != null)
  720. {
  721. _selectPlayer.UntilCalculateFixedCostEffect.Add(getChangeCostEffect);
  722. }
  723. }
  724. #endregion
  725. #region set fixed cost
  726. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  727. if (_fixedCostTuple != null)
  728. {
  729. bool CardCondition(CardSource cardSource)
  730. {
  731. return SharedCardCondition(cardSource)
  732. && (_fixedCostTuple.Value.fixedCostCardCondition == null || _fixedCostTuple.Value.fixedCostCardCondition(cardSource));
  733. }
  734. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  735. {
  736. if (PermanentsCondition(targetPermanents))
  737. {
  738. Cost = _fixedCostTuple.Value.fixedCost;
  739. }
  740. return Cost;
  741. }
  742. bool isUpDown() => false;
  743. ChangeCostClass changeCostClass = new ChangeCostClass();
  744. changeCostClass.SetUpICardEffect($"Play Cost {_fixedCostTuple.Value.fixedCost}", CanUseCondition, _cardEffect.EffectSourceCard);
  745. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  746. getFixedCostEffect = GetCardEffect;
  747. ICardEffect GetCardEffect(EffectTiming _timing)
  748. {
  749. if (_timing == EffectTiming.None)
  750. {
  751. return changeCostClass;
  752. }
  753. return null;
  754. }
  755. if (getFixedCostEffect != null)
  756. {
  757. _selectPlayer.UntilCalculateFixedCostEffect.Add(getFixedCostEffect);
  758. }
  759. }
  760. #endregion
  761. yield return ContinuousController.instance.StartCoroutine(
  762. CardEffectCommons.PlayPermanentCards(
  763. cardSources: _targetCards,
  764. activateClass: _cardEffect,
  765. payCost: true,
  766. isTapped: false,
  767. root: SelectCardEffect.Root.Hand,
  768. activateETB: true));
  769. #region release effect
  770. if (getChangeCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  771. #endregion
  772. #region release effect
  773. if (getFixedCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  774. #endregion
  775. break;
  776. }
  777. case Mode.Custom:
  778. if (_selectCardCoroutine != null)
  779. {
  780. foreach (CardSource cardSource in _targetCards)
  781. {
  782. yield return StartCoroutine(_selectCardCoroutine(cardSource));
  783. }
  784. }
  785. break;
  786. }
  787. if (handCards.Count >= 1)
  788. {
  789. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, _cardEffect));
  790. }
  791. #region ログ追加
  792. if (!_notAddLog)
  793. {
  794. if (_isShowOpponent || _selectPlayer.isYou)
  795. {
  796. if (_targetCards.Count >= 1)
  797. {
  798. log += "\n";
  799. PlayLog.OnAddLog?.Invoke(log);
  800. }
  801. }
  802. }
  803. #endregion
  804. }
  805. if (_afterSelectCardCoroutine != null)
  806. {
  807. yield return StartCoroutine(_afterSelectCardCoroutine(_targetCards));
  808. }
  809. if (_afterSelectIndexCoroutine != null)
  810. {
  811. yield return StartCoroutine(_afterSelectIndexCoroutine(_slectedInexesInList));
  812. }
  813. GManager.instance.turnStateMachine.gameContext.IsSecurityLooking = false;
  814. GManager.instance.turnStateMachine.IsSelecting = oldIsSelecting;
  815. }
  816. [PunRPC]
  817. public void SetTargetCard(int[] CardIDs)
  818. {
  819. _targetCards = new List<CardSource>();
  820. foreach (int CardID in CardIDs)
  821. {
  822. _targetCards.Add(GManager.instance.turnStateMachine.gameContext.ActiveCardList[CardID]);
  823. }
  824. _endSelect = true;
  825. }
  826. [PunRPC]
  827. public void SetTargetIndicies(int[] CardIDs)
  828. {
  829. _slectedInexesInList = new List<int>();
  830. foreach (int index in CardIDs)
  831. {
  832. _slectedInexesInList.Add(index);
  833. }
  834. }
  835. }