SelectCardEffect.cs 38 KB

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