Link.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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", 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))
  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. yield return ContinuousController.instance.StartCoroutine(card.Owner.AddMemory(-card.linkCondition.cost, activateClass));
  61. Permanent selectedPermanent = null;
  62. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  63. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  64. selectPermanentEffect.SetUp(
  65. selectPlayer: card.Owner,
  66. canTargetCondition: CanSelectPermanentCondition,
  67. canTargetCondition_ByPreSelecetedList: null,
  68. canEndSelectCondition: null,
  69. maxCount: maxCount,
  70. canNoSelect: false,
  71. canEndNotMax: false,
  72. selectPermanentCoroutine: SelectPermanentCoroutine,
  73. afterSelectPermanentCoroutine: null,
  74. mode: SelectPermanentEffect.Mode.Custom,
  75. cardEffect: activateClass);
  76. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to link.", "The opponent is selecting 1 Digimon to link.");
  77. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  78. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  79. {
  80. selectedPermanent = permanent;
  81. yield return null;
  82. }
  83. if (selectedPermanent != null)
  84. {
  85. yield return ContinuousController.instance.StartCoroutine(selectedPermanent.AddLinkCard(card, activateClass));
  86. }
  87. }
  88. return activateClass;
  89. }
  90. #endregion
  91. }