Execute.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections;
  2. using System;
  3. public partial class CardEffectFactory
  4. {
  5. #region Trigger effect of [Execute] on oneself
  6. public static ActivateClass ExecuteSelfEffect(bool isInheritedEffect, CardSource card, Func<bool> condition,
  7. ICardEffect rootCardEffect = null)
  8. {
  9. Permanent targetPermanent = card.PermanentOfThisCard();
  10. bool CanUseCondition()
  11. {
  12. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) &&
  13. (condition == null || condition());
  14. }
  15. return ExecuteEffect(targetPermanent: targetPermanent, isInheritedEffect: isInheritedEffect, condition: CanUseCondition,
  16. rootCardEffect: rootCardEffect, card);
  17. }
  18. #endregion
  19. #region Trigger effect of [Execute]
  20. public static ActivateClass ExecuteEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition,
  21. ICardEffect rootCardEffect, CardSource card)
  22. {
  23. if (targetPermanent == null) return null;
  24. if (targetPermanent.TopCard == null) return null;
  25. if (card == null) return null;
  26. ActivateClass activateClass = new ActivateClass();
  27. activateClass.SetUpICardEffect("Execute", CanUseCondition, card);
  28. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, DataBase.ExecuteEffectDiscription());
  29. activateClass.SetIsInheritedEffect(isInheritedEffect);
  30. if (rootCardEffect != null)
  31. {
  32. activateClass.SetIsInheritedEffect(false);
  33. activateClass.SetEffectSourcePermanent(targetPermanent);
  34. activateClass.SetRootCardEffect(rootCardEffect);
  35. }
  36. bool CanUseCondition(Hashtable hashtable)
  37. {
  38. return CardEffectCommons.IsExistOnBattleArea(card) &&
  39. CardEffectCommons.IsOwnerTurn(card) &&
  40. (condition == null || condition());
  41. }
  42. bool CanActivateCondition(Hashtable hashtable)
  43. {
  44. return CardEffectCommons.CanActivateExecute(targetPermanent.TopCard, activateClass) &&
  45. (condition == null || condition());
  46. }
  47. IEnumerator ActivateCoroutine(Hashtable hashtable)
  48. {
  49. return CardEffectCommons.ExecuteProcess(targetPermanent.TopCard, activateClass);
  50. }
  51. return activateClass;
  52. }
  53. #endregion
  54. }