Exemplo n.º 1
0
        public static bool CheckPull()
        {
            string fnname = "Evade.CheckPull";

            MyTimer.Start(fnname);
            // Check for botpoi not being something else
            if (!(BotPoi.Current.Type == PoiType.Kill || BotPoi.Current.Type == PoiType.None))
            {
                return(false);
            }

            // Check for pull taking too long
            WoWUnit target = StyxWoW.Me.CurrentTarget;

            if (target == null || target.IsFriendly)
            {
                MyTimer.Stop(fnname);
                return(false);
            }

            if (StyxWoW.Me.HealthPercent < 50 || StyxWoW.Me.ManaPercent < 50)
            {
                FTWLogger.log(Color.Red, "Health or mana is below 50%, not pulling!");
                StyxWoW.Me.ClearTarget();
                MyTimer.Stop(fnname);
                return(false);
            }

            //if (!target.IsValidUnit())
            //{
            //    log("Blacklisting {0} for 60 seconds in CheckPull", target.SafeName());
            //    Blacklist.Add(target, TimeSpan.FromSeconds(60));
            //    StyxWoW.Me.ClearTarget();
            //    MyTimer.Stop(fnname);
            //    return false;
            //}

            int clustersize = target.ClusterSize();

            FTWLogger.log(Color.Violet, "PULL: Target = {0} at {1} ({2}) ({3} mobs surrounding)", target.SafeName(), target.DistanceCalc(), target.FactionId, clustersize);

            if (target.Guid != PullTargetGuid)
            {
                // New pull target - reset timer for maxPullTime seconds
                PullStopTime   = DateTime.Now.AddSeconds(MaxPullTime);
                PullTargetGuid = target.Guid;
            }
            else if (DateTime.Now > PullStopTime)
            {
                // Still pulling after maxPullTime seconds
                FTWLogger.log(Color.Red, "Can't pull {0} after {1} seconds - blacklist for 5 minutes.", target.SafeName(), MaxPullTime);
                Blacklist.Add(target.Guid, TimeSpan.FromMinutes(5));
                StyxWoW.Me.ClearTarget();
                MyTimer.Stop(fnname);
                return(false);
            }
            MyTimer.Stop(fnname);
            return(true);
        }
Exemplo n.º 2
0
        public static bool On_PetCast(string spellname, WoWUnit target, bool castnow)
        {
            string fnname = "FTWCore.On_PetCast";

            MyTimer.Start(fnname);
            LocalPlayer Me    = StyxWoW.Me;
            WoWPetSpell spell = null;

            // Don't even try to cast if I don't have a pet.
            if (!Me.GotAlivePet)
            {
                MyTimer.Stop(fnname);
                return(false);
            }

            foreach (WoWPetSpell sp in StyxWoW.Me.PetSpells)
            {
                if (sp.Action.ToString() == spellname)
                {
                    Lua.DoString("CastPetAction({0})", sp.ActionBarIndex + 1);
                    FTWLogger.log("[Pet] Action = {0}", sp.Action.ToString());
                    break;
                }

                else if (sp.Spell != null && sp.Spell.Name == spellname)
                {
                    spell = sp;
                    break;
                }
            }
            if (spell == null)
            {
                FTWLogger.debug(Color.Gray, "[Pet] Unknown spell {0}", spellname);
                MyTimer.Stop(fnname);
                return(false);
            }

            if (FTWCoreStatus.OnPetCooldown(spellname))
            {
                MyTimer.Stop(fnname);
                return(false);
            }

            if (!castnow && (Me.Pet.IsCasting || Me.Pet.IsChanneling))
            {
                MyTimer.Stop(fnname);
                return(false);
            }

            if (spell.Spell.MinRange > 0 && target.DistanceCalc() < spell.Spell.MinRange)
            {
                FTWLogger.debug(Color.Yellow, "[Pet] Too close to {0} to cast {1}.", target.SafeName(), spell.Spell.Name);
                MyTimer.Stop(fnname);
                return(false);
            }
            if (spell.Spell.MaxRange > 0 && target.DistanceCalc() > spell.Spell.MaxRange)
            {
                FTWLogger.debug(Color.Yellow, "[Pet] Too far away to {0} to cast {1}.", target.SafeName(), spell.Spell.Name);
                MyTimer.Stop(fnname);
                return(false);
            }

            string strTarget;

            if (target.Guid == StyxWoW.Me.Guid)
            {
                strTarget = "player";
            }
            else if (target.Guid == StyxWoW.Me.Pet.Guid)
            {
                strTarget = "pet";
            }
            else if (target.Guid == StyxWoW.Me.CurrentTargetGuid)
            {
                strTarget = "target";
            }
            else
            {
                strTarget = null;
            }

            if (strTarget == null)
            {
                Lua.DoString("CastPetAction({0})", spell.ActionBarIndex + 1);
                FTWLogger.log("    [Pet] Cast {0}", spell.Spell.Name);
            }
            else
            {
                Lua.DoString("CastPetAction({0}, {1})", spell.ActionBarIndex + 1, strTarget);
                FTWLogger.log("    [Pet] Cast {0} on {1} health {2:0.0} dist {3:0.0}", spell.Spell.Name, strTarget, target.HealthPercent, target.DistanceCalc());
            }

            if (spell.Spell.IsAreaSpell())
            {
                // Area spell
                WoWPoint loc;

                if (spell.Spell.IsSelfOnlySpell)
                {
                    loc = StyxWoW.Me.Location;
                }
                else
                {
                    loc = target.Location;
                }

                DateTime stoptime = DateTime.Now.AddMilliseconds(500);
                while (DateTime.Now < stoptime)
                {
                    if (StyxWoW.Me.CurrentPendingCursorSpell != null)
                    {
                        break;
                    }
                    Thread.Sleep(10);
                }
                SpellManager.ClickRemoteLocation(loc);
                stoptime = DateTime.Now.AddMilliseconds(500);
                while (DateTime.Now < stoptime)
                {
                    // Clear target spell, if one is up
                    if (StyxWoW.Me.CurrentPendingCursorSpell == null)
                    {
                        break;
                    }
                    Thread.Sleep(10);
                }
                // Clear target spell, if one is up
                if (StyxWoW.Me.CurrentPendingCursorSpell != null)
                {
                    Lua.DoString("SpellStopTargeting()");
                }
            }

            FTWCoreStatus.SaveCooldown(spell.Spell.Name);

            MyTimer.Stop(fnname);

            // We have no way of knowing if this spell was successfully cast or not.
            // Therefore, return false so it doesn't stop the action sequence.
            return(false);
        }
