SelectCardEffect.cs 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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. photonView.RPC("SetTargetCardAndIndicies", RpcTarget.All, _selectPlayer.PlayerID, targetCardIDs.ToArray(), _slectedInexesInList.ToArray());
  476. }
  477. }
  478. else
  479. {
  480. if (!string.IsNullOrEmpty(_customMessage_Enemy))
  481. {
  482. GManager.instance.commandText.OpenCommandText(_customMessage_Enemy, _isDigiXros, _isAssembly);
  483. }
  484. else
  485. {
  486. GManager.instance.commandText.OpenCommandText("The opponent is selecting cards.", _isDigiXros, _isAssembly);
  487. }
  488. #region AI
  489. if (GManager.instance.IsAI)
  490. {
  491. AutoSelect();
  492. }
  493. #endregion
  494. }
  495. void AutoSelect()
  496. {
  497. List<CardSource> ValidCards = new List<CardSource>();
  498. foreach (CardSource cardSource in RootCardList())
  499. {
  500. if (CanSelectCard(cardSource))
  501. {
  502. ValidCards.Add(cardSource);
  503. }
  504. }
  505. IList<int> indexList = Enumerable.Range(0, ValidCards.Count).ToList();
  506. if (ValidCards.Count >= _maxCount)
  507. {
  508. for (int i = 0; i < 1000; i++)
  509. {
  510. List<int> GetIndexes = indexList.GetRandom(_maxCount).ToList();
  511. List<CardSource> GetCards = new List<CardSource>();
  512. foreach (int index in GetIndexes)
  513. {
  514. GetCards.Add(ValidCards[index]);
  515. }
  516. if (_canEndSelectCondition != null)
  517. {
  518. if (!_canEndSelectCondition(GetCards))
  519. {
  520. continue;
  521. }
  522. }
  523. List<int> CardIDs = new List<int>();
  524. foreach (CardSource cardSource in GetCards)
  525. {
  526. CardIDs.Add(cardSource.CardIndex);
  527. }
  528. if (GManager.instance.IsAI)
  529. {
  530. SetTargetCardAndIndicies(_selectPlayer.PlayerID, CardIDs.ToArray(), null);
  531. }
  532. else
  533. {
  534. photonView.RPC("SetTargetCardAndIndicies", RpcTarget.All, _selectPlayer.PlayerID, CardIDs.ToArray(), null);
  535. }
  536. break;
  537. }
  538. }
  539. }
  540. yield return new WaitUntil(() => _selectPlayer.HasPlayerSelection());
  541. CardSelection cardSelection = _selectPlayer.DequeuePlayerSelection<CardSelection>();
  542. if (cardSelection != null && cardSelection.CardIDList != null)
  543. {
  544. _targetCards = new List<CardSource>();
  545. foreach (int cardID in cardSelection.CardIDList)
  546. {
  547. _targetCards.Add(GManager.instance.turnStateMachine.gameContext.ActiveCardList[cardID]);
  548. }
  549. }
  550. yield return new WaitUntil(() => _selectPlayer.HasPlayerSelection());
  551. CardSelection indiciesSelection = _selectPlayer.DequeuePlayerSelection<CardSelection>();
  552. if (indiciesSelection != null && indiciesSelection.CardIDList != null)
  553. {
  554. _slectedInexesInList = new List<int>();
  555. foreach (int index in indiciesSelection.CardIDList)
  556. {
  557. _slectedInexesInList.Add(index);
  558. }
  559. }
  560. GManager.instance.commandText.CloseCommandText();
  561. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  562. #region Show selected card
  563. if (_targetCards.Count > 0 && _showCard)
  564. {
  565. if (_targetCards.Count((cardSource) => cardSource.IsFlipped) > 0 && !_showReverseCard)
  566. {
  567. //表示しない
  568. }
  569. else
  570. {
  571. if (_isShowOpponent || (_selectPlayer.isYou && _targetCards.Count((cardSource) => cardSource.Owner == _selectPlayer) > 0))
  572. {
  573. if (!string.IsNullOrEmpty(_customMessage_ShowCard))
  574. {
  575. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, _customMessage_ShowCard, true, true));
  576. }
  577. else
  578. {
  579. switch (_mode)
  580. {
  581. case Mode.AddHand:
  582. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Cards added to hand", true, true));
  583. break;
  584. case Mode.Discard:
  585. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Cards put on the trash", true, true));
  586. break;
  587. case Mode.PlayForFree:
  588. case Mode.PlayForCost:
  589. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Played cards", true, true));
  590. break;
  591. case Mode.Custom:
  592. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Selected Cards", true, true));
  593. break;
  594. }
  595. }
  596. }
  597. }
  598. }
  599. #endregion
  600. Hashtable hashtable = CardEffectCommons.CardEffectHashtable(_cardEffect);
  601. string log = "";
  602. if (_mode == Mode.AddHand)
  603. {
  604. log += $"\nCard{Utils.PluralFormSuffix(_targetCards.Count)} added to hand:";
  605. }
  606. else if (_mode == Mode.AddHand)
  607. {
  608. log += $"\nTrash Card{Utils.PluralFormSuffix(_targetCards.Count)}:";
  609. }
  610. else
  611. {
  612. log += $"\nSelected Card{Utils.PluralFormSuffix(_targetCards.Count)}:";
  613. }
  614. if (_root == Root.Library)
  615. {
  616. //yield return ContinuousController.instance.StartCoroutine(CardObjectController.Shuffle(_selectPlayer));
  617. }
  618. foreach (CardSource cardSource in _targetCards)
  619. {
  620. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  621. }
  622. switch (_mode)
  623. {
  624. case Mode.AddHand:
  625. foreach (CardSource cardSource in _targetCards)
  626. {
  627. cardSource.SetFace();
  628. if (cardSource.IsDigiEgg) yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource> { cardSource }));
  629. else
  630. {
  631. if (cardSource.PermanentOfThisCard() != null)
  632. {
  633. if (cardSource.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  634. {
  635. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
  636. }
  637. }
  638. handCards.Add(cardSource);
  639. }
  640. }
  641. break;
  642. case Mode.Discard:
  643. foreach (CardSource cardSource in _targetCards)
  644. {
  645. if (CardEffectCommons.IsExistOnHand(cardSource))
  646. {
  647. List<IDiscardHand> discardHands = _targetCards.Map(cardSource => new IDiscardHand(cardSource, hashtable));
  648. yield return ContinuousController.instance.StartCoroutine(new IDiscardHands(discardHands, _cardEffect).DiscardHands());
  649. }
  650. else if (CardEffectCommons.IsExistLinked(cardSource))
  651. {
  652. yield return ContinuousController.instance.StartCoroutine(new ITrashLinkCards(
  653. cardSource.PermanentOfThisCard(),
  654. new List<CardSource> { cardSource },
  655. _cardEffect).TrashLinkCards());
  656. }
  657. //After IsExistLinked, this would be digivolution cards, or topcard which should have been disbarred by selection condition.
  658. //ITrashDigiviolutionCards also refuses to do anything with a TopCard
  659. else if (CardEffectCommons.IsExistOnBattleArea(cardSource))
  660. {
  661. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  662. cardSource.PermanentOfThisCard(),
  663. new List<CardSource> { cardSource },
  664. _cardEffect).TrashDigivolutionCards());
  665. }
  666. else
  667. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  668. }
  669. break;
  670. case Mode.PlayForFree:
  671. yield return ContinuousController.instance.StartCoroutine(
  672. CardEffectCommons.PlayPermanentCards(
  673. cardSources: _targetCards,
  674. activateClass: _cardEffect,
  675. payCost: false,
  676. isTapped: false,
  677. root: _root,
  678. activateETB: true));
  679. break;
  680. case Mode.PlayForCost:
  681. {
  682. bool PermanentsCondition(List<Permanent> targetPermanents)
  683. {
  684. if (targetPermanents == null)
  685. {
  686. return true;
  687. }
  688. else
  689. {
  690. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  691. {
  692. return true;
  693. }
  694. }
  695. return false;
  696. }
  697. bool SharedCardCondition(CardSource cardSource) => _targetCards.Contains(cardSource);
  698. bool RootCondition(SelectCardEffect.Root root) => true;
  699. bool CanUseCondition(Hashtable hashtable) => true;
  700. #region reduce cost
  701. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  702. if (_reduceCostTuple != null)
  703. {
  704. bool CardCondition(CardSource cardSource)
  705. {
  706. return SharedCardCondition(cardSource)
  707. && (_reduceCostTuple.Value.reduceCostCardCondition == null || _reduceCostTuple.Value.reduceCostCardCondition(cardSource));
  708. }
  709. int ChangeCost(CardSource cardSource, int Cost, Root root, List<Permanent> targetPermanents)
  710. {
  711. if (PermanentsCondition(targetPermanents))
  712. {
  713. Cost -= _reduceCostTuple.Value.reduceCost;
  714. }
  715. return Cost;
  716. }
  717. bool isUpDown() => true;
  718. ChangeCostClass changeCostClass = new ChangeCostClass();
  719. changeCostClass.SetUpICardEffect($"Play Cost -{_reduceCostTuple.Value.reduceCost}", CanUseCondition, _cardEffect.EffectSourceCard);
  720. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  721. getChangeCostEffect = GetCardEffect;
  722. ICardEffect GetCardEffect(EffectTiming _timing)
  723. {
  724. if (_timing == EffectTiming.None)
  725. {
  726. return changeCostClass;
  727. }
  728. return null;
  729. }
  730. if (getChangeCostEffect != null)
  731. {
  732. _selectPlayer.UntilCalculateFixedCostEffect.Add(getChangeCostEffect);
  733. }
  734. }
  735. #endregion
  736. #region set fixed cost
  737. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  738. if (_fixedCostTuple != null)
  739. {
  740. bool CardCondition(CardSource cardSource)
  741. {
  742. return SharedCardCondition(cardSource)
  743. && (_fixedCostTuple.Value.fixedCostCardCondition == null || _fixedCostTuple.Value.fixedCostCardCondition(cardSource));
  744. }
  745. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  746. {
  747. if (PermanentsCondition(targetPermanents))
  748. {
  749. Cost = _fixedCostTuple.Value.fixedCost;
  750. }
  751. return Cost;
  752. }
  753. bool isUpDown() => false;
  754. ChangeCostClass changeCostClass = new ChangeCostClass();
  755. changeCostClass.SetUpICardEffect($"Play Cost {_fixedCostTuple.Value.fixedCost}", CanUseCondition, _cardEffect.EffectSourceCard);
  756. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  757. getFixedCostEffect = GetCardEffect;
  758. ICardEffect GetCardEffect(EffectTiming _timing)
  759. {
  760. if (_timing == EffectTiming.None)
  761. {
  762. return changeCostClass;
  763. }
  764. return null;
  765. }
  766. if (getFixedCostEffect != null)
  767. {
  768. _selectPlayer.UntilCalculateFixedCostEffect.Add(getFixedCostEffect);
  769. }
  770. }
  771. #endregion
  772. yield return ContinuousController.instance.StartCoroutine(
  773. CardEffectCommons.PlayPermanentCards(
  774. cardSources: _targetCards,
  775. activateClass: _cardEffect,
  776. payCost: true,
  777. isTapped: false,
  778. root: SelectCardEffect.Root.Hand,
  779. activateETB: true));
  780. #region release effect
  781. if (getChangeCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  782. #endregion
  783. #region release effect
  784. if (getFixedCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  785. #endregion
  786. break;
  787. }
  788. case Mode.Custom:
  789. if (_selectCardCoroutine != null)
  790. {
  791. foreach (CardSource cardSource in _targetCards)
  792. {
  793. yield return StartCoroutine(_selectCardCoroutine(cardSource));
  794. }
  795. }
  796. break;
  797. }
  798. if (handCards.Count >= 1)
  799. {
  800. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, _cardEffect));
  801. }
  802. #region ログ追加
  803. if (!_notAddLog)
  804. {
  805. if (_isShowOpponent || _selectPlayer.isYou)
  806. {
  807. if (_targetCards.Count >= 1)
  808. {
  809. log += "\n";
  810. PlayLog.OnAddLog?.Invoke(log);
  811. }
  812. }
  813. }
  814. #endregion
  815. }
  816. if (_afterSelectCardCoroutine != null)
  817. {
  818. yield return StartCoroutine(_afterSelectCardCoroutine(_targetCards));
  819. }
  820. if (_afterSelectIndexCoroutine != null)
  821. {
  822. yield return StartCoroutine(_afterSelectIndexCoroutine(_slectedInexesInList));
  823. }
  824. GManager.instance.turnStateMachine.gameContext.IsSecurityLooking = false;
  825. GManager.instance.turnStateMachine.IsSelecting = oldIsSelecting;
  826. }
  827. [PunRPC]
  828. public void SetTargetCardAndIndicies(int playerID, int[] CardIDs, int[] Indicies)
  829. {
  830. Player player = GManager.instance.GetPlayerFromID(playerID);
  831. if (!player)
  832. {
  833. return;
  834. }
  835. player.QueuePlayerSelection(new CardSelection(CardIDs));
  836. player.QueuePlayerSelection(new CardSelection(Indicies));
  837. }
  838. }