Ejemplo n.º 1
0
        public static void ToggleForceWalk()
        {
            _forceWalk = !_forceWalk;

            UOC.SetForceWalk(_forceWalk);
            UOC.SystemMessage(_forceWalk ? Strings.Force_Walk_On : Strings.Force_Walk_Off);
        }
Ejemplo n.º 2
0
        public static void ClearHands(string hand = "both")
        {
            hand = hand.ToLower();
            List <Layer> unequipLayers = new List <Layer>();

            switch (hand)
            {
            case "left":
                unequipLayers.Add(Layer.OneHanded);
                break;

            case "right":
                unequipLayers.Add(Layer.TwoHanded);
                break;

            case "both":
                unequipLayers.Add(Layer.OneHanded);
                unequipLayers.Add(Layer.TwoHanded);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(hand));
            }

            PlayerMobile player = Engine.Player;

            List <int> serials = unequipLayers.Select(unequipLayer => Engine.Player.GetLayer(unequipLayer))
                                 .Where(serial => serial != 0).ToList();

            foreach (int serial in serials)
            {
                UOC.DragDropAsync(serial, 1, player.Backpack?.Serial ?? 0).Wait();
                Thread.Sleep(Options.CurrentOptions.ActionDelayMS);
            }
        }
Ejemplo n.º 3
0
        public static void Attack(object obj)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

            if (Options.CurrentOptions.PreventAttackingInnocentsInGuardzone)
            {
                Mobile mobile = Engine.Mobiles.GetMobile(serial);

                if (mobile != null && mobile.Notoriety == Notoriety.Innocent &&
                    mobile.GetRegion().Attributes.HasFlag(RegionAttributes.Guarded))
                {
                    UOC.SystemMessage(Strings.Attack_request_blocked___);

                    return;
                }
            }

            Engine.SendPacketToClient(new ChangeCombatant(serial));
            Engine.SendPacketToServer(new AttackRequest(serial));
        }
Ejemplo n.º 4
0
        public static int PromptAlias(string aliasName)
        {
            int serial = UOC.GetTargetSerialAsync(string.Format(Strings.Target_object___0_____, aliasName)).Result;

            SetAlias(aliasName, serial);
            return(serial);
        }
Ejemplo n.º 5
0
        public static int Graphic(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.ID);
            }

            if (!MacroManager.QuietMode)
            {
                UOC.SystemMessage(Strings.Entity_not_found___);
            }

            return(0);
        }
Ejemplo n.º 6
0
            public override void Execute()
            {
                if (!Options.CurrentOptions.QueueLastTarget)
                {
                    UOC.SystemMessage(Strings.Target_queue_is_not_enabled___);
                    return;
                }

                object nextTarget = Engine.LastTargetQueue.Peek()?.Object;

                switch (nextTarget)
                {
                case string targetAlias:
                    MsgCommands.HeadMsg(string.Format(Strings.Next_Target___0_, targetAlias),
                                        Engine.Player?.Serial);
                    break;

                case int targetSerial:
                {
                    Mobile entity = Engine.Mobiles.GetMobile(targetSerial);

                    MsgCommands.HeadMsg(
                        string.Format(Strings.Next_Target___0_,
                                      $"0x{targetSerial:x} - {entity?.Name ?? "Unknown"}"), Engine.Player?.Serial);
                    break;
                }
                }
            }
Ejemplo n.º 7
0
        public static void Feed(object obj, int graphic, int amount = 1, int hue = -1)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

            if (Engine.Player?.Backpack == null)
            {
                UOC.SystemMessage(Strings.Error__Cannot_find_player_backpack);
                return;
            }

            Item foodItem =
                Engine.Player.Backpack?.Container.SelectEntity(i => i.ID == graphic && (hue == -1 || i.Hue == hue));

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

            ActionPacketQueue.EnqueueDragDrop(foodItem.Serial, amount, serial);
        }
Ejemplo n.º 8
0
        public static void TargetType(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;
            }

            if (Engine.Player?.Backpack == null)
            {
                UOC.SystemMessage(Strings.Error__Cannot_find_player_backpack);
                return;
            }

            Item item = Engine.Items.SelectEntity(i =>
                                                  i.ID == id && (hue == -1 || i.Hue == hue) &&
                                                  i.IsDescendantOf(Engine.Player.Backpack.Serial, range));

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

            Target(item.Serial, false, Options.CurrentOptions.QueueLastTarget);
        }
