public override void Execute(CommandEventArgs e, object obj)
            {
                int found   = 0;
                int visited = 0;

                try
                {
                    Item item = obj as Item;
                    if (e.Arguments.Length == 0)
                    {
                        e.Mobile.SendMessage("Usage: FindItemInArea ItemID");
                        return;
                    }

                    int ItemID = 0;
                    if (int.TryParse(e.Arguments[0], out ItemID) == false)
                    {
                        e.Mobile.SendMessage("Usage: FindItemInArea decimal-ItemID");
                        return;
                    }

                    visited++;
                    if (item.ItemID == ItemID)
                    {
                        found++;
                        AddResponse(String.Format("Found Item {0} at {1}", item.ItemID, item.Location));
                    }
                }
                catch (Exception exe)
                {
                    LogHelper.LogException(exe);
                    e.Mobile.SendMessage(exe.Message);
                }

                AddResponse(String.Format("{0} items visited, {1} items found.", visited, found));
            }
示例#2
0
        public static void CheckLOS_OnCommand(CommandEventArgs e)
        {
            if (e.Mobile.AccessLevel == AccessLevel.Player && TestCenter.Enabled == false)
            {                   // Players can only test this on Test Center
                e.Mobile.SendMessage("Not available here.");
                return;
            }

            if (e.Mobile.AccessLevel > AccessLevel.Player)
            {                   // you will not get good results if you test this with AccessLevel > Player
                e.Mobile.SendMessage("You should test this with AccessLevel.Player.");
                return;
            }

            try
            {
                e.Mobile.Target = new LOSTarget();
                e.Mobile.SendMessage("Check LOS to which object?");
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
            }
        }
        public static void Jump_Next(CommandEventArgs e)
        {
            try
            {
                // sanity
                if (e == null || e.Mobile == null || e.Mobile is PlayerMobile == false)
                {
                    return;
                }

                PlayerMobile pm = e.Mobile as PlayerMobile;

                if (pm.JumpList != null && pm.JumpList.Count > 0)
                {
                    if (pm.JumpIndex < pm.JumpList.Count)
                    {
                        if (pm.JumpList[pm.JumpIndex] is Item)
                        {
                            if ((pm.JumpList[pm.JumpIndex] as Item).Map == Map.Internal)
                            {
                                e.Mobile.SendMessage("Item {0} is on the {1} map", (pm.JumpList[pm.JumpIndex] as Item), (pm.JumpList[pm.JumpIndex] as Item).Map);
                                pm.JumpIndex++;
                            }
                            else
                            {
                                if ((pm.JumpList[pm.JumpIndex] as Item).RootParent != null)
                                {
                                    if ((pm.JumpList[pm.JumpIndex] as Item).RootParent is Item)
                                    {
                                        Item ix = (pm.JumpList[pm.JumpIndex] as Item).RootParent as Item;
                                        e.Mobile.Location = ix.Location;
                                    }
                                    else
                                    {
                                        Mobile mx = (pm.JumpList[pm.JumpIndex] as Item).RootParent as Mobile;
                                        e.Mobile.Location = mx.Location;
                                    }
                                }
                                else
                                {
                                    Item ix = (Item)pm.JumpList[pm.JumpIndex];
                                    e.Mobile.Location = ix.Location;
                                }
                                e.Mobile.SendMessage("there.");
                                pm.JumpIndex++;
                            }
                        }
                        else if (pm.JumpList[pm.JumpIndex] is Mobile)
                        {
                            if ((pm.JumpList[pm.JumpIndex] as Mobile).Map == Map.Internal)
                            {
                                e.Mobile.SendMessage("Mobile {0} is on the {1} map", (pm.JumpList[pm.JumpIndex] as Mobile), (pm.JumpList[pm.JumpIndex] as Mobile).Map);
                                pm.JumpIndex++;
                            }
                            else
                            {
                                Mobile ix = (Mobile)pm.JumpList[pm.JumpIndex];
                                e.Mobile.Location = ix.Location;
                                e.Mobile.SendMessage("there.");
                                pm.JumpIndex++;
                            }
                        }
                    }
                    else
                    {
                        e.Mobile.SendMessage("You are at the end of your jump list, returning to top.");
                        pm.JumpIndex = 0;
                    }
                }
                else
                {
                    e.Mobile.SendMessage("Your jump list is empty.");
                }
            }
            catch (Exception ex)
            {
                e.Mobile.SendMessage("Jump List Exception.");
                LogHelper.LogException(ex);
            }
        }
        public override void Execute(CommandEventArgs e, object obj)
        {
            PlayerMobile pm   = obj as PlayerMobile;
            Mobile       from = e.Mobile;

            try
            {
                if (pm != null)
                {
                    NetState ns = pm.NetState;
                    if (ns == null)
                    {
                        from.SendMessage("That player is no longer online.");
                        return;
                    }
                    Server.Accounting.Account pmAccount = (Server.Accounting.Account)pm.Account;
                    HardwareInfo pmHWInfo = pmAccount.HardwareInfo;

                    from.SendMessage("{0}/{1}: Finding possible multi-clients (IP: {2}, CV: {3})",
                                     pmAccount.Username, pm.Name, ns.Address.ToString(), ns.Version.ToString());

                    //ArrayList netStates = NetState.Instances;
                    List <NetState> netStates = NetState.Instances;

                    for (int i = 0; i < netStates.Count; i++)
                    {
                        NetState compState = netStates[i];

                        //guard against NetStates which haven't completely logged in yet
                        if (compState == null ||
                            compState.Address == null ||
                            compState.Mobile == null)
                        {
                            continue;
                        }

                        if (ns.Address.Equals(compState.Address))
                        {
                            if (compState.Mobile != pm)
                            {
                                Server.Accounting.Account compAcct = (Server.Accounting.Account)compState.Mobile.Account;
                                string clientName = string.Format("{0}/{1}", compAcct.Username, compState.Mobile.Name);

                                HardwareInfo compHWInfo = compAcct.HardwareInfo;

                                from.SendMessage("{0}: Same IP Address ({1})", clientName, compState.Address.ToString());

                                //Found another client from same IP, check client version
                                if (ns.Version.CompareTo(compState.Version) == 0)
                                {
                                    from.SendMessage("{0}: Same Client Version: {1}", clientName, compState.Version.ToString());
                                }
                                else
                                {
                                    from.SendMessage("{0}: Different Client Version: {1}", clientName, compState.Version.ToString());
                                }

                                //Check HWInfo
                                if (pmHWInfo == null && compHWInfo == null)
                                {
                                    from.SendMessage("{0}+{1}: BOTH Hardware UNKNOWN", pm.Name, clientName);
                                }
                                else if (pmHWInfo == null || (pmHWInfo.CpuClockSpeed == 0 && pmHWInfo.OSMajor == 0))
                                {
                                    from.SendMessage("{0}: Hardware UNKNOWN, {1} Known", pm.Name, clientName);
                                }
                                else if (compHWInfo == null || (compHWInfo.CpuClockSpeed == 0 && compHWInfo.OSMajor == 0))
                                {
                                    from.SendMessage("{0}: Hardware UNKNOWN, {1} Known", clientName, pm.Name);
                                }
                                else if (IsSameHWInfo(pmHWInfo, compHWInfo))
                                {
                                    from.SendMessage("{0}: Same Hardware", clientName);
                                }
                                else
                                {
                                    from.SendMessage("{0}: Different Hardware", clientName);
                                }
                            }
                        }
                    }
                }
                else
                {
                    AddResponse("Please target a player.");
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                from.SendMessage("ERROR: Caught exception: " + ex.Message);
            }
        }
示例#5
0
        public override void ExecuteList(CommandEventArgs e, ArrayList list)
        {
            if (list.Count == 0)
            {
                LogFailure("Nothing was found to use this command on.");
                return;
            }

            try
            {
                BaseCommand[]      commands  = new BaseCommand[m_BatchCommands.Count];
                CommandEventArgs[] eventArgs = new CommandEventArgs[m_BatchCommands.Count];

                for (int i = 0; i < m_BatchCommands.Count; ++i)
                {
                    BatchCommand bc = (BatchCommand)m_BatchCommands[i];

                    string   commandString, argString;
                    string[] args;

                    bc.GetDetails(out commandString, out argString, out args);

                    BaseCommand command = (BaseCommand)m_Scope.Commands[commandString];

                    commands[i]  = command;
                    eventArgs[i] = new CommandEventArgs(e.Mobile, commandString, argString, args);

                    if (command == null)
                    {
                        e.Mobile.SendMessage("That is either an invalid command name or one that does not support this modifier: {0}.", commandString);
                        return;
                    }
                    else if (e.Mobile.AccessLevel < command.AccessLevel)
                    {
                        e.Mobile.SendMessage("You do not have access to that command: {0}.", commandString);
                        return;
                    }
                    else if (!command.ValidateArgs(m_Scope, eventArgs[i]))
                    {
                        return;
                    }
                }

                for (int i = 0; i < commands.Length; ++i)
                {
                    BaseCommand  command = commands[i];
                    BatchCommand bc      = (BatchCommand)m_BatchCommands[i];

                    if (list.Count > 20)
                    {
                        CommandLogging.Enabled = false;
                    }

                    ArrayList usedList;

                    if (Utility.InsensitiveCompare(bc.Object, "Current") == 0)
                    {
                        usedList = list;
                    }
                    else
                    {
                        Hashtable propertyChains = new Hashtable();

                        usedList = new ArrayList(list.Count);

                        for (int j = 0; j < list.Count; ++j)
                        {
                            object obj = list[j];

                            if (obj == null)
                            {
                                continue;
                            }

                            Type type = obj.GetType();

                            PropertyInfo[] chain = (PropertyInfo[])propertyChains[type];

                            string failReason = "";

                            if (chain == null && !propertyChains.Contains(type))
                            {
                                propertyChains[type] = chain = Properties.GetPropertyInfoChain(e.Mobile, type, bc.Object, true, ref failReason);
                            }

                            if (chain == null)
                            {
                                continue;
                            }

                            PropertyInfo endProp = Properties.GetPropertyInfo(ref obj, chain, ref failReason);

                            if (endProp == null)
                            {
                                continue;
                            }

                            try
                            {
                                obj = endProp.GetValue(obj, null);

                                if (obj != null)
                                {
                                    usedList.Add(obj);
                                }
                            }
                            catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); }
                        }
                    }

                    command.ExecuteList(eventArgs[i], usedList);

                    if (list.Count > 20)
                    {
                        CommandLogging.Enabled = true;
                    }

                    command.Flush(e.Mobile, list.Count > 20);
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                e.Mobile.SendMessage(ex.Message);
            }
        }
