PermanentEffectFactory.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. /// <summary>
  7. /// Class for given effects for Permanents, applying to the entire stack even if any specific card is removed from it
  8. /// </summary>
  9. public partial class PermanentEffectFactory
  10. {
  11. #region Effect of a Permanent to Delete Itself
  12. public static ActivateClass DeleteSelfEffect(Permanent permanent, ICardEffect cardEffect, bool deleteOnOwnturn = true, bool deleteOnOpponentsTurn = true)
  13. {
  14. ActivateClass activateClass = new ActivateClass();
  15. activateClass.SetUpICardEffect("Delete this Digimon", CanUseCondition, permanent.TopCard);
  16. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, "");
  17. activateClass.SetEffectSourcePermanent(permanent);
  18. return activateClass;
  19. bool CanUseCondition(Hashtable hashtable)
  20. {
  21. if (permanent.TopCard != null
  22. && CardEffectCommons.IsExistOnBattleArea(permanent.TopCard)
  23. && !permanent.TopCard.CanNotBeAffected(cardEffect))
  24. {
  25. if (CardEffectCommons.IsOwnerTurn(permanent.TopCard))
  26. {
  27. return deleteOnOwnturn;
  28. }
  29. else
  30. {
  31. return deleteOnOpponentsTurn;
  32. }
  33. }
  34. return false;
  35. }
  36. bool CanActivateCondition(Hashtable hashtable)
  37. {
  38. return permanent.TopCard != null
  39. && CardEffectCommons.IsExistOnBattleArea(permanent.TopCard);
  40. }
  41. IEnumerator ActivateCoroutine(Hashtable hashtable)
  42. {
  43. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(new List<Permanent>() { permanent }, CardEffectCommons.CardEffectHashtable(activateClass)).Destroy());
  44. }
  45. }
  46. #endregion
  47. #region Digimon Effect Immunity
  48. public static CanNotAffectedClass DigimonEffectImmunity(Permanent permanent)
  49. {
  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 Cannot change Attack Target Effect
  72. public static CanNotSwitchAttackTargetClass CanNotSwitchAttackTargetEffect(Permanent targetPermanent, ICardEffect activateClass)
  73. {
  74. CanNotSwitchAttackTargetClass canNotSwitchAttackTargetClass = new CanNotSwitchAttackTargetClass();
  75. canNotSwitchAttackTargetClass.SetUpICardEffect("This Digimon's attack target can't be switched.", CanUseCondition, targetPermanent.TopCard);
  76. canNotSwitchAttackTargetClass.SetUpCanNotSwitchAttackTargetClass(PermanentCondition: PermanentCondition);
  77. return canNotSwitchAttackTargetClass;
  78. bool CanUseCondition(Hashtable hashtable)
  79. {
  80. return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)
  81. && CardEffectCommons.IsOwnerTurn(targetPermanent.TopCard)
  82. && !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  83. }
  84. bool PermanentCondition(Permanent permanent)
  85. {
  86. return permanent != null && permanent.TopCard && permanent == targetPermanent;
  87. }
  88. }
  89. #endregion
  90. #region Gain Collision Effect
  91. public static CollisionClass CollisionEffect(Permanent targetPermanent, ICardEffect activateClass)
  92. {
  93. return CardEffectFactory.CollisionStaticEffect(PermanentCondition, false, targetPermanent.TopCard, CanUseCondition);
  94. bool CanUseCondition()
  95. {
  96. return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)
  97. && !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  98. }
  99. bool PermanentCondition(Permanent permanent) => permanent == targetPermanent;
  100. }
  101. #endregion
  102. #region Add Detail for Display
  103. public static AddDetailClass AddDetailClass(Permanent targetPermanent, string detail, bool triggerEffect, ICardEffect activateClass)
  104. {
  105. return CardEffectFactory.AddDetailClass(CanUseCondition, PermanentCondition, detail, triggerEffect, activateClass.EffectSourceCard);
  106. bool PermanentCondition(Permanent permanent)
  107. {
  108. return permanent != null
  109. && permanent == targetPermanent;
  110. }
  111. bool CanUseCondition(Hashtable hashtable)
  112. {
  113. return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)
  114. && !targetPermanent.TopCard.CanNotBeAffected(activateClass);
  115. }
  116. }
  117. #endregion
  118. }