ICardEffect.cs 29 KB

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