Decode.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public partial class CardEffectCommons
  5. {
  6. static bool CanSelectSourceCardCondition(CardSource source, Func<CardSource, bool> sourceCondition, ICardEffect activateClass)
  7. {
  8. return source.IsDigimon &&
  9. sourceCondition(source) &&
  10. CanPlayAsNewPermanent(cardSource: source, payCost: false, cardEffect: activateClass);
  11. }
  12. #region Can activate [Decode]
  13. public static bool CanActivateDecode(CardSource cardSource, Func<CardSource, bool> sourceCondition, ICardEffect activateClass)
  14. {
  15. return IsExistOnBattleAreaDigimon(cardSource) &&
  16. cardSource.PermanentOfThisCard().DigivolutionCards.Some(
  17. source => CanSelectSourceCardCondition(source, sourceCondition, activateClass));
  18. }
  19. #endregion
  20. #region Effect process of [Decode]
  21. public static IEnumerator DecodeProcess(CardSource cardSource, Func<CardSource, bool> sourceCondition,string[] decodeStrings, ICardEffect activateClass)
  22. {
  23. List<CardSource> selectedCards = new List<CardSource>();
  24. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  25. selectCardEffect.SetUp(
  26. canTargetCondition: source => CanSelectSourceCardCondition(source, sourceCondition, activateClass),
  27. canTargetCondition_ByPreSelecetedList: null,
  28. canEndSelectCondition: null,
  29. canNoSelect: () => true,
  30. selectCardCoroutine: SelectCardCoroutine,
  31. afterSelectCardCoroutine: null,
  32. message: $"Select 1 {decodeStrings[0]} digivolution card to play.",
  33. maxCount: 1,
  34. canEndNotMax: false,
  35. isShowOpponent: true,
  36. mode: SelectCardEffect.Mode.Custom,
  37. root: SelectCardEffect.Root.Custom,
  38. customRootCardList: cardSource.PermanentOfThisCard().DigivolutionCards,
  39. canLookReverseCard: true,
  40. selectPlayer: cardSource.Owner,
  41. cardEffect: activateClass);
  42. selectCardEffect.SetUpCustomMessage(
  43. $"Select 1 {decodeStrings[0]} digivolution card to play.",
  44. $"The opponent is selecting 1 {decodeStrings[0]} digivolution card to play.");
  45. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  46. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  47. IEnumerator SelectCardCoroutine(CardSource source)
  48. {
  49. selectedCards.Add(source);
  50. yield return null;
  51. }
  52. yield return ContinuousController.instance.StartCoroutine(
  53. PlayPermanentCards(
  54. cardSources: selectedCards,
  55. activateClass: activateClass,
  56. payCost: false,
  57. isTapped: false,
  58. root: SelectCardEffect.Root.DigivolutionCards,
  59. activateETB: true));
  60. }
  61. #endregion
  62. #region Target 1 Digimon gains [Decode]
  63. public static IEnumerator GainDecode(Permanent targetPermanent, string[] decodeStrings, Func<CardSource, bool> sourceCondition, EffectDuration effectDuration,
  64. ICardEffect activateClass)
  65. {
  66. if (targetPermanent == null) yield break;
  67. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  68. if (activateClass == null) yield break;
  69. if (activateClass.EffectSourceCard == null) yield break;
  70. CardSource card = activateClass.EffectSourceCard;
  71. bool CanUseCondition()
  72. {
  73. return IsPermanentExistsOnBattleArea(targetPermanent) &&
  74. !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  75. }
  76. ActivateClass decode = CardEffectFactory.DecodeEffect(
  77. targetPermanent: targetPermanent, isInheritedEffect: false, decodeStrings,
  78. condition: CanUseCondition, sourceCondition: sourceCondition, rootCardEffect: activateClass, card);
  79. AddEffectToPermanent(
  80. targetPermanent: targetPermanent,
  81. effectDuration: effectDuration,
  82. card: card,
  83. cardEffect: decode,
  84. timing: EffectTiming.WhenRemoveField);
  85. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  86. {
  87. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  88. .CreateBuffEffect(targetPermanent));
  89. }
  90. }
  91. #endregion
  92. }