ICardEffect.cs 32 KB

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