Fragment.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 [Fragment] on oneself
  9. public static ActivateClass FragmentSelfEffect(bool isInheritedEffect, CardSource card, Func<bool> condition, int trashValue, 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 FragmentEffect(targetPermanent: targetPermanent, isInheritedEffect: isInheritedEffect, condition: CanUseCondition, rootCardEffect: rootCardEffect, trashValue: trashValue, effectName: effectName, effectDiscription: effectDiscription, card);
  24. }
  25. #endregion
  26. #region Trigger effect of [Fragment]
  27. public static ActivateClass FragmentEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition, ICardEffect rootCardEffect, int trashValue, 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($"Fragment_{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 CanUseCondition(Hashtable hashtable)
  44. {
  45. Debug.Log($"FRAGMENT CAN USE: {CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)}");
  46. if (CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent))
  47. {
  48. Debug.Log($"FRAGMENT CAN USE: {CardEffectCommons.CanTriggerWhenRemoveField(hashtable, targetPermanent.TopCard)}");
  49. if (CardEffectCommons.CanTriggerWhenRemoveField(hashtable, targetPermanent.TopCard))
  50. {
  51. if (condition == null || condition())
  52. {
  53. Debug.Log($"FRAGMENT CAN USE: TRUE");
  54. return true;
  55. }
  56. }
  57. }
  58. return false;
  59. }
  60. bool CanActivateCondition(Hashtable hashtable)
  61. {
  62. if (CardEffectCommons.CanActivateFragment(targetPermanent, trashValue, activateClass))
  63. {
  64. if (condition == null || condition())
  65. {
  66. return true;
  67. }
  68. }
  69. return false;
  70. }
  71. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  72. {
  73. return CardEffectCommons.FragmentProcess(activateClass, targetPermanent, trashValue);
  74. }
  75. return activateClass;
  76. }
  77. #endregion
  78. }