Partition.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. using static UnityEngine.UI.GridLayoutGroup;
  7. public partial class CardEffectCommons
  8. {
  9. #region Can trigger [Partition]
  10. public static bool CanTriggerPartition(Hashtable hashtable, CardSource card)
  11. {
  12. if (CanTriggerWhenPermanentRemoveField(hashtable, (permanent) => permanent.cardSources.Contains(card)))
  13. {
  14. if (!IsByBattle(hashtable))
  15. {
  16. if (!IsByEffect(hashtable, cardEffect => IsOwnerEffect(cardEffect, card)))
  17. {
  18. return true;
  19. }
  20. }
  21. }
  22. return false;
  23. }
  24. #endregion
  25. #region Can activate [Partition]
  26. public static bool CanActivatePartition(Permanent permanent)
  27. {
  28. if (IsPermanentExistsOnBattleArea(permanent))
  29. {
  30. if (permanent.DigivolutionCards.Count >= 1)
  31. {
  32. return true;
  33. }
  34. }
  35. return false;
  36. }
  37. #endregion
  38. #region Effect process of [Partition]
  39. public static IEnumerator PartitionProcess(ICardEffect activateClass, Permanent permanent, Func<CardSource, bool> CanSelectCardCondition)
  40. {
  41. yield return ContinuousController.instance.StartCoroutine(new PartitionClass(permanent).Partition(activateClass, CanSelectCardCondition));
  42. }
  43. #endregion
  44. #region Partition class
  45. public class PartitionClass
  46. {
  47. public PartitionClass(Permanent permanent)
  48. {
  49. _permanent = permanent;
  50. }
  51. Permanent _permanent = null;
  52. public IEnumerator Partition(ICardEffect activateClass, Func<CardSource, bool> CanSelectCardCondition)
  53. {
  54. if (_permanent != null)
  55. {
  56. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  57. CardSource topCard = _permanent.TopCard;
  58. List<CardSource> selectedCards = new List<CardSource>();
  59. if (_permanent.TopCard != null)
  60. {
  61. //int maxCount = Math.Min(1, MatchConditionPermanentCount(CanSelectCardCondition));
  62. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  63. selectCardEffect.SetUp(
  64. canTargetCondition: CanSelectCardCondition,
  65. canTargetCondition_ByPreSelecetedList: null,
  66. canEndSelectCondition: null,
  67. canNoSelect: () => false,
  68. selectCardCoroutine: SelectCardCoroutine,
  69. afterSelectCardCoroutine: null,
  70. message: "Select card to play",
  71. maxCount: 1,
  72. canEndNotMax: false,
  73. isShowOpponent: false,
  74. mode: SelectCardEffect.Mode.Custom,
  75. root: SelectCardEffect.Root.DigivolutionCards,
  76. customRootCardList: _permanent.cardSources,
  77. canLookReverseCard: true,
  78. selectPlayer: topCard.Owner,
  79. cardEffect: activateClass);
  80. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  81. IEnumerator SelectCardCoroutine(CardSource cardSource)
  82. {
  83. selectedCards.Add(cardSource);
  84. yield return null;
  85. }
  86. }
  87. foreach(CardSource card in selectedCards)
  88. {
  89. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  90. cardSources: new List<CardSource>() { card },
  91. activateClass: activateClass,
  92. payCost: false,
  93. isTapped: false,
  94. root: SelectCardEffect.Root.Trash,
  95. activateETB: true));
  96. }
  97. #region Play Log
  98. string log = "";
  99. log += $"\nPartition :";
  100. log += $"\n{topCard.BaseENGCardNameFromEntity}({topCard.CardID})";
  101. log += "\n";
  102. GManager.instance.playLog.AddLogString(log);
  103. #endregion
  104. }
  105. }
  106. }
  107. #endregion
  108. }