ICardEffect.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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)
  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. #endregion
  523. #region Read only bool properties
  524. #region Whether this effect is disabled
  525. public bool IsDisabled
  526. {
  527. get
  528. {
  529. return CheckEffectDisabledClass.isDisabled(this);
  530. }
  531. }
  532. #endregion
  533. #region Whether this effect is [On Play] effect
  534. public bool IsOnPlay
  535. {
  536. get
  537. {
  538. if (EffectSourceCard != null)
  539. {
  540. if (!string.IsNullOrEmpty(EffectDiscription))
  541. {
  542. Debug.Log($"Effect Description: {EffectDiscription.StartsWith("[On Play]")}");
  543. if (EffectDiscription.StartsWith("[On Play]"))
  544. {
  545. Hashtable hashtable = CardEffectCommons.OnPlayCheckHashtableOfCard(EffectSourceCard);
  546. Debug.Log($"Can Trigger: {CanTrigger(hashtable)}");
  547. if (CanTrigger(hashtable))
  548. {
  549. return true;
  550. }
  551. }
  552. }
  553. }
  554. return false;
  555. }
  556. }
  557. #endregion
  558. #region Whether this effect is [When Digivolving] effect
  559. public bool IsWhenDigivolving
  560. {
  561. get
  562. {
  563. if (EffectSourceCard != null)
  564. {
  565. if (!string.IsNullOrEmpty(EffectDiscription))
  566. {
  567. if (EffectDiscription.StartsWith("[When Digivolving]"))
  568. {
  569. Hashtable hashtable = CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(EffectSourceCard);
  570. if (CanTrigger(hashtable))
  571. {
  572. return true;
  573. }
  574. }
  575. }
  576. }
  577. return false;
  578. }
  579. }
  580. #endregion
  581. #region Whether this effect is [On Deletion] effect
  582. public bool IsOnDeletion
  583. {
  584. get
  585. {
  586. if (EffectSourceCard != null)
  587. {
  588. if (!string.IsNullOrEmpty(EffectDiscription))
  589. {
  590. if (EffectDiscription.StartsWith("[On Deletion]"))
  591. {
  592. Permanent effectPermanent = EffectSourceCard.PermanentOfThisCard() ?? new Permanent(new List<CardSource>() { EffectSourceCard });
  593. Hashtable hashtable = CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { effectPermanent }, null, null, false);
  594. if (CanTrigger(hashtable))
  595. {
  596. return true;
  597. }
  598. }
  599. }
  600. }
  601. return false;
  602. }
  603. }
  604. #endregion
  605. #region Whether this effect is [On Attack] effect
  606. public bool IsOnAttack
  607. {
  608. get
  609. {
  610. if (EffectSourceCard != null)
  611. {
  612. if (!string.IsNullOrEmpty(EffectDiscription))
  613. {
  614. if (EffectDiscription.StartsWith("[When Attacking]"))
  615. {
  616. Hashtable hashtable = CardEffectCommons.OnAttackCheckHashtableOfCard(EffectSourceCard, null);
  617. if (CanTrigger(hashtable))
  618. {
  619. return true;
  620. }
  621. }
  622. }
  623. }
  624. return false;
  625. }
  626. }
  627. #endregion
  628. #endregion
  629. #region Whether the target effect is the same as this effect
  630. public bool IsSameEffect(ICardEffect cardEffect)
  631. {
  632. if (cardEffect != null)
  633. {
  634. if (cardEffect == this)
  635. {
  636. return true;
  637. }
  638. if (cardEffect.EffectSourceCard != null)
  639. {
  640. if (this.EffectSourceCard != null)
  641. {
  642. if (cardEffect.EffectSourceCard == this.EffectSourceCard)
  643. {
  644. if (HasSameHashString() && HasSameRootCardEffect())
  645. {
  646. return true;
  647. }
  648. bool HasSameHashString()
  649. {
  650. if (string.IsNullOrEmpty(cardEffect.HashString))
  651. {
  652. if (string.IsNullOrEmpty(this.HashString))
  653. {
  654. return true;
  655. }
  656. }
  657. if (!string.IsNullOrEmpty(cardEffect.HashString))
  658. {
  659. if (!string.IsNullOrEmpty(this.HashString))
  660. {
  661. if (cardEffect.HashString == this.HashString)
  662. {
  663. return true;
  664. }
  665. }
  666. }
  667. return false;
  668. }
  669. bool HasSameRootCardEffect()
  670. {
  671. if (cardEffect.RootCardEffect == null)
  672. {
  673. if (this.RootCardEffect == null)
  674. {
  675. return true;
  676. }
  677. }
  678. if (cardEffect.RootCardEffect != null)
  679. {
  680. if (this.RootCardEffect != null)
  681. {
  682. if (cardEffect.RootCardEffect == this.RootCardEffect)
  683. {
  684. return true;
  685. }
  686. }
  687. }
  688. return false;
  689. }
  690. }
  691. }
  692. }
  693. }
  694. return false;
  695. }
  696. #endregion
  697. }
  698. #region Calculation order
  699. public enum CalculateOrder
  700. {
  701. UpValue,
  702. DownValue,
  703. UpToConstant,
  704. UpDownValue,
  705. DownToConstant,
  706. }
  707. #endregion
  708. #region Effect Duration
  709. public enum EffectDuration
  710. {
  711. UntilEachTurnEnd,
  712. UntilOpponentTurnEnd,
  713. UntilOwnerTurnEnd,
  714. UntilEndAttack,
  715. UntilEndBattle,
  716. UntilOwnerActivePhase,
  717. UntilCalculateFixedCost,
  718. UntilNextUntap,
  719. }
  720. #endregion
  721. #region Timing of effect triggers
  722. public enum EffectTiming
  723. {
  724. None,
  725. OnUseOption,
  726. OnDeclaration,
  727. OnEnterFieldAnyone,
  728. OnGetDamage,
  729. OptionSkill,
  730. OnDestroyedAnyone,
  731. WhenDigisorption,
  732. WhenRemoveField,
  733. WhenPermanentWouldBeDeleted,
  734. WhenReturntoLibraryAnyone,
  735. WhenReturntoHandAnyone,
  736. WhenUntapAnyone,
  737. OnEndAttackPhase,
  738. OnEndTurn,
  739. OnStartTurn,
  740. OnEndMainPhase,
  741. OnDraw,
  742. OnAddHand,
  743. OnLoseSecurity,
  744. OnAddSecurity,
  745. OnUseDigiburst,
  746. OnDiscardHand,
  747. OnDiscardSecurity,
  748. OnDiscardLibrary,
  749. OnKnockOut,
  750. OnMove,
  751. OnEndCoinToss,
  752. OnUseAttack,
  753. OnTappedAnyone,
  754. OnUnTappedAnyone,
  755. OnAddDigivolutionCards,
  756. OnAllyAttack,
  757. OnCounterTiming,
  758. OnBlockAnyone,
  759. OnSecurityCheck,
  760. OnAttackTargetChanged,
  761. OnEndBlockDesignation,
  762. SecuritySkill,
  763. OnStartMainPhase,
  764. OnStartBattle,
  765. OnEndBattle,
  766. OnDetermineDoSecurityCheck,
  767. OnEndAttack,
  768. BeforePayCost,
  769. AfterPayCost,
  770. OnDigivolutionCardDiscarded,
  771. OnDigivolutionCardReturnToDeckBottom,
  772. OnReturnCardsToLibraryFromTrash,
  773. OnPermamemtReturnedToHand,
  774. OnReturnCardsToHandFromTrash,
  775. AfterEffectsActivate,
  776. WhenWouldDigivolutionCardDiscarded,
  777. WhenWouldLink,
  778. WhenLinked,
  779. WhenTopCardTrashed,
  780. RulesTiming,
  781. OnRemovedField,
  782. OnLinkCardDiscarded,
  783. OnFaceUpSecurityIncreased,
  784. OnLeaveFieldAnyone
  785. }
  786. #endregion
  787. #region card effect that processes
  788. public interface ActivateICardEffect
  789. {
  790. IEnumerator Activate(Hashtable hash);
  791. public Permanent PermanentWhenTriggered { get; set; }
  792. public CardSource TopCardWhenTriggered { get; set; }
  793. }
  794. public static class ActivateICardEffectExtensionClass
  795. {
  796. #region Optional
  797. public static IEnumerator Activate_Optional(this ActivateICardEffect activateICardEffect, Hashtable hash)
  798. {
  799. if (((ICardEffect)activateICardEffect).IsOptional)
  800. {
  801. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<OptionalSkill>().SelectOptional((ICardEffect)activateICardEffect, hash));
  802. }
  803. }
  804. #endregion
  805. #region Effect
  806. public static IEnumerator Activate_Effect(this ActivateICardEffect activateICardEffect)
  807. {
  808. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  809. if (card != null)
  810. {
  811. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowActivateCardEffectDiscription((ICardEffect)activateICardEffect));
  812. Permanent permanent = card.PermanentOfThisCard();
  813. if (permanent != null)
  814. {
  815. if (permanent.ShowingPermanentCard != null)
  816. {
  817. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateFieldPokemonSkillEffect(permanent, (ICardEffect)activateICardEffect));
  818. }
  819. }
  820. else if (card.Owner.HandCards.Contains(card))
  821. {
  822. if (card.ShowingHandCard != null)
  823. {
  824. bool showEffect = false;
  825. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  826. {
  827. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  828. {
  829. showEffect = true;
  830. }
  831. }
  832. if (showEffect)
  833. {
  834. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateHandCardSkillEffect(card, (ICardEffect)activateICardEffect));
  835. }
  836. }
  837. }
  838. else if (CardEffectCommons.IsExistOnTrash(card))
  839. {
  840. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateTrashCardSkillEffect((ICardEffect)activateICardEffect));
  841. }
  842. else if (card.Owner.ExecutingCards.Contains(card))
  843. {
  844. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateExecutingCardSkillEffect(card, (ICardEffect)activateICardEffect));
  845. }
  846. yield return new WaitForSeconds(0.4f);
  847. }
  848. }
  849. #endregion
  850. #region Processing
  851. public static IEnumerator Activate_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash)
  852. {
  853. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  854. {
  855. ((ICardEffect)activateICardEffect).OnProcessCallbuck?.Invoke();
  856. ((ICardEffect)activateICardEffect).SetOnProcessCallbuck(null);
  857. //Handling Effect
  858. yield return ContinuousController.instance.StartCoroutine(activateICardEffect.Activate(hash));
  859. }
  860. }
  861. #endregion
  862. #region Optional→ Effect → Processing
  863. public static IEnumerator Activate_Optional_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, bool isCheckOptional = true, UnityAction<ICardEffect> useEffectCallback = null)
  864. {
  865. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  866. FieldPermanentCard fieldPermanentCard = null;
  867. HandCard handCard = null;
  868. if (card != null)
  869. {
  870. if (card.PermanentOfThisCard() != null)
  871. {
  872. fieldPermanentCard = card.PermanentOfThisCard().ShowingPermanentCard;
  873. }
  874. if (card.Owner.HandCards.Contains(card))
  875. {
  876. if (card.ShowingHandCard != null)
  877. {
  878. handCard = card.ShowingHandCard;
  879. }
  880. }
  881. }
  882. bool oldIsExecuting = GManager.instance.turnStateMachine.isExecuting;
  883. GManager.instance.turnStateMachine.isExecuting = true;
  884. if (fieldPermanentCard != null)
  885. {
  886. fieldPermanentCard.OnSelectEffect(1.1f);
  887. fieldPermanentCard.Outline_Select.gameObject.SetActive(true);
  888. fieldPermanentCard.SetOrangeOutline();
  889. }
  890. if (handCard != null)
  891. {
  892. if (card.Owner.isYou)
  893. {
  894. bool isHandEffect = false;
  895. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  896. {
  897. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  898. {
  899. isHandEffect = true;
  900. }
  901. }
  902. if (isHandEffect)
  903. {
  904. handCard.Outline_Select.SetActive(true);
  905. handCard.SetOrangeOutline();
  906. }
  907. }
  908. }
  909. UnityEngine.Debug.Log($"Activate_Optional_Effect_Execute: {(activateICardEffect is ICardEffect)}");
  910. if (activateICardEffect is ICardEffect)
  911. {
  912. UnityEngine.Debug.Log($"Activate_Optional_Effect_Execute: {((ICardEffect)activateICardEffect).EffectSourceCard.BaseENGCardNameFromEntity}");
  913. //Optional effect activation selection
  914. if (((ICardEffect)activateICardEffect).IsOptional)
  915. {
  916. if (isCheckOptional)
  917. {
  918. yield return ContinuousController.instance.StartCoroutine(Activate_Optional(activateICardEffect, hash));
  919. }
  920. else
  921. {
  922. ((ICardEffect)activateICardEffect).SetUseOptional(true);
  923. }
  924. }
  925. //Optional effect activation selection → cost → processing
  926. yield return ContinuousController.instance.StartCoroutine(Activate_Effect_Execute(activateICardEffect, hash, useEffectCallback));
  927. }
  928. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  929. {
  930. player.TrashHandCard.gameObject.SetActive(false);
  931. player.TrashHandCard.IsExecuting = false;
  932. }
  933. yield return new WaitForSeconds(Time.deltaTime * 2);
  934. if (fieldPermanentCard != null)
  935. {
  936. fieldPermanentCard.OffUsingSkillEffect();
  937. fieldPermanentCard.OffSkillName();
  938. fieldPermanentCard.RemoveSelectEffect();
  939. }
  940. foreach (FieldPermanentCard fieldPokemonCard in card.Owner.FieldPermanentObjects)
  941. {
  942. fieldPokemonCard.OffUsingSkillEffect();
  943. fieldPokemonCard.OffSkillName();
  944. }
  945. if (handCard != null)
  946. {
  947. handCard.Outline_Select.SetActive(false);
  948. }
  949. if (card != null)
  950. {
  951. GManager.instance.turnStateMachine.isExecuting = oldIsExecuting;
  952. }
  953. }
  954. #endregion
  955. #region remove a usage of an X Per Turn
  956. public static void RemoveUse(this ActivateICardEffect activateICardEffect)
  957. {
  958. ((ICardEffect)activateICardEffect).EffectSourceCard.cEntity_EffectController.RemoveUseEffectThisTurn((ICardEffect)activateICardEffect);
  959. }
  960. #endregion
  961. #region add a usage of an X Per Turn
  962. public static void AddUse(this ActivateICardEffect activateICardEffect)
  963. {
  964. ((ICardEffect)activateICardEffect).EffectSourceCard.cEntity_EffectController.RegisterUseEffectThisTurn((ICardEffect)activateICardEffect);
  965. }
  966. #endregion
  967. #region Effect → Processing
  968. public static IEnumerator Activate_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, UnityAction<ICardEffect> useEffectCallback)
  969. {
  970. //cost → effect processing
  971. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  972. {
  973. useEffectCallback?.Invoke((ICardEffect)activateICardEffect);
  974. Debug.Log($"{((ICardEffect)activateICardEffect).EffectName} was used");
  975. #region Add log
  976. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  977. if (card != null)
  978. {
  979. PlayLog.OnAddLog?.Invoke($"\nEffect:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n\"{((ICardEffect)activateICardEffect).EffectName}\"\n");
  980. }
  981. #endregion
  982. //effect
  983. yield return ContinuousController.instance.StartCoroutine(Activate_Effect(activateICardEffect));
  984. yield return ContinuousController.instance.StartCoroutine(Activate_Execute(activateICardEffect, hash));
  985. }
  986. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(null, EffectTiming.AfterEffectsActivate));
  987. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.RuleProcess());
  988. }
  989. #endregion
  990. }
  991. #endregion