ChangeSAttack.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 Static effect that changes one's own SAttack
  9. public static ChangeSAttackClass ChangeSelfSAttackStaticEffect<T>(
  10. T changeValue,
  11. bool isInheritedEffect,
  12. CardSource card,
  13. Func<bool> condition)
  14. {
  15. bool CanUseCondition()
  16. {
  17. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  18. {
  19. if (condition == null || condition())
  20. {
  21. return true;
  22. }
  23. }
  24. return false;
  25. }
  26. return ChangeTargetSAttackStaticEffect(
  27. targetPermanent: card.PermanentOfThisCard(),
  28. changeValue: changeValue,
  29. isInheritedEffect: isInheritedEffect,
  30. card: card,
  31. condition: CanUseCondition);
  32. }
  33. #endregion
  34. #region Static effect that changes SAttack
  35. public static ChangeSAttackClass ChangeTargetSAttackStaticEffect<T>(
  36. Permanent targetPermanent,
  37. T changeValue,
  38. bool isInheritedEffect,
  39. CardSource card,
  40. Func<bool> condition,
  41. string hashstring = null)
  42. {
  43. bool PermanentCondition(Permanent permanent)
  44. {
  45. return permanent == targetPermanent;
  46. }
  47. return ChangeSAttackStaticEffect(
  48. permanentCondition: PermanentCondition,
  49. changeValue: changeValue,
  50. isInheritedEffect: isInheritedEffect,
  51. card: card,
  52. condition: condition,
  53. hashstring: hashstring
  54. );
  55. }
  56. public static ChangeSAttackClass ChangeSAttackStaticEffect<T>(
  57. Func<Permanent, bool> permanentCondition,
  58. T changeValue,
  59. bool isInheritedEffect,
  60. CardSource card,
  61. Func<bool> condition,
  62. string hashstring = null)
  63. {
  64. bool isInt = typeof(T) == typeof(int);
  65. bool isIntFunc = typeof(T) == typeof(Func<int>);
  66. if (!isInt && !isIntFunc) return null;
  67. if (isInt && (int)(object)changeValue == 0) return null;
  68. if (isIntFunc && changeValue as Func<int> == null) return null;
  69. int _changeValue() => isInt ? (int)(object)changeValue : (changeValue as Func<int>)();
  70. bool isUpValue() => _changeValue() > 0;
  71. string effectName() => isUpValue() ? $"Security Attack +{_changeValue()}" : $"Security Attack {_changeValue()}";
  72. ChangeSAttackClass changeSAttackClass = new ChangeSAttackClass();
  73. changeSAttackClass.SetUpICardEffect("", CanUseCondition, card);
  74. changeSAttackClass.SetUpChangeSAttackClass(changeSAttackFunc: ChangeSAttack, permanentCondition: PermanentCondition, isUpDown: _isUpDown);
  75. if (hashstring != null)
  76. {
  77. changeSAttackClass.SetHashString(hashstring);
  78. }
  79. if (isInheritedEffect)
  80. {
  81. changeSAttackClass.SetIsInheritedEffect(true);
  82. }
  83. bool CanUseCondition(Hashtable hashtable)
  84. {
  85. if (condition == null || condition())
  86. {
  87. changeSAttackClass.SetEffectName(effectName());
  88. return true;
  89. }
  90. return false;
  91. }
  92. int ChangeSAttack(Permanent permanent, int SAttack)
  93. {
  94. if (PermanentCondition(permanent))
  95. {
  96. SAttack += _changeValue();
  97. }
  98. return SAttack;
  99. }
  100. bool PermanentCondition(Permanent permanent)
  101. {
  102. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  103. {
  104. if (!permanent.TopCard.CanNotBeAffected(changeSAttackClass))
  105. {
  106. if (permanentCondition == null || permanentCondition(permanent))
  107. {
  108. return true;
  109. }
  110. }
  111. }
  112. return false;
  113. }
  114. CalculateOrder _isUpDown()
  115. {
  116. return CalculateOrder.UpDownValue;
  117. }
  118. return changeSAttackClass;
  119. }
  120. #endregion
  121. #region Static effect that inverts one's own SAttack
  122. public static InvertSAttackClass InvertSelfSAttackStaticEffect<T>(
  123. T changeValue,
  124. bool isInheritedEffect,
  125. CardSource card,
  126. Func<bool> condition)
  127. {
  128. bool CanUseCondition()
  129. {
  130. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  131. {
  132. if (condition == null || condition())
  133. {
  134. return true;
  135. }
  136. }
  137. return false;
  138. }
  139. return InvertTargetSAttackStaticEffect(
  140. targetPermanent: card.PermanentOfThisCard(),
  141. changeValue: changeValue,
  142. isInheritedEffect: isInheritedEffect,
  143. card: card,
  144. condition: CanUseCondition);
  145. }
  146. #endregion
  147. #region Static effect that inverts SAttack
  148. public static InvertSAttackClass InvertTargetSAttackStaticEffect<T>(
  149. Permanent targetPermanent,
  150. T changeValue,
  151. bool isInheritedEffect,
  152. CardSource card,
  153. Func<bool> condition)
  154. {
  155. bool PermanentCondition(Permanent permanent)
  156. {
  157. return permanent == targetPermanent;
  158. }
  159. return InvertSAttackStaticEffect(
  160. permanentCondition: PermanentCondition,
  161. changeValue: changeValue,
  162. isInheritedEffect: isInheritedEffect,
  163. card: card,
  164. condition: condition
  165. );
  166. }
  167. public static InvertSAttackClass InvertSAttackStaticEffect<T>(
  168. Func<Permanent, bool> permanentCondition,
  169. T changeValue,
  170. bool isInheritedEffect,
  171. CardSource card,
  172. Func<bool> condition)
  173. {
  174. bool isInt = typeof(T) == typeof(int);
  175. bool isIntFunc = typeof(T) == typeof(Func<int>);
  176. if (!isInt && !isIntFunc) return null;
  177. if (isInt && (int)(object)changeValue == 0) return null;
  178. if (isIntFunc && changeValue as Func<int> == null) return null;
  179. int _changeValue() => isInt ? (int)(object)changeValue : (changeValue as Func<int>)();
  180. bool isUpValue() => _changeValue() > 0;
  181. string effectName() => isUpValue() ? $"<Security A. +> are turned into <Security A. ->" : $"<Security A. -> are turned into <Security A. +>";
  182. InvertSAttackClass invertSAttackClass = new InvertSAttackClass();
  183. invertSAttackClass.SetUpICardEffect("", CanUseCondition, card);
  184. invertSAttackClass.SetUpChangeSAttackClass(changeInvertFunc: InvertValue, permanentCondition: PermanentCondition);
  185. invertSAttackClass.SetIsInheritedEffect(isInheritedEffect);
  186. invertSAttackClass.SetHashString($"InvertSecA_{card.CardID}");
  187. invertSAttackClass.SetIsBackgroundProcess(true);
  188. bool CanUseCondition(Hashtable hashtable)
  189. {
  190. if (condition == null || condition())
  191. {
  192. invertSAttackClass.SetEffectName(effectName());
  193. return true;
  194. }
  195. return false;
  196. }
  197. int InvertValue(Permanent permanent, int invertValue)
  198. {
  199. if (PermanentCondition(permanent))
  200. {
  201. invertValue += _changeValue();
  202. }
  203. return invertValue;
  204. }
  205. bool PermanentCondition(Permanent permanent)
  206. {
  207. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  208. {
  209. if (!permanent.TopCard.CanNotBeAffected(invertSAttackClass))
  210. {
  211. if (permanentCondition == null || permanentCondition(permanent))
  212. {
  213. return true;
  214. }
  215. }
  216. }
  217. return false;
  218. }
  219. return invertSAttackClass;
  220. }
  221. #endregion
  222. }