Example #1
0
        public void WillOnlySetSecondaryAbilityOnce()
        {
            AbilitiesManager manager = AbilitiesManager.GetInstance();

            Engine.Player = new PlayerMobile(0x01);

            Engine.InternalPacketSentEvent += ExpectAbilityPacket;

            AbilitiesCommands.SetAbility("secondary", "on");

            bool result = _are.WaitOne(5000);

            if (!result)
            {
                Assert.Fail();
            }

            Assert.AreEqual(AbilityType.Secondary, manager.Enabled);
            Assert.IsTrue(manager.IsSecondaryEnabled);

            Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
            Engine.InternalPacketSentEvent += NotExpectAbilityPacket;

            AbilitiesCommands.SetAbility("secondary", "on");

            Engine.InternalPacketSentEvent -= NotExpectAbilityPacket;

            AbilitiesCommands.ClearAbility();

            Engine.Player = null;
        }
        public static void SetAbility(string ability, string onOff = "toggle")
        {
            AbilitiesManager manager = AbilitiesManager.GetInstance();

            // TODO stun/disarm old
            bool primary;

            switch (ability.ToLower())
            {
            case "primary":
                primary = true;
                break;

            default:
                primary = false;
                break;
            }

            string onOffNormalized = onOff.Trim().ToLower();

            if (onOffNormalized != "toggle")
            {
                switch (onOffNormalized)
                {
                case "on":
                {
                    if (primary && manager.IsPrimaryEnabled || !primary && manager.IsSecondaryEnabled)
                    {
                        if (!MacroManager.QuietMode)
                        {
                            UOC.SystemMessage(Strings.Ability_already_set___, 0x3F);
                        }

                        return;
                    }

                    break;
                }

                case "off":
                {
                    if (primary && !manager.IsPrimaryEnabled || !primary && !manager.IsSecondaryEnabled)
                    {
                        if (!MacroManager.QuietMode)
                        {
                            UOC.SystemMessage(Strings.Ability_not_set___, 0x3F);
                        }

                        return;
                    }

                    break;
                }
                }
            }

            UOC.SystemMessage(string.Format(Strings.Setting_ability___0_____, ability), 0x3F);
            manager.SetAbility(primary ? AbilityType.Primary : AbilityType.Secondary);
        }
Example #3
0
        private static bool OnUseRequest(ref byte[] packet, ref int length)
        {
            if (!Options.CurrentOptions.CheckHandsPotions)
            {
                return(false);
            }

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

            return(AbilitiesManager.GetInstance().CheckHands(serial));
        }
        private static void OnClearWeaponAbility(PacketReader reader)
        {
            AbilitiesManager manager = AbilitiesManager.GetInstance();

            if (manager.Enabled != AbilityType.None)
            {
                Commands.SystemMessage(Strings.Current_Ability_Cleared);
            }

            manager.Enabled = AbilityType.None;
        }
Example #5
0
        public void WontSetAbilitySetOff()
        {
            Engine.Player = new PlayerMobile(0x01);

            Engine.InternalPacketSentEvent += NotExpectAbilityPacket;

            AbilitiesCommands.SetAbility("primary", "off");

            Assert.AreEqual(AbilityType.None, AbilitiesManager.GetInstance().Enabled);

            Engine.Player = null;
        }
        public static void ClearAbility()
        {
            AbilitiesManager manager = AbilitiesManager.GetInstance();

            if (manager.IsPrimaryEnabled)
            {
                manager.SetAbility(AbilityType.Primary);
            }
            else if (manager.IsSecondaryEnabled)
            {
                manager.SetAbility(AbilityType.Secondary);
            }
        }
Example #7
0
        public static bool ActiveAbility()
        {
            AbilitiesManager manager = AbilitiesManager.GetInstance();

            bool result = false;

            if (manager.IsPrimaryEnabled)
            {
                result = true;
            }
            else if (manager.IsSecondaryEnabled)
            {
                result = true;
            }

            return(result);
        }
        private static bool OnUseRequest(ref byte[] packet, ref int length)
        {
            int serial = (packet[1] << 24) | (packet[2] << 16) | (packet[3] << 8) | packet[4];

            if (Options.CurrentOptions.CheckHandsPotions)
            {
                return(AbilitiesManager.GetInstance().CheckHands(serial));
            }

            if (Options.CurrentOptions.UseObjectQueue)
            {
                ActionPacketQueue.EnqueuePacket(new UseObject(serial), QueuePriority.High);

                return(true);
            }

            return(false);
        }
