コード例 #1
0
        public static void SetEnemy(object obj)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial <= 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);

                return;
            }

            Entity entity = Engine.Items.GetItem(serial) ?? (Entity)Engine.Mobiles.GetMobile(serial);

            if (entity == null)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return;
            }

            TargetManager.GetInstance().SetEnemy(entity);
        }
コード例 #2
0
ファイル: AliasCommands.cs プロジェクト: wverri/ClassicAssist
        internal static int ResolveSerial(object obj, bool defaultSelf = true)
        {
            int serial;

            switch (obj)
            {
            case string str:
                serial = GetAlias(str);

                if (serial == 0 && !MacroManager.QuietMode)
                {
                    UOC.SystemMessage(string.Format(Strings.Unknown_alias___0___, str));
                }

                break;

            case int i:
                serial = i;
                break;

            case uint i:
                serial = (int)i;
                break;

            case Entity i:
                serial = i.Serial;
                break;

            case null when defaultSelf:
                serial = Engine.Player == null ? 0 : Engine.Player.Serial;

                break;

            default:
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return(0);
            }

            return(serial);
        }
コード例 #3
0
        public static bool MoveTypeOffset(int id, object findLocation, int xOffset, int yOffset, int zOffset,
                                          int amount = -1)
        {
            if (findLocation == null ||
                ((string)findLocation).Equals("ground", StringComparison.InvariantCultureIgnoreCase))
            {
                UOC.SystemMessage(Strings.Invalid_container___);
                return(false);
            }

            int owner = AliasCommands.ResolveSerial(findLocation);

            bool Predicate(Item i)
            {
                return(i.ID == id && i.IsDescendantOf(owner));
            }

            Item entity = Engine.Items.SelectEntities(Predicate)?.FirstOrDefault();

            if (entity == null)
            {
                return(false);
            }

            PlayerMobile player = Engine.Player;

            if (player == null)
            {
                return(false);
            }

            int x = player.X + xOffset;
            int y = player.Y + yOffset;
            int z = player.Z + zOffset;

            ActionPacketQueue.EnqueueDragDropGround(entity.Serial, amount, x, y, z);

            return(true);
        }
コード例 #4
0
        public static int X(object obj = null)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return(0);
            }

            Entity entity = UOMath.IsMobile(serial)
                ? Engine.Mobiles.GetMobile(serial)
                : Engine.Items.GetItem(serial) as Entity;

            if (entity != null)
            {
                return(entity.X);
            }

            UOC.SystemMessage(Strings.Entity_not_found___);
            return(0);
        }
コード例 #5
0
        public static void Pathfind(object obj)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Entity_not_found___);
                return;
            }

            Entity entity = UOMath.IsMobile(serial)
                ? (Entity)Engine.Mobiles.GetMobile(serial)
                : Engine.Items.GetItem(serial);

            if (entity == null)
            {
                UOC.SystemMessage(Strings.Entity_not_found___);
                return;
            }

            Pathfind(entity.X, entity.Y, entity.Z);
        }
コード例 #6
0
        public static void UseType(object type, int hue = -1, object container = null)
        {
            int serial = AliasCommands.ResolveSerial(type);

            if (serial <= 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);

                return;
            }

            if (container == null)
            {
                container = Engine.Player?.Backpack?.Serial;
            }

            int containerSerial = AliasCommands.ResolveSerial(container);

            if (!Engine.Items.GetItem(containerSerial, out Item containerItem))
            {
                UOC.SystemMessage(Strings.Cannot_find_container___);

                return;
            }

            Item useItem = hue == -1
                ? containerItem.Container.SelectEntity(i => i.ID == serial)
                : containerItem.Container.SelectEntity(i => i.ID == serial && i.Hue == hue);

            if (useItem == null)
            {
                UOC.SystemMessage(Strings.Cannot_find_item___);

                return;
            }

            Engine.SendPacketToServer(new UseObject(useItem.Serial));
        }
