PermanentEffectFactory.cs 6.4 KB

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