ICardEffect.cs 32 KB

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