ChangeSAttack.cs 8.1 KB

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