コード例 #7
0
        public static bool WaitForContext(object obj, int entry, int timeout)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return(false);
            }

            AutoResetEvent are = new AutoResetEvent(false);

            PacketFilterInfo pfi = new PacketFilterInfo(0xBF,
                                                        new[]
            {
                PacketFilterConditions.ShortAtPositionCondition(0x14, 3),
                PacketFilterConditions.IntAtPositionCondition(serial, 7)
            }, (bytes, info) =>
            {
                Engine.SendPacketToServer(new ContextMenuClick(serial, entry));
                are.Set();
            });

            Engine.AddReceiveFilter(pfi);

            Engine.SendPacketToServer(new ContextMenuRequest(serial));

            try
            {
                bool result = are.WaitOne(timeout);

                return(result);
            }
            finally
            {
                Engine.RemoveReceiveFilter(pfi);
            }
        }
コード例 #8
0
        public static void TargetGround(object obj, int hue = -1, int range = -1)
        {
            int id = AliasCommands.ResolveSerial(obj);

            if (id == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return;
            }

            Entity entity = (Entity)Engine.Items.SelectEntity(i =>
                                                              i.ID == id && (hue == -1 || i.Hue == hue) &&
                                                              (range == -1 || i.Distance < range)) ?? Engine.Mobiles.SelectEntity(m =>
                                                                                                                                  m.ID == id && (hue == -1 || m.Hue == hue) && (range == -1 || m.Distance < range));

            if (entity == null)
            {
                UOC.SystemMessage(Strings.Cannot_find_item___);
                return;
            }

            Target(entity.Serial, false, Options.CurrentOptions.QueueLastTarget);
        }
コード例 #9
0
        public static int CountType(int graphic, object source = null, int hue = -1)
        {
            if (source == null)
            {
                source = "backpack";
            }

            int sourceSerial = AliasCommands.ResolveSerial(source);

            Item countainerItem = Engine.Items.GetItem(sourceSerial);

            if (countainerItem?.Container == null)
            {
                UOC.SystemMessage(Strings.Invalid_container___);

                return(0);
            }

            Item[] matches =
                countainerItem.Container.SelectEntities(i => i.ID == graphic && (hue == -1 || i.Hue == hue));

            return(matches?.Sum(i => i.Count) ?? 0);
        }
コード例 #10
0
        public static void PlaySound(object param)
        {
            switch (param)
            {
            case int id:
                Engine.SendPacketToClient(new PlaySound(id));
                break;

            case string soundFile:
            {
                string fullPath = Path.Combine(Engine.StartupPath, "Sounds", soundFile);

                if (!File.Exists(fullPath))
                {
                    UOC.SystemMessage(Strings.Cannot_find_sound_file___);
                    return;
                }

                SoundPlayer soundPlayer = new SoundPlayer(fullPath);
                soundPlayer.PlaySync();
                break;
            }
            }
        }
コード例 #11
0
        public Entity PromptTarget()
        {
            int serial = UOC.GetTargetSerialAsync(Strings.Target_object___).Result;

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id, true);
                return(null);
            }

            Entity entity = UOMath.IsMobile(serial)
                ? (Entity)Engine.Mobiles.GetMobile(serial)
                : Engine.Items.GetItem(serial);

            if (entity != null)
            {
                return(entity);
            }

            UOC.SystemMessage(UOMath.IsMobile(serial) ? Strings.Mobile_not_found___ : Strings.Cannot_find_item___,
                              true);

            return(null);
        }
コード例 #12
0
        public static void MoveItemOffset(object obj, int xOffset, int yOffset, int zOffset, int amount = -1)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);

                return;
            }

            PlayerMobile player = Engine.Player;

            if (player == null)
            {
                return;
            }

            int x = player.X + xOffset;
            int y = player.Y + yOffset;
            int z = player.Z + zOffset;

            ActionPacketQueue.EnqueueDragDropGround(serial, amount, x, y, z);
        }