Exemplo n.º 3
0
        public static bool On_Cast(string firstpart, string spellname, WoWUnit target, bool castnow, bool castonce, bool debugspell = false)
        {
            string fnname = "FTWCore.On_Cast";

            MyTimer.Start(fnname);
            LocalPlayer Me     = StyxWoW.Me;
            WoWSpell    spell  = null;
            bool        retval = true;
            Color       ds     = Color.Magenta;

            if (target != null && !target.IsFriendly && target.IsDead)
            {
                if (debugspell)
                {
                    FTWLogger.log(ds, "Target is hostile and dead");
                }
                MyTimer.Stop(fnname);
                return(false);
            }

            if (FTWCoreStatus.OnCooldown(spellname, debugspell))
            {
                MyTimer.Stop(fnname);
                return(false);
            }

            if (target != null && !target.IsFriendly && !FTWUtils.MovementDisabled())
            {
                FTWCoreMovement.Face(target);
            }

            // Clear out expired CastOnce entries (older than CastOnceTime seconds)
            foreach (KeyValuePair <String, DateTime> kvp in FTWProps.CastOnce.ToList())
            {
                if (DateTime.Now > kvp.Value)
                {
                    FTWProps.CastOnce.Remove(kvp.Key);
                }
            }

            // Leave early if CastOnce contains unexpired entry for this unit
            if (FTWProps.CastOnce.ContainsKey(spellname + target.Guid.ToString()))
            {
                if (debugspell)
                {
                    FTWLogger.log(ds, "Already cast {0} on {1}", spellname, target.Name);
                }
                MyTimer.Stop(fnname);
                return(false);
            }

            if (SpellManager.GlobalCooldown)
            {
                if (debugspell)
                {
                    FTWLogger.log(ds, "...");
                }
                MyTimer.Stop(fnname);
                return(false);
            }

            try
            {
                if (FTWProps.fakecooldowns.ContainsKey(spellname))
                {
                    spell = WoWSpell.FromId(FTWProps.fakecooldowns[spellname].SpellID);
                }
                else if (SpellManager.Spells.ContainsKey(spellname))
                {
                    spell = SpellManager.Spells[spellname];
                }
                else
                {
                    FTWLogger.debug(Color.Gray, "Unknown spell {0}", spellname);
                    MyTimer.Stop(fnname);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                FTWLogger.log(Color.Pink, "Error when getting spell {0}: {1}", spellname, ex.Message);
                MyTimer.Stop(fnname);
                return(false);
            }

            if (spell == null)
            {
                FTWLogger.debug(Color.Gray, "Unknown spell '{0}'", spellname);
                MyTimer.Stop(fnname);
                return(false);
            }

            // Check whether or not you know the spell according to WoW
            if (false) // leave commented out for now
            {
                List <string> known      = Lua.GetReturnValues(String.Format("return IsSpellKnown({0})", spell.Id), "SpellKnown.lua");
                int           knownspell = Int32.Parse(known[0]);
                if (knownspell == 0)
                {
                    FTWLogger.log(Color.Gray, "GetSpellInfo says you don't know spell {0} ({1})", spellname, known[0]);
                    MyTimer.Stop(fnname);
                    return(false);
                }
            }

            if (false)
            {
                // Check power requirements
                List <string> values = Lua.GetReturnValues(String.Format("return GetSpellInfo({0})", spell.Id), "SpellInfo.lua");
                //string[] vars = {"name", "rank", "icon", "cost", "isFunnel", "powerType", "castTime", "minRange", "maxRange"};
                int      powerType  = Int32.Parse(values[5]);
                int      powerCost  = Int32.Parse(values[3]);
                string[] powertypes = { "mana",      "rage",        "focus",           "energy",
                                        "happiness", "runes",       "runic power",     "soul shards",
                                        "eclipse",   "holy power",  "alternate power", "dark force",
                                        "chi",       "shadow orbs", "burning embers",  "demonic fury" };
                if (StyxWoW.Me.UnitPower(powerType) < powerCost)
                {
                    FTWLogger.log(Color.Orange, "NOT ENOUGH {0} - Requires: {1}, but I have: {2}", powertypes[powerType], powerCost, StyxWoW.Me.UnitPower(powerType));
                    MyTimer.Stop(fnname);
                    return(false);
                }
            }

            if (!spell.IsSelfOnlySpell)
            {
                if (target == null)
                {
                    FTWLogger.log(Color.Orange, "Can't cast {0} on null target!", spell.Name);
                    if (debugspell)
                    {
                        FTWLogger.log(ds, "Null target");
                    }
                    MyTimer.Stop(fnname);
                    return(false);
                }
                double dist = target.Distance; // target.DistanceCalc();
                if ((spell.MinRange > 0 || spell.MaxRange > 0) && !(dist >= spell.MinRange && dist <= spell.MaxRange))
                {
                    FTWLogger.log(Color.Orange, "Can't cast spell {0} {1} on {2} health {3:0.0} dist {4:0.0} minrange {5} maxrange {6}", spellname, spell.Id, target.SafeName(), target.HealthPercent, target.DistanceCalc(), spell.MinRange, spell.MaxRange);
                    if (debugspell)
                    {
                        FTWLogger.log(ds, "Out of range");
                    }
                    MyTimer.Stop(fnname);
                    return(false);
                }
                if (!target.InLineOfSight)
                {
                    FTWLogger.log(Color.Orange, "Can't cast spell {0} {1} on {2} health {3:0.0} dist {4:0.0} (not in line of sight)", spellname, spell.Id, target.SafeName(), target.HealthPercent, target.DistanceCalc());
                    if (debugspell)
                    {
                        FTWLogger.log(ds, "Not in line of sight. Attempts = {0}.", FTWProps.not_in_los_attempts);
                    }
                    MyTimer.Stop(fnname);

                    FTWProps.not_in_los_attempts += 1;
                    Navigator.MoveTo(target.Location);
                    Thread.Sleep(2000);
                    return(false);
                }

                if (spellname == "Death Pact" && Me.GotAlivePet)
                {
                    Me.Pet.Target();
                    for (int l = 0; l < 2; l++)
                    {
                        Thread.Sleep(10);
                    }
                }

                if (FTWProps.CastOver.Contains(FTWProps.lastspellcastname))
                {
                    retval = true;
                }
                else if (spell.IsSelfOnlySpell)
                {
                    retval = SpellManager.CanCast(spell, true);
                }
                else
                {
                    retval = SpellManager.CanCast(spell, target, true);
                }

                if (FTWProps.IgnoreCanCast.Contains(spellname))
                {
                    if (debugspell)
                    {
                        FTWLogger.log(ds, "Ignoring cancast for {0}", spellname);
                    }
                    retval = true;
                }
                if (retval == false)
                {
                    if (spell.IsSelfOnlySpell)
                    {
                        FTWLogger.debug(Color.Orange, "CanCast returned false for {0} {1} on me", spellname, spell.Id);
                    }
                    else
                    {
                        FTWLogger.debug(Color.Orange, "CanCast returned false for {0} {1} on {2} health {3:0.0} dist {4:0.0}", spellname, spell.Id, target.SafeName(), target.HealthPercent, target.DistanceCalc());
                    }
                    MyTimer.Stop(fnname);
                    if (debugspell)
                    {
                        FTWLogger.log(ds, "CanCast returned false");
                    }
                    return(false);
                }
            }

            // Leave early if still casting
            if (!castnow && (Me.IsCasting || Me.IsChanneling))
            {
                if (debugspell)
                {
                    FTWLogger.log(ds, "Still casting");
                }
                return(false);
            }
            // Definitely going to cast - Stop casting
            if (Me.IsCasting || Me.IsChanneling)
            {
                if (FTWProps.CastOver.Contains(FTWProps.lastspellcastname))
                {
                    FTWLogger.log("Currently casting {0} - casting over it with {1}", FTWProps.lastspellcastname, spellname);
                }
                else if (castnow)
                {
                    SpellManager.StopCasting();
                }
            }

            // Stop moving
            if (spell.CastTime > 0 && !FTWUtils.MovementDisabled())
            {
                WoWMovement.MoveStop();
            }

            // Clear target spell, if one is up
            if (StyxWoW.Me.CurrentPendingCursorSpell != null)
            {
                Lua.DoString("SpellStopTargeting()");
            }

            if (spell.IsTankOnlySpell() == true)
            {
                // Spells that are only ever cast on tanks, such as Misdirection and Tricks of the Trade.
                if (FTWProps.people.Count > 1 && FTWProps.tank.Guid != Me.Guid && FTWProps.tank.IsDead == false)
                {
                    FTWLogger.log("cast tank-only spell {0} on {1}", spell.Name, FTWProps.tank.SafeName());
                    if (SpellManager.CanCast(spell, FTWProps.tank))
                    {
                        FTWLogger.log("nope - failed cancast check.");
                        retval = SpellManager.Cast(spell, FTWProps.tank);
                    }
                }
                else if (StyxWoW.Me.GotAlivePet && Me.Pet.IsDead == false)
                {
                    FTWLogger.log("cast tank-only spell {0} on pet", spell.Name);
                    if (SpellManager.CanCast(spell, Me.Pet))
                    {
                        FTWLogger.log("nope - failed cancast check.");
                        retval = SpellManager.Cast(spell, Me.Pet);
                    }
                }
                else
                {
                    retval = false;
                }
            }
            else if (spell.IsAreaSpell() == false)
            {
                // Most normal spells
                if (spell.IsSelfOnlySpell)
                {
                    retval = SpellManager.Cast(spell);
                }
                else
                {
                    retval = SpellManager.Cast(spell, target);
                }

                // Post-spell processing
                if (spellname == "Feign Death")
                {
                    while (Me.HasAura("Feign Death"))
                    {
                        List <WoWUnit> mobs = (List <WoWUnit>)FTWCoreUnits.GetNearbyUnfriendlyUnits();
                        if (mobs.Count == 0 && StyxWoW.Me.HealthPercent > 95)
                        {
                            break;
                        }
                        Thread.Sleep(10);
                    }
                }
            }
            else
            {
                // Area spell
                WoWPoint loc;

                if (spell.IsSelfOnlySpell && !spell.Name.EndsWith(" Trap"))
                {
                    loc = StyxWoW.Me.Location;
                }
                else
                {
                    loc = target.Location;
                }
                retval = SpellManager.Cast(spell);
                DateTime stoptime = DateTime.Now.AddMilliseconds(500);
                while (DateTime.Now < stoptime)
                {
                    if (StyxWoW.Me.CurrentPendingCursorSpell != null)
                    {
                        break;
                    }
                    Thread.Sleep(10);
                }
                SpellManager.ClickRemoteLocation(loc);
                stoptime = DateTime.Now.AddMilliseconds(500);
                while (DateTime.Now < stoptime)
                {
                    // Clear target spell, if one is up
                    if (StyxWoW.Me.CurrentPendingCursorSpell == null)
                    {
                        break;
                    }
                    Thread.Sleep(10);
                }
                // Clear target spell, if one is up
                if (StyxWoW.Me.CurrentPendingCursorSpell != null)
                {
                    Lua.DoString("SpellStopTargeting()");
                }
            }

            // Add current spell to CastOnce dictionary
            if (castonce == true)
            {
                FTWProps.CastOnce[spellname + target.Guid.ToString()] = DateTime.Now.AddSeconds(FTWProps.CastOnceTime);
            }

            // Wait until spell starts casting
            if (spell.CastTime > 0)
            {
                DateTime dt = DateTime.Now.AddSeconds(1.5);
                while (DateTime.Now < dt && !StyxWoW.Me.IsCasting && !StyxWoW.Me.IsChanneling)
                {
                    Thread.Sleep(10);
                }
            }

            // Save spell cooldown
            if (retval == true)
            {
                FTWLogger.log("    {0} {1} on {2} {3} health {4:0} dist {5:0.0} aggro {6} {7} (addscount {8})", firstpart, spellname, target.SafeName(), target.ShortGuid(), target.HealthPercent, target.DistanceCalc(), (int)target.ThreatInfo.ThreatStatus, target.ThreatInfo.ThreatStatus, FTWProps.adds.Count);
                FTWCoreStatus.SaveCooldown(spellname);
                FTWProps.MovementCooldown    = DateTime.Now.Add(TimeSpan.FromMilliseconds(Math.Min(1500, spell.CastTime)));
                FTWProps.not_in_los_attempts = 0;
            }
            else
            {
                FTWLogger.log(Color.Gray, "  - Couldn't cast spell {0} on {1} {2} at dist {3:0.0}", spellname, target.SafeName(), target.ShortGuid(), target.DistanceCalc());
            }

            if (FTWProps.Stuns.Contains(spellname))
            {
                // Don't attack again for 3 seconds - hb is slow in noticing cc's.
                Blacklist.Add(target.Guid, BlacklistFlags.Combat, TimeSpan.FromSeconds(3));
                if (target.Guid == StyxWoW.Me.CurrentTargetGuid)
                {
                    StyxWoW.Me.ClearTarget();
                }
            }

            MyTimer.Stop(fnname);
            return(retval);
        }
Exemplo n.º 4
0
        public static bool On_PetCast(string spellname, WoWUnit target, bool castnow)
        {
            string fnname = "FTWCore.On_PetCast";
            MyTimer.Start(fnname);
            LocalPlayer Me = StyxWoW.Me;
            WoWPetSpell spell = null;

            // Don't even try to cast if I don't have a pet.
            if (!Me.GotAlivePet)
            {
                MyTimer.Stop(fnname);
                return false;
            }

            foreach (WoWPetSpell sp in StyxWoW.Me.PetSpells)
            {
                if (sp.Action.ToString() == spellname)
                {
                    Lua.DoString("CastPetAction({0})", sp.ActionBarIndex + 1);
                    FTWLogger.log("[Pet] Action = {0}", sp.Action.ToString());
                    break;
                }

                else if (sp.Spell != null && sp.Spell.Name == spellname)
                {
                    spell = sp;
                    break;
                }
            }
            if (spell == null)
            {
                FTWLogger.debug(Color.Gray, "[Pet] Unknown spell {0}", spellname);
                MyTimer.Stop(fnname);
                return false;
            }

            if (FTWCoreStatus.OnPetCooldown(spellname))
            {
                MyTimer.Stop(fnname);
                return false;
            }

            if (!castnow && (Me.Pet.IsCasting || Me.Pet.IsChanneling))
            {
                MyTimer.Stop(fnname);
                return false;
            }

            if (spell.Spell.MinRange > 0 && target.DistanceCalc() < spell.Spell.MinRange)
            {
                FTWLogger.debug(Color.Yellow, "[Pet] Too close to {0} to cast {1}.", target.SafeName(), spell.Spell.Name);
                MyTimer.Stop(fnname);
                return false;
            }
            if (spell.Spell.MaxRange > 0 && target.DistanceCalc() > spell.Spell.MaxRange)
            {
                FTWLogger.debug(Color.Yellow, "[Pet] Too far away to {0} to cast {1}.", target.SafeName(), spell.Spell.Name);
                MyTimer.Stop(fnname);
                return false;
            }

            string strTarget;
            if (target.Guid == StyxWoW.Me.Guid)
                strTarget = "player";
            else if (target.Guid == StyxWoW.Me.Pet.Guid)
                strTarget = "pet";
            else if (target.Guid == StyxWoW.Me.CurrentTargetGuid)
                strTarget = "target";
            else
                strTarget = null;

            if (strTarget == null)
            {
                Lua.DoString("CastPetAction({0})", spell.ActionBarIndex + 1);
                FTWLogger.log("    [Pet] Cast {0}", spell.Spell.Name);
            }
            else
            {
                Lua.DoString("CastPetAction({0}, {1})", spell.ActionBarIndex + 1, strTarget);
                FTWLogger.log("    [Pet] Cast {0} on {1} health {2:0.0} dist {3:0.0}", spell.Spell.Name, strTarget, target.HealthPercent, target.DistanceCalc());
            }

            if (spell.Spell.IsAreaSpell())
            {
                // Area spell
                WoWPoint loc;

                if (spell.Spell.IsSelfOnlySpell)
                    loc = StyxWoW.Me.Location;
                else
                    loc = target.Location;

                DateTime stoptime = DateTime.Now.AddMilliseconds(500);
                while (DateTime.Now < stoptime)
                {
                    if (StyxWoW.Me.CurrentPendingCursorSpell != null)
                        break;
                    Thread.Sleep(10);
                }
                SpellManager.ClickRemoteLocation(loc);
                stoptime = DateTime.Now.AddMilliseconds(500);
                while (DateTime.Now < stoptime)
                {
                    // Clear target spell, if one is up
                    if (StyxWoW.Me.CurrentPendingCursorSpell == null)
                        break;
                    Thread.Sleep(10);
                }
                // Clear target spell, if one is up
                if (StyxWoW.Me.CurrentPendingCursorSpell != null)
                    Lua.DoString("SpellStopTargeting()");
            }

            FTWCoreStatus.SaveCooldown(spell.Spell.Name);

            MyTimer.Stop(fnname);

            // We have no way of knowing if this spell was successfully cast or not.
            // Therefore, return false so it doesn't stop the action sequence.
            return false;
        }
Exemplo n.º 5
0
        public static bool On_Cast(string firstpart, string spellname, WoWUnit target, bool castnow, bool castonce, bool debugspell = false)
        {
            string fnname = "FTWCore.On_Cast";
            MyTimer.Start(fnname);
            LocalPlayer Me = StyxWoW.Me;
            WoWSpell spell = null;
            bool retval = true;
            Color ds = Color.Magenta;

            if (target != null && !target.IsFriendly && target.IsDead)
            {
                if (debugspell) FTWLogger.log(ds, "Target is hostile and dead");
                MyTimer.Stop(fnname);
                return false;
            }

            if (FTWCoreStatus.OnCooldown(spellname, debugspell))
            {
                MyTimer.Stop(fnname);
                return false;
            }

            if (target != null && !target.IsFriendly && !FTWUtils.MovementDisabled())
                FTWCoreMovement.Face(target);

            // Clear out expired CastOnce entries (older than CastOnceTime seconds)
            foreach (KeyValuePair<String, DateTime> kvp in FTWProps.CastOnce.ToList())
            {
                if (DateTime.Now > kvp.Value)
                    FTWProps.CastOnce.Remove(kvp.Key);
            }

            // Leave early if CastOnce contains unexpired entry for this unit
            if (FTWProps.CastOnce.ContainsKey(spellname + target.Guid.ToString()))
            {
                if (debugspell)
                    FTWLogger.log(ds, "Already cast {0} on {1}", spellname, target.Name);
                MyTimer.Stop(fnname);
                return false;
            }

            if (SpellManager.GlobalCooldown)
            {
                if (debugspell)
                    FTWLogger.log(ds, "...");
                MyTimer.Stop(fnname);
                return false;
            }

            try
            {
                if (FTWProps.fakecooldowns.ContainsKey(spellname))
                    spell = WoWSpell.FromId(FTWProps.fakecooldowns[spellname].SpellID);
                else if (SpellManager.Spells.ContainsKey(spellname))
                    spell = SpellManager.Spells[spellname];
                else
                {
                    FTWLogger.debug(Color.Gray, "Unknown spell {0}", spellname);
                    MyTimer.Stop(fnname);
                    return false;
                }
            }
            catch (Exception ex)
            {
                FTWLogger.log(Color.Pink, "Error when getting spell {0}: {1}", spellname, ex.Message);
                MyTimer.Stop(fnname);
                return false;
            }

            if (spell == null)
            {
                FTWLogger.debug(Color.Gray, "Unknown spell '{0}'", spellname);
                MyTimer.Stop(fnname);
                return false;
            }

            // Check whether or not you know the spell according to WoW
            if (false) // leave commented out for now
            {
                List<string> known = Lua.GetReturnValues(String.Format("return IsSpellKnown({0})", spell.Id), "SpellKnown.lua");
                int knownspell = Int32.Parse(known[0]);
                if (knownspell == 0)
                {
                    FTWLogger.log(Color.Gray, "GetSpellInfo says you don't know spell {0} ({1})", spellname, known[0]);
                    MyTimer.Stop(fnname);
                    return false;
                }
            }

            if (false)
            {
                // Check power requirements
                List<string> values = Lua.GetReturnValues(String.Format("return GetSpellInfo({0})", spell.Id), "SpellInfo.lua");
                //string[] vars = {"name", "rank", "icon", "cost", "isFunnel", "powerType", "castTime", "minRange", "maxRange"};
                int powerType = Int32.Parse(values[5]);
                int powerCost = Int32.Parse(values[3]);
                string[] powertypes = { "mana", "rage", "focus", "energy",
                                        "happiness", "runes", "runic power", "soul shards",
                                        "eclipse", "holy power", "alternate power", "dark force",
                                        "chi", "shadow orbs", "burning embers", "demonic fury"
                                      };
                if (StyxWoW.Me.UnitPower(powerType) < powerCost)
                {
                    FTWLogger.log(Color.Orange, "NOT ENOUGH {0} - Requires: {1}, but I have: {2}", powertypes[powerType], powerCost, StyxWoW.Me.UnitPower(powerType));
                    MyTimer.Stop(fnname);
                    return false;
                }
            }

            if (!spell.IsSelfOnlySpell)
            {
                if (target == null)
                {
                    FTWLogger.log(Color.Orange, "Can't cast {0} on null target!", spell.Name);
                    if (debugspell)
                        FTWLogger.log(ds, "Null target");
                    MyTimer.Stop(fnname);
                    return false;
                }
                double dist = target.Distance; // target.DistanceCalc();
                if ((spell.MinRange > 0 || spell.MaxRange > 0) && !(dist >= spell.MinRange && dist <= spell.MaxRange))
                {
                    FTWLogger.log(Color.Orange, "Can't cast spell {0} {1} on {2} health {3:0.0} dist {4:0.0} minrange {5} maxrange {6}", spellname, spell.Id, target.SafeName(), target.HealthPercent, target.DistanceCalc(), spell.MinRange, spell.MaxRange);
                    if (debugspell)
                        FTWLogger.log(ds, "Out of range");
                    MyTimer.Stop(fnname);
                    return false;
                }
                if (!target.InLineOfSight)
                {
                    FTWLogger.log(Color.Orange, "Can't cast spell {0} {1} on {2} health {3:0.0} dist {4:0.0} (not in line of sight)", spellname, spell.Id, target.SafeName(), target.HealthPercent, target.DistanceCalc());
                    if (debugspell)
                        FTWLogger.log(ds, "Not in line of sight. Attempts = {0}.", FTWProps.not_in_los_attempts);
                    MyTimer.Stop(fnname);

                    FTWProps.not_in_los_attempts += 1;
                    Navigator.MoveTo(target.Location);
                    Thread.Sleep(2000);
                    return false;
                }

                if (spellname == "Death Pact" && Me.GotAlivePet)
                {
                    Me.Pet.Target();
                    for (int l = 0; l < 2; l++)
                        Thread.Sleep(10);
                }

                if (FTWProps.CastOver.Contains(FTWProps.lastspellcastname))
                    retval = true;
                else if (spell.IsSelfOnlySpell)
                    retval = SpellManager.CanCast(spell, true);
                else
                    retval = SpellManager.CanCast(spell, target, true);

                if (FTWProps.IgnoreCanCast.Contains(spellname))
                {
                    if (debugspell)
                        FTWLogger.log(ds, "Ignoring cancast for {0}", spellname);
                    retval = true;
                }
                if (retval == false)
                {
                    if (spell.IsSelfOnlySpell)
                        FTWLogger.debug(Color.Orange, "CanCast returned false for {0} {1} on me", spellname, spell.Id);
                    else
                        FTWLogger.debug(Color.Orange, "CanCast returned false for {0} {1} on {2} health {3:0.0} dist {4:0.0}", spellname, spell.Id, target.SafeName(), target.HealthPercent, target.DistanceCalc());
                    MyTimer.Stop(fnname);
                    if (debugspell)
                        FTWLogger.log(ds, "CanCast returned false");
                    return false;
                }
            }

            // Leave early if still casting
            if (!castnow && (Me.IsCasting || Me.IsChanneling))
            {
                if (debugspell) FTWLogger.log(ds, "Still casting");
                return false;
            }
            // Definitely going to cast - Stop casting
            if (Me.IsCasting || Me.IsChanneling)
            {
                if (FTWProps.CastOver.Contains(FTWProps.lastspellcastname))
                    FTWLogger.log("Currently casting {0} - casting over it with {1}", FTWProps.lastspellcastname, spellname);
                else if (castnow)
                    SpellManager.StopCasting();
            }

            // Stop moving
            if (spell.CastTime > 0 && !FTWUtils.MovementDisabled())
                WoWMovement.MoveStop();

            // Clear target spell, if one is up
            if (StyxWoW.Me.CurrentPendingCursorSpell != null)
                Lua.DoString("SpellStopTargeting()");

            if (spell.IsTankOnlySpell() == true)
            {
                // Spells that are only ever cast on tanks, such as Misdirection and Tricks of the Trade.
                if (FTWProps.people.Count > 1 && FTWProps.tank.Guid != Me.Guid && FTWProps.tank.IsDead == false)
                {
                    FTWLogger.log("cast tank-only spell {0} on {1}", spell.Name, FTWProps.tank.SafeName());
                    if (SpellManager.CanCast(spell, FTWProps.tank))
                    {
                        FTWLogger.log("nope - failed cancast check.");
                        retval = SpellManager.Cast(spell, FTWProps.tank);
                    }
                }
                else if (StyxWoW.Me.GotAlivePet && Me.Pet.IsDead == false)
                {
                    FTWLogger.log("cast tank-only spell {0} on pet", spell.Name);
                    if (SpellManager.CanCast(spell, Me.Pet))
                    {
                        FTWLogger.log("nope - failed cancast check.");
                        retval = SpellManager.Cast(spell, Me.Pet);
                    }
                }
                else
                    retval = false;
            }
            else if (spell.IsAreaSpell() == false)
            {
                // Most normal spells
                if (spell.IsSelfOnlySpell)
                    retval = SpellManager.Cast(spell);
                else
                    retval = SpellManager.Cast(spell, target);

                // Post-spell processing
                if (spellname == "Feign Death")
                {
                    while (Me.HasAura("Feign Death"))
                    {
                        List<WoWUnit> mobs = (List<WoWUnit>)FTWCoreUnits.GetNearbyUnfriendlyUnits();
                        if (mobs.Count == 0 && StyxWoW.Me.HealthPercent > 95)
                            break;
                        Thread.Sleep(10);
                    }
                }
            }
            else
            {
                // Area spell
                WoWPoint loc;

                if (spell.IsSelfOnlySpell && !spell.Name.EndsWith(" Trap"))
                    loc = StyxWoW.Me.Location;
                else
                    loc = target.Location;
                retval = SpellManager.Cast(spell);
                DateTime stoptime = DateTime.Now.AddMilliseconds(500);
                while (DateTime.Now < stoptime)
                {
                    if (StyxWoW.Me.CurrentPendingCursorSpell != null)
                        break;
                    Thread.Sleep(10);
                }
                SpellManager.ClickRemoteLocation(loc);
                stoptime = DateTime.Now.AddMilliseconds(500);
                while (DateTime.Now < stoptime)
                {
                    // Clear target spell, if one is up
                    if (StyxWoW.Me.CurrentPendingCursorSpell == null)
                        break;
                    Thread.Sleep(10);
                }
                // Clear target spell, if one is up
                if (StyxWoW.Me.CurrentPendingCursorSpell != null)
                    Lua.DoString("SpellStopTargeting()");

            }

            // Add current spell to CastOnce dictionary
            if (castonce == true)
                FTWProps.CastOnce[spellname + target.Guid.ToString()] = DateTime.Now.AddSeconds(FTWProps.CastOnceTime);

            // Wait until spell starts casting
            if (spell.CastTime > 0)
            {
                DateTime dt = DateTime.Now.AddSeconds(1.5);
                while (DateTime.Now < dt && !StyxWoW.Me.IsCasting && !StyxWoW.Me.IsChanneling)
                    Thread.Sleep(10);
            }

            // Save spell cooldown
            if (retval == true)
            {
                FTWLogger.log("    {0} {1} on {2} {3} health {4:0} dist {5:0.0} aggro {6} {7} (addscount {8})", firstpart, spellname, target.SafeName(), target.ShortGuid(), target.HealthPercent, target.DistanceCalc(), (int)target.ThreatInfo.ThreatStatus, target.ThreatInfo.ThreatStatus, FTWProps.adds.Count);
                FTWCoreStatus.SaveCooldown(spellname);
                FTWProps.MovementCooldown = DateTime.Now.Add(TimeSpan.FromMilliseconds(Math.Min(1500, spell.CastTime)));
                FTWProps.not_in_los_attempts = 0;
            }
            else
            {
                FTWLogger.log(Color.Gray, "  - Couldn't cast spell {0} on {1} {2} at dist {3:0.0}", spellname, target.SafeName(), target.ShortGuid(), target.DistanceCalc());
            }

            if (FTWProps.Stuns.Contains(spellname))
            {
                // Don't attack again for 3 seconds - hb is slow in noticing cc's.
                Blacklist.Add(target.Guid, BlacklistFlags.Combat, TimeSpan.FromSeconds(3));
                if (target.Guid == StyxWoW.Me.CurrentTargetGuid)
                    StyxWoW.Me.ClearTarget();
            }

            MyTimer.Stop(fnname);
            return retval;
        }
Exemplo n.º 6
0
        public static bool FollowTarget()
        {
            string fnname = "FTWCore.FollowTarget";

            MyTimer.Start(fnname);
            LocalPlayer Me           = StyxWoW.Me;
            WoWUnit     followtarget = null;
            double      maxDist      = FTWProps.range;
            bool        retval       = false;
            bool        followtank   = false;

            if (Styx.CommonBot.BotManager.Current.Name == "Grind Bot" &&
                FTWProps.tank.IsDead == false &&
                FTWProps.tank.Guid != StyxWoW.Me.Guid)
            {
                followtank = true;
            }
            else
            {
                followtank = false;
            }

            // Leave early if they don't want movement and facing.
            if (FTWUtils.MovementDisabled())
            {
                FTWLogger.log(Color.Violet, "Movement disabled, not following");
            }
            else if (DateTime.Now < FTWProps.MovementCooldown || StyxWoW.Me.IsCasting || StyxWoW.Me.IsChanneling)
            {
                //log(Color.Violet, "Casting, not following");
            }
            else if (BotPoi.Current.Type == PoiType.Loot)
            {
                FTWLogger.log(Color.Violet, "Looting, not following");
            }
            else if (FTWProps.mode == "@PULL")
            {
                // Just follow whoever is targeted
                followtarget = StyxWoW.Me.CurrentTarget;
            }
            else if (FTWProps.mode == "@COMBAT")
            {
                // In combat, follow target preferentially
                followtarget = StyxWoW.Me.CurrentTarget;
                if (StyxWoW.Me.IsHealer() ||
                    (followtarget == null ||
                     !followtarget.IsValidUnit()
                    ) && followtank)
                {
                    followtarget = FTWProps.tank;
                    maxDist      = 10;
                }
            }
            else if (FTWProps.mode == "@REST")
            {
                // Out of combat, follow tank preferentially
                if (followtank)
                {
                    followtarget = FTWProps.tank;
                    maxDist      = 15;
                }
            }
            else
            {
                FTWLogger.log(Color.Red, "UNKNOWN MODE {0}", FTWProps.mode);
            }

            if (followtarget == null)
            {
                //log(Color.Violet, "No target in FollowTarget");
            }
            else if (followtarget.IsDead)
            {
                //log(Color.Violet, "Target is dead in FollowTarget");
            }
            else if (followtarget.DistanceCalc() <= maxDist && followtarget.InLineOfSpellSight)
            {
                // If close enough, leave
                WoWMovement.MoveStop();
                if (followtarget.IsValidUnit() && !StyxWoW.Me.IsSafelyFacing(followtarget))
                {
                    Face(followtarget);
                }
            }
            else
            {
                // Keep following
                FTWLogger.log("Keep following {0} (dist {1:0.00}, InLineOfSight = {2}, InLineOfSpellSight = {3})", followtarget.SafeName(), followtarget.DistanceCalc(), followtarget.InLineOfSight, followtarget.InLineOfSpellSight);
                WoWPoint loc = followtarget.Location;

                // Get to right under the mob, if it's flying
                if (!Navigator.CanNavigateFully(StyxWoW.Me.Location, followtarget.Location))
                {
                    //List<float> heights = Navigator.FindHeights(loc.X, loc.Y);
                    //if (heights.Count > 0)
                    //    loc.Z = heights.Max();
                    Styx.WoWInternals.WoWMovement.ClickToMove(loc);
                }
                else
                {
                    // Move to the mob's location
                    Navigator.MoveTo(loc);
                }
                retval = true;
            }

            MyTimer.Stop(fnname);
            return(retval);
        }