IsMaxCost.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. public partial class CardEffectCommons
  4. {
  5. public static bool IsMaxCost(Permanent permanent, Player owner, bool IsDigimonOnly)
  6. {
  7. if (permanent == null) return false;
  8. if (permanent.TopCard == null) return false;
  9. if (permanent.TopCard.Owner != owner) return false;
  10. if (!IsPermanentExistsOnOwnerBattleArea(permanent, permanent.TopCard)) return false;
  11. if (!permanent.IsDigimon && !permanent.IsTamer) return false;
  12. if (!permanent.TopCard.HasPlayCost) return false;
  13. if (IsDigimonOnly)
  14. {
  15. if (!permanent.IsDigimon) return false;
  16. var costs = permanent.TopCard.Owner.GetBattleAreaDigimons()
  17. .Filter(x => x.TopCard.HasPlayCost)
  18. .Select(x => x.TopCard.GetCostItself).ToList();
  19. return costs.Count >= 1 && permanent.TopCard.GetCostItself == costs.Max();
  20. }
  21. else
  22. {
  23. var costs = permanent.TopCard.Owner.GetBattleAreaPermanents()
  24. .Filter(x => (x.IsDigimon || x.IsTamer) && x.TopCard.HasPlayCost)
  25. .Select(x => x.TopCard.GetCostItself).ToList();
  26. return costs.Count >= 1 && permanent.TopCard.GetCostItself == costs.Max();
  27. }
  28. }
  29. public static List<Permanent> GetNonMaxCostPermanents(Player owner, bool digimonOnly = true)
  30. {
  31. var candidates = digimonOnly
  32. ? owner.GetBattleAreaDigimons()
  33. : owner.GetBattleAreaPermanents().Where(p => p.IsDigimon || p.IsTamer);
  34. var list = candidates
  35. .Where(x => x.TopCard != null && x.TopCard.HasPlayCost)
  36. .ToList();
  37. if (list.Count == 0) return new List<Permanent>();
  38. var maxCost = list.Max(p => p.TopCard.GetCostItself);
  39. return list
  40. .Where(p => p.TopCard.GetCostItself < maxCost)
  41. .ToList();
  42. }
  43. }