コード例 #13
0
        internal static int ResolveSerial(object obj)
        {
            int serial;

            switch (obj)
            {
            case string str:
                serial = GetAlias(str);

                if (serial == -1)
                {
                    UOC.SystemMessage(string.Format(Strings.Unknown_alias___0___, str));
                }

                break;

            case int i:
                serial = i;
                break;

            case uint i:
                serial = (int)i;
                break;

            case null:
                serial = Engine.Player == null ? 0 : Engine.Player.Serial;

                break;

            default:
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return(-1);
            }

            return(serial);
        }
コード例 #14
0
 public static void ClearUseOnce()
 {
     UseOnceList?.Clear();
     UOC.SystemMessage(Strings.UseOnce_cleared___);
 }
コード例 #15
0
 public static void SetForceWalk(bool force)
 {
     UOC.SetForceWalk(force);
     UOC.SystemMessage(force ? Strings.Force_Walk_On : Strings.Force_Walk_Off);
 }
コード例 #16
0
        public static bool FindLayer(object layer, object obj = null)
        {
            if (obj == null)
            {
                obj = "self";
            }

            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return(false);
            }

            Layer layerValue = Layer.Invalid;

            switch (layer)
            {
            case string s:
                layerValue = Utility.GetEnumValueByName <Layer>(s);
                break;

            case int i:
                layerValue = (Layer)i;
                break;

            case Layer l:
                layerValue = l;
                break;
            }

            if (layerValue == Layer.Invalid)
            {
                UOC.SystemMessage(Strings.Invalid_layer_value___);
                return(false);
            }

            if (!UOMath.IsMobile(serial))
            {
                UOC.SystemMessage(Strings.Cannot_find_item___);
                return(false);
            }

            Mobile mobile = Engine.Mobiles.GetMobile(serial);

            int layerSerial = mobile?.GetLayer(layerValue) ?? 0;

            if (layerSerial == 0)
            {
                AliasCommands.UnsetAlias("found");
                return(false);
            }

            AliasCommands.SetMacroAlias("found", layerSerial);

            if (MacroManager.QuietMode)
            {
                return(true);
            }

            UOC.SystemMessage(string.Format(Strings.Object___0___updated___, "found"));

            return(true);
        }
コード例 #17
0
        public static void TargetTileRelative(object obj, int distance, bool reverse = false)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return;
            }

            Entity entity = Engine.Mobiles.GetMobile(serial);

            if (entity == null)
            {
                UOC.SystemMessage(Strings.Mobile_not_found___);
                return;
            }

            int x = entity.X;
            int y = entity.Y;

            int offsetX = 0;
            int offsetY = 0;

            // TODO
            Direction direction = (Direction)((int)entity.Direction & ~0x80);

            switch (direction)
            {
            case Direction.North:
                offsetY = -1;
                break;

            case Direction.Northeast:
                offsetY = -1;
                offsetX = 1;
                break;

            case Direction.East:
                offsetX = 1;
                break;

            case Direction.Southeast:
                offsetX = 1;
                offsetY = 1;
                break;

            case Direction.South:
                offsetY = 1;
                break;

            case Direction.Southwest:
                offsetY = 1;
                offsetX = -1;
                break;

            case Direction.West:
                offsetX = -1;
                break;

            case Direction.Northwest:
                offsetX = -1;
                offsetY = -1;
                break;

            case Direction.Invalid:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            int totalOffsetX = offsetX * distance;
            int totalOffsetY = offsetY * distance;

            if (reverse)
            {
                totalOffsetX = -totalOffsetX;
                totalOffsetY = -totalOffsetY;
            }

            int destinationX = x + totalOffsetX;
            int destinationY = y + totalOffsetY;

            Engine.SendPacketToServer(new Target(TargetType.Tile, -1, TargetFlags.None, 0, destinationX,
                                                 destinationY, entity.Z, 0, true));
        }
