Hello Wrobot Community,
I am currently working on a script for WoW 3.3.5a private server, and I need some assistance in making my function asynchronous to ensure it is executed properly. Here's the code snippet I am using:
public static bool WildGrowthHeal(WowPlayerExtended player)
{
if (CanCast(Main.WildGrowth, player.OriginalPlayer))
{
SpellManager.CastSpellByNameOn("Wild Growth", player.OriginalPlayer.Name);
Logging.WriteDebug($"{player.OriginalPlayer.Name}Wild Growth");
return true;
}
return false;
}
&&
internal static bool CanCast(Spell spell, WoWUnit target, bool canMove = true, bool tank = false)
{
// Check if the caster is not stunned, not dead, not casting, the target is alive, the spell is usable,
// the distance to the target is good, and there is no line of sight issue
if (!ObjectManager.Me.IsStunned && !ObjectManager.Me.IsDead && !ObjectManager.Me.IsCast && !target.IsDead && spell.IsSpellUsable && spell.IsDistanceGood && !TraceLine.TraceLineGo(target.Position))
{
if (target.MaxHealth - target.Health != 0 || tank)
{
// Log the spell cast and the target's health percentage
Logging.WriteDebug($"Cast: {spell.NameInGame} on {target.Name} because life had less than {target.MaxHealth - target.Health} PV and he is a {target.WowClass}");
// Return true, indicating the spell can be cast
return true;
}
}
// Return false, indicating the spell cannot be cast
return false;
}
This function checks if "Wild Growth" can be cast on a player and casts the spell if possible. However, I want to make sure that the function waits for the spell to be cast before proceeding further. I am aware that using Thread.Sleep is not the best solution, as it can block the thread and cause other issues.
Instead, I would like to make this function asynchronous using async and await, but I'm not sure how to do this with the current SpellManager.CastSpellByNameOn method, which is not asynchronous.
Could anyone please provide guidance on how to make this function asynchronous or suggest an alternative way to ensure that the spell is cast before the function proceeds further? Any help would be greatly appreciated
Thank you in advance for your assistance!