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);
        }
Exemple #2
0
        private static async Task <Item[]> FindWands(WandTypes wandType, int containerSerial, int minimumCharges)
        {
            if (!Engine.TooltipsEnabled)
            {
                Item[] allWands = Engine.Items.SelectEntities(i =>
                                                              _wandIds.Contains(i.ID) && !ObjectCommands.InIgnoreList(i.Serial) && (containerSerial == -1 || i.IsDescendantOf(containerSerial)));

                if (allWands == null)
                {
                    return(null);
                }

                foreach (Item wand in allWands)
                {
                    Engine.SendPacketToServer(new LookRequest(wand.Serial));
                    await UOC.WaitForIncomingPacketFilterAsync(
                        new PacketFilterInfo( 0xBF,
                                              new[]
                    {
                        PacketFilterConditions.ShortAtPositionCondition(0x10, 3),
                        PacketFilterConditions.IntAtPositionCondition(wand.Serial, 5)
                    } ), 2500);
                }
            }

            Item[] matches = Engine.Items.SelectEntities(i =>
                                                         _wandIds.Contains(i.ID) && !ObjectCommands.InIgnoreList(i.Serial) && (containerSerial == -1 || i.IsDescendantOf(containerSerial)) &&
                                                         i.Properties != null && i.Properties.Any(p =>
                                                                                                  _wandClilocs[wandType].Contains(p.Cliloc) &&
                                                                                                  (minimumCharges == -1 || int.Parse(p.Arguments[0]) >= minimumCharges)));

            return(matches);
        }
        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);
        }
        public static bool BandageSelf()
        {
            PlayerMobile player = Engine.Player;

            if (player == null)
            {
                SystemMessage(Strings.Error__No_Player);
                return(false);
            }

            Item backpack = player.Backpack;

            if (backpack == null)
            {
                SystemMessage(Strings.Error__Cannot_find_player_backpack);
                return(false);
            }

            Item bandage = backpack.Container?.SelectEntity(i => _bandageTypes.Contains(i.ID));

            if (bandage == null)
            {
                SystemMessage(Strings.Error__Cannot_find_type);
                return(false);
            }

            ObjectCommands.UseObject(bandage.Serial);

            PacketWaitEntry we = Engine.PacketWaitEntries.Add(new PacketFilterInfo(0x6C), PacketDirection.Incoming);

            bool result = we.Lock.WaitOne(TIMEOUT);

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

            byte[] packet = we.Packet;

            int senderSerial = (packet[2] << 24) | (packet[3] << 16) | (packet[4] << 8) | packet[5];

            Engine.SendPacketToServer(new Target(senderSerial, player, true));

            return(true);
        }