ICardEffect.cs 33 KB

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