ICardEffect.cs 32 KB

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