Scapegoat.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. using System.Runtime.InteropServices.WindowsRuntime;
  7. public partial class CardEffectFactory
  8. {
  9. #region Trigger effect of [Scapegoat] on oneself
  10. public static ActivateClass ScapegoatSelfEffect(bool isInheritedEffect, CardSource card, Func<bool> condition, string effectName, string effectDiscription, ICardEffect rootCardEffect = null, bool isLinkedEffect = false)
  11. {
  12. Permanent targetPermanent = card.PermanentOfThisCard();
  13. bool CanUseCondition()
  14. {
  15. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  16. {
  17. if (condition == null || condition())
  18. {
  19. return true;
  20. }
  21. }
  22. return false;
  23. }
  24. return ScapegoatEffect(targetPermanent: targetPermanent, isInheritedEffect: isInheritedEffect, condition: CanUseCondition, rootCardEffect: rootCardEffect, effectName: effectName, effectDiscription: effectDiscription, card, isLinkedEffect: isLinkedEffect);
  25. }
  26. #endregion
  27. #region Trigger effect of [Scapegoat]
  28. public static ActivateClass ScapegoatEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition, ICardEffect rootCardEffect, string effectName, string effectDiscription, CardSource card, bool isLinkedEffect = false)
  29. {
  30. if (targetPermanent == null) return null;
  31. if (targetPermanent.TopCard == null) return null;
  32. if (card == null) return null;
  33. ActivateClass activateClass = new ActivateClass();
  34. activateClass.SetUpICardEffect(effectName, CanUseCondition, card);
  35. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, effectDiscription);
  36. activateClass.SetHashString($"Scapegoat_{card.CardID}" + (isInheritedEffect ? "_inherited" : ""));
  37. activateClass.SetIsInheritedEffect(isInheritedEffect);
  38. activateClass.SetIsLinkedEffect(isLinkedEffect);
  39. if (rootCardEffect != null)
  40. {
  41. activateClass.SetIsInheritedEffect(false);
  42. activateClass.SetEffectSourcePermanent(targetPermanent);
  43. activateClass.SetRootCardEffect(rootCardEffect);
  44. }
  45. bool CanSelectPermanentCondition(Permanent permanent) => CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) && permanent != card.PermanentOfThisCard();
  46. bool PermanentCondition(Permanent permanent)
  47. {
  48. if(permanent == targetPermanent)
  49. {
  50. return true;
  51. }
  52. return false;
  53. }
  54. bool CanUseCondition(Hashtable hashtable)
  55. {
  56. bool CardEffectCondition(ICardEffect cardEffect) => CardEffectCommons.IsOwnerEffect(cardEffect,card);
  57. if (CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent))
  58. {
  59. if (CardEffectCommons.CanTriggerWhenPermanentRemoveField(hashtable, PermanentCondition))
  60. {
  61. if (CardEffectCommons.IsByEffect(hashtable, CardEffectCondition))
  62. return false;
  63. if (condition == null || condition())
  64. {
  65. return true;
  66. }
  67. }
  68. }
  69. return false;
  70. }
  71. bool CanActivateCondition(Hashtable hashtable)
  72. {
  73. if (CardEffectCommons.CanActivateScapegoat(targetPermanent, CanSelectPermanentCondition))
  74. {
  75. if (condition == null || condition())
  76. {
  77. return true;
  78. }
  79. }
  80. return false;
  81. }
  82. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  83. {
  84. return CardEffectCommons.ScapegoatProcess(activateClass, targetPermanent, CanSelectPermanentCondition);
  85. }
  86. return activateClass;
  87. }
  88. #endregion
  89. #region Static effect of [Scapegoat]
  90. public static ScapegoatClass ScapegoatStaticEffect(Func<Permanent, bool> permanentCondition, bool isInheritedEffect, CardSource card, Func<bool> condition)
  91. {
  92. string effectName = "Scapegoat";
  93. ScapegoatClass scapegoateClass = new ScapegoatClass();
  94. scapegoateClass.SetUpICardEffect(effectName, CanUseCondition, card);
  95. scapegoateClass.SetUpScapegoatClass(PermanentCondition: PermanentCondition);
  96. if (isInheritedEffect)
  97. {
  98. scapegoateClass.SetIsInheritedEffect(true);
  99. }
  100. bool CanUseCondition(Hashtable hashtable)
  101. {
  102. return condition == null || condition();
  103. }
  104. bool PermanentCondition(Permanent permanent)
  105. {
  106. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  107. {
  108. if (permanentCondition == null || permanentCondition(permanent))
  109. {
  110. return true;
  111. }
  112. }
  113. return false;
  114. }
  115. return scapegoateClass;
  116. }
  117. #endregion
  118. }