CEntity_EffectController.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. public class CEntity_EffectController : MonoBehaviour
  6. {
  7. //Number of skills used this turn (referenced by use limit)
  8. List<ICardEffect> UseEffectsThisTurn = new List<ICardEffect>();
  9. #region CEntity_Effect
  10. public CEntity_Effect cEntity_Effect { get; set; }
  11. #endregion
  12. #region 効果リストを取得
  13. public List<ICardEffect> GetCardEffects_ExceptAddedEffects(EffectTiming timing, CardSource card)
  14. {
  15. List<ICardEffect> GetCardEffects = new List<ICardEffect>();
  16. if (cEntity_Effect != null)
  17. {
  18. foreach (ICardEffect cardEffect in cEntity_Effect.GetCardEffects(timing, card))
  19. {
  20. GetCardEffects.Add(cardEffect);
  21. }
  22. }
  23. return GetCardEffects;
  24. }
  25. public List<ICardEffect> GetCardEffects(EffectTiming timing, CardSource card)
  26. {
  27. List<ICardEffect> GetCardEffects = new List<ICardEffect>();
  28. foreach (ICardEffect cardEffect in GetCardEffects_ExceptAddedEffects(timing, card))
  29. {
  30. GetCardEffects.Add(cardEffect);
  31. }
  32. Permanent thisPermanent = card.PermanentOfThisCard();
  33. bool isDigivolutionCard = thisPermanent != null && thisPermanent.DigivolutionCards.Contains(card);
  34. if (!isDigivolutionCard)
  35. {
  36. // 他のカードの効果によって追加された効果
  37. if (timing != EffectTiming.None)
  38. {
  39. #region 他のカードの効果によって追加された効果
  40. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  41. {
  42. if (player != null)
  43. {
  44. #region 場のパーマネントの効果
  45. foreach (Permanent permanent in player.GetFieldPermanents())
  46. {
  47. if (permanent.TopCard.cEntity_EffectController.cEntity_Effect != null)
  48. {
  49. foreach (CardSource cardSource in permanent.cardSources)
  50. {
  51. if (cardSource != permanent.TopCard)
  52. {
  53. if (!permanent.IsDigimon)
  54. {
  55. continue;
  56. }
  57. }
  58. foreach (ICardEffect cardEffect in cardSource.cEntity_EffectController.cEntity_Effect.GetCardEffects(EffectTiming.None, permanent.TopCard))
  59. {
  60. if (cardEffect is IAddSkillEffect)
  61. {
  62. if (cardEffect.IsInheritedEffect == (cardSource == permanent.TopCard))
  63. {
  64. continue;
  65. }
  66. if (cardEffect.CanUse(null))
  67. {
  68. GetCardEffects = ((IAddSkillEffect)cardEffect).GetCardEffect(card, GetCardEffects, timing);
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. #endregion
  76. #region プレイヤーによって追加された効果
  77. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  78. {
  79. if (cardEffect is IAddSkillEffect)
  80. {
  81. if (cardEffect.CanUse(null))
  82. {
  83. GetCardEffects = ((IAddSkillEffect)cardEffect).GetCardEffect(card, GetCardEffects, timing);
  84. }
  85. }
  86. }
  87. #endregion
  88. }
  89. }
  90. #endregion
  91. }
  92. // 自分によって追加される場合のみEffectTiming.Noneについて探索
  93. else
  94. {
  95. if (thisPermanent != null)
  96. {
  97. if (thisPermanent.TopCard.cEntity_EffectController.cEntity_Effect != null)
  98. {
  99. foreach (CardSource cardSource in thisPermanent.cardSources)
  100. {
  101. /*
  102. if (cardSource != thisPermanent.TopCard)
  103. {
  104. if (!thisPermanent.IsDigimon)
  105. {
  106. continue;
  107. }
  108. }
  109. */
  110. foreach (ICardEffect cardEffect in cardSource.cEntity_EffectController.cEntity_Effect.GetCardEffects(EffectTiming.None, thisPermanent.TopCard))
  111. {
  112. if (cardEffect is IAddSkillEffect)
  113. {
  114. if (cardEffect.IsInheritedEffect == (cardSource == thisPermanent.TopCard))
  115. {
  116. continue;
  117. }
  118. if (cardEffect.CanUse(null))
  119. {
  120. GetCardEffects = ((IAddSkillEffect)cardEffect).GetCardEffect(card, GetCardEffects, timing);
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }
  129. return GetCardEffects.Filter(cardEfect => cardEfect != null);
  130. }
  131. #endregion
  132. #region そのターン中の使用回数をリセット
  133. public void InitUseCountThisTurn()
  134. {
  135. UseEffectsThisTurn = new List<ICardEffect>();
  136. }
  137. #endregion
  138. #region カード効果をセット
  139. public void AddCardEffect(string ClassName)
  140. {
  141. #region カード効果クラスのインスタンスを生成してセット
  142. bool CanAttachEffectComponent()
  143. {
  144. if (string.IsNullOrEmpty(ClassName)) return false;
  145. if (Type.GetType(ClassName) == null) return false;
  146. return true;
  147. }
  148. CEntity_Effect cEntity_Effect = null;
  149. if (CanAttachEffectComponent())
  150. {
  151. Type t = Type.GetType(ClassName);
  152. Component component = this.gameObject.AddComponent(t);
  153. if (component is CEntity_Effect)
  154. {
  155. cEntity_Effect = (CEntity_Effect)(component);
  156. }
  157. else
  158. {
  159. Debug.Log($"{ClassName} has error");
  160. }
  161. }
  162. else
  163. {
  164. cEntity_Effect = this.gameObject.AddComponent<EmptyEffectClass>();
  165. }
  166. this.cEntity_Effect = cEntity_Effect;
  167. #endregion
  168. }
  169. #endregion
  170. #region その効果をこのターンに使用した回数を取得
  171. public int GetUseCountThisTurn(ICardEffect cardEffect)
  172. {
  173. int useCount = 0;
  174. foreach (ICardEffect cardEffect1 in UseEffectsThisTurn)
  175. {
  176. if (cardEffect.IsSameEffect(cardEffect1))
  177. {
  178. useCount++;
  179. }
  180. }
  181. return useCount;
  182. }
  183. #endregion
  184. #region その効果がこのターン中の使用上限回数に達しているかどうか
  185. public bool isOverMaxCountPerTurn(ICardEffect cardEffect, int MaxCountPerTurn)
  186. {
  187. return GetUseCountThisTurn(cardEffect) >= MaxCountPerTurn;
  188. }
  189. #endregion
  190. #region このターンに使った効果に登録
  191. public void RegisterUseEfffectThisTurn(ICardEffect cardEffect)
  192. {
  193. UseEffectsThisTurn.Add(cardEffect);
  194. }
  195. #endregion
  196. }
  197. public class EmptyEffectClass : CEntity_Effect
  198. {
  199. }