Ejemplo n.º 9
0
        public static void MoveItem(object item, object destination, int amount = -1)
        {
            int itemSerial = AliasCommands.ResolveSerial(item);

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

            Item itemObj = Engine.Items.GetItem(itemSerial);

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

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

            int containerSerial = AliasCommands.ResolveSerial(destination);

            if (containerSerial == 0)
            {
                //TODO
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return;
            }

            UOC.DragDropAsync(itemSerial, amount, containerSerial).Wait();
        }
Ejemplo n.º 10
0
        public static bool UseOnce(int graphic, int hue = -1)
        {
            //TODO hue?
            if (Engine.Player?.Backpack?.Container == null)
            {
                return(false);
            }

            Item backpack = Engine.Player.Backpack;

            Item match = backpack.Container.SelectEntity(i =>
                                                         i.ID == graphic && !UseOnceList.Contains(i.Serial) && (hue == -1 || hue == i.Hue));

            if (match == null)
            {
                UOC.SystemMessage(Strings.UseOnce__Cannot_find_type___);
                return(false);
            }

            UseOnceList.Add(match);

            ObjectCommands.UseObject(match.Serial);

            return(true);
        }
Ejemplo n.º 11
0
        public static void Hotkeys(string onOff = "toggle")
        {
            HotkeyManager manager = HotkeyManager.GetInstance();

            switch (onOff.Trim().ToLower())
            {
            case "on":
            {
                manager.Enabled = true;
                break;
            }

            case "off":
            {
                manager.Enabled = false;
                break;
            }

            default:
            {
                manager.Enabled = !manager.Enabled;
                break;
            }
            }

            UOC.SystemMessage(manager.Enabled ? Strings.Hotkeys_enabled___ : Strings.Hotkeys_disabled___,
                              manager.Enabled ? 0x3F : 36);
        }
Ejemplo n.º 12
0
        public static void ToggleMounted()
        {
            PlayerMobile player = Engine.Player;

            if (player == null)
            {
                return;
            }

            if (player.IsMounted)
            {
                ObjectCommands.UseObject(player.Serial);
                return;
            }

            if (!AliasCommands.FindAlias("mount"))
            {
                int serial = UOC.GetTargetSerialAsync(Strings.Target_new_mount___).Result;

                if (serial == -1)
                {
                    UOC.SystemMessage(Strings.Invalid_mount___);
                    return;
                }

                AliasCommands.SetAlias("mount", serial);
            }

            int mountSerial = AliasCommands.GetAlias("mount");

            ObjectCommands.UseObject(mountSerial);
        }
Ejemplo n.º 13
0
        public static void PlaySound(object param, bool playSync = true)
        {
            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);

                if (playSync)
                {
                    soundPlayer.PlaySync();
                }
                else
                {
                    soundPlayer.Play();
                }

                break;
            }
            }
        }
Ejemplo n.º 14
0
        public static void MoveItem(object item, object destination, int amount = -1, int x = -1, int y = -1)
        {
            int itemSerial = AliasCommands.ResolveSerial(item);

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

            Item itemObj = Engine.Items.GetItem(itemSerial);

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

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

            int containerSerial = AliasCommands.ResolveSerial(destination);

            if (containerSerial == 0)
            {
                //TODO
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return;
            }

            ActionPacketQueue.EnqueueDragDrop(itemSerial, amount, containerSerial, QueuePriority.Low, false, true,
                                              false, x, y);
        }
Ejemplo n.º 15
0
        public Entity PromptTarget()
        {
            int serial = UOC.GetTargetSerialAsync(Strings.Target_object___).Result;

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

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

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

            if (!MacroManager.QuietMode)
            {
                UOC.SystemMessage(
                    UOMath.IsMobile(serial) ? Strings.Mobile_not_found___ : Strings.Cannot_find_item___);
            }

            return(null);
        }
Ejemplo n.º 16
0
        public static void EquipType(int id, object layer)
        {
            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;
            }

            UOC.EquipType(id, layerValue);
        }
Ejemplo n.º 17
0
        public static void Hotkeys()
        {
            HotkeyManager manager = HotkeyManager.GetInstance();

            manager.Enabled = !manager.Enabled;

            UOC.SystemMessage(manager.Enabled ? Strings.Hotkeys_enabled___ : Strings.Hotkeys_disabled___, 0x3F);
        }
