public static ShardColor GetColor(string castingCost) { return(Shard.GetShards(castingCost).Select(shard => shard.Color) .Aggregate(ShardColor.Colorless, (current, newColor) => current | newColor)); }
public static int GetConvertedCastCost(string castingCost) { return(Shard.GetShards(castingCost).Sum(shard => shard.ConvertedCastingCost)); }
private static Shard GetShard(string shardCastingCost) { if (_shards.TryGetValue(shardCastingCost, out Shard shard)) { return(shard); } if (int.TryParse(shardCastingCost, out int _)) { //IsGeneric shard = new Shard(shardCastingCost, true, false, false, false); _shards.Add(shardCastingCost, shard); return(shard); } if (shardCastingCost == Snow) { //IsSnow shard = new Shard(shardCastingCost, false, true, false, false); _shards.Add(shardCastingCost, shard); return(shard); } if (shardCastingCost == Colorless) { //IsColorless shard = new Shard(shardCastingCost, false, false, true, false); _shards.Add(shardCastingCost, shard); return(shard); } if (Generics.Contains(shardCastingCost)) { //IsXYZ => IsGeneric shard = new Shard(shardCastingCost, true, false, false, true); _shards.Add(shardCastingCost, shard); return(shard); } string workingShardCastingCost = shardCastingCost; ShardColor color = ShardColor.Colorless; bool isPhyrexian = false; bool isHybrid = false; bool is2Hybrid = false; bool isHalf = false; if (workingShardCastingCost.StartsWith(Half)) { isHalf = true; workingShardCastingCost = workingShardCastingCost.Substring(Half.Length); } if (workingShardCastingCost.EndsWith(Phyrexian)) { isPhyrexian = true; workingShardCastingCost = workingShardCastingCost.Substring(0, workingShardCastingCost.Length - Phyrexian.Length); } if (workingShardCastingCost.StartsWith(TwoHybrid)) { is2Hybrid = true; workingShardCastingCost = workingShardCastingCost.Substring(TwoHybrid.Length); } if (workingShardCastingCost.Length == 0) { throw new Exception($"length of workingShardCastingCost is 0 after removing additional info : {shardCastingCost}"); } foreach (char c in workingShardCastingCost) { isHybrid = color != ShardColor.Colorless; switch (c) { case White: color |= ShardColor.White; break; case Blue: color |= ShardColor.Blue; break; case Black: color |= ShardColor.Black; break; case Red: color |= ShardColor.Red; break; case Green: color |= ShardColor.Green; break; default: throw new Exception($"Unknown element in shard cast cost {shardCastingCost}: {c}"); } } shard = new Shard(shardCastingCost, color, isPhyrexian, isHybrid, is2Hybrid, isHalf); _shards.Add(shardCastingCost, shard); return(shard); }