CanNotBeAttacked.cs 2.2 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 attacked
  9. public static IEnumerator GainCanNotBeAttacked(
  10. Permanent targetPermanent,
  11. Func<Permanent, bool> attackerCondition,
  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 defender)
  22. {
  23. if (attackerCondition == null || attackerCondition(defender))
  24. {
  25. return true;
  26. }
  27. return false;
  28. }
  29. bool DefenderCondition(Permanent attacker) => attacker == targetPermanent;
  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. CanNotAttackTargetDefendingPermanentClass canNotAttackClass = CardEffectFactory.CanNotAttackStaticEffect(
  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. }