ICardEffect.cs 32 KB

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