ICardEffect.cs 34 KB

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