private void CalculateDerivedStats() { DerivedStats.Add(DerivedStat.DamageReduction, Stats[Stat.Health]); DerivedStats.Add(DerivedStat.Energy, Stats[Stat.Willpower]); DerivedStats.Add(DerivedStat.Evade, Stats[Stat.Agility]); DerivedStats.Add(DerivedStat.MentalDamage, Stats[Stat.Willpower]); DerivedStats.Add(DerivedStat.MentalHit, Stats[Stat.Intelligence]); DerivedStats.Add(DerivedStat.PhysicalDamage, Stats[Stat.Strength]); DerivedStats.Add(DerivedStat.PhysicalHit, Stats[Stat.Dexterity]); DerivedStats.Add(DerivedStat.Sabotage, Stats[Stat.Cunning]); DerivedStats.Add(DerivedStat.SkillPoints, Stats[Stat.Cunning]); DerivedStats.Add(DerivedStat.Slots, Stats[Stat.Intelligence]); DerivedStats.Add(DerivedStat.Weight, Stats[Stat.Strength] + Stats[Stat.Health]); }
public void SetAV(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.SetStat(secondPart, value); if (!propagate.HasValue) { UpdateStats(); } } else if (firstPart == "DerivedStats") { DerivedStats.SetStat(secondPart, value); } else if (firstPart == "Conditions") { string fqConditionName = GetType().Namespace + "." + value.ToString(); Condition c = (Condition)Activator.CreateInstance(Type.GetType(fqConditionName)); Conditions.Add(c); if (!propagate.HasValue) { UpdateStats(); } } else if (firstPart == "ExtraData") { ExtraData[secondPart] = value; } } else { //search and set property var prop = GetType().GetProperty(av); prop.SetValue(this, Convert.ChangeType(value, prop.PropertyType), null); } if (propagate.HasValue && propagate.Value) { UpdateStats(); } }
public object GetAV(string av) { if (av.Contains(".")) { string firstPart = av.Substring(0, av.IndexOf('.')); string secondPart = av.Substring(av.IndexOf('.') + 1); if (firstPart == "BaseStats") { return(BaseStats.GetStat(secondPart)); } else if (firstPart == "DerivedStats") { return(DerivedStats.GetStat(secondPart)); } else if (firstPart == "Conditions") { string fqConditionName = GetType().Namespace + "." + secondPart.ToString(); Condition newC = (Condition)Activator.CreateInstance(Type.GetType(fqConditionName)); bool found = false; foreach (Condition c in Conditions) { if (c.GetType() == newC.GetType()) { found = true; break; } } return(found); } else if (firstPart == "ExtraData") { return(ExtraData[secondPart]); } } else { //search and get property return(GetType().GetProperty(av).GetValue(this, null)); } //fail throw new KeyNotFoundException(); }
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(); } }