ICardEffect.cs 31 KB

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