public void ModAV(string av, object value, bool?propagate) { if (av.Contains(".")) { string firstPart = av.Substring(0, av.IndexOf('.')); string secondPart = av.Substring(av.IndexOf('.') + 1); if (firstPart == "BaseStats") { BaseStats.ModStat(secondPart, value); if (!propagate.HasValue) { UpdateStats(); } } else if (firstPart == "DerivedStats") { DerivedStats.ModStat(secondPart, value); } else if (firstPart == "Conditions") { //delete if present, add if not string fqConditionName = GetType().Namespace + "." + value.ToString(); Condition newCondition = (Condition)Activator.CreateInstance(Type.GetType(fqConditionName)); Condition oldCondition = null; foreach (Condition c in Conditions) { if (c.GetType() == newCondition.GetType()) { oldCondition = c; break; } } if (oldCondition != null) { Conditions.Remove(oldCondition); } else { Conditions.Add(newCondition); } if (!propagate.HasValue) { UpdateStats(); } } } else { //search and modify property var prop = GetType().GetProperty(av); if (TypeUtils.IsNumericType(prop.PropertyType)) { decimal newVal = Convert.ToDecimal(prop.GetValue(this, null)) + Convert.ToDecimal(value); prop.SetValue(this, Convert.ChangeType(newVal, prop.PropertyType), null); } else if (prop.PropertyType == typeof(string)) { string newVal = ((string)prop.GetValue(this, null)) + (string)(object)value; prop.SetValue(this, newVal, null); } else { prop.SetValue(this, Convert.ChangeType(value, prop.PropertyType), null); } } if (propagate.HasValue && propagate.Value) { UpdateStats(); } }