CanNotBlock.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectFactory
  7. {
  8. #region Static effect that oneself can't block
  9. public static CannotBlockClass CanNotBlockStaticSelfEffect(
  10. Func<Permanent, bool> attackerCondition,
  11. bool isInheritedEffect,
  12. CardSource card,
  13. Func<bool> condition,
  14. string effectName)
  15. {
  16. bool CanUseCondition()
  17. {
  18. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  19. {
  20. if (condition == null || condition())
  21. {
  22. return true;
  23. }
  24. }
  25. return false;
  26. }
  27. bool DefenderCondition(Permanent defender)
  28. {
  29. if (CardEffectCommons.IsPermanentExistsOnBattleArea(defender))
  30. {
  31. if (defender == card.PermanentOfThisCard())
  32. {
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. return CanNotBlockStaticEffect(
  39. attackerCondition: attackerCondition,
  40. defenderCondition: DefenderCondition,
  41. isInheritedEffect: isInheritedEffect,
  42. card: card,
  43. condition: CanUseCondition,
  44. effectName: effectName);
  45. }
  46. #endregion
  47. #region Static effect that can't block
  48. public static CannotBlockClass CanNotBlockStaticEffect(
  49. Func<Permanent, bool> attackerCondition,
  50. Func<Permanent, bool> defenderCondition,
  51. bool isInheritedEffect,
  52. CardSource card,
  53. Func<bool> condition,
  54. string effectName)
  55. {
  56. CannotBlockClass cannotBlockClass = new CannotBlockClass();
  57. cannotBlockClass.SetUpICardEffect(effectName, CanUseCondition, card);
  58. cannotBlockClass.SetUpCannotBlockClass(permanentsCondition: PermanentsCondition);
  59. if (isInheritedEffect)
  60. {
  61. cannotBlockClass.SetIsInheritedEffect(true);
  62. }
  63. bool CanUseCondition(Hashtable hashtable)
  64. {
  65. return condition == null || condition();
  66. }
  67. bool PermanentsCondition(Permanent attacker, Permanent defender)
  68. {
  69. return AttackerCondition(attacker) && DefenderCondition(defender);
  70. }
  71. bool AttackerCondition(Permanent attacker)
  72. {
  73. if (CardEffectCommons.IsPermanentExistsOnBattleArea(attacker))
  74. {
  75. if (!attacker.TopCard.CanNotBeAffected(cannotBlockClass))
  76. {
  77. if (attackerCondition == null || attackerCondition(attacker))
  78. {
  79. return true;
  80. }
  81. }
  82. }
  83. return false;
  84. }
  85. bool DefenderCondition(Permanent defender)
  86. {
  87. if (CardEffectCommons.IsPermanentExistsOnBattleArea(defender))
  88. {
  89. if (!defender.TopCard.CanNotBeAffected(cannotBlockClass))
  90. {
  91. if (defenderCondition == null || defenderCondition(defender))
  92. {
  93. return true;
  94. }
  95. }
  96. }
  97. return false;
  98. }
  99. return cannotBlockClass;
  100. }
  101. #endregion
  102. }