Link.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectFactory
  7. {
  8. #region Trigger effect of Link
  9. /// <summary>
  10. /// Linking 1 digimon in hand/field to another digimon
  11. /// </summary>
  12. /// <param name="CardSource">card being linked</param>
  13. /// <param name="int">cost for link</param>
  14. /// <param name="int">DP buff</param>
  15. /// <param name="Func(bool)">condition for you to be able to link</param>
  16. /// <param name="Func(Permanent,bool)">Any permaent condtion for you to link to</param>
  17. /// <author>Mike Bunch</author>
  18. public static ActivateClass LinkEffect(CardSource card, Func<bool> condition = null)
  19. {
  20. if (card == null) return null;
  21. if (!CardEffectCommons.IsOwnerTurn(card)) return null;
  22. if (!CardEffectCommons.IsExistOnHand(card) && !CardEffectCommons.IsExistOnBattleAreaDigimon(card)) return null;
  23. if (!CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition)) return null;
  24. ActivateClass activateClass = new ActivateClass();
  25. activateClass.SetUpICardEffect($"Link (Cost: {card.linkCondition.cost})", CanUseCondition, card);
  26. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, true, DataBase.LinkEffectDiscription());
  27. bool CanSelectPermanentCondition(Permanent permanent)
  28. {
  29. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card))
  30. {
  31. if(permanent != card.PermanentOfThisCard())
  32. {
  33. if (permanent.IsDigimon)
  34. {
  35. if (card.linkCondition == null || card.linkCondition.digimonCondition(permanent))
  36. {
  37. return true;
  38. }
  39. }
  40. }
  41. }
  42. return false;
  43. }
  44. bool CanUseCondition(Hashtable hashtable)
  45. {
  46. if (CardEffectCommons.IsExistOnHand(card) || (CardEffectCommons.IsExistOnBattleAreaDigimon(card) && !card.IsLinked))
  47. {
  48. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  49. {
  50. if (condition == null || condition())
  51. {
  52. return true;
  53. }
  54. }
  55. }
  56. return false;
  57. }
  58. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  59. {
  60. Permanent selectedPermanent = null;
  61. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  62. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  63. selectPermanentEffect.SetUp(
  64. selectPlayer: card.Owner,
  65. canTargetCondition: CanSelectPermanentCondition,
  66. canTargetCondition_ByPreSelecetedList: null,
  67. canEndSelectCondition: null,
  68. maxCount: maxCount,
  69. canNoSelect: false,
  70. canEndNotMax: false,
  71. selectPermanentCoroutine: SelectPermanentCoroutine,
  72. afterSelectPermanentCoroutine: null,
  73. mode: SelectPermanentEffect.Mode.Custom,
  74. cardEffect: activateClass);
  75. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to link.", "The opponent is selecting 1 Digimon to link.");
  76. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  77. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  78. {
  79. selectedPermanent = permanent;
  80. yield return null;
  81. }
  82. if (selectedPermanent != null)
  83. {
  84. yield return ContinuousController.instance.StartCoroutine(new ILinkCard(true, card, selectedPermanent, activateClass).LinkCard());
  85. }
  86. }
  87. return activateClass;
  88. }
  89. #endregion
  90. #region Granted Link Cost Reduction
  91. public static ChangeLinkCostClass GrantedReduceLinkCostClass(CardSource card, int reducedCost, Func<CardSource, bool> cardSourceCondition, Func<Permanent, bool> permanentCondition, Func<SelectCardEffect.Root, bool> rootCondition)
  92. {
  93. return ReduceLinkCostClass(card, _ => true, false, false, reducedCost, cardSourceCondition, permanentCondition, rootCondition);
  94. }
  95. #endregion
  96. #region Get when would link granted cost reduction
  97. public static ChangeLinkCostClass GrantedChangeLinkCostClass(CardSource card, string effectName, Func<CardSource, Permanent, int, SelectCardEffect.Root, int> changeCostFunc, Func<CardSource, bool> cardSourceCondition, Func<Permanent, bool> permanentCondition, Func<SelectCardEffect.Root, bool> rootCondition, Func<bool> isUpDown)
  98. {
  99. return ChangeLinkCostClass(card, _ => true, effectName, false, false, changeCostFunc, cardSourceCondition, permanentCondition, rootCondition, isUpDown);
  100. }
  101. #endregion
  102. #region GetChangeLinkCostClass
  103. public static ChangeLinkCostClass ChangeLinkCostClass(CardSource card, Func<Hashtable, bool> canUseCondition, string effectName, bool isInheritedEffect, bool isOptional, Func<CardSource, Permanent, int, SelectCardEffect.Root, int> changeCostFunc, Func<CardSource, bool> cardSourceCondition, Func<Permanent, bool> permanentCondition, Func<SelectCardEffect.Root, bool> rootCondition, Func<bool> isUpDown)
  104. {
  105. ChangeLinkCostClass changeLinkCostClass = new ();
  106. changeLinkCostClass.SetUpICardEffect(effectName, canUseCondition, card);
  107. changeLinkCostClass.SetUpChangeLinkCostClass(changeCostFunc, cardSourceCondition, permanentCondition, rootCondition, isUpDown);
  108. changeLinkCostClass.SetNotShowUI(isOptional);
  109. changeLinkCostClass.SetIsInheritedEffect(isInheritedEffect);
  110. return changeLinkCostClass;
  111. }
  112. #endregion
  113. #region GetChangeLinkCostClass for Cost Reduction
  114. public static ChangeLinkCostClass ReduceLinkCostClass(CardSource card, Func<Hashtable, bool> canUseCondition, bool isInheritedEffect, bool isOptional, int reducedCost, Func<CardSource, bool> cardSourceCondition, Func<Permanent, bool> permanentCondition, Func<SelectCardEffect.Root, bool> rootCondition)
  115. {
  116. return ChangeLinkCostClass(card, canUseCondition, $"Link Cost -{reducedCost}", isInheritedEffect, isOptional, ChangeCost, cardSourceCondition, permanentCondition, rootCondition, () => true);
  117. int ChangeCost(CardSource cardSource, Permanent targetPermanent, int Cost, SelectCardEffect.Root root)
  118. {
  119. if (cardSourceCondition(cardSource))
  120. {
  121. if (rootCondition(root))
  122. {
  123. if (permanentCondition(targetPermanent))
  124. {
  125. Cost -= reducedCost;
  126. }
  127. }
  128. }
  129. return Cost;
  130. }
  131. }
  132. #endregion
  133. }