Exemplo n.º 1
0
        /// <summary>
        /// Appends a new blueprint hashtable entry. Return value indicates success or lack thereof.
        /// </summary>
        /// <param name="blueprint"></param>
        /// <returns></returns>
        private static bool AppendBlueprint(HouseBlueprint blueprint)
        {
            if (blueprint == null)
            {
                return(false);
            }

            //add the new entry under its ID
            try
            {
                m_BlueprintList.Add(blueprint.ID, blueprint);
                return(true);
            }
            catch (ArgumentNullException ex)
            {
                LogHelper.LogException(ex, "Null argument caught during blueprint hashtable append");
                Console.WriteLine("Null argument caught during blueprint hashtable append");
                return(false);
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex, "Exception caught during blueprint hashtable append");
                Console.WriteLine("Exception caught during blueprint hashtable append");
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retruns the multi id for the foundation of this house size
        /// </summary>
        /// <param name="houseID"></param>
        /// <returns></returns>
        public static int GetFoundationID(string houseID)
        {
            if (!IsBlueprintLoaded(houseID))
            {
                if (!LoadBlueprint(houseID))
                {
                    return(0);
                }
            }

            HouseBlueprint house = m_BlueprintList[houseID] as HouseBlueprint;

            if (house == null)
            {
                return(0);
            }
            if (m_FoundationLookup == null || m_FoundationLookup.Count == 0)
            {
                CreateFoundationTable();
            }

            //build key from width and height
            string key = house.Width.ToString() + "x" + house.Height.ToString();

            if (m_FoundationLookup.ContainsKey(key))
            {
                return((int)m_FoundationLookup[key]);
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 3
0
        public static List <StaticHouseDescription> GetAllStaticHouseDescriptions()
        {
            List <StaticHouseDescription> returnList = new List <StaticHouseDescription>();

            try
            {
                foreach (DictionaryEntry de in m_BlueprintList)
                {
                    HouseBlueprint hb = de.Value as HouseBlueprint;
                    if (hb != null)
                    {
                        try
                        {
                            string id   = hb.ID;                                        // element["id"].InnerText;
                            string desc = hb.Description;                               // element["Description"].InnerText;
                            desc += " by ";
                            desc += hb.OriginalOwnerName;                               // element["OriginalOwnerName"].InnerText;
                            int price = hb.Price;
                            StaticHouseDescription shd = new StaticHouseDescription(id, desc, price);
                            returnList.Add(shd);
                        }
                        catch (Exception e)
                        {
                            Server.Commands.LogHelper.LogException(e, "Possible bad element in static house xml: element[id].");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Server.Commands.LogHelper.LogException(e, "Botched Static Housing xml.");
            }

            return(returnList);
        }
Exemplo n.º 4
0
        public static void TransferData(StaticHouse sh)
        {
            // now transfer over the data from the original blueprint house
            try
            {
                Misc.Diagnostics.Assert(sh != null, "sh == null");
                if (!IsBlueprintLoaded(sh.HouseBlueprintID))
                {
                    if (!LoadBlueprint(sh.HouseBlueprintID))
                    {
                        try { throw new ApplicationException(); }
                        catch (Exception ex) { LogHelper.LogException(ex, "Can't find/load blueprint from hashtable/xml."); }
                        return;
                    }
                }

                Misc.Diagnostics.Assert(m_BlueprintList[sh.HouseBlueprintID] is HouseBlueprint, "m_BlueprintList[sh.HouseBlueprintID] is HouseBlueprint == false");
                HouseBlueprint house = m_BlueprintList[sh.HouseBlueprintID] as HouseBlueprint;
                if (house == null)
                {
                    try { throw new ApplicationException(); }
                    catch (Exception ex) { LogHelper.LogException(ex, "Can't find/load blueprint from hashtable."); }
                    return;
                }

                // copy the data
                sh.DefaultPrice         = house.Price;
                sh.BlueprintVersion     = house.Version;
                sh.Description          = house.Description;
                sh.OriginalOwnerName    = house.OriginalOwnerName;
                sh.OriginalOwnerAccount = house.OriginalOwnerAccount;
                sh.OriginalOwnerSerial  = house.OriginalOwnerSerial;
                sh.SignHanger.ItemID    = house.SignHangerGraphic;
                sh.Signpost.ItemID      = house.SignpostGraphic;
                sh.SignpostGraphic      = house.SignpostGraphic;
                sh.RevisionDate         = house.Capture;

                Misc.Diagnostics.Assert(house.Region != null, "house.Region == null");
                if (house.Region != null && house.Region.Count > 0)
                {
                    Misc.Diagnostics.Assert(sh.Components != null, "sh.Components == null");
                    foreach (Rectangle2D rect in house.Region)
                    {                           // fixup offsets
                        MultiComponentList mcl = sh.Components;
                        int x = rect.X + sh.X + mcl.Min.X;
                        int y = rect.Y + sh.Y + mcl.Min.Y;
                        sh.AreaList.Add(new Rectangle2D(x, y, rect.Width, rect.Height));
                    }
                    sh.UpdateRegionArea();
                }
            }
            catch (Exception e)
            {
                Server.Commands.LogHelper.LogException(e, "Botched Static Housing xml.");
            }
        }
Exemplo n.º 5
0
        public static ArrayList GetPatchTiles(string BlueprintID)
        {
            if (!StaticHouseHelper.IsBlueprintLoaded(BlueprintID))
            {
                if (!StaticHouseHelper.LoadBlueprint(BlueprintID))
                {
                    return(null);
                }
            }

            //grab blueprint
            HouseBlueprint house = m_BlueprintList[BlueprintID] as HouseBlueprint;

            if (house == null)
            {
                return(null);
            }

            return(house.PatchTiles);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates and returns a FixerAddon object for this house blueprint.
        /// </summary>
        public static FixerAddon BuildFixerAddon(string houseID)
        {
            if (!IsBlueprintLoaded(houseID))
            {
                if (!LoadBlueprint(houseID))
                {
                    return(null);
                }
            }

            //grab blueprint
            HouseBlueprint house = m_BlueprintList[houseID] as HouseBlueprint;

            if (house == null)
            {
                return(null);
            }

            return(new FixerAddon(house.PatchTiles));
        }
Exemplo n.º 7
0
        public static int GetPrice(string houseID)
        {
            if (!IsBlueprintLoaded(houseID))
            {
                if (!LoadBlueprint(houseID))
                {
                    // failsafe pricing
                    return((int)Error.PriceError);
                }
            }

            HouseBlueprint house = m_BlueprintList[houseID] as HouseBlueprint;

            if (house == null)
            {
                return((int)Error.PriceError);
            }
            else
            {
                return(house.Price);
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Returns component list from the hashtable
        /// </summary>
        /// <param name="houseID"></param>
        /// <returns></returns>
        public static MultiComponentList GetComponents(string houseID)
        {
            MultiComponentList mcl = MultiComponentList.Empty;

            if (!IsBlueprintLoaded(houseID))
            {
                if (!LoadBlueprint(houseID))
                {
                    return(mcl);
                }
            }

            //grab blueprint
            HouseBlueprint house = m_BlueprintList[houseID] as HouseBlueprint;

            if (house == null)
            {
                return(mcl);
            }

            //now the fun tile processing and mcl setup
            MultiTileEntry[] allTiles = mcl.List = new MultiTileEntry[house.Multis.Count + house.Deco.Count];

            // normal house tiles
            int i = 0;

            foreach (MultiStruct multiData in house.Multis)
            {
                allTiles[i].m_ItemID  = multiData.id;
                allTiles[i].m_OffsetX = multiData.x;
                allTiles[i].m_OffsetY = multiData.y;
                allTiles[i].m_OffsetZ = multiData.z;
                ++i;
            }

            // deco items on the plot, like steps (outside bounding rect)
            foreach (MultiStruct multiData in house.Deco)
            {
                allTiles[i].m_ItemID  = multiData.id;
                allTiles[i].m_OffsetX = multiData.x;
                allTiles[i].m_OffsetY = multiData.y;
                allTiles[i].m_OffsetZ = multiData.z;
                ++i;
            }

            mcl.Center = new Point2D(-mcl.Min.X, -mcl.Min.Y);
            mcl.Width  = (mcl.Max.X - mcl.Min.X) + 1;
            mcl.Height = (mcl.Max.Y - mcl.Min.Y) + 1;

            TileList[][] tiles = new TileList[mcl.Width][];
            mcl.Tiles = new Tile[mcl.Width][][];

            for (int x = 0; x < mcl.Width; ++x)
            {
                tiles[x]     = new TileList[mcl.Height];
                mcl.Tiles[x] = new Tile[mcl.Height][];

                for (int y = 0; y < mcl.Height; ++y)
                {
                    tiles[x][y] = new TileList();
                }
            }

            if (i == 0)
            {
                int xOffset = allTiles[i].m_OffsetX + mcl.Center.X;
                int yOffset = allTiles[i].m_OffsetY + mcl.Center.Y;

                tiles[xOffset][yOffset].Add((short)((allTiles[i].m_ItemID & 0x3FFF) | 0x4000), (sbyte)allTiles[i].m_OffsetZ);
            }

            for (int x = 0; x < mcl.Width; ++x)
            {
                for (int y = 0; y < mcl.Height; ++y)
                {
                    mcl.Tiles[x][y] = tiles[x][y].ToArray();
                }
            }

            return(mcl);
        }
Exemplo n.º 10
0
		/// <summary>
		/// Appends a new blueprint hashtable entry. Return value indicates success or lack thereof.
		/// </summary>
		/// <param name="blueprint"></param>
		/// <returns></returns>
		private static bool AppendBlueprint(HouseBlueprint blueprint)
		{
			if (blueprint == null)
				return false;

			//add the new entry under its ID
			try
			{
				m_BlueprintList.Add(blueprint.ID, blueprint);
				return true;
			}
			catch (ArgumentNullException ex)
			{
				LogHelper.LogException(ex, "Null argument caught during blueprint hashtable append");
				Console.WriteLine("Null argument caught during blueprint hashtable append");
				return false;
			}
			catch (Exception ex)
			{
				LogHelper.LogException(ex, "Exception caught during blueprint hashtable append");
				Console.WriteLine("Exception caught during blueprint hashtable append");
				return false;
			}

		}
Exemplo n.º 11
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;
		}