SelectCardEffect.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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. else
  647. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  648. }
  649. break;
  650. case Mode.PlayForFree:
  651. yield return ContinuousController.instance.StartCoroutine(
  652. CardEffectCommons.PlayPermanentCards(
  653. cardSources: _targetCards,
  654. activateClass: _cardEffect,
  655. payCost: false,
  656. isTapped: false,
  657. root: _root,
  658. activateETB: true));
  659. break;
  660. case Mode.PlayForCost:
  661. {
  662. bool PermanentsCondition(List<Permanent> targetPermanents)
  663. {
  664. if (targetPermanents == null)
  665. {
  666. return true;
  667. }
  668. else
  669. {
  670. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  671. {
  672. return true;
  673. }
  674. }
  675. return false;
  676. }
  677. bool SharedCardCondition(CardSource cardSource) => _targetCards.Contains(cardSource);
  678. bool RootCondition(SelectCardEffect.Root root) => true;
  679. bool CanUseCondition(Hashtable hashtable) => true;
  680. #region reduce cost
  681. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  682. if (_reduceCostTuple != null)
  683. {
  684. bool CardCondition(CardSource cardSource)
  685. {
  686. return SharedCardCondition(cardSource)
  687. && (_reduceCostTuple.Value.reduceCostCardCondition == null || _reduceCostTuple.Value.reduceCostCardCondition(cardSource));
  688. }
  689. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  690. {
  691. if (PermanentsCondition(targetPermanents))
  692. {
  693. Cost += _reduceCostTuple.Value.reduceCost;
  694. }
  695. return Cost;
  696. }
  697. bool isUpDown() => true;
  698. ChangeCostClass changeCostClass = new ChangeCostClass();
  699. changeCostClass.SetUpICardEffect($"Play Cost -{_reduceCostTuple.Value.reduceCost}", CanUseCondition, _cardEffect.EffectSourceCard);
  700. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  701. ICardEffect GetCardEffect(EffectTiming _timing)
  702. {
  703. if (_timing == EffectTiming.None)
  704. {
  705. return changeCostClass;
  706. }
  707. return null;
  708. }
  709. if (getChangeCostEffect != null)
  710. {
  711. _selectPlayer.UntilCalculateFixedCostEffect.Add(GetCardEffect);
  712. }
  713. }
  714. #endregion
  715. #region set fixed cost
  716. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  717. if (_fixedCostTuple != null)
  718. {
  719. bool CardCondition(CardSource cardSource)
  720. {
  721. return SharedCardCondition(cardSource)
  722. && (_fixedCostTuple.Value.fixedCostCardCondition == null || _fixedCostTuple.Value.fixedCostCardCondition(cardSource));
  723. }
  724. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  725. {
  726. if (PermanentsCondition(targetPermanents))
  727. {
  728. Cost = _fixedCostTuple.Value.fixedCost;
  729. }
  730. return Cost;
  731. }
  732. bool isUpDown() => false;
  733. ChangeCostClass changeCostClass = new ChangeCostClass();
  734. changeCostClass.SetUpICardEffect($"Play Cost -{_reduceCostTuple.Value.reduceCost}", CanUseCondition, _cardEffect.EffectSourceCard);
  735. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  736. ICardEffect GetCardEffect(EffectTiming _timing)
  737. {
  738. if (_timing == EffectTiming.None)
  739. {
  740. return changeCostClass;
  741. }
  742. return null;
  743. }
  744. if (getChangeCostEffect != null)
  745. {
  746. _selectPlayer.UntilCalculateFixedCostEffect.Add(GetCardEffect);
  747. }
  748. }
  749. #endregion
  750. yield return ContinuousController.instance.StartCoroutine(
  751. CardEffectCommons.PlayPermanentCards(
  752. cardSources: _targetCards,
  753. activateClass: _cardEffect,
  754. payCost: true,
  755. isTapped: false,
  756. root: SelectCardEffect.Root.Hand,
  757. activateETB: true));
  758. #region release effect
  759. if (getChangeCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  760. #endregion
  761. #region release effect
  762. if (getFixedCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  763. #endregion
  764. break;
  765. }
  766. case Mode.Custom:
  767. if (_selectCardCoroutine != null)
  768. {
  769. foreach (CardSource cardSource in _targetCards)
  770. {
  771. yield return StartCoroutine(_selectCardCoroutine(cardSource));
  772. }
  773. }
  774. break;
  775. }
  776. if (handCards.Count >= 1)
  777. {
  778. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, _cardEffect));
  779. }
  780. #region ログ追加
  781. if (!_notAddLog)
  782. {
  783. if (_isShowOpponent || _selectPlayer.isYou)
  784. {
  785. if (_targetCards.Count >= 1)
  786. {
  787. log += "\n";
  788. PlayLog.OnAddLog?.Invoke(log);
  789. }
  790. }
  791. }
  792. #endregion
  793. }
  794. if (_afterSelectCardCoroutine != null)
  795. {
  796. yield return StartCoroutine(_afterSelectCardCoroutine(_targetCards));
  797. }
  798. if (_afterSelectIndexCoroutine != null)
  799. {
  800. yield return StartCoroutine(_afterSelectIndexCoroutine(_slectedInexesInList));
  801. }
  802. GManager.instance.turnStateMachine.gameContext.IsSecurityLooking = false;
  803. GManager.instance.turnStateMachine.IsSelecting = oldIsSelecting;
  804. }
  805. [PunRPC]
  806. public void SetTargetCard(int[] CardIDs)
  807. {
  808. _targetCards = new List<CardSource>();
  809. foreach (int CardID in CardIDs)
  810. {
  811. _targetCards.Add(GManager.instance.turnStateMachine.gameContext.ActiveCardList[CardID]);
  812. }
  813. _endSelect = true;
  814. }
  815. [PunRPC]
  816. public void SetTargetIndicies(int[] CardIDs)
  817. {
  818. _slectedInexesInList = new List<int>();
  819. foreach (int index in CardIDs)
  820. {
  821. _slectedInexesInList.Add(index);
  822. }
  823. }
  824. }