Decoy.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 Trigger effect of [Decoy] on oneself
  9. public static ActivateClass DecoySelfEffect(bool isInheritedEffect, CardSource card, Func<bool> condition, Func<Permanent, bool> permanentCondition, string effectName, string effectDiscription, ICardEffect rootCardEffect = null)
  10. {
  11. Permanent targetPermanent = card.PermanentOfThisCard();
  12. bool CanUseCondition()
  13. {
  14. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  15. {
  16. if (condition == null || condition())
  17. {
  18. return true;
  19. }
  20. }
  21. return false;
  22. }
  23. return DecoyEffect(targetPermanent: targetPermanent, isInheritedEffect: isInheritedEffect, condition: CanUseCondition, rootCardEffect: rootCardEffect, permanentCondition: permanentCondition, effectName: effectName, effectDiscription: effectDiscription, card);
  24. }
  25. #endregion
  26. #region Trigger effect of [Decoy]
  27. public static ActivateClass DecoyEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition, ICardEffect rootCardEffect, Func<Permanent, bool> permanentCondition, string effectName, string effectDiscription, CardSource card)
  28. {
  29. if (targetPermanent == null) return null;
  30. if (targetPermanent.TopCard == null) return null;
  31. if (card == null) return null;
  32. ActivateClass activateClass = new ActivateClass();
  33. activateClass.SetUpICardEffect(effectName, CanUseCondition, card);
  34. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, effectDiscription);
  35. activateClass.SetHashString($"Decoy_{card.CardID}" + (isInheritedEffect ? "_inherited" : ""));
  36. activateClass.SetIsInheritedEffect(isInheritedEffect);
  37. if (rootCardEffect != null)
  38. {
  39. activateClass.SetIsInheritedEffect(false);
  40. activateClass.SetEffectSourcePermanent(targetPermanent);
  41. activateClass.SetRootCardEffect(rootCardEffect);
  42. }
  43. bool CanSelectPermanentCondition(Permanent permanent) => permanent != targetPermanent && CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) && (permanentCondition == null || permanentCondition(permanent));
  44. bool CanUseCondition(Hashtable hashtable)
  45. {
  46. bool CardEffectCondition(ICardEffect cardEffect) => cardEffect.EffectSourceCard.Owner == card.Owner.Enemy;
  47. if (CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent))
  48. {
  49. if (CardEffectCommons.CanTriggerWhenPermanentRemoveField(hashtable, CanSelectPermanentCondition))
  50. {
  51. if (CardEffectCommons.IsByEffect(hashtable, CardEffectCondition))
  52. {
  53. if (condition == null || condition())
  54. {
  55. return true;
  56. }
  57. }
  58. }
  59. }
  60. return false;
  61. }
  62. bool CanActivateCondition(Hashtable hashtable)
  63. {
  64. if (CardEffectCommons.CanActivateDecoy(targetPermanent, activateClass))
  65. {
  66. if (condition == null || condition())
  67. {
  68. return true;
  69. }
  70. }
  71. return false;
  72. }
  73. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  74. {
  75. return CardEffectCommons.DecoyProcess(activateClass, targetPermanent, CanSelectPermanentCondition);
  76. }
  77. return activateClass;
  78. }
  79. #endregion
  80. }