public bool check(GameLocation loc) { bool ret = true; if (Children.Count > 0) { if (ChildrenCombine != "and") { ret = false; } int totalMet = 0; foreach (var child in Children) { bool childCheck = child.check(loc); if (childCheck) { ++totalMet; } switch (ChildrenCombine) { case "and": ret = ret && childCheck; break; case "or": ret = ret || childCheck; break; case "xor": ret = ret ^ childCheck; break; } } if (ChildrenCombine.StartsWith("atleast")) { ret = totalMet >= int.Parse(ChildrenCombine.Substring(7)); } else if (ChildrenCombine.StartsWith("exactly")) { ret = totalMet == int.Parse(ChildrenCombine.Substring(7)); } else if (ChildrenCombine != "and" && ChildrenCombine != "or" && ChildrenCombine != "xor") { throw new ArgumentException("Bad ChildrenCombine: " + ChildrenCombine); } } else if (MinTimeOfDay != -1 && Game1.timeOfDay < MinTimeOfDay) { ret = false; } else if (MaxTimeOfDay != -1 && Game1.timeOfDay > MaxTimeOfDay) { ret = false; } else if (Seasons != null && Seasons.Count() > 0 && !Seasons.Contains(Game1.currentSeason)) { ret = false; } else if (Locations != null && Locations.Count() > 0 && !Locations.Contains(loc.Name)) { ret = false; } else if (Game1.random.NextDouble() >= Math.Max(0.15, (Math.Min(0.5, loc.map.Layers[0].LayerWidth * loc.map.Layers[0].LayerHeight / ChancePerTile)))) { ret = false; } else if (RequireDarkOut && !Game1.isDarkOut()) { ret = false; } else if (!AllowRain && Game1.isRaining) { ret = false; } if (Not) { ret = !ret; } return(ret); }
public bool check(object obj) { bool ret = true; if (Children.Count > 0) { if (ChildrenCombine != "and") { ret = false; } int totalMet = 0; foreach (var child in Children) { bool childCheck = child.check(obj); if (childCheck) { ++totalMet; } switch (ChildrenCombine) { case "and": ret = ret && childCheck; break; case "or": ret = ret || childCheck; break; case "xor": ret = ret ^ childCheck; break; } } if (ChildrenCombine.StartsWith("atleast")) { ret = totalMet >= int.Parse(ChildrenCombine.Substring(7)); } else if (ChildrenCombine.StartsWith("exactly")) { ret = totalMet == int.Parse(ChildrenCombine.Substring(7)); } else if (ChildrenCombine != "and" && ChildrenCombine != "or" && ChildrenCombine != "xor") { throw new ArgumentException("Bad ChildrenCombine: " + ChildrenCombine); } } else { if (Chance != 1.0 && Game1.random.NextDouble() > Chance) { ret = false; } if (Variable != null && Variable != "") { string[] toks = Variable.Split('.'); var o = obj; for (int i = 0; i < toks.Length; ++i) { if (o == null) { break; } var f = o.GetType().GetField(toks[i], BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (f == null) { o = null; break; } o = f.GetValue(o); } if (o != null) { if (Is != null && Is != "" && !o.GetType().IsInstanceOfType(Type.GetType(Is))) { ret = false; } else if (ValueEquals != null && ValueEquals != "" && !o.ToString().Equals(ValueEquals)) { ret = false; } } else if (RequireNotNull) { ret = false; } } } if (Not) { ret = !ret; } return(ret); }