示例#6
0
        private static void PickerCallback(Mobile from, Map map, Point3D start, Point3D end, object state)
        {
            object[]  args          = state as object[];
            string    name          = args[0] as string; // house name
            string    description   = args[1] as string; // house description
            bool      items         = false;             // we capture items separatly
            bool      statics       = true;              // we alwaye want statics when capturing a house
            bool      land          = false;             // we never land tiles when capturing a house
            bool      raw           = (bool)args[2];     // raw capture will ignore BaseHouse info
            bool      no_foundation = (bool)args[3];     // remove the foundation
            bool      range         = (bool)args[4];     // specify Z
            bool      patch         = (bool)args[7];     // create a FixerAddon to patch missing tiles (expensive, don't use unless you must)
            BaseHouse houseInRect   = null;              // when not doing raw capture, we extract data directly from the house

            // normalize bounding rect
            if (start.X > end.X)
            {
                int x = start.X;
                start.X = end.X;
                end.X   = x;
            }
            if (start.Y > end.Y)
            {
                int y = start.Y;
                start.Y = end.Y;
                end.Y   = y;
            }

            // if we have a house here and we're not in 'raw capture' mode, extract
            //  the actual multi rect instead of leaving it up to the user ;p
switching_to_Raw_mode:
            if (raw == false)
            {               // check each tile looking for a house
                for (int ix = start.X; ix < end.X; ix++)
                {
                    for (int iy = start.Y; iy < end.Y; iy++)
                    {
                        Point3D point = new Point3D(ix, iy, 16);
                        houseInRect = BaseHouse.FindHouseAt(point, from.Map, 16);
                        if (houseInRect != null)
                        {                           // get the *real* location/dimentions from the multi
                            from.SendMessage(0x40, "Progress: Found a house at this location, extracting info.");
                            MultiComponentList mcl = houseInRect.Components;
                            int x = houseInRect.X + mcl.Min.X;
                            int y = houseInRect.Y + mcl.Min.Y;
                            start.X = x;
                            end.X   = start.X + mcl.Width;
                            start.Y = y;
                            end.Y   = start.Y + mcl.Height;
                            // for houses with plots, use the plot dimentions
                            if (houseInRect is HouseFoundation)
                            {                                   // patch width based on plot size and not multi
                                int MultiID = houseInRect.ItemID;
                                int width = 0; int height = 0;
                                StaticHouseHelper.GetFoundationSize(MultiID, out width, out height);
                                end.X = start.X + width;
                                end.Y = start.Y + height;
                            }
                            goto exit_house_info;
                        }
                    }
                }

                // if we can't find a house here, switch to raw capture mode
                if (houseInRect == null)
                {
                    from.SendMessage(0x40, "Info: No house at this location, switching to Raw mode.");
                    raw = true;
                    goto switching_to_Raw_mode;
                }
            }
            // we're in raw capture mode, help the user by snapping to the next valid plot size
            //	if the rect they selected is not a valid size
            else
            {
                if (!StaticHouseHelper.IsFoundationSizeValid(end.X - start.X, end.Y - start.Y))
                {
                    int tempWidth = end.X - start.X;
                    int tempHeight = end.Y - start.Y;
                    int ix = 0, iy = 0;
                    while (true)
                    {
                        if (StaticHouseHelper.IsFoundationSizeValid(tempWidth + ix, tempHeight))
                        {
                            end.X += ix;
                            from.SendMessage(0x40, String.Format("Info: Snapping to next leagal X plot size."));
                            goto exit_house_info;
                        }
                        else if (StaticHouseHelper.IsFoundationSizeValid(tempWidth, tempHeight + iy))
                        {
                            end.Y += iy;
                            from.SendMessage(0x40, String.Format("Info: Snapping to next leagal Y plot size."));
                            goto exit_house_info;
                        }

                        if (ix == 18 && iy == 18)
                        {
                            break;                                                      // we should exit before hitting this case
                        }
                        if (ix < 18)
                        {
                            ix++;                                                                       // next valid X
                        }
                        if (iy < 18)
                        {
                            iy++;                                                                       // next valid Y
                        }
                    }
                }
            }

            // we now have the 'perfect' rect for BaseHouse being captured.
exit_house_info:

            // do we have a valid plot size?
            if (!StaticHouseHelper.IsFoundationSizeValid(end.X - start.X, end.Y - start.Y))
            {
                from.SendMessage(0x22, "Error: House size " + Convert.ToString(end.X - start.X) + "x" + Convert.ToString(end.Y - start.Y) + " is invalid!");
                from.SendGump(new InternalGump(from, (object[])state));
                return;
            }
            else
            {
                from.SendMessage(0x40, String.Format("Info: Selected plot size {0}x{1}.", end.X - start.X, end.Y - start.Y));
            }

            // calc price based on plot size
            // THIS is the portion an NPC architect will refund... not the tile(plot size) assessment
            //	added below.
            int BasePrice = StaticHouseHelper.GetBasePrice(end.X - start.X, end.Y - start.Y);

            //pla: Check if the house blueprint file already exists, and if not then create one
            if (!Directory.Exists("Data"))
            {
                Directory.CreateDirectory("Data");
            }

            if (!File.Exists(StaticHouseHelper.BlueprintDatabase))
            {
                using (XmlTextWriter writer = new XmlTextWriter(StaticHouseHelper.BlueprintDatabase, System.Text.Encoding.Unicode))
                {
                    writer.WriteStartElement("StaticHousing");
                    writer.WriteEndElement();
                }
            }

            //pla: Create document object for manipulation
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(StaticHouseHelper.BlueprintDatabase);
            if (xmlDoc == null)
            {
                return;
            }

            // version of this XML format
            //  do not confuse this version with the version of the house.
            XmlNode root                    = xmlDoc.FirstChild;
            double  formatVersion           = 1.0;
            XmlAttributeCollection attrColl = root.Attributes;
            XmlAttribute           attr     = null;

            if (attrColl != null)
            {
                attr = (XmlAttribute)attrColl.GetNamedItem("Version");
            }
            if (attr == null)
            {               // we don't have a version stamp, add one
                XmlNode vattr = xmlDoc.CreateNode(XmlNodeType.Attribute, "Version", "");
                vattr.Value = formatVersion.ToString();
                root.Attributes.SetNamedItem(vattr);
            }

            // a new house
            XmlElement  newHouse = xmlDoc.CreateElement("HouseID");
            Rectangle2D bounds   = new Rectangle2D(start, end);

            // house name
            XmlElement nameElement = xmlDoc.CreateElement("id");

            nameElement.InnerText = name;
            newHouse.AppendChild(nameElement);

            // house description
            //	a deed name is constructed as follows:
            //	"deed to a " + sh.Description
            //	an example name: "deed to a marble house with patio"
            XmlElement descriptionElement = xmlDoc.CreateElement("Description");

            if (description != null && description.Length > 0)
            {
                descriptionElement.InnerText = description;
            }
            else
            {
                descriptionElement.InnerText = "(none)";
            }
            newHouse.AppendChild(descriptionElement);

            // version of the house.
            //  do not confuse with the version of this XML format
            //  this is not the XML format of the house either, it's the construction version
            //	Displayed in the House Gump.
            double     houseVersion        = 1.0;
            XmlElement houseVersionElement = xmlDoc.CreateElement("Version");

            houseVersionElement.InnerText = houseVersion.ToString();
            newHouse.AppendChild(houseVersionElement);

            // Date/Time this version of this house was captured
            //	Displayed in the House Gump.
            DateTime   CaptureDate    = DateTime.Now;
            XmlElement CaptureElement = xmlDoc.CreateElement("Capture");

            CaptureElement.InnerText = CaptureDate.ToString();
            newHouse.AppendChild(CaptureElement);

            // Record region info
            //	we will also capture the (HouseRegion) region info. We don't like the dumb
            //	complete-plot-is-the-region system introduced with Custom Housing, but prefer
            //	the old-school OSI bodle where the region is an array of well defined rects.
            //	we use the rect editing tools on copy1 of the Custom House, then recapture to
            //	record the region info
            if (raw == false && houseInRect != null)
            {
                Region r = houseInRect.Region;
                if (!(r == null || r.Coords == null || r.Coords.Count == 0))
                {
                    ArrayList c = r.Coords;

                    XmlElement regionElement = xmlDoc.CreateElement("Region");
                    XmlElement rectElement   = null;
                    for (int i = 0; i < c.Count; i++)
                    {
                        if (c[i] is Rectangle2D)
                        {
                            int width  = ((Rectangle2D)(c[i])).Width;
                            int height = ((Rectangle2D)(c[i])).Height;
                            int x      = ((Rectangle2D)(c[i])).Start.X - start.X;
                            int y      = ((Rectangle2D)(c[i])).Start.Y - start.Y;
                            if (x < 0)
                            {
                                x = 0;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }

                            XmlElement CoordsElement = xmlDoc.CreateElement("Rectangle2D");

                            rectElement           = xmlDoc.CreateElement("x");
                            rectElement.InnerText = x.ToString();
                            CoordsElement.AppendChild(rectElement);

                            rectElement           = xmlDoc.CreateElement("y");
                            rectElement.InnerText = y.ToString();
                            CoordsElement.AppendChild(rectElement);

                            rectElement           = xmlDoc.CreateElement("width");
                            rectElement.InnerText = width.ToString();
                            CoordsElement.AppendChild(rectElement);

                            rectElement           = xmlDoc.CreateElement("height");
                            rectElement.InnerText = height.ToString();
                            CoordsElement.AppendChild(rectElement);

                            regionElement.AppendChild(CoordsElement);
                        }
                    }

                    newHouse.AppendChild(regionElement);
                }
            }

            sbyte min = sbyte.MinValue;
            sbyte max = sbyte.MaxValue;

            try { min = sbyte.Parse(args[5] as string); }
            catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); }
            try { max = sbyte.Parse(args[6] as string); }
            catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); }

            if (max < min)
            {
                sbyte temp = max;
                max = min;
                min = temp;
            }

            Hashtable tiles = new Hashtable();

            // (x == end.X || y == end.Y) will be steps or other deco outside the plot
            // see below where we output statics and set TileType 'flags'
            if (statics)
            {
                for (int x = start.X; x <= end.X; x++)
                {
                    for (int y = start.Y; y <= end.Y; y++)
                    {
                        ArrayList list = map.GetTilesAt(new Point2D(x, y), items, land, statics);

                        if (range)
                        {
                            ArrayList remove = new ArrayList();

                            foreach (Tile t in list)
                            {
                                if (t.Z < min || t.Z > max)
                                {
                                    remove.Add(t);
                                }
                            }

                            foreach (Tile t in remove)
                            {
                                list.Remove(t);
                            }
                        }

                        if (list != null && list.Count > 0)
                        {
                            tiles[new Point2D(x, y)] = list;
                        }
                    }
                }
            }

            // we increase the bounds by one here to match the way we scan for static above, that is: including end.X and end.Y
            //	the end.X and end.Y allows us to pick up things on the steps, and the house sign hanger
            Rectangle2D       iBounds = new Rectangle2D(bounds.X, bounds.Y, bounds.Width + 1, bounds.Height + 1);
            IPooledEnumerable en      = map.GetItemsInBounds(iBounds);
            ArrayList         target  = new ArrayList();
            bool foundSign            = false;

            // info pulled from captured house
            DateTime BuiltOn              = DateTime.MaxValue;
            string   OriginalOwnerName    = "(unknown)";
            string   OriginalOwnerAccount = "(unknown)";
            Serial   OriginalOwnerSerial  = Serial.MinusOne;
            Point3D  SignLocation         = Point3D.Zero;       // not used
            int      SignHangerGraphic    = 0xB98;              // default
            int      SignpostGraphic      = 0x09;               // default

            try
            {
                // (x == end.X || y == end.Y) will be steps or other deco outside the plot
                // see below where we output statics and set TileType 'flags'
                foreach (object o in en)
                {
                    // remove all doors
                    if (o is BaseDoor)
                    {
                        from.SendMessage(0x40, "Progress: removing door.");
                        continue;
                    }

                    // Remove SignHanger from the outside of a Custom House
                    //	we look for it at a particular location
                    if (raw == false && houseInRect != null && houseInRect is HouseFoundation == true)
                    {
                        if (IsSignHanger(o) && (o as Item).Y == bounds.Y + bounds.Height)
                        {
                            from.SendMessage(0x40, "Progress: removing sign hanger.");
                            SignHangerGraphic = (o as Item).ItemID;
                            continue;
                        }
                    }

                    // Remove Signpost  from the outside of a Custom House
                    //	we look for it at a particular location
                    if (raw == false && houseInRect != null && houseInRect is HouseFoundation == true)
                    {
                        if (IsSignpost(o) && (o as Item).Y == bounds.Y + bounds.Height - 1)
                        {
                            from.SendMessage(0x40, "Progress: removing Signpost.");
                            SignpostGraphic = (o as Item).ItemID;
                            continue;
                        }
                    }

                    // any BaseHouse
                    if (o is HouseSign)
                    {                       // suck the meaningful info from the house sign
                        from.SendMessage(0x40, "Progress: Processing house sign.");
                        HouseSign sign  = o as HouseSign;
                        BaseHouse house = sign.Structure;
                        if (house != null)
                        {                           // from house
                            BuiltOn = house.BuiltOn;
                        }
                        // from sign
                        OriginalOwnerName    = sign.Owner.Name;
                        OriginalOwnerAccount = sign.Owner.Account.ToString();
                        OriginalOwnerSerial  = sign.Owner.Serial;
                        SignLocation         = sign.Location;
                        foundSign            = true;
                        continue;
                    }

                    // GM built or OSI town static structure
                    if (o is StaticHouseSign)
                    {                       // suck the meaningful info from the house sign
                        from.SendMessage(0x40, "Progress: Processing static house sign.");
                        StaticHouseSign sign = o as StaticHouseSign;
                        // from sign
                        BuiltOn              = sign.BuiltOn;
                        OriginalOwnerName    = sign.Owner.Name;
                        OriginalOwnerAccount = sign.Owner.Account.ToString();
                        OriginalOwnerSerial  = sign.Owner.Serial;
                        SignLocation         = sign.Location;
                        foundSign            = true;
                        continue;
                    }

                    // outside the rect?
                    if (range && ((o as Static).Z < min || (o as Static).Z > max))
                    {
                        continue;
                    }

                    target.Add(o);
                }

                // on OSI houses the sign falls outside the multi-rect
                if (raw == false && houseInRect != null && foundSign == false)
                {
                    // suck the meaningful info from the house sign
                    from.SendMessage(0x40, "Progress: Processing house sign.");
                    HouseSign sign  = houseInRect.Sign;
                    BaseHouse house = sign.Structure;
                    if (house != null)
                    {                       // from house
                        BuiltOn = house.BuiltOn;
                    }
                    // from sign
                    OriginalOwnerName    = sign.Owner.Name;
                    OriginalOwnerAccount = sign.Owner.Account.ToString();
                    OriginalOwnerSerial  = sign.Owner.Serial;
                    SignLocation         = sign.Location;
                    foundSign            = true;
                }
            }
            catch (Exception er)
            {
                LogHelper.LogException(er);
                Console.WriteLine(er.ToString());
                from.SendMessage(0x40, "Info: The targeted items have been modified. Please retry.");
                return;
            }
            finally
            {
                en.Free();
            }

            // captured houses need a sign. for static houses, [add StaticHouseSign and set props
            // we also use the location if the sign as the location for the real sign during construction
            if (foundSign == false)
            {
                from.SendMessage(0x22, "Warning: No StaticHouseSign found for static house.");
                from.SendMessage(0x22, "Warning: [add StaticHouseSign and set props.");
                // don't fail.. assume the XML will be hand edited
            }

            if (target.Count == 0 && tiles.Keys.Count == 0)
            {
                from.SendMessage(0x22, "Error: No items have been selected.");
                return;
            }

            /* -- save the house builder / designed info --
             * BuiltOn = sign.BuiltOn;
             * OriginalOwnerName = sign.OriginalOwner.Name;
             * OriginalOwnerAccount = sign.OriginalOwner.Account.ToString();
             * OriginalOwnerSerial = sign.OriginalOwner.Serial;
             * SignLocation = sign.Location;
             */

            // Date/Time this version of this house was created
            //	Displayed in the House Gump as the revision date
            XmlElement BuiltOnElement = xmlDoc.CreateElement("BuiltOn");

            CaptureElement.InnerText = BuiltOn.ToString();
            newHouse.AppendChild(CaptureElement);

            // OriginalOwnerName
            //	Displayed in the House Gump.
            XmlElement OriginalOwnerNameElement = xmlDoc.CreateElement("OriginalOwnerName");

            OriginalOwnerNameElement.InnerText = OriginalOwnerName.ToString();
            newHouse.AppendChild(OriginalOwnerNameElement);

            // OriginalOwnerAccount
            XmlElement OriginalOwnerAccountElement = xmlDoc.CreateElement("OriginalOwnerAccount");

            OriginalOwnerAccountElement.InnerText = OriginalOwnerAccount.ToString();
            newHouse.AppendChild(OriginalOwnerAccountElement);

            // OriginalOwnerSerial
            //	Displayed in the House Gump as the 'designer's licence number'
            XmlElement OriginalOwnerSerialElement = xmlDoc.CreateElement("OriginalOwnerSerial");

            OriginalOwnerSerialElement.InnerText = OriginalOwnerSerial.ToString();
            newHouse.AppendChild(OriginalOwnerSerialElement);

            // SignLocation
            //	not used
            XmlElement SignLocationElement = xmlDoc.CreateElement("SignLocation");

            SignLocationElement.InnerText = "(unused)" + SignLocation.ToString();
            newHouse.AppendChild(SignLocationElement);

            // SignHangerGraphic
            XmlElement SignHangerGraphicElement = xmlDoc.CreateElement("SignHangerGraphic");

            SignHangerGraphicElement.InnerText = SignHangerGraphic.ToString();
            newHouse.AppendChild(SignHangerGraphicElement);

            // SignpostGraphic
            XmlElement SignpostGraphicElement = xmlDoc.CreateElement("SignpostGraphic");

            SignpostGraphicElement.InnerText = SignpostGraphic.ToString();
            newHouse.AppendChild(SignpostGraphicElement);

            // Get center
            Point3D center = new Point3D();

            center.Z = 127;

            int x1 = bounds.End.X;
            int y1 = bounds.End.Y;
            int x2 = bounds.Start.X;
            int y2 = bounds.Start.Y;

            // Get correct bounds
            foreach (object o in target)
            {
                Item item = o as Item;
                if (item == null)
                {
                    continue;
                }

                // don't factor these tiles as they are outside the bounding rect.
                //	(steps most likely)
                if (item.X >= end.X || item.Y >= end.Y)
                {
                    continue;
                }

                if (item.Z < center.Z)
                {
                    center.Z = item.Z;
                }

                x1 = Math.Min(x1, item.X);
                y1 = Math.Min(y1, item.Y);
                x2 = Math.Max(x2, item.X);
                y2 = Math.Max(y2, item.Y);
            }

            // Get correct bounds
            foreach (Point2D p in tiles.Keys)
            {
                ArrayList list = tiles[p] as ArrayList;

                // don't factor these tiles as they are outside the bounding rect.
                //	(steps most likely)
                if (p.X >= end.X || p.Y >= end.Y)
                {
                    continue;
                }

                foreach (Tile t in list)
                {
                    if (t.Z < center.Z)
                    {
                        center.Z = t.Z;
                    }
                }

                x1 = Math.Min(x1, p.X);
                y1 = Math.Min(y1, p.Y);
                x2 = Math.Max(x2, p.X);
                y2 = Math.Max(y2, p.Y);
            }

            center.X = x1 + ((x2 - x1) / 2);
            center.Y = y1 + ((y2 - y1) / 2);

            // width
            int        PlotWidth    = end.X - start.X;
            XmlElement widthElement = xmlDoc.CreateElement("Width");

            widthElement.InnerText = PlotWidth.ToString();
            newHouse.AppendChild(widthElement);

            // height
            int        PlotHeight    = end.Y - start.Y;
            XmlElement heightElement = xmlDoc.CreateElement("Height");

            heightElement.InnerText = PlotHeight.ToString();
            newHouse.AppendChild(heightElement);

            XmlElement multiElement = xmlDoc.CreateElement("Multi");
            XmlElement tempElement  = null;
            ArrayList  tileTable    = new ArrayList();

            // Statics - add to master list
            foreach (Point2D p in tiles.Keys)
            {
                ArrayList list = tiles[p] as ArrayList;

                int xOffset = p.X - center.X;
                int yOffset = p.Y - center.Y;
                StaticHouseHelper.TileType flags = StaticHouseHelper.TileType.Normal;

                // mark these tiles as existing outside the bounding rect (steps most likely)
                if (p.X >= end.X || p.Y >= end.Y)
                {
                    flags |= StaticHouseHelper.TileType.OutsideRect;
                }

                foreach (Tile t in list)
                {
                    int zOffset = t.Z - center.Z;
                    int id      = t.ID & 0x3FFF;

                    Unit unit = new Unit(xOffset, yOffset, zOffset, id, flags);
                    bool add  = true;

                    foreach (Unit existing in tileTable)
                    {
                        if (existing.m_xOffset == unit.m_xOffset &&
                            existing.m_yOffset == unit.m_yOffset &&
                            existing.m_zOffset == unit.m_zOffset)
                        {
                            if (existing.m_id == unit.m_id)
                            {
                                add = false;
                                break;
                            }
                            else
                            {
                                if (patch == true)
                                {
                                    unit.m_flags |= StaticHouseHelper.TileType.Overlapped;
                                }
                            }
                        }
                    }

                    // only add if unique
                    if (add == true)
                    {
                        tileTable.Add(unit);
                    }
                    else
                    {
                        from.SendMessage(0x40, "Progress: Ignoring duplicate tile.");
                    }
                }
            }

            // Items - add to master list
            foreach (Object o in target)
            {
                Item item = o as Item;
                if (item == null)
                {
                    continue;
                }

                int xOffset = item.X - center.X;
                int yOffset = item.Y - center.Y;
                int zOffset = item.Z - center.Z;
                int id      = item.ItemID;
                StaticHouseHelper.TileType flags = StaticHouseHelper.TileType.Normal;

                // aftermarket addons are 'patched' later
                if (item is AddonComponent || item is StaticHouseHelper.FixerAddon)
                {
                    flags |= StaticHouseHelper.TileType.Patch;
                }

                // mark these tiles as existing outside the bounding rect (steps most likely)
                if (item.X >= end.X || item.Y >= end.Y)
                {
                    flags |= StaticHouseHelper.TileType.OutsideRect;
                }

                Unit unit = new Unit(xOffset, yOffset, zOffset, id, flags);
                bool add  = true;

                foreach (Unit existing in tileTable)
                {
                    if (existing.m_xOffset == unit.m_xOffset &&
                        existing.m_yOffset == unit.m_yOffset &&
                        existing.m_zOffset == unit.m_zOffset)
                    {
                        if (existing.m_id == unit.m_id)
                        {
                            if ((unit.m_flags & StaticHouseHelper.TileType.Patch) != 0)                                         // if the one we are trying the add is a patch..
                            {
                                existing.m_flags |= StaticHouseHelper.TileType.Patch;                                           // convert the existing one to the patch and don't add this one
                            }
                            add = false;
                            break;
                        }
                        else
                        {
                            if (patch == true)
                            {
                                unit.m_flags |= StaticHouseHelper.TileType.Overlapped;
                            }
                        }
                    }
                }

                // only add if unique
                if (add == true)
                {
                    tileTable.Add(unit);
                }
                else
                {
                    from.SendMessage(0x40, "Progress: Ignoring duplicate tile.");
                }
            }

            // Preprocess the list - pass I
            ArrayList removeList = new ArrayList();

            foreach (Unit unit in tileTable)
            {
                Item o = new Item(unit.m_id);

                // remove the foundation and fixup the
                if (no_foundation == true)
                {
                    if (unit.m_zOffset == 0)
                    {
                        // remove foundation tiles
                        if (unit.m_xOffset == start.X - center.X ||
                            unit.m_yOffset == start.Y - center.Y ||
                            unit.m_xOffset == (end.X - center.X) - 1 ||
                            unit.m_yOffset == (end.Y - center.Y) - 1)
                        {
                            removeList.Add(unit);
                        }

                        // steps
                        if ((unit.m_flags & StaticHouseHelper.TileType.OutsideRect) != 0)
                        {
                            removeList.Add(unit);
                        }
                    }
                    // dirt tiles
                    else if (unit.m_zOffset == 7 && unit.m_id == 12788)
                    {
                        removeList.Add(unit);
                    }
                    else
                    {
                        // move all tiles down 7
                        //	bug: when we move down 7, tiles at 0 get clipped.
                        unit.m_zOffset -= 7;
                    }
                }

                // Remove SignHanger on outside of an OSI house
                if (raw == false && houseInRect != null && houseInRect is HouseFoundation == false)
                {
                    if (IsSignHanger(o) && unit.m_yOffset * 2 == PlotHeight)
                    {
                        from.SendMessage(0x40, "Progress: removing sign hanger.");
                        removeList.Add(unit);
                    }
                }

                // remove all doors
                if (o is BaseDoor)
                {
                    from.SendMessage(0x40, "Progress: removing door.");
                    removeList.Add(unit);
                }
            }

            // preprocess - pass II
            //	remove / process all things found in pass I
            foreach (Unit unit in removeList)
            {
                if (tileTable.Contains(unit))
                {
                    tileTable.Remove(unit);
                }
            }

            // house price
            //	price is a base price based on the plot size + a per tile cost (PTC).
            //	PTC is greater as the plot gets bigger .. this will encourage smaller houses, and 'tax' the big land hogs.
            //	the numbers were heuristically derived by looking at a very large and complex 18x18 and deciding that we wanted to add
            //	about 1,000,000 to the price, then dividing that by the number of tiles on this house (1130) and came up with a cost of approx
            //	885 per tile. We then use the logic 18x18 = 36 and 885/32 == 24 which gives us the base PTC. We then multiply
            //	24 * (width + height) to get the actual PTC for this house.
            //	so using this system above, a small 8x8 house has a PTC of 384 where a large 18x18 has a pertile cost of 864
            int        price        = BasePrice + (tileTable.Count * (24 * (PlotWidth + PlotWidth)));
            XmlElement priceElement = xmlDoc.CreateElement("Price");

            priceElement.InnerText = BasePrice.ToString();
            newHouse.AppendChild(priceElement);

            // Okay, write out all tile data
            foreach (Unit unit in tileTable)
            {
                XmlElement singleMultiElement = xmlDoc.CreateElement("Graphic");

                tempElement           = xmlDoc.CreateElement("id");
                tempElement.InnerText = unit.m_id.ToString();
                singleMultiElement.AppendChild(tempElement);

                tempElement           = xmlDoc.CreateElement("x");
                tempElement.InnerText = unit.m_xOffset.ToString();
                singleMultiElement.AppendChild(tempElement);

                tempElement           = xmlDoc.CreateElement("y");
                tempElement.InnerText = unit.m_yOffset.ToString();
                singleMultiElement.AppendChild(tempElement);

                tempElement           = xmlDoc.CreateElement("z");
                tempElement.InnerText = unit.m_zOffset.ToString();
                singleMultiElement.AppendChild(tempElement);

                tempElement           = xmlDoc.CreateElement("flags");
                tempElement.InnerText = ((int)unit.m_flags).ToString();
                singleMultiElement.AppendChild(tempElement);

                multiElement.AppendChild(singleMultiElement);
            }

            // stats

            /*int total = tileTable.Count, deco = 0, patch = 0;
             * foreach (Unit existing in tileTable)
             * {
             *      //StaticHouseHelper.TileType flags = StaticHouseHelper.TileType.Normal;
             *      //StaticHouseHelper.TileType.OutsideRect;
             *      //StaticHouseHelper.TileType.Overlapped;
             *      if (existing.m_flags & StaticHouseHelper.TileType.OutsideRect != 0)
             *              deco++;
             *
             *      if (existing.m_flags & StaticHouseHelper.TileType.Overlapped != 0)
             *              patch++;
             * }
             * from.SendMessage(String.Format("{0} total tiles of which {1} were outside the foundation and {2} were patch tiles.",total, deco, patch));*/

            newHouse.AppendChild(multiElement);
            xmlDoc["StaticHousing"].AppendChild(newHouse);
            xmlDoc.Save(StaticHouseHelper.BlueprintDatabase);
            from.SendMessage("Blueprint creation successful");

            // give the GM a deed to test with
            from.SendMessage("A deed has been placed in your backpack");
            from.AddToBackpack(new StaticDeed(name, description));
        }
