| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using System.Linq;
- using UnityEngine;
- using UnityEditor.Rendering;
- public partial class CardEffectCommons
- {
- #region Can trigger
- #region Can trigger [On Deletion] effect
- public static bool CanTriggerOnDeletion(Hashtable hashtable, CardSource card, ICardEffect cardEffect)
- {
- return CanTriggerOnPermanentDeleted(hashtable, (permanent) => permanent.cardSources.Contains(card), cardEffect);
- }
- #endregion
- #region Can trigger "when permanent is deleted" effect
- public static bool CanTriggerOnPermanentDeleted(Hashtable hashtable, Func<Permanent, bool> permanentCondition, ICardEffect cardEffect)
- {
- List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
- if (hashtables != null)
- {
- foreach (Hashtable hashtable1 in hashtables)
- {
- Permanent permanent = GetPermanentFromHashtable(hashtable1);
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (permanentCondition != null)
- {
- if (permanentCondition(permanent))
- {
- RegisterOnDeletion(permanent, cardEffect);//Not always used when called directly, but there are some On deletions granted to permanents that need to use this method instead of CanTriggerOnDeletion
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region Can trigger "when permanent leaves the battle area" effect
- public static bool CanTriggerOnPermanentLeave(Hashtable hashtable, Func<Permanent, bool> permanentCondition)
- {
- List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
- if (hashtables != null)
- {
- foreach (Hashtable hashtable1 in hashtables)
- {
- Permanent permanent = GetPermanentFromHashtable(hashtable1);
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (permanentCondition != null)
- {
- if (permanentCondition(permanent))
- {
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region Can trigger "when permanent is deleted by battle" effects
- public static bool IsByBattle(Hashtable hashtable)
- {
- return GetBattleFromHashtable(hashtable) != null;
- }
- #endregion
- #region Can trigger "when permanent is deleted or played by effect that satisfies the condition" effects
- public static bool IsByEffect(Hashtable hashtable, Func<ICardEffect, bool> cardEffectCondition)
- {
- ICardEffect CardEffect = GetCardEffectFromHashtable(hashtable);
- if (CardEffect != null)
- {
- if (CardEffect.EffectSourceCard != null)
- {
- if (cardEffectCondition == null || cardEffectCondition(CardEffect))
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #endregion
- #region Can activate
- #region Can activate [On Deletion] effect
- public static bool CanActivateOnDeletion(CardSource card, ICardEffect cardEffect)
- {
- return card.IsToken || IsTopCardStillInTrash(cardEffect);
- }
- #endregion
- #region Whether any TopCard is in trash when check [On Deletion] effect
- public static bool IsTopCardInTrashOnDeletion(Hashtable hashtable)
- {
- List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
- if (hashtables != null)
- {
- foreach (Hashtable hashtable1 in hashtables)
- {
- CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
- if (TopCard != null)
- {
- if (IsExistOnTrash(TopCard) || TopCard.IsToken)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region Whether the card that uses the effect and the top card belonged to the same permanent
- public static bool IsTopCardSamePermanent(Hashtable hashtable, CardSource card)
- {
- if (card == null) return false;
- if (card.PermanentJustBeforeRemoveField == null) return false;
- List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
- if (hashtables != null)
- {
- foreach (Hashtable hashtable1 in hashtables)
- {
- CardSource TopCard = GetTopCardFromOneHashtable(hashtable1);
- if (TopCard != null)
- {
- if (TopCard.PermanentJustBeforeRemoveField != null)
- {
- if (card.PermanentJustBeforeRemoveField == TopCard.PermanentJustBeforeRemoveField)
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region Can activate [On Deletion] effect that can activate if the permanent conains specific name
- public static bool CanActivateSelfOnDeletionWithContainingCardName(Hashtable hashtable, string name, CardSource card)
- {
- return CanActivateOnDeletionWithContainingCardName(
- hashtable: hashtable,
- name: name,
- cardCondition: cardSource => cardSource == card
- );
- }
- public static bool CanActivateOnDeletionWithContainingCardName(
- Hashtable hashtable,
- string name,
- Func<CardSource, bool> cardCondition)
- {
- List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
- if (hashtables != null)
- {
- foreach (Hashtable hashtable1 in hashtables)
- {
- if (hashtable1 != null)
- {
- List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
- if (CardSources != null)
- {
- if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
- {
- if (hashtable1.ContainsKey("CardNames"))
- {
- if (hashtable1["CardNames"] is List<string>)
- {
- List<string> CardNames = (List<string>)hashtable1["CardNames"];
- if (CardNames != null)
- {
- if (CardNames.Count((cardName) => cardName.Contains(name)) >= 1)
- {
- return true;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region Can activate [On Deletion] effect that can activate if the permanent conains specific trait
- public static bool CanActivateSelfOnDeletionWithContainingTrait(Hashtable hashtable, string name, CardSource card)
- {
- return CanActivateOnDeletionWithContainingTrait(
- hashtable: hashtable,
- name: name,
- cardCondition: cardSource => cardSource == card
- );
- }
- public static bool CanActivateOnDeletionWithContainingTrait(
- Hashtable hashtable,
- string name,
- Func<CardSource, bool> cardCondition)
- {
- List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
- if (hashtables != null)
- {
- foreach (Hashtable hashtable1 in hashtables)
- {
- if (hashtable1 != null)
- {
- List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
- if (CardSources != null)
- {
- if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
- {
- if (hashtable1.ContainsKey("TopCard"))
- {
- if (hashtable1["TopCard"] is CardSource)
- {
- CardSource topCard = (CardSource)hashtable1["TopCard"];
- if (topCard != null)
- {
- if (topCard.ContainsTraits(name))
- {
- return true;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region Can activate [On Deletion] effect that can activate if the permanent has specific colors
- public static bool CanActivateSelfOnDeletionWithCardColors(Hashtable hashtable, Func<List<CardColor>, bool> cardColorCondition, CardSource card)
- {
- return CanActivateOnDeletionWithCardColors(
- hashtable: hashtable,
- cardColorCondition: cardColorCondition,
- cardCondition: cardSource => cardSource == card
- );
- }
- public static bool CanActivateOnDeletionWithCardColors(
- Hashtable hashtable,
- Func<List<CardColor>, bool> cardColorCondition,
- Func<CardSource, bool> cardCondition)
- {
- if (hashtable != null)
- {
- List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
- if (hashtables != null)
- {
- foreach (Hashtable hashtable1 in hashtables)
- {
- List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
- if (CardSources != null)
- {
- if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
- {
- if (hashtable1.ContainsKey("CardColors"))
- {
- if (hashtable1["CardColors"] is List<CardColor>)
- {
- List<CardColor> CardColors = (List<CardColor>)hashtable1["CardColors"];
- if (CardColors != null)
- {
- if (cardColorCondition == null || cardColorCondition(CardColors))
- {
- return true;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region Can activate [On Deletion] effect that can activate if the permanent has Save text
- public static bool CanActivateSelefOnDeletionWithSaveText(Hashtable hashtable, CardSource card)
- {
- return CanActivateOnDeletionWithSaveText(
- hashtable: hashtable,
- cardCondition: cardSource => cardSource == card
- );
- }
- public static bool CanActivateOnDeletionWithSaveText(
- Hashtable hashtable,
- Func<CardSource, bool> cardCondition)
- {
- List<Hashtable> hashtables = GetHashtablesFromHashtable(hashtable);
- if (hashtables != null)
- {
- foreach (Hashtable hashtable1 in hashtables)
- {
- List<CardSource> CardSources = GetCardSourcesFromHashtable(hashtable1);
- if (CardSources != null)
- {
- if (CardSources.Some(cardSource => cardCondition == null || cardCondition(cardSource)))
- {
- if (hashtable1.ContainsKey("HasSaveText"))
- {
- if (hashtable1["HasSaveText"] is bool)
- {
- bool HasSaveText = (bool)hashtable1["HasSaveText"];
- if (HasSaveText)
- {
- return true;
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #endregion
- }
|