コード例 #1
0
ファイル: XmlQuest.cs プロジェクト: jamison654321/xmlspawner
		public static object CreateItem(IEntity from, string action, out string status_str, Type typerestrict)
		{
			status_str = null;

			if (action == null || action.Length <= 0 || from == null) return null;

			XmlSpawner.SpawnObject TheSpawn = new XmlSpawner.SpawnObject(null, 0);

			//BaseXmlSpawner.ApplyObjectStringProperties(null, action, m_TargetItem, m, m_TargetItem, out status_str);

			TheSpawn.TypeName = action;
			string substitutedtypeName = BaseXmlSpawner.ApplySubstitution(null, null, null, action);
			string typeName = BaseXmlSpawner.ParseObjectType(substitutedtypeName);

			if (BaseXmlSpawner.IsTypeOrItemKeyword(typeName))
			{
				BaseXmlSpawner.SpawnTypeKeyword(null, TheSpawn, typeName, substitutedtypeName, true, null, from.Location, Map.Internal, out status_str);
			}
			else
			{
				// its a regular type descriptor so find out what it is
				Type type = SpawnerType.GetType(typeName);

				// if a type restriction has been specified then test it
				if (typerestrict != null && type != null && type != typerestrict && !type.IsSubclassOf(typerestrict))
				{
					return null;
				}


				try
				{
					string[] arglist = BaseXmlSpawner.ParseString(substitutedtypeName, 3, "/");
					object o = XmlSpawner.CreateObject(type, arglist[0], true, true);

					if (o == null)
					{
						status_str = "invalid type specification: " + arglist[0];
					}
					else if (o is Mobile)
					{
						Mobile m = (Mobile)o;

						// dont do mobiles as rewards at this point
						m.Delete();
					}
					else if (o is Item)
					{
						Item item = (Item)o;
						BaseXmlSpawner.AddSpawnItem(null, from, TheSpawn, item, from.Location, Map.Internal, null, false, substitutedtypeName, out status_str);
					}
					else if (o is XmlAttachment)
					{
						BaseXmlSpawner.ApplyObjectStringProperties(null, substitutedtypeName, o, from as Mobile, o, out status_str);
						return o;
					}
				}
				catch { }
			}
			if (TheSpawn.SpawnedObjects.Count > 0)
			{
				if (TheSpawn.SpawnedObjects[0] is Item)
				{
					return ((Item)TheSpawn.SpawnedObjects[0]);
				}
				else if (TheSpawn.SpawnedObjects[0] is Mobile)
				{
					// dont do mobiles as rewards at this point
					((Mobile)(TheSpawn.SpawnedObjects[0])).Delete();
				}
			}

			return null;
		}
コード例 #2
0
ファイル: XmlDialog.cs プロジェクト: greeduomacro/UO-Forever
		private void ExecuteGump(Mobile mob, string gumpstring)
		{
			if (gumpstring == null || gumpstring.Length <= 0)
			{
				return;
			}

			string status_str = null;

			XmlSpawner.SpawnObject TheSpawn = new XmlSpawner.SpawnObject(null, 0);

			TheSpawn.TypeName = gumpstring;
			string substitutedtypeName = BaseXmlSpawner.ApplySubstitution(null, this, mob, gumpstring);
			string typeName = BaseXmlSpawner.ParseObjectType(substitutedtypeName);

			Point3D loc = new Point3D(0, 0, 0);
			Map map = null;

			if (AttachedTo is Mobile)
			{
				Mobile m = AttachedTo as Mobile;
				loc = m.Location;
				map = m.Map;
			}
			else if (AttachedTo is Item && ((Item)AttachedTo).Parent == null)
			{
				Item i = AttachedTo as Item;
				loc = i.Location;
				map = i.Map;
			}

			if (typeName == "GUMP")
			{
				BaseXmlSpawner.SpawnTypeKeyword(
					this, TheSpawn, typeName, substitutedtypeName, true, mob, loc, map, DialogGumpCallback, out status_str);
				// hold processing until the gump response is completed

				m_HoldProcessing = true;
			}
			else
			{
				status_str = "not a GUMP specification";
			}

			ReportError(mob, status_str);
		}
コード例 #3
0
ファイル: XmlDialog.cs プロジェクト: greeduomacro/UO-Forever
		private void ExecuteAction(Mobile mob, 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, this, mob, action);
			string typeName = BaseXmlSpawner.ParseObjectType(substitutedtypeName);

			Point3D loc = new Point3D(0, 0, 0);
			Map map = null;

			if (AttachedTo is Mobile)
			{
				Mobile m = AttachedTo as Mobile;
				loc = m.Location;
				map = m.Map;
			}
			else if (AttachedTo is Item && ((Item)AttachedTo).Parent == null)
			{
				Item i = AttachedTo as Item;
				loc = i.Location;
				map = i.Map;
			}

			if (BaseXmlSpawner.IsTypeOrItemKeyword(typeName))
			{
				BaseXmlSpawner.SpawnTypeKeyword(
					AttachedTo, 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
				{
					var 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, AttachedTo, out status_str);
					}
					else if (o is Item)
					{
						Item item = (Item)o;
						BaseXmlSpawner.AddSpawnItem(
							null, AttachedTo, TheSpawn, item, loc, map, mob, false, substitutedtypeName, out status_str);
					}
				}
				catch
				{ }
			}

			ReportError(mob, status_str);
		}
コード例 #4
0
		public static void ExecuteAction(Mobile trigmob, 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 = ApplySubstitution(null, target, trigmob, action);
			string typeName = 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 (IsTypeOrItemKeyword(typeName))
			{
				SpawnTypeKeyword(target, TheSpawn, typeName, substitutedtypeName, true, trigmob, loc, map, out status_str);
			}
			else
			{
				// its a regular type descriptor so find out what it is
				Type type = SpawnerType.GetType(typeName);
				try
				{
					var arglist = 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.Map = map; // swapped: map before location, so that BaseAI activates 
						m.Location = loc;

						ApplyObjectStringProperties(null, substitutedtypeName, m, trigmob, target, out status_str);
					}
					else if (o is Item)
					{
						Item item = (Item)o;
						AddSpawnItem(null, target, TheSpawn, item, loc, map, trigmob, false, substitutedtypeName, out status_str);
					}
				}
				catch
				{ }
			}

			ReportError(trigmob, status_str);
		}