PermanentEffectFactory.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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, 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 && CardEffectCommons.IsExistOnBattleArea(permanent.TopCard))
  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. bool CanUseCondition1(Hashtable hashtable)
  49. {
  50. return CardEffectCommons.IsExistOnBattleAreaDigimon(permanent.TopCard);
  51. }
  52. bool CardCondition(CardSource cardSource)
  53. {
  54. return cardSource == permanent.TopCard
  55. && CardEffectCommons.IsExistOnBattleAreaDigimon(permanent.TopCard);
  56. }
  57. bool SkillCondition(ICardEffect cardEffect)
  58. {
  59. return CardEffectCommons.IsOpponentEffect(cardEffect, permanent.TopCard)
  60. && cardEffect.IsDigimonEffect;
  61. }
  62. CanNotAffectedClass canNotAffectedClass = new CanNotAffectedClass();
  63. canNotAffectedClass.SetUpICardEffect("Not affected by opponent's Digimon's effects", CanUseCondition1, permanent.TopCard);
  64. canNotAffectedClass.SetUpCanNotAffectedClass(CardCondition: CardCondition, SkillCondition: SkillCondition);
  65. canNotAffectedClass.SetEffectSourcePermanent(permanent);
  66. return canNotAffectedClass;
  67. }
  68. #endregion
  69. #region Cannot change Attack Target Effect
  70. public static CanNotSwitchAttackTargetClass CanNotSwitchAttackTargetEffect(Permanent targetPermanent)
  71. {
  72. CanNotSwitchAttackTargetClass canNotSwitchAttackTargetClass = new CanNotSwitchAttackTargetClass();
  73. canNotSwitchAttackTargetClass.SetUpICardEffect("This Digimon's attack target can't be switched.", CanUseCondition, targetPermanent.TopCard);
  74. canNotSwitchAttackTargetClass.SetUpCanNotSwitchAttackTargetClass(PermanentCondition: PermanentCondition);
  75. return canNotSwitchAttackTargetClass;
  76. bool CanUseCondition(Hashtable hashtable)
  77. {
  78. return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent) &&
  79. CardEffectCommons.IsOwnerTurn(targetPermanent.TopCard);
  80. }
  81. bool PermanentCondition(Permanent permanent)
  82. {
  83. return permanent != null && permanent.TopCard && permanent == targetPermanent;
  84. }
  85. }
  86. #endregion
  87. }