コード例 #1
0
        private static void PickerCallback(Mobile m, Map map, Point3D start, Point3D end, object state)
        {
            var args = state as object[];

            if (args == null)
            {
                return;
            }

            if (start.X > end.X)
            {
                var x = start.X;

                start.X = end.X;
                end.X   = x;
            }

            if (start.Y > end.Y)
            {
                var y = start.Y;

                start.Y = end.Y;
                end.Y   = y;
            }

            var bounds = new Rectangle2D(start, end);

            var name      = args[0] as string;
            var namesplit = name;

            if (name != null)
            {
                namesplit = name.SpaceWords().ToUpperWords();
                name      = namesplit.Replace(" ", String.Empty);
            }

            var ns = args[1] as string;

            var getStatics         = (bool)args[2];
            var getItems           = (bool)args[3];
            var getTiles           = (bool)args[4];
            var includeStaticRange = (bool)args[5];
            var includeItemRange   = (bool)args[6];
            var includeTileRange   = (bool)args[7];
            var includeZRange      = (bool)args[8];
            var generateTest       = (bool)args[17];

            int minZ, maxZ, minStaticID, maxStaticID, minItemID, maxItemID, minTileID, maxTileID;

            if (!Int32.TryParse(args[9] as string, out minZ))
            {
                minZ = Region.MinZ;
            }

            if (!Int32.TryParse(args[10] as string, out maxZ))
            {
                maxZ = Region.MaxZ;
            }

            if (!Int32.TryParse(args[11] as string, out minStaticID))
            {
                minStaticID = 2;
            }

            if (!Int32.TryParse(args[12] as string, out maxStaticID))
            {
                maxStaticID = UInt16.MaxValue;
            }

            if (!Int32.TryParse(args[13] as string, out minItemID))
            {
                minItemID = 2;
            }

            if (!Int32.TryParse(args[14] as string, out maxItemID))
            {
                maxItemID = UInt16.MaxValue;
            }

            if (!Int32.TryParse(args[15] as string, out minTileID))
            {
                minTileID = 2;
            }

            if (!Int32.TryParse(args[16] as string, out maxTileID))
            {
                maxTileID = UInt16.MaxValue;
            }

            var cList = GetComponents(
                bounds,
                map,
                getTiles,
                getStatics,
                getItems,
                includeZRange,
                minZ,
                maxZ,
                includeTileRange,
                minTileID,
                maxTileID,
                includeStaticRange,
                minStaticID,
                maxStaticID,
                includeItemRange,
                minItemID,
                maxItemID);

            if (cList == null || cList.Count == 0)
            {
                m.SendMessage(0x40, "No components have been selected.");
                m.SendGump(new InternalGump(m, args));
                return;
            }

            var list = String.Join(
                "\n\t\t\t",
                cList.Select((s, i) => s + (i < cList.Count - 1 ? "," : String.Empty) + " // " + (i + 1)));

            var fileOut = new StringBuilder(_Template);

            var useref = "using System;";

            if (!ns.StartsWith("Server"))
            {
                useref += "\nusing Server;";
                useref += "\nusing Server.Items;";
            }
            else if (!ns.StartsWith("Server.Items"))
            {
                useref += "\nusing Server.Items;";
            }

            fileOut.Replace("~USING~", useref);
            fileOut.Replace("~NAMESPACE~", ns);
            fileOut.Replace("~NAME~", name);
            fileOut.Replace("~NAMESPLIT~", namesplit);
            fileOut.Replace("~LIST~", list);

            var path = Path.IsPathRooted(OutputDirectory) ? OutputDirectory : Path.Combine(Core.BaseDirectory, OutputDirectory);

            var file = IOUtility.EnsureFile(path + "/" + name + "Addon.cs", true);

            try
            {
                file.AppendText(true, fileOut.ToString());
            }
            catch (Exception ex)
            {
                ex.ToConsole(true, true);

                m.SendMessage(0x40, "An error occurred while writing the Addon file.");
                return;
            }

            m.SendMessage(0x40, "Addon saved to {0}", file);
            m.SendMessage(0x40, "Total components in Addon: {0}", cList.Count);

            if (!generateTest)
            {
                return;
            }

            var ia = new CEOIdentifyAddon();

            for (var i = 0; i < cList.Count; i++)
            {
                AddTestComponent(ia, cList[i], i + 1);
            }

            m.SendMessage(0x37, "Target a location to place the test Addon...");
            var target =
                m.Target =
                    new GenericSelectTarget <IPoint3D>(
                        (u, t) => ia.MoveToWorld(t.ToPoint3D(), u.Map),
                        u => ia.Delete(),
                        -1,
                        true,
                        TargetFlags.None);

            Timer timer = null;

            timer = Timer.DelayCall(
                TimeSpan.FromSeconds(1.0),
                TimeSpan.FromSeconds(1.0),
                () =>
            {
                if (m.Target == target)
                {
                    return;
                }

                if (ia.Map == null || ia.Map == Map.Internal)
                {
                    ia.Delete();
                }

                if (timer != null)
                {
                    timer.Stop();
                }
            });

            timer.Start();
        }