CopiedEffects.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. public partial class CardEffectFactory
  4. {
  5. /// <summary>
  6. /// Effect to copy through the effects of digivolution cards as effect of the top card. Done directly in CEntity_Effect.CardEffects for efficiency
  7. /// </summary>
  8. /// <param name="cardEffects">Reference to the list of effects for this card to add effects to</param>
  9. /// <param name="timing">timing being queried</param>
  10. /// <param name="card">Card with the copy effect</param>
  11. /// <param name="canUseCondition">Condition to use this effect (Current turn, This digimon with X trait, etc.)</param>
  12. /// <param name="cardCondition">Condition of the cards to copy from (gammamon in name, MachineDramon or Chaosdramon, etc.)</param>
  13. /// <param name="effectCondition">Conditions on the effects to copy (Only On Plays, only activate effects, etc.)</param>
  14. public static void CopyDigivolutionCardEffects(ref List<ICardEffect> cardEffects,
  15. EffectTiming timing,
  16. CardSource card,
  17. bool isInheritedEffect = false,
  18. bool isLinkedEffect = false,
  19. Func<bool> canUseCondition = null,
  20. Func<CardSource, bool> cardCondition = null,
  21. Func<ICardEffect, bool> effectCondition = null
  22. )
  23. {
  24. if (card.PermanentOfThisCard() == null) return;
  25. if (canUseCondition != null && !canUseCondition()) return;
  26. Permanent thisPermanent = card.PermanentOfThisCard();
  27. //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)
  28. if (isInheritedEffect != thisPermanent.DigivolutionCards.Contains(card)) return;
  29. if (isLinkedEffect != thisPermanent.LinkedCards.Contains(card)) return;
  30. List<CardSource> validSources = thisPermanent.DigivolutionCards.Filter(cardSource => cardSource != card && (cardCondition == null || cardCondition(cardSource)));
  31. foreach (CardSource cardSource in validSources)
  32. {
  33. List<ICardEffect> toCopyEffects = cardSource.EffectList(timing);
  34. int i = 0;
  35. foreach (ICardEffect cardEffect in toCopyEffects)
  36. {
  37. if (cardEffect.IsInheritedEffect || cardEffect.IsLinkedEffect) continue;
  38. if (cardEffect is ActivateClass)
  39. {
  40. ActivateClass activateClass = (ActivateClass)cardEffect;
  41. activateClass.SetHashString(GenerateHashString(card, cardSource, i));//Set unique hashstring so OPTs work correctly
  42. cardEffects.Add(activateClass);
  43. cardEffects.Add(PermanentEffectFactory.AddDetailClass(thisPermanent, activateClass.EffectDiscription, true, activateClass));
  44. }
  45. else//If any other effect types need their can use condition changed to work correctly those can be handled here, otherwise just copied through
  46. {
  47. cardEffects.Add(cardEffect);
  48. }
  49. }
  50. }
  51. }
  52. private static string GenerateHashString(CardSource card, CardSource cardSource, int i) => $"Card-{card.CardIndex}-Copying-Card-{cardSource.CardIndex}-effect-{i}";
  53. }