CanNotBeBlocked.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectCommons
  7. {
  8. #region Target 1 Digimon can't be blocked
  9. public static IEnumerator GainCanNotBeBlocked(
  10. Permanent targetPermanent,
  11. Func<Permanent, bool> defenderCondition,
  12. EffectDuration effectDuration,
  13. ICardEffect activateClass,
  14. string effectName)
  15. {
  16. if (targetPermanent == null) yield break;
  17. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  18. if (activateClass == null) yield break;
  19. if (activateClass.EffectSourceCard == null) yield break;
  20. CardSource card = activateClass.EffectSourceCard;
  21. bool AttackerCondition(Permanent attacker) => attacker == targetPermanent;
  22. bool DefenderCondition(Permanent defender)
  23. {
  24. if (defenderCondition == null || defenderCondition(defender))
  25. {
  26. return true;
  27. }
  28. return false;
  29. }
  30. bool CanUseCondition()
  31. {
  32. if (IsPermanentExistsOnBattleArea(targetPermanent))
  33. {
  34. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  35. {
  36. return true;
  37. }
  38. }
  39. return false;
  40. }
  41. CannotBlockClass canNotAttackClass = CardEffectFactory.CanNotBlockStaticEffect(
  42. attackerCondition: AttackerCondition,
  43. defenderCondition: DefenderCondition,
  44. isInheritedEffect: false,
  45. card: card,
  46. condition: CanUseCondition,
  47. effectName: effectName);
  48. AddEffectToPermanent(
  49. targetPermanent: targetPermanent,
  50. effectDuration: effectDuration,
  51. card: card,
  52. cardEffect: canNotAttackClass,
  53. timing: EffectTiming.None);
  54. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  55. {
  56. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
  57. }
  58. }
  59. #endregion
  60. }