ICardEffect.cs 32 KB

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