Link.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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, int cost, int dp, Func<bool> condition = null, Func<Permanent, bool> digimonCondition = 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.BlastDigivolveEffectDiscription());
  27. bool CanSelectPermanentCondition(Permanent permanent)
  28. {
  29. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card))
  30. {
  31. if (digimonCondition == null || digimonCondition(permanent))
  32. {
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. bool CanUseCondition(Hashtable hashtable)
  39. {
  40. if (CardEffectCommons.IsExistOnHand(card) || CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  41. {
  42. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  43. {
  44. if (condition == null || condition())
  45. {
  46. return true;
  47. }
  48. }
  49. }
  50. return false;
  51. }
  52. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  53. {
  54. yield return ContinuousController.instance.StartCoroutine(card.Owner.AddMemory(-cost, activateClass));
  55. Permanent selectedPermanent = null;
  56. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  57. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  58. selectPermanentEffect.SetUp(
  59. selectPlayer: card.Owner,
  60. canTargetCondition: CanSelectPermanentCondition,
  61. canTargetCondition_ByPreSelecetedList: null,
  62. canEndSelectCondition: null,
  63. maxCount: maxCount,
  64. canNoSelect: false,
  65. canEndNotMax: false,
  66. selectPermanentCoroutine: SelectPermanentCoroutine,
  67. afterSelectPermanentCoroutine: null,
  68. mode: SelectPermanentEffect.Mode.Custom,
  69. cardEffect: activateClass);
  70. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to link.", "The opponent is selecting 1 Digimon to link.");
  71. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  72. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  73. {
  74. selectedPermanent = permanent;
  75. yield return null;
  76. }
  77. if (selectedPermanent != null)
  78. {
  79. if (CardEffectCommons.IsExistOnHand(card))
  80. yield return ContinuousController.instance.StartCoroutine(selectedPermanent.AddLinkedCard(card, dp, activateClass));
  81. else
  82. yield return ContinuousController.instance.StartCoroutine(new ILinkPermanentToPermanent(new List<Permanent[]>() { new Permanent[] { card.PermanentOfThisCard(), selectedPermanent } }, dp, activateClass).LinkPermanent());
  83. }
  84. }
  85. return activateClass;
  86. }
  87. #endregion
  88. }