PlayEffects.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectCommons
  7. {
  8. public static IEnumerator PlayByEffect(Func<CardSource, bool> canTargetCondition,
  9. SelectCardEffect.Root root,
  10. ICardEffect cardEffect,
  11. bool payCost,
  12. Func<List<CardSource>, CardSource, bool> canTargetCondition_ByPreSelecetedList = null,
  13. Func<List<CardSource>, bool> canEndSelectCondition = null,
  14. Func<List<CardSource>, IEnumerator> afterSelectCardCoroutine = null,
  15. int maxCount = 1,
  16. bool canNoSelect = true,
  17. bool canEndNotMax = false,
  18. (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple = null,
  19. (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple = null,
  20. Permanent targetPermanent = null)
  21. {
  22. if (cardEffect == null) yield break;
  23. Player owner = cardEffect.EffectSourceCard.Owner;
  24. List<CardSource> selectedCards = new List<CardSource>();
  25. IEnumerator SelectCardCoroutine(CardSource card)
  26. {
  27. selectedCards.Add(card);
  28. yield return null;
  29. }
  30. switch (root)
  31. {
  32. case SelectCardEffect.Root.Hand:
  33. {
  34. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  35. selectHandEffect.SetUp(
  36. selectPlayer: owner,
  37. canTargetCondition: canTargetCondition,
  38. canTargetCondition_ByPreSelecetedList: canTargetCondition_ByPreSelecetedList,
  39. canEndSelectCondition: canEndSelectCondition,
  40. maxCount: maxCount,
  41. canNoSelect: canNoSelect,
  42. canEndNotMax: canEndNotMax,
  43. isShowOpponent: true,
  44. selectCardCoroutine: SelectCardCoroutine,
  45. afterSelectCardCoroutine: afterSelectCardCoroutine,
  46. mode: SelectHandEffect.Mode.Custom,
  47. cardEffect: cardEffect);
  48. selectHandEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  49. selectHandEffect.SetUpCustomMessage_ShowCard("Played Card");
  50. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  51. break;
  52. }
  53. case SelectCardEffect.Root.DigivolutionCards:
  54. {
  55. if (targetPermanent == null) yield break;
  56. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  57. selectCardEffect.SetUp(
  58. canTargetCondition: canTargetCondition,
  59. canTargetCondition_ByPreSelecetedList: canTargetCondition_ByPreSelecetedList,
  60. canEndSelectCondition: canEndSelectCondition,
  61. canNoSelect: () => canNoSelect,
  62. selectCardCoroutine: SelectCardCoroutine,
  63. afterSelectCardCoroutine: afterSelectCardCoroutine,
  64. message: "Select 1 card to play.",
  65. maxCount: maxCount,
  66. canEndNotMax: canEndNotMax,
  67. isShowOpponent: true,
  68. mode: SelectCardEffect.Mode.Custom,
  69. root: root,
  70. customRootCardList: targetPermanent.DigivolutionCards,
  71. canLookReverseCard: true,
  72. selectPlayer: owner,
  73. cardEffect: cardEffect);
  74. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  75. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  76. break;
  77. }
  78. case SelectCardEffect.Root.LinkedCards:
  79. {
  80. if (targetPermanent == null) yield break;
  81. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  82. selectCardEffect.SetUp(
  83. canTargetCondition: canTargetCondition,
  84. canTargetCondition_ByPreSelecetedList: canTargetCondition_ByPreSelecetedList,
  85. canEndSelectCondition: canEndSelectCondition,
  86. canNoSelect: () => canNoSelect,
  87. selectCardCoroutine: SelectCardCoroutine,
  88. afterSelectCardCoroutine: afterSelectCardCoroutine,
  89. message: "Select 1 card to play.",
  90. maxCount: maxCount,
  91. canEndNotMax: canEndNotMax,
  92. isShowOpponent: true,
  93. mode: SelectCardEffect.Mode.Custom,
  94. root: root,
  95. customRootCardList: targetPermanent.LinkedCards,
  96. canLookReverseCard: true,
  97. selectPlayer: owner,
  98. cardEffect: cardEffect);
  99. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  100. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  101. break;
  102. }
  103. default:
  104. {
  105. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  106. selectCardEffect.SetUp(
  107. canTargetCondition: canTargetCondition,
  108. canTargetCondition_ByPreSelecetedList: canTargetCondition_ByPreSelecetedList,
  109. canEndSelectCondition: canEndSelectCondition,
  110. canNoSelect: () => canNoSelect,
  111. selectCardCoroutine: SelectCardCoroutine,
  112. afterSelectCardCoroutine: afterSelectCardCoroutine,
  113. message: "Select 1 card to play.",
  114. maxCount: maxCount,
  115. canEndNotMax: canEndNotMax,
  116. isShowOpponent: true,
  117. mode: SelectCardEffect.Mode.Custom,
  118. root: root,
  119. customRootCardList: null,
  120. canLookReverseCard: true,
  121. selectPlayer: owner,
  122. cardEffect: cardEffect);
  123. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  124. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  125. break;
  126. }
  127. }
  128. bool PermanentsCondition(List<Permanent> targetPermanents)
  129. {
  130. if (targetPermanents == null)
  131. {
  132. return true;
  133. }
  134. else
  135. {
  136. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  137. {
  138. return true;
  139. }
  140. }
  141. return false;
  142. }
  143. bool SharedCardCondition(CardSource cardSource) => selectedCards.Contains(cardSource);
  144. bool RootCondition(SelectCardEffect.Root root) => true;
  145. bool CanUseCondition(Hashtable hashtable) => true;
  146. #region reduce cost
  147. Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
  148. if (reduceCostTuple != null)
  149. {
  150. bool CardCondition(CardSource cardSource)
  151. {
  152. return SharedCardCondition(cardSource)
  153. && (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource));
  154. }
  155. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  156. {
  157. if (PermanentsCondition(targetPermanents))
  158. {
  159. Cost -= reduceCostTuple.Value.reduceCost;
  160. }
  161. return Cost;
  162. }
  163. bool isUpDown() => true;
  164. ChangeCostClass changeCostClass = new ChangeCostClass();
  165. changeCostClass.SetUpICardEffect($"Play Cost -{reduceCostTuple.Value.reduceCost}", CanUseCondition, cardEffect.EffectSourceCard);
  166. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  167. getChangeCostEffect = GetCardEffect;
  168. ICardEffect GetCardEffect(EffectTiming _timing)
  169. {
  170. if (_timing == EffectTiming.None)
  171. {
  172. return changeCostClass;
  173. }
  174. return null;
  175. }
  176. if (getChangeCostEffect != null)
  177. {
  178. owner.UntilCalculateFixedCostEffect.Add(getChangeCostEffect);
  179. }
  180. }
  181. #endregion
  182. #region set fixed cost
  183. Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
  184. if (fixedCostTuple != null)
  185. {
  186. bool CardCondition(CardSource cardSource)
  187. {
  188. return SharedCardCondition(cardSource)
  189. && (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource));
  190. }
  191. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  192. {
  193. if (PermanentsCondition(targetPermanents))
  194. {
  195. Cost = fixedCostTuple.Value.fixedCost;
  196. }
  197. return Cost;
  198. }
  199. bool isUpDown() => false;
  200. ChangeCostClass changeCostClass = new ChangeCostClass();
  201. changeCostClass.SetUpICardEffect($"Play Cost {fixedCostTuple.Value.fixedCost}", CanUseCondition, cardEffect.EffectSourceCard);
  202. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  203. getFixedCostEffect = GetCardEffect;
  204. ICardEffect GetCardEffect(EffectTiming _timing)
  205. {
  206. if (_timing == EffectTiming.None)
  207. {
  208. return changeCostClass;
  209. }
  210. return null;
  211. }
  212. if (getFixedCostEffect != null)
  213. {
  214. owner.UntilCalculateFixedCostEffect.Add(getFixedCostEffect);
  215. }
  216. }
  217. #endregion
  218. yield return ContinuousController.instance.StartCoroutine(
  219. CardEffectCommons.PlayPermanentCards(
  220. cardSources: selectedCards,
  221. activateClass: cardEffect,
  222. payCost: payCost,
  223. isTapped: false,
  224. root: root,
  225. activateETB: true));
  226. #region release effect
  227. if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
  228. #endregion
  229. #region release effect
  230. if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
  231. #endregion
  232. }
  233. //TODO: UseByEffect
  234. //TODO: PlayOrUseByEffect
  235. }