CEntity_EffectController.cs 8.5 KB

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