ICardEffect.cs 33 KB

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