ICardEffect.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  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. bool CardBelowBecameTopMostCard = EffectSourceCard == EffectSourceCard.PermanentOfThisCard().TopCard;
  302. if (CardBelowBecameTopMostCard)
  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. #region Determination whether the permanent is same as when triggered
  311. bool CardBelowMovedFromUnderPermanentToAnother;
  312. if (((ActivateICardEffect)this).PermanentWhenTriggered != null)
  313. {
  314. if (EffectSourceCard != null)
  315. {
  316. Permanent currentPermanent = EffectSourceCard.PermanentOfThisCard();
  317. if (currentPermanent != null)
  318. {
  319. CardBelowMovedFromUnderPermanentToAnother = currentPermanent != ((ActivateICardEffect)this).PermanentWhenTriggered;
  320. if (CardBelowMovedFromUnderPermanentToAnother)
  321. {
  322. return false;
  323. }
  324. }
  325. }
  326. }
  327. #endregion
  328. }
  329. else
  330. {
  331. if (EffectSourceCard != EffectSourceCard.PermanentOfThisCard().TopCard)
  332. {
  333. return false;
  334. }
  335. }
  336. }
  337. }
  338. }
  339. #endregion
  340. #region Determination of availability due to be disabled
  341. if (IsDisabled)
  342. {
  343. return false;
  344. }
  345. #endregion
  346. return true;
  347. }
  348. #endregion
  349. #region Whether this static effect applies , or this declarative effect can be declared
  350. public bool CanUse(Hashtable hashtable)
  351. {
  352. if (!CanTrigger(hashtable) || !CanActivate(hashtable))
  353. {
  354. return false;
  355. }
  356. return true;
  357. }
  358. #endregion
  359. #endregion
  360. #region Changable bool properties
  361. #region Whether this effect is an optional effect
  362. bool _isOptional = false;
  363. public bool IsOptional
  364. {
  365. get { return _isOptional; }
  366. private set { _isOptional = value; }
  367. }
  368. public void SetIsOptional(bool isOptional)
  369. {
  370. IsOptional = isOptional;
  371. }
  372. #endregion
  373. #region Whether to use this optional effect
  374. bool _useOptional = false;
  375. public bool UseOptional
  376. {
  377. get { return _useOptional; }
  378. private set { _useOptional = value; }
  379. }
  380. public void SetUseOptional(bool useOptional)
  381. {
  382. UseOptional = useOptional;
  383. }
  384. #endregion
  385. #region Whether this effect is a declarative effect
  386. bool _isDeclarative = false;
  387. public bool IsDeclarative
  388. {
  389. get { return _isDeclarative; }
  390. private set { _isDeclarative = value; }
  391. }
  392. public void SetIsDeclarative(bool isDeclarative)
  393. {
  394. IsDeclarative = isDeclarative;
  395. }
  396. #endregion
  397. #region Whether this effect is an Inherited Effect
  398. bool _isInheritedEffect = false;
  399. public bool IsInheritedEffect
  400. {
  401. get { return _isInheritedEffect; }
  402. private set { _isInheritedEffect = value; }
  403. }
  404. public void SetIsInheritedEffect(bool isInheritatedEffect)
  405. {
  406. IsInheritedEffect = isInheritatedEffect;
  407. }
  408. #endregion
  409. #region Whether this effect is an Linked Effect
  410. bool _isLinkededEffect = false;
  411. public bool IsLinkedEffect
  412. {
  413. get { return _isLinkededEffect; }
  414. private set { _isLinkededEffect = value; }
  415. }
  416. public void SetIsLinkedEffect(bool isLinkededEffect)
  417. {
  418. IsLinkedEffect = isLinkededEffect;
  419. }
  420. #endregion
  421. #region Whether this effect is an Security Effect
  422. bool _isSecurityEffect = false;
  423. public bool IsSecurityEffect
  424. {
  425. get { return _isSecurityEffect; }
  426. private set { _isSecurityEffect = value; }
  427. }
  428. public void SetIsSecurityEffect(bool isSecurityEffect)
  429. {
  430. IsSecurityEffect = isSecurityEffect;
  431. }
  432. #endregion
  433. #region Whether this effect is an Counter Effect
  434. bool _isCounterEffect = false;
  435. public bool IsCounterEffect
  436. {
  437. get { return _isCounterEffect; }
  438. private set { _isCounterEffect = value; }
  439. }
  440. public void SetIsCounterEffect(bool isCounterEffect)
  441. {
  442. IsCounterEffect = isCounterEffect;
  443. }
  444. #endregion
  445. #region Whether this effect is Digimon's effect
  446. bool _isDigimonEffect = false;
  447. public bool IsDigimonEffect
  448. {
  449. get { return _isDigimonEffect; }
  450. private set { _isDigimonEffect = value; }
  451. }
  452. public void SetIsDigimonEffect(bool isDigimonEffect)
  453. {
  454. IsDigimonEffect = isDigimonEffect;
  455. }
  456. #endregion
  457. #region Whether this effect is Tamer's effect
  458. bool _isTamerEffect = false;
  459. public bool IsTamerEffect
  460. {
  461. get { return _isTamerEffect; }
  462. private set { _isTamerEffect = value; }
  463. }
  464. public void SetIsTamerEffect(bool isTamerEffect)
  465. {
  466. IsTamerEffect = isTamerEffect;
  467. }
  468. #endregion
  469. #region Whether this is specifically an Option Card effect, overriding anything settign it as a Digimon or Tamer effect
  470. bool _isOptionEffect = false;
  471. public bool IsOptionEffect
  472. {
  473. get { return _isOptionEffect; }
  474. private set { _isOptionEffect = value; }
  475. }
  476. public void SetIsOptionEffect(bool isOptionEffect)
  477. {
  478. IsOptionEffect = isOptionEffect;
  479. }
  480. #endregion
  481. #region How many times this effect can activate per chain
  482. int _chainActivations = -1;
  483. public int ChainActivations
  484. {
  485. get { return _chainActivations; }
  486. private set { _chainActivations = value; }
  487. }
  488. public void SetChainActivationCount(int chainActivations)
  489. {
  490. ChainActivations = chainActivations;
  491. }
  492. #endregion
  493. #region Whether this effect is carried out in the background
  494. bool _isBackgroundProcess = false;
  495. public bool IsBackgroundProcess
  496. {
  497. get { return _isBackgroundProcess; }
  498. private set { _isBackgroundProcess = value; }
  499. }
  500. public void SetIsBackgroundProcess(bool isBackgroundProcess)
  501. {
  502. IsBackgroundProcess = isBackgroundProcess;
  503. }
  504. #endregion
  505. #region Whether this effect should be displayed in the UI
  506. bool _isNotShowUI = false;
  507. public bool IsNotShowUI
  508. {
  509. get { return _isNotShowUI; }
  510. private set { _isNotShowUI = value; }
  511. }
  512. public void SetNotShowUI(bool isNotShowUI)
  513. {
  514. IsNotShowUI = isNotShowUI;
  515. }
  516. #endregion
  517. #region When this effect was activated for comparison
  518. DateTime _activatedTime = DateTime.MinValue;
  519. public DateTime ActivatedTime
  520. {
  521. get { return _activatedTime; }
  522. private set { _activatedTime = value; }
  523. }
  524. public void SetActivatedTime(params DateTime[] activationTimes)
  525. {
  526. if (activationTimes.Length > 0)
  527. {
  528. DateTime latest = activationTimes[0];
  529. foreach (DateTime time in activationTimes)
  530. {
  531. if (time > latest) latest = time;
  532. }
  533. _activatedTime = latest;
  534. }
  535. }
  536. #endregion
  537. #endregion
  538. #region Read only bool properties
  539. #region Whether this effect is disabled
  540. public bool IsDisabled
  541. {
  542. get
  543. {
  544. return CheckEffectDisabledClass.isDisabled(this);
  545. }
  546. }
  547. #endregion
  548. #region Whether this effect is [On Play] effect
  549. public bool IsOnPlay
  550. {
  551. get
  552. {
  553. if (EffectSourceCard != null)
  554. {
  555. if (!string.IsNullOrEmpty(EffectDiscription))
  556. {
  557. Debug.Log($"Effect Description: {EffectDiscription.StartsWith("[On Play]")}");
  558. if (EffectDiscription.StartsWith("[On Play]"))
  559. {
  560. Hashtable hashtable = CardEffectCommons.OnPlayCheckHashtableOfCard(EffectSourceCard);
  561. Debug.Log($"Can Trigger: {CanTrigger(hashtable)}");
  562. if (CanTrigger(hashtable))
  563. {
  564. return true;
  565. }
  566. }
  567. }
  568. }
  569. return false;
  570. }
  571. }
  572. #endregion
  573. #region Whether this effect is [When Digivolving] effect
  574. public bool IsWhenDigivolving
  575. {
  576. get
  577. {
  578. if (EffectSourceCard != null)
  579. {
  580. if (!string.IsNullOrEmpty(EffectDiscription))
  581. {
  582. if (EffectDiscription.StartsWith("[When Digivolving]"))
  583. {
  584. Hashtable hashtable = CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(EffectSourceCard);
  585. if (CanTrigger(hashtable))
  586. {
  587. return true;
  588. }
  589. }
  590. }
  591. }
  592. return false;
  593. }
  594. }
  595. #endregion
  596. #region Whether this effect is [On Deletion] effect
  597. public bool IsOnDeletion
  598. {
  599. get
  600. {
  601. if (EffectSourceCard != null)
  602. {
  603. if (!string.IsNullOrEmpty(EffectDiscription))
  604. {
  605. if (EffectDiscription.StartsWith("[On Deletion]"))
  606. {
  607. // Permanent effectPermanent = EffectSourceCard.PermanentOfThisCard() ?? new Permanent(new List<CardSource>() { EffectSourceCard });
  608. // Hashtable hashtable = CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { effectPermanent }, null, null, false);
  609. // if (CanTrigger(hashtable))
  610. return true;
  611. }
  612. }
  613. }
  614. return false;
  615. }
  616. }
  617. #endregion
  618. #region Whether this effect is [On Attack] effect
  619. public bool IsOnAttack
  620. {
  621. get
  622. {
  623. if (EffectSourceCard != null)
  624. {
  625. if (!string.IsNullOrEmpty(EffectDiscription))
  626. {
  627. if (EffectDiscription.StartsWith("[When Attacking]"))
  628. {
  629. Hashtable hashtable = CardEffectCommons.OnAttackCheckHashtableOfCard(EffectSourceCard, null);
  630. if (CanTrigger(hashtable))
  631. {
  632. return true;
  633. }
  634. }
  635. }
  636. }
  637. return false;
  638. }
  639. }
  640. #endregion
  641. #endregion
  642. #region Whether the target effect is the same as this effect
  643. public bool IsSameEffect(ICardEffect cardEffect)
  644. {
  645. if (cardEffect != null)
  646. {
  647. if (cardEffect == this)
  648. {
  649. return true;
  650. }
  651. if (cardEffect.EffectSourceCard != null)
  652. {
  653. if (this.EffectSourceCard != null)
  654. {
  655. if (cardEffect.EffectSourceCard == this.EffectSourceCard)
  656. {
  657. if (HasSameHashString() && HasSameRootCardEffect())
  658. {
  659. return true;
  660. }
  661. bool HasSameHashString()
  662. {
  663. if (string.IsNullOrEmpty(cardEffect.HashString))
  664. {
  665. if (string.IsNullOrEmpty(this.HashString))
  666. {
  667. return true;
  668. }
  669. }
  670. if (!string.IsNullOrEmpty(cardEffect.HashString))
  671. {
  672. if (!string.IsNullOrEmpty(this.HashString))
  673. {
  674. if (cardEffect.HashString == this.HashString)
  675. {
  676. return true;
  677. }
  678. }
  679. }
  680. return false;
  681. }
  682. bool HasSameRootCardEffect()
  683. {
  684. if (cardEffect.RootCardEffect == null)
  685. {
  686. if (this.RootCardEffect == null)
  687. {
  688. return true;
  689. }
  690. }
  691. if (cardEffect.RootCardEffect != null)
  692. {
  693. if (this.RootCardEffect != null)
  694. {
  695. if (cardEffect.RootCardEffect == this.RootCardEffect)
  696. {
  697. return true;
  698. }
  699. }
  700. }
  701. return false;
  702. }
  703. }
  704. }
  705. }
  706. }
  707. return false;
  708. }
  709. #endregion
  710. }
  711. #region Calculation order
  712. public enum CalculateOrder
  713. {
  714. UpValue,
  715. DownValue,
  716. UpToConstant,
  717. UpDownValue,
  718. DownToConstant,
  719. }
  720. #endregion
  721. #region Effect Duration
  722. public enum EffectDuration
  723. {
  724. UntilEachTurnEnd,
  725. UntilOpponentTurnEnd,
  726. UntilOwnerTurnEnd,
  727. UntilEndAttack,
  728. UntilEndBattle,
  729. UntilOwnerActivePhase,
  730. UntilCalculateFixedCost,
  731. UntilNextUntap,
  732. }
  733. #endregion
  734. #region Timing of effect triggers
  735. public enum EffectTiming
  736. {
  737. None,
  738. OnUseOption,
  739. OnDeclaration,
  740. OnEnterFieldAnyone,
  741. OnGetDamage,
  742. OptionSkill,
  743. OnDestroyedAnyone,
  744. WhenDigisorption,
  745. WhenRemoveField,
  746. WhenPermanentWouldBeDeleted,
  747. WhenReturntoLibraryAnyone,
  748. WhenReturntoHandAnyone,
  749. WhenUntapAnyone,
  750. OnEndAttackPhase,
  751. OnEndTurn,
  752. OnStartTurn,
  753. OnEndMainPhase,
  754. OnDraw,
  755. OnAddHand,
  756. OnLoseSecurity,
  757. OnAddSecurity,
  758. OnUseDigiburst,
  759. OnDiscardHand,
  760. OnDiscardSecurity,
  761. OnDiscardLibrary,
  762. OnKnockOut,
  763. OnMove,
  764. OnEndCoinToss,
  765. OnUseAttack,
  766. OnTappedAnyone,
  767. OnUnTappedAnyone,
  768. OnAddDigivolutionCards,
  769. OnAllyAttack,
  770. OnCounterTiming,
  771. OnBlockAnyone,
  772. OnSecurityCheck,
  773. OnAttackTargetChanged,
  774. OnEndBlockDesignation,
  775. SecuritySkill,
  776. OnStartMainPhase,
  777. OnStartBattle,
  778. OnEndBattle,
  779. OnDetermineDoSecurityCheck,
  780. OnEndAttack,
  781. BeforePayCost,
  782. AfterPayCost,
  783. OnDigivolutionCardDiscarded,
  784. OnDigivolutionCardReturnToDeckBottom,
  785. OnReturnCardsToLibraryFromTrash,
  786. OnPermamemtReturnedToHand,
  787. OnReturnCardsToHandFromTrash,
  788. AfterEffectsActivate,
  789. WhenWouldDigivolutionCardDiscarded,
  790. WhenWouldLink,
  791. WhenLinked,
  792. WhenTopCardTrashed,
  793. RulesTiming,
  794. OnRemovedField,
  795. OnLinkCardDiscarded,
  796. OnFaceUpSecurityIncreased,
  797. OnLeaveFieldAnyone
  798. }
  799. #endregion
  800. #region card effect that processes
  801. public interface ActivateICardEffect
  802. {
  803. IEnumerator Activate(Hashtable hash);
  804. public Permanent PermanentWhenTriggered { get; set; }
  805. public CardSource TopCardWhenTriggered { get; set; }
  806. }
  807. public static class ActivateICardEffectExtensionClass
  808. {
  809. #region Optional
  810. public static IEnumerator Activate_Optional(this ActivateICardEffect activateICardEffect, Hashtable hash)
  811. {
  812. if (((ICardEffect)activateICardEffect).IsOptional)
  813. {
  814. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<OptionalSkill>().SelectOptional((ICardEffect)activateICardEffect, hash));
  815. }
  816. }
  817. #endregion
  818. #region Effect
  819. public static IEnumerator Activate_Effect(this ActivateICardEffect activateICardEffect)
  820. {
  821. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  822. if (card != null)
  823. {
  824. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowActivateCardEffectDiscription((ICardEffect)activateICardEffect));
  825. Permanent permanent = card.PermanentOfThisCard();
  826. if (permanent != null)
  827. {
  828. if (permanent.ShowingPermanentCard != null)
  829. {
  830. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateFieldPokemonSkillEffect(permanent, (ICardEffect)activateICardEffect));
  831. }
  832. }
  833. else if (card.Owner.HandCards.Contains(card))
  834. {
  835. if (card.ShowingHandCard != null)
  836. {
  837. bool showEffect = false;
  838. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  839. {
  840. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  841. {
  842. showEffect = true;
  843. }
  844. }
  845. if (showEffect)
  846. {
  847. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateHandCardSkillEffect(card, (ICardEffect)activateICardEffect));
  848. }
  849. }
  850. }
  851. else if (CardEffectCommons.IsExistOnTrash(card))
  852. {
  853. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateTrashCardSkillEffect((ICardEffect)activateICardEffect));
  854. }
  855. else if (card.Owner.ExecutingCards.Contains(card))
  856. {
  857. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateExecutingCardSkillEffect(card, (ICardEffect)activateICardEffect));
  858. }
  859. yield return new WaitForSeconds(0.4f);
  860. }
  861. }
  862. #endregion
  863. #region Processing
  864. public static IEnumerator Activate_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash)
  865. {
  866. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  867. {
  868. ((ICardEffect)activateICardEffect).OnProcessCallbuck?.Invoke();
  869. ((ICardEffect)activateICardEffect).SetOnProcessCallbuck(null);
  870. //Handling Effect
  871. yield return ContinuousController.instance.StartCoroutine(activateICardEffect.Activate(hash));
  872. }
  873. }
  874. #endregion
  875. #region Optional→ Effect → Processing
  876. public static IEnumerator Activate_Optional_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, bool isCheckOptional = true, UnityAction<ICardEffect> useEffectCallback = null)
  877. {
  878. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  879. FieldPermanentCard fieldPermanentCard = null;
  880. HandCard handCard = null;
  881. if (card != null)
  882. {
  883. if (card.PermanentOfThisCard() != null)
  884. {
  885. fieldPermanentCard = card.PermanentOfThisCard().ShowingPermanentCard;
  886. }
  887. if (card.Owner.HandCards.Contains(card))
  888. {
  889. if (card.ShowingHandCard != null)
  890. {
  891. handCard = card.ShowingHandCard;
  892. }
  893. }
  894. }
  895. bool oldIsExecuting = GManager.instance.turnStateMachine.isExecuting;
  896. GManager.instance.turnStateMachine.isExecuting = true;
  897. if (fieldPermanentCard != null)
  898. {
  899. fieldPermanentCard.OnSelectEffect(1.1f);
  900. fieldPermanentCard.Outline_Select.gameObject.SetActive(true);
  901. fieldPermanentCard.SetOrangeOutline();
  902. }
  903. if (handCard != null)
  904. {
  905. if (card.Owner.isYou)
  906. {
  907. bool isHandEffect = false;
  908. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  909. {
  910. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  911. {
  912. isHandEffect = true;
  913. }
  914. }
  915. if (isHandEffect)
  916. {
  917. handCard.Outline_Select.SetActive(true);
  918. handCard.SetOrangeOutline();
  919. }
  920. }
  921. }
  922. UnityEngine.Debug.Log($"Activate_Optional_Effect_Execute: {(activateICardEffect is ICardEffect)}");
  923. if (activateICardEffect is ICardEffect)
  924. {
  925. UnityEngine.Debug.Log($"Activate_Optional_Effect_Execute: {((ICardEffect)activateICardEffect).EffectSourceCard.BaseENGCardNameFromEntity}");
  926. //Optional effect activation selection
  927. if (((ICardEffect)activateICardEffect).IsOptional)
  928. {
  929. if (isCheckOptional)
  930. {
  931. yield return ContinuousController.instance.StartCoroutine(Activate_Optional(activateICardEffect, hash));
  932. }
  933. else
  934. {
  935. ((ICardEffect)activateICardEffect).SetUseOptional(true);
  936. }
  937. }
  938. //Optional effect activation selection → cost → processing
  939. yield return ContinuousController.instance.StartCoroutine(Activate_Effect_Execute(activateICardEffect, hash, useEffectCallback));
  940. }
  941. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  942. {
  943. player.TrashHandCard.gameObject.SetActive(false);
  944. player.TrashHandCard.IsExecuting = false;
  945. }
  946. yield return new WaitForSeconds(Time.deltaTime * 2);
  947. if (fieldPermanentCard != null)
  948. {
  949. fieldPermanentCard.OffUsingSkillEffect();
  950. fieldPermanentCard.OffSkillName();
  951. fieldPermanentCard.RemoveSelectEffect();
  952. }
  953. foreach (FieldPermanentCard fieldPokemonCard in card.Owner.FieldPermanentObjects)
  954. {
  955. fieldPokemonCard.OffUsingSkillEffect();
  956. fieldPokemonCard.OffSkillName();
  957. }
  958. if (handCard != null)
  959. {
  960. handCard.Outline_Select.SetActive(false);
  961. }
  962. if (card != null)
  963. {
  964. GManager.instance.turnStateMachine.isExecuting = oldIsExecuting;
  965. }
  966. }
  967. #endregion
  968. #region remove a usage of an X Per Turn
  969. public static void RemoveUse(this ActivateICardEffect activateICardEffect)
  970. {
  971. ((ICardEffect)activateICardEffect).EffectSourceCard.cEntity_EffectController.RemoveUseEffectThisTurn((ICardEffect)activateICardEffect);
  972. }
  973. #endregion
  974. #region add a usage of an X Per Turn
  975. public static void AddUse(this ActivateICardEffect activateICardEffect)
  976. {
  977. ((ICardEffect)activateICardEffect).EffectSourceCard.cEntity_EffectController.RegisterUseEffectThisTurn((ICardEffect)activateICardEffect);
  978. }
  979. #endregion
  980. #region Effect → Processing
  981. public static IEnumerator Activate_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, UnityAction<ICardEffect> useEffectCallback)
  982. {
  983. //cost → effect processing
  984. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  985. {
  986. useEffectCallback?.Invoke((ICardEffect)activateICardEffect);
  987. Debug.Log($"{((ICardEffect)activateICardEffect).EffectName} was used");
  988. #region Add log
  989. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  990. if (card != null)
  991. {
  992. PlayLog.OnAddLog?.Invoke($"\nEffect:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n\"{((ICardEffect)activateICardEffect).EffectName}\"\n");
  993. }
  994. #endregion
  995. //effect
  996. yield return ContinuousController.instance.StartCoroutine(Activate_Effect(activateICardEffect));
  997. yield return ContinuousController.instance.StartCoroutine(Activate_Execute(activateICardEffect, hash));
  998. }
  999. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(null, EffectTiming.AfterEffectsActivate));
  1000. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.RuleProcess());
  1001. }
  1002. #endregion
  1003. }
  1004. #endregion