CanNotBeDestroyedByBattleClass.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. public class CanNotBeDestroyedByBattleClass : ICardEffect, ICanNotBeDestroyedByBattleEffect
  6. {
  7. public void SetUpCanNotBeDestroyedByBattleClass(Func<Permanent, Permanent, Permanent, CardSource, bool> canNotBeDestroyedByBattleCondition, Func<Permanent, bool> permanentCondition)
  8. {
  9. _canNotBeDestroyedByBattleCondition = canNotBeDestroyedByBattleCondition;
  10. _permanentCondition = permanentCondition;
  11. }
  12. Func<Permanent, Permanent, Permanent, CardSource, bool> _canNotBeDestroyedByBattleCondition = null;
  13. Func<Permanent, bool> _permanentCondition = null;
  14. public bool CanNotBeDestroyedByBattle(Permanent permanent, Permanent attackingPermanent, Permanent defendingPermanent, CardSource defendingCard)
  15. {
  16. if (_canNotBeDestroyedByBattleCondition != null)
  17. {
  18. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  19. {
  20. if (PermanentCondition(permanent))
  21. {
  22. if (_canNotBeDestroyedByBattleCondition(permanent, attackingPermanent, defendingPermanent, defendingCard))
  23. {
  24. return true;
  25. }
  26. }
  27. }
  28. }
  29. return false;
  30. }
  31. public bool PermanentCondition(Permanent permanent)
  32. {
  33. if (_permanentCondition != null)
  34. {
  35. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  36. {
  37. if (_permanentCondition(permanent))
  38. {
  39. return true;
  40. }
  41. }
  42. }
  43. return false;
  44. }
  45. }