Scapegoat.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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)
  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);
  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)
  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. if (rootCardEffect != null)
  39. {
  40. activateClass.SetIsInheritedEffect(false);
  41. activateClass.SetEffectSourcePermanent(targetPermanent);
  42. activateClass.SetRootCardEffect(rootCardEffect);
  43. }
  44. bool CanSelectPermanentCondition(Permanent permanent) => CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) && permanent != card.PermanentOfThisCard();
  45. bool PermanentCondition(Permanent permanent)
  46. {
  47. if(permanent == targetPermanent)
  48. {
  49. return true;
  50. }
  51. return false;
  52. }
  53. bool CanUseCondition(Hashtable hashtable)
  54. {
  55. bool CardEffectCondition(ICardEffect cardEffect) => cardEffect.EffectSourceCard.Owner == card.Owner.Enemy;
  56. if (CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent))
  57. {
  58. if (CardEffectCommons.CanTriggerWhenPermanentRemoveField(hashtable, PermanentCondition))
  59. {
  60. if (CardEffectCommons.IsByEffect(hashtable, CardEffectCondition) || CardEffectCommons.IsByBattle(hashtable))
  61. {
  62. if (condition == null || condition())
  63. {
  64. return true;
  65. }
  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. }