public static object Spawn(string spawnString, object caller) { if (spawnString == null || spawnString == "") { return(null); } int commaIndex = spawnString.IndexOf(','); Type type; if (commaIndex != -1) { type = ScriptCompiler.FindTypeByName(spawnString.Substring(0, commaIndex)); } else { type = ScriptCompiler.FindTypeByName(spawnString); } // do not allow mobiles to be spawned into item backpack if (type != null) { object o = XmlSpawner.CreateObject(type, spawnString); if (o == null) { throw new UberScriptException("Could not create spawn: " + spawnString + "... should be impossible!"); } return(o); } return(null); }
private static void ExecuteDeathAction(Item corpse, Mobile killer, string action) { if (action == null || action.Length <= 0 || corpse == null) { return; } string status_str = null; XmlSpawner.SpawnObject TheSpawn = new XmlSpawner.SpawnObject(null, 0); TheSpawn.TypeName = action; string substitutedtypeName = BaseXmlSpawner.ApplySubstitution(null, corpse, killer, action); string typeName = BaseXmlSpawner.ParseObjectType(substitutedtypeName); Point3D loc = corpse.Location; Map map = corpse.Map; if (BaseXmlSpawner.IsTypeOrItemKeyword(typeName)) { BaseXmlSpawner.SpawnTypeKeyword(corpse, TheSpawn, typeName, substitutedtypeName, true, killer, loc, map, out status_str); } else { // its a regular type descriptor so find out what it is Type type = SpawnerType.GetType(typeName); try { string[] arglist = BaseXmlSpawner.ParseString(substitutedtypeName, 3, "/"); object o = XmlSpawner.CreateObject(type, arglist[0]); if (o == null) { status_str = "invalid type specification: " + arglist[0]; } else if (o is Mobile) { Mobile m = (Mobile)o; if (m is BaseCreature) { BaseCreature c = (BaseCreature)m; c.Home = loc; // Spawners location is the home point } m.Location = loc; m.Map = map; BaseXmlSpawner.ApplyObjectStringProperties(null, substitutedtypeName, m, killer, corpse, out status_str); } else if (o is Item) { Item item = (Item)o; BaseXmlSpawner.AddSpawnItem(null, corpse, TheSpawn, item, loc, map, killer, false, substitutedtypeName, out status_str); } } catch { } } }
// adds components from a multi.txt file to an existing addon public static int LoadAddonFromMulti(XmlSpawnerAddon newaddon, string filename, out string status_str) { status_str = null; if (filename == null) { status_str = "Invalid filename"; return(0); } if (newaddon == null) { status_str = "Invalid addon"; return(0); } bool badformat = false; int ncomponents = 0; if (System.IO.File.Exists(filename)) { using (StreamReader sr = new StreamReader(filename)) { string line; int linenumber = 0; // Read and process lines from the file until the end of the file is reached. // Individual lines have the format of // itemid x y z visible [hue] ; attachment[,args] // where visible is a 0/1 and hue can be optionally specified for individual itemid entries. while ((line = sr.ReadLine()) != null) { linenumber++; // process the line if (line.Length == 0) { continue; } // first parse out the component specification from any optional attachment specifications string[] specs = line.Split(';'); // the component spec will always be first if (specs == null || specs.Length < 1) { continue; } string[] args = specs[0].Trim().Split(' '); AddonComponent newcomponent = null; if (args != null && args.Length >= 5) { int itemid = -1; int x = 0; int y = 0; int z = 0; int visible = 0; int hue = -1; try { itemid = int.Parse(args[0]); x = int.Parse(args[1]); y = int.Parse(args[2]); z = int.Parse(args[3]); visible = int.Parse(args[4]); // handle the optional fields that are not part of the original multi.txt specification if (args.Length > 5) { hue = int.Parse(args[5]); } } catch { badformat = true; } if (itemid < 0 || badformat) { status_str = String.Format("Error line {0}", linenumber); break; } // create the new component newcomponent = new AddonComponent(itemid); // set the properties according to the specification newcomponent.Visible = (visible == 1); if (hue >= 0) { newcomponent.Hue = hue; } // add it to the addon newaddon.AddComponent(newcomponent, x, y, z); ncomponents++; } // if a valid component was added, then check to see if any additional attachment specifications need to be processed if (newcomponent != null && specs.Length > 1) { for (int j = 1; j < specs.Length; j++) { if (specs[j] == null) { continue; } string attachstring = specs[j].Trim(); Type type = null; try { type = SpawnerType.GetType(BaseXmlSpawner.ParseObjectType(attachstring)); } catch { } // if so then create it if (type != null && type.IsSubclassOf(typeof(XmlAttachment))) { object newo = XmlSpawner.CreateObject(type, attachstring, false, true); if (newo is XmlAttachment) { // add the attachment to the target XmlAttach.AttachTo(newcomponent, (XmlAttachment)newo); } } } } } sr.Close(); } } else { status_str = "No such file : " + filename; } if (badformat) { return(0); } else { return(ncomponents); } }
private void ExecuteAction(Mobile mob, object target, string action) { if (action == null || action.Length <= 0) { return; } string status_str = null; XmlSpawner.SpawnObject TheSpawn = new XmlSpawner.SpawnObject(null, 0); TheSpawn.TypeName = action; string substitutedtypeName = BaseXmlSpawner.ApplySubstitution(null, target, mob, action); string typeName = BaseXmlSpawner.ParseObjectType(substitutedtypeName); Point3D loc = new Point3D(0, 0, 0); Map map = null; if (target is Item) { Item ti = target as Item; if (ti.Parent == null) { loc = ti.Location; map = ti.Map; } else if (ti.RootParent is Item) { loc = ((Item)ti.RootParent).Location; map = ((Item)ti.RootParent).Map; } else if (ti.RootParent is Mobile) { loc = ((Mobile)ti.RootParent).Location; map = ((Mobile)ti.RootParent).Map; } } else if (target is Mobile) { Mobile ti = target as Mobile; loc = ti.Location; map = ti.Map; } if (BaseXmlSpawner.IsTypeOrItemKeyword(typeName)) { BaseXmlSpawner.SpawnTypeKeyword(target, TheSpawn, typeName, substitutedtypeName, true, mob, loc, map, out status_str); } else { // its a regular type descriptor so find out what it is Type type = SpawnerType.GetType(typeName); try { string[] arglist = BaseXmlSpawner.ParseString(substitutedtypeName, 3, "/"); object o = XmlSpawner.CreateObject(type, arglist[0]); if (o == null) { status_str = "invalid type specification: " + arglist[0]; } else if (o is Mobile) { Mobile m = (Mobile)o; if (m is BaseCreature) { BaseCreature c = (BaseCreature)m; c.Home = loc; // Spawners location is the home point } m.Location = loc; m.Map = map; BaseXmlSpawner.ApplyObjectStringProperties(null, substitutedtypeName, m, mob, target, out status_str); } else if (o is Item) { Item item = (Item)o; BaseXmlSpawner.AddSpawnItem(null, target, TheSpawn, item, loc, map, mob, false, substitutedtypeName, out status_str); } } catch { } } ReportError(mob, status_str); }