ICardEffect.cs 31 KB

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