ICardEffect.cs 33 KB

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