Example #9
0
        public static void UseType(object type, int hue = -1, object container = null, bool skipQueue = false)
        {
            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;
            }

            if (!AbilitiesManager.GetInstance().CheckHands(useItem.Serial))
            {
                ActionPacketQueue.EnqueuePacket(new UseObject(useItem.Serial),
                                                skipQueue ? QueuePriority.Immediate : QueuePriority.Medium);
            }
        }
        private static void OnEncodedCommand(PacketReader reader)
        {
            int serial = reader.ReadInt32();

            int command = reader.ReadInt16();

            switch (command)
            {
            case 0x19:
            {
                reader.ReadByte();

                int abilityIndex = reader.ReadInt32();

                AbilitiesManager.GetInstance().CheckAbility(abilityIndex);

                break;
            }
            }
        }
Example #11
0
        public void WillTogglePrimaryAbility()
        {
            AbilitiesManager manager = AbilitiesManager.GetInstance();

            Engine.Player = new PlayerMobile(0x01);

            manager.Enabled = AbilityType.None;

            Engine.InternalPacketSentEvent += ExpectAbilityPacket;

            AbilitiesCommands.SetAbility("primary");

            bool result = _are.WaitOne(5000);

            if (!result)
            {
                Assert.Fail();
            }

            Assert.AreEqual(AbilityType.Primary, manager.Enabled);
            Assert.IsTrue(manager.IsPrimaryEnabled);

            AbilitiesCommands.SetAbility("primary");

            result = _are.WaitOne(5000);

            if (!result)
            {
                Assert.Fail();
            }

            Assert.AreEqual(AbilityType.None, manager.Enabled);
            Assert.IsFalse(manager.IsPrimaryEnabled);

            Engine.InternalPacketSentEvent -= ExpectAbilityPacket;

            Engine.Player = null;
        }
Example #12
0
        public void WillClearAbilities()
        {
            Engine.Player = new PlayerMobile(0x01);

            AbilitiesManager manager = AbilitiesManager.GetInstance();

            Engine.InternalPacketSentEvent += ExpectAbilityPacket;

            manager.Enabled = AbilityType.Primary;

            AbilitiesCommands.ClearAbility();

            bool result = _are.WaitOne(5000);

            if (!result)
            {
                Assert.Fail();
            }

            Assert.AreEqual(AbilityType.None, manager.Enabled);

            manager.Enabled = AbilityType.Secondary;

            AbilitiesCommands.ClearAbility();

            result = _are.WaitOne(5000);

            if (!result)
            {
                Assert.Fail();
            }

            Assert.AreEqual(AbilityType.None, manager.Enabled);

            Engine.InternalPacketSentEvent -= ExpectAbilityPacket;

            Engine.Player = null;
        }
        private static void OnEquipRequest(PacketReader reader)
        {
            AbilitiesManager manager = AbilitiesManager.GetInstance();

            manager.ResendGump(manager.Enabled);
        }
Example #14
0
        public static void SetPlayer(PlayerMobile mobile)
        {
            Player = mobile;

            PlayerInitializedEvent?.Invoke(mobile);

            mobile.MobileStatusUpdated += (status, newStatus) =>
            {
                if (!Options.CurrentOptions.UseDeathScreenWhilstHidden)
                {
                    return;
                }

                if (newStatus.HasFlag(MobileStatus.Hidden))
                {
                    SendPacketToClient(new MobileUpdate(mobile.Serial, mobile.ID == 0x191 ? 0x193 : 0x192, mobile.Hue,
                                                        newStatus, mobile.X,
                                                        mobile.Y, mobile.Z, mobile.Direction));
                }
            };

            Task.Run(async() =>
            {
                try
                {
                    GitHubClient client = new GitHubClient(new ProductHeaderValue("ClassicAssist"));

                    IReadOnlyList <Release> releases =
                        await client.Repository.Release.GetAll("Reetus",
                                                               "ClassicAssist");

                    Release latestRelease = releases.FirstOrDefault();

                    if (latestRelease == null)
                    {
                        return;
                    }

                    Version latestVersion = Version.Parse(latestRelease.TagName);

                    if (!Version.TryParse(
                            FileVersionInfo.GetVersionInfo(Path.Combine(StartupPath, "ClassicAssist.dll"))
                            .ProductVersion,
                            out Version localVersion))
                    {
                        return;
                    }

                    if (latestVersion > localVersion && AssistantOptions.UpdateGumpVersion < latestVersion)
                    {
                        IReadOnlyList <GitHubCommit> commits =
                            await client.Repository.Commit.GetAll("Reetus", "ClassicAssist");

                        IEnumerable <GitHubCommit> latestCommits =
                            commits.OrderByDescending(c => c.Commit.Author.Date).Take(7);

                        StringBuilder commitMessage = new StringBuilder();

                        foreach (GitHubCommit gitHubCommit in latestCommits)
                        {
                            commitMessage.AppendLine($"{gitHubCommit.Commit.Author.Date.Date.ToShortDateString()}:");
                            commitMessage.AppendLine();
                            commitMessage.AppendLine(gitHubCommit.Commit.Message);
                            commitMessage.AppendLine();
                        }

                        StringBuilder message = new StringBuilder();
                        message.AppendLine(Strings.ProductName);
                        message.AppendLine($"{Strings.New_version_available_} {latestVersion}");
                        message.AppendLine();
                        message.AppendLine(commitMessage.ToString());

                        UpdateMessageGump gump = new UpdateMessageGump(message.ToString(), latestVersion);
                        byte[] packet          = gump.Compile();

                        SendPacketToClient(packet, packet.Length);
                    }
                }
                catch (Exception)
                {
                    // Squash all
                }
            });

            AbilitiesManager.GetInstance().Enabled = AbilityType.None;
        }
