Alliance.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 [Alliance] on oneself
  9. public static ICardEffect AllianceSelfEffect(bool isInheritedEffect, CardSource card, Func<bool> condition)
  10. {
  11. Permanent targetPermanent = card.PermanentOfThisCard();
  12. bool CanUseCondition()
  13. {
  14. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  15. {
  16. if (condition == null || condition())
  17. {
  18. return true;
  19. }
  20. }
  21. return false;
  22. }
  23. return AllianceEffect(
  24. targetPermanent: targetPermanent,
  25. isInheritedEffect: isInheritedEffect,
  26. condition: CanUseCondition,
  27. rootCardEffect: null, card);
  28. }
  29. #endregion
  30. #region Trigger effect of [Alliance]
  31. public static ActivateClass AllianceEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition, ICardEffect rootCardEffect, CardSource card)
  32. {
  33. if (targetPermanent == null) return null;
  34. if (targetPermanent.TopCard == null) return null;
  35. if (card == null) return null;
  36. ActivateClass activateClass = new ActivateClass();
  37. activateClass.SetUpICardEffect("Alliance", CanUseCondition, card);
  38. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, DataBase.AllianceEffectDiscription());
  39. activateClass.SetIsInheritedEffect(isInheritedEffect);
  40. if (rootCardEffect != null)
  41. {
  42. activateClass.SetIsInheritedEffect(false);
  43. activateClass.SetEffectSourcePermanent(targetPermanent);
  44. activateClass.SetRootCardEffect(rootCardEffect);
  45. }
  46. bool CanUseCondition(Hashtable hashtable)
  47. {
  48. if (CardEffectCommons.CanTriggerOnPermanentAttack(hashtable, (permanent) => permanent.cardSources.Contains(targetPermanent.TopCard)))
  49. {
  50. if (condition == null || condition())
  51. {
  52. return true;
  53. }
  54. }
  55. return false;
  56. }
  57. bool CanActivateCondition(Hashtable hashtable)
  58. {
  59. return CardEffectCommons.CanActivateAlliance(hashtable, card);
  60. }
  61. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  62. {
  63. return CardEffectCommons.AllianceProcess(_hashtable, activateClass, targetPermanent, card);
  64. }
  65. return activateClass;
  66. }
  67. #endregion
  68. #region Static effect of [Alliance] to all PermanentCondition Digimon
  69. public static ActivateClass AllianceStaticEffect(Func<Permanent, bool> permanentCondition, bool isInheritedEffect, CardSource card, Func<bool> condition)
  70. {
  71. ActivateClass activateClass = new ActivateClass();
  72. activateClass.SetUpICardEffect("Alliance", CanUseCondition, card);
  73. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, DataBase.AllianceEffectDiscription());
  74. activateClass.SetIsInheritedEffect(isInheritedEffect);
  75. bool CanUseCondition(Hashtable hashtable)
  76. {
  77. if (CardEffectCommons.CanTriggerOnPermanentAttack(hashtable, permanentCondition))
  78. {
  79. if (condition == null || condition())
  80. {
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. bool CanActivateCondition(Hashtable hashtable)
  87. {
  88. Permanent attackingPermanent = CardEffectCommons.GetAttackerFromHashtable(hashtable);
  89. bool CanSelectPermanentCondition(Permanent permanent)
  90. {
  91. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card)
  92. && permanent != attackingPermanent
  93. && CardEffectCommons.CanActivateSuspendCostEffect(permanent.TopCard);
  94. }
  95. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(attackingPermanent, card)
  96. && CardEffectCommons.HasMatchConditionOwnersPermanent(card, CanSelectPermanentCondition)
  97. && (condition == null || condition());
  98. }
  99. IEnumerator ActivateCoroutine(Hashtable hashtable)
  100. {
  101. Permanent attackingPermanent = CardEffectCommons.GetAttackerFromHashtable(hashtable);
  102. return CardEffectCommons.AllianceProcess(hashtable, activateClass, attackingPermanent, card);
  103. }
  104. return activateClass;
  105. }
  106. #endregion
  107. }