| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using System.Linq;
- using UnityEngine;
- public partial class CardEffectCommons
- {
- #region Whether the card is in the field
- public static bool IsExistOnField(CardSource card)
- {
- if(card != null)
- {
- if (card.PermanentOfThisCard() != null)
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region Whether the card is in the Breeding Area
- public static bool IsExistOnBreedingArea(CardSource card)
- {
- if (IsExistOnField(card))
- {
- if (card.Owner.GetBreedingAreaPermanents().Contains(card.PermanentOfThisCard()))
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region Whether the card is Digimon and in the Breeding Area
- public static bool IsExistOnBreedingAreaDigimon(CardSource card)
- {
- if (IsExistOnField(card))
- {
- if (card.Owner.GetBreedingAreaPermanents().Contains(card.PermanentOfThisCard()))
- {
- if (card.PermanentOfThisCard().IsDigimon)
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #region Whether the card is in the Battle Area
- public static bool IsExistOnBattleArea(CardSource card)
- {
- if (IsExistOnField(card))
- {
- if (card.Owner.GetBattleAreaPermanents().Contains(card.PermanentOfThisCard()))
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region Whether the card is Digimon and in the Battle Area
- public static bool IsExistOnBattleAreaDigimon(CardSource card)
- {
- if (IsExistOnBattleArea(card))
- {
- if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region Whether the card is in hand
- public static bool IsExistOnHand(CardSource card)
- {
- if (card.Owner.HandCards.Contains(card))
- {
- return true;
- }
- return false;
- }
- #endregion
- #region Whether the card is in trash
- public static bool IsExistOnTrash(CardSource card)
- {
- if (card.Owner.TrashCards.Contains(card))
- {
- return true;
- }
- return false;
- }
- #endregion
- #region Whether the card is in Executing Area
- public static bool IsExistOnExecutingArea(CardSource card)
- {
- if (card.Owner.ExecutingCards.Contains(card))
- {
- return true;
- }
- return false;
- }
- #endregion
- #region Whether the card Can be played as a new permanent
- public static bool CanPlayAsNewPermanent(
- CardSource cardSource,
- bool payCost,
- ICardEffect cardEffect,
- SelectCardEffect.Root root = SelectCardEffect.Root.Hand,
- bool isBreedingArea = false,
- bool isPlayOption = false,
- int fixedCost = -1) =>
- cardSource != null &&
- (isPlayOption || !cardSource.IsOption)
- && cardSource.Owner.fieldCardFrames.Some((frame) =>
- frame.IsEmptyFrame()
- && cardSource.CanPlayCardTargetFrame(frame, payCost, cardEffect, root, isBreedingArea: isBreedingArea, fixedCost:fixedCost));
- #endregion
- #region Whether the permanent is in the Battle Area
- public static bool IsPermanentExistsOnBattleArea(Permanent permanent)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent))
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #region Whether the permanent is in the Breeding Area
- public static bool IsPermanentExistsOnBreedingArea(Permanent permanent)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (permanent.TopCard.Owner.GetBreedingAreaPermanents().Contains(permanent))
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #region Whether the permanent is card's owner's
- public static bool IsOwnerPermanent(Permanent permanent, CardSource card)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (card != null)
- {
- if (permanent.TopCard.Owner == card.Owner)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region Whether the permanent is card's owner's opponent's
- public static bool IsOpponentPermanent(Permanent permanent, CardSource card)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (permanent.TopCard.Owner == card.Owner.Enemy)
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #region Whether the permanent is in the card's owner's Battle Area
- public static bool IsPermanentExistsOnOwnerBattleArea(Permanent permanent, CardSource card)
- {
- if (IsPermanentExistsOnBattleArea(permanent))
- {
- if (IsOwnerPermanent(permanent, card))
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region Whether the permanent is in the card's owner's opponent's Battle Area
- public static bool IsPermanentExistsOnOpponentBattleArea(Permanent permanent, CardSource card)
- {
- if (IsPermanentExistsOnBattleArea(permanent))
- {
- if (IsOpponentPermanent(permanent, card))
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region Whether the permanent is in the card's owner's Breeding Area
- public static bool IsPermanentExistsOnOwnerBreedingArea(Permanent permanent, CardSource card)
- {
- if (IsPermanentExistsOnBreedingArea(permanent))
- {
- if (IsOwnerPermanent(permanent, card))
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region Whether the permanent is in the card's owner's opponent's Breeding Area
- public static bool IsPermanentExistsOnOpponentBreedingArea(Permanent permanent, CardSource card)
- {
- if (IsPermanentExistsOnBreedingArea(permanent))
- {
- if (IsOpponentPermanent(permanent, card))
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region Whether the permanent is Digimon and in the card's owner's Battle Area
- public static bool IsPermanentExistsOnOwnerBattleAreaDigimon(Permanent permanent, CardSource card)
- {
- if (IsPermanentExistsOnOwnerBattleArea(permanent, card))
- {
- if (permanent.IsDigimon)
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region Whether the permanent is Digimon and in the card's owner's opponent's Battle Area
- public static bool IsPermanentExistsOnOpponentBattleAreaDigimon(Permanent permanent, CardSource card)
- {
- if (IsPermanentExistsOnOpponentBattleArea(permanent, card))
- {
- if (permanent.IsDigimon)
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region How many permanents there are in the Battle Area that satisfy the condition
- public static int MatchConditionPermanentCount(Func<Permanent, bool> CanSelectPermanentCondition, bool isContainBreedingArea = false)
- {
- if (isContainBreedingArea)
- {
- return GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Count(CanSelectPermanentCondition);
- }
- else
- {
- return GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetBattleAreaPermanents())
- .Flat()
- .Count(CanSelectPermanentCondition);
- }
- }
- #endregion
- #region How many permanents there are in the owner's Battle Area that satisfy the condition
- public static int MatchConditionOwnersPermanentCount(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
- {
- return MatchConditionPermanentCount(permanent => CanSelectPermanentCondition(permanent) && IsOwnerPermanent(permanent, card));
- }
- #endregion
- #region How many permanents there are in the owner's opponent's Battle Area that satisfy the condition
- public static int MatchConditionOpponentsPermanentCount(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
- {
- return MatchConditionPermanentCount(permanent => CanSelectPermanentCondition(permanent) && IsOpponentPermanent(permanent, card));
- }
- #endregion
- #region Whether there is at least 1 permanent in the Battle Area that satisfies the condition
- public static bool HasMatchConditionPermanent(Func<Permanent, bool> CanSelectPermanentCondition, bool isContainBreedingArea = false)
- {
- if (isContainBreedingArea)
- {
- return GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Some(CanSelectPermanentCondition);
- }
- else
- {
- return GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetBattleAreaPermanents())
- .Flat()
- .Some(CanSelectPermanentCondition);
- }
- }
- #endregion
- #region Whether there is at least 1 card in the owner's hand that satisfies the condition
- public static bool HasMatchConditionOwnersHand(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
- {
- return GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.HandCards)
- .Flat()
- .Some(source => CanSelectCardCondition(source) && IsExistOnHand(card));
- }
- #endregion
- #region How many cards there are in the owner's hand that satisfy the condition
- public static int MatchConditionOwnersCardCountInHand(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
- {
- return card.Owner.HandCards.Count(CanSelectCardCondition);
- }
- #endregion
- #region Whether there is at least 1 permanent in the owner's Battle Area that satisfies the condition
- public static bool HasMatchConditionOwnersPermanent(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
- {
- return GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetBattleAreaPermanents())
- .Flat()
- .Some(permanent => CanSelectPermanentCondition(permanent) && IsOwnerPermanent(permanent, card));
- }
- #endregion
- #region Whether there is at least 1 permanent in the owner's opponent's Battle Area that satisfies the condition
- public static bool HasMatchConditionOpponentsPermanent(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
- {
- return GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetBattleAreaPermanents())
- .Flat()
- .Some(permanent => CanSelectPermanentCondition(permanent) && IsOpponentPermanent(permanent, card));
- }
- #endregion
- #region How many cards there are in the owner's trash that satisfy the condition
- public static int MatchConditionOwnersCardCountInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
- {
- return card.Owner.TrashCards.Count(CanSelectCardCondition);
- }
- #endregion
- #region How many cards there are in the owner's opponent's trash that satisfy the condition
- public static int MatchConditionOpponentsCardCountInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
- {
- return card.Owner.Enemy.TrashCards.Count(CanSelectCardCondition);
- }
- #endregion
- #region Whether there is at least 1 card in the owner's trash that satisfies the condition
- public static bool HasMatchConditionOwnersCardInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
- {
- return card.Owner.TrashCards.Some(CanSelectCardCondition);
- }
- #endregion
- #region Whether there is at least 1 card in the owner's opponent's trash that satisfies the condition
- public static bool HasMatchConditionOpponentsCardInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
- {
- return card.Owner.Enemy.TrashCards.Some(CanSelectCardCondition);
- }
- #endregion
- #region Whether the list has no element
- public static bool HasNoElement<T>(List<T> list) => list.Count <= 0;
- #endregion
- #region Wheter it is the player's turn
- public static bool IsOwnerTurn(CardSource card) => GManager.instance.turnStateMachine.gameContext.TurnPlayer == card.Owner;
- public static bool IsOpponentTurn(CardSource card) => !IsOwnerTurn(card);
- #endregion
- #region Whether the effect is your effect
- public static bool IsOwnerEffect(ICardEffect cardEffect, CardSource card)
- {
- if (cardEffect != null)
- {
- if (cardEffect.EffectSourceCard != null)
- {
- if (cardEffect.EffectSourceCard.Owner == card.Owner)
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #region Whether the effect is opponent's effect
- public static bool IsOpponentEffect(ICardEffect cardEffect, CardSource card)
- {
- if (cardEffect != null)
- {
- if (cardEffect.EffectSourceCard != null)
- {
- if (cardEffect.EffectSourceCard.Owner == card.Owner.Enemy)
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- }
|