Ejemplo n.º 18
0
        private static T GetEntityProperty <T>(object obj, string propertyName)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial <= 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return(default);
Ejemplo n.º 19
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;
            }

            Engine.SendPacketToServer(new Target(TargetTypeEnum.Object, -1, TargetFlags.None, serial, -1, -1, -1, 0,
                                                 true));
            Engine.TargetExists = false;
        }
Ejemplo n.º 20
0
        public static bool FindObject(object obj, int range = -1, object findLocation = null)
        {
            int owner = 0;

            int serial = AliasCommands.ResolveSerial(obj);

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

                return(false);
            }

            if (findLocation != null)
            {
                owner = AliasCommands.ResolveSerial(findLocation);
            }

            Entity entity;

            bool Predicate(Entity i)
            {
                return(i.Serial == serial);
            }

            if (owner != 0)
            {
                entity = Engine.Items.SelectEntities(i => Predicate(i) && i.IsDescendantOf(owner, range))
                         ?.FirstOrDefault();
            }
            else
            {
                entity =
                    (Entity)Engine.Mobiles
                    .SelectEntities(i => Predicate(i) && (range == -1 || i.Distance < range))
                    ?.FirstOrDefault() ?? Engine.Items.SelectEntities(i =>
                                                                      Predicate(i) && (range == -1 || i.Distance < range) && i.Owner == 0)?.FirstOrDefault();
            }

            if (entity == null)
            {
                AliasCommands.UnsetAlias("found");
                return(false);
            }

            AliasCommands.SetMacroAlias("found", entity.Serial);

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

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

            return(true);
        }
Ejemplo n.º 21
0
        public static bool WaitForContents(object obj, int timeout = 5000)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

            return(UOC.WaitForContainerContentsUse(serial, timeout));
        }
Ejemplo n.º 22
0
        public static void Rename(object obj, string name)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

            UOC.RenameRequest(serial, name);
        }
Ejemplo n.º 23
0
        public static void ClickObject(object obj)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

            Engine.SendPacketToServer(new LookRequest(serial));
        }
Ejemplo n.º 24
0
        public static void Turn(string direction)
        {
            Direction directionEnum = Utility.GetEnumValueByName <Direction>(direction);

            if (Engine.Player.Direction == directionEnum)
            {
                return;
            }

            Engine.Move(directionEnum, false);
            UOC.WaitForIncomingPacket(new PacketFilterInfo(22), MOVEMENT_TIMEOUT);
        }
Ejemplo n.º 25
0
        public static void Pathfind(int x, int y, int z)
        {
            int distance = Math.Max(Math.Abs(x - Engine.Player?.X ?? x), Math.Abs(y - Engine.Player?.Y ?? y));

            if (distance > PATHFIND_MAX_DISTANCE)
            {
                UOC.SystemMessage(Strings.Maximum_distance_exceeded_);
                return;
            }

            Engine.SendPacketToClient(new Pathfind(x, y, z));
        }
Ejemplo n.º 26
0
        public static bool InIgnoreList(object obj)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial > 0)
            {
                return(IgnoreList.Contains(serial));
            }

            UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);

            return(false);
        }
Ejemplo n.º 27
0
        public static void UseTargetedItem(object item, object target)
        {
            int serial       = AliasCommands.ResolveSerial(item);
            int targetSerial = AliasCommands.ResolveSerial(target);

            if (serial == 0 || targetSerial == 0)
            {
                UOC.SystemMessage(Strings.Cannot_find_item___);
                return;
            }

            Engine.SendPacketToServer(new UseTargetedItem(serial, targetSerial));
        }
Ejemplo n.º 28
0
        public static void Attack(object obj)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

            Engine.SendPacketToClient(new ChangeCombatant(serial));
            Engine.SendPacketToServer(new AttackRequest(serial));
        }
Ejemplo n.º 29
0
        public static bool UseLayer(object layer, object obj = null)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0 || !UOMath.IsMobile(serial))
            {
                UOC.SystemMessage(Strings.Cannot_find_item___);
                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;
            }

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

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

                return(false);
            }

            int layerSerial = mobile.GetLayer(layerValue);

            if (layerSerial == 0)
            {
                UOC.SystemMessage(Strings.Cannot_find_item___);
                return(false);
            }

            UseObject(layerSerial);

            return(true);
        }
Ejemplo n.º 30
0
        public static double Distance(object obj = null)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

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

            return(entity?.Distance ?? 0);
        }