CanNotBeDeletedByEffect.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 can't be deleted by effect
  9. public static CanNotBeDestroyedBySkillClass CanNotBeDestroyedBySkillStaticEffect(Func<Permanent, bool> permanentCondition, Func<ICardEffect, bool> cardEffectCondition, bool isInheritedEffect, CardSource card, Func<bool> condition, string effectName)
  10. {
  11. CanNotBeDestroyedBySkillClass canNotBeDestroyedBySkillClass = new CanNotBeDestroyedBySkillClass();
  12. canNotBeDestroyedBySkillClass.SetUpICardEffect(effectName, CanUseCondition, card);
  13. canNotBeDestroyedBySkillClass.SetUpCanNotBeDestroyedBySkillClass(canNotBeDestroyedCondition: CanNotBeDestroyedCondition);
  14. if (isInheritedEffect)
  15. {
  16. canNotBeDestroyedBySkillClass.SetIsInheritedEffect(true);
  17. }
  18. bool CanUseCondition(Hashtable hashtable)
  19. {
  20. return condition == null || condition();
  21. }
  22. bool CanNotBeDestroyedCondition(Permanent permanent, ICardEffect cardEffect)
  23. {
  24. if (PermanentCondition(permanent))
  25. {
  26. if (CardEffectCondition(cardEffect))
  27. {
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33. bool PermanentCondition(Permanent permanent)
  34. {
  35. if (CardEffectCommons.IsPermanentExistsOnField(permanent))
  36. {
  37. if (!permanent.TopCard.CanNotBeAffected(canNotBeDestroyedBySkillClass))
  38. {
  39. if (permanentCondition == null || permanentCondition(permanent))
  40. {
  41. return true;
  42. }
  43. }
  44. }
  45. return false;
  46. }
  47. bool CardEffectCondition(ICardEffect cardEffect)
  48. {
  49. if (cardEffectCondition == null || cardEffectCondition(cardEffect))
  50. {
  51. return true;
  52. }
  53. return false;
  54. }
  55. return canNotBeDestroyedBySkillClass;
  56. }
  57. #endregion
  58. }