ICardEffect.cs 33 KB

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