示例#7
0
            private static bool Verify(Mobile from, object[] state)
            {
                // error: name
                if (state[0] == null || (state[0] as string).Length == 0)
                {
                    from.SendMessage(0x22, "Error: You must specify a name for your blueprint.");
                    return(false);
                }

                // warning: Description
                if (state[1] == null || (state[1] as string).Length == 0)
                {
                    from.SendMessage(0x22, "Warning: You should specify a description for this house.");
                    // continue, only a warning
                }

                //pla: Check if this name is already taken
                try
                {
                    if (StaticHouseHelper.IsBlueprintInFile(state[0] as string))
                    {
                        from.SendMessage(0x22, "Error: A blueprint by that name already exists.");
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.LogException(ex);
                    from.SendMessage(0x22, "Error: Unknown blueprint generation error.");
                    return(false);
                }

                bool  raw        = (bool)state[2];
                bool  foundation = (bool)state[3];
                bool  range      = (bool)state[4];
                bool  patch      = (bool)state[7];
                sbyte min        = sbyte.MinValue;
                sbyte max        = sbyte.MaxValue;
                bool  fail       = false;

                try
                {
                    min = sbyte.Parse(state[5] as string);
                }
                catch
                {
                    from.SendMessage(0x22, "Error: Bad min Z specified.");
                    fail = true;
                }

                try
                {
                    max = sbyte.Parse(state[6] as string);
                }
                catch
                {
                    from.SendMessage(0x22, "Error: Bad max Z specified.");
                    fail = true;
                }

                // error already reported
                if (range && fail)
                {
                    return(false);
                }

                if (raw == true)
                {
                    from.SendMessage(0x40, "Info: Raw capture will ignore house data.");
                }

                return(true);
            }
示例#8
0
        public static void On_RHFile(CommandEventArgs e)
        {
            if (e.Arguments.Length != 1)
            {
                e.Mobile.SendMessage("Usage: [LoadCont <filename>");
                return;
            }

            try
            {
                int       loaded = 0;
                int       count;
                LogHelper log = new LogHelper(e.Arguments[0] + " LoadCont.log");
                log.Log(LogType.Text, String.Format("Reload process initiated by {0}, with {1} as backup data.", e.Mobile, e.Arguments[0]));

                using (FileStream idxfs = new FileStream(e.Arguments[0] + ".idx", FileMode.Open, FileAccess.Read))
                {
                    using (FileStream binfs = new FileStream(e.Arguments[0] + ".bin", FileMode.Open, FileAccess.Read))
                    {
                        GenericReader bin = new BinaryFileReader(new BinaryReader(binfs));
                        GenericReader idx = new BinaryFileReader(new BinaryReader(idxfs));

                        count = idx.ReadInt();
                        if (count == -1)
                        {
                            log.Log(LogType.Text, "No item data to reload.");                             // do nothing
                        }
                        else
                        {
                            ArrayList items = new ArrayList(count);
                            log.Log(LogType.Text, String.Format("Attempting to reload {0} items.", count));

                            Type[]   ctortypes = new Type[] { typeof(Serial) };
                            object[] ctorargs  = new object[1];

                            for (int i = 0; i < count; i++)
                            {
                                string type     = idx.ReadString();
                                Serial serial   = (Serial)idx.ReadInt();
                                long   position = idx.ReadLong();
                                int    length   = idx.ReadInt();

                                Type t = ScriptCompiler.FindTypeByFullName(type);
                                if (t == null)
                                {
                                    Console.WriteLine("Warning: Tried to load nonexistent type {0}. Ignoring item.", type);
                                    log.Log(String.Format("Warning: Tried to load nonexistent type {0}. Ignoring item.", type));
                                    continue;
                                }

                                ConstructorInfo ctor = t.GetConstructor(ctortypes);
                                if (ctor == null)
                                {
                                    Console.WriteLine("Warning: Tried to load type {0} which has no serialization constructor. Ignoring item.", type);
                                    log.Log(String.Format("Warning: Tried to load type {0} which has no serialization constructor. Ignoring item.", type));
                                    continue;
                                }

                                Item item = null;
                                try
                                {
                                    if (World.FindItem(serial) != null)
                                    {
                                        log.Log(LogType.Item, World.FindItem(serial), "Serial already in use!! Loading of saved item failed.");
                                    }
                                    else if (!World.IsReserved(serial))
                                    {
                                        log.Log(String.Format("Serial {0} is not reserved!! Loading of saved item failed.", serial));
                                    }
                                    else
                                    {
                                        ctorargs[0] = serial;
                                        item        = (Item)(ctor.Invoke(ctorargs));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.LogException(ex);
                                    Console.WriteLine("An exception occurred while trying to invoke {0}'s serialization constructor.", t.FullName);
                                    Console.WriteLine(ex.ToString());
                                    log.Log(String.Format("An exception occurred while trying to invoke {0}'s serialization constructor.", t.FullName));
                                    log.Log(ex.ToString());
                                }

                                if (item != null)
                                {
                                    World.FreeSerial(serial);

                                    World.AddItem(item);
                                    items.Add(new object[] { item, position, length });
                                    log.Log(String.Format("Successfully created item {0}", item));
                                }
                            }

                            for (int i = 0; i < items.Count; i++)
                            {
                                object[] entry    = (object[])items[i];
                                Item     item     = entry[0] as Item;
                                long     position = (long)entry[1];
                                int      length   = (int)entry[2];

                                if (item != null)
                                {
                                    bin.Seek(position, SeekOrigin.Begin);

                                    try
                                    {
                                        item.Deserialize(bin);

                                        // take care of parent hierarchy
                                        object p = item.Parent;
                                        if (p is Item)
                                        {
                                            ((Item)p).RemoveItem(item);
                                            item.Parent = null;
                                            ((Item)p).AddItem(item);
                                        }
                                        else if (p is Mobile)
                                        {
                                            ((Mobile)p).RemoveItem(item);
                                            item.Parent = null;
                                            ((Mobile)p).AddItem(item);
                                        }
                                        else
                                        {
                                            item.Delta(ItemDelta.Update);
                                        }

                                        item.ClearProperties();

                                        object rp = item.RootParent;
                                        if (rp is Item)
                                        {
                                            ((Item)rp).UpdateTotals();
                                        }
                                        else if (rp is Mobile)
                                        {
                                            ((Mobile)rp).UpdateTotals();
                                        }
                                        else
                                        {
                                            item.UpdateTotals();
                                        }

                                        if (bin.Position != (position + length))
                                        {
                                            throw new Exception(String.Format("Bad serialize on {0}", item));
                                        }

                                        log.Log(LogType.Item, item, "Successfully loaded.");
                                        loaded++;
                                    }
                                    catch (Exception ex)
                                    {
                                        LogHelper.LogException(ex);
                                        Console.WriteLine("Caught exception while deserializing {0}:", item);
                                        Console.WriteLine(ex.ToString());
                                        Console.WriteLine("Deleting item.");
                                        log.Log(String.Format("Caught exception while deserializing {0}:", item));
                                        log.Log(ex.ToString());
                                        log.Log("Deleting item.");
                                        item.Delete();
                                    }
                                }
                            }
                        }
                        idx.Close();
                        bin.Close();
                    }
                }

                Console.WriteLine("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded);
                log.Log(String.Format("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded));
                e.Mobile.SendMessage("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded);
                log.Finish();
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                Console.WriteLine(ex.ToString());
                e.Mobile.SendMessage("Exception: {0}", ex.Message);
            }
        }
示例#9
0
        private static Spawner Load(XmlNode xml)
        {
            Spawner spawner = new Spawner();

            try
            {
                // "Location"
                string location = XmlUtility.GetText(xml["Location"], "(0, 0, 0)");
                spawner.Location = Point3D.Parse(location);

                // "Map"
                string map = XmlUtility.GetText(xml["Map"], "xxx");
                spawner.Map = Map.Parse(map);

                // "Version"
                string version = XmlUtility.GetText(xml["Version"], "0");

                // "NavDest"
                string navDest = XmlUtility.GetText(xml["NavDest"], "0");
                spawner.NavPoint = (Server.Engines.NavDestinations)XmlUtility.GetInt32(navDest, 0);

                // "MobDirection"
                string MobDirection = XmlUtility.GetText(xml["MobDirection"], "0");
                spawner.MobileDirection = (Direction)XmlUtility.GetInt32(MobDirection, 0);

                // "WayPoint" (unsupported)
                string WayPoint = XmlUtility.GetText(xml["WayPoint"], "0");
                //spawner.WayPoint =

                // "Group"
                string Group = XmlUtility.GetText(xml["Group"], "0");
                spawner.Group = XmlUtility.GetInt32(Group, 0) == 1 ? true : false;

                // "MinDelay"
                string MinDelay = XmlUtility.GetText(xml["MinDelay"], "0");
                spawner.MinDelay = TimeSpan.FromSeconds((double)XmlUtility.GetInt32(MinDelay, 0));

                // "MaxDelay"
                string MaxDelay = XmlUtility.GetText(xml["MaxDelay"], "0");
                spawner.MaxDelay = TimeSpan.FromSeconds((double)XmlUtility.GetInt32(MaxDelay, 0));

                // might as well fix this since I'm here
                if (spawner.MinDelay > spawner.MaxDelay)
                {
                    Console.WriteLine("Swapping poorly formed spawner min/max for {0}", spawner.Serial.ToString());
                    TimeSpan temp = spawner.MinDelay;
                    spawner.MinDelay = spawner.MaxDelay;
                    spawner.MaxDelay = temp;
                }

                // "Count"
                string Count = XmlUtility.GetText(xml["Count"], "0");
                spawner.Count = XmlUtility.GetInt32(Count, 0);

                // "Team"
                string Team = XmlUtility.GetText(xml["Team"], "0");
                spawner.Team = XmlUtility.GetInt32(Team, 0);

                // "HomeRange"
                string HomeRange = XmlUtility.GetText(xml["HomeRange"], "0");
                spawner.HomeRange = XmlUtility.GetInt32(HomeRange, 0);

                // "CreatureCount"
                int CreatureCount = XmlUtility.GetInt32(XmlUtility.GetText(xml["CreatureCount"], "0"), 0);
                spawner.ObjectNames = new ArrayList();

                // the creatures
                for (int i = 0; i < CreatureCount; i++)
                {
                    spawner.ObjectNames.Add(XmlUtility.GetText(xml["Line" + i], "?"));
                }

                // "Running"
                string Running = XmlUtility.GetText(xml["Running"], "0");
                spawner.Running = XmlUtility.GetInt32(Running, 0) == 1 ? true : false;

                // "NextSpawn"
                if (spawner.Running)
                {
                    string NextSpawn = XmlUtility.GetText(xml["NextSpawn"], "0");
                    spawner.NextSpawn = TimeSpan.FromSeconds((double)XmlUtility.GetInt32(NextSpawn, 0));
                }

                return(spawner);
            }
            catch (Exception e)
            {
                LogHelper.LogException(e);
                Console.WriteLine("Exception caught loading spawners.xml");
                Console.WriteLine(e.StackTrace);
            }

            return(null);
        }
示例#10
0
            public void GoToPrison()
            {
                try
                {
                    if (m_Player == null || m_Player.Deleted)
                    {
                        return;
                    }

                    Account acct = m_Player.Account as Account;

                    // stable the players pets
                    StablePets(m_Staff, m_Player);

                    // drop holding
                    Item held = m_Player.Holding;
                    if (held != null)
                    {
                        held.ClearBounce();
                        if (m_Player.Backpack != null)
                        {
                            m_Player.Backpack.DropItem(held);
                        }
                    }
                    m_Player.Holding = null;

                    // move their items to the bank, overload if needed
                    Backpack  bag   = new Backpack();
                    ArrayList equip = new ArrayList(m_Player.Items);

                    if (m_Player.Backpack != null)
                    {
                        // count clothing items
                        int WornCount = 0;
                        foreach (Item i in equip)
                        {
                            if (Moongate.RestrictedItem(m_Player, i) == false)
                            {
                                continue;                                       // not clothes
                            }
                            else
                            {
                                WornCount++;
                            }
                        }

                        // Unequip any items being worn
                        foreach (Item i in equip)
                        {
                            if (Moongate.RestrictedItem(m_Player, i) == false)
                            {
                                continue;
                            }
                            else
                            {
                                m_Player.Backpack.DropItem(i);
                            }
                        }

                        // Get a count of all items in the player's backpack.
                        ArrayList items = new ArrayList(m_Player.Backpack.Items);

                        // Drop our new bag in the player's bank
                        m_Player.BankBox.DropItem(bag);

                        // Run through all items in player's pack, move them to the bag we just dropped in the bank
                        foreach (Item i in items)
                        {
                            m_Player.Backpack.RemoveItem(i);
                            bag.DropItem(i);
                        }
                    }

                    // handle imprisoning of logged out players
                    m_Player.MoveToWorld(m_Location, Map.Felucca);
                    if (m_Player.NetState == null)
                    {
                        m_Player.LogoutLocation = m_Location;
                        m_Player.Map            = Map.Internal;
                    }

                    // make them an inmate
                    m_Player.Inmate = true;

                    // Give them a Deathrobe, Stinger dagger, and a blank spell book
                    if (m_Player.Alive)
                    {
                        Item robe = new Server.Items.DeathRobe();
                        if (!m_Player.EquipItem(robe))
                        {
                            robe.Delete();
                        }
                    }

                    Item aiStinger = new Server.Items.AIStinger();
                    if (!m_Player.AddToBackpack(aiStinger))
                    {
                        aiStinger.Delete();
                    }

                    Item spellbook = new Server.Items.Spellbook();
                    if (!m_Player.AddToBackpack(spellbook))
                    {
                        spellbook.Delete();
                    }

                    m_Player.ShortTermCriminalCounts += 3;                                                              // how long you will stay
                    m_Player.LongTermCriminalCounts++;                                                                  // how many times you've been to prison

                    if (!m_Player.Alive && m_Player.NetState != null)
                    {
                        m_Player.CloseGump(typeof(Server.Gumps.ResurrectGump));
                        m_Player.SendGump(new Server.Gumps.ResurrectGump(m_Player, Server.Gumps.ResurrectMessage.Healer));
                    }

                    int sentence = (int)m_Player.ShortTermCriminalCounts * 4;                     // decay time in prison is 4 hours per count
                    m_Player.SendMessage("You have been imprisoned for {0} hours.", sentence);
                    m_Staff.SendMessage("{0} has been imprisoned for {1} hours.", m_Player.Name, sentence);

                    LogHelper Logger = new LogHelper("Prison.log", false, true);

                    Logger.Log(LogType.Mobile, m_Player, string.Format("{0}:{1}:{2}:{3}",
                                                                       m_Staff.Name,
                                                                       m_Staff.Location,
                                                                       m_Comment,
                                                                       sentence));
                    Logger.Finish();

                    Commands.CommandLogging.WriteLine(m_Staff, "{0} imprisoned {1}(Username: {2}) for {4} hours with reason: {3}.",
                                                      m_Staff.Name, m_Player.Name, acct.Username, m_Comment, sentence);
                    acct.Comments.Add(new AccountComment(m_Staff.Name, DateTime.Now + "\nTag count: " + (acct.Comments.Count + 1) + "\nImprisoned for " + sentence + " hours. Reason: " + m_Comment));
                }
                catch (Exception ex)
                {
                    LogHelper.LogException(ex);
                }
            }
示例#11
0
        public void OnTarget(Mobile from, object targeted, object state)
        {
            if (!BaseCommand.IsAccessible(from, targeted))
            {
                from.SendMessage("That is not accessible.");
                return;
            }

            object[]    states  = (object[])state;
            BaseCommand command = (BaseCommand)states[0];

            string[] args = (string[])states[1];

            if (command.ObjectTypes == ObjectTypes.Mobiles)
            {
                return;                 // sanity check
            }
            if (!(targeted is Container))
            {
                from.SendMessage("That is not a container.");
            }
            else
            {
                try
                {
                    ObjectConditional cond = ObjectConditional.Parse(from, ref args);

                    bool items, mobiles;

                    if (!CheckObjectTypes(command, cond, out items, out mobiles))
                    {
                        return;
                    }

                    if (!items)
                    {
                        from.SendMessage("This command only works on items.");
                        return;
                    }

                    Container cont = (Container)targeted;

                    Item[] found;

                    if (cond.Type == null)
                    {
                        found = cont.FindItemsByType(typeof(Item), true);
                    }
                    else
                    {
                        found = cont.FindItemsByType(cond.Type, true);
                    }

                    ArrayList list = new ArrayList();

                    for (int i = 0; i < found.Length; ++i)
                    {
                        if (cond.CheckCondition(found[i]))
                        {
                            list.Add(found[i]);
                        }
                    }

                    RunCommand(from, list, command, args);
                }
                catch (Exception e)
                {
                    LogHelper.LogException(e);
                    from.SendMessage(e.Message);
                }
            }
        }
        public void RunCommand(Mobile from, object obj, BaseCommand command, string[] args)
        {
            try
            {
                CommandEventArgs e = new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args);

                if (!command.ValidateArgs(this, e))
                {
                    return;
                }

                bool flushToLog = false;

                if (obj is ArrayList)
                {
                    ArrayList list = (ArrayList)obj;

                    if (list.Count > 20)
                    {
                        CommandLogging.Enabled = false;
                    }
                    else if (list.Count == 0)
                    {
                        command.LogFailure("Nothing was found to use this command on.");
                    }

                    command.Begin(e);
                    command.ExecuteList(e, list);
                    command.End(e);

                    if (list.Count > 20)
                    {
                        flushToLog             = true;
                        CommandLogging.Enabled = true;
                    }
                }
                else if (obj != null)
                {
                    if (command.ListOptimized)
                    {
                        ArrayList list = new ArrayList();
                        list.Add(obj);
                        command.Begin(e);
                        command.ExecuteList(e, list);
                        command.End(e);
                    }
                    else
                    {
                        command.Begin(e);
                        command.Execute(e, obj);
                        command.End(e);
                    }
                }

                command.Flush(from, flushToLog);
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                from.SendMessage(ex.Message);
            }
        }
示例#13
0
        public static void Announcement_OnCommand(CommandEventArgs e)
        {
            Mobile from = e.Mobile;

            // check arguments
            if (e.Length != 3)
            {
                Usage(from);
                return;
            }

            // can only be run on Test Center
            if (TestCenter.Enabled == false)
            {
                from.SendMessage("This command may only be executed on Test Center.");
                return;
            }

            int iChecked  = 0;
            int Reminders = 0;

            try
            {
                // loop through the accouints looking for current users
                ArrayList results = new ArrayList();

                int days = 0;
                try { days = Convert.ToInt32(e.GetString(0)); }
                catch { Usage(from); return; }

                foreach (Account acct in Accounts.Table.Values)
                {
                    iChecked++;
                    // logged in the last n days.
                    if (Server.Engines.CronScheduler.EmailHelpers.RecentLogin(acct, days) == true)
                    {
                        Reminders++;
                        results.Add(acct.EmailAddress);
                    }
                }

                if (Reminders > 0)
                {
                    from.SendMessage("Sending {0} email announcement(s).", Reminders);

                    string subject = String.Format(e.GetString(1));
                    string body    = null;

                    try
                    {
                        // create reader & open file
                        TextReader tr = new StreamReader(String.Format("Msgs/{0}", e.GetString(2)));

                        // read it
                        body = tr.ReadToEnd();

                        // close the stream
                        tr.Close();
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogException(ex);
                        from.SendMessage(ex.Message);
                        Usage(from);
                        return;
                    }

                    // okay, now hand the list of users off to our mailer daemon
                    new Emailer().SendEmail(results, subject, body, false);
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                System.Console.WriteLine("Exception Caught in generic emailer: " + ex.Message);
                System.Console.WriteLine(ex.StackTrace);
            }

            return;
        }
示例#14
0
        public static void AddressDump_OnCommand(CommandEventArgs e)
        {
            Mobile from = e.Mobile;

            // check arguments
            if (e.Length < 1)
            {
                Usage(from);
                return;
            }

            int iChecked  = 0;
            int Reminders = 0;

            try
            {
                // loop through the accouints looking for current users
                ArrayList results = new ArrayList();

                // assume DaysActive
                if (e.Length == 1 && LooksLikeInt(e.GetString(0)))
                {
                    int days = 0;
                    try { days = Convert.ToInt32(e.GetString(0)); }
                    catch { Usage(from); return; }
                    foreach (Account acct in Accounts.Table.Values)
                    {
                        iChecked++;
                        // logged in the last n days.
                        if (Server.Engines.CronScheduler.EmailHelpers.RecentLogin(acct, days) == true)
                        {
                            if (ValidEmail(acct.EmailAddress))
                            {
                                Reminders++;
                                results.Add(acct.EmailAddress);
                            }
                        }
                    }
                }
                // assume activations since date
                else
                {
                    string buff = null;
                    for (int ix = 0; ix < e.Length; ix++)
                    {
                        buff += e.GetString(ix) + " ";
                    }

                    DateTime Since;
                    try { Since = DateTime.Parse(buff); }
                    catch { Usage(from); return; }

                    foreach (Account acct in Accounts.Table.Values)
                    {
                        iChecked++;
                        // account created since...
                        if (acct.Created >= Since && acct.EmailAddress != null)
                        {
                            if (ValidEmail(acct.EmailAddress))
                            {
                                Reminders++;
                                results.Add(acct.EmailAddress);
                            }
                        }
                    }
                }

                if (Reminders > 0)
                {
                    from.SendMessage("Logging {0} email address(es).", Reminders);
                    LogHelper Logger = new LogHelper("accountEmails.log", true);

                    foreach (object ox in results)
                    {
                        string address = ox as string;
                        if (address == null)
                        {
                            continue;
                        }
                        Logger.Log(LogType.Text, address);
                    }
                    Logger.Finish();
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                System.Console.WriteLine("Exception Caught in generic emailer: " + ex.Message);
                System.Console.WriteLine(ex.StackTrace);
            }

            return;
        }
        public static void ClientMon_OnCommand(CommandEventArgs e)
        {
            try
            {
                if (e.Arguments.Length == 0)
                {
                    e.Mobile.SendMessage("Usage: ClientMon -ui|-ma|-mc|-hi|-ho");
                    e.Mobile.SendMessage("Where: -ui ... Unique IP addresses");
                    e.Mobile.SendMessage("Where: -ma ... total multi accounts");
                    e.Mobile.SendMessage("Where: -mc ... total multi clients");
                    e.Mobile.SendMessage("Where: -hi ... clients that have hardware info");
                    e.Mobile.SendMessage("Where: -ho ... HIGH only. use with -mc");
                    return;
                }

                if (e.ArgString.Contains("-hi"))
                {
                    int clients          = 0;
                    int hardwareInfo     = 0;
                    int badHardwareInfo  = 0;
                    int nullHardwareInfo = 0;
                    foreach (DictionaryEntry de in ClientMon.list)
                    {
                        ArrayList al = de.Value as ArrayList;

                        if (al == null)
                        {
                            continue;
                        }

                        foreach (Account acct in al)
                        {
                            if (acct == null)
                            {
                                continue;                                       // bogus
                            }
                            PlayerMobile pm = GetActiveCharacter(acct);
                            if (pm == null)
                            {
                                continue;                                       // no longer logged in?
                            }
                            NetState ns = pm.NetState;
                            if (ns == null || ns.Address == null || ns.Mobile == null)
                            {
                                continue;                                       // still logging in?
                            }
                            Server.Accounting.Account pmAccount = (Server.Accounting.Account)ns.Account;
                            HardwareInfo pmHWInfo = pmAccount.HardwareInfo;

                            clients++;

                            if (pmHWInfo == null)
                            {
                                nullHardwareInfo++;
                            }
                            else
                            {
                                if (pmHWInfo.CpuClockSpeed == 0 || pmHWInfo.OSMajor == 0)
                                {
                                    badHardwareInfo++;
                                }
                                else
                                {
                                    hardwareInfo++;
                                }
                            }
                        }
                    }

                    e.Mobile.SendMessage(String.Format("{0} total clients, {1} with hardware info", clients, hardwareInfo));
                    e.Mobile.SendMessage(String.Format("{0} with null hardware info, {1} with bad hardware info", nullHardwareInfo, badHardwareInfo));
                }

                if (e.ArgString.Contains("-mc"))
                {
                    bool highOnly = false;
                    if (e.ArgString.Contains("-ho"))
                    {
                        highOnly = true;
                    }

                    foreach (DictionaryEntry de in ClientMon.list)
                    {
                        ArrayList al = de.Value as ArrayList;

                        if (al == null)                                 // bogus
                        {
                            continue;
                        }

                        if (al.Count < 2)                               // no more than 1 account for this IP
                        {
                            continue;
                        }

                        PlayerMobile pm1  = null;
                        PlayerMobile pm2  = null;
                        ArrayList    seen = new ArrayList();
                        foreach (Account acct1 in al)
                        {
                            if (acct1 == null)
                            {
                                continue;                                       // bogus
                            }
                            if (!TestCenter.Enabled && acct1.GetAccessLevel() > AccessLevel.Player)
                            {
                                continue;                                       // ignore staff
                            }
                            pm1 = GetActiveCharacter(acct1);
                            if (pm1 == null)
                            {
                                continue;                                       // logged out maybe?
                            }
                            seen.Add(acct1);

                            foreach (Account acct2 in al)
                            {
                                if (acct2 == null)
                                {
                                    continue;                                           // bogus
                                }
                                if (seen.Contains(acct2))
                                {
                                    continue;                                           // already processed
                                }
                                if (!TestCenter.Enabled && acct2.GetAccessLevel() > AccessLevel.Player)
                                {
                                    continue;                                           // ignore staff
                                }
                                pm2 = GetActiveCharacter(acct2);
                                if (pm2 == null)
                                {
                                    continue;                                           // logged out maybe?
                                }
                                // okay check the hardware and report
                                ProcessMatch(e.Mobile, highOnly, pm1, pm2);
                            }
                        }
                    }
                }

                if (e.ArgString.Contains("-ma"))
                {
                    int clients     = 0;
                    int ipaddresses = 0;
                    foreach (DictionaryEntry de in ClientMon.list)
                    {
                        ArrayList al = de.Value as ArrayList;

                        if (al == null)
                        {
                            continue;
                        }

                        if (al.Count > 1)
                        {
                            clients += al.Count;
                            ipaddresses++;
                        }
                    }

                    if (clients == 0)
                    {
                        e.Mobile.SendMessage("There are no shared IP addresses");
                    }
                    else
                    {
                        e.Mobile.SendMessage(String.Format("There {2} {0} client{3} sharing {1} IP address{4}",
                                                           clients, ipaddresses,
                                                           clients == 1 ? "is" : "are",
                                                           clients == 1 ? "" : "s",
                                                           ipaddresses == 1 ? "" : "es"
                                                           ));
                    }
                }

                if (e.ArgString.Contains("-ui"))
                {
                    e.Mobile.SendMessage(String.Format("There {1} {0} unique IP address{2}",
                                                       ClientMon.list.Count,
                                                       ClientMon.list.Count == 1 ? "is" : "are",
                                                       ClientMon.list.Count == 1 ? "" : "es"
                                                       ));
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
            }

            e.Mobile.SendMessage("done.");
        }
示例#16
0
            protected override void OnTarget(Mobile from, object o)
            {
                try
                {
                    if (from == null)
                    {
                        return;
                    }

                    if (o == null)
                    {
                        from.SendMessage("Target does not exist.");
                        return;
                    }


                    if (o is BaseContainer == false)
                    {
                        from.SendMessage("That is not a container.");
                        return;
                    }

                    BaseContainer bc = o as BaseContainer;

                    if (Misc.Diagnostics.Assert(from.Backpack != null, "from.Backpack == null") == false)
                    {
                        from.SendMessage("You cannot use this deed without a backpack.");
                        return;
                    }

                    // mobile backpacks may not be used
                    if (bc == from.Backpack || bc.Parent is Mobile)
                    {
                        from.SendMessage("You may not use that container.");
                        return;
                    }

                    // must not be locked down
                    if (bc.IsLockedDown == true || bc.IsSecure == true)
                    {
                        from.SendMessage("That container is locked down.");
                        return;
                    }

                    // if it's in your bankbox, or it's in YOUR house, you can deed it
                    if ((bc.IsChildOf(from.BankBox) || CheckAccess(from)) == false)
                    {
                        from.SendMessage("The container must be in your bankbox, or a home you own.");
                        return;
                    }

                    // cannot be in another container
                    if (bc.RootParent is BaseContainer && bc.IsChildOf(from.BankBox) == false)
                    {
                        from.SendMessage("You must remove it from that container first.");
                        return;
                    }

                    // okay, done with target checking, now deed the container.
                    // place a special deed to reclaim the container in the players backpack
                    PlayerQuestDeed deed = new PlayerQuestDeed(bc);
                    if (from.Backpack.CheckHold(from, deed, true, false, 0, 0))
                    {
                        bc.PlayerQuest = true;                                                  // mark as special
                        bc.MoveToWorld(from.Location, Map.Internal);                            // put it on the internal map
                        bc.SetLastMoved();                                                      // record the move (will use this in Heartbeat cleanup)
                        //while (deed.Expires.Hours + deed.Expires.Minutes == 0)
                        //Console.WriteLine("Waiting...");
                        //int hours = deed.Expires.Hours;
                        //int minutes = deed.Expires.Minutes;
                        //string text = String.Format("{0} {1}, and {2} {3}",	hours, hours == 1 ? "hour" : "hours", minutes, minutes == 1 ? "minute" : "minutes");
                        from.Backpack.DropItem(deed);
                        from.SendMessage("A deed for the container has been placed in your backpack.");
                        //from.SendMessage( "This quest will expire in {0}.", text);
                    }
                    else
                    {
                        from.SendMessage("Your backpack is full and connot hold the deed.");
                        deed.Delete();
                    }
                }
                catch (Exception e)
                {
                    LogHelper.LogException(e);
                }
            }
        private static void ProcessMatch(Mobile from, bool highOnly, PlayerMobile pm1, PlayerMobile pm2)
        {
            try
            {               // sanity
                if (from == null || pm1 == null || pm2 == null)
                {
                    return;                     // wtf
                }
                NetState ns1 = pm1.NetState;
                NetState ns2 = pm2.NetState;

                if (ns1 == null || ns2 == null)
                {
                    return;                     // logged out / disconnected
                }
                if (ns1.Address == null || ns1.Mobile == null || ns2.Address == null || ns2.Mobile == null)
                {
                    return;                     // still logging in?
                }
                if (ns1.Account == null || ns2.Account == null)
                {
                    return;                     // error state .. ignore this account
                }
                if (ns1.Account as Server.Accounting.Account == null || ns2.Account as Server.Accounting.Account == null)
                {
                    return;                     // error state .. ignore this account
                }
                Server.Accounting.Account pm1Account = (Server.Accounting.Account)ns1.Account;
                int    pm1HWInfo = pm1Account.HardwareHash;                     // most recent hardware info
                string pm1Name   = string.Format("{0}/{1}", pm1Account.Username, ns1.Mobile.Name);

                Server.Accounting.Account pm2Account = (Server.Accounting.Account)ns2.Account;
                int    pm2HWInfo = pm2Account.HardwareHash;                     // most recent hardware info
                string pm2Name   = string.Format("{0}/{1}", pm2Account.Username, ns2.Mobile.Name);

                alert alarm = alert.LOW;
                if (pm1HWInfo == 0 && pm2HWInfo == 0 && ns1.Version == ns2.Version)
                {
                    // unknown hardware, same client version
                    if (LineOfSight(pm1, pm2))
                    {
                        alarm = alert.MEDIUM;
                    }
                }
                else if (pm1HWInfo == 0 || pm2HWInfo == 0 && ns1.Version == ns2.Version)
                {
                    // unknown hardware, same client version
                    if (LineOfSight(pm1, pm2))
                    {
                        alarm = alert.MEDIUM;
                    }
                }
                // we don't care about 'bad hardware' here as long as it matches!

                /*else if ((pm1HWInfo != null && pm2HWInfo != null) && (pm1HWInfo.CpuClockSpeed == 0 || pm1HWInfo.OSMajor == 0 || pm2HWInfo.CpuClockSpeed == 0 || pm2HWInfo.OSMajor == 0))
                 * {
                 *      // unknown hardware
                 *      if (LineOfSight(pm1, pm2))
                 *              alarm = alert.MEDIUM;
                 * }*/
                else if ((pm1HWInfo != 0 && pm2HWInfo != 0) && pm1HWInfo == pm2HWInfo /*Server.Commands.MultiClientCommand.IsSameHWInfo(pm1HWInfo, pm2HWInfo)*/)
                {
                    // same hardware
                    alarm = alert.MEDIUM;
                    if (LineOfSight(pm1, pm2) && ns1.Version == ns2.Version)
                    {
                        alarm = alert.HIGH;
                    }
                }
                else
                {
                    // different hardware
                    if (LineOfSight(pm1, pm2) && ns1.Version == ns2.Version)
                    {
                        alarm = alert.MEDIUM;
                    }
                }

                // caller wants to filter to HIGH alarms only
                if (highOnly == true && alarm != alert.HIGH)
                {
                    return;
                }

                from.SendMessage(String.Format("{0}, {1}, Alarm({2})", pm1Name, pm2Name, alarm.ToString()));
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
            }
        }
示例#18
0
        public static void RetargetRunes_OnCommand(CommandEventArgs e)
        {
            ArrayList regionList = new ArrayList();

            if (HaveRegions(e, regionList))
            {
                try
                {
                    LogHelper Logger = new LogHelper("retarget.log", e.Mobile, true);

                    foreach (Item item in World.Items.Values)
                    {
                        if (item is RecallRune)
                        {
                            RecallRune rune = (RecallRune)item;

                            for (int ix = 0; ix < regionList.Count; ix++)
                            {
                                if (rune.Marked && rune.TargetMap != null && (regionList[ix] as Region).Contains(rune.Target))
                                {
                                    object root = item.RootParent;

                                    if (root is Mobile)
                                    {
                                        if (((Mobile)root).AccessLevel < AccessLevel.GameMaster)
                                        {
                                            Logger.Log(LogType.Item, rune, rune.Description);
                                            rune.Target = new Point3D(0, 0, 0);
                                        }
                                    }
                                    else
                                    {
                                        Logger.Log(LogType.Item, rune, rune.Description);
                                        rune.Target = new Point3D(0, 0, 0);
                                    }
                                }
                            }
                        }
                        else if (item is Moonstone)
                        {
                            Moonstone stone = (Moonstone)item;

                            for (int ix = 0; ix < regionList.Count; ix++)
                            {
                                if (stone.Marked && (regionList[ix] as Region).Contains(stone.Destination))
                                {
                                    object root = item.RootParent;

                                    if (root is Mobile)
                                    {
                                        if (((Mobile)root).AccessLevel < AccessLevel.GameMaster)
                                        {
                                            Logger.Log(LogType.Item, stone, stone.Description);
                                            stone.Destination = new Point3D(0, 0, 0);
                                        }
                                    }
                                    else
                                    {
                                        Logger.Log(LogType.Item, stone, stone.Description);
                                        stone.Destination = new Point3D(0, 0, 0);
                                    }
                                }
                            }
                        }
                        else if (item is Runebook)
                        {
                            Runebook book = (Runebook)item;

                            for (int ix = 0; ix < regionList.Count; ix++)
                            {
                                for (int i = 0; i < book.Entries.Count; ++i)
                                {
                                    RunebookEntry entry = (RunebookEntry)book.Entries[i];

                                    if (entry.Map != null && (regionList[ix] as Region).Contains(entry.Location))
                                    {
                                        object root = item.RootParent;

                                        if (root is Mobile)
                                        {
                                            if (((Mobile)root).AccessLevel < AccessLevel.GameMaster)
                                            {
                                                Logger.Log(LogType.Item, item, string.Format("{0}:{1}:{2}",
                                                                                             i,
                                                                                             entry.Description,
                                                                                             book.Description));

                                                entry.Location = new Point3D(0, 0, 0);
                                            }
                                        }
                                        else
                                        {
                                            Logger.Log(LogType.Item, item, string.Format("{0}:{1}:{2}",
                                                                                         i,
                                                                                         entry.Description,
                                                                                         book.Description));

                                            entry.Location = new Point3D(0, 0, 0);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    Logger.Finish();
                    e.Mobile.SendMessage("DONE search for runes.");

                    return;
                }
                catch (Exception exc)
                {
                    LogHelper.LogException(exc);
                    e.Mobile.SendMessage("Exception in [Retarget -- see console.");
                    System.Console.WriteLine("Exception in [Retarget: {0}", exc.Message);
                    System.Console.WriteLine(exc.StackTrace);
                    return;
                }
            }
            else
            {
                e.Mobile.SendMessage("Usage: [Retarget <-regionName|-type|-point|-RegionUID> <name|type|point|uid>");
            }
        }
示例#19
0
        public static int Build(Mobile from, Point3D start, Point3D end, ConstructorInfo ctor, object[] values, string[,] props, PropertyInfo[] realProps, ArrayList packs)
        {
            try
            {
                Map map = from.Map;

                int objectCount = (packs == null ? (((end.X - start.X) + 1) * ((end.Y - start.Y) + 1)) : packs.Count);

                if (objectCount >= 20)
                {
                    from.SendMessage("Constructing {0} objects, please wait.", objectCount);
                }

                bool sendError = true;

                if (packs != null)
                {
                    for (int i = 0; i < packs.Count; ++i)
                    {
                        object built = Build(from, ctor, values, props, realProps, ref sendError);

                        if (built is Item)
                        {
                            Container pack = (Container)packs[i];

                            pack.DropItem((Item)built);
                        }
                        else if (built is Mobile)
                        {
                            Mobile m = (Mobile)built;

                            m.MoveToWorld(new Point3D(start.X, start.Y, start.Z), map);
                        }
                    }
                }
                else
                {
                    for (int x = start.X; x <= end.X; ++x)
                    {
                        for (int y = start.Y; y <= end.Y; ++y)
                        {
                            object built = Build(from, ctor, values, props, realProps, ref sendError);

                            if (built is Item)
                            {
                                Item item = (Item)built;
                                item.MoveToWorld(new Point3D(x, y, start.Z), map);
                                AddItemEventArgs e = new AddItemEventArgs(built as Item, from);
                                EventSink.InvokeAddItem(e);

                                // erl: stores person adding it if Spawner
                                // or ChestItemSpawner type + calls change log

                                if (built is Spawner)
                                {
                                    Spawner sp = (Spawner)built;
                                    sp.LastProps = from;
                                    sp.LogChange("Spawner added");
                                }
                                else if (built is ChestItemSpawner)
                                {
                                    ChestItemSpawner sp = (ChestItemSpawner)built;
                                    sp.LastProps = from;
                                    sp.LogChange("ChestItemSpawner added");
                                }
                                else if (built is ChestLootPackSpawner)
                                {
                                    ChestLootPackSpawner sp = (ChestLootPackSpawner)built;
                                    sp.LastProps = from;
                                    sp.LogChange("ChestLootPackSpawner added");
                                }
                            }
                            else if (built is Mobile)
                            {
                                Mobile m = (Mobile)built;

                                m.MoveToWorld(new Point3D(x, y, start.Z), map);
                            }
                        }
                    }
                }

                return(objectCount);
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                Console.WriteLine(ex);
                return(0);
            }
        }
            public override void Execute(CommandEventArgs e, object obj)
            {
                try
                {
                    Item item = obj as Item;

                    if (!RareFactory.InUse)
                    {
                        if (e.Arguments.Length == 4)
                        {
                            int iRarity = 0;
                            if (int.TryParse(e.Arguments[1], out iRarity) == true && iRarity >= 0 && iRarity <= 10)
                            {
                                DODGroup match;
                                if ((match = FindGroup(e.Arguments[0], iRarity)) != null)
                                {
                                    int iStartIndex = 0;
                                    if (int.TryParse(e.Arguments[2], out iStartIndex) == true && iStartIndex > 0 && iStartIndex <= 255)
                                    {
                                        int iLastIndex = 0;
                                        if (int.TryParse(e.Arguments[3], out iLastIndex) == true && iLastIndex > 0 && iLastIndex <= 255)
                                        {
                                            if (item != null)
                                            {
                                                LogHelper Logger = null;
                                                try
                                                {
                                                    DODInstance di = RareFactory.AddRare(match, item);                                                        // rarity is defined by the group
                                                    di.LastIndex  = (short)iLastIndex;
                                                    di.StartIndex = (short)iStartIndex;
                                                    di.StartDate  = DateTime.MinValue;                                                      // valid now
                                                    di.EndDate    = DateTime.MaxValue;                                                      // valid forever

                                                    // default the name to the name of the item
                                                    if (item.Name != null && item.Name != "")
                                                    {
                                                        di.Name = item.Name;
                                                    }
                                                    else
                                                    {
                                                        di.Name = item.GetType().Name;
                                                    }

                                                    AddResponse("Sucessfully defined new rare '" + di.Name + "'!");
                                                }
                                                catch (Exception ex)
                                                {
                                                    LogHelper.LogException(ex);
                                                    e.Mobile.SendMessage(ex.Message);
                                                }
                                                finally
                                                {
                                                    if (Logger != null)
                                                    {
                                                        Logger.Finish();
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                LogFailure("Only an item may be converted into a rare.");
                                            }
                                        }
                                        else
                                        {
                                            LogFailure("The LastIndex must be a numeric value between 1 and 255 inclusive.");
                                        }
                                    }
                                    else
                                    {
                                        LogFailure("The StartIndex must be a numeric value between 1 and 255 inclusive.");
                                    }
                                }
                                else
                                {
                                    LogFailure(String.Format("Could not find the group \"{0}\" with a rarity of {1}", e.Arguments[0], iRarity));
                                }
                            }
                            else
                            {
                                LogFailure("The rarity must be a numeric value between 0 and 10 inclusive.");
                            }
                        }
                        else
                        {
                            LogFailure("AddRare sGroup iRarity iStartIndex iLastIndex");
                        }
                    }
                    else
                    {
                        LogFailure("Rare Factory is currently being configured by another administrator! Please wait. ");
                    }
                }
                catch (Exception exe)
                {
                    LogHelper.LogException(exe);
                    e.Mobile.SendMessage(exe.Message);
                }
            }