Example #15
0
        private static void OnMobileIncoming(PacketReader reader)
        {
            int            serial    = reader.ReadInt32();
            ItemCollection container = new ItemCollection(serial);

            Mobile mobile = serial == Engine.Player?.Serial ? Engine.Player : Engine.GetOrCreateMobile(serial);

            mobile.ID        = reader.ReadInt16();
            mobile.X         = reader.ReadInt16();
            mobile.Y         = reader.ReadInt16();
            mobile.Z         = reader.ReadSByte();
            mobile.Direction = (Direction)(reader.ReadByte() & 0x07);
            mobile.Hue       = reader.ReadUInt16();
            mobile.Status    = (MobileStatus)reader.ReadByte();
            mobile.Notoriety = (Notoriety)reader.ReadByte();

            bool useNewIncoming = Engine.ClientVersion >= new Version(7, 0, 33, 1);

            for ( ;;)
            {
                int itemSerial = reader.ReadInt32();

                if (itemSerial == 0)
                {
                    break;
                }

                Item item = Engine.GetOrCreateItem(itemSerial);
                item.Owner = serial;
                item.ID    = reader.ReadUInt16();
                item.Layer = (Layer)reader.ReadByte();

                if (useNewIncoming)
                {
                    item.Hue = reader.ReadUInt16();
                }
                else
                {
                    if ((item.ID & 0x8000) != 0)
                    {
                        item.ID ^= 0x8000;
                        item.Hue = reader.ReadUInt16();
                    }
                }

                container.Add(item);
            }

            mobile.Equipment.Clear();
            mobile.Equipment.Add(container.GetItems());

            foreach (Item item in container.GetItems())
            {
                mobile.SetLayer(item.Layer, item.Serial);
            }

            Engine.Items.Add(container.GetItems());

            if (!(mobile is PlayerMobile))
            {
                Engine.Mobiles.Add(mobile);
            }
            else
            {
                AbilitiesManager manager = AbilitiesManager.GetInstance();
                manager.ResendGump(manager.Enabled);
            }

            MobileIncomingEvent?.Invoke(mobile, container);
        }
        public static void SetAbility(string ability, string onOff = "toggle")
        {
            AbilitiesManager manager = AbilitiesManager.GetInstance();

            if (ability.ToLower().Equals("stun"))
            {
                Engine.SendPacketToServer(new StunRequest());
                return;
            }

            if (ability.ToLower().Equals("disarm"))
            {
                Engine.SendPacketToServer(new DisarmRequest());
                return;
            }

            bool primary;

            switch (ability.ToLower())
            {
            case "primary":
                primary = true;
                break;

            default:
                primary = false;
                break;
            }

            string onOffNormalized = onOff.Trim().ToLower();

            if (onOffNormalized != "toggle")
            {
                switch (onOffNormalized)
                {
                case "on":
                {
                    if (primary && manager.IsPrimaryEnabled || !primary && manager.IsSecondaryEnabled)
                    {
                        if (!MacroManager.QuietMode)
                        {
                            UOC.SystemMessage(Strings.Ability_already_set___, (int)UOC.SystemMessageHues.Green);
                        }

                        return;
                    }

                    break;
                }

                case "off":
                {
                    if (primary && !manager.IsPrimaryEnabled || !primary && !manager.IsSecondaryEnabled)
                    {
                        if (!MacroManager.QuietMode)
                        {
                            UOC.SystemMessage(Strings.Ability_not_set___, (int)UOC.SystemMessageHues.Green);
                        }

                        return;
                    }

                    break;
                }
                }
            }

            UOC.SystemMessage(string.Format(Strings.Setting_ability___0_____, ability),
                              (int)UOC.SystemMessageHues.Green);
            manager.SetAbility(primary ? AbilityType.Primary : AbilityType.Secondary);
        }