ICardEffect.cs 33 KB

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