ICardEffect.cs 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  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 Effect availability determined by the maximum number of times it can be used in a turn
  228. if (EffectSourceCard.cEntity_EffectController.isOverMaxCountPerTurn(this, MaxCountPerTurn))
  229. {
  230. return false;
  231. }
  232. #endregion
  233. #region Determination of availability for each effect
  234. if (CanUseCondition == null || !CanUseCondition(hashtable))
  235. {
  236. return false;
  237. }
  238. #endregion
  239. return true;
  240. }
  241. #endregion
  242. #region Whether this triggering effect activates
  243. public bool CanActivate(Hashtable hashtable)
  244. {
  245. #region Effect availability determined by the maximum number of times it can be used in a turn
  246. if (EffectSourceCard.cEntity_EffectController.isOverMaxCountPerTurn(this, MaxCountPerTurn))
  247. {
  248. return false;
  249. }
  250. #endregion
  251. #region Determination of availability for each effect
  252. if (CanActivateCondition != null && !CanActivateCondition(hashtable))
  253. {
  254. return false;
  255. }
  256. #endregion
  257. #region Determination of availability for Inheritated/Linked Effect
  258. if (this is ActivateICardEffect)
  259. {
  260. if (EffectSourceCard != null)
  261. {
  262. if (EffectSourceCard.PermanentOfThisCard() != null)
  263. {
  264. if (IsInheritedEffect || IsLinkedEffect)
  265. {
  266. if (EffectSourceCard == EffectSourceCard.PermanentOfThisCard().TopCard)
  267. return false;
  268. if (EffectSourceCard.IsFlipped)
  269. return false;
  270. if (!EffectSourceCard.PermanentOfThisCard().IsDigimon)
  271. return false;
  272. if (IsLinkedEffect && !EffectSourceCard.PermanentOfThisCard().LinkedCards.Contains(EffectSourceCard))
  273. return false;
  274. }
  275. else
  276. {
  277. if (EffectSourceCard != EffectSourceCard.PermanentOfThisCard().TopCard)
  278. {
  279. return false;
  280. }
  281. }
  282. }
  283. }
  284. }
  285. #endregion
  286. #region Determination of availability due to be disabled
  287. if (IsDisabled)
  288. {
  289. return false;
  290. }
  291. #endregion
  292. //TODO: Look into this for the on deletion General issue
  293. #region Determination whether the permanent is same as when triggered
  294. if (IsInheritedEffect || IsLinkedEffect)
  295. {
  296. if (this is ActivateICardEffect)
  297. {
  298. Permanent PermanentWhenTriggered = ((ActivateICardEffect)this).PermanentWhenTriggered;
  299. if (PermanentWhenTriggered != null)
  300. {
  301. if (EffectSourceCard != null)
  302. {
  303. Permanent currentPermanent = EffectSourceCard.PermanentOfThisCard();
  304. if (currentPermanent != null)
  305. {
  306. if (currentPermanent != PermanentWhenTriggered)
  307. {
  308. return false;
  309. }
  310. }
  311. }
  312. }
  313. }
  314. }
  315. #endregion
  316. return true;
  317. }
  318. #endregion
  319. #region Whether this static effect applies , or this declarative effect can be declared
  320. public bool CanUse(Hashtable hashtable)
  321. {
  322. if (!CanTrigger(hashtable) || !CanActivate(hashtable))
  323. {
  324. return false;
  325. }
  326. return true;
  327. }
  328. #endregion
  329. #endregion
  330. #region Changable bool properties
  331. #region Whether this effect is an optional effect
  332. bool _isOptional = false;
  333. public bool IsOptional
  334. {
  335. get { return _isOptional; }
  336. private set { _isOptional = value; }
  337. }
  338. public void SetIsOptional(bool isOptional)
  339. {
  340. IsOptional = isOptional;
  341. }
  342. #endregion
  343. #region Whether to use this optional effect
  344. bool _useOptional = false;
  345. public bool UseOptional
  346. {
  347. get { return _useOptional; }
  348. private set { _useOptional = value; }
  349. }
  350. public void SetUseOptional(bool useOptional)
  351. {
  352. UseOptional = useOptional;
  353. }
  354. #endregion
  355. #region Whether this effect is a declarative effect
  356. bool _isDeclarative = false;
  357. public bool IsDeclarative
  358. {
  359. get { return _isDeclarative; }
  360. private set { _isDeclarative = value; }
  361. }
  362. public void SetIsDeclarative(bool isDeclarative)
  363. {
  364. IsDeclarative = isDeclarative;
  365. }
  366. #endregion
  367. #region Whether this effect is an Inherited Effect
  368. bool _isInheritedEffect = false;
  369. public bool IsInheritedEffect
  370. {
  371. get { return _isInheritedEffect; }
  372. private set { _isInheritedEffect = value; }
  373. }
  374. public void SetIsInheritedEffect(bool isInheritatedEffect)
  375. {
  376. IsInheritedEffect = isInheritatedEffect;
  377. }
  378. #endregion
  379. #region Whether this effect is an Linked Effect
  380. bool _isLinkededEffect = false;
  381. public bool IsLinkedEffect
  382. {
  383. get { return _isLinkededEffect; }
  384. private set { _isLinkededEffect = value; }
  385. }
  386. public void SetIsLinkedEffect(bool isLinkededEffect)
  387. {
  388. IsLinkedEffect = isLinkededEffect;
  389. }
  390. #endregion
  391. #region Whether this effect is an Security Effect
  392. bool _isSecurityEffect = false;
  393. public bool IsSecurityEffect
  394. {
  395. get { return _isSecurityEffect; }
  396. private set { _isSecurityEffect = value; }
  397. }
  398. public void SetIsSecurityEffect(bool isSecurityEffect)
  399. {
  400. IsSecurityEffect = isSecurityEffect;
  401. }
  402. #endregion
  403. #region Whether this effect is an Counter Effect
  404. bool _isCounterEffect = false;
  405. public bool IsCounterEffect
  406. {
  407. get { return _isCounterEffect; }
  408. private set { _isCounterEffect = value; }
  409. }
  410. public void SetIsCounterEffect(bool isCounterEffect)
  411. {
  412. IsCounterEffect = isCounterEffect;
  413. }
  414. #endregion
  415. #region Whether this effect is Digimon's effect
  416. bool _isDigimonEffect = false;
  417. public bool IsDigimonEffect
  418. {
  419. get { return _isDigimonEffect; }
  420. private set { _isDigimonEffect = value; }
  421. }
  422. public void SetIsDigimonEffect(bool isDigimonEffect)
  423. {
  424. IsDigimonEffect = isDigimonEffect;
  425. }
  426. #endregion
  427. #region Whether this effect is Tamer's effect
  428. bool _isTamerEffect = false;
  429. public bool IsTamerEffect
  430. {
  431. get { return _isTamerEffect; }
  432. private set { _isTamerEffect = value; }
  433. }
  434. public void SetIsTamerEffect(bool isTamerEffect)
  435. {
  436. IsTamerEffect = isTamerEffect;
  437. }
  438. #endregion
  439. #region How many times this effect can activate per chain
  440. int _chainActivations = -1;
  441. public int ChainActivations
  442. {
  443. get { return _chainActivations; }
  444. private set { _chainActivations = value; }
  445. }
  446. public void SetChainActivationCount(int chainActivations)
  447. {
  448. ChainActivations = chainActivations;
  449. }
  450. #endregion
  451. #region Whether this effect is carried out in the background
  452. bool _isBackgroundProcess = false;
  453. public bool IsBackgroundProcess
  454. {
  455. get { return _isBackgroundProcess; }
  456. private set { _isBackgroundProcess = value; }
  457. }
  458. public void SetIsBackgroundProcess(bool isBackgroundProcess)
  459. {
  460. IsBackgroundProcess = isBackgroundProcess;
  461. }
  462. #endregion
  463. #region Whether this effect should be displayed in the UI
  464. bool _isNotShowUI = false;
  465. public bool IsNotShowUI
  466. {
  467. get { return _isNotShowUI; }
  468. private set { _isNotShowUI = value; }
  469. }
  470. public void SetNotShowUI(bool isNotShowUI)
  471. {
  472. IsNotShowUI = isNotShowUI;
  473. }
  474. #endregion
  475. #endregion
  476. #region Read only bool properties
  477. #region Whether this effect is disabled
  478. public bool IsDisabled
  479. {
  480. get
  481. {
  482. return CheckEffectDisabledClass.isDisabled(this);
  483. }
  484. }
  485. #endregion
  486. #region Whether this effect is [On Play] effect
  487. public bool IsOnPlay
  488. {
  489. get
  490. {
  491. if (EffectSourceCard != null)
  492. {
  493. if (!string.IsNullOrEmpty(EffectDiscription))
  494. {
  495. Debug.Log($"Effect Description: {EffectDiscription.StartsWith("[On Play]")}");
  496. if (EffectDiscription.StartsWith("[On Play]"))
  497. {
  498. Hashtable hashtable = CardEffectCommons.OnPlayCheckHashtableOfCard(EffectSourceCard);
  499. Debug.Log($"Can Trigger: {CanTrigger(hashtable)}");
  500. if (CanTrigger(hashtable))
  501. {
  502. return true;
  503. }
  504. }
  505. }
  506. }
  507. return false;
  508. }
  509. }
  510. #endregion
  511. #region Whether this effect is [When Digivolving] effect
  512. public bool IsWhenDigivolving
  513. {
  514. get
  515. {
  516. if (EffectSourceCard != null)
  517. {
  518. if (!string.IsNullOrEmpty(EffectDiscription))
  519. {
  520. if (EffectDiscription.StartsWith("[When Digivolving]"))
  521. {
  522. Hashtable hashtable = CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(EffectSourceCard);
  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 [On Deletion] effect
  535. public bool IsOnDeletion
  536. {
  537. get
  538. {
  539. if (EffectSourceCard != null)
  540. {
  541. if (!string.IsNullOrEmpty(EffectDiscription))
  542. {
  543. if (EffectDiscription.StartsWith("[On Deletion]"))
  544. {
  545. Permanent effectPermanent = EffectSourceCard.PermanentOfThisCard() ?? new Permanent(new List<CardSource>() { EffectSourceCard });
  546. Hashtable hashtable = CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { effectPermanent }, null, null, false);
  547. if (CanTrigger(hashtable))
  548. {
  549. return true;
  550. }
  551. }
  552. }
  553. }
  554. return false;
  555. }
  556. }
  557. #endregion
  558. #region Whether this effect is [On Attack] effect
  559. public bool IsOnAttack
  560. {
  561. get
  562. {
  563. if (EffectSourceCard != null)
  564. {
  565. if (!string.IsNullOrEmpty(EffectDiscription))
  566. {
  567. if (EffectDiscription.StartsWith("[When Attacking]"))
  568. {
  569. Hashtable hashtable = CardEffectCommons.OnAttackCheckHashtableOfCard(EffectSourceCard, null);
  570. if (CanTrigger(hashtable))
  571. {
  572. return true;
  573. }
  574. }
  575. }
  576. }
  577. return false;
  578. }
  579. }
  580. #endregion
  581. #endregion
  582. #region Whether the target effect is the same as this effect
  583. public bool IsSameEffect(ICardEffect cardEffect)
  584. {
  585. if (cardEffect != null)
  586. {
  587. if (cardEffect == this)
  588. {
  589. return true;
  590. }
  591. if (cardEffect.EffectSourceCard != null)
  592. {
  593. if (this.EffectSourceCard != null)
  594. {
  595. if (cardEffect.EffectSourceCard == this.EffectSourceCard)
  596. {
  597. if (HasSameHashString() && HasSameRootCardEffect())
  598. {
  599. return true;
  600. }
  601. bool HasSameHashString()
  602. {
  603. if (string.IsNullOrEmpty(cardEffect.HashString))
  604. {
  605. if (string.IsNullOrEmpty(this.HashString))
  606. {
  607. return true;
  608. }
  609. }
  610. if (!string.IsNullOrEmpty(cardEffect.HashString))
  611. {
  612. if (!string.IsNullOrEmpty(this.HashString))
  613. {
  614. if (cardEffect.HashString == this.HashString)
  615. {
  616. return true;
  617. }
  618. }
  619. }
  620. return false;
  621. }
  622. bool HasSameRootCardEffect()
  623. {
  624. if (cardEffect.RootCardEffect == null)
  625. {
  626. if (this.RootCardEffect == null)
  627. {
  628. return true;
  629. }
  630. }
  631. if (cardEffect.RootCardEffect != null)
  632. {
  633. if (this.RootCardEffect != null)
  634. {
  635. if (cardEffect.RootCardEffect == this.RootCardEffect)
  636. {
  637. return true;
  638. }
  639. }
  640. }
  641. return false;
  642. }
  643. }
  644. }
  645. }
  646. }
  647. return false;
  648. }
  649. #endregion
  650. }
  651. #region Calculation order
  652. public enum CalculateOrder
  653. {
  654. UpValue,
  655. DownValue,
  656. UpToConstant,
  657. UpDownValue,
  658. DownToConstant,
  659. }
  660. #endregion
  661. #region Effect Duration
  662. public enum EffectDuration
  663. {
  664. UntilEachTurnEnd,
  665. UntilOpponentTurnEnd,
  666. UntilOwnerTurnEnd,
  667. UntilEndAttack,
  668. UntilEndBattle,
  669. UntilOwnerActivePhase,
  670. UntilCalculateFixedCost,
  671. UntilNextUntap,
  672. }
  673. #endregion
  674. #region Timing of effect triggers
  675. public enum EffectTiming
  676. {
  677. None,
  678. OnUseOption,
  679. OnDeclaration,
  680. OnEnterFieldAnyone,
  681. OnGetDamage,
  682. OptionSkill,
  683. OnDestroyedAnyone,
  684. WhenDigisorption,
  685. WhenRemoveField,
  686. WhenPermanentWouldBeDeleted,
  687. WhenReturntoLibraryAnyone,
  688. WhenReturntoHandAnyone,
  689. WhenUntapAnyone,
  690. OnEndAttackPhase,
  691. OnEndTurn,
  692. OnStartTurn,
  693. OnEndMainPhase,
  694. OnDraw,
  695. OnAddHand,
  696. OnLoseSecurity,
  697. OnAddSecurity,
  698. OnUseDigiburst,
  699. OnDiscardHand,
  700. OnDiscardSecurity,
  701. OnDiscardLibrary,
  702. OnKnockOut,
  703. OnMove,
  704. OnEndCoinToss,
  705. OnUseAttack,
  706. OnTappedAnyone,
  707. OnUnTappedAnyone,
  708. OnAddDigivolutionCards,
  709. OnAllyAttack,
  710. OnCounterTiming,
  711. OnBlockAnyone,
  712. OnSecurityCheck,
  713. OnAttackTargetChanged,
  714. OnEndBlockDesignation,
  715. SecuritySkill,
  716. OnStartMainPhase,
  717. OnStartBattle,
  718. OnEndBattle,
  719. OnDetermineDoSecurityCheck,
  720. OnEndAttack,
  721. BeforePayCost,
  722. AfterPayCost,
  723. OnDigivolutionCardDiscarded,
  724. OnDigivolutionCardReturnToDeckBottom,
  725. OnReturnCardsToLibraryFromTrash,
  726. OnPermamemtReturnedToHand,
  727. OnReturnCardsToHandFromTrash,
  728. AfterEffectsActivate,
  729. WhenWouldDigivolutionCardDiscarded,
  730. WhenLinked,
  731. WhenTopCardTrashed,
  732. RulesTiming,
  733. OnRemovedField,
  734. OnLinkCardDiscarded,
  735. OnFaceUpSecurityIncreased
  736. }
  737. #endregion
  738. #region card effect that processes
  739. public interface ActivateICardEffect
  740. {
  741. IEnumerator Activate(Hashtable hash);
  742. public Permanent PermanentWhenTriggered { get; set; }
  743. public CardSource TopCardWhenTriggered { get; set; }
  744. }
  745. public static class ActivateICardEffectExtensionClass
  746. {
  747. #region Optional
  748. public static IEnumerator Activate_Optional(this ActivateICardEffect activateICardEffect)
  749. {
  750. if (((ICardEffect)activateICardEffect).IsOptional)
  751. {
  752. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<OptionalSkill>().SelectOptional((ICardEffect)activateICardEffect));
  753. }
  754. }
  755. #endregion
  756. #region Effect
  757. public static IEnumerator Activate_Effect(this ActivateICardEffect activateICardEffect)
  758. {
  759. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  760. if (card != null)
  761. {
  762. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowActivateCardEffectDiscription((ICardEffect)activateICardEffect));
  763. Permanent permanent = card.PermanentOfThisCard();
  764. if (permanent != null)
  765. {
  766. if (permanent.ShowingPermanentCard != null)
  767. {
  768. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateFieldPokemonSkillEffect(permanent, (ICardEffect)activateICardEffect));
  769. }
  770. }
  771. else if (card.Owner.HandCards.Contains(card))
  772. {
  773. if (card.ShowingHandCard != null)
  774. {
  775. bool showEffect = false;
  776. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  777. {
  778. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  779. {
  780. showEffect = true;
  781. }
  782. }
  783. if (showEffect)
  784. {
  785. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateHandCardSkillEffect(card, (ICardEffect)activateICardEffect));
  786. }
  787. }
  788. }
  789. else if (CardEffectCommons.IsExistOnTrash(card))
  790. {
  791. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateTrashCardSkillEffect((ICardEffect)activateICardEffect));
  792. }
  793. else if (card.Owner.ExecutingCards.Contains(card))
  794. {
  795. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateExecutingCardSkillEffect(card, (ICardEffect)activateICardEffect));
  796. }
  797. yield return new WaitForSeconds(0.4f);
  798. }
  799. }
  800. #endregion
  801. #region Processing
  802. public static IEnumerator Activate_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash)
  803. {
  804. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  805. {
  806. ((ICardEffect)activateICardEffect).OnProcessCallbuck?.Invoke();
  807. ((ICardEffect)activateICardEffect).SetOnProcessCallbuck(null);
  808. //Handling Effect
  809. ((ICardEffect)activateICardEffect).EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(((ICardEffect)activateICardEffect));
  810. yield return ContinuousController.instance.StartCoroutine(activateICardEffect.Activate(hash));
  811. }
  812. }
  813. #endregion
  814. #region Optional→ Effect → Processing
  815. public static IEnumerator Activate_Optional_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, bool isCheckOptional = true, UnityAction<ICardEffect> useEffectCallback = null)
  816. {
  817. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  818. FieldPermanentCard fieldPermanentCard = null;
  819. HandCard handCard = null;
  820. if (card != null)
  821. {
  822. if (card.PermanentOfThisCard() != null)
  823. {
  824. fieldPermanentCard = card.PermanentOfThisCard().ShowingPermanentCard;
  825. }
  826. if (card.Owner.HandCards.Contains(card))
  827. {
  828. if (card.ShowingHandCard != null)
  829. {
  830. handCard = card.ShowingHandCard;
  831. }
  832. }
  833. }
  834. bool oldIsExecuting = GManager.instance.turnStateMachine.isExecuting;
  835. GManager.instance.turnStateMachine.isExecuting = true;
  836. if (fieldPermanentCard != null)
  837. {
  838. fieldPermanentCard.OnSelectEffect(1.1f);
  839. fieldPermanentCard.Outline_Select.gameObject.SetActive(true);
  840. fieldPermanentCard.SetOrangeOutline();
  841. }
  842. if (handCard != null)
  843. {
  844. if (card.Owner.isYou)
  845. {
  846. bool isHandEffect = false;
  847. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  848. {
  849. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  850. {
  851. isHandEffect = true;
  852. }
  853. }
  854. if (isHandEffect)
  855. {
  856. handCard.Outline_Select.SetActive(true);
  857. handCard.SetOrangeOutline();
  858. }
  859. }
  860. }
  861. UnityEngine.Debug.Log($"Activate_Optional_Effect_Execute: {(activateICardEffect is ICardEffect)}");
  862. if (activateICardEffect is ICardEffect)
  863. {
  864. UnityEngine.Debug.Log($"Activate_Optional_Effect_Execute: {((ICardEffect)activateICardEffect).EffectSourceCard.BaseENGCardNameFromEntity}");
  865. //Optional effect activation selection
  866. if (((ICardEffect)activateICardEffect).IsOptional)
  867. {
  868. if (isCheckOptional)
  869. {
  870. yield return ContinuousController.instance.StartCoroutine(Activate_Optional(activateICardEffect));
  871. }
  872. else
  873. {
  874. ((ICardEffect)activateICardEffect).SetUseOptional(true);
  875. }
  876. }
  877. //Optional effect activation selection → cost → processing
  878. yield return ContinuousController.instance.StartCoroutine(Activate_Effect_Execute(activateICardEffect, hash, useEffectCallback));
  879. }
  880. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  881. {
  882. player.TrashHandCard.gameObject.SetActive(false);
  883. player.TrashHandCard.IsExecuting = false;
  884. }
  885. yield return new WaitForSeconds(Time.deltaTime * 2);
  886. if (fieldPermanentCard != null)
  887. {
  888. fieldPermanentCard.OffUsingSkillEffect();
  889. fieldPermanentCard.OffSkillName();
  890. fieldPermanentCard.RemoveSelectEffect();
  891. }
  892. foreach (FieldPermanentCard fieldPokemonCard in card.Owner.FieldPermanentObjects)
  893. {
  894. fieldPokemonCard.OffUsingSkillEffect();
  895. fieldPokemonCard.OffSkillName();
  896. }
  897. if (handCard != null)
  898. {
  899. handCard.Outline_Select.SetActive(false);
  900. }
  901. if (card != null)
  902. {
  903. GManager.instance.turnStateMachine.isExecuting = oldIsExecuting;
  904. }
  905. }
  906. #endregion
  907. #region Effect → Processing
  908. public static IEnumerator Activate_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, UnityAction<ICardEffect> useEffectCallback)
  909. {
  910. //cost → effect processing
  911. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  912. {
  913. useEffectCallback?.Invoke((ICardEffect)activateICardEffect);
  914. Debug.Log($"{((ICardEffect)activateICardEffect).EffectName} was used");
  915. #region Add log
  916. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  917. if (card != null)
  918. {
  919. PlayLog.OnAddLog?.Invoke($"\nEffect:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n\"{((ICardEffect)activateICardEffect).EffectName}\"\n");
  920. }
  921. #endregion
  922. //effect
  923. yield return ContinuousController.instance.StartCoroutine(Activate_Effect(activateICardEffect));
  924. yield return ContinuousController.instance.StartCoroutine(Activate_Execute(activateICardEffect, hash));
  925. }
  926. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(null, EffectTiming.AfterEffectsActivate));
  927. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.RuleProcess());
  928. }
  929. #endregion
  930. }
  931. #endregion