CanNotAttack.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 Player gains effect to have Digimon can't attack
  9. public static IEnumerator GainCanNotAttackPlayerEffect(
  10. Func<Permanent, bool> attackerCondition,
  11. Func<Permanent, bool> defenderCondition,
  12. EffectDuration effectDuration,
  13. ICardEffect activateClass,
  14. string effectName)
  15. {
  16. if (activateClass == null) yield break;
  17. if (activateClass.EffectSourceCard == null) yield break;
  18. CardSource card = activateClass.EffectSourceCard;
  19. bool AttackerCondition(Permanent attacker)
  20. {
  21. if (IsPermanentExistsOnBattleArea(attacker))
  22. {
  23. if (!attacker.TopCard.CanNotBeAffected(activateClass))
  24. {
  25. if (attackerCondition == null || attackerCondition(attacker))
  26. {
  27. return true;
  28. }
  29. }
  30. }
  31. return false;
  32. }
  33. bool DefenderCondition(Permanent defender)
  34. {
  35. if (defenderCondition == null || defenderCondition(defender))
  36. {
  37. return true;
  38. }
  39. return false;
  40. }
  41. bool Condition()
  42. {
  43. return true;
  44. }
  45. CanNotAttackTargetDefendingPermanentClass canNotAttackClass = CardEffectFactory.CanNotAttackStaticEffect(
  46. attackerCondition: AttackerCondition,
  47. defenderCondition: DefenderCondition,
  48. isInheritedEffect: false,
  49. card: card,
  50. condition: Condition,
  51. effectName: effectName);
  52. AddEffectToPlayer(effectDuration: effectDuration, card: card, cardEffect: canNotAttackClass, timing: EffectTiming.None);
  53. foreach (Permanent permanent in GManager.instance.turnStateMachine.gameContext.PermanentsForTurnPlayer)
  54. {
  55. if (AttackerCondition(permanent))
  56. {
  57. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(permanent));
  58. }
  59. }
  60. }
  61. #endregion
  62. }