public void ExecuteLisp(SimObjectUsage botObjectAction, Object lisp) { if (lisp == null) { return; } if (lisp is SimTypeUsage) { SimTypeUsage u = (SimTypeUsage)lisp; if (u.LispScript != null) { ExecuteLisp(botObjectAction, u.LispScript); } foreach (SimObjectType ot in botObjectAction.Target.Affordances.ObjectType.SuperType) { } return; } BotClient Client = GetBotClient(); { Client.Intern("TheBot", this); Client.Intern("TheTarget", botObjectAction.Target); Client.Intern("TheAction", botObjectAction); Client.evalLispCode(lisp); } }
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 IList <SimTypeUsage> GetTypeUsages() { lock (UsageAffect) { HashSet <string> verbs = new HashSet <string>(); foreach (string key in UsageAffect.Keys) { verbs.Add(key); } lock (SuperType) foreach (SimObjectType st in SuperType) { foreach (SimTypeUsage v in st.GetTypeUsages()) { verbs.Add(v.UsageName); } } List <SimTypeUsage> usages = new List <SimTypeUsage>(); foreach (string st in verbs) { SimTypeUsage use = FindObjectUsage(st); use.ToString(); usages.Add(use); } return(usages); } }
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 BotSocialAction(SimAvatar who, SimTypeUsage what, SimAvatar target) : base(what.UsageName + " " + target) { TheBot = (SimControllableAvatar) who; TypeUsage = what; Victem = target; CurrentTopic = null; TimeRemaining = rand.Next(1, 3); // one to tree cycles }
public BotSocialAction(SimAvatar who, SimTypeUsage what, SimAvatar target) : base(what.UsageName + " " + target) { TheBot = (SimControllableAvatar)who; TypeUsage = what; Victem = target; CurrentTopic = null; TimeRemaining = rand.Next(1, 3); // one to tree cycles }
public BotNeeds GetUsageActual(string usename) { SimTypeUsage use = FindObjectUsage(usename); if (use == null) { return(BotNeeds.ZERO); } return(use.ChangeActual); }
public float RateIt(BotNeeds from, SimTypeUsage use) { if (use == null) { return(-100f); } BotNeeds sat = GetUsagePromise(use.UsageName).Copy(); sat.AddFrom(from); sat.SetRange(0.0F, 100.0F); return(sat.Total()); }
static public SimObjectType SetSimType(string aspectName, Cons cons) { object[] parseStr = ConsParams(cons); SimObjectType type = GetObjectType(aspectName); SimTypeUsage usage = null; if (type.IsUseType) { usage = type.CreateObjectUsage(aspectName); } type.ParseAffect(usage, parseStr); return(type); }
public SimTypeUsage CreateObjectUsage(string usename) { lock (UsageAffect) { if (UsageAffect.ContainsKey(usename)) { return(UsageAffect[usename]); } SimTypeUsage sou = new SimTypeUsage(usename); // sou.TextName = usename; UsageAffect[usename] = sou; return(sou); } }
static public SimTypeUsage CreateTypeUsage(string classname, params object[] parseStr) { if (parseStr.Length == 1 && parseStr[0] is object[]) { parseStr = (object[])parseStr[0]; } SimObjectType type = GetObjectType(classname); type.AddSuperType(USEABLE); type.IsUseType = true; SimTypeUsage usage = type.CreateObjectUsage(classname); type.ParseAffect(usage, parseStr); return(usage); }
public SimTypeUsage FindObjectUsage(string usename) { lock (UsageAffect) { List <SimTypeUsage> usages = new List <SimTypeUsage>(); lock (SuperType) foreach (SimObjectType type in SuperType) { SimTypeUsage find = type.FindObjectUsage(usename); if (find != null) { usages.Add(find); } } if (UsageAffect.ContainsKey(usename)) { usages.Add(UsageAffect[usename]); } if (usages.Count == 0) { return(null); } SimTypeUsage newUse = new SimTypeUsage(usename); foreach (SimTypeUsage use in usages) { newUse.OverrideProperties(use); } // TODO maybe store for later? // usageAffect[usename] = newUse; return(newUse); } }
private void InvokeThis(SimTypeUsage name, object sender, EventArgs args, SimObject O, object target, Type type) { Plugin.TheBot.WorldSystem.TheSimAvatar.Do(name, O ?? GetSimObject(target)); }
public SimObjectUsage(SimTypeUsage use, SimObject target) : base("" + use.ToString() + " " + target.ToString()) { TypeUsage = use; Target = target; }
public SimTypeUsage FindObjectUsage(string usename) { lock (UsageAffect) { List<SimTypeUsage> usages = new List<SimTypeUsage>(); lock (SuperType) foreach (SimObjectType type in SuperType) { SimTypeUsage find = type.FindObjectUsage(usename); if (find != null) { usages.Add(find); } } if (UsageAffect.ContainsKey(usename)) usages.Add(UsageAffect[usename]); if (usages.Count == 0) return null; SimTypeUsage newUse = new SimTypeUsage(usename); foreach (SimTypeUsage use in usages) { newUse.OverrideProperties(use); } // TODO maybe store for later? // usageAffect[usename] = newUse; return newUse; } }
public SimTypeUsage CreateObjectUsage(string usename) { lock (UsageAffect) { if (UsageAffect.ContainsKey(usename)) return UsageAffect[usename]; SimTypeUsage sou = new SimTypeUsage(usename); // sou.TextName = usename; UsageAffect[usename] = sou; return sou; } }
public float RateIt(BotNeeds from, SimTypeUsage use) { if (use == null) return -100f; BotNeeds sat = GetUsagePromise(use.UsageName).Copy(); sat.AddFrom(from); sat.SetRange(0.0F, 100.0F); return sat.Total(); }
/// public void AddGrass(Simulator simulator, Vector3 scale, Quaternion rotation, Vector3 position, Grass grassType, UUID groupOwner) /// { /// } /// public void AddPrim(Simulator simulator, Primitive.ConstructionData prim, UUID groupID, Vector3 position, Vector3 scale, Quaternion rotation) /// { /// } /// public void AddTree(Simulator simulator, Vector3 scale, Quaternion rotation, Vector3 position, Tree treeType, UUID groupOwner, bool newTree) /// { /// } /// public void AttachObject(Simulator simulator, uint localID, AttachmentPoint attachPoint, Quaternion rotation) /// { /// } /// public static Primitive.ConstructionData BuildBasicShape(PrimType type) /// { /// } /// public ISimObject RezObjectType(ISimObject copyOf) /// { /// string treeName = args[0].Trim(new char[] { ' ' }); /// Tree tree = (Tree)Enum.Parse(typeof(Tree), treeName); /// Vector3 treePosition = ClientSelf.SimPosition; /// treePosition.Z += 3.0f; /// Client.Objects.AddTree(Client.Network.CurrentSim, new Vector3(0.5f, 0.5f, 0.5f), /// Quaternion.Identity, treePosition, tree, Client.GroupID, false); /// /// ClientSelf. /// return copyOf; /// } /// public void SortActs(List<SimUsage> acts) /// { /// acts.Sort(CompareUsage); /// } public void Do(SimTypeUsage use, SimObject someObject) { CurrentAction = new BotObjectAction(this, new SimObjectUsage(use, someObject)); }
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 + "'"); } }
public SimObjectUsage(SimTypeUsage use, SimObject target) : base (""+ use.ToString() + " " + target.ToString()) { TypeUsage = use; Target = target; }
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 + "'"); } }