ICardEffect.cs 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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. if(IsInheritedEffect && IsOnDeletion)
  369. {
  370. SetEffectSourcePermanent(_effectSourceCard.PermanentOfThisCard());
  371. }
  372. }
  373. #endregion
  374. #region Whether this effect is an Security Effect
  375. bool _isSecurityEffect = false;
  376. public bool IsSecurityEffect
  377. {
  378. get { return _isSecurityEffect; }
  379. private set { _isSecurityEffect = value; }
  380. }
  381. public void SetIsSecurityEffect(bool isSecurityEffect)
  382. {
  383. IsSecurityEffect = isSecurityEffect;
  384. }
  385. #endregion
  386. #region Whether this effect is an Counter Effect
  387. bool _isCounterEffect = false;
  388. public bool IsCounterEffect
  389. {
  390. get { return _isCounterEffect; }
  391. private set { _isCounterEffect = value; }
  392. }
  393. public void SetIsCounterEffect(bool isCounterEffect)
  394. {
  395. IsCounterEffect = isCounterEffect;
  396. }
  397. #endregion
  398. #region Whether this effect is Digimon's effect
  399. bool _isDigimonEffect = false;
  400. public bool IsDigimonEffect
  401. {
  402. get { return _isDigimonEffect; }
  403. private set { _isDigimonEffect = value; }
  404. }
  405. public void SetIsDigimonEffect(bool isDigimonEffect)
  406. {
  407. IsDigimonEffect = isDigimonEffect;
  408. }
  409. #endregion
  410. #region Whether this effect is Tamer's effect
  411. bool _isTamerEffect = false;
  412. public bool IsTamerEffect
  413. {
  414. get { return _isTamerEffect; }
  415. private set { _isTamerEffect = value; }
  416. }
  417. public void SetIsTamerEffect(bool isTamerEffect)
  418. {
  419. IsTamerEffect = isTamerEffect;
  420. }
  421. #endregion
  422. #region Whether this effect is carried out in the background
  423. bool _isBackgroundProcess = false;
  424. public bool IsBackgroundProcess
  425. {
  426. get { return _isBackgroundProcess; }
  427. private set { _isBackgroundProcess = value; }
  428. }
  429. public void SetIsBackgroundProcess(bool isBackgroundProcess)
  430. {
  431. IsBackgroundProcess = isBackgroundProcess;
  432. }
  433. #endregion
  434. #region Whether this effect should be displayed in the UI
  435. bool _isNotShowUI = false;
  436. public bool IsNotShowUI
  437. {
  438. get { return _isNotShowUI; }
  439. private set { _isNotShowUI = value; }
  440. }
  441. public void SetNotShowUI(bool isNotShowUI)
  442. {
  443. IsNotShowUI = isNotShowUI;
  444. }
  445. #endregion
  446. #endregion
  447. #region Read only bool properties
  448. #region Whether this effect is disabled
  449. public bool IsDisabled
  450. {
  451. get
  452. {
  453. return CheckEffectDisabledClass.isDisabled(this);
  454. }
  455. }
  456. #endregion
  457. #region Whether this effect is [On Play] effect
  458. public bool IsOnPlay
  459. {
  460. get
  461. {
  462. if (EffectSourceCard != null)
  463. {
  464. if (!string.IsNullOrEmpty(EffectDiscription))
  465. {
  466. if (EffectDiscription.Contains("[On Play]"))
  467. {
  468. Hashtable hashtable = CardEffectCommons.OnPlayCheckHashtableOfCard(EffectSourceCard);
  469. if (CanTrigger(hashtable))
  470. {
  471. return true;
  472. }
  473. }
  474. }
  475. }
  476. return false;
  477. }
  478. }
  479. #endregion
  480. #region Whether this effect is [When Digivolving] effect
  481. public bool IsWhenDigivolving
  482. {
  483. get
  484. {
  485. if (EffectSourceCard != null)
  486. {
  487. if (!string.IsNullOrEmpty(EffectDiscription))
  488. {
  489. if (EffectDiscription.Contains("[When Digivolving]"))
  490. {
  491. Hashtable hashtable = CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(EffectSourceCard);
  492. if (CanTrigger(hashtable))
  493. {
  494. return true;
  495. }
  496. }
  497. }
  498. }
  499. return false;
  500. }
  501. }
  502. #endregion
  503. #region Whether this effect is [On Deletion] effect
  504. public bool IsOnDeletion
  505. {
  506. get
  507. {
  508. if (EffectSourceCard != null)
  509. {
  510. if (!string.IsNullOrEmpty(EffectDiscription))
  511. {
  512. if (EffectDiscription.Contains("[On Deletion]"))
  513. {
  514. Permanent effectPermanent = EffectSourceCard.PermanentOfThisCard() ?? new Permanent(new List<CardSource>() { EffectSourceCard });
  515. Hashtable hashtable = CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { effectPermanent }, null, null, false);
  516. if (CanTrigger(hashtable))
  517. {
  518. return true;
  519. }
  520. }
  521. }
  522. }
  523. return false;
  524. }
  525. }
  526. #endregion
  527. #region Whether this effect is [On Attack] effect
  528. public bool IsOnAttack
  529. {
  530. get
  531. {
  532. if (EffectSourceCard != null)
  533. {
  534. if (!string.IsNullOrEmpty(EffectDiscription))
  535. {
  536. if (EffectDiscription.Contains("[When Attacking]"))
  537. {
  538. Hashtable hashtable = CardEffectCommons.OnAttackCheckHashtableOfCard(EffectSourceCard, null);
  539. if (CanTrigger(hashtable))
  540. {
  541. return true;
  542. }
  543. }
  544. }
  545. }
  546. return false;
  547. }
  548. }
  549. #endregion
  550. #endregion
  551. #region Whether the target effect is the same as this effect
  552. public bool IsSameEffect(ICardEffect cardEffect)
  553. {
  554. if (cardEffect != null)
  555. {
  556. if (cardEffect == this)
  557. {
  558. return true;
  559. }
  560. if (cardEffect.EffectSourceCard != null)
  561. {
  562. if (this.EffectSourceCard != null)
  563. {
  564. if (cardEffect.EffectSourceCard == this.EffectSourceCard)
  565. {
  566. if (HasSameHashString() && HasSameRootCardEffect())
  567. {
  568. return true;
  569. }
  570. bool HasSameHashString()
  571. {
  572. if (string.IsNullOrEmpty(cardEffect.HashString))
  573. {
  574. if (string.IsNullOrEmpty(this.HashString))
  575. {
  576. return true;
  577. }
  578. }
  579. if (!string.IsNullOrEmpty(cardEffect.HashString))
  580. {
  581. if (!string.IsNullOrEmpty(this.HashString))
  582. {
  583. if (cardEffect.HashString == this.HashString)
  584. {
  585. return true;
  586. }
  587. }
  588. }
  589. return false;
  590. }
  591. bool HasSameRootCardEffect()
  592. {
  593. if (cardEffect.RootCardEffect == null)
  594. {
  595. if (this.RootCardEffect == null)
  596. {
  597. return true;
  598. }
  599. }
  600. if (cardEffect.RootCardEffect != null)
  601. {
  602. if (this.RootCardEffect != null)
  603. {
  604. if (cardEffect.RootCardEffect == this.RootCardEffect)
  605. {
  606. return true;
  607. }
  608. }
  609. }
  610. return false;
  611. }
  612. }
  613. }
  614. }
  615. }
  616. return false;
  617. }
  618. #endregion
  619. }
  620. #region Calculation order
  621. public enum CalculateOrder
  622. {
  623. UpValue,
  624. DownValue,
  625. UpToConstant,
  626. UpDownValue,
  627. DownToConstant,
  628. }
  629. #endregion
  630. #region Effect Duration
  631. public enum EffectDuration
  632. {
  633. UntilEachTurnEnd,
  634. UntilOpponentTurnEnd,
  635. UntilOwnerTurnEnd,
  636. UntilEndAttack,
  637. UntilEndBattle,
  638. UntilOwnerActivePhase,
  639. UntilCalculateFixedCost,
  640. UntilNextUntap,
  641. }
  642. #endregion
  643. #region Timing of effect triggers
  644. public enum EffectTiming
  645. {
  646. None,
  647. OnUseOption,
  648. OnDeclaration,
  649. OnEnterFieldAnyone,
  650. OnGetDamage,
  651. OptionSkill,
  652. OnDestroyedAnyone,
  653. WhenDigisorption,
  654. WhenRemoveField,
  655. WhenPermanentWouldBeDeleted,
  656. WhenReturntoLibraryAnyone,
  657. WhenReturntoHandAnyone,
  658. WhenUntapAnyone,
  659. OnEndAttackPhase,
  660. OnEndTurn,
  661. OnStartTurn,
  662. OnEndMainPhase,
  663. OnDraw,
  664. OnAddHand,
  665. OnLoseSecurity,
  666. OnAddSecurity,
  667. OnUseDigiburst,
  668. OnDiscardHand,
  669. OnDiscardSecurity,
  670. OnDiscardLibrary,
  671. OnKnockOut,
  672. OnMove,
  673. OnEndCoinToss,
  674. OnUseAttack,
  675. OnTappedAnyone,
  676. OnUnTappedAnyone,
  677. OnAddDigivolutionCards,
  678. OnAllyAttack,
  679. OnCounterTiming,
  680. OnBlockAnyone,
  681. OnSecurityCheck,
  682. OnAttackTargetChanged,
  683. OnEndBlockDesignation,
  684. SecuritySkill,
  685. OnStartMainPhase,
  686. OnStartBattle,
  687. OnEndBattle,
  688. OnDetermineDoSecurityCheck,
  689. OnEndAttack,
  690. BeforePayCost,
  691. AfterPayCost,
  692. OnDigivolutionCardDiscarded,
  693. OnDigivolutionCardReturnToDeckBottom,
  694. OnReturnCardsToLibraryFromTrash,
  695. OnPermamemtReturnedToHand,
  696. OnReturnCardsToHandFromTrash,
  697. }
  698. #endregion
  699. #region card effect that processes
  700. public interface ActivateICardEffect
  701. {
  702. IEnumerator Activate(Hashtable hash);
  703. public Permanent PermanentWhenTriggered { get; set; }
  704. public CardSource TopCardWhenTriggered { get; set; }
  705. }
  706. public static class ActivateICardEffectExtensionClass
  707. {
  708. #region Optional
  709. public static IEnumerator Activate_Optional(this ActivateICardEffect activateICardEffect)
  710. {
  711. if (((ICardEffect)activateICardEffect).IsOptional)
  712. {
  713. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<OptionalSkill>().SelectOptional((ICardEffect)activateICardEffect));
  714. }
  715. }
  716. #endregion
  717. #region Effect
  718. public static IEnumerator Activate_Effect(this ActivateICardEffect activateICardEffect)
  719. {
  720. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  721. if (card != null)
  722. {
  723. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowActivateCardEffectDiscription((ICardEffect)activateICardEffect));
  724. Permanent permanent = card.PermanentOfThisCard();
  725. if (permanent != null)
  726. {
  727. if (permanent.ShowingPermanentCard != null)
  728. {
  729. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateFieldPokemonSkillEffect(permanent, (ICardEffect)activateICardEffect));
  730. }
  731. }
  732. else if (card.Owner.HandCards.Contains(card))
  733. {
  734. if (card.ShowingHandCard != null)
  735. {
  736. bool showEffect = false;
  737. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  738. {
  739. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  740. {
  741. showEffect = true;
  742. }
  743. }
  744. if (showEffect)
  745. {
  746. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateHandCardSkillEffect(card, (ICardEffect)activateICardEffect));
  747. }
  748. }
  749. }
  750. else if (CardEffectCommons.IsExistOnTrash(card))
  751. {
  752. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateTrashCardSkillEffect((ICardEffect)activateICardEffect));
  753. }
  754. else if (card.Owner.ExecutingCards.Contains(card))
  755. {
  756. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ActivateExecutingCardSkillEffect(card, (ICardEffect)activateICardEffect));
  757. }
  758. yield return new WaitForSeconds(0.4f);
  759. }
  760. }
  761. #endregion
  762. #region Processing
  763. public static IEnumerator Activate_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash)
  764. {
  765. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  766. {
  767. ((ICardEffect)activateICardEffect).OnProcessCallbuck?.Invoke();
  768. ((ICardEffect)activateICardEffect).SetOnProcessCallbuck(null);
  769. //Handling Effects
  770. yield return ContinuousController.instance.StartCoroutine(activateICardEffect.Activate(hash));
  771. }
  772. }
  773. #endregion
  774. #region Optional→ Effect → Processing
  775. public static IEnumerator Activate_Optional_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, bool isCheckOptional = true, UnityAction<ICardEffect> useEffectCallback = null)
  776. {
  777. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  778. FieldPermanentCard fieldPermanentCard = null;
  779. HandCard handCard = null;
  780. if (card != null)
  781. {
  782. if (card.PermanentOfThisCard() != null)
  783. {
  784. fieldPermanentCard = card.PermanentOfThisCard().ShowingPermanentCard;
  785. }
  786. if (card.Owner.HandCards.Contains(card))
  787. {
  788. if (card.ShowingHandCard != null)
  789. {
  790. handCard = card.ShowingHandCard;
  791. }
  792. }
  793. }
  794. bool oldIsExecuting = GManager.instance.turnStateMachine.isExecuting;
  795. GManager.instance.turnStateMachine.isExecuting = true;
  796. if (fieldPermanentCard != null)
  797. {
  798. fieldPermanentCard.OnSelectEffect(1.1f);
  799. fieldPermanentCard.Outline_Select.gameObject.SetActive(true);
  800. fieldPermanentCard.SetOrangeOutline();
  801. }
  802. if (handCard != null)
  803. {
  804. if (card.Owner.isYou)
  805. {
  806. bool isHandEffect = false;
  807. if (!string.IsNullOrEmpty(((ICardEffect)activateICardEffect).EffectDiscription))
  808. {
  809. if (((ICardEffect)activateICardEffect).EffectDiscription.Contains("[Hand]"))
  810. {
  811. isHandEffect = true;
  812. }
  813. }
  814. if (isHandEffect)
  815. {
  816. handCard.Outline_Select.SetActive(true);
  817. handCard.SetOrangeOutline();
  818. }
  819. }
  820. }
  821. if (activateICardEffect is ICardEffect)
  822. {
  823. //Optional effect activation selection
  824. if (((ICardEffect)activateICardEffect).IsOptional)
  825. {
  826. if (isCheckOptional)
  827. {
  828. yield return ContinuousController.instance.StartCoroutine(Activate_Optional(activateICardEffect));
  829. }
  830. else
  831. {
  832. ((ICardEffect)activateICardEffect).SetUseOptional(true);
  833. }
  834. }
  835. //Optional effect activation selection → cost → processing
  836. yield return ContinuousController.instance.StartCoroutine(Activate_Effect_Execute(activateICardEffect, hash, useEffectCallback));
  837. }
  838. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  839. {
  840. player.TrashHandCard.gameObject.SetActive(false);
  841. player.TrashHandCard.IsExecuting = false;
  842. }
  843. yield return new WaitForSeconds(Time.deltaTime * 2);
  844. if (fieldPermanentCard != null)
  845. {
  846. fieldPermanentCard.OffUsingSkillEffect();
  847. fieldPermanentCard.OffSkillName();
  848. fieldPermanentCard.RemoveSelectEffect();
  849. }
  850. foreach (FieldPermanentCard fieldPokemonCard in card.Owner.FieldPermanentObjects)
  851. {
  852. fieldPokemonCard.OffUsingSkillEffect();
  853. fieldPokemonCard.OffSkillName();
  854. }
  855. if (handCard != null)
  856. {
  857. handCard.Outline_Select.SetActive(false);
  858. }
  859. if (card != null)
  860. {
  861. GManager.instance.turnStateMachine.isExecuting = oldIsExecuting;
  862. }
  863. }
  864. #endregion
  865. #region Effect → Processing
  866. public static IEnumerator Activate_Effect_Execute(this ActivateICardEffect activateICardEffect, Hashtable hash, UnityAction<ICardEffect> useEffectCallback)
  867. {
  868. //cost → effect processing
  869. if (((ICardEffect)activateICardEffect).UseOptional || !((ICardEffect)activateICardEffect).IsOptional)
  870. {
  871. useEffectCallback?.Invoke((ICardEffect)activateICardEffect);
  872. Debug.Log($"{((ICardEffect)activateICardEffect).EffectName} was used");
  873. #region ログ追加
  874. CardSource card = ((ICardEffect)activateICardEffect).EffectSourceCard;
  875. if (card != null)
  876. {
  877. GManager.instance.playLog.AddLogString($"\nEffect:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n\"{((ICardEffect)activateICardEffect).EffectName}\"\n");
  878. }
  879. #endregion
  880. //effect
  881. yield return ContinuousController.instance.StartCoroutine(Activate_Effect(activateICardEffect));
  882. yield return ContinuousController.instance.StartCoroutine(Activate_Execute(activateICardEffect, hash));
  883. }
  884. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.RuleProcess());
  885. }
  886. #endregion
  887. }
  888. #endregion