Beispiel #1
0
        /// <summary>
        /// Creates a new blueprint object fron the passed xml node
        /// </summary>
        /// <param name="multis"></param>
        /// <returns></returns>
        private static HouseBlueprint CreateBlueprint(XmlElement blueprint)
        {
            if (blueprint == null)
            {
                return(null);
            }

            HouseBlueprint b = new HouseBlueprint();

            foreach (XmlElement e in blueprint)
            {
                switch (e.Name.ToLower())
                {
                case "id":
                {
                    b.ID = e.InnerText;
                    break;
                }

                case "width":
                {
                    b.Width = int.Parse(e.InnerText);
                    break;
                }

                case "height":
                {
                    b.Height = int.Parse(e.InnerText);
                    break;
                }

                case "multi":
                {
                    foreach (XmlElement multi in e)
                    {
                        try
                        {
                            MultiStruct s = new MultiStruct();
                            s.id = short.Parse(multi["id"].InnerText);
                            s.x  = short.Parse(multi["x"].InnerText);
                            s.y  = short.Parse(multi["y"].InnerText);
                            s.z  = short.Parse(multi["z"].InnerText);

                            // flags == TileType.OutsideRect means the component exists outside
                            //	the bounding rect of the house (plot) (steps probably)
                            TileType flags = (TileType)int.Parse(multi["flags"].InnerText);
                            if (flags == TileType.Normal)
                            {
                                b.Multis.Add(s);
                            }
                            else if (((flags & TileType.Overlapped) != 0) || ((flags & TileType.Patch) != 0))                                             // must come before OutsideRect
                            {
                                b.PatchTiles.Add(s);
                            }
                            else if ((flags & TileType.OutsideRect) != 0)
                            {
                                b.Deco.Add(s);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.LogException(ex);
                        }
                    }
                    break;
                }

                // informational nodes
                case "description":
                {
                    b.Description = e.InnerText;
                    break;
                }

                case "price":
                {                                       // fail safe pricing
                    int price;
                    if (int.TryParse(e.InnerText, out price) == false)
                    {
                        b.Price = (int)Error.PriceError;
                    }
                    else
                    {
                        b.Price = price;
                    }
                    break;
                }

                case "originalownername":
                {
                    b.OriginalOwnerName = e.InnerText;
                    break;
                }

                case "version":
                {
                    double version;
                    if (double.TryParse(e.InnerText, out version) == false)
                    {
                        b.Version = 1.0;
                    }
                    else
                    {
                        b.Version = version;
                    }
                    break;
                }

                case "capture":
                {
                    DateTime capture;
                    if (DateTime.TryParse(e.InnerText, out capture) == false)
                    {
                        b.Capture = DateTime.MinValue;
                    }
                    else
                    {
                        b.Capture = capture;
                    }
                    break;
                }

                case "originalowneraccount":
                {
                    b.OriginalOwnerAccount = e.InnerText;
                    break;
                }

                case "originalownerserial":
                {
                    Int32 temp;
                    if (System.Int32.TryParse(e.InnerText.Remove(0, 2), System.Globalization.NumberStyles.AllowHexSpecifier, null, out temp) == false)
                    {
                        b.OriginalOwnerSerial = Serial.MinusOne;
                    }
                    else
                    {
                        b.OriginalOwnerSerial = (Serial)temp;
                    }
                    break;
                }

                case "signlocation":
                {                                       // not used - but we keep the case label to avoid the console warning
                    break;
                }

                case "region":
                {
                    foreach (XmlElement rect in e)
                    {
                        try
                        {
                            int         OffsetX   = short.Parse(rect["x"].InnerText);
                            int         OffsetY   = short.Parse(rect["y"].InnerText);
                            int         width     = short.Parse(rect["width"].InnerText);
                            int         height    = short.Parse(rect["height"].InnerText);
                            Rectangle2D rectangle = new Rectangle2D(OffsetX, OffsetY, width, height);
                            b.Region.Add(rectangle);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.LogException(ex);
                        }
                    }
                    break;
                }

                case "signhangergraphic":
                {
                    int signhangergraphic;
                    if (int.TryParse(e.InnerText, out signhangergraphic) == false)
                    {
                        b.SignHangerGraphic = 0xB98;
                    }
                    else
                    {
                        b.SignHangerGraphic = signhangergraphic;
                    }
                    break;
                }

                case "signpostgraphic":
                {
                    int signpostgraphic;
                    if (int.TryParse(e.InnerText, out signpostgraphic) == false)
                    {
                        b.SignpostGraphic = 0x09;
                    }
                    else
                    {
                        b.SignpostGraphic = signpostgraphic;
                    }
                    break;
                }

                default:
                {
                    Console.WriteLine("Unrecognized XML node name \"{0}\"", e.Name.ToLower());
                    break;
                }
                }
            }
            return(b);
        }
		/// <summary>
		/// Creates a new blueprint object fron the passed xml node
		/// </summary>
		/// <param name="multis"></param>
		/// <returns></returns>
		private static HouseBlueprint CreateBlueprint(XmlElement blueprint)
		{
			if (blueprint == null)
				return null;

			HouseBlueprint b = new HouseBlueprint();
			foreach (XmlElement e in blueprint)
			{
				switch (e.Name.ToLower())
				{
					case "id":
					{
						b.ID = e.InnerText;
						break;
					}
					case "width":
					{
						b.Width = int.Parse(e.InnerText);
						break;
					}
					case "height":
					{
						b.Height = int.Parse(e.InnerText);
						break;
					}
					case "multi":
					{
						foreach (XmlElement multi in e)
						{
							try
							{
								MultiStruct s = new MultiStruct();
								s.id = short.Parse(multi["id"].InnerText);
								s.x = short.Parse(multi["x"].InnerText);
								s.y = short.Parse(multi["y"].InnerText);
								s.z = short.Parse(multi["z"].InnerText);

								// flags == TileType.OutsideRect means the component exists outside 
								//	the bounding rect of the house (plot) (steps probably)
								TileType flags = (TileType)int.Parse(multi["flags"].InnerText);
                                if (flags == TileType.Normal)
                                    b.Multis.Add(s);
								else if (((flags & TileType.Overlapped) != 0) || ((flags & TileType.Patch) != 0)) // must come before OutsideRect
                                    b.PatchTiles.Add(s);
                                else if ((flags & TileType.OutsideRect) != 0)
                                    b.Deco.Add(s);
							}
							catch (Exception ex)
							{
								LogHelper.LogException(ex);
							}
						}
						break;
					}

					// informational nodes
					case "description":
					{
						b.Description = e.InnerText;
						break;
					}

					case "price":
					{	// fail safe pricing
						int price;
						if (int.TryParse(e.InnerText, out price) == false)
							b.Price = (int)Error.PriceError;
						else
							b.Price = price;
						break;
					}

					case "originalownername":
					{
						b.OriginalOwnerName = e.InnerText;
						break;
					}

					case "version":
					{
						double version;
						if (double.TryParse(e.InnerText, out version) == false)
							b.Version = 1.0;
						else
							b.Version = version;
						break;
					}

					case "capture":
					{
						DateTime capture;
						if (DateTime.TryParse(e.InnerText, out capture) == false)
							b.Capture = DateTime.MinValue;
						else
							b.Capture = capture;
						break;
					}

					case "originalowneraccount":
					{
						b.OriginalOwnerAccount = e.InnerText;
						break;
					}

					case "originalownerserial":
					{
						Int32 temp;
						if (System.Int32.TryParse(e.InnerText.Remove(0, 2), System.Globalization.NumberStyles.AllowHexSpecifier, null, out temp) == false)
							b.OriginalOwnerSerial = Serial.MinusOne;
						else
							b.OriginalOwnerSerial = (Serial)temp;
						break;
					}

					case "signlocation":
					{	// not used - but we keep the case label to avoid the console warning
						break;
					}

					case "region":
					{
						foreach (XmlElement rect in e)
						{
							try
							{
								int OffsetX = short.Parse(rect["x"].InnerText);
								int OffsetY = short.Parse(rect["y"].InnerText);
								int width = short.Parse(rect["width"].InnerText);
								int height = short.Parse(rect["height"].InnerText);
								Rectangle2D rectangle = new Rectangle2D(OffsetX, OffsetY, width, height);
								b.Region.Add(rectangle);
							}
							catch (Exception ex)
							{
								LogHelper.LogException(ex);
							}
						}
						break;
					}

					case "signhangergraphic":
					{
						int signhangergraphic;
						if (int.TryParse(e.InnerText, out signhangergraphic) == false)
							b.SignHangerGraphic = 0xB98;   
						else
							b.SignHangerGraphic = signhangergraphic;
						break;
					}

					case "signpostgraphic":
					{
						int signpostgraphic;
						if (int.TryParse(e.InnerText, out signpostgraphic) == false)
							b.SignpostGraphic = 0x09;
						else
							b.SignpostGraphic = signpostgraphic;
						break;
					}

					default:
					{
						Console.WriteLine("Unrecognized XML node name \"{0}\"", e.Name.ToLower());
						break;
					}
				}

			}
			return b;
		}