Collision.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. if (targetPermanent == null) yield break;
  12. if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
  13. if (activateClass == null) yield break;
  14. if (activateClass.EffectSourceCard == null) yield break;
  15. CardSource card = targetPermanent.TopCard;
  16. bool PermanentCondition(Permanent permanent) => permanent == targetPermanent;
  17. bool CanUseCondition()
  18. {
  19. if (IsPermanentExistsOnBattleArea(targetPermanent))
  20. {
  21. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  22. {
  23. return true;
  24. }
  25. }
  26. return false;
  27. }
  28. ActivateClass collision = CardEffectFactory.CollisionStaticEffect(permanentCondition: PermanentCondition, isInheritedEffect: false, card: card, condition: CanUseCondition);
  29. AddEffectToPermanent(targetPermanent: targetPermanent, effectDuration: effectDuration, card: card, cardEffect: collision, timing: EffectTiming.OnCounterTiming);
  30. if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
  31. {
  32. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
  33. }
  34. }
  35. #endregion
  36. #region Can activate [Collision]
  37. public static bool CanActivateCollision(CardSource cardSource)
  38. {
  39. if (IsExistOnBattleArea(cardSource))
  40. {
  41. if (cardSource.Owner.Enemy.GetBattleAreaDigimons().Count >= 1)
  42. {
  43. if (GManager.instance.attackProcess.IsAttacking)
  44. {
  45. return true;
  46. }
  47. }
  48. }
  49. return false;
  50. }
  51. #endregion
  52. #region Effect process of [Collision]
  53. public static IEnumerator CollisionProcess(CardSource cardSource, ICardEffect activateClass, Func<IEnumerator> beforeOnAttackCoroutine = null)
  54. {
  55. List<Permanent> enemyDigimons = cardSource.Owner.Enemy.GetBattleAreaDigimons();
  56. if (CanActivateCollision(cardSource))
  57. {
  58. foreach (Permanent enemyDigimon in enemyDigimons)
  59. {
  60. if (enemyDigimon.TopCard.CanNotBeAffected(activateClass))
  61. continue;
  62. yield return ContinuousController.instance.StartCoroutine(GainBlocker(
  63. targetPermanent: enemyDigimon,
  64. effectDuration: EffectDuration.UntilEndAttack,
  65. activateClass: activateClass));
  66. }
  67. if (HasMatchConditionOpponentsPermanent(cardSource, permanent => permanent.HasBlocker))
  68. GManager.instance.attackProcess.IsBlocking = true;
  69. }
  70. }
  71. #endregion
  72. }