ICardEffect.cs 30 KB

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