Link.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. public static ActivateClass LinkEffect(CardSource card, Func<bool> condition, Func<Permanent, bool> digimonCondition)
  10. {
  11. if (card == null) return null;
  12. if (!CardEffectCommons.IsExistOnHand(card) || !CardEffectCommons.IsExistOnBattleAreaDigimon(card)) return null;
  13. if (CardEffectCommons.HasMatchConditionPermanent(digimonCondition)) return null;
  14. ActivateClass activateClass = new ActivateClass();
  15. activateClass.SetUpICardEffect("Link", CanUseCondition, card);
  16. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, true, DataBase.BlastDigivolveEffectDiscription());
  17. bool CanSelectPermanentCondition(Permanent permanent)
  18. {
  19. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card))
  20. {
  21. if (card.CanPlayCardTargetFrame(permanent.PermanentFrame, false, activateClass))
  22. {
  23. if(!permanent.TopCard.CanNotBeAffected(activateClass))
  24. return true;
  25. }
  26. }
  27. return false;
  28. }
  29. bool CanUseCondition(Hashtable hashtable)
  30. {
  31. if (CardEffectCommons.IsExistOnHand(card) || CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  32. {
  33. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  34. {
  35. if (condition == null || condition())
  36. {
  37. return true;
  38. }
  39. }
  40. }
  41. return false;
  42. }
  43. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  44. {
  45. Permanent selectedPermanent = null;
  46. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  47. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  48. selectPermanentEffect.SetUp(
  49. selectPlayer: card.Owner,
  50. canTargetCondition: CanSelectPermanentCondition,
  51. canTargetCondition_ByPreSelecetedList: null,
  52. canEndSelectCondition: null,
  53. maxCount: maxCount,
  54. canNoSelect: false,
  55. canEndNotMax: false,
  56. selectPermanentCoroutine: SelectPermanentCoroutine,
  57. afterSelectPermanentCoroutine: null,
  58. mode: SelectPermanentEffect.Mode.Custom,
  59. cardEffect: activateClass);
  60. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to link.", "The opponent is selecting 1 Digimon to link.");
  61. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  62. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  63. {
  64. selectedPermanent = permanent;
  65. yield return null;
  66. }
  67. if (selectedPermanent != null)
  68. {
  69. if (CardEffectCommons.IsExistOnHand(card))
  70. yield return ContinuousController.instance.StartCoroutine(selectedPermanent.AddLinkedCard(card, activateClass));
  71. else
  72. yield return ContinuousController.instance.StartCoroutine(new ILinkPermanentToPermanent(new List<Permanent[]>() { new Permanent[] { card.PermanentOfThisCard(), selectedPermanent } }, activateClass).LinkPermanent());
  73. }
  74. }
  75. return activateClass;
  76. }
  77. #endregion
  78. }