SelectCardEffect.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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. Custom,
  157. }
  158. Mode _mode;
  159. public enum Root
  160. {
  161. Library,
  162. Trash,
  163. Clock,
  164. Security,
  165. Custom,
  166. Hand,
  167. Recollection,
  168. Execution,
  169. DigivolutionCards,
  170. LinkedCards,
  171. None,
  172. }
  173. Root _root;
  174. bool _isDeckBottom = false;
  175. bool _isDeckTop = false;
  176. string _customMessage = null;
  177. string _customMessage_Enemy = null;
  178. string _customMessage_ShowCard = null;
  179. string _customCountText = null;
  180. List<SkillInfo> _skillInfos = new List<SkillInfo>();
  181. List<int> _slectedInexesInList = new List<int>();
  182. Func<List<int>, IEnumerator> _afterSelectIndexCoroutine = null;
  183. public void SetUpAfterSelectIndexCoroutine(Func<List<int>, IEnumerator> AfterSelectIndexCoroutine)
  184. {
  185. _afterSelectIndexCoroutine = AfterSelectIndexCoroutine;
  186. }
  187. public virtual List<CardSource> RootCardList()
  188. {
  189. List<CardSource> RootCardList = new List<CardSource>();
  190. if (_customRootCardList == null)
  191. {
  192. switch (_root)
  193. {
  194. case Root.Library:
  195. foreach (CardSource cardSource in _selectPlayer.LibraryCards)
  196. {
  197. RootCardList.Add(cardSource);
  198. }
  199. break;
  200. case Root.Trash:
  201. foreach (CardSource cardSource in _selectPlayer.TrashCards)
  202. {
  203. RootCardList.Add(cardSource);
  204. }
  205. break;
  206. case Root.Security:
  207. foreach (CardSource cardSource in _selectPlayer.SecurityCards)
  208. {
  209. RootCardList.Add(cardSource);
  210. }
  211. break;
  212. case Root.Recollection:
  213. foreach (CardSource cardSource in _selectPlayer.LostCards)
  214. {
  215. RootCardList.Add(cardSource);
  216. }
  217. break;
  218. }
  219. }
  220. else
  221. {
  222. foreach (CardSource cardSource in _customRootCardList)
  223. {
  224. RootCardList.Add(cardSource);
  225. }
  226. }
  227. return RootCardList;
  228. }
  229. private bool CanSelectCard(CardSource cardSource)
  230. {
  231. if (_root != Root.Library && _root != Root.Security && _root != Root.DigivolutionCards && _root != Root.Custom)
  232. {
  233. if (cardSource.IsFlipped)
  234. return false;
  235. }
  236. if (_canTargetCondition != null)
  237. {
  238. if (_canTargetCondition(cardSource))
  239. {
  240. if (!_allowFaceDown)
  241. {
  242. if (cardSource.IsFlipped)
  243. return false;
  244. }
  245. return true;
  246. }
  247. }
  248. return false;
  249. }
  250. public bool active()
  251. {
  252. if (RootCardList().Count > 0)
  253. {
  254. if (_root != Root.Library && _root != Root.Security)
  255. {
  256. if (RootCardList().Count(CanSelectCard) > 0)
  257. {
  258. return true;
  259. }
  260. }
  261. else
  262. {
  263. if (_root == Root.Library)
  264. SetUseFaceDown();
  265. if(_root == Root.Security)
  266. {
  267. if (_canLookReverseCard)
  268. SetUseFaceDown();
  269. }
  270. return true;
  271. }
  272. }
  273. return false;
  274. }
  275. public virtual IEnumerator Activate()
  276. {
  277. bool oldIsSelecting = GManager.instance.turnStateMachine.IsSelecting;
  278. List<CardSource> handCards = new List<CardSource>();
  279. _targetCards = new List<CardSource>();
  280. _slectedInexesInList = new List<int>();
  281. bool oldIsActiveOutline_AttackingPermanent = false;
  282. if (GManager.instance.attackProcess.AttackingPermanent != null)
  283. {
  284. if (GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard != null)
  285. {
  286. oldIsActiveOutline_AttackingPermanent = GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard.Outline_Select.gameObject.activeSelf;
  287. }
  288. }
  289. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  290. {
  291. GManager.instance.turnStateMachine.OffFieldCardTarget(player);
  292. GManager.instance.turnStateMachine.OffHandCardTarget(player);
  293. }
  294. if (GManager.instance.attackProcess.AttackingPermanent != null)
  295. {
  296. if (GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard != null)
  297. {
  298. GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard.Outline_Select.gameObject.SetActive(oldIsActiveOutline_AttackingPermanent);
  299. }
  300. }
  301. if (_maxCount == 0)
  302. {
  303. _canNoSelect = () => true;
  304. }
  305. if (_root == Root.Security)
  306. {
  307. SetIsSecurity();
  308. }
  309. if (active())
  310. {
  311. if (_isSecurity)
  312. {
  313. GManager.instance.turnStateMachine.gameContext.IsSecurityLooking = true;
  314. }
  315. if (_selectPlayer.isYou)
  316. {
  317. if ((_isDeckBottom && ContinuousController.instance.autoDeckBottomOrder)
  318. || (_isDeckTop && ContinuousController.instance.autoDeckTopOrder))
  319. {
  320. AutoSelect();
  321. }
  322. else
  323. {
  324. List<int> targetCardIDs = new List<int>();
  325. GManager.instance.turnStateMachine.IsSelecting = true;
  326. #region Message Display
  327. if (!string.IsNullOrEmpty(_customMessage))
  328. {
  329. GManager.instance.commandText.OpenCommandText(_customMessage, _isDigiXros, _isAssembly);
  330. }
  331. else
  332. {
  333. string message = "";
  334. switch (_mode)
  335. {
  336. case Mode.AddHand:
  337. message = "Select cards to add to your hand.";
  338. break;
  339. case Mode.Discard:
  340. message = "Select cards to trash.";
  341. break;
  342. case Mode.Custom:
  343. message = "Select cards.";
  344. break;
  345. }
  346. if (!string.IsNullOrEmpty(message))
  347. {
  348. GManager.instance.commandText.OpenCommandText(message, _isDigiXros, _isAssembly);
  349. }
  350. }
  351. #endregion
  352. List<CardSource> RootCards = new List<CardSource>();
  353. foreach (CardSource cardSource in RootCardList())
  354. {
  355. RootCards.Add(cardSource);
  356. }
  357. #region Sort
  358. if (_root == Root.Library || _root == Root.Trash)
  359. {
  360. RootCards = DeckData.SortedCardsList(RootCards);
  361. List<CardSource> matchConditionCards = new List<CardSource>();
  362. List<CardSource> notMatchConditionCards = new List<CardSource>();
  363. foreach (CardSource cardSource in RootCards)
  364. {
  365. if (CanSelectCard(cardSource))
  366. {
  367. matchConditionCards.Add(cardSource);
  368. }
  369. else
  370. {
  371. notMatchConditionCards.Add(cardSource);
  372. }
  373. }
  374. RootCards = new List<CardSource>();
  375. foreach (CardSource cardSource in matchConditionCards)
  376. {
  377. RootCards.Add(cardSource);
  378. }
  379. foreach (CardSource cardSource in notMatchConditionCards)
  380. {
  381. RootCards.Add(cardSource);
  382. }
  383. }
  384. #endregion
  385. #region Effect in progress/waiting to be activated
  386. if (_cardEffect != null)
  387. {
  388. if (_cardEffect.EffectSourceCard != null)
  389. {
  390. if (_skillInfos.Count == 0)
  391. {
  392. if (_root == Root.Trash || _root == Root.DigivolutionCards || _root == Root.LinkedCards)
  393. {
  394. SkillInfo[] skillInfoArray = new SkillInfo[RootCards.Count];
  395. for (int i = 0; i < skillInfoArray.Length; i++)
  396. {
  397. if (0 <= i && i <= RootCards.Count - 1)
  398. {
  399. if (RootCards[i] == _cardEffect.EffectSourceCard)
  400. {
  401. ICardEffect cardEffect = new ChangeBaseDPClass();
  402. cardEffect.SetUpICardEffect("Effect Processing", null, RootCards[i]);
  403. skillInfoArray[i] = new SkillInfo(cardEffect, null, EffectTiming.None);
  404. }
  405. else
  406. {
  407. if (GManager.instance.autoProcessing.executingMultipleSkills != null)
  408. {
  409. bool isEffectWaiting(SkillInfo skillInfo)
  410. {
  411. if (skillInfo != null)
  412. {
  413. if (skillInfo.CardEffect != null)
  414. {
  415. if (skillInfo.CardEffect.EffectSourceCard != null)
  416. {
  417. if (skillInfo.CardEffect.EffectSourceCard == RootCards[i])
  418. {
  419. return true;
  420. }
  421. }
  422. }
  423. }
  424. return false;
  425. }
  426. if (GManager.instance.autoProcessing.executingMultipleSkills.StackedSkillInfos.Count(isEffectWaiting) >= 1)
  427. {
  428. ICardEffect cardEffect = new ChangeBaseDPClass();
  429. cardEffect.SetUpICardEffect("Effect Waiting", null, RootCards[i]);
  430. skillInfoArray[i] = new SkillInfo(cardEffect, null, EffectTiming.None);
  431. }
  432. }
  433. }
  434. }
  435. }
  436. _skillInfos = skillInfoArray.ToList();
  437. }
  438. }
  439. }
  440. }
  441. #endregion
  442. GManager.instance.selectCardPanel._customCountText = _customCountText;
  443. yield return StartCoroutine(GManager.instance.selectCardPanel.OpenSelectCardPanel(
  444. Message: _message,
  445. RootCardSources: RootCards,
  446. _CanTargetCondition: CanSelectCard,
  447. _CanTargetCondition_ByPreSelecetedList: _canTargetCondition_ByPreSelecetedList,
  448. _CanEndSelectCondition: _canEndSelectCondition,
  449. _MaxCount: _maxCount,
  450. _CanEndNotMax: _canEndNotMax,
  451. _CanNoSelect: _canNoSelect,
  452. CanLookReverseCard: _canLookReverseCard,
  453. skillInfos: _skillInfos,
  454. root: _root));
  455. foreach (CardSource selectedCard in GManager.instance.selectCardPanel.SelectedList)
  456. {
  457. targetCardIDs.Add(selectedCard.CardIndex);
  458. }
  459. foreach (int selectedIndex in GManager.instance.selectCardPanel.SelectedIndex)
  460. {
  461. _slectedInexesInList.Add(selectedIndex);
  462. }
  463. if (_isLocal)
  464. {
  465. SetTargetCardAndIndicies(_selectPlayer.PlayerID, targetCardIDs.ToArray(), _slectedInexesInList.ToArray());
  466. }
  467. else
  468. {
  469. photonView.RPC("SetTargetCardAndIndicies", RpcTarget.All, _selectPlayer.PlayerID, targetCardIDs.ToArray(), _slectedInexesInList.ToArray());
  470. }
  471. }
  472. }
  473. else
  474. {
  475. if (!string.IsNullOrEmpty(_customMessage_Enemy))
  476. {
  477. GManager.instance.commandText.OpenCommandText(_customMessage_Enemy, _isDigiXros, _isAssembly);
  478. }
  479. else
  480. {
  481. GManager.instance.commandText.OpenCommandText("The opponent is selecting cards.", _isDigiXros, _isAssembly);
  482. }
  483. #region AI
  484. if (GManager.instance.IsAI)
  485. {
  486. AutoSelect();
  487. }
  488. #endregion
  489. }
  490. void AutoSelect()
  491. {
  492. List<CardSource> ValidCards = new List<CardSource>();
  493. foreach (CardSource cardSource in RootCardList())
  494. {
  495. if (CanSelectCard(cardSource))
  496. {
  497. ValidCards.Add(cardSource);
  498. }
  499. }
  500. IList<int> indexList = Enumerable.Range(0, ValidCards.Count).ToList();
  501. if (ValidCards.Count >= _maxCount)
  502. {
  503. for (int i = 0; i < 1000; i++)
  504. {
  505. List<int> GetIndexes = indexList.GetRandom(_maxCount).ToList();
  506. List<CardSource> GetCards = new List<CardSource>();
  507. foreach (int index in GetIndexes)
  508. {
  509. GetCards.Add(ValidCards[index]);
  510. }
  511. if (_canEndSelectCondition != null)
  512. {
  513. if (!_canEndSelectCondition(GetCards))
  514. {
  515. continue;
  516. }
  517. }
  518. List<int> CardIDs = new List<int>();
  519. foreach (CardSource cardSource in GetCards)
  520. {
  521. CardIDs.Add(cardSource.CardIndex);
  522. }
  523. if (GManager.instance.IsAI || _isLocal)
  524. {
  525. SetTargetCardAndIndicies(_selectPlayer.PlayerID, CardIDs.ToArray(), null);
  526. }
  527. else
  528. {
  529. photonView.RPC("SetTargetCardAndIndicies", RpcTarget.All, _selectPlayer.PlayerID, CardIDs.ToArray(), null);
  530. }
  531. break;
  532. }
  533. }
  534. }
  535. yield return new WaitUntil(() => _selectPlayer.HasPlayerSelection());
  536. CardSelection cardSelection = _selectPlayer.DequeuePlayerSelection<CardSelection>();
  537. if (cardSelection != null && cardSelection.CardIDList != null)
  538. {
  539. _targetCards = new List<CardSource>();
  540. foreach (int cardID in cardSelection.CardIDList)
  541. {
  542. _targetCards.Add(GManager.instance.turnStateMachine.gameContext.ActiveCardList[cardID]);
  543. }
  544. }
  545. yield return new WaitUntil(() => _selectPlayer.HasPlayerSelection());
  546. CardSelection indiciesSelection = _selectPlayer.DequeuePlayerSelection<CardSelection>();
  547. if (indiciesSelection != null && indiciesSelection.CardIDList != null)
  548. {
  549. _slectedInexesInList = new List<int>();
  550. foreach (int index in indiciesSelection.CardIDList)
  551. {
  552. _slectedInexesInList.Add(index);
  553. }
  554. }
  555. GManager.instance.commandText.CloseCommandText();
  556. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  557. #region Show selected card
  558. if (_targetCards.Count > 0 && _showCard)
  559. {
  560. if (_targetCards.Count((cardSource) => cardSource.IsFlipped) > 0 && !_showReverseCard)
  561. {
  562. //表示しない
  563. }
  564. else
  565. {
  566. if (_isShowOpponent || (_selectPlayer.isYou && _targetCards.Count((cardSource) => cardSource.Owner == _selectPlayer) > 0))
  567. {
  568. if (!string.IsNullOrEmpty(_customMessage_ShowCard))
  569. {
  570. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, _customMessage_ShowCard, true, true));
  571. }
  572. else
  573. {
  574. switch (_mode)
  575. {
  576. case Mode.AddHand:
  577. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Cards added to hand", true, true));
  578. break;
  579. case Mode.Discard:
  580. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Cards put on the trash", true, true));
  581. break;
  582. case Mode.Custom:
  583. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Selected Cards", true, true));
  584. break;
  585. }
  586. }
  587. }
  588. }
  589. }
  590. #endregion
  591. Hashtable hashtable = CardEffectCommons.CardEffectHashtable(_cardEffect);
  592. string log = "";
  593. if (_mode == Mode.AddHand)
  594. {
  595. log += $"\nCard{Utils.PluralFormSuffix(_targetCards.Count)} added to hand:";
  596. }
  597. else if (_mode == Mode.AddHand)
  598. {
  599. log += $"\nTrash Card{Utils.PluralFormSuffix(_targetCards.Count)}:";
  600. }
  601. else
  602. {
  603. log += $"\nSelected Card{Utils.PluralFormSuffix(_targetCards.Count)}:";
  604. }
  605. if (_root == Root.Library)
  606. {
  607. //yield return ContinuousController.instance.StartCoroutine(CardObjectController.Shuffle(_selectPlayer));
  608. }
  609. foreach (CardSource cardSource in _targetCards)
  610. {
  611. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  612. }
  613. switch (_mode)
  614. {
  615. case Mode.AddHand:
  616. foreach (CardSource cardSource in _targetCards)
  617. {
  618. cardSource.SetFace();
  619. if (cardSource.IsDigiEgg) yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource> { cardSource }));
  620. else
  621. {
  622. if (cardSource.PermanentOfThisCard() != null)
  623. {
  624. if (cardSource.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  625. {
  626. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
  627. }
  628. }
  629. handCards.Add(cardSource);
  630. }
  631. }
  632. break;
  633. case Mode.Discard:
  634. foreach (CardSource cardSource in _targetCards)
  635. {
  636. if (CardEffectCommons.IsExistOnHand(cardSource))
  637. {
  638. List<IDiscardHand> discardHands = _targetCards.Map(cardSource => new IDiscardHand(cardSource, hashtable));
  639. yield return ContinuousController.instance.StartCoroutine(new IDiscardHands(discardHands, _cardEffect).DiscardHands());
  640. }
  641. else if (CardEffectCommons.IsExistLinked(cardSource))
  642. {
  643. yield return ContinuousController.instance.StartCoroutine(new ITrashLinkCards(
  644. cardSource.PermanentOfThisCard(),
  645. new List<CardSource> { cardSource },
  646. _cardEffect).TrashLinkCards());
  647. }
  648. //After IsExistLinked, this would be digivolution cards, or topcard which should have been disbarred by selection condition.
  649. //ITrashDigiviolutionCards also refuses to do anything with a TopCard
  650. else if (CardEffectCommons.IsExistOnBattleArea(cardSource))
  651. {
  652. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  653. cardSource.PermanentOfThisCard(),
  654. new List<CardSource> { cardSource },
  655. _cardEffect).TrashDigivolutionCards());
  656. }
  657. else
  658. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  659. }
  660. break;
  661. case Mode.Custom:
  662. if (_selectCardCoroutine != null)
  663. {
  664. foreach (CardSource cardSource in _targetCards)
  665. {
  666. yield return StartCoroutine(_selectCardCoroutine(cardSource));
  667. }
  668. }
  669. break;
  670. }
  671. if (handCards.Count >= 1)
  672. {
  673. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, _cardEffect));
  674. }
  675. #region ログ追加
  676. if (!_notAddLog)
  677. {
  678. if (_isShowOpponent || _selectPlayer.isYou)
  679. {
  680. if (_targetCards.Count >= 1)
  681. {
  682. log += "\n";
  683. PlayLog.OnAddLog?.Invoke(log);
  684. }
  685. }
  686. }
  687. #endregion
  688. }
  689. if (_afterSelectCardCoroutine != null)
  690. {
  691. yield return StartCoroutine(_afterSelectCardCoroutine(_targetCards));
  692. }
  693. if (_afterSelectIndexCoroutine != null)
  694. {
  695. yield return StartCoroutine(_afterSelectIndexCoroutine(_slectedInexesInList));
  696. }
  697. GManager.instance.turnStateMachine.gameContext.IsSecurityLooking = false;
  698. GManager.instance.turnStateMachine.IsSelecting = oldIsSelecting;
  699. }
  700. [PunRPC]
  701. public void SetTargetCardAndIndicies(int playerID, int[] CardIDs, int[] Indicies)
  702. {
  703. Player player = GManager.instance.GetPlayerFromID(playerID);
  704. if (!player)
  705. {
  706. return;
  707. }
  708. player.QueuePlayerSelection(new CardSelection(CardIDs));
  709. player.QueuePlayerSelection(new CardSelection(Indicies));
  710. }
  711. }