PermanentEffectFactory.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. /// <summary>
  5. /// Class for given effects for Permanents, applying to the entire stack even if any specific card is removed from it
  6. /// </summary>
  7. public partial class PermanentEffectFactory
  8. {
  9. #region Effect of a Permanent to Delete Itself
  10. public static ActivateClass DeleteSelfEffect(Permanent permanent, ICardEffect cardEffect, bool deleteOnOwnturn = true, bool deleteOnOpponentsTurn = true)
  11. {
  12. if(permanent == null || permanent.TopCard == null) return null;
  13. ActivateClass activateClass = new ActivateClass();
  14. activateClass.SetUpICardEffect("Delete this Digimon", CanUseCondition, permanent.TopCard);
  15. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, "");
  16. activateClass.SetEffectSourcePermanent(permanent);
  17. return activateClass;
  18. bool CanUseCondition(Hashtable hashtable)
  19. {
  20. if (permanent.TopCard != null
  21. && CardEffectCommons.IsExistOnBattleArea(permanent.TopCard)
  22. && !permanent.TopCard.CanNotBeAffected(cardEffect))
  23. {
  24. if (CardEffectCommons.IsOwnerTurn(permanent.TopCard))
  25. {
  26. return deleteOnOwnturn;
  27. }
  28. else
  29. {
  30. return deleteOnOpponentsTurn;
  31. }
  32. }
  33. return false;
  34. }
  35. bool CanActivateCondition(Hashtable hashtable)
  36. {
  37. return permanent.TopCard != null
  38. && CardEffectCommons.IsExistOnBattleArea(permanent.TopCard);
  39. }
  40. IEnumerator ActivateCoroutine(Hashtable hashtable)
  41. {
  42. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(new List<Permanent>() { permanent }, CardEffectCommons.CardEffectHashtable(activateClass)).Destroy());
  43. }
  44. }
  45. #endregion
  46. #region Digimon Effect Immunity
  47. public static CanNotAffectedClass DigimonEffectImmunity(Permanent permanent)
  48. {
  49. if(permanent == null || permanent.TopCard == null) return null;
  50. bool CanUseCondition1(Hashtable hashtable)
  51. {
  52. return CardEffectCommons.IsExistOnBattleAreaDigimon(permanent.TopCard);
  53. }
  54. bool CardCondition(CardSource cardSource)
  55. {
  56. return cardSource == permanent.TopCard
  57. && CardEffectCommons.IsExistOnBattleAreaDigimon(permanent.TopCard);
  58. }
  59. bool SkillCondition(ICardEffect cardEffect)
  60. {
  61. return CardEffectCommons.IsOpponentEffect(cardEffect, permanent.TopCard)
  62. && cardEffect.IsDigimonEffect;
  63. }
  64. CanNotAffectedClass canNotAffectedClass = new CanNotAffectedClass();
  65. canNotAffectedClass.SetUpICardEffect("Not affected by opponent's Digimon's effects", CanUseCondition1, permanent.TopCard);
  66. canNotAffectedClass.SetUpCanNotAffectedClass(CardCondition: CardCondition, SkillCondition: SkillCondition);
  67. canNotAffectedClass.SetEffectSourcePermanent(permanent);
  68. return canNotAffectedClass;
  69. }
  70. #endregion
  71. #region Option Effect Immunity
  72. public static CanNotAffectedClass OptionEffectImmunity(Permanent permanent)
  73. {
  74. if(permanent == null || permanent.TopCard == null) return null;
  75. bool CanUseCondition1(Hashtable hashtable)
  76. {
  77. return CardEffectCommons.IsExistOnBattleAreaDigimon(permanent.TopCard);
  78. }
  79. bool CardCondition(CardSource cardSource)
  80. {
  81. return cardSource == permanent.TopCard
  82. && CardEffectCommons.IsExistOnBattleAreaDigimon(permanent.TopCard);
  83. }
  84. bool SkillCondition(ICardEffect cardEffect)
  85. {
  86. return CardEffectCommons.IsOpponentEffect(cardEffect, permanent.TopCard)
  87. && !cardEffect.IsDigimonEffect && !cardEffect.IsTamerEffect;
  88. }
  89. CanNotAffectedClass canNotAffectedClass = new CanNotAffectedClass();
  90. canNotAffectedClass.SetUpICardEffect("Not affected by opponent's Option effects", CanUseCondition1, permanent.TopCard);
  91. canNotAffectedClass.SetUpCanNotAffectedClass(CardCondition: CardCondition, SkillCondition: SkillCondition);
  92. canNotAffectedClass.SetEffectSourcePermanent(permanent);
  93. return canNotAffectedClass;
  94. }
  95. #endregion
  96. #region Cannot change Attack Target Effect
  97. public static CanNotSwitchAttackTargetClass CanNotSwitchAttackTargetEffect(Permanent targetPermanent, ICardEffect activateClass)
  98. {
  99. if(targetPermanent == null || targetPermanent.TopCard == null) return null;
  100. CanNotSwitchAttackTargetClass canNotSwitchAttackTargetClass = new CanNotSwitchAttackTargetClass();
  101. canNotSwitchAttackTargetClass.SetUpICardEffect("This Digimon's attack target can't be switched.", CanUseCondition, targetPermanent.TopCard);
  102. canNotSwitchAttackTargetClass.SetUpCanNotSwitchAttackTargetClass(PermanentCondition: PermanentCondition);
  103. return canNotSwitchAttackTargetClass;
  104. bool CanUseCondition(Hashtable hashtable)
  105. {
  106. return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)
  107. && CardEffectCommons.IsOwnerTurn(targetPermanent.TopCard)
  108. && !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  109. }
  110. bool PermanentCondition(Permanent permanent)
  111. {
  112. return permanent != null && permanent.TopCard && permanent == targetPermanent;
  113. }
  114. }
  115. #endregion
  116. #region Gain Collision Effect
  117. public static CollisionClass CollisionEffect(Permanent targetPermanent, ICardEffect activateClass)
  118. {
  119. if(targetPermanent == null || targetPermanent.TopCard == null) return null;
  120. return CardEffectFactory.CollisionStaticEffect(PermanentCondition, false, targetPermanent.TopCard, CanUseCondition);
  121. bool CanUseCondition()
  122. {
  123. return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)
  124. && !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  125. }
  126. bool PermanentCondition(Permanent permanent) => permanent == targetPermanent;
  127. }
  128. #endregion
  129. #region Add Detail for Display
  130. public static AddDetailClass AddDetailClass(Permanent targetPermanent, string detail, bool triggerEffect, ICardEffect activateClass)
  131. {
  132. if(targetPermanent == null || targetPermanent.TopCard == null) return null;
  133. return StaticAddDetailClass(CanUseCondition, PermanentCondition, detail, triggerEffect, activateClass);
  134. bool PermanentCondition(Permanent permanent)
  135. {
  136. return permanent != null
  137. && permanent == targetPermanent
  138. && !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  139. }
  140. bool CanUseCondition(Hashtable hashtable)
  141. {
  142. return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent);
  143. }
  144. }
  145. #endregion
  146. #region Add Global Detail for Display
  147. public static AddDetailClass StaticAddDetailClass(Func<Hashtable, bool> canUseCondition, Func<Permanent, bool> permanentCondition, string detail, bool triggerEffect, ICardEffect activateClass)
  148. {
  149. return CardEffectFactory.AddDetailClass(canUseCondition, permanentCondition, detail, triggerEffect, activateClass.EffectSourceCard);
  150. }
  151. #endregion
  152. }