Collision.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectCommons
  7. {
  8. #region Target 1 Digimon gains [Collision]
  9. public static IEnumerator GainCollision(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass)
  10. {
  11. Debug.Log($"GAIN COLLISION: START");
  12. if (targetPermanent == null) yield break;
  13. Debug.Log($"GAIN COLLISION: PERMANENT");
  14. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  15. Debug.Log($"GAIN COLLISION: BATTLE AREA");
  16. if (activateClass == null) yield break;
  17. Debug.Log($"GAIN COLLISION: ACTIVATE CLASS");
  18. if (activateClass.EffectSourceCard == null) yield break;
  19. Debug.Log($"GAIN COLLISION: PASSED");
  20. CardSource card = activateClass.EffectSourceCard;
  21. bool PermanentCondition(Permanent permanent) => permanent == targetPermanent;
  22. bool CanUseCondition()
  23. {
  24. if (IsPermanentExistsOnBattleArea(targetPermanent))
  25. {
  26. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  27. {
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33. ActivateClass collision = CardEffectFactory.CollisionStaticEffect(permanentCondition: PermanentCondition, isInheritedEffect: false, card: card, condition: CanUseCondition);
  34. AddEffectToPermanent(targetPermanent: targetPermanent, effectDuration: effectDuration, card: card, cardEffect: collision, timing: EffectTiming.OnCounterTiming);
  35. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  36. {
  37. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
  38. }
  39. }
  40. #endregion
  41. #region Can activate [Collision]
  42. public static bool CanActivateCollision(CardSource cardSource)
  43. {
  44. if (IsExistOnBattleArea(cardSource))
  45. {
  46. if (cardSource.Owner.Enemy.GetBattleAreaDigimons().Count >= 1)
  47. {
  48. if (GManager.instance.attackProcess.IsAttacking)
  49. {
  50. return true;
  51. }
  52. }
  53. }
  54. return false;
  55. }
  56. #endregion
  57. #region Effect process of [Collision]
  58. public static IEnumerator CollisionProcess(CardSource cardSource, ICardEffect activateClass, Func<IEnumerator> beforeOnAttackCoroutine = null)
  59. {
  60. List<Permanent> enemyDigimons = cardSource.Owner.Enemy.GetBattleAreaDigimons();
  61. if (CanActivateCollision(cardSource))
  62. {
  63. foreach (Permanent enemyDigimon in enemyDigimons)
  64. {
  65. if (enemyDigimon.TopCard.CanNotBeAffected(activateClass))
  66. continue;
  67. yield return ContinuousController.instance.StartCoroutine(GainBlocker(
  68. targetPermanent: enemyDigimon,
  69. effectDuration: EffectDuration.UntilEndAttack,
  70. activateClass: activateClass));
  71. }
  72. if (HasMatchConditionOpponentsPermanent(cardSource, permanent => permanent.HasBlocker))
  73. GManager.instance.attackProcess.IsBlocking = true;
  74. }
  75. }
  76. #endregion
  77. }