Exemple #1
0
        public static async Task <bool> CastSpell(
            TkClient caster,
            KeySpell spell,
            bool isLowCostSpell   = false,
            string targetName     = null,
            string secondaryInput = null)
        {
            if (spell == null)
            {
                return(false);
            }

            if (spell.IsOrbSpell)
            {
                await caster.Activity.WaitForCommandCooldown();
            }
            else if (spell.Cost == 0) // For spells like Ambush and Invisible.
            {
                await caster.Activity.WaitForMeleeCooldown();
            }
            else if (isLowCostSpell && !await ItemCommands.RestoreMinorManaForSpell(caster, spell))
            {
                return(false);
            }
            else if (!await ItemCommands.RestoreMajorManaForSpell(caster, spell))
            {
                return(false);
            }

            var spellOrItemKey = spell.IsOrbSpell
                ? "u"
                : "Z";

            caster.Send($"{Keys.Esc}{spellOrItemKey}");

            if (!string.IsNullOrWhiteSpace(secondaryInput))
            {
                await Task.Delay(SecondaryInputDelay);

                caster.Send(spell.Letter);
                await Task.Delay(SecondaryInputDelay);

                caster.Send(secondaryInput);
            }
            else
            {
                caster.Send(spell.Letter);
            }

            if (!string.IsNullOrWhiteSpace(targetName) || !string.IsNullOrWhiteSpace(secondaryInput))
            {
                caster.Send($"{Keys.Enter}");
            }

            caster.Activity.ResetCommandCooldown();

            // ReSharper disable once InvertIf
            if (Log.IsEnabled(LogEventLevel.Information))
            {
                var logMessage = $"{caster.Self.Name} cast {spell.DisplayName}.";

                if (!string.IsNullOrWhiteSpace(targetName))
                {
                    logMessage = logMessage.Replace(".", $" on {targetName}.");
                }

                if (!string.IsNullOrWhiteSpace(secondaryInput))
                {
                    logMessage = logMessage.Replace(".", $" using \"{secondaryInput}\".");
                }

                Log.Information(logMessage);
            }

            return(true);
        }
Exemple #2
0
        public static async Task <bool> CastSpell(
            TkClient caster,
            KeySpell spell,
            bool isLowCostSpell   = false,
            string targetName     = null,
            string secondaryInput = null)
        {
            if (spell == null)
            {
                return(false);
            }

            if (spell.Cost == 0)
            {
                // Do not bother checking to see if a mana restoration item is needed.
            }

            else if (isLowCostSpell)
            {
                await ItemCommands.RestoreMinorManaForSpell(caster, spell);
            }

            else
            {
                await ItemCommands.RestoreMajorManaForSpell(caster, spell);
            }

            caster.Send($"{Keys.Esc}Z");

            if (!string.IsNullOrWhiteSpace(secondaryInput))
            {
                await Task.Delay(SecondaryInputDelay);

                caster.Send(spell.Letter);
                await Task.Delay(SecondaryInputDelay);

                caster.Send(secondaryInput);
            }

            else
            {
                caster.Send(spell.Letter);
            }

            if (!string.IsNullOrWhiteSpace(targetName) || !string.IsNullOrWhiteSpace(secondaryInput))
            {
                caster.Send($"{Keys.Enter}");
            }

            caster.Activity.ResetCommandCooldown();

            // ReSharper disable once InvertIf
            if (Log.IsEnabled(LogEventLevel.Information))
            {
                var logMessage = $"{caster.Self.Name} cast {spell.DisplayName}.";

                if (!string.IsNullOrWhiteSpace(targetName))
                {
                    logMessage = logMessage.Replace(".", $" on {targetName}.");
                }

                if (!string.IsNullOrWhiteSpace(secondaryInput))
                {
                    logMessage = logMessage.Replace(".", $" using \"{secondaryInput}\".");
                }

                Log.Information(logMessage);
            }

            return(true);
        }