当前位置: 首页>>代码示例>>C#>>正文


C# Spawner.Serialize方法代码示例

本文整理汇总了C#中Server.Mobiles.Spawner.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# Spawner.Serialize方法的具体用法?C# Spawner.Serialize怎么用?C# Spawner.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Server.Mobiles.Spawner的用法示例。


在下文中一共展示了Spawner.Serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveSpawners_OnCommand

		public static void SaveSpawners_OnCommand(CommandEventArgs e)
		{

			if (e.Arguments.Length == 5)
			{
				int count = 0;
				int x1, y1, x2, y2;
				string FileName = e.Arguments[0].ToString();
				try
				{
					x1 = Int32.Parse(e.Arguments[1]);
					y1 = Int32.Parse(e.Arguments[2]);
					x2 = Int32.Parse(e.Arguments[3]);
					y2 = Int32.Parse(e.Arguments[4]);
				}
				catch
				{
					Usage(e.Mobile);
					return;
				}
				//adjust rect				
				if (x1 > x2)
				{
					int x3 = x1;
					x1 = x2;
					x2 = x3;
				}
				if (y1 > y2)
				{
					int y3 = y1;
					y1 = y2;
					y2 = y3;
				}
				string itemIdxPath = Path.Combine("Saves/Spawners/", FileName + ".idx");
				string itemBinPath = Path.Combine("Saves/Spawners/", FileName + ".bin");

				try
				{
					ArrayList list = new ArrayList();
					foreach (Item item in Server.World.Items.Values)
					{
						if (item is Spawner)
						{
							if (item.X >= x1 && item.Y >= y1 && item.X < x2 && item.Y < y2 && item.Map == e.Mobile.Map)
								list.Add(item);
						}
					}

					if (list.Count > 0)
					{
						try
						{
							string folder = Path.GetDirectoryName(itemIdxPath);

							if (!Directory.Exists(folder))
							{
								Directory.CreateDirectory(folder);
							}

						}
						catch
						{
							e.Mobile.SendMessage("An error occured while trying to create Spawner folder.");
						}

						count = list.Count;
						GenericWriter idx;
						GenericWriter bin;

						idx = new BinaryFileWriter(itemIdxPath, false);
						bin = new BinaryFileWriter(itemBinPath, true);

						idx.Write((int)list.Count);

						for (int i = 0; i < list.Count; ++i)
						{
							long start = bin.Position;
							Spawner temp = new Spawner();
							CopyProperties(temp, (Spawner)list[i]);

							idx.Write((long)start);
							//dont save template data as we cant load it back properly
							temp.TemplateItem = null;
							temp.TemplateMobile = null;
							temp.CreaturesName = ((Spawner)list[i]).CreaturesName;
							temp.Serialize(bin);

							idx.Write((int)(bin.Position - start));
							temp.Delete();
						}
						idx.Close();
						bin.Close();
					}
				}
				catch (Exception ex)
				{
					LogHelper.LogException(ex);
					System.Console.WriteLine("Exception Caught in SaveSpawner code: " + ex.Message);
					System.Console.WriteLine(ex.StackTrace);
				}
//.........这里部分代码省略.........
开发者ID:zerodowned,项目名称:angelisland,代码行数:101,代码来源:SpawnerManagement.cs


注:本文中的Server.Mobiles.Spawner.Serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。