コード例 #18
0
        public static bool Snapshot(int delay = 0, bool fullscreen = false, string fileName = "")
        {
            try
            {
                if (delay > 0)
                {
                    Thread.Sleep(delay);
                }

                IntPtr screenDC;
                int    width, height;

                if (fullscreen)
                {
                    screenDC = GetDC(IntPtr.Zero);
                    width    = (int)SystemParameters.VirtualScreenWidth;
                    height   = (int)SystemParameters.VirtualScreenHeight;
                }
                else
                {
                    screenDC = GetDC(Engine.WindowHandle);
                    GetClientRect(Engine.WindowHandle, out RECT rect);
                    width  = rect.Right - rect.Left;
                    height = rect.Bottom - rect.Top;
                }

                IntPtr memDC   = CreateCompatibleDC(screenDC);
                IntPtr hBitmap = CreateCompatibleBitmap(screenDC, width, height);
                SelectObject(memDC, hBitmap);

                BitBlt(memDC, 0, 0, width, height, screenDC, 0, 0, TernaryRasterOperations.SRCCOPY);
                BitmapSource bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero,
                                                                                  Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                DeleteObject(hBitmap);
                ReleaseDC(IntPtr.Zero, screenDC);
                ReleaseDC(IntPtr.Zero, memDC);

                DateTime now = DateTime.Now;

                if (string.IsNullOrEmpty(fileName))
                {
                    fileName =
                        $"ClassicAssist-{now.Year}-{now.Month}-{now.Day}-{now.Hour}-{now.Minute}-{now.Second}.png";
                }

                string filePath = fileName;

                if (!Path.IsPathRooted(fileName))
                {
                    string path = Path.Combine(Engine.StartupPath, "Screenshots");

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

                    filePath = Path.Combine(path, fileName);
                }

                using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
                {
                    BitmapEncoder encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
                    encoder.Save(fileStream);
                }

                return(true);
            }
            catch (Exception e)
            {
                UOC.SystemMessage(e.Message, (int)UOC.SystemMessageHues.Red);
                return(false);
            }
        }
コード例 #19
0
 public static void SysMessage(string text, int hue = 0x03b2)
 {
     UOC.SystemMessage(text, hue);
 }
コード例 #20
0
        public static void MoveType(int id, object sourceContainer, object destinationContainer, int x = -1,
                                    int y = -1, int z = 0, int hue = -1, int amount = -1)
        {
            int sourceSerial = AliasCommands.ResolveSerial(sourceContainer);

            if (sourceSerial == -1)
            {
                UOC.SystemMessage(Strings.Invalid_source_container___);
                return;
            }

            int destinationSerial;

            if (destinationContainer is int destSerial)
            {
                destinationSerial = destSerial;
            }
            else
            {
                destinationSerial = AliasCommands.ResolveSerial(destinationContainer);
            }

            Item sourceItem = Engine.Items.GetItem(sourceSerial);

            if (sourceItem == null)
            {
                UOC.SystemMessage(Strings.Cannot_find_item___);
                return;
            }

            if (sourceItem.Container == null)
            {
                UOC.SystemMessage(Strings.Invalid_container___);
                return;
            }

            Item entity = sourceItem.Container.SelectEntities(i => i.ID == id && (hue == -1 || i.Hue == hue))
                          .FirstOrDefault();

            if (entity == null)
            {
                return;
            }

            if (amount == -1)
            {
                amount = entity.Count;
            }

            if (amount > entity.Count)
            {
                amount = entity.Count;
            }

            if (destinationSerial == -1)
            {
                ActionPacketQueue.EnqueueDragDropGround(entity.Serial, amount, x, y, z);
            }
            else
            {
                ActionPacketQueue.EnqueueDragDrop(entity.Serial, amount, destinationSerial);
            }
        }
コード例 #21
0
 public static void SysMessage(string text)
 {
     UOC.SystemMessage(text);
 }
