SelectCardEffect.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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. bool oldIsActiveOutline_AttackingPermanent = false;
  284. if (GManager.instance.attackProcess.AttackingPermanent != null)
  285. {
  286. if (GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard != null)
  287. {
  288. oldIsActiveOutline_AttackingPermanent = GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard.Outline_Select.gameObject.activeSelf;
  289. }
  290. }
  291. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  292. {
  293. GManager.instance.turnStateMachine.OffFieldCardTarget(player);
  294. GManager.instance.turnStateMachine.OffHandCardTarget(player);
  295. }
  296. if (GManager.instance.attackProcess.AttackingPermanent != null)
  297. {
  298. if (GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard != null)
  299. {
  300. GManager.instance.attackProcess.AttackingPermanent.ShowingPermanentCard.Outline_Select.gameObject.SetActive(oldIsActiveOutline_AttackingPermanent);
  301. }
  302. }
  303. if (_maxCount == 0)
  304. {
  305. _canNoSelect = () => true;
  306. }
  307. if (_root == Root.Security)
  308. {
  309. SetIsSecurity();
  310. }
  311. if (active())
  312. {
  313. if (_isSecurity)
  314. {
  315. GManager.instance.turnStateMachine.gameContext.IsSecurityLooking = true;
  316. }
  317. if (_selectPlayer.isYou)
  318. {
  319. if ((_isDeckBottom && ContinuousController.instance.autoDeckBottomOrder)
  320. || (_isDeckTop && ContinuousController.instance.autoDeckTopOrder))
  321. {
  322. AutoSelect();
  323. }
  324. else
  325. {
  326. List<int> targetCardIDs = new List<int>();
  327. GManager.instance.turnStateMachine.IsSelecting = true;
  328. #region Message Display
  329. if (!string.IsNullOrEmpty(_customMessage))
  330. {
  331. GManager.instance.commandText.OpenCommandText(_customMessage, _isDigiXros, _isAssembly);
  332. }
  333. else
  334. {
  335. string message = "";
  336. switch (_mode)
  337. {
  338. case Mode.AddHand:
  339. message = "Select cards to add to your hand.";
  340. break;
  341. case Mode.Discard:
  342. message = "Select cards to trash.";
  343. break;
  344. case Mode.PlayForFree:
  345. message = "Select cards to play without paying the cost.";
  346. break;
  347. case Mode.PlayForCost:
  348. message = "Select cards to play.";
  349. break;
  350. case Mode.Custom:
  351. message = "Select cards.";
  352. break;
  353. }
  354. if (!string.IsNullOrEmpty(message))
  355. {
  356. GManager.instance.commandText.OpenCommandText(message, _isDigiXros, _isAssembly);
  357. }
  358. }
  359. #endregion
  360. List<CardSource> RootCards = new List<CardSource>();
  361. foreach (CardSource cardSource in RootCardList())
  362. {
  363. RootCards.Add(cardSource);
  364. }
  365. #region Sort
  366. if (_root == Root.Library || _root == Root.Trash)
  367. {
  368. RootCards = DeckData.SortedCardsList(RootCards);
  369. List<CardSource> matchConditionCards = new List<CardSource>();
  370. List<CardSource> notMatchConditionCards = new List<CardSource>();
  371. foreach (CardSource cardSource in RootCards)
  372. {
  373. if (CanSelectCard(cardSource))
  374. {
  375. matchConditionCards.Add(cardSource);
  376. }
  377. else
  378. {
  379. notMatchConditionCards.Add(cardSource);
  380. }
  381. }
  382. RootCards = new List<CardSource>();
  383. foreach (CardSource cardSource in matchConditionCards)
  384. {
  385. RootCards.Add(cardSource);
  386. }
  387. foreach (CardSource cardSource in notMatchConditionCards)
  388. {
  389. RootCards.Add(cardSource);
  390. }
  391. }
  392. #endregion
  393. #region Effect in progress/waiting to be activated
  394. if (_cardEffect != null)
  395. {
  396. if (_cardEffect.EffectSourceCard != null)
  397. {
  398. if (_skillInfos.Count == 0)
  399. {
  400. if (_root == Root.Trash || _root == Root.DigivolutionCards || _root == Root.LinkedCards)
  401. {
  402. SkillInfo[] skillInfoArray = new SkillInfo[RootCards.Count];
  403. for (int i = 0; i < skillInfoArray.Length; i++)
  404. {
  405. if (0 <= i && i <= RootCards.Count - 1)
  406. {
  407. if (RootCards[i] == _cardEffect.EffectSourceCard)
  408. {
  409. ICardEffect cardEffect = new ChangeBaseDPClass();
  410. cardEffect.SetUpICardEffect("Effect Processing", null, RootCards[i]);
  411. skillInfoArray[i] = new SkillInfo(cardEffect, null, EffectTiming.None);
  412. }
  413. else
  414. {
  415. if (GManager.instance.autoProcessing.executingMultipleSkills != null)
  416. {
  417. bool isEffectWaiting(SkillInfo skillInfo)
  418. {
  419. if (skillInfo != null)
  420. {
  421. if (skillInfo.CardEffect != null)
  422. {
  423. if (skillInfo.CardEffect.EffectSourceCard != null)
  424. {
  425. if (skillInfo.CardEffect.EffectSourceCard == RootCards[i])
  426. {
  427. return true;
  428. }
  429. }
  430. }
  431. }
  432. return false;
  433. }
  434. if (GManager.instance.autoProcessing.executingMultipleSkills.StackedSkillInfos.Count(isEffectWaiting) >= 1)
  435. {
  436. ICardEffect cardEffect = new ChangeBaseDPClass();
  437. cardEffect.SetUpICardEffect("Effect Waiting", null, RootCards[i]);
  438. skillInfoArray[i] = new SkillInfo(cardEffect, null, EffectTiming.None);
  439. }
  440. }
  441. }
  442. }
  443. }
  444. _skillInfos = skillInfoArray.ToList();
  445. }
  446. }
  447. }
  448. }
  449. #endregion
  450. GManager.instance.selectCardPanel._customCountText = _customCountText;
  451. yield return StartCoroutine(GManager.instance.selectCardPanel.OpenSelectCardPanel(
  452. Message: _message,
  453. RootCardSources: RootCards,
  454. _CanTargetCondition: CanSelectCard,
  455. _CanTargetCondition_ByPreSelecetedList: _canTargetCondition_ByPreSelecetedList,
  456. _CanEndSelectCondition: _canEndSelectCondition,
  457. _MaxCount: _maxCount,
  458. _CanEndNotMax: _canEndNotMax,
  459. _CanNoSelect: _canNoSelect,
  460. CanLookReverseCard: _canLookReverseCard,
  461. skillInfos: _skillInfos,
  462. root: _root));
  463. foreach (CardSource selectedCard in GManager.instance.selectCardPanel.SelectedList)
  464. {
  465. targetCardIDs.Add(selectedCard.CardIndex);
  466. }
  467. foreach (int selectedIndex in GManager.instance.selectCardPanel.SelectedIndex)
  468. {
  469. _slectedInexesInList.Add(selectedIndex);
  470. }
  471. if (_isLocal)
  472. {
  473. SetTargetCardAndIndicies(_selectPlayer.PlayerID, targetCardIDs.ToArray(), _slectedInexesInList.ToArray());
  474. }
  475. else
  476. {
  477. photonView.RPC("SetTargetCardAndIndicies", RpcTarget.All, _selectPlayer.PlayerID, targetCardIDs.ToArray(), _slectedInexesInList.ToArray());
  478. }
  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 || _isLocal)
  532. {
  533. SetTargetCardAndIndicies(_selectPlayer.PlayerID, CardIDs.ToArray(), null);
  534. }
  535. else
  536. {
  537. photonView.RPC("SetTargetCardAndIndicies", RpcTarget.All, _selectPlayer.PlayerID, CardIDs.ToArray(), null);
  538. }
  539. break;
  540. }
  541. }
  542. }
  543. yield return new WaitUntil(() => _selectPlayer.HasPlayerSelection());
  544. CardSelection cardSelection = _selectPlayer.DequeuePlayerSelection<CardSelection>();
  545. if (cardSelection != null && cardSelection.CardIDList != null)
  546. {
  547. _targetCards = new List<CardSource>();
  548. foreach (int cardID in cardSelection.CardIDList)
  549. {
  550. _targetCards.Add(GManager.instance.turnStateMachine.gameContext.ActiveCardList[cardID]);
  551. }
  552. }
  553. yield return new WaitUntil(() => _selectPlayer.HasPlayerSelection());
  554. CardSelection indiciesSelection = _selectPlayer.DequeuePlayerSelection<CardSelection>();
  555. if (indiciesSelection != null && indiciesSelection.CardIDList != null)
  556. {
  557. _slectedInexesInList = new List<int>();
  558. foreach (int index in indiciesSelection.CardIDList)
  559. {
  560. _slectedInexesInList.Add(index);
  561. }
  562. }
  563. GManager.instance.commandText.CloseCommandText();
  564. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  565. #region Show selected card
  566. if (_targetCards.Count > 0 && _showCard)
  567. {
  568. if (_targetCards.Count((cardSource) => cardSource.IsFlipped) > 0 && !_showReverseCard)
  569. {
  570. //表示しない
  571. }
  572. else
  573. {
  574. if (_isShowOpponent || (_selectPlayer.isYou && _targetCards.Count((cardSource) => cardSource.Owner == _selectPlayer) > 0))
  575. {
  576. if (!string.IsNullOrEmpty(_customMessage_ShowCard))
  577. {
  578. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, _customMessage_ShowCard, true, true));
  579. }
  580. else
  581. {
  582. switch (_mode)
  583. {
  584. case Mode.AddHand:
  585. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Cards added to hand", true, true));
  586. break;
  587. case Mode.Discard:
  588. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Cards put on the trash", true, true));
  589. break;
  590. case Mode.PlayForFree:
  591. case Mode.PlayForCost:
  592. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Played cards", true, true));
  593. break;
  594. case Mode.Custom:
  595. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Selected Cards", true, true));
  596. break;
  597. }
  598. }
  599. }
  600. }
  601. }
  602. #endregion
  603. Hashtable hashtable = CardEffectCommons.CardEffectHashtable(_cardEffect);
  604. string log = "";
  605. if (_mode == Mode.AddHand)
  606. {
  607. log += $"\nCard{Utils.PluralFormSuffix(_targetCards.Count)} added to hand:";
  608. }
  609. else if (_mode == Mode.AddHand)
  610. {
  611. log += $"\nTrash Card{Utils.PluralFormSuffix(_targetCards.Count)}:";
  612. }
  613. else
  614. {
  615. log += $"\nSelected Card{Utils.PluralFormSuffix(_targetCards.Count)}:";
  616. }
  617. if (_root == Root.Library)
  618. {
  619. //yield return ContinuousController.instance.StartCoroutine(CardObjectController.Shuffle(_selectPlayer));
  620. }
  621. foreach (CardSource cardSource in _targetCards)
  622. {
  623. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  624. }
  625. switch (_mode)
  626. {
  627. case Mode.AddHand:
  628. foreach (CardSource cardSource in _targetCards)
  629. {
  630. cardSource.SetFace();
  631. if (cardSource.IsDigiEgg) yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource> { cardSource }));
  632. else
  633. {
  634. if (cardSource.PermanentOfThisCard() != null)
  635. {
  636. if (cardSource.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  637. {
  638. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
  639. }
  640. }
  641. handCards.Add(cardSource);
  642. }
  643. }
  644. break;
  645. case Mode.Discard:
  646. foreach (CardSource cardSource in _targetCards)
  647. {
  648. if (CardEffectCommons.IsExistOnHand(cardSource))
  649. {
  650. List<IDiscardHand> discardHands = _targetCards.Map(cardSource => new IDiscardHand(cardSource, hashtable));
  651. yield return ContinuousController.instance.StartCoroutine(new IDiscardHands(discardHands, _cardEffect).DiscardHands());
  652. }
  653. else if (CardEffectCommons.IsExistLinked(cardSource))
  654. {
  655. yield return ContinuousController.instance.StartCoroutine(new ITrashLinkCards(
  656. cardSource.PermanentOfThisCard(),
  657. new List<CardSource> { cardSource },
  658. _cardEffect).TrashLinkCards());
  659. }
  660. //After IsExistLinked, this would be digivolution cards, or topcard which should have been disbarred by selection condition.
  661. //ITrashDigiviolutionCards also refuses to do anything with a TopCard
  662. else if (CardEffectCommons.IsExistOnBattleArea(cardSource))
  663. {
  664. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  665. cardSource.PermanentOfThisCard(),
  666. new List<CardSource> { cardSource },
  667. _cardEffect).TrashDigivolutionCards());
  668. }
  669. else
  670. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  671. }
  672. break;
  673. case Mode.PlayForFree:
  674. yield return ContinuousController.instance.StartCoroutine(
  675. CardEffectCommons.PlayPermanentCards(
  676. cardSources: _targetCards,
  677. activateClass: _cardEffect,
  678. payCost: false,
  679. isTapped: false,
  680. root: _root,
  681. activateETB: true));
  682. break;
  683. case Mode.PlayForCost:
  684. {
  685. bool PermanentsCondition(List<Permanent> targetPermanents)
  686. {
  687. if (targetPermanents == null)
  688. {
  689. return true;
  690. }
  691. else
  692. {
  693. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  694. {
  695. return true;
  696. }
  697. }
  698. return false;
  699. }
  700. bool SharedCardCondition(CardSource cardSource) => _targetCards.Contains(cardSource);
  701. bool RootCondition(SelectCardEffect.Root root) => true;
  702. bool CanUseCondition(Hashtable hashtable) => true;
  703. #region reduce cost
  704. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  705. if (_reduceCostTuple != null)
  706. {
  707. bool CardCondition(CardSource cardSource)
  708. {
  709. return SharedCardCondition(cardSource)
  710. && (_reduceCostTuple.Value.reduceCostCardCondition == null || _reduceCostTuple.Value.reduceCostCardCondition(cardSource));
  711. }
  712. int ChangeCost(CardSource cardSource, int Cost, Root root, List<Permanent> targetPermanents)
  713. {
  714. if (PermanentsCondition(targetPermanents))
  715. {
  716. Cost -= _reduceCostTuple.Value.reduceCost;
  717. }
  718. return Cost;
  719. }
  720. bool isUpDown() => true;
  721. ChangeCostClass changeCostClass = new ChangeCostClass();
  722. changeCostClass.SetUpICardEffect($"Play Cost -{_reduceCostTuple.Value.reduceCost}", CanUseCondition, _cardEffect.EffectSourceCard);
  723. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  724. getChangeCostEffect = GetCardEffect;
  725. ICardEffect GetCardEffect(EffectTiming _timing)
  726. {
  727. if (_timing == EffectTiming.None)
  728. {
  729. return changeCostClass;
  730. }
  731. return null;
  732. }
  733. if (getChangeCostEffect != null)
  734. {
  735. _selectPlayer.UntilCalculateFixedCostEffect.Add(getChangeCostEffect);
  736. }
  737. }
  738. #endregion
  739. #region set fixed cost
  740. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  741. if (_fixedCostTuple != null)
  742. {
  743. bool CardCondition(CardSource cardSource)
  744. {
  745. return SharedCardCondition(cardSource)
  746. && (_fixedCostTuple.Value.fixedCostCardCondition == null || _fixedCostTuple.Value.fixedCostCardCondition(cardSource));
  747. }
  748. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  749. {
  750. if (PermanentsCondition(targetPermanents))
  751. {
  752. Cost = _fixedCostTuple.Value.fixedCost;
  753. }
  754. return Cost;
  755. }
  756. bool isUpDown() => false;
  757. ChangeCostClass changeCostClass = new ChangeCostClass();
  758. changeCostClass.SetUpICardEffect($"Play Cost {_fixedCostTuple.Value.fixedCost}", CanUseCondition, _cardEffect.EffectSourceCard);
  759. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  760. getFixedCostEffect = GetCardEffect;
  761. ICardEffect GetCardEffect(EffectTiming _timing)
  762. {
  763. if (_timing == EffectTiming.None)
  764. {
  765. return changeCostClass;
  766. }
  767. return null;
  768. }
  769. if (getFixedCostEffect != null)
  770. {
  771. _selectPlayer.UntilCalculateFixedCostEffect.Add(getFixedCostEffect);
  772. }
  773. }
  774. #endregion
  775. yield return ContinuousController.instance.StartCoroutine(
  776. CardEffectCommons.PlayPermanentCards(
  777. cardSources: _targetCards,
  778. activateClass: _cardEffect,
  779. payCost: true,
  780. isTapped: false,
  781. root: SelectCardEffect.Root.Hand,
  782. activateETB: true));
  783. #region release effect
  784. if (getChangeCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  785. #endregion
  786. #region release effect
  787. if (getFixedCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  788. #endregion
  789. break;
  790. }
  791. case Mode.Custom:
  792. if (_selectCardCoroutine != null)
  793. {
  794. foreach (CardSource cardSource in _targetCards)
  795. {
  796. yield return StartCoroutine(_selectCardCoroutine(cardSource));
  797. }
  798. }
  799. break;
  800. }
  801. if (handCards.Count >= 1)
  802. {
  803. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, _cardEffect));
  804. }
  805. #region ログ追加
  806. if (!_notAddLog)
  807. {
  808. if (_isShowOpponent || _selectPlayer.isYou)
  809. {
  810. if (_targetCards.Count >= 1)
  811. {
  812. log += "\n";
  813. PlayLog.OnAddLog?.Invoke(log);
  814. }
  815. }
  816. }
  817. #endregion
  818. }
  819. if (_afterSelectCardCoroutine != null)
  820. {
  821. yield return StartCoroutine(_afterSelectCardCoroutine(_targetCards));
  822. }
  823. if (_afterSelectIndexCoroutine != null)
  824. {
  825. yield return StartCoroutine(_afterSelectIndexCoroutine(_slectedInexesInList));
  826. }
  827. GManager.instance.turnStateMachine.gameContext.IsSecurityLooking = false;
  828. GManager.instance.turnStateMachine.IsSelecting = oldIsSelecting;
  829. }
  830. [PunRPC]
  831. public void SetTargetCardAndIndicies(int playerID, int[] CardIDs, int[] Indicies)
  832. {
  833. Player player = GManager.instance.GetPlayerFromID(playerID);
  834. if (!player)
  835. {
  836. return;
  837. }
  838. player.QueuePlayerSelection(new CardSelection(CardIDs));
  839. player.QueuePlayerSelection(new CardSelection(Indicies));
  840. }
  841. }