public SimTypeUsage OverrideProperties(SimTypeUsage use) { SimTypeUsage newUse = this; foreach (string prop in use.SpecifiedProperties) { newUse.SpecifiedProperties.Add(prop); System.Reflection.FieldInfo fi = newUse.GetType().GetField(prop); if (fi.FieldType == typeof(BotNeeds)) { continue; } SimTypeSystem.SetValue(fi, newUse, fi.GetValue(use)); } //if (use.SpecifiedProperties.Contains("TextName")) // newUse.TextName = use.TextName; //if (use.SpecifiedProperties.Contains("UseGrab")) // newUse.UseGrab = use.UseGrab; //if (use.SpecifiedProperties.Contains("UseSit")) // newUse.UseSit = use.UseSit; //if (use.SpecifiedProperties.Contains("LispScript")) // newUse.LispScript = use.LispScript; //if (use.SpecifiedProperties.Contains("UseAnim")) // newUse.UseAnim = use.UseAnim; newUse.ChangeActual = newUse.ChangeActual.Copy(); newUse.ChangeActual.AddFrom(use.ChangeActual); newUse.ChangePromise = newUse.ChangePromise.Copy(); newUse.ChangePromise.AddFrom(use.ChangePromise); return(newUse); }
public void ParseAffect(SimTypeUsage usage, object[] parseStr) { SimObjectType type = this; int i = 0; while (i < parseStr.Length) { if (parseStr[i] == null) { i++; continue; } string s = (string)parseStr[i++];//.ToString(); if (s == "SuperType") { String arg = parseStr[i++].ToString(); SimObjectType test = SimTypeSystem.FindObjectType(arg); if (test == null) { throw new Exception("unknown super type " + arg + " for " + type); } AddSuperType(test); //Not all types need to be by default usage types - was causing problems // use types are fined by "Verb" // usage = type.CreateObjectUsage(arg); continue; } //if (s == "Match") //{ // String arg = parseStr[i++].ToString(); // arg = SimTypeSystem.MakeRegExpression(arg); // type.Match.Add(new Regex(arg)); // continue; //} //if (s == "NoMatch") //{ // String arg = parseStr[i++].ToString(); // arg = SimTypeSystem.MakeRegExpression(arg); // type.NoMatch.Add(new Regex(arg)); // continue; //} if (s == "Verb") { String arg = parseStr[i++].ToString(); // TODO make sure creation order internalizes correctly SimObjectType superType = SimTypeSystem.CreateObjectUse(arg, new object[0]); AddSuperType(superType); usage = type.CreateObjectUsage(arg); continue; } // usage / distanceToExcite / etc FieldInfo fi = type.GetType().GetField(s); if (fi != null) { type.SpecifiedProperties.AddTo(fi.Name); SimTypeSystem.SetValue(fi, type, parseStr[i++]); continue; } fi = type.GetType().GetField(s + "s"); if (fi != null) { type.SpecifiedProperties.AddTo(fi.Name); SimTypeSystem.SetValue(fi, type, parseStr[i++]); continue; } if (usage == null) { if (type.IsUseType) { usage = type.CreateObjectUsage(type.GetTypeName()); } } fi = usage.GetType().GetField(s); if (fi != null) { usage.SpecifiedProperties.Add(fi.Name); SimTypeSystem.SetValue(fi, usage, parseStr[i++]); continue; } fi = usage.GetType().GetField(s + "s"); if (fi != null) { usage.SpecifiedProperties.Add(fi.Name); SimTypeSystem.SetValue(fi, usage, parseStr[i++]); continue; } // Hygiene / Hunger fi = typeof(BotNeeds).GetField(s); if (fi != null) { float ff = Single.Parse(parseStr[i++].ToString()); fi.SetValue(usage.ChangePromise, ff); ff = Single.Parse(parseStr[i++].ToString()); fi.SetValue(usage.ChangeActual, ff); continue; } DLRConsole.DebugWriteLine("ERROR: SimBots.ini-like dirrective unknown: '" + s + "'"); } }