| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using System.Linq;
- using UnityEngine;
- public class PartitionCondition
- {
- public int Level;
- public CardColor Color;
- public CardColor Color2;
- public bool hasTwoColor = false;
- public PartitionCondition(int level, CardColor color)
- {
- Level = level;
- Color = color;
- }
- public PartitionCondition(int level, CardColor color, CardColor color2)
- {
- Level = level;
- Color = color;
- Color2 = color2;
- hasTwoColor = true;
- }
- /*
- public bool ContainsAll(List<CardColor> sourceColors)
- {
- foreach(CardColor cardColor in Color)
- {
- if(!sourceColors.Contains(cardColor))
- return false;
- }
- return false;
- }
- */
- }
- public partial class CardEffectFactory
- {
- #region Trigger effect of [Partition] on oneself
- public static ActivateClass PartitionSelfEffect(bool isInheritedEffect, CardSource card, Func<bool> condition, List<PartitionCondition> cardSourceConditions)
- {
- Permanent targetPermanent = card.PermanentOfThisCard();
-
- bool CanUseCondition()
- {
- if (condition == null || condition())
- {
- return true;
- }
- return false;
- }
- return PartitionEffect(targetPermanent: targetPermanent, isInheritedEffect: isInheritedEffect, condition: CanUseCondition, partitionConditions: cardSourceConditions, card);
- }
- #endregion
- #region Trigger effect of [Partition]
- public static ActivateClass PartitionEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition, List<PartitionCondition> partitionConditions, CardSource card)
- {
- if (targetPermanent == null) return null;
- if (targetPermanent.TopCard == null) return null;
- if (card == null) return null;
- if (partitionConditions[0].hasTwoColor == false || partitionConditions[1].hasTwoColor == false)
- {
- List<CardSource> sourceOneCard = targetPermanent.cardSources
- .Clone()
- .Filter(source =>
- source.CardColors.Contains(partitionConditions[0].Color)
- && (source.HasLevel && source.Level == partitionConditions[0].Level));
- List<CardSource> sourceTwoCard = targetPermanent.cardSources
- .Clone()
- .Filter(source =>
- source.CardColors.Contains(partitionConditions[1].Color)
- && (source.HasLevel && source.Level == partitionConditions[1].Level));
- ActivateClass activateClass = new ActivateClass();
- activateClass.SetUpICardEffect("Partition", CanUseCondition, card);
- activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
- activateClass.SetHashString($"Partition_{card.CardID}" + (isInheritedEffect ? "_inherited" : ""));
- activateClass.SetIsInheritedEffect(isInheritedEffect);
- string EffectDiscription()
- {
- return DataBase.PartitionEffectDiscription();
- }
- bool CanUseCondition(Hashtable hashtable)
- {
- if (CardEffectCommons.CanTriggerPartition(hashtable, card))
- {
- if (condition == null || condition())
- {
- return true;
- }
- }
- return false;
- }
- bool CanActivateCondition(Hashtable hashtable)
- {
- if (CardEffectCommons.CanActivatePartition(targetPermanent))
- {
- if (sourceOneCard == null || sourceOneCard.Count > 0)
- {
- if (sourceTwoCard == null || sourceTwoCard.Count > 0)
- {
- return true;
- }
- }
- }
- return false;
- }
- IEnumerator ActivateCoroutine(Hashtable _hashtable)
- {
- if (sourceOneCard.Count == 1)
- sourceTwoCard = sourceTwoCard.Except(sourceOneCard).ToList();
- if (sourceTwoCard.Count == 1)
- sourceOneCard = sourceOneCard.Except(sourceTwoCard).ToList();
- return CardEffectCommons.PartitionProcess(activateClass, targetPermanent, sourceOneCard, sourceTwoCard);
- }
- return activateClass;
- }
- else
- {
- List<CardSource> sourceOneCard = targetPermanent.cardSources
- .Clone()
- .Filter(source =>
- source.CardColors.Contains(partitionConditions[0].Color) || source.CardColors.Contains(partitionConditions[0].Color2)
- && (source.HasLevel && source.Level == partitionConditions[0].Level));
- List<CardSource> sourceTwoCard = targetPermanent.cardSources
- .Clone()
- .Filter(source =>
- source.CardColors.Contains(partitionConditions[1].Color) || source.CardColors.Contains(partitionConditions[1].Color2)
- && (source.HasLevel && source.Level == partitionConditions[1].Level));
- ActivateClass activateClass = new ActivateClass();
- activateClass.SetUpICardEffect("Partition", CanUseCondition, card);
- activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
- activateClass.SetHashString($"Partition_{card.CardID}" + (isInheritedEffect ? "_inherited" : ""));
- activateClass.SetIsInheritedEffect(isInheritedEffect);
- string EffectDiscription()
- {
- return DataBase.PartitionEffectDiscription();
- }
- bool CanUseCondition(Hashtable hashtable)
- {
- if (CardEffectCommons.CanTriggerPartition(hashtable, card))
- {
- if (condition == null || condition())
- {
- return true;
- }
- }
- return false;
- }
- bool CanActivateCondition(Hashtable hashtable)
- {
- if (CardEffectCommons.CanActivatePartition(targetPermanent))
- {
- if (sourceOneCard == null || sourceOneCard.Count > 0)
- {
- if (sourceTwoCard == null || sourceTwoCard.Count > 0)
- {
- return true;
- }
- }
- }
- return false;
- }
- IEnumerator ActivateCoroutine(Hashtable _hashtable)
- {
- if (sourceOneCard.Count == 1)
- sourceTwoCard = sourceTwoCard.Except(sourceOneCard).ToList();
- if (sourceTwoCard.Count == 1)
- sourceOneCard = sourceOneCard.Except(sourceTwoCard).ToList();
- return CardEffectCommons.PartitionProcess(activateClass, targetPermanent, sourceOneCard, sourceTwoCard);
- }
- return activateClass;
- }
- }
- #endregion
- }
|