ChangeLinkMax.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 Link Max
  9. public static ChangeLinkMaxClass ChangeSelfLinkMaxStaticEffect<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 ChangeTargetLinkMaxStaticEffect(
  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 LinkMax
  35. public static ChangeLinkMaxClass ChangeTargetLinkMaxStaticEffect<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 ChangeLinkMaxStaticEffect(
  48. permanentCondition: PermanentCondition,
  49. changeValue: changeValue,
  50. isInheritedEffect: isInheritedEffect,
  51. card: card,
  52. condition: condition,
  53. hashstring: hashstring
  54. );
  55. }
  56. public static ChangeLinkMaxClass ChangeLinkMaxStaticEffect<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() ? $"Link Max +{_changeValue()}" : $"Link Max {_changeValue()}";
  72. ChangeLinkMaxClass changeLinkMaxClass = new ChangeLinkMaxClass();
  73. changeLinkMaxClass.SetUpICardEffect("", CanUseCondition, card);
  74. changeLinkMaxClass.SetUpChangeLinkMaxClass(changeLinkMaxFunc: ChangeLinkMax, permanentCondition: PermanentCondition, isUpDown: _isUpDown);
  75. if (hashstring != null)
  76. {
  77. changeLinkMaxClass.SetHashString(hashstring);
  78. }
  79. if (isInheritedEffect)
  80. {
  81. changeLinkMaxClass.SetIsInheritedEffect(true);
  82. }
  83. bool CanUseCondition(Hashtable hashtable)
  84. {
  85. if (condition == null || condition())
  86. {
  87. changeLinkMaxClass.SetEffectName(effectName());
  88. return true;
  89. }
  90. return false;
  91. }
  92. int ChangeLinkMax(Permanent permanent, int linkMax)
  93. {
  94. if (PermanentCondition(permanent))
  95. {
  96. linkMax += _changeValue();
  97. }
  98. return linkMax;
  99. }
  100. bool PermanentCondition(Permanent permanent)
  101. {
  102. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  103. {
  104. if (!permanent.TopCard.CanNotBeAffected(changeLinkMaxClass))
  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 changeLinkMaxClass;
  119. }
  120. #endregion
  121. }