Fragment.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections;
  3. public partial class CardEffectFactory
  4. {
  5. #region Trigger effect of [Fragment] on oneself
  6. public static ActivateClass FragmentSelfEffect(bool isInheritedEffect, CardSource card, Func<bool> condition, int trashValue, string effectName, string effectDiscription, ICardEffect rootCardEffect = null)
  7. {
  8. Permanent targetPermanent = card.PermanentOfThisCard();
  9. bool CanUseCondition()
  10. {
  11. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  12. {
  13. if (condition == null || condition())
  14. {
  15. return true;
  16. }
  17. }
  18. return false;
  19. }
  20. return FragmentEffect(targetPermanent: targetPermanent, isInheritedEffect: isInheritedEffect, condition: CanUseCondition, rootCardEffect: rootCardEffect, trashValue: trashValue, effectName: effectName, effectDiscription: effectDiscription, card);
  21. }
  22. #endregion
  23. #region Trigger effect of [Fragment]
  24. public static ActivateClass FragmentEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition, ICardEffect rootCardEffect, int trashValue, string effectName, string effectDiscription, CardSource card)
  25. {
  26. if (targetPermanent == null) return null;
  27. if (targetPermanent.TopCard == null) return null;
  28. if (card == null) return null;
  29. ActivateClass activateClass = new ActivateClass();
  30. activateClass.SetUpICardEffect(effectName, CanUseCondition, card);
  31. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, effectDiscription);
  32. activateClass.SetHashString($"Fragment_{card.CardID}" + (isInheritedEffect ? "_inherited" : ""));
  33. activateClass.SetIsInheritedEffect(isInheritedEffect);
  34. if (rootCardEffect != null)
  35. {
  36. activateClass.SetIsInheritedEffect(false);
  37. activateClass.SetEffectSourcePermanent(targetPermanent);
  38. activateClass.SetRootCardEffect(rootCardEffect);
  39. }
  40. bool CanUseCondition(Hashtable hashtable)
  41. {
  42. if (CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent))
  43. {
  44. if (CardEffectCommons.CanTriggerWhenRemoveField(hashtable, targetPermanent.TopCard))
  45. {
  46. if (condition == null || condition())
  47. {
  48. return true;
  49. }
  50. }
  51. }
  52. return false;
  53. }
  54. bool CanActivateCondition(Hashtable hashtable)
  55. {
  56. if (CardEffectCommons.CanActivateFragment(targetPermanent, trashValue, activateClass))
  57. {
  58. if (condition == null || condition())
  59. {
  60. return true;
  61. }
  62. }
  63. return false;
  64. }
  65. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  66. {
  67. return CardEffectCommons.FragmentProcess(activateClass, targetPermanent, trashValue);
  68. }
  69. return activateClass;
  70. }
  71. #endregion
  72. }