using System.Collections; using System.Collections.Generic; using System; public partial class CardEffectFactory { #region [Guard] self effect public static ActivateClass GuardSelfEffect(bool isInheritedEffect, CardSource card, Func condition, bool isLinkedEffect = false) { return GuardEffect( targetPermanent: card.PermanentOfThisCard(), isInheritedEffect, condition, rootCardEffect: null, card, isLinkedEffect); } #endregion #region [Guard] Effect public static ActivateClass GuardEffect(Permanent targetPermanent, bool isInheritedEffect, Func condition, ICardEffect rootCardEffect, CardSource card, bool isLinkedEffect = false) { if (targetPermanent == null) return null; if (targetPermanent.TopCard == null) return null; if (card == null) return null; ActivateClass activateClass = new ActivateClass(); activateClass.SetUpICardEffect("Guard", CanUseCondition, card); activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, DataBase.GuardEffectDescription()); activateClass.SetIsInheritedEffect(isInheritedEffect); activateClass.SetIsLinkedEffect(isLinkedEffect); activateClass.SetIsSkippable(true); if (rootCardEffect != null) { activateClass.SetIsInheritedEffect(false); activateClass.SetEffectSourcePermanent(targetPermanent); activateClass.SetRootCardEffect(rootCardEffect); } bool CanUseCondition(Hashtable hashtable) { return CardEffectCommons.IsPermanentExistsOnBattleAreaDigimon(targetPermanent) && !targetPermanent.TopCard.CanNotBeAffected(activateClass) && CardEffectCommons.CanTriggerWhenPermanentRemoveField(hashtable, PermanentCondition) && CardEffectCommons.IsByEffect(hashtable, effect => CardEffectCommons.IsOpponentEffect(effect, card)); } bool PermanentCondition(Permanent permanent) => permanent != targetPermanent && CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card); bool CanActivateCondition(Hashtable hashtable) { return CanActivateGuard(targetPermanent, activateClass); } IEnumerator ActivateCoroutine(Hashtable hashtable) { yield return ContinuousController.instance.StartCoroutine(GuardProcess(hashtable, activateClass, targetPermanent)); } return activateClass; } #endregion #region Can activate [Guard] public static bool CanActivateGuard(Permanent permanent, ICardEffect activateClass) { return CardEffectCommons.IsPermanentExistsOnBattleArea(permanent) && permanent.CanBeDestroyedBySkill(activateClass); } #endregion #region Effect process of [Guard] public static IEnumerator GuardProcess(Hashtable hashtable, ICardEffect activateClass, Permanent guardPermanent) { if (guardPermanent == null) yield break; if (guardPermanent.TopCard == null) yield break; CardSource topCard = guardPermanent.TopCard; bool PermanentCondition(Permanent otherPermanent) { return otherPermanent != guardPermanent && CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(otherPermanent, topCard); } Player owner = topCard.Owner; string selectPlayerMessage = "Will you delete this digimon to prevent the removal?"; string notSelectPlayerMessage = "The opponent is choosing if they will use Guard."; List> command_SelectCommands = new List>() { new SelectionElement(message: $"Yes", value: true, spriteIndex: 0), new SelectionElement(message: $"No", value: false, spriteIndex: 1), }; GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: command_SelectCommands, selectPlayer: owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage); yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect()); if (GManager.instance.userSelectionManager.SelectedBoolValue) { yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DeletePeremanentAndProcessAccordingToResult(targetPermanents: new List() { guardPermanent }, activateClass: activateClass, successProcess: permanents => SuccessProcess(), failureProcess: null)); IEnumerator SuccessProcess() { List removedPermanents = CardEffectCommons.GetPermanentsFromHashtable(hashtable).Filter(PermanentCondition); foreach (Permanent removed in removedPermanents) { removed.willBeRemoveField = false; removed.HideDeleteEffect(); removed.HideHandBounceEffect(); removed.HideDeckBounceEffect(); removed.HideWillRemoveFieldEffect(); } yield return null; } } } #endregion #region Target 1 Digimon gains [Guard] public static IEnumerator GainGuard(Permanent targetPermanent, EffectDuration effectDuration, ICardEffect activateClass) { if (targetPermanent == null) yield break; if (!CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent)) yield break; if (activateClass == null) yield break; if (activateClass.EffectSourceCard == null) yield break; CardSource card = activateClass.EffectSourceCard; bool CanUseCondition() { return CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent) && !targetPermanent.TopCard.CanNotBeAffected(activateClass); } ActivateClass guard = CardEffectFactory.GuardEffect( targetPermanent: targetPermanent, isInheritedEffect: false, condition: CanUseCondition, rootCardEffect: activateClass, card: targetPermanent.TopCard); CardEffectCommons.AddEffectToPermanent( targetPermanent: targetPermanent, effectDuration: effectDuration, card: card, cardEffect: guard, timing: EffectTiming.WhenRemoveField); if (!targetPermanent.TopCard.CanNotBeAffected(activateClass)) { yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent().CreateBuffEffect(targetPermanent)); } } #endregion }