ICardEffect.cs 30 KB

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