ICardEffect.cs 32 KB

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