ICardEffect.cs 29 KB

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