using System;
using System.Collections.Generic;
public partial class CardEffectFactory
{
///
/// Effect to copy through the effects of digivolution cards as effect of the top card. Done directly in CEntity_Effect.CardEffects for efficiency
///
/// Reference to the list of effects for this card to add effects to
/// timing being queried
/// Card with the copy effect
/// Condition to use this effect (Current turn, This digimon with X trait, etc.)
/// Condition of the cards to copy from (gammamon in name, MachineDramon or Chaosdramon, etc.)
/// Conditions on the effects to copy (Only On Plays, only activate effects, etc.)
public static void CopyDigivolutionCardEffects(ref List cardEffects,
EffectTiming timing,
CardSource card,
bool isInheritedEffect = false,
bool isLinkedEffect = false,
Func canUseCondition = null,
Func cardCondition = null,
Func effectCondition = null
)
{
if (card.PermanentOfThisCard() == null) return;
if (canUseCondition != null && !canUseCondition()) return;
Permanent thisPermanent = card.PermanentOfThisCard();
//If it is an inherited effect it should be in digivolution cards, if link effect should be linked, if neither it should not be in either (leaving only topcard)
if (isInheritedEffect != thisPermanent.DigivolutionCards.Contains(card)) return;
if (isLinkedEffect != thisPermanent.LinkedCards.Contains(card)) return;
List validSources = thisPermanent.DigivolutionCards.Filter(cardSource => cardSource != card && (cardCondition == null || cardCondition(cardSource)));
foreach (CardSource cardSource in validSources)
{
List toCopyEffects = cardSource.EffectList(timing);
int i = 0;
foreach (ICardEffect cardEffect in toCopyEffects)
{
if (cardEffect.IsInheritedEffect || cardEffect.IsLinkedEffect) continue;
if (cardEffect is ActivateClass)
{
ActivateClass activateClass = (ActivateClass)cardEffect;
activateClass.SetHashString(GenerateHashString(card, cardSource, i));//Set unique hashstring so OPTs work correctly
cardEffects.Add(activateClass);
cardEffects.Add(PermanentEffectFactory.AddDetailClass(thisPermanent, activateClass.EffectDiscription, true, activateClass));
}
else//If any other effect types need their can use condition changed to work correctly those can be handled here, otherwise just copied through
{
cardEffects.Add(cardEffect);
}
}
}
}
private static string GenerateHashString(CardSource card, CardSource cardSource, int i) => $"Card-{card.CardIndex}-Copying-Card-{cardSource.CardIndex}-effect-{i}";
}