ChangeSAttack.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. {
  42. bool PermanentCondition(Permanent permanent)
  43. {
  44. return permanent == targetPermanent;
  45. }
  46. return ChangeSAttackStaticEffect(
  47. permanentCondition: PermanentCondition,
  48. changeValue: changeValue,
  49. isInheritedEffect: isInheritedEffect,
  50. card: card,
  51. condition: condition
  52. );
  53. }
  54. public static ChangeSAttackClass ChangeSAttackStaticEffect<T>(
  55. Func<Permanent, bool> permanentCondition,
  56. T changeValue,
  57. bool isInheritedEffect,
  58. CardSource card,
  59. Func<bool> condition)
  60. {
  61. bool isInt = typeof(T) == typeof(int);
  62. bool isIntFunc = typeof(T) == typeof(Func<int>);
  63. if (!isInt && !isIntFunc) return null;
  64. if (isInt && (int)(object)changeValue == 0) return null;
  65. if (isIntFunc && changeValue as Func<int> == null) return null;
  66. int _changeValue() => isInt ? (int)(object)changeValue : (changeValue as Func<int>)();
  67. bool isUpValue() => _changeValue() > 0;
  68. string effectName() => isUpValue() ? $"Security Attack +{_changeValue()}" : $"Security Attack {_changeValue()}";
  69. ChangeSAttackClass changeSAttackClass = new ChangeSAttackClass();
  70. changeSAttackClass.SetUpICardEffect("", CanUseCondition, card);
  71. changeSAttackClass.SetUpChangeSAttackClass(changeSAttackFunc: ChangeSAttack, permanentCondition: PermanentCondition, isUpDown: _isUpDown);
  72. if (isInheritedEffect)
  73. {
  74. changeSAttackClass.SetIsInheritedEffect(true);
  75. }
  76. bool CanUseCondition(Hashtable hashtable)
  77. {
  78. if (condition == null || condition())
  79. {
  80. changeSAttackClass.SetEffectName(effectName());
  81. return true;
  82. }
  83. return false;
  84. }
  85. int ChangeSAttack(Permanent permanent, int SAttack)
  86. {
  87. if (PermanentCondition(permanent))
  88. {
  89. SAttack += _changeValue();
  90. }
  91. return SAttack;
  92. }
  93. bool PermanentCondition(Permanent permanent)
  94. {
  95. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  96. {
  97. if (!permanent.TopCard.CanNotBeAffected(changeSAttackClass))
  98. {
  99. if (permanentCondition == null || permanentCondition(permanent))
  100. {
  101. return true;
  102. }
  103. }
  104. }
  105. return false;
  106. }
  107. CalculateOrder _isUpDown()
  108. {
  109. return CalculateOrder.UpDownValue;
  110. }
  111. return changeSAttackClass;
  112. }
  113. #endregion
  114. }