コード例 #22
0
        public static void TargetTileRelative(object obj, int distance, bool reverse = false, int itemID = 0)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return;
            }

            Entity entity = Engine.Mobiles.GetMobile(serial);

            if (entity == null)
            {
                if (!MacroManager.QuietMode)
                {
                    UOC.SystemMessage(Strings.Mobile_not_found___);
                }

                return;
            }

            int x = entity.X;
            int y = entity.Y;

            int offsetX = 0;
            int offsetY = 0;

            // TODO
            Direction direction = (Direction)((int)entity.Direction & ~0x80);

            switch (direction)
            {
            case Direction.North:
                offsetY = -1;
                break;

            case Direction.Northeast:
                offsetY = -1;
                offsetX = 1;
                break;

            case Direction.East:
                offsetX = 1;
                break;

            case Direction.Southeast:
                offsetX = 1;
                offsetY = 1;
                break;

            case Direction.South:
                offsetY = 1;
                break;

            case Direction.Southwest:
                offsetY = 1;
                offsetX = -1;
                break;

            case Direction.West:
                offsetX = -1;
                break;

            case Direction.Northwest:
                offsetX = -1;
                offsetY = -1;
                break;

            case Direction.Invalid:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            int totalOffsetX = offsetX * distance;
            int totalOffsetY = offsetY * distance;

            if (reverse)
            {
                totalOffsetX = -totalOffsetX;
                totalOffsetY = -totalOffsetY;
            }

            int destinationX = x + totalOffsetX;
            int destinationY = y + totalOffsetY;

            (int surfaceZ, int surfaceID) =
                MapInfo.GetMapSurface((int)Engine.Player.Map, destinationX, destinationY);

            if (itemID == 0)
            {
                itemID = surfaceID;
            }

            TargetXYZ(destinationX, destinationY, surfaceZ, itemID);
        }
コード例 #23
0
 public static void ClearTargetQueue()
 {
     Engine.LastTargetQueue?.Clear();
     UOC.SystemMessage(Strings.Target_queue_cleared___);
 }
コード例 #24
0
        public static void Target(object obj, bool checkRange = false, bool useQueue = false)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                return;
            }

            if (checkRange && UOMath.IsMobile(serial) && Engine.TargetExists)
            {
                Mobile mobile = Engine.Mobiles.GetMobile(serial);

                if (mobile != null)
                {
                    if (mobile.Distance > Options.CurrentOptions.RangeCheckLastTargetAmount)
                    {
                        UOC.SystemMessage(Strings.Target_out_of_range__try_again___);
                        UOC.ResendTargetToClient();
                        return;
                    }
                }
                else
                {
                    UOC.SystemMessage(Strings.Target_out_of_range__try_again___);
                    UOC.ResendTargetToClient();
                    return;
                }
            }

            if (Options.CurrentOptions.PreventTargetingInnocentsInGuardzone && Engine.TargetExists)
            {
                Mobile mobile = Engine.Mobiles.GetMobile(serial);

                if (mobile != null && mobile.Notoriety == Notoriety.Innocent &&
                    mobile.Serial != Engine.Player?.Serial && Engine.TargetFlags == TargetFlags.Harmful &&
                    mobile.GetRegion().Attributes.HasFlag(RegionAttributes.Guarded))
                {
                    UOC.SystemMessage(Strings.Target_blocked____try_again___);
                    UOC.ResendTargetToClient();

                    return;
                }
            }

            if (useQueue && !Engine.TargetExists)
            {
                MsgCommands.HeadMsg(Strings.Target_Queued, Engine.Player?.Serial);
                Engine.LastTargetQueue.Enqueue(new TargetQueueObject {
                    Object = obj
                });
                return;
            }

            if (Engine.InternalTarget)
            {
                PacketWriter writer = new PacketWriter(19);
                writer.Write((byte)0x6C);
                writer.Write((byte)0);
                writer.Write(Engine.InternalTargetSerial);
                writer.Write((byte)0);
                writer.Write(serial);
                writer.Fill();

                if (Engine.CheckOutgoingPreFilter(writer.ToArray()))
                {
                    byte[] packet = writer.ToArray();
                    packet[6] = 0x03;

                    Engine.SendPacketToClient(packet, packet.Length, false);
                    Engine.TargetExists = false;

                    return;
                }
            }

            Engine.SendPacketToServer(new Target(TargetTypeEnum.Object, -1, TargetFlags.None, serial, -1, -1, -1, 0,
                                                 true));
            Engine.TargetExists = false;
        }