public virtual bool Contains(Cost c) { Costs cst = this as Costs; if (cst != null) { foreach (Cost cc in cst.CostList) { if (cc.Contains(c)) { return(true); } } return(false); } ManaChoice mc = this as ManaChoice; if (mc != null) { foreach (Mana i in mc.Manas) { if (i.Contains(c)) { return(true); } } return(false); } Mana m = this as Mana; if (m != null) { Mana cm = c as Mana; if (cm == null) { return(false); } if ((cm.TypeOfMana == m.TypeOfMana || (cm.TypeOfMana == ManaTypes.Colorless && m.TypeOfMana <= ManaTypes.Colorless) || (m.TypeOfMana == ManaTypes.Colorless && cm.TypeOfMana <= ManaTypes.Colorless)) && m.count >= cm.count) { return(true); } else { return(false); } } return(this == c ? true : false); }
public static bool IsNullOrCountIsZero(Cost c) { if (c == null) { return(true); } Mana m = c as Mana; if (m == null) { return(false); } return(m.count == 0); }
public override bool IsSameType(Mana m) { ManaChoice choice = m as ManaChoice; if (choice == null) { return(false); } if (choice.Manas.Count != Manas.Count) { return(false); } for (int i = 0; i < Manas.Count; i++) { if (!choice.Manas[i].IsSameType(Manas[i])) { return(false); } } return(true); }
public virtual bool IsSameType(Mana m) { return(m == null ? false : m.TypeOfMana == TypeOfMana && TypeOfMana != ManaTypes.Composite && count > 0 && m.count > 0 ? true : false); }
public override Cost Pay(ref Cost c) { if (c == null) { return(this); } c.OrderFirst(this.GetDominantMana()); Costs cl = c as Costs; if (cl != null) { Cost tmp = this.Clone(); for (int i = 0; i < cl.CostList.Count; i++) { Cost cli = cl.CostList [i]; tmp = tmp.Pay(ref cli); if (cli == null) { cl.CostList.RemoveAt(i); i--; } if (tmp == null) { break; } } if (cl.CostList.Count == 0) { c = null; } return(tmp); } Mana m = c as Mana; if (m == null) { return(this); } if (m is ManaChoice) { ManaChoice mc = m.Clone() as ManaChoice; for (int i = 0; i < mc.Manas.Count; i++) { Cost result = this.Clone(); Cost tmp = mc.Manas[i]; result = result.Pay(ref tmp); if (tmp == null) { c = null; } if (result == null) { return(null); } } } else { if (TypeOfMana == m.TypeOfMana || TypeOfMana == ManaTypes.Colorless) { count -= m.count; if (count == 0) { c = null; return(null); } else if (count < 0) { m.count = -count; return(null); } else { c = null; return(this); } } } return(this); }
public static MagicCard LoadCardData(Stream s) { MagicCard c = new MagicCard(); using (StreamReader sr = new StreamReader(s)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] tmp = line.Split(new char[] { ':' }); switch (tmp[0].ToLower()) { case "name": c.Name = tmp [1]; break; case "manacost": c.Cost = Mana.Parse(tmp[1]); break; case "types": string[] types = tmp[1].Split(new char[] { ' ' }); foreach (string t in types) { if (string.IsNullOrEmpty(t)) { continue; } string tt = t.Replace('\'', '_'); tt = tt.Replace('-', '_'); c.Types += (CardTypes)Enum.Parse(typeof(CardTypes), tt, true); } break; case "a": c.Abilities.Add(Ability.Parse(tmp[1])); break; case "oracle": c.Oracle = string.Join("\n", tmp.ToList().GetRange(1, tmp.Length - 1).ToArray()); break; case "pt": string[] pt = tmp[1].Split(new char[] { '/' }); int intPT; if (int.TryParse(pt[0], out intPT)) { c.Power = intPT; } else { Debug.WriteLine("power:" + pt[0]); } if (int.TryParse(pt[1], out intPT)) { c.Toughness = intPT; } else { Debug.WriteLine("toughness:" + pt[1]); } break; case "s": // Ability aa = c.Abilities.FirstOrDefault (); // if (aa == null) { // aa = new Ability (); // c.Abilities.Add (aa); // } else // Debugger.Break; c.SpellEffects.Add(EffectGroup.Parse(tmp[1])); break; case "t": c.Triggers.Add(Trigger.Parse(tmp[1])); break; case "svar": if (SVarToResolve.TryToParseAndSetValue(tmp [1], tmp [2])) { break; } switch (tmp[1].ToLower()) { case "darkeffect": break; case "darkpower": break; case "darkmana": break; case "picture": c.picturePath = tmp[3]; break; case "remaideck": break; case "piccount": c.nbrImg = int.Parse(tmp[2]); break; default: Debug.WriteLine("Unknow SVAR: " + tmp[1]); break; } break; case "k": Ability a = Ability.ParseKeyword(tmp[1], c); if (a != null) { c.Abilities.Add(a); } break; case "r": c.R.Add(tmp[1]); break; case "deckneeds": c.DeckNeeds.Add(tmp[1]); break; case "text": c.TextField.Add(tmp[1]); break; case "alternatemode": c.AlternateMode = tmp[1]; break; case "alternate": c.Alternate = true; break; case "colors": c.Colors += (ManaTypes)Enum.Parse(typeof(ManaTypes), tmp[1], true); break; case "loyalty": c.Loyalty = tmp[1]; break; case "handlifemodifier": c.HandLifeModifier = tmp[1]; break; case "deckhints": c.DeckHints = tmp[1]; break; case "var": Debug.WriteLine("var: {0} {1} {2}", c.Name, tmp[1], tmp[2]); break; default: if (tmp[0].StartsWith("#")) { c.Comments.Add(tmp[0]); } else if (!string.IsNullOrEmpty(tmp[0])) { string txt = ""; for (int i = 0; i < tmp.Length; i++) { txt += ":" + tmp[i]; } Debug.WriteLine("? => {0} {1}", c.Name, txt); } break; } } SVarToResolve.UnresolvedSVars.Clear(); } #region add mana ability to basic lands if (c.Types == CardTypes.Land) { if (c.Abilities.Count == 0) { Mana m = null; switch (c.Name.ToLower()) { case "plains": case "snow-covered plains": m = ManaTypes.White; break; case "mountain": case "snow-covered mountain": m = ManaTypes.Red; break; case "swamp": case "snow-covered swamp": m = ManaTypes.Black; break; case "forest": case "snow-covered forest": m = ManaTypes.Green; break; case "island": case "snow-covered island": m = ManaTypes.Blue; break; } if (m != null) { c.Abilities.Add( new Ability(new ManaEffect(m)) { ActivationCost = CostTypes.Tap }); } } } #endregion return(c); }
public static Cost Parse(string costString) { if (costString.ToLower() == "no cost") { return(null); } if (costString.ToLower() == "any") { return(new Mana(ManaTypes.Any)); } if (costString.ToLower() == "combo any") { return(new Mana(ManaTypes.ComboAny)); } Costs sum = new Costs(); string[] tmp = costString.Split(new char[] { }); foreach (string c in tmp) { if (string.IsNullOrWhiteSpace(c)) { continue; } switch (c) { case "T": sum += new Cost(CostTypes.Tap); continue; } if (c.StartsWith("Discard")) { sum += CardCost.Parse(CostTypes.Discard, c); continue; } else if (c.StartsWith("Sac")) { sum += CardCost.Parse(CostTypes.Sacrifice, c); continue; } else if (c.StartsWith("SubCounter")) { sum += CardCost.Parse(CostTypes.SubCounter, c); continue; } string number = ""; ManaChoice choice = new ManaChoice(); for (int i = 0; i < c.Length; i++) { if (char.IsDigit(c[i])) { number += c[i]; if (i < c.Length - 1) { if (char.IsDigit(c[i + 1])) { continue; } } choice += new Mana(int.Parse(number)); number = null; } else { switch (c[i]) { case 'W': choice += ManaTypes.White; break; case 'R': choice += ManaTypes.Red; break; case 'G': choice += ManaTypes.Green; break; case 'B': choice += ManaTypes.Black; break; case 'U': choice += ManaTypes.Blue; break; case 'P': choice += ManaTypes.Life; break; case 'X': choice += new Mana(-1); break; case '/': continue; default: break; } } } if (choice.Manas.Count == 1) { sum += choice.Manas[0]; } else { sum += choice; } } if (sum.CostList.Count == 0) { return(null); } if (sum.CostList.Count == 1) { return(sum.CostList[0]); } else { return(sum); } return(sum); }