ICardEffect.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. using Photon.Pun;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.Events;
  7. //Card Effect
  8. public abstract class ICardEffect
  9. {
  10. #region Set up effect
  11. public void SetUpICardEffect(string effectName, Func<Hashtable, bool> canUseCondition, CardSource card)
  12. {
  13. SetEffectSourceCard(card);
  14. SetEffectSourcePermanent(null);
  15. SetMaxCountPerTurn(-1);
  16. SetEffectName(effectName);
  17. SetEffectDiscription("");
  18. SetHashString("");
  19. SetOnProcessCallbuck(null);
  20. SetRootCardEffect(null);
  21. SetCanUseCondition(canUseCondition);
  22. SetCanActivateCondition(null);
  23. SetIsOptional(false);
  24. SetUseOptional(false);
  25. SetIsDeclarative(false);
  26. SetIsInheritedEffect(false);
  27. SetIsSecurityEffect(false);
  28. SetIsCounterEffect(false);
  29. SetIsDigimonEffect(false);
  30. SetIsTamerEffect(false);
  31. SetChainActivationCount(-1);
  32. SetIsBackgroundProcess(false);
  33. SetNotShowUI(false);
  34. if (!(this is ActivateICardEffect))
  35. {
  36. SetIsDigimonEffect(card != null && CardEffectCommons.IsExistOnBattleArea(card) && card.PermanentOfThisCard().IsDigimon);
  37. SetIsTamerEffect(card != null && CardEffectCommons.IsExistOnBattleArea(card) && card.PermanentOfThisCard().IsTamer);
  38. }
  39. }
  40. #endregion
  41. #region The source card of this effect
  42. CardSource _effectSourceCard = null;
  43. public CardSource EffectSourceCard
  44. {
  45. get
  46. {
  47. if (EffectSourcePermanent != null)
  48. {
  49. if (EffectSourcePermanent.TopCard != null)
  50. {
  51. return EffectSourcePermanent.TopCard;
  52. }
  53. }
  54. return _effectSourceCard;
  55. }
  56. private set { _effectSourceCard = value; }
  57. }
  58. public void SetEffectSourceCard(CardSource effectSourceCard)
  59. {
  60. EffectSourceCard = effectSourceCard;
  61. }
  62. #endregion
  63. #region The source permanent of this effect
  64. private Permanent _effectSourcePermanent = null;
  65. public Permanent EffectSourcePermanent
  66. {
  67. get { return _effectSourcePermanent; }
  68. private set { _effectSourcePermanent = value; }
  69. }
  70. public void SetEffectSourcePermanent(Permanent effectSourcePermanent)
  71. {
  72. EffectSourcePermanent = effectSourcePermanent;
  73. }
  74. #endregion
  75. #region Maximum number of times this effect can be used in a turn
  76. int _maxCountPerTurn = 114514;
  77. public int MaxCountPerTurn
  78. {
  79. get { return _maxCountPerTurn; }
  80. private set
  81. {
  82. if (value > 0)
  83. {
  84. _maxCountPerTurn = value;
  85. }
  86. }
  87. }
  88. public void SetMaxCountPerTurn(int maxCountPerTurn)
  89. {
  90. MaxCountPerTurn = maxCountPerTurn;
  91. }
  92. #endregion
  93. #region Effect name
  94. string _effectName = "";
  95. public string EffectName
  96. {
  97. get { return _effectName; }
  98. private set
  99. {
  100. if (string.IsNullOrEmpty(value))
  101. {
  102. _effectName = "";
  103. }
  104. else
  105. {
  106. _effectName = value;
  107. }
  108. }
  109. }
  110. internal void SetEffectName(string effectName)
  111. {
  112. EffectName = effectName;
  113. }
  114. #endregion
  115. #region Effect discription
  116. string _effectDiscription = "";
  117. public string EffectDiscription
  118. {
  119. get { return _effectDiscription; }
  120. private set
  121. {
  122. if (string.IsNullOrEmpty(value))
  123. {
  124. _effectDiscription = "";
  125. }
  126. else
  127. {
  128. _effectDiscription = value;
  129. }
  130. }
  131. }
  132. internal void SetEffectDiscription(string effectDiscription)
  133. {
  134. EffectDiscription = effectDiscription;
  135. }
  136. #endregion
  137. #region Hash value for identification of same effects
  138. string _hashString = "";
  139. public string HashString
  140. {
  141. get { return _hashString; }
  142. private set
  143. {
  144. if (string.IsNullOrEmpty(value))
  145. {
  146. _hashString = "";
  147. }
  148. else
  149. {
  150. _hashString = value;
  151. }
  152. }
  153. }
  154. public void SetHashString(string hashString)
  155. {
  156. HashString = hashString;
  157. }
  158. #endregion
  159. #region Callbacks when this effect is executed
  160. UnityAction _onProcessCallbuck = null;
  161. public UnityAction OnProcessCallbuck
  162. {
  163. get { return _onProcessCallbuck; }
  164. private set { _onProcessCallbuck = value; }
  165. }
  166. public void SetOnProcessCallbuck(UnityAction onProcessCallbuck)
  167. {
  168. OnProcessCallbuck = onProcessCallbuck;
  169. }
  170. #endregion
  171. #region Effect giving this effect
  172. ICardEffect _rootCardEffect = null;
  173. public ICardEffect RootCardEffect
  174. {
  175. get { return _rootCardEffect; }
  176. private set { _rootCardEffect = value; }
  177. }
  178. public void SetRootCardEffect(ICardEffect rootCardEffect)
  179. {
  180. RootCardEffect = rootCardEffect;
  181. }
  182. #endregion
  183. #region Determine whether this effect can be used
  184. #region Condition for which this triggering effect triggers, this static effect applies or this declarative effect can be declared
  185. Func<Hashtable, bool> _canUseCondition = null;
  186. public Func<Hashtable, bool> CanUseCondition
  187. {
  188. get { return _canUseCondition; }
  189. private set { _canUseCondition = value; }
  190. }
  191. public void SetCanUseCondition(Func<Hashtable, bool> canUseCondition)
  192. {
  193. CanUseCondition = canUseCondition;
  194. }
  195. #endregion
  196. #region Condition for which this triggering effect activates
  197. Func<Hashtable, bool> _canActivateCondition = null;
  198. public Func<Hashtable, bool> CanActivateCondition
  199. {
  200. get { return _canActivateCondition; }
  201. private set { _canActivateCondition = value; }
  202. }
  203. public void SetCanActivateCondition(Func<Hashtable, bool> canActivateCondition)
  204. {
  205. CanActivateCondition = canActivateCondition;
  206. }
  207. #endregion
  208. #region Whether this triggering effect triggers
  209. public bool CanTrigger(Hashtable hashtable)
  210. {
  211. #region Effects not available before the start of the game
  212. if (GManager.instance != null)
  213. {
  214. if (GManager.instance.turnStateMachine != null)
  215. {
  216. if (GManager.instance.turnStateMachine.gameContext != null)
  217. {
  218. if (!GManager.instance.turnStateMachine.DoneStartGame)
  219. {
  220. return false;
  221. }
  222. }
  223. }
  224. }
  225. #endregion
  226. #region Determination of availability for each effect
  227. if (CanUseCondition == null || !CanUseCondition(hashtable))
  228. {
  229. return false;
  230. }
  231. #endregion
  232. return true;
  233. }
  234. #endregion
  235. #region Whether this triggering effect activates
  236. public bool CanActivate(Hashtable hashtable)
  237. {
  238. #region Effect availability determined by the maximum number of times it can be used in a turn
  239. if (EffectSourceCard.cEntity_EffectController.isOverMaxCountPerTurn(this, MaxCountPerTurn))
  240. {
  241. return false;
  242. }
  243. #endregion
  244. #region Determination of availability for each effect
  245. if (CanActivateCondition != null && !CanActivateCondition(hashtable))
  246. {
  247. return false;
  248. }
  249. #endregion
  250. #region Determination of availability for Inheritated Effect
  251. if (this is ActivateICardEffect)
  252. {
  253. if (EffectSourceCard != null)
  254. {
  255. if (EffectSourceCard.PermanentOfThisCard() != null)
  256. {
  257. if (IsInheritedEffect)
  258. {
  259. if (EffectSourceCard == EffectSourceCard.PermanentOfThisCard().TopCard)
  260. {
  261. return false;
  262. }
  263. if (!EffectSourceCard.PermanentOfThisCard().IsDigimon)
  264. {
  265. return false;
  266. }
  267. }
  268. else
  269. {
  270. if (EffectSourceCard != EffectSourceCard.PermanentOfThisCard().TopCard)
  271. {
  272. return false;
  273. }
  274. }
  275. }
  276. }
  277. }
  278. #endregion
  279. #region Determination of availability due to be disabled
  280. if (IsDisabled)
  281. {
  282. return false;
  283. }
  284. #endregion
  285. #region Determination whether the permanent is same as when triggered
  286. if (IsInheritedEffect)
  287. {
  288. if (this is ActivateICardEffect)
  289. {
  290. Permanent PermanentWhenTriggered = ((ActivateICardEffect)this).PermanentWhenTriggered;
  291. if (PermanentWhenTriggered != null)
  292. {
  293. if (EffectSourceCard != null)
  294. {
  295. Permanent currentPermanent = EffectSourceCard.PermanentOfThisCard();
  296. if (currentPermanent != null)
  297. {
  298. if (currentPermanent != PermanentWhenTriggered)
  299. {
  300. return false;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. }
  307. #endregion
  308. return true;
  309. }
  310. #endregion
  311. #region Whether this static effect applies , or this declarative effect can be declared
  312. public bool CanUse(Hashtable hashtable)
  313. {
  314. if (!CanTrigger(hashtable) || !CanActivate(hashtable))
  315. {
  316. return false;
  317. }
  318. return true;
  319. }
  320. #endregion
  321. #endregion
  322. #region Changable bool properties
  323. #region Whether this effect is an optional effect
  324. bool _isOptional = false;
  325. public bool IsOptional
  326. {
  327. get { return _isOptional; }
  328. private set { _isOptional = value; }
  329. }
  330. public void SetIsOptional(bool isOptional)
  331. {
  332. IsOptional = isOptional;
  333. }
  334. #endregion
  335. #region Whether to use this optional effect
  336. bool _useOptional = false;
  337. public bool UseOptional
  338. {
  339. get { return _useOptional; }
  340. private set { _useOptional = value; }
  341. }
  342. public void SetUseOptional(bool useOptional)
  343. {
  344. UseOptional = useOptional;
  345. }
  346. #endregion
  347. #region Whether this effect is a declarative effect
  348. bool _isDeclarative = false;
  349. public bool IsDeclarative
  350. {
  351. get { return _isDeclarative; }
  352. private set { _isDeclarative = value; }
  353. }
  354. public void SetIsDeclarative(bool isDeclarative)
  355. {
  356. IsDeclarative = isDeclarative;
  357. }
  358. #endregion
  359. #region Whether this effect is an Inherited Effect
  360. bool _isInheritedEffect = false;
  361. public bool IsInheritedEffect
  362. {
  363. get { return _isInheritedEffect; }
  364. private set { _isInheritedEffect = value; }
  365. }
  366. public void SetIsInheritedEffect(bool isInheritatedEffect)
  367. {
  368. IsInheritedEffect = isInheritatedEffect;
  369. }
  370. #endregion
  371. #region Whether this effect is an Security Effect
  372. bool _isSecurityEffect = false;
  373. public bool IsSecurityEffect
  374. {
  375. get { return _isSecurityEffect; }
  376. private set { _isSecurityEffect = value; }
  377. }
  378. public void SetIsSecurityEffect(bool isSecurityEffect)
  379. {
  380. IsSecurityEffect = isSecurityEffect;
  381. }
  382. #endregion
  383. #region Whether this effect is an Counter Effect
  384. bool _isCounterEffect = false;
  385. public bool IsCounterEffect
  386. {
  387. get { return _isCounterEffect; }
  388. private set { _isCounterEffect = value; }
  389. }
  390. public void SetIsCounterEffect(bool isCounterEffect)
  391. {
  392. IsCounterEffect = isCounterEffect;
  393. }
  394. #endregion
  395. #region Whether this effect is Digimon's effect
  396. bool _isDigimonEffect = false;
  397. public bool IsDigimonEffect
  398. {
  399. get { return _isDigimonEffect; }
  400. private set { _isDigimonEffect = value; }
  401. }
  402. public void SetIsDigimonEffect(bool isDigimonEffect)
  403. {
  404. IsDigimonEffect = isDigimonEffect;
  405. }
  406. #endregion
  407. #region Whether this effect is Tamer's effect
  408. bool _isTamerEffect = false;
  409. public bool IsTamerEffect
  410. {
  411. get { return _isTamerEffect; }
  412. private set { _isTamerEffect = value; }
  413. }
  414. public void SetIsTamerEffect(bool isTamerEffect)
  415. {
  416. IsTamerEffect = isTamerEffect;
  417. }
  418. #endregion
  419. #region How many times this effect can activate per chain
  420. int _chainActivations = -1;
  421. public int ChainActivations
  422. {
  423. get { return _chainActivations; }
  424. private set { _chainActivations = value; }
  425. }
  426. public void SetChainActivationCount(int chainActivations)
  427. {
  428. ChainActivations = chainActivations;
  429. }
  430. #endregion
  431. #region Whether this effect is carried out in the background
  432. bool _isBackgroundProcess = false;
  433. public bool IsBackgroundProcess
  434. {
  435. get { return _isBackgroundProcess; }
  436. private set { _isBackgroundProcess = value; }
  437. }
  438. public void SetIsBackgroundProcess(bool isBackgroundProcess)
  439. {
  440. IsBackgroundProcess = isBackgroundProcess;
  441. }
  442. #endregion
  443. #region Whether this effect should be displayed in the UI
  444. bool _isNotShowUI = false;
  445. public bool IsNotShowUI
  446. {
  447. get { return _isNotShowUI; }
  448. private set { _isNotShowUI = value; }
  449. }
  450. public void SetNotShowUI(bool isNotShowUI)
  451. {
  452. IsNotShowUI = isNotShowUI;
  453. }
  454. #endregion
  455. #endregion
  456. #region Read only bool properties
  457. #region Whether this effect is disabled
  458. public bool IsDisabled
  459. {
  460. get
  461. {
  462. return CheckEffectDisabledClass.isDisabled(this);
  463. }
  464. }
  465. #endregion
  466. #region Whether this effect is [On Play] effect
  467. public bool IsOnPlay
  468. {
  469. get
  470. {
  471. if (EffectSourceCard != null)
  472. {
  473. if (!string.IsNullOrEmpty(EffectDiscription))
  474. {
  475. if (EffectDiscription.Contains("[On Play]"))
  476. {
  477. Hashtable hashtable = CardEffectCommons.OnPlayCheckHashtableOfCard(EffectSourceCard);
  478. if (CanTrigger(hashtable))
  479. {
  480. return true;
  481. }
  482. }
  483. }
  484. }
  485. return false;
  486. }
  487. }
  488. #endregion
  489. #region Whether this effect is [When Digivolving] effect
  490. public bool IsWhenDigivolving
  491. {
  492. get
  493. {
  494. if (EffectSourceCard != null)
  495. {
  496. if (!string.IsNullOrEmpty(EffectDiscription))
  497. {
  498. if (EffectDiscription.Contains("[When Digivolving]"))
  499. {
  500. Hashtable hashtable = CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(EffectSourceCard);
  501. if (CanTrigger(hashtable))
  502. {
  503. return true;
  504. }
  505. }
  506. }
  507. }
  508. return false;
  509. }
  510. }
  511. #endregion
  512. #region Whether this effect is [On Deletion] effect
  513. public bool IsOnDeletion
  514. {
  515. get
  516. {
  517. if (EffectSourceCard != null)
  518. {
  519. if (!string.IsNullOrEmpty(EffectDiscription))
  520. {
  521. if (EffectDiscription.Contains("[On Deletion]"))
  522. {
  523. Permanent effectPermanent = EffectSourceCard.PermanentOfThisCard() ?? new Permanent(new List<CardSource>() { EffectSourceCard });
  524. Hashtable hashtable = CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { effectPermanent }, null, null, false);
  525. if (CanTrigger(hashtable))
  526. {
  527. return true;
  528. }
  529. }
  530. }
  531. }
  532. return false;
  533. }
  534. }
  535. #endregion
  536. #region Whether this effect is [On Attack] effect
  537. public bool IsOnAttack
  538. {
  539. get
  540. {
  541. if (EffectSourceCard != null)
  542. {
  543. if (!string.IsNullOrEmpty(EffectDiscription))
  544. {
  545. if (EffectDiscription.Contains("[When Attacking]"))
  546. {
  547. Hashtable hashtable = CardEffectCommons.OnAttackCheckHashtableOfCard(EffectSourceCard, null);
  548. if (CanTrigger(hashtable))
  549. {
  550. return true;
  551. }
  552. }
  553. }
  554. }
  555. return false;
  556. }
  557. }
  558. #endregion
  559. #endregion
  560. #region Whether the target effect is the same as this effect
  561. public bool IsSameEffect(ICardEffect cardEffect)
  562. {
  563. if (cardEffect != null)
  564. {
  565. if (cardEffect == this)
  566. {
  567. return true;
  568. }
  569. if (cardEffect.EffectSourceCard != null)
  570. {
  571. if (this.EffectSourceCard != null)
  572. {
  573. if (cardEffect.EffectSourceCard == this.EffectSourceCard)
  574. {
  575. if (HasSameHashString() && HasSameRootCardEffect())
  576. {
  577. return true;
  578. }
  579. bool HasSameHashString()
  580. {
  581. if (string.IsNullOrEmpty(cardEffect.HashString))
  582. {
  583. if (string.IsNullOrEmpty(this.HashString))
  584. {
  585. return true;
  586. }
  587. }
  588. if (!string.IsNullOrEmpty(cardEffect.HashString))
  589. {
  590. if (!string.IsNullOrEmpty(this.HashString))
  591. {
  592. if (cardEffect.HashString == this.HashString)
  593. {
  594. return true;
  595. }
  596. }
  597. }
  598. return false;
  599. }
  600. bool HasSameRootCardEffect()
  601. {
  602. if (cardEffect.RootCardEffect == null)
  603. {
  604. if (this.RootCardEffect == null)
  605. {
  606. return true;
  607. }
  608. }
  609. if (cardEffect.RootCardEffect != null)
  610. {
  611. if (this.RootCardEffect != null)
  612. {
  613. if (cardEffect.RootCardEffect == this.RootCardEffect)
  614. {
  615. return true;
  616. }
  617. }
  618. }
  619. return false;
  620. }
  621. }
  622. }
  623. }
  624. }
  625. return false;
  626. }
  627. #endregion
  628. }
  629. #region Calculation order
  630. public enum CalculateOrder
  631. {
  632. UpValue,
  633. DownValue,
  634. UpToConstant,
  635. UpDownValue,
  636. DownToConstant,
  637. }
  638. #endregion
  639. #region Effect Duration
  640. public enum EffectDuration
  641. {
  642. UntilEachTurnEnd,
  643. UntilOpponentTurnEnd,
  644. UntilOwnerTurnEnd,
  645. UntilEndAttack,
  646. UntilEndBattle,
  647. UntilOwnerActivePhase,
  648. UntilCalculateFixedCost,
  649. UntilNextUntap,
  650. }
  651. #endregion
  652. #region Timing of effect triggers
  653. public enum EffectTiming
  654. {
  655. None,
  656. OnUseOption,
  657. OnDeclaration,
  658. OnEnterFieldAnyone,
  659. OnGetDamage,
  660. OptionSkill,
  661. OnDestroyedAnyone,
  662. WhenDigisorption,
  663. WhenRemoveField,
  664. WhenPermanentWouldBeDeleted,
  665. WhenReturntoLibraryAnyone,
  666. WhenReturntoHandAnyone,
  667. WhenUntapAnyone,
  668. OnEndAttackPhase,
  669. OnEndTurn,
  670. OnStartTurn,
  671. OnEndMainPhase,
  672. OnDraw,
  673. OnAddHand,
  674. OnLoseSecurity,
  675. OnAddSecurity,
  676. OnUseDigiburst,
  677. OnDiscardHand,
  678. OnDiscardSecurity,
  679. OnDiscardLibrary,
  680. OnKnockOut,
  681. OnMove,
  682. OnEndCoinToss,
  683. OnUseAttack,
  684. OnTappedAnyone,
  685. OnUnTappedAnyone,
  686. OnAddDigivolutionCards,
  687. OnAllyAttack,
  688. OnCounterTiming,
  689. OnBlockAnyone,
  690. OnSecurityCheck,
  691. OnAttackTargetChanged,
  692. OnEndBlockDesignation,
  693. SecuritySkill,
  694. OnStartMainPhase,
  695. OnStartBattle,
  696. OnEndBattle,
  697. OnDetermineDoSecurityCheck,
  698. OnEndAttack,
  699. BeforePayCost,
  700. AfterPayCost,
  701. OnDigivolutionCardDiscarded,
  702. OnDigivolutionCardReturnToDeckBottom,
  703. OnReturnCardsToLibraryFromTrash,
  704. OnPermamemtReturnedToHand,
  705. OnReturnCardsToHandFromTrash,
  706. AfterEffectsActivate,
  707. WhenWouldDigivolutionCardDiscarded,
  708. }
  709. #endregion
  710. #region card effect that processes
  711. public interface ActivateICardEffect
  712. {
  713. IEnumerator Activate(Hashtable hash);
  714. public Permanent PermanentWhenTriggered { get; set; }
  715. public CardSource TopCardWhenTriggered { get; set; }
  716. }
  717. public static class ActivateICardEffectExtensionClass
  718. {
  719. #region Optional
  720. public static IEnumerator Activate_Optional(this ActivateICardEffect activateICardEffect)
  721. {
  722. if (((ICardEffect)activateICardEffect).IsOptional)
  723. {
  724. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<OptionalSkill>().SelectOptional((ICardEffect)activateICardEffect));
  725. }
  726. }
  727. #endregion
  728. #region Effect
  729. public static IEnumerator Activate_Effect(this ActivateICardEffect activateICardEffect)
  730. {
  731. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  732. if (card != null)
  733. {
  734. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowActivateCardEffectDiscription((ICardEffect)activateICardEffect));
  735. Permanent permanent = card.PermanentOfThisCard();
  736. if (permanent != null)
  737. {
  738. if (permanent.ShowingPermanentCard != null)
  739. {
  740. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateFieldPokemonSkillEffect(permanent, (ICardEffect)activateICardEffect));
  741. }
  742. }
  743. else if (card.Owner.HandCards.Contains(card))
  744. {
  745. if (card.ShowingHandCard != null)
  746. {
  747. bool showEffect = false;
  748. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  749. {
  750. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  751. {
  752. showEffect = true;
  753. }
  754. }
  755. if (showEffect)
  756. {
  757. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateHandCardSkillEffect(card, (ICardEffect)activateICardEffect));
  758. }
  759. }
  760. }
  761. else if (CardEffectCommons.IsExistOnTrash(card))
  762. {
  763. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateTrashCardSkillEffect((ICardEffect)activateICardEffect));
  764. }
  765. else if (card.Owner.ExecutingCards.Contains(card))
  766. {
  767. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateExecutingCardSkillEffect(card, (ICardEffect)activateICardEffect));
  768. }
  769. yield return new WaitForSeconds(0.4f);
  770. }
  771. }
  772. #endregion
  773. #region Processing
  774. public static IEnumerator Activate_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash)
  775. {
  776. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  777. {
  778. ((ICardEffect)activateICardEffect).OnProcessCallbuck?.Invoke();
  779. ((ICardEffect)activateICardEffect).SetOnProcessCallbuck(null);
  780. //Handling Effects
  781. yield return ContinuousController.instance.StartCoroutine(activateICardEffect.Activate(hash));
  782. }
  783. }
  784. #endregion
  785. #region Optional→ Effect → Processing
  786. public static IEnumerator Activate_Optional_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, bool isCheckOptional = true, UnityAction<ICardEffect> useEffectCallback = null)
  787. {
  788. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  789. FieldPermanentCard fieldPermanentCard = null;
  790. HandCard handCard = null;
  791. if (card != null)
  792. {
  793. if (card.PermanentOfThisCard() != null)
  794. {
  795. fieldPermanentCard = card.PermanentOfThisCard().ShowingPermanentCard;
  796. }
  797. if (card.Owner.HandCards.Contains(card))
  798. {
  799. if (card.ShowingHandCard != null)
  800. {
  801. handCard = card.ShowingHandCard;
  802. }
  803. }
  804. }
  805. bool oldIsExecuting = GManager.instance.turnStateMachine.isExecuting;
  806. GManager.instance.turnStateMachine.isExecuting = true;
  807. if (fieldPermanentCard != null)
  808. {
  809. fieldPermanentCard.OnSelectEffect(1.1f);
  810. fieldPermanentCard.Outline_Select.gameObject.SetActive(true);
  811. fieldPermanentCard.SetOrangeOutline();
  812. }
  813. if (handCard != null)
  814. {
  815. if (card.Owner.isYou)
  816. {
  817. bool isHandEffect = false;
  818. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  819. {
  820. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  821. {
  822. isHandEffect = true;
  823. }
  824. }
  825. if (isHandEffect)
  826. {
  827. handCard.Outline_Select.SetActive(true);
  828. handCard.SetOrangeOutline();
  829. }
  830. }
  831. }
  832. UnityEngine.Debug.Log($"Activate_Optional_Effect_Execute: {(activateICardEffect is ICardEffect)}");
  833. if (activateICardEffect is ICardEffect)
  834. {
  835. UnityEngine.Debug.Log($"Activate_Optional_Effect_Execute: {((ICardEffect)activateICardEffect).EffectSourceCard.BaseENGCardNameFromEntity}");
  836. //Optional effect activation selection
  837. if (((ICardEffect)activateICardEffect).IsOptional)
  838. {
  839. if (isCheckOptional)
  840. {
  841. yield return ContinuousController.instance.StartCoroutine(Activate_Optional(activateICardEffect));
  842. }
  843. else
  844. {
  845. ((ICardEffect)activateICardEffect).SetUseOptional(true);
  846. }
  847. }
  848. //Optional effect activation selection → cost → processing
  849. yield return ContinuousController.instance.StartCoroutine(Activate_Effect_Execute(activateICardEffect, hash, useEffectCallback));
  850. }
  851. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  852. {
  853. player.TrashHandCard.gameObject.SetActive(false);
  854. player.TrashHandCard.IsExecuting = false;
  855. }
  856. yield return new WaitForSeconds(Time.deltaTime * 2);
  857. if (fieldPermanentCard != null)
  858. {
  859. fieldPermanentCard.OffUsingSkillEffect();
  860. fieldPermanentCard.OffSkillName();
  861. fieldPermanentCard.RemoveSelectEffect();
  862. }
  863. foreach (FieldPermanentCard fieldPokemonCard in card.Owner.FieldPermanentObjects)
  864. {
  865. fieldPokemonCard.OffUsingSkillEffect();
  866. fieldPokemonCard.OffSkillName();
  867. }
  868. if (handCard != null)
  869. {
  870. handCard.Outline_Select.SetActive(false);
  871. }
  872. if (card != null)
  873. {
  874. GManager.instance.turnStateMachine.isExecuting = oldIsExecuting;
  875. }
  876. }
  877. #endregion
  878. #region Effect → Processing
  879. public static IEnumerator Activate_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, UnityAction<ICardEffect> useEffectCallback)
  880. {
  881. //cost → effect processing
  882. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  883. {
  884. useEffectCallback?.Invoke((ICardEffect)activateICardEffect);
  885. Debug.Log($"{((ICardEffect)activateICardEffect).EffectName} was used");
  886. #region Add log
  887. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  888. if (card != null)
  889. {
  890. PlayLog.OnAddLog?.Invoke($"\nEffect:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n\"{((ICardEffect)activateICardEffect).EffectName}\"\n");
  891. }
  892. #endregion
  893. //effect
  894. yield return ContinuousController.instance.StartCoroutine(Activate_Effect(activateICardEffect));
  895. yield return ContinuousController.instance.StartCoroutine(Activate_Execute(activateICardEffect, hash));
  896. }
  897. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.RuleProcess());
  898. }
  899. #endregion
  900. }
  901. #endregion