SelectCardEffect.cs 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  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. }