| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335 |
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- using Photon.Pun;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- public class CardSource : MonoBehaviour
- {
- #region card base entity
- CEntity_Base _cEntity_Base = null;
- #endregion
- #region PhotonView
- public PhotonView PhotonView { get; set; }
- #endregion
- #region owner
- public Player Owner { get; private set; } = null;
- #endregion
- #region card index
- public int CardIndex { get; private set; } = 0;
- #endregion
- #region set card base entity
- public void SetBaseData(CEntity_Base cEntity_Base, Player owner)
- {
- _cEntity_Base = cEntity_Base;
- Owner = owner;
- gameObject.name = _cEntity_Base.CardName_ENG;
- SetFace();
- }
- #endregion
- #region card effect controller
- public CEntity_EffectController cEntity_EffectController;
- #endregion
- #region whether this card is reversed
- public bool IsFlipped { get; private set; }
- #region set face
- public void SetFace()
- {
- IsFlipped = false;
- }
- #endregion
- #region set reverse
- public void SetReverse()
- {
- IsFlipped = true;
- }
- #endregion
- #endregion
- #region Card ID setup
- public void SetUpCardIndex(int _cardIndex)
- {
- PhotonView _PhotonView = GetComponent<PhotonView>();
- _PhotonView ??= gameObject.AddComponent<PhotonView>();
- CardIndex = _cardIndex;
- _PhotonView.ViewID = CardIndex + 60;
- PhotonView = _PhotonView;
- }
- #endregion
- #region whether this card can be played
- public bool CanPlayFromHandDuringMainPhase
- {
- get
- {
- if (CanNotPlayThisOption)
- {
- return false;
- }
- if (_cEntity_Base.IsPermanent)
- {
- if (!CanPlayJogress(true))
- {
- if (!CanPutFieldThisPermanentCard(true, null))
- {
- return false;
- }
- }
- }
- else if (IsOption)
- {
- #region whether cost can be paid
- List<int> costs = new List<int>() { this.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: true) };
- bool canPayCost = costs.Some(cost => Owner.MaxMemoryCost >= cost);
- if (!canPayCost) return false;
- #endregion
- }
- return true;
- }
- }
- #endregion
- #region Whether this option card's effect prevents it from being played
- public bool CanNotPlayThisOption
- {
- get
- {
- if (!IsOption)
- {
- return false;
- }
- #region the effects of players
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is ICanNotPlayCardEffect
- && cardEffect.CanUse(null)
- && ((ICanNotPlayCardEffect)cardEffect).CanNotPlay(this)))
- {
- return true;
- }
- #endregion
- #region the effects of permanents
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is ICanNotPlayCardEffect
- && cardEffect.CanUse(null)
- && ((ICanNotPlayCardEffect)cardEffect).CanNotPlay(this)))
- {
- return true;
- }
- #endregion
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- if (EffectList(EffectTiming.None)
- .Some(cardEffect => cardEffect is ICanNotPlayCardEffect
- && cardEffect.CanUse(null)
- && ((ICanNotPlayCardEffect)cardEffect).CanNotPlay(this)))
- {
- return true;
- }
- }
- #endregion
- #region Whether the color requirement is met
- if (!MatchColorRequirement)
- {
- return true;
- }
- #endregion
- return false;
- }
- }
- #endregion
- #region Whether the color requirement is met
- public bool MatchColorRequirement
- {
- get
- {
- if (IsOption)
- {
- #region "ignore color requirement" effects
- #region the effects of permanents
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is IIgnoreColorConditionEffect
- && cardEffect.CanUse(null)
- && ((IIgnoreColorConditionEffect)cardEffect).IgnoreColorCondition(this)))
- {
- return true;
- }
- #endregion
- #region the effects of players
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is IIgnoreColorConditionEffect
- && cardEffect.CanUse(null)
- && ((IIgnoreColorConditionEffect)cardEffect).IgnoreColorCondition(this)))
- {
- return true;
- }
- #endregion
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- if (EffectList(EffectTiming.None)
- .Some(cardEffect => cardEffect is IIgnoreColorConditionEffect
- && cardEffect.CanUse(null)
- && ((IIgnoreColorConditionEffect)cardEffect).IgnoreColorCondition(this)))
- {
- return true;
- }
- }
- #endregion
- #endregion
- bool matchColorRequirement = CardColors.Every(cardColor =>
- Owner.GetFieldPermanents().Some(permanent =>
- !permanent.TopCard.IsOption && permanent.TopCard.CardColors.Contains(cardColor)));
- if (!matchColorRequirement)
- {
- return false;
- }
- }
- return true;
- }
- }
- #endregion
- #region Card object in hand displaying this card
- public HandCard ShowingHandCard { get; private set; }
- public void SetShowingHandCard(HandCard showingHandCard) => ShowingHandCard = showingHandCard;
- #endregion
- #region Permanent in the field containing this card
- public Permanent PermanentOfThisCard()
- {
- return Owner.GetFieldPermanents().Find(permanent => permanent.cardSources.Contains(this) && !IsFlipped);
- }
- #endregion
- #region initialize
- public void Init()
- {
- cEntity_EffectController.InitUseCountThisTurn();
- SetFace();
- }
- #endregion
- #region base card colors from entity
- public List<CardColor> BaseCardColorsFromEntity => _cEntity_Base.cardColors.Distinct().ToList();
- #endregion
- #region base card colors
- public List<CardColor> BaseCardColors
- {
- get
- {
- List<CardColor> baseCardColors = BaseCardColorsFromEntity;
- #region the effects that changes base card colors
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- EffectList(EffectTiming.None)
- .Filter(cardEffect => cardEffect is IChangeBaseCardColorEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => baseCardColors = ((IChangeBaseCardColorEffect)cardEffect).GetBaseCardColors(baseCardColors, this));
- }
- #endregion
- #region the effects of permanents
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IChangeBaseCardColorEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => baseCardColors = ((IChangeBaseCardColorEffect)cardEffect).GetBaseCardColors(baseCardColors, this));
- #endregion
- #endregion
- baseCardColors = baseCardColors.Distinct().ToList();
- return baseCardColors;
- }
- }
- #endregion
- #region card colors
- public List<CardColor> CardColors
- {
- get
- {
- List<CardColor> cardColors = BaseCardColors;
- #region the effects that changes card colors
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- EffectList(EffectTiming.None)
- .Filter(cardEffect => cardEffect is IChangeCardColorEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => cardColors = ((IChangeCardColorEffect)cardEffect).GetCardColors(cardColors, this));
- }
- #endregion
- #region the effects of permanents
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IChangeCardColorEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => cardColors = ((IChangeCardColorEffect)cardEffect).GetCardColors(cardColors, this));
- #endregion
- #endregion
- cardColors = cardColors.Distinct().ToList();
- return cardColors;
- }
- }
- #endregion
- #region evoCosts from entity
- public List<EvoCost> BaseEvoCostsFromEntity => _cEntity_Base.EvoCosts;
- #endregion
- #region evoCosts
- public List<Func<Permanent, int>> EvoCosts(bool ignoreLevel, bool checkAvailability)
- {
- List<Func<Permanent, int>> EvoCosts = new List<Func<Permanent, int>>();
- #region the effects that add evoCosts
- #region the effects of players
- EvoCosts = EvoCosts
- .Concat(
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IAddDigivolutionRequirementEffect && cardEffect.CanUse(null))
- .Map<ICardEffect, Func<Permanent, int>>(cardEffect =>
- (targetPermanent) => ((IAddDigivolutionRequirementEffect)cardEffect).GetEvoCost(targetPermanent, this, checkAvailability)))
- .ToList();
- #endregion
- #region the effects of permanents
- EvoCosts = EvoCosts
- .Concat(
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IAddDigivolutionRequirementEffect && cardEffect.CanUse(null))
- .Map<ICardEffect, Func<Permanent, int>>(cardEffect =>
- (targetPermanent) => ((IAddDigivolutionRequirementEffect)cardEffect).GetEvoCost(targetPermanent, this, checkAvailability)))
- .ToList();
- #endregion
- #region the effects of itself
- if (PermanentOfThisCard() == null || PermanentOfThisCard().DigivolutionCards.Contains(this))
- {
- EvoCosts = EvoCosts
- .Concat(
- EffectList(EffectTiming.None)
- .Filter(cardEffect => cardEffect is IAddDigivolutionRequirementEffect && cardEffect.CanUse(null))
- .Map<ICardEffect, Func<Permanent, int>>(cardEffect =>
- (targetPermanent) => ((IAddDigivolutionRequirementEffect)cardEffect).GetEvoCost(targetPermanent, this, checkAvailability)))
- .ToList();
- }
- #endregion
- #endregion
- EvoCosts = EvoCosts
- .Concat(
- BaseEvoCostsFromEntity
- .Map<EvoCost, Func<Permanent, int>>(evoCost =>
- (targetPermanent) =>
- {
- if (targetPermanent.TopCard.CardColors.Contains(evoCost.CardColor))
- {
- if (ignoreLevel || targetPermanent.Level == evoCost.Level)
- {
- return evoCost.MemoryCost;
- }
- }
- return -1;
- }))
- .ToList();
- return EvoCosts;
- }
- #endregion
- #region evo cost list
- public List<int> CostList(Permanent targetPermanent, bool ignoreLevel, bool checkAvailability)
- {
- return EvoCosts(ignoreLevel, checkAvailability)
- .Filter(evoCost => evoCost(targetPermanent) >= 0)
- .Map(evoCost => evoCost(targetPermanent));
- }
- #endregion
- #region cost list
- #region cost to pay
- public int PayingCost(SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false, bool ignoreLevel = false, int FixedCost = -1)
- {
- int baseCost = _cEntity_Base.PlayCost;
- if (targetPermanents != null)
- {
- if (targetPermanents.Count == 1)
- {
- Permanent targetPermanent = targetPermanents[0];
- if (targetPermanent != null)
- {
- List<int> costList = CostList(targetPermanent, ignoreLevel: ignoreLevel, checkAvailability: checkAvailability);
- if (costList.Count >= 1)
- {
- baseCost = costList.Min();
- }
- }
- }
- }
- return GetPayingCostWithBaseCost(baseCost, root, targetPermanents, checkAvailability: checkAvailability, FixedCost: FixedCost);
- }
- #endregion
- #region cost that will be paid taking into account baseCost
- public int GetPayingCostWithBaseCost(int baseCost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false, int FixedCost = -1)
- {
- int Cost = FixedCost >= 0 ? FixedCost : baseCost;
- bool isEvolution = targetPermanents != null && targetPermanents.Some((permanent) => permanent != null);
- #region DigiXros
- if (!isEvolution)
- {
- if (HasDigiXros)
- {
- if (Owner.CanReduceCost(null, this))
- {
- //AI
- if (!(!Owner.isYou && GManager.instance.IsAI))
- {
- if (checkAvailability)
- {
- return 0;
- }
- }
- if (!checkAvailability)
- {
- SelectDigiXrosClass selectDigiXrosClass = GManager.instance.GetComponent<SelectDigiXrosClass>();
- if (selectDigiXrosClass != null)
- {
- if (selectDigiXrosClass.playCard == this)
- {
- Cost -= selectDigiXrosClass.selectedDigicrossCards.Count * digiXrosCondition.reduceCostPerCard;
- }
- }
- }
- }
- }
- }
- #endregion
- Cost = GetChangedCostItselef(Cost, root, targetPermanents, checkAvailability);
- Cost = GetChangedPayingCost(Cost, root, targetPermanents, checkAvailability);
- if (Cost < 0)
- {
- Cost = 0;
- }
- return Cost;
- }
- #endregion
- #region base play cost from entity
- public int BasePlayCostFromEntity => _cEntity_Base.PlayCost;
- #endregion
- #region get card cost of itself (refered by card effects)
- public int GetCostItself => Math.Max(0, GetChangedCostItselef(BasePlayCostFromEntity, SelectCardEffect.Root.None, new List<Permanent>()));
- #endregion
- #region get card cost of itself taking into account card effects
- public int GetChangedCostItselef(int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false)
- {
- if (checkAvailability)
- {
- if (GManager.instance.IsAI)
- {
- if (targetPermanents != null)
- {
- if (targetPermanents.Some(permanent => permanent != null && permanent.TopCard != null && !permanent.TopCard.Owner.isYou))
- {
- return Math.Max(0, Cost);
- }
- }
- }
- }
- #region card effects that changes card cost
- List<ICardEffect> changeCostCardEffects = new List<ICardEffect>();
- #region the effects of permanents
- changeCostCardEffects = changeCostCardEffects
- .Concat(
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
- && ((IChangeCostEffect)cardEffect).CardCondition(this)
- && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
- && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
- .ToList();
- #endregion
- #region the effects of players
- changeCostCardEffects = changeCostCardEffects
- .Concat(
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
- && ((IChangeCostEffect)cardEffect).CardCondition(this)
- && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
- && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
- .ToList();
- #endregion
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- changeCostCardEffects = changeCostCardEffects
- .Concat(
- EffectList(EffectTiming.None)
- .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
- && ((IChangeCostEffect)cardEffect).CardCondition(this)
- && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
- && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
- .ToList();
- }
- #endregion
- List<ICardEffect> changeCostCardEffects_NotIsUpDown = changeCostCardEffects
- .Filter(cardEffect => !((IChangeCostEffect)cardEffect).IsUpDown());
- List<ICardEffect> changeCostCardEffects_IsUpDown = changeCostCardEffects
- .Filter(cardEffect => ((IChangeCostEffect)cardEffect).IsUpDown());
- changeCostCardEffects_NotIsUpDown
- .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
- changeCostCardEffects_IsUpDown
- .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
- #endregion
- return Math.Max(0, Cost);
- }
- #endregion
- #region get card cost to pay of itself taking into account card effects
- public int GetChangedPayingCost(int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false)
- {
- #region card effects that changes card cost to pay
- List<ICardEffect> changePayingCostCardEffects = new List<ICardEffect>();
- #region the effects of permanents
- changePayingCostCardEffects = changePayingCostCardEffects
- .Concat(
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
- && ((IChangeCostEffect)cardEffect).CardCondition(this)
- && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
- && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
- .ToList();
- #endregion
- #region the effects of players
- changePayingCostCardEffects = changePayingCostCardEffects
- .Concat(
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
- && ((IChangeCostEffect)cardEffect).CardCondition(this)
- && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
- && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
- .ToList();
- #endregion
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- changePayingCostCardEffects = changePayingCostCardEffects
- .Concat(
- EffectList(EffectTiming.None)
- .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
- && ((IChangeCostEffect)cardEffect).CardCondition(this)
- && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
- && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
- .ToList();
- }
- #endregion
- List<ICardEffect> changePayingCostCardEffects_NotIsUpDown = changePayingCostCardEffects
- .Filter(cardEffect => !((IChangeCostEffect)cardEffect).IsUpDown());
- List<ICardEffect> changePayingCostCardEffects_IsUpDown = changePayingCostCardEffects
- .Filter(cardEffect => ((IChangeCostEffect)cardEffect).IsUpDown());
- changePayingCostCardEffects_NotIsUpDown
- .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
- changePayingCostCardEffects_IsUpDown
- .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
- #endregion
- return Math.Max(0, Cost);
- }
- #endregion
- #endregion
- #region level
- public int Level => _cEntity_Base.Level;
- #endregion
- #region effect list
- public List<ICardEffect> EffectList(EffectTiming timing)
- {
- return EffectList_ForCard(timing, this);
- }
- #endregion
- #region effect list for 1 card
- public List<ICardEffect> EffectList_ForCard(EffectTiming timing, CardSource cardSource)
- {
- List<ICardEffect> _EffectList = cEntity_EffectController
- .GetCardEffects(timing, cardSource)
- .Filter(cardEffect => cardEffect != null);
- foreach (ICardEffect cardEffect in _EffectList)
- {
- if (cardEffect.EffectSourceCard == null)
- {
- cardEffect.SetEffectSourceCard(this);
- }
- }
- return _EffectList;
- }
- #endregion
- #region effect list except added effects
- public List<ICardEffect> EffectList_ExceptAddedEffects(EffectTiming timing)
- {
- return EffectList_ForCard_ExceptAddedEffects(timing, this);
- }
- #endregion
- #region effect list for 1 card
- public List<ICardEffect> EffectList_ForCard_ExceptAddedEffects(EffectTiming timing, CardSource cardSource)
- {
- List<ICardEffect> _EffectList = cEntity_EffectController
- .GetCardEffects_ExceptAddedEffects(timing, cardSource)
- .Filter(cardEffect => cardEffect != null);
- foreach (ICardEffect cardEffect in _EffectList)
- {
- if (cardEffect.EffectSourceCard == null)
- {
- cardEffect.SetEffectSourceCard(this);
- }
- }
- return _EffectList;
- }
- #endregion
- #region whether this card can declare skill
- public bool CanDeclareSkill => CanDeclareSkillList.Count > 0;
- #endregion
- #region effect list that this card can declare
- public List<ICardEffect> CanDeclareSkillList
- {
- get
- {
- return EffectList(EffectTiming.OnDeclaration)
- .Filter(cardEffect => cardEffect is ActivateICardEffect && cardEffect.CanUse(null));
- }
- }
- #endregion
- #region whether this card can not be affected by the effect
- public bool CanNotBeAffected(ICardEffect _cardEffect)
- {
- if (_cardEffect == null) return false;
- #region the effects of permanents
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is ICanNotAffectedEffect
- && cardEffect.CanUse(null)
- && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
- {
- return true;
- }
- #endregion
- #region the effects of players
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is ICanNotAffectedEffect
- && cardEffect.CanUse(null)
- && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
- {
- return true;
- }
- #endregion
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- if (EffectList(EffectTiming.None)
- .Some(cardEffect => cardEffect is ICanNotAffectedEffect
- && cardEffect.CanUse(null)
- && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
- {
- return true;
- }
- }
- #endregion
- return false;
- }
- #endregion
- #region whether this card can be played at the frame
- public bool CanPlayCardTargetFrame(FieldCardFrame frame, bool PayCost, ICardEffect cardEffect, SelectCardEffect.Root root = SelectCardEffect.Root.Hand, int fixedCost = -1, bool isBreedingArea = false)
- {
- bool isBattleAreaFrame = FieldCardFrame.isBattleAreaFrameID(frame.FrameID);
- if (isBreedingArea)
- {
- if (isBattleAreaFrame)
- {
- return false;
- }
- }
- if (PermanentOfThisCard() != null)
- {
- if (this == PermanentOfThisCard().TopCard)
- {
- if (PermanentOfThisCard().HasNoDigivolutionCards)
- {
- return false;
- }
- }
- }
- if (frame.player != Owner)
- {
- return false;
- }
- if (PayCost && frame.GetFramePermanent() == null)
- {
- int cost = PayingCost(root, new List<Permanent>() { frame.GetFramePermanent() }, checkAvailability: true, FixedCost: fixedCost);
- if (Owner.MaxMemoryCost < cost)
- {
- return false;
- }
- }
- if (frame.GetFramePermanent() != null)
- {
- if (!CanEvolve(frame.GetFramePermanent(), true))
- {
- return false;
- }
- }
- else
- {
- if (!CanEnterField(cardEffect))
- {
- return false;
- }
- }
- if (IsDigiEgg)
- {
- if (isBattleAreaFrame)
- {
- return false;
- }
- }
- else
- {
- if (!isBattleAreaFrame && frame.GetFramePermanent() == null && !isBreedingArea)
- {
- return false;
- }
- }
- return true;
- }
- #endregion
- #region whether there is at least 1 frame where this card can be placed
- public bool CanPutFieldThisPermanentCard(bool PayCost, ICardEffect cardEffect, bool isBreedingArea = false)
- {
- return Owner.fieldCardFrames.Some((frame) => CanPlayCardTargetFrame(frame, PayCost, cardEffect, isBreedingArea: isBreedingArea));
- }
- #endregion
- #region whether this card can be placed on the field by the effect
- public bool CanEnterField(ICardEffect _cardEffect)
- {
- #region the effects of permanents
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
- && cardEffect.CanUse(null)
- && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
- {
- return false;
- }
- #endregion
- #region the effects of players
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
- && cardEffect.CanUse(null)
- && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
- {
- return false;
- }
- #endregion
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- if (EffectList(EffectTiming.None)
- .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
- && cardEffect.CanUse(null)
- && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
- {
- return false;
- }
- }
- #endregion
- return true;
- }
- #endregion
- #region whether the permanent can digivolve into this card
- public bool CanEvolve(Permanent targetPermanent, bool checkAvailability)
- {
- if (targetPermanent != null)
- {
- if (CanNotEvolve(targetPermanent))
- {
- return false;
- }
- if (targetPermanent.TopCard != null)
- {
- foreach (Func<Permanent, int> EvoCost in EvoCosts(false, checkAvailability))
- {
- if (EvoCost(targetPermanent) >= 0)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region whether the permanent's digivolution into this card is prohibited
- public bool CanNotEvolve(Permanent targetPermanent)
- {
- if (targetPermanent.IsToken)
- {
- return true;
- }
- if (IsToken)
- {
- return true;
- }
- #region card effects that can't digivolve
- #region the effects of permanents
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
- && cardEffect.CanUse(null)
- && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
- {
- return true;
- }
- #endregion
- #region the effects of players
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
- && cardEffect.CanUse(null)
- && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
- {
- return true;
- }
- #endregion
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- if (EffectList(EffectTiming.None)
- .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
- && cardEffect.CanUse(null)
- && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
- {
- return true;
- }
- }
- #endregion
- #endregion
- return false;
- }
- #endregion
- #region ENG card name from entity
- public string BaseENGCardNameFromEntity => _cEntity_Base.CardName_ENG;
- #endregion
- #region JPN card name from entity
- public string BaseJPNCardNameFromEntity => _cEntity_Base.CardName_ENG;
- #endregion
- #region base card names
- public List<string> BaseCardNames
- {
- get
- {
- List<string> baseCardNames = new List<string>() { BaseENGCardNameFromEntity };
- Permanent thisPermanent = PermanentOfThisCard();
- bool isPermanent = PermanentOfThisCard() != null;
- bool isDigivolutionCard = isPermanent && thisPermanent.DigivolutionCards.Contains(this);
- #region card effects that change base card names
- if (isDigivolutionCard)
- {
- EffectList_ExceptAddedEffects(EffectTiming.None)
- .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
- }
- else
- {
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- EffectList(EffectTiming.None)
- .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
- }
- #endregion
- #region the effects of permanents
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
- #endregion
- #region the effects of players
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
- #endregion
- }
- #endregion
- return baseCardNames;
- }
- }
- #endregion
- #region card names
- public List<string> CardNames
- {
- get
- {
- List<string> cardNames = BaseCardNames.Clone();
- #region the effects of itself
- EffectList_ExceptAddedEffects(EffectTiming.None)
- .Filter(cardEffect => cardEffect != null)
- .Filter(cardEffect => cardEffect is IChangeCardNamesEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => cardNames = ((IChangeCardNamesEffect)cardEffect).ChangeCardNames(cardNames, this));
- #endregion
- return cardNames.Distinct().ToList();
- }
- }
- #endregion
- #region Whether target other card's name has same name as this
- public bool HasSameCardName(CardSource cardSource) => cardSource.CardNames.Count((cardName) => CardNames.Contains(cardName)) >= 1;
- #endregion
- #region whether this card has at least 1 card name that contains the string
- public bool ContainsCardName(string name)
- {
- if (string.IsNullOrEmpty(name))
- {
- return false;
- }
- string replaced = name.Replace(" ", "");
- string lower = name.ToLower();
- return CardNames.Some((cardName) =>
- cardName.Contains(name)
- || cardName.Contains(replaced)
- || cardName.Contains(lower)
- || cardName.ToLower().Contains(lower));
- }
- #endregion
- #region whether this card has at least 1 card name that contains "Greymon"
- public bool HasGreymonName
- {
- get
- {
- if (CardNames.Some((cardName) => (cardName.Contains("Greymon") || cardName.Contains("greymon"))
- && cardName != "DoruGreymon"
- && cardName != "BurningGreymon"
- && cardName != "DexDoruGreymon"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 card name that contains "Garurumon"
- public bool HasGarurumonName
- {
- get
- {
- if (CardNames.Some((cardName) => (cardName.Contains("Garurumon") || cardName.Contains("garurumon"))
- && cardName != "KendoGarurumon"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 card name that contains "Impmon"
- public bool HasImpmonName
- {
- get
- {
- if (CardNames.Some((cardName) => (cardName.Contains("Impmon") || cardName.Contains("impmon"))
- && cardName != "Blimpmon"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 card name that contains "Dramon"
- public bool HasDramonName
- {
- get
- {
- if (CardNames.Some((cardName) => (cardName.Contains("Dramon") || cardName.Contains("dramon"))
- && cardName != "Indramon"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 card name that contains "AAntibody"
- public bool HasXAntiBodyName => CardNames.Some(DataBase.IsContainingXAntibodyString);
- #endregion
- #region whether this card has at least 1 trait that contains the string
- public bool ContainsTraits(string trait)
- {
- if (string.IsNullOrEmpty(trait))
- {
- return false;
- }
- string replaced = trait.Replace(" ", "");
- return CardTraits.Some(cardTrait => cardTrait.Contains(trait) || cardTrait.Contains(replaced));
- }
- #endregion
- #region whether this card has at least 1 trait that contains "Bird"
- public bool HasBirdTraits
- {
- get
- {
- if (ContainsTraits("Avian"))
- {
- return true;
- }
- if (ContainsTraits("Bird"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 trait that contains "Beast"
- public bool HasBeastTraits
- {
- get
- {
- if (CardTraits.Count((trait) => trait.Contains("Animal") && trait != "Sea Animal" && trait != "SeaAnimal") >= 1)
- {
- return true;
- }
- if (ContainsTraits("Beast"))
- {
- return true;
- }
- if (ContainsTraits("Animal"))
- {
- return true;
- }
- if (ContainsTraits("Sovereign"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 trait that contains "Plant"
- public bool HasPlantTraits
- {
- get
- {
- if (ContainsTraits("Vegetation"))
- {
- return true;
- }
- if (ContainsTraits("Plant"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 trait that contains "Fairy"
- public bool HasFairyTraits
- {
- get
- {
- if (ContainsTraits("Fairy"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 trait that contains "Dragon"
- public bool HasDragonTraits
- {
- get
- {
- if (ContainsTraits("Dragon"))
- {
- return true;
- }
- if (ContainsTraits("saur"))
- {
- return true;
- }
- if (ContainsTraits("Ceratopsian"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 trait that contains "Aqua"
- public bool HasAquaTraits
- {
- get
- {
- if (ContainsTraits("Aqua"))
- {
- return true;
- }
- if (ContainsTraits("Sea Animal"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 trait that contains "Angel"
- public bool HasAngelTraits
- {
- get
- {
- if (CardTraits.Count((trait) => (trait.Contains("Angel") || trait.Contains("angel")) && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
- {
- return true;
- }
- if (ContainsTraits("Cherub"))
- {
- return true;
- }
- if (ContainsTraits("Throne"))
- {
- return true;
- }
- if (ContainsTraits("Authority"))
- {
- return true;
- }
- if (ContainsTraits("Seraph"))
- {
- return true;
- }
- if (ContainsTraits("Virtue"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has "XAntibody" trait
- public bool HasXAntibodyTraits => CardTraits.Some(DataBase.IsXAntibodyString);
- #endregion
- #region whether this card has "Royal Knight" trait
- public bool HasRoyalKnightTraits
- {
- get
- {
- if (CardTraits.Contains("Royal Knight") || CardTraits.Contains("RoyalKnight"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 trait that contains "Beast Dragon"
- public bool HasBeastDragonTraits
- {
- get
- {
- if (ContainsTraits("BeastDragon"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has at least 1 trait that contains "DigiPolice"
- public bool HasDigiPoliceTraits
- {
- get
- {
- if (ContainsTraits("DigiPolice"))
- {
- return true;
- }
- return false;
- }
- }
- #endregion
- #region whether this card has the string in text
- public bool HasText(string text)
- {
- if (String.IsNullOrEmpty(text)) return false;
- text = DataBase.ReplaceToASCII(text);
- string replaced = text.Replace(" ", "");
- string lower = text.ToLower();
- List<string> checkStrings = new List<string>()
- {
- DataBase.ReplaceToASCII(_cEntity_Base.CardName_ENG),
- DataBase.ReplaceToASCII(_cEntity_Base.EffectDiscription_ENG),
- DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG),
- DataBase.ReplaceToASCII(_cEntity_Base.SecurityEffectDiscription_ENG),
- };
- foreach (string checkString in checkStrings)
- {
- if (!string.IsNullOrEmpty(checkString))
- {
- if (checkString.Contains(text))
- {
- return true;
- }
- if (checkString.Contains(replaced))
- {
- return true;
- }
- if (checkString.Contains(lower))
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #region whether this card has <Save> in text
- public bool HasSaveText => HasText("<Save>");
- #endregion
- #region card names checked when digixros
- public List<string> CardNames_DigiXros
- {
- get
- {
- List<string> cardNames_DigiXros = CardNames.Clone();
- #region the effects of itself
- EffectList(EffectTiming.None)
- .Filter(cardEffect => cardEffect is IChangeCardNamesForDigiXrosEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => cardNames_DigiXros = ((IChangeCardNamesForDigiXrosEffect)cardEffect).ChangeCardNamesForDigiXros(cardNames_DigiXros, this));
- #endregion
- return cardNames_DigiXros;
- }
- }
- #endregion
- #region preferered frame to play
- public FieldCardFrame PreferredFrame()
- {
- FieldCardFrame PreferredFrame = Owner.fieldCardFrames[0];
- List<FieldCardFrame> fieldCardFrames =
- Owner.fieldCardFrames
- .Filter(fieldCardFrame => fieldCardFrame.IsBattleAreaFrame()
- && fieldCardFrame.IsEmptyFrame());
- if (_cEntity_Base != null)
- {
- if (IsDigimon || IsDigiEgg)
- {
- if (Owner.isYou)
- {
- fieldCardFrames = fieldCardFrames
- .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
- .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
- .ThenBy(value => value.Frame.transform.parent.localPosition.x)
- .ToList();
- }
- else
- {
- fieldCardFrames = fieldCardFrames
- .OrderBy(value => value.Frame.transform.parent.localPosition.y)
- .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
- .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
- .ToList();
- int[] correctOrder = new int[] { 4, 3, 5, 2, 6, 1, 7, 0, 8, 11, 10, 12, 9, 13, 14, 15, };
- List<FieldCardFrame> correctOrderFrames = new List<FieldCardFrame>();
- for (int i = 0; i < correctOrder.Length; i++)
- {
- foreach (FieldCardFrame frame in fieldCardFrames)
- {
- if (frame.FrameID == correctOrder[i])
- {
- correctOrderFrames.Add(frame);
- }
- }
- }
- fieldCardFrames = correctOrderFrames;
- }
- }
- else if (IsTamer || IsOption)
- {
- if (Owner.isYou)
- {
- fieldCardFrames = fieldCardFrames
- .OrderBy(value => value.Frame.transform.parent.localPosition.y)
- .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
- .ThenBy(value => value.Frame.transform.parent.localPosition.x)
- .ToList();
- }
- else
- {
- fieldCardFrames = fieldCardFrames
- .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
- .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
- .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
- .ToList();
- }
- }
- if (fieldCardFrames.Count >= 1)
- {
- PreferredFrame = fieldCardFrames[0];
- }
- }
- return PreferredFrame;
- }
- #endregion
- #region Whether this card has DP
- public bool HasDP => IsDigimon || _cEntity_Base.DP > 0;
- #endregion
- #region base card DP
- public int BaseCardDP => _cEntity_Base.DP;
- #endregion
- #region DP
- public int CardDP
- {
- get
- {
- int cardDP = -1;
- if (HasDP)
- {
- cardDP = BaseCardDP;
- #region card effects that change card DP
- List<ICardEffect> changeCardDPCardEffects = new List<ICardEffect>();
- #region the effects of permanents
- changeCardDPCardEffects = changeCardDPCardEffects
- .Concat(
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
- && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
- .ToList();
- #endregion
- #region the effects of players
- changeCardDPCardEffects = changeCardDPCardEffects
- .Concat(
- GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
- && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
- .ToList();
- #endregion
- List<ICardEffect> cardEffects_ChangeDP_IsUpDown = changeCardDPCardEffects
- .Filter(cardEffect => ((IChangeCardDPEffect)cardEffect).IsUpDown());
- List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = changeCardDPCardEffects
- .Filter(cardEffect => !((IChangeCardDPEffect)cardEffect).IsUpDown());
- cardEffects_ChangeDP_IsUpDown
- .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
- cardEffects_ChangeDP_NotIsUpDown
- .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
- #endregion
- }
- return Math.Max(0, cardDP);
- }
- }
- #endregion
- #region whether this card is token
- public bool IsToken { get; private set; } = false;
- public void SetIsToken(bool isToken) => IsToken = isToken;
- #endregion
- #region whether this card can not be trashed from digivolution cards
- public bool CanNotTrashFromDigivolutionCards(ICardEffect _cardEffect)
- {
- #region the effects of permanents
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.GetFieldPermanents())
- .Flat()
- .Map(permanent => permanent.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
- && cardEffect.CanUse(null)
- && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
- {
- return true;
- }
- #endregion
- #region the effects of players
- if (GManager.instance.turnStateMachine.gameContext.Players
- .Map(player => player.EffectList(EffectTiming.None))
- .Flat()
- .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
- && cardEffect.CanUse(null)
- && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
- {
- return true;
- }
- #endregion
- #region the effects of itself
- if (PermanentOfThisCard() == null)
- {
- if (EffectList(EffectTiming.None)
- .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
- && cardEffect.CanUse(null)
- && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
- {
- return true;
- }
- }
- #endregion
- return false;
- }
- #endregion
- #region whether this card has [Fortitude]
- public bool HasBlocker =>
- EffectList(EffectTiming.None)
- .Some(cardEffect => cardEffect is BlockerClass
- && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect);
- #endregion
- #region whether this card has [DigiBurst]
- public bool HasDigiBurst
- {
- get
- {
- if (_cEntity_Base != null)
- {
- if (!string.IsNullOrEmpty(_cEntity_Base.EffectDiscription_JPN))
- {
- bool result = Regex.IsMatch(_cEntity_Base.EffectDiscription_JPN, DataBase.DigiburstRegex);
- if (result)
- {
- return true;
- }
- }
- }
- return false;
- }
- }
- #endregion
- #region whether this card has [DigiXros]
- public bool HasDigiXros => digiXrosCondition != null;
- #endregion
- #region traits
- public List<string> CardTraits
- {
- get
- {
- List<string> traits =
- _cEntity_Base.Form_ENG
- .Filter(s => !string.IsNullOrEmpty(s))
- .Concat(_cEntity_Base.Attribute_ENG
- .Filter(s => !string.IsNullOrEmpty(s)))
- .Concat(_cEntity_Base.Type_ENG
- .Filter(s => !string.IsNullOrEmpty(s)))
- .ToList();
- #region the effects of itself
- EffectList(EffectTiming.None)
- .Filter(cardEffect => cardEffect is IChangeTraitsEffect && cardEffect.CanUse(null))
- .ForEach(cardEffect => traits = ((IChangeTraitsEffect)cardEffect).ChangTraits(traits, this));
- #endregion
- return traits;
- }
- }
- #endregion
- #region whether this card has [On Deletion] effect
- public bool HasOnDeletionEffect =>
- EffectList(EffectTiming.OnDestroyedAnyone)
- .Some(cardEffect => cardEffect is ActivateICardEffect
- && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
- && cardEffect.IsOnDeletion);
- #endregion
- #region whether this card has [On Play] effect
- public bool HasOnPlayEffect =>
- EffectList(EffectTiming.OnEnterFieldAnyone)
- .Some(cardEffect => cardEffect is ActivateICardEffect
- && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
- && cardEffect.IsOnPlay);
- #endregion
- #region whether this card has [Digisorption]
- public bool HasDigisorption =>
- EffectList(EffectTiming.BeforePayCost)
- .Some(cardEffect => cardEffect is ActivateICardEffect
- && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
- && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
- && cardEffect.EffectDiscription.Contains("Digisorption -"));
- #endregion
- #region whether this card has [Blitz]
- public bool HasBlitz =>
- EffectList(EffectTiming.OnEnterFieldAnyone)
- .Some(cardEffect => cardEffect is ActivateICardEffect
- && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
- && (cardEffect.CanTrigger(CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(this)) || cardEffect.CanTrigger(CardEffectCommons.OnPlayCheckHashtableOfCard(this)))
- && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
- && cardEffect.EffectDiscription.Contains("Blitz"));
- #endregion
- #region whether this card has [Retaliation]
- public bool HasRetaliation =>
- EffectList(EffectTiming.OnDestroyedAnyone)
- .Some(cardEffect => cardEffect is ActivateICardEffect
- && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
- && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
- && cardEffect.EffectName == "Retaliation");
- #endregion
- #region whether this card has [Fortitude]
- public bool HasFortitude =>
- EffectList(EffectTiming.OnDestroyedAnyone)
- .Some(cardEffect => cardEffect is ActivateICardEffect
- && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
- && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
- && cardEffect.EffectName == "Fortitude");
- #endregion
- #region whether this card has inherited effect
- public bool HasInheritedEffect
- {
- get
- {
- foreach (EffectTiming timing in Enum.GetValues(typeof(EffectTiming)))
- {
- if (EffectList(timing)
- .Some(cardEffect => cardEffect.IsInheritedEffect
- && !cardEffect.IsDisabled))
- {
- return true;
- }
- }
- return false;
- }
- }
- #endregion
- #region DNA digivolution requirement
- public JogressCondition jogressCondition
- {
- get
- {
- ICardEffect addJogressConditionEffect =
- EffectList(EffectTiming.None)
- .Find(cardEffect => cardEffect is IAddJogressConditionEffect
- && cardEffect.CanUse(null)
- && ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this) != null);
- if (addJogressConditionEffect != null) return ((IAddJogressConditionEffect)addJogressConditionEffect).GetJogressCondition(this);
- return null;
- }
- }
- #endregion
- #region whether this card can DNA digivolve
- public bool CanPlayJogress(bool PayCost)
- {
- if (jogressCondition != null)
- {
- if (Owner.GetBattleAreaDigimons().Count >= jogressCondition.elements.Length)
- {
- List<Permanent[]> permanentsList = ParameterComparer.Enumerate(Owner.GetBattleAreaDigimons(), jogressCondition.elements.Length).ToList();
- foreach (Permanent[] permanents in permanentsList)
- {
- if (permanents != null)
- {
- if (permanents.Length == jogressCondition.elements.Length)
- {
- if (permanents.Length == 2)
- {
- if (jogressCondition.elements[0].EvoRootCondition(permanents[0]) && !this.CanNotEvolve(permanents[0]))
- {
- if (jogressCondition.elements[1].EvoRootCondition(permanents[1]) && !this.CanNotEvolve(permanents[1]))
- {
- if (PayCost)
- {
- int cost = jogressCondition.cost;
- cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, permanents.ToList(), checkAvailability: true);
- if (Owner.MaxMemoryCost < cost)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region whether target permanent can DNA digivolve into this card
- public bool CanJogressFromTargetPermanent(Permanent targetPermanent, bool PayCost)
- {
- if (targetPermanent != null)
- {
- if (targetPermanent.TopCard != null)
- {
- if (targetPermanent.TopCard.Owner.GetBattleAreaDigimons().Contains(targetPermanent))
- {
- if (this.CanPlayJogress(PayCost))
- {
- if (jogressCondition != null)
- {
- if (jogressCondition.elements.ToList().Count((element) => element.EvoRootCondition(targetPermanent)) >= 1)
- {
- if (!this.CanNotEvolve(targetPermanent))
- {
- if (PayCost)
- {
- int cost = jogressCondition.cost;
- cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent, new Permanent(new List<CardSource>()) }, checkAvailability: true);
- if (Owner.MaxMemoryCost < cost)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region whether target permanents can DNA digivolve into this card
- public bool CanJogressFromTargetPermanents(List<Permanent> targetPermanents, bool PayCost)
- {
- if (targetPermanents != null)
- {
- if (targetPermanents.Count == 2)
- {
- if (this.CanPlayJogress(PayCost))
- {
- if (jogressCondition != null)
- {
- List<Permanent[]> permanentsList = ParameterComparer.Enumerate(targetPermanents, 2).ToList();
- foreach (Permanent[] permanents in permanentsList)
- {
- if (jogressCondition.elements.Length == permanents.Length)
- {
- bool canJogress = true;
- for (int i = 0; i < permanents.Length; i++)
- {
- if (permanents[i] != null)
- {
- if (permanents[i].TopCard != null)
- {
- if ((!jogressCondition.elements[i].EvoRootCondition(permanents[i])) || this.CanNotEvolve(permanents[i]))
- {
- canJogress = false;
- break;
- }
- }
- }
- }
- if (canJogress)
- {
- return true;
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region whether this card has level
- public bool HasLevel => _cEntity_Base == null || _cEntity_Base.HasLevel;
- #endregion
- #region DigiXros requirement
- public DigiXrosCondition digiXrosCondition
- {
- get
- {
- foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
- {
- if (cardEffect is IAddDigiXrosConditionEffect)
- {
- if (cardEffect.CanUse(null))
- {
- DigiXrosCondition digiXrosCondition = ((IAddDigiXrosConditionEffect)cardEffect).GetDigiXrosCondition(this);
- if (digiXrosCondition != null)
- {
- return digiXrosCondition;
- }
- }
- }
- }
- return null;
- }
- }
- #endregion
- #region Blast Digivolution requirement
- public BurstDigivolutionCondition burstDigivolutionCondition
- {
- get
- {
- foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
- {
- if (cardEffect is IAddBurstDigivolutionConditionEffect)
- {
- if (cardEffect.CanUse(null))
- {
- BurstDigivolutionCondition burstDigivolutionCondition = ((IAddBurstDigivolutionConditionEffect)cardEffect).GetBurstDigivolutionCondition(this);
- if (burstDigivolutionCondition != null)
- {
- return burstDigivolutionCondition;
- }
- }
- }
- }
- return null;
- }
- }
- #endregion
- #region whether this card can Burst digivolve
- public bool CanPlayBurst(bool PayCost)
- {
- if (burstDigivolutionCondition != null)
- {
- if (PayCost)
- {
- int cost = burstDigivolutionCondition.cost;
- cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { new Permanent(new List<CardSource>()) }, checkAvailability: true);
- if (Owner.MaxMemoryCost < cost)
- {
- return false;
- }
- }
- if (Owner.GetBattleAreaDigimons().Count >= 1)
- {
- foreach (Permanent digimon in Owner.GetFieldPermanents())
- {
- if (digimon != null)
- {
- if (!this.CanNotEvolve(digimon))
- {
- if (burstDigivolutionCondition.digimonCondition(digimon))
- {
- foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
- {
- if (tamer != digimon)
- {
- if (burstDigivolutionCondition.tamerCondition(tamer))
- {
- if (!tamer.CannotReturnToHand(null))
- {
- if (PayCost)
- {
- int cost = burstDigivolutionCondition.cost;
- cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { digimon }, checkAvailability: true);
- if (Owner.MaxMemoryCost < cost)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region whether target permanent can Burst digivolve into this card
- public bool CanBurstDigivolutionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
- {
- if (targetPermanent != null)
- {
- if (targetPermanent.TopCard != null)
- {
- if (targetPermanent.TopCard.Owner.GetFieldPermanents().Contains(targetPermanent))
- {
- if (this.CanPlayBurst(PayCost))
- {
- if (burstDigivolutionCondition != null)
- {
- if (!this.CanNotEvolve(targetPermanent))
- {
- if (burstDigivolutionCondition.digimonCondition(targetPermanent))
- {
- foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
- {
- if (tamer != targetPermanent)
- {
- if (burstDigivolutionCondition.tamerCondition(tamer))
- {
- if (!tamer.CannotReturnToHand(null))
- {
- if (PayCost)
- {
- int cost = burstDigivolutionCondition.cost;
- cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
- if (Owner.MaxMemoryCost < cost)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region Whether this card's digiXrosCondition contains target card
- public bool IsContainDigiXrosCondition(CardSource cardSource)
- {
- if (cardSource != null)
- {
- if (cardSource.Owner == Owner)
- {
- if (PermanentOfThisCard() != null)
- {
- if (PermanentOfThisCard().TopCard.HasDigiXros)
- {
- if (this == PermanentOfThisCard().TopCard)
- {
- if (digiXrosCondition != null)
- {
- if (digiXrosCondition.elements.Count((element) => element.CardCondition(cardSource)) >= 1)
- {
- return true;
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region CardID
- public string CardID => _cEntity_Base.CardID;
- #endregion
- #region whether this card is Digimon
- public bool IsDigimon => CardKind == CardKind.Digimon;
- #endregion
- #region whether this card is DigiEgg
- public bool IsDigiEgg => CardKind == CardKind.DigiEgg;
- #endregion
- #region whether this card is Tamer
- public bool IsTamer => CardKind == CardKind.Tamer;
- #endregion
- #region whether this card is Option
- public bool IsOption => CardKind == CardKind.Option;
- #endregion
- #region Wheter this card is permanent
- public bool IsPermanent => _cEntity_Base.IsPermanent;
- #endregion
- #region Whether to have Play Cost
- public bool HasPlayCost => _cEntity_Base.HasPlayCost;
- #endregion
- #region Whether to have Use Cost
- public bool HasUseCost => _cEntity_Base.HasUseCost;
- #endregion
- #region Inherited Effects ENG discription
- public string InheritedEffectDiscription_ENG => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG);
- #endregion
- #region Inherited Effects JPN discription
- public string InheritedEffectDiscription_JPN => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_JPN);
- #endregion
- #region Card Sprite
- public Sprite CardSprite => _cEntity_Base.CardSprite;
- public async Task<Sprite> GetCardSprite()
- {
- return await _cEntity_Base.GetCardSprite();
- }
- #endregion
- #region SetID
- public string SetID => _cEntity_Base.SetID;
- #endregion
- #region CardEntityIndex
- public int CardEntityIndex => _cEntity_Base.CardIndex;
- #endregion
- #region Card Kind
- public CardKind CardKind => _cEntity_Base.cardKind;
- #endregion
- #region ACE
- public bool IsACE => _cEntity_Base.IsACE;
- #endregion
- #region OverflowMemory
- public int OverflowMemory => _cEntity_Base.OverflowMemory;
- #endregion
- #region Whether this card is being revealed
- public bool IsBeingRevealed { get; set; } = false;
- #endregion
- #region The permanent that belonged to this card just before it left the field
- public Permanent PermanentJustBeforeRemoveField { get; set; } = null;
- #endregion
- }
- public class JogressCondition
- {
- public JogressCondition(JogressConditionElement[] elements, int cost)
- {
- this.elements = new JogressConditionElement[2];
- if (this.elements.Length == elements.Length)
- {
- for (int i = 0; i < elements.Length; i++)
- {
- this.elements[i] = elements[i];
- }
- }
- this.cost = cost;
- }
- public JogressConditionElement[] elements { get; private set; } = new JogressConditionElement[2];
- public int cost { get; private set; } = 0;
- }
- public class JogressConditionElement
- {
- public JogressConditionElement(Func<Permanent, bool> evoRootCondition, string selectMessage)
- {
- EvoRootCondition = evoRootCondition;
- SelectMessage = selectMessage;
- }
- Func<Permanent, bool> _evoRootCondition = null;
- public Func<Permanent, bool> EvoRootCondition
- {
- get
- {
- return permanent => _evoRootCondition == null || _evoRootCondition(permanent);
- }
- private set
- {
- _evoRootCondition = value;
- }
- }
- public string SelectMessage { get; private set; } = "";
- }
- public class DigiXrosCondition
- {
- public DigiXrosCondition(List<DigiXrosConditionElement> elements, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, int reduceCostPerCard)
- {
- this.elements = new List<DigiXrosConditionElement>();
- foreach (DigiXrosConditionElement element in elements)
- {
- this.elements.Add(element);
- }
- this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
- this.reduceCostPerCard = reduceCostPerCard;
- }
- public List<DigiXrosConditionElement> elements { get; private set; } = new List<DigiXrosConditionElement>();
- public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
- public int reduceCostPerCard { get; private set; } = 0;
- }
- public class DigiXrosConditionElement
- {
- public DigiXrosConditionElement(Func<CardSource, bool> cardCondition, string selectMessage, bool skipAllIfNoSelect = false)
- {
- this.CardCondition = cardCondition;
- this.selectMessage = selectMessage;
- this.skipAllIfNoSelect = skipAllIfNoSelect;
- }
- public Func<CardSource, bool> CardCondition { get; private set; } = null;
- public string selectMessage { get; private set; } = "";
- public bool skipAllIfNoSelect { get; private set; } = false;
- }
- public class BurstDigivolutionCondition
- {
- public BurstDigivolutionCondition(Func<Permanent, bool> tamerCondition, string selectTamerMessage, Func<Permanent, bool> digimonCondition, string selectDigimonMessage, int cost)
- {
- this.tamerCondition = tamerCondition;
- this.selectTamerMessage = selectTamerMessage;
- this.digimonCondition = digimonCondition;
- this.selectDigimonMessage = selectDigimonMessage;
- this.cost = cost;
- }
- public Func<Permanent, bool> tamerCondition { get; private set; } = null;
- public string selectTamerMessage { get; private set; } = null;
- public Func<Permanent, bool> digimonCondition { get; private set; } = null;
- public string selectDigimonMessage { get; private set; } = null;
- public int cost { get; private set; } = 0;
- }
|