ICardEffect.cs 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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 Effect availability determined by the maximum number of times it can be used in a turn
  228. if (EffectSourceCard.cEntity_EffectController.isOverMaxCountPerTurn(this, MaxCountPerTurn))
  229. {
  230. return false;
  231. }
  232. #endregion
  233. #region Determination of availability for each effect
  234. if (CanUseCondition == null || !CanUseCondition(hashtable))
  235. {
  236. return false;
  237. }
  238. #endregion
  239. return true;
  240. }
  241. #endregion
  242. #region Whether this triggering effect activates
  243. public bool CanActivate(Hashtable hashtable)
  244. {
  245. #region Effect availability determined by the maximum number of times it can be used in a turn
  246. if (EffectSourceCard.cEntity_EffectController.isOverMaxCountPerTurn(this, MaxCountPerTurn))
  247. {
  248. return false;
  249. }
  250. #endregion
  251. #region Determination of availability for each effect
  252. if (CanActivateCondition != null && !CanActivateCondition(hashtable))
  253. {
  254. return false;
  255. }
  256. #endregion
  257. #region Determination of availability for Inheritated/Linked Effect
  258. if (this is ActivateICardEffect)
  259. {
  260. if (EffectSourceCard != null)
  261. {
  262. if (EffectSourceCard.PermanentOfThisCard() != null)
  263. {
  264. if (IsInheritedEffect || IsLinkedEffect)
  265. {
  266. if (EffectSourceCard == EffectSourceCard.PermanentOfThisCard().TopCard)
  267. return false;
  268. if (EffectSourceCard.IsFlipped)
  269. return false;
  270. if (!EffectSourceCard.PermanentOfThisCard().IsDigimon)
  271. return false;
  272. if (IsLinkedEffect && !EffectSourceCard.PermanentOfThisCard().LinkedCards.Contains(EffectSourceCard))
  273. return false;
  274. }
  275. else
  276. {
  277. if (EffectSourceCard != EffectSourceCard.PermanentOfThisCard().TopCard)
  278. {
  279. return false;
  280. }
  281. }
  282. }
  283. }
  284. }
  285. #endregion
  286. #region Determination of availability due to be disabled
  287. if (IsDisabled)
  288. {
  289. return false;
  290. }
  291. #endregion
  292. //TODO: Look into this for the on deletion General issue
  293. #region Determination whether the permanent is same as when triggered
  294. if (IsInheritedEffect || IsLinkedEffect)
  295. {
  296. if (this is ActivateICardEffect)
  297. {
  298. Permanent PermanentWhenTriggered = ((ActivateICardEffect)this).PermanentWhenTriggered;
  299. if (PermanentWhenTriggered != null)
  300. {
  301. if (EffectSourceCard != null)
  302. {
  303. Permanent currentPermanent = EffectSourceCard.PermanentOfThisCard();
  304. if (currentPermanent != null)
  305. {
  306. if (currentPermanent != PermanentWhenTriggered)
  307. {
  308. return false;
  309. }
  310. }
  311. }
  312. }
  313. }
  314. }
  315. #endregion
  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. OnLinkCardDiscarded
  733. }
  734. #endregion
  735. #region card effect that processes
  736. public interface ActivateICardEffect
  737. {
  738. IEnumerator Activate(Hashtable hash);
  739. public Permanent PermanentWhenTriggered { get; set; }
  740. public CardSource TopCardWhenTriggered { get; set; }
  741. }
  742. public static class ActivateICardEffectExtensionClass
  743. {
  744. #region Optional
  745. public static IEnumerator Activate_Optional(this ActivateICardEffect activateICardEffect)
  746. {
  747. if (((ICardEffect)activateICardEffect).IsOptional)
  748. {
  749. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<OptionalSkill>().SelectOptional((ICardEffect)activateICardEffect));
  750. }
  751. }
  752. #endregion
  753. #region Effect
  754. public static IEnumerator Activate_Effect(this ActivateICardEffect activateICardEffect)
  755. {
  756. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  757. if (card != null)
  758. {
  759. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowActivateCardEffectDiscription((ICardEffect)activateICardEffect));
  760. Permanent permanent = card.PermanentOfThisCard();
  761. if (permanent != null)
  762. {
  763. if (permanent.ShowingPermanentCard != null)
  764. {
  765. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateFieldPokemonSkillEffect(permanent, (ICardEffect)activateICardEffect));
  766. }
  767. }
  768. else if (card.Owner.HandCards.Contains(card))
  769. {
  770. if (card.ShowingHandCard != null)
  771. {
  772. bool showEffect = false;
  773. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  774. {
  775. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  776. {
  777. showEffect = true;
  778. }
  779. }
  780. if (showEffect)
  781. {
  782. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateHandCardSkillEffect(card, (ICardEffect)activateICardEffect));
  783. }
  784. }
  785. }
  786. else if (CardEffectCommons.IsExistOnTrash(card))
  787. {
  788. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateTrashCardSkillEffect((ICardEffect)activateICardEffect));
  789. }
  790. else if (card.Owner.ExecutingCards.Contains(card))
  791. {
  792. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateExecutingCardSkillEffect(card, (ICardEffect)activateICardEffect));
  793. }
  794. yield return new WaitForSeconds(0.4f);
  795. }
  796. }
  797. #endregion
  798. #region Processing
  799. public static IEnumerator Activate_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash)
  800. {
  801. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  802. {
  803. ((ICardEffect)activateICardEffect).OnProcessCallbuck?.Invoke();
  804. ((ICardEffect)activateICardEffect).SetOnProcessCallbuck(null);
  805. //Handling Effect
  806. ((ICardEffect)activateICardEffect).EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(((ICardEffect)activateICardEffect));
  807. yield return ContinuousController.instance.StartCoroutine(activateICardEffect.Activate(hash));
  808. }
  809. }
  810. #endregion
  811. #region Optional→ Effect → Processing
  812. public static IEnumerator Activate_Optional_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, bool isCheckOptional = true, UnityAction<ICardEffect> useEffectCallback = null)
  813. {
  814. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  815. FieldPermanentCard fieldPermanentCard = null;
  816. HandCard handCard = null;
  817. if (card != null)
  818. {
  819. if (card.PermanentOfThisCard() != null)
  820. {
  821. fieldPermanentCard = card.PermanentOfThisCard().ShowingPermanentCard;
  822. }
  823. if (card.Owner.HandCards.Contains(card))
  824. {
  825. if (card.ShowingHandCard != null)
  826. {
  827. handCard = card.ShowingHandCard;
  828. }
  829. }
  830. }
  831. bool oldIsExecuting = GManager.instance.turnStateMachine.isExecuting;
  832. GManager.instance.turnStateMachine.isExecuting = true;
  833. if (fieldPermanentCard != null)
  834. {
  835. fieldPermanentCard.OnSelectEffect(1.1f);
  836. fieldPermanentCard.Outline_Select.gameObject.SetActive(true);
  837. fieldPermanentCard.SetOrangeOutline();
  838. }
  839. if (handCard != null)
  840. {
  841. if (card.Owner.isYou)
  842. {
  843. bool isHandEffect = false;
  844. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  845. {
  846. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  847. {
  848. isHandEffect = true;
  849. }
  850. }
  851. if (isHandEffect)
  852. {
  853. handCard.Outline_Select.SetActive(true);
  854. handCard.SetOrangeOutline();
  855. }
  856. }
  857. }
  858. UnityEngine.Debug.Log($"Activate_Optional_Effect_Execute: {(activateICardEffect is ICardEffect)}");
  859. if (activateICardEffect is ICardEffect)
  860. {
  861. UnityEngine.Debug.Log($"Activate_Optional_Effect_Execute: {((ICardEffect)activateICardEffect).EffectSourceCard.BaseENGCardNameFromEntity}");
  862. //Optional effect activation selection
  863. if (((ICardEffect)activateICardEffect).IsOptional)
  864. {
  865. if (isCheckOptional)
  866. {
  867. yield return ContinuousController.instance.StartCoroutine(Activate_Optional(activateICardEffect));
  868. }
  869. else
  870. {
  871. ((ICardEffect)activateICardEffect).SetUseOptional(true);
  872. }
  873. }
  874. //Optional effect activation selection → cost → processing
  875. yield return ContinuousController.instance.StartCoroutine(Activate_Effect_Execute(activateICardEffect, hash, useEffectCallback));
  876. }
  877. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  878. {
  879. player.TrashHandCard.gameObject.SetActive(false);
  880. player.TrashHandCard.IsExecuting = false;
  881. }
  882. yield return new WaitForSeconds(Time.deltaTime * 2);
  883. if (fieldPermanentCard != null)
  884. {
  885. fieldPermanentCard.OffUsingSkillEffect();
  886. fieldPermanentCard.OffSkillName();
  887. fieldPermanentCard.RemoveSelectEffect();
  888. }
  889. foreach (FieldPermanentCard fieldPokemonCard in card.Owner.FieldPermanentObjects)
  890. {
  891. fieldPokemonCard.OffUsingSkillEffect();
  892. fieldPokemonCard.OffSkillName();
  893. }
  894. if (handCard != null)
  895. {
  896. handCard.Outline_Select.SetActive(false);
  897. }
  898. if (card != null)
  899. {
  900. GManager.instance.turnStateMachine.isExecuting = oldIsExecuting;
  901. }
  902. }
  903. #endregion
  904. #region Effect → Processing
  905. public static IEnumerator Activate_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, UnityAction<ICardEffect> useEffectCallback)
  906. {
  907. //cost → effect processing
  908. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  909. {
  910. useEffectCallback?.Invoke((ICardEffect)activateICardEffect);
  911. Debug.Log($"{((ICardEffect)activateICardEffect).EffectName} was used");
  912. #region Add log
  913. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  914. if (card != null)
  915. {
  916. PlayLog.OnAddLog?.Invoke($"\nEffect:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n\"{((ICardEffect)activateICardEffect).EffectName}\"\n");
  917. }
  918. #endregion
  919. //effect
  920. yield return ContinuousController.instance.StartCoroutine(Activate_Effect(activateICardEffect));
  921. yield return ContinuousController.instance.StartCoroutine(Activate_Execute(activateICardEffect, hash));
  922. }
  923. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(null, EffectTiming.AfterEffectsActivate));
  924. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.RuleProcess());
  925. }
  926. #endregion
  927. }
  928. #endregion