PermanentEffectFactory.cs 7.0 KB

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