Beispiel #1
0
        public static void AddFriend(object obj = null)
        {
            int serial = obj != null
                ? AliasCommands.ResolveSerial(obj)
                : UOC.GetTargeSerialAsync(Strings.Target_new_friend___).Result;

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

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

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

            FriendEntry fe = new FriendEntry {
                Name = m.Name.Trim(), Serial = m.Serial
            };

            if (!Options.CurrentOptions.Friends.Contains(fe))
            {
                Engine.Dispatcher?.Invoke(() => Options.CurrentOptions.Friends.Add(fe));
            }
        }
Beispiel #2
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, true, x, y);
        }
Beispiel #3
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);
        }
        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();
        }
Beispiel #5
0
        public static void RemoveFriend(object obj = null)
        {
            int serial = obj != null
                ? AliasCommands.ResolveSerial(obj)
                : UOC.GetTargetSerialAsync(Strings.Target_friend_to_remove___).Result;

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

            FriendEntry entry = Options.CurrentOptions.Friends.FirstOrDefault(i => i.Serial == serial);

            if (entry == null)
            {
                return;
            }

            Engine.Dispatcher?.Invoke(() =>
            {
                bool result = Options.CurrentOptions.Friends.Remove(entry);

                if (!Options.CurrentOptions.RehueFriends)
                {
                    return(result);
                }

                Engine.RehueList.Remove(serial);
                MainCommands.Resync();

                return(result);
            });
        }
Beispiel #6
0
        public static bool WaitForProperties(object obj, int timeout)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

            PacketFilterInfo pfi = new PacketFilterInfo(0xD6,
                                                        new[] { PacketFilterConditions.IntAtPositionCondition(serial, 5) });

            PacketWaitEntry we = Engine.PacketWaitEntries.Add(pfi, PacketDirection.Incoming, true);

            Engine.SendPacketToServer(new BatchQueryProperties(serial));

            try
            {
                bool result = we.Lock.WaitOne(timeout);

                return(result);
            }
            finally
            {
                Engine.PacketWaitEntries.Remove(we);
            }
        }
Beispiel #7
0
        public static bool EquipWand(string wandName, int minimumCharges = -1)
        {
            try
            {
                WandTypes wandType = Utility.GetEnumValueByName <WandTypes>(wandName);

                int containerSerial = AliasCommands.ResolveSerial("backpack");

                Item[] matches = FindWands(wandType, containerSerial, minimumCharges).Result;

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

                ActionCommands.EquipItem(matches.First().Serial, Layer.OneHanded);

                return(true);
            }
            catch (InvalidOperationException)
            {
                UOC.SystemMessage(string.Format(Strings.Invalid_skill_name___0__, wandName));
            }

            return(false);
        }
Beispiel #8
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, true);
                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);

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

            return(true);
        }
        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);
        }
Beispiel #10
0
        public static void Attack(object obj)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                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));
        }
Beispiel #11
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);
                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);
        }
        public static bool FindWand(string wandName, object containerSource = null, int minimumCharges = -1)
        {
            try
            {
                WandTypes wandType = Utility.GetEnumValueByName <WandTypes>(wandName);

                int containerSerial = AliasCommands.ResolveSerial(containerSource);

                if (containerSource == null)
                {
                    containerSerial = -1;
                }

                Item[] matches = FindWands(wandType, containerSerial, minimumCharges).Result;

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

                AliasCommands.SetMacroAlias("found", matches.First().Serial);

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

                return(true);
            }
            catch (InvalidOperationException)
            {
                UOC.SystemMessage(string.Format(Strings.Invalid_skill_name___0__, wandName));
            }

            return(false);
        }
Beispiel #13
0
        public static T PropertyValue <T>(object obj, string property, int argument = 0)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return(default);
Beispiel #14
0
        private static T GetMobileProperty <T>(object obj, string propertyName)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial <= 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return(default);
Beispiel #15
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;
        }
Beispiel #16
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);
        }
Beispiel #17
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));
        }
Beispiel #18
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);
        }
Beispiel #19
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));
        }
Beispiel #20
0
        public static void OpenVirtueGump(object obj = null)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

            Engine.SendPacketToServer(new GumpButtonClick(0x1CD, Engine.Player.Serial, 1, new[] { serial }));
        }
        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));
        }
Beispiel #22
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));
        }
Beispiel #23
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);
        }
Beispiel #24
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);
        }
Beispiel #25
0
        public static bool WaitForContext(object obj, string entryName, int timeout)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

            AutoResetEvent are = new AutoResetEvent(false);

            PacketFilterInfo pfi = new PacketFilterInfo(0xBF,
                                                        new[]
            {
                PacketFilterConditions.ShortAtPositionCondition(0x14, 3),
                PacketFilterConditions.IntAtPositionCondition(serial, 7)
            }, (bytes, info) =>
            {
                IEnumerable <ContextMenuEntry> entries = ParseContextMenuEntries(bytes);

                ContextMenuEntry entry =
                    entries.FirstOrDefault(e => e.Text.Trim().ToLower().Equals(entryName.Trim().ToLower()));

                if (entry == null)
                {
                    UOC.SystemMessage(Strings.Context_menu_entry_not_found___, (int)UOC.SystemMessageHues.Yellow,
                                      true, true);
                    return;
                }

                Engine.SendPacketToServer(new ContextMenuClick(serial, entry.Index));
                are.Set();
            });

            Engine.AddReceiveFilter(pfi);

            Engine.SendPacketToServer(new ContextMenuRequest(serial));

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

                return(result);
            }
            finally
            {
                Engine.RemoveReceiveFilter(pfi);
            }
        }
Beispiel #26
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);
        }
Beispiel #27
0
        public static bool FindType(int graphic, int range = -1, object findLocation = null, int hue = -1,
                                    int minimumStackAmount = -1)
        {
            int owner = 0;

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

            Entity entity;

            bool Predicate(Entity i)
            {
                return((graphic == -1 || i.ID == graphic) && (hue == -1 || i.Hue == hue) &&
                       (minimumStackAmount == -1 || !(i is Item) ||
                        i is Item itm && itm.Count >= minimumStackAmount) && !IgnoreList.Contains(i.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);
        }
Beispiel #28
0
        public static void UseObject(object obj, bool skipQueue = false)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

                return;
            }

            ActionPacketQueue.EnqueueActionPacket(new UseObject(serial),
                                                  skipQueue ? QueuePriority.Immediate : QueuePriority.Low);
        }
Beispiel #29
0
        public static bool Cast(string name, object obj)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

            SpellData sd = _manager.GetSpellData(name);

            if (sd == null)
            {
                UOC.SystemMessage(Strings.Unknown_spell___);
                return(false);
            }

            // Debugging only
            Stopwatch sw = new Stopwatch();

            sw.Start();
            //

            _manager.CastSpell(sd.ID);

            bool result = Options.CurrentOptions.UseExperimentalFizzleDetection
                ? UOC.WaitForTargetOrFizzle(sd.Timeout + 1000)
                : TargetCommands.WaitForTarget(sd.Timeout + 500);

            if (!result)
            {
                UOC.SystemMessage(Strings.Timeout___);
                return(false);
            }

            // Debugging only
            sw.Stop();

            if (Options.CurrentOptions.Debug)
            {
                UOC.SystemMessage(
                    $"Target received in {sw.ElapsedMilliseconds}ms, Spell data timeout: {sd.Timeout}ms");
            }
            //

            TargetCommands.Target(serial);

            return(true);
        }
Beispiel #30
0
        public static void IgnoreObject(object obj)
        {
            int serial = AliasCommands.ResolveSerial(obj);

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

                return;
            }

            if (!IgnoreList.Contains(serial))
            {
                IgnoreList.Add(serial);
            }
        }