Esempio n. 1
0
        public static bool On_FindBetterTarget(string reason)
        {
            string fnname = "FTWCore.On_FindBetterTarget";

            MyTimer.Start(fnname);
            if (FTWUtils.MovementDisabled())
            {
                FTWLogger.log(Color.Violet, "MOVEMENT DISABLED, not looking for better target");
                MyTimer.Stop(fnname);
                return(false);
            }
            WoWUnit target = StyxWoW.Me.CurrentTarget;

            if (target != null && target.IsValidUnit() && !target.IsDead && !target.IsCrowdControlled() && FTWCoreStatus.OnCooldown("FindBetterTarget"))
            {
                MyTimer.Stop(fnname);
                return(false);
            }

            bool retval = ListAndTakeNewTarget(FTWProps.adds);

            if (retval == true)
            {
                FTWCoreStatus.SaveCooldown("FindBetterTarget");
            }
            MyTimer.Stop(fnname);
            return(retval);
        }
Esempio n. 2
0
        public static bool ImbueWeapon(String spellname, string slotname, int slotid)
        {
            bool retval;

            FTWLogger.log(Color.YellowGreen, "ImbueWeapon {0} {1} {2}", spellname, slotname, slotid);
            if (!SpellManager.HasSpell(spellname))
            {
                FTWLogger.log(Color.YellowGreen, "Don't have spell");
                retval = false;
            }
            else if (FTWCoreStatus.OnCooldown(spellname, true))
            {
                retval = false;
            }
            else
            {
                FTWLogger.log(Color.YellowGreen, "Imbuing {0} weapon with '{1}'", slotname, spellname);
                Lua.DoString(string.Format("CancelItemTempEnchantment({0})", slotid));
                Thread.Sleep(1000);
                FTWCoreActions.On_Cast(string.Format("Me.ImbueWeapon{0}", slotid), spellname, StyxWoW.Me, false, false);
                Thread.Sleep(1000);
                FTWCoreStatus.SaveCooldown(spellname);
                retval = true;
            }
            return(retval);
        }
Esempio n. 3
0
        public static bool On_CastAll(string firstpart, string auraname)
        {
            bool   retval = false;
            string fnname = "FTWCore.On_CastAll";

            MyTimer.Start(fnname);
            WoWUnit mobwithoutaura = (from a in FTWProps.adds
                                      where a.HealthPercent > 30
                                      where a.InLineOfSight
                                      where a.Distance < 40
                                      where a.HasMyAura(auraname) == false
                                      select a).FirstOrDefault();

            if (mobwithoutaura != null)
            {
                if (FTWUtils.MovementDisabled())
                {
                    FTWLogger.log(Color.Violet, "MOVEMENT DISABLED - Not facing target in CastAll");
                }
                else
                {
                    FTWCoreMovement.Face(mobwithoutaura);
                }
                retval = On_Cast(firstpart, auraname, mobwithoutaura, false, false);
            }

            MyTimer.Stop(fnname);
            return(retval);
        }
Esempio n. 4
0
        public static bool On_Execute(string firstpart, string spellname)
        {
            // Interrupts the spellcaster furthest away from you
            string fnname = "FTWCore.On_Execute";

            MyTimer.Start(fnname);
            int      range = 5;
            WoWSpell spell = null;

            try
            {
                if (FTWProps.fakecooldowns.ContainsKey(spellname))
                {
                    spell = WoWSpell.FromId(FTWProps.fakecooldowns[spellname].SpellID);
                }
                else
                {
                    spell = SpellManager.Spells[spellname];
                }
            }
            catch (KeyNotFoundException ex) { }
            if (spell == null || spell.CooldownTimeLeft.TotalMilliseconds > 0)
            {
                MyTimer.Stop(fnname);
                return(false);
            }
            range = Math.Max(range, (int)spell.MaxRange);
            WoWUnit mob = (from a in FTWProps.adds
                           where a.HealthPercent < 25
                           where a.InLineOfSight
                           //where (a.IsCasting == true || a.IsChanneling == true)
                           where a.Distance < range
                           //where a.CanInterruptCurrentSpellCast == true
                           orderby a.Distance descending
                           select a).FirstOrDefault();

            if (mob == null)
            {
                MyTimer.Stop(fnname);
                return(false);
            }
            if (FTWUtils.MovementDisabled())
            {
                FTWLogger.log(Color.Violet, "MOVEMENT DISABLED - Not facing target on execute!");
            }
            else
            {
                FTWCoreMovement.Face(mob);
            }
            bool retval = On_Cast(firstpart, spellname, mob, true, false);

            if (retval)
            {
                FTWLogger.log(Color.GreenYellow, "    Executed on {0} with {1} dist {2:0.0} ", mob.SafeName(), spellname, mob.Distance);
            }
            MyTimer.Stop(fnname);
            return(retval);
        }
Esempio n. 5
0
        public static bool ListAndTakeNewTarget(List <WoWUnit> units)
        {
            string fnname = "FTWCore.ListAndTakeNewTarget";

            MyTimer.Start(fnname);
            if (units == null || units.Count == 0)
            {
                MyTimer.Stop(fnname);
                return(false);
            }

            WoWUnit newtarget = units[0];

            // Leave early if the first unit is the same as the current target
            if (newtarget.Guid == StyxWoW.Me.CurrentTargetGuid)
            {
                MyTimer.Stop(fnname);
                return(false);
            }
            FTWLogger.log(Color.Violet, "Retargeting during combat - taking the first target from the list below.");
            foreach (WoWUnit unit in units)
            {
                string tag2 = "";
                if (unit.Guid == newtarget.Guid)
                {
                    tag2 += "+";
                }
                if (unit.Guid == StyxWoW.Me.CurrentTargetGuid)
                {
                    tag2 += "-";
                }
                if (unit.Guid == FTWProps.tank.CurrentTargetGuid)
                {
                    tag2 += "t";
                }
                tag2 = (tag2 + "  ").Substring(0, 2);
                FTWLogger.log(Color.Violet, "    {0} {1,-24} cc={2} atkhlr={3} wgt={4} thr={5} tank={6} inrange={7} dist={8:0.0} atk={9} {10} {11:0}",
                              tag2,
                              unit.SafeName(),
                              unit.IsCrowdControlled() ? 1 : 0,
                              unit.IsAttackingHealer() ? 1 : 0,
                              unit.TargetWeight(),
                              (int)unit.ThreatInfo.ThreatStatus,
                              unit.Guid == FTWProps.tank.CurrentTargetGuid ? 1 : 0,
                              unit.Distance < 5 ? 1 : 0,
                              unit.DistanceCalc(),
                              unit.CurrentTarget != null && unit.CurrentTarget.IsPlayer ? "?" : "",
                              unit.CurrentTarget != null ? unit.CurrentTarget.SafeName() : "",
                              unit.CurrentTarget != null ? unit.CurrentTarget.HealthPercent : 0);
            }
            newtarget.Target();
            FTWCoreMovement.Face(newtarget);

            MyTimer.Stop(fnname);
            return(true);
        }
Esempio n. 6
0
        public static bool On_Paralyze(string firstpart, string spellname)
        {
            // Paralyzes the spellcaster furthest away from you
            // Similar to On_Interrupt, except doesn't check for interruptability
            // and prioritizes mobs attacking the healer over others.
            int      range = 5;
            WoWSpell spell = null;

            try
            {
                if (FTWProps.fakecooldowns.ContainsKey(spellname))
                {
                    spell = WoWSpell.FromId(FTWProps.fakecooldowns[spellname].SpellID);
                }
                else
                {
                    spell = SpellManager.Spells[spellname];
                }
            }
            catch (KeyNotFoundException ex) { }
            if (spell == null || spell.CooldownTimeLeft.TotalMilliseconds > 0)
            {
                return(false);
            }
            range = Math.Max(range, (int)spell.MaxRange);
            WoWUnit castingmob = (from a in FTWProps.adds
                                  where a.HealthPercent > 30
                                  where a.InLineOfSight
                                  where a.IsCasting == true ||
                                  a.IsChanneling == true ||
                                  a.IsAttackingHealer() == true
                                  where a.Distance < range
                                  orderby a.IsAttackingHealer() descending, a.Distance descending
                                  select a).FirstOrDefault();

            if (castingmob == null)
            {
                return(false);
            }
            if (FTWUtils.MovementDisabled())
            {
                FTWLogger.log(Color.Violet, "MOVEMENT DISABLED - Not facing target on paralyze!");
            }
            else
            {
                FTWCoreMovement.Face(castingmob);
            }

            bool retval = On_Cast(firstpart, spellname, castingmob, true, false);

            if (retval)
            {
                FTWLogger.log(Color.GreenYellow, "    Paralyzed {0} with {1} dist {2:0.0} attackinghealer {3}", castingmob.SafeName(), spellname, castingmob.Distance, castingmob.IsAttackingHealer());
            }
            return(retval);
        }
Esempio n. 7
0
        public static bool On_AutoAttack()
        {
            string fnname = "FTWCore.On_AutoAttack";

            MyTimer.Start(fnname);
            if (!StyxWoW.Me.IsAutoAttacking && StyxWoW.Me.CurrentTarget != null)
            {
                FTWLogger.log("    AutoAttack");
                Lua.DoString("StartAttack()");
            }
            MyTimer.Stop(fnname);
            return(false);
        }
Esempio n. 8
0
        public static List <WoWPlayer> GetGroup()
        {
            List <WoWPlayer> list;

            try
            {
                string fnname = "FTWCore.GetGroup";
                MyTimer.Start(fnname);
                //ulong[] guids = StyxWoW.Me.GroupInfo.RaidMemberGuids.Union(StyxWoW.Me.GroupInfo.PartyMemberGuids).Union(new[] { StyxWoW.Me.Guid }).Distinct().ToArray();

                //list = (from p in ObjectManager.GetObjectsOfType<WoWPlayer>(true, true)
                //        where p.IsFriendly && guids.Any(g => g == p.Guid)
                //        select p).ToList();

                list = (StyxWoW.Me.GroupInfo.IsInRaid ? StyxWoW.Me.RaidMembers : StyxWoW.Me.PartyMembers);
                if (!list.Contains(StyxWoW.Me))
                {
                    list.Add(StyxWoW.Me);
                }
                list.Sort(
                    delegate(WoWPlayer p1, WoWPlayer p2)
                {
                    if (p1.DistanceSqr.CompareTo(p2.DistanceSqr) == 0)
                    {
                        return(p1.Guid.CompareTo(p2.Guid));
                    }
                    else
                    {
                        return(p1.DistanceSqr.CompareTo(p2.DistanceSqr));
                    }
                }
                    );

                MyTimer.Stop(fnname);
                return(list);
            }
            catch (Exception ex)
            {
                FTWLogger.log(Color.Red, "Error when getting group members: {0}", ex.Message);
                list = new List <WoWPlayer>();
                list.Add(StyxWoW.Me);
                return(list);
            }
        }
Esempio n. 9
0
        public static bool On_GrabAggro()
        {
            string fnname = "FTWCore.On_GrabAggro";

            MyTimer.Start(fnname);
            if (FTWUtils.MovementDisabled())
            {
                FTWLogger.log(Color.Violet, "MOVEMENT DISABLED - Not grabbing aggro.");
                MyTimer.Stop(fnname);
                return(false);
            }
            WoWUnit target = StyxWoW.Me.CurrentTarget;

            if (target != null && target.IsValidUnit() && FTWCoreStatus.OnCooldown("GrabAggro"))
            {
                MyTimer.Stop(fnname);
                return(false);
            }

            List <WoWUnit> units =
                (from u in FTWProps.adds
                 where u.Combat && u.IsValidUnit()
                 orderby
                 u.TargetWeight() descending,
                 u.IsCrowdControlled() ascending,
                 u.IsAttackingHealer() descending,
                 (int)u.ThreatInfo.ThreatStatus < 4 descending,
                 u.Guid == StyxWoW.Me.CurrentTargetGuid descending,
                 u.Guid == FTWProps.tank.CurrentTargetGuid descending,
                 u.Distance < 5 descending,
                 u.DistanceSqr ascending
                 select u).ToList();

            bool retval = ListAndTakeNewTarget(units);

            if (retval == true)
            {
                FTWCoreStatus.SaveCooldown("GrabAggro");
            }
            MyTimer.Stop(fnname);
            return(retval);
        }
Esempio n. 10
0
        public static bool On_PetAttack()
        {
            bool   retval;
            string fnname = "FTWCore.On_PetAttack";

            MyTimer.Start(fnname);
            using (StyxWoW.Memory.AcquireFrame())
            {
                if (!(StyxWoW.Me.GotAlivePet))
                {
                    FTWLogger.log(Color.Red, "Don't have alive pet");
                    retval = false;
                }
                else
                {
                    WoWUnit pet = StyxWoW.Me.Pet;
                    if (pet.CurrentTargetGuid == StyxWoW.Me.CurrentTargetGuid)
                    {
                        retval = false;
                    }
                    else
                    {
                        FTWLogger.log("    Siccing pet on {0} health {1:0} dist {2:0.0}", StyxWoW.Me.CurrentTarget.SafeName(), StyxWoW.Me.CurrentTarget.HealthPercent, StyxWoW.Me.CurrentTarget.DistanceCalc());
                        foreach (WoWPetSpell sp in StyxWoW.Me.PetSpells)
                        {
                            if (sp.Action.ToString() == "Attack")
                            {
                                Lua.DoString("CastPetAction({0})", sp.ActionBarIndex + 1);
                                break;
                            }
                        }
                        retval = false;
                    }
                }
            }
            MyTimer.Stop(fnname);
            return(retval);
        }
Esempio n. 11
0
        public static bool On_UsePotion(HashSet <String> spellnames)
        {
            bool   retval = true;
            string fnname = "FTWCore.On_UsePotion";

            MyTimer.Start(fnname);
            using (StyxWoW.Memory.AcquireFrame())
            {
                if (!FTWUtils.ValidState())
                {
                    retval = false;
                }
                else
                {
                    WoWItem potion = (from i in StyxWoW.Me.CarriedItems
                                      let spells = i.ItemSpells
                                                   where i.ItemInfo != null && spells != null && spells.Count != 0 &&
                                                   i.Usable && i.Cooldown == 0 && i.ItemInfo.RequiredLevel <= StyxWoW.Me.Level &&
                                                   spells.Any(s => s.IsValid && s.ActualSpell != null && spellnames.Contains(s.ActualSpell.Name))
                                                   orderby i.ItemInfo.Level descending
                                                   select i).FirstOrDefault();
                    if (FTWProps.debugitems.Count > 0)
                    {
                        foreach (WoWItem item in StyxWoW.Me.CarriedItems)
                        {
                            if (FTWProps.debugitems.Contains(item.Name))
                            {
                                List <WoWItem.WoWItemSpell> spells = item.ItemSpells;
                                ItemInfo inf = item.ItemInfo;
                                FTWLogger.debug(string.Format("{0} {1} {2}", item.Name, item.Usable, item.Cooldown));
                                if (spells != null)
                                {
                                    foreach (WoWItem.WoWItemSpell itemspell in spells)
                                    {
                                        FTWLogger.debug(string.Format("    {0} {1}", itemspell.Id, itemspell.ToString()));
                                        WoWSpell actualspell = itemspell.ActualSpell;
                                        if (actualspell != null)
                                        {
                                            FTWLogger.debug(string.Format("        {0} {1} {2}", actualspell.Id, actualspell.Name, actualspell.IsValid));
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (potion == null)
                    {
                        retval = false;
                    }
                    else
                    {
                        potion.UseContainerItem();
                        FTWLogger.log(Color.SkyBlue, "Using {0}", potion.Name);
                        retval = true;
                    }
                }
            }
            MyTimer.Stop(fnname);
            return(retval);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        public static bool ExecuteAction(string action)
        {
            string fnname = "FTWCore.ExecuteAction";
            string subfn  = string.Format("FTWCore.ExecuteAction '{0}'", action);

            MyTimer.Start(fnname);
            MyTimer.Start(subfn);
            bool    retval = false;
            WoWUnit Me     = StyxWoW.Me;

            if (action == null)
            {
                throw new Exception("ExecuteAction - received null action");
            }
            action = action.Replace("\t", "");
            while (action.StartsWith(" "))
            {
                action = action.Substring(1, action.Length - 1);
            }
            action = action.Replace("  ", " ");
            if (!action.Contains("."))
            {
                action = "Target.Cast " + action;
            }

            if (action == "Target.Cast Blacklist" && Me.CurrentTarget != null)
            {
                FTWLogger.log(Color.Violet, "Blackisting {0} for 60 seconds", Me.CurrentTarget.SafeName());
                Blacklist.Add(Me.CurrentTarget, TimeSpan.FromSeconds(60));
                StyxWoW.Me.ClearTarget();
                retval = true;
            }
            else
            {
                // Get first and last part of string
                string lastpart  = string.Empty;
                string firstpart = string.Empty;

                int index = action.IndexOf(" ");
                if (index > -1)
                {
                    firstpart = action.Substring(0, index);
                    lastpart  = action.Substring(index + 1, action.Length - index - 1);
                }
                else
                {
                    firstpart = action;
                    lastpart  = string.Empty;
                }

                // Get target of action
                string[] words  = firstpart.Split('.');
                WoWUnit  target = null;
                switch (words[0])
                {
                case "Me": target = Me; break;

                case "Target": target = Me.CurrentTarget; break;

                case "Tank": target = FTWProps.tank; break;

                case "Healer": target = FTWProps.healer; break;

                case "Heal": target = FTWProps.healTarget; break;

                case "Revive": target = FTWProps.reviveTarget; break;

                case "Cleanse": target = FTWProps.cleanseTarget; break;

                case "Pet": target = Me.Pet; break;

                case "Add": target = FTWProps.add; break;

                default: target = null; break;
                }
                if (target == null)
                {
                    retval = false;
                }
                else
                {
                    switch (words[1])
                    {
                    // Actions that use targets (Me, Target, Tank, etc from the list above.)
                    case "DebugCast": retval = On_Cast(firstpart, lastpart, target, false, false, true); break;

                    case "Cast": retval = On_Cast(firstpart, lastpart, target, false, false); break;

                    case "DebugCastNow": retval = On_Cast(firstpart, lastpart, target, true, false, true); break;

                    case "CastNow": retval = On_Cast(firstpart, lastpart, target, true, false); break;

                    case "StopCasting": retval = On_StopCasting(lastpart); break;

                    case "DebugCastOnce": retval = On_Cast(firstpart, lastpart, target, true, true, true); break;

                    case "CastOnce": retval = On_Cast(firstpart, lastpart, target, true, true); break;

                    case "DumpAuras": retval = FTWCoreStatus.On_DumpAuras(target); break;

                    case "DumpParty": retval = FTWCoreStatus.On_DumpParty(); break;

                    case "PetCast": retval = On_PetCast(lastpart, target, false); break;

                    case "PetCastNow": retval = On_PetCast(lastpart, target, true); break;

                    case "Use": retval = FTWCoreItems.On_Use(lastpart, target); break;

                    // Actions that don't use targets (don't care what the prefix is - can be any from the list above)
                    case "PullMore": retval = On_PullMore(firstpart, lastpart); break;

                    case "ImbueWeapon1": retval = FTWCoreItems.ImbueWeapon(lastpart, "mainhand", 1); break;

                    case "ImbueWeapon2": retval = FTWCoreItems.ImbueWeapon(lastpart, "offhand", 2); break;

                    case "CastAll": retval = On_CastAll(firstpart, lastpart); break;

                    case "InterruptAny": retval = On_Interrupt(firstpart, lastpart); break;

                    case "ExecuteAny": retval = On_Execute(firstpart, lastpart); break;

                    case "ParalyzeAny": retval = On_Paralyze(firstpart, lastpart); break;

                    case "Message": retval = false; FTWLogger.log(lastpart); break;

                    case "Range": retval = false; FTWProps.range = double.Parse(lastpart); FTWLogger.log("Combat range set to {0:0.00}", FTWProps.range); break;

                    case "ClipTime": retval = false; FTWProps.cliptime = Int32.Parse(lastpart); FTWLogger.log("Spells will be clipped with {0} ms remaining cast time.", FTWProps.cliptime); break;

                    case "Eat": retval = FTWCoreItems.On_Eat(); break;

                    case "Drink": retval = FTWCoreItems.On_Drink(); break;

                    case "UseBandage": retval = FTWCoreItems.On_UseBandage(); break;

                    case "UseHealthPotion": retval = FTWCoreItems.On_UseHealthPotion(); break;

                    case "UseManaPotion": retval = FTWCoreItems.On_UseManaPotion(); break;

                    case "FollowTarget": retval = FTWCoreMovement.FollowTarget(); break;

                    case "FindBetterTarget": retval = On_FindBetterTarget("by script request"); break;

                    case "PetAttack": retval = On_PetAttack(); break;

                    case "AutoAttack": retval = On_AutoAttack(); break;

                    case "OnCooldown": retval = FTWCoreStatus.OnCooldown(lastpart); break;

                    case "Macro": retval = false; Macro(lastpart); break;

                    case "LootChestsOn": CharacterSettings.Instance.LootChests = true; break;

                    case "LootChestsOff": CharacterSettings.Instance.LootChests = false; break;

                    case "GrabAggro": retval = On_GrabAggro(); break;

                    case "LeaveEarly": retval = true; break;

                    // Unknown action
                    default: retval = On_UnimplementedAction(action); break;
                    }
                }
            }

            MyTimer.Stop(subfn);
            MyTimer.Stop(fnname);
            return(retval);
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
 public static bool On_UnimplementedAction(string action)
 {
     FTWLogger.log("Unimplemented action '{0}'", action);
     return(false);
 }
Esempio n. 16
0
        public bool EvaluateRules(String desiredsection)
        {
            FTWLogger.log("HasAura = " + StyxWoW.Me.HasAura("Serendipity"));
            FTWLogger.log("HasMyAura = " + StyxWoW.Me.HasMyAura("Serendipity"));

            string fnname = string.Format("FTWCore.EvaluateRules {0}", desiredsection);

            MyTimer.Start(fnname);

            FTWProps.mode = desiredsection;
            string result = string.Empty;

            List <String> origlines = FTWProps.rules[FTWProps.ClassAndSpec].Split('\n').ToList();

            // Replace left side of conditions with current values
            String s;

            MyTimer.Start("FTWCore.EvaluateRules.Replace");
            using (StyxWoW.Memory.AcquireFrame())
            {
                this.StartReplace();
                s = FTWProps.rules[FTWProps.ClassAndSpec];
                s = this.Replace("Me", s, StyxWoW.Me);
                s = this.Replace("Target", s, StyxWoW.Me.CurrentTarget);
                s = this.Replace("Tank", s, FTWProps.tank);
                s = this.Replace("Healer", s, FTWProps.healer);
                s = this.Replace("Heal", s, FTWProps.healTarget);
                s = this.Replace("Pet", s, StyxWoW.Me.Pet);
                s = this.Replace("Cleanse", s, FTWProps.cleanseTarget);
                s = this.Replace("Revive", s, FTWProps.reviveTarget);
                s = this.Replace("Add", s, FTWProps.add);
            }
            MyTimer.Stop("FTWCore.EvaluateRules.Replace");

            MyTimer.Start("FTWCore.EvaluateRules.Remainder");
            List <String> lines = s.Split('\n').ToList();

            lines.Add("@END OF FILE");

            for (int i = 0; i < lines.Count; i++)
            {
                lines[i] = lines[i].Replace("\n", "").Replace("\r", "");
            }
            for (int i = 0; i < origlines.Count; i++)
            {
                origlines[i] = origlines[i].Replace("\n", "").Replace("\r", "");
            }

            string        section    = null;
            string        action     = null;
            List <string> conditions = new List <string>();
            List <string> output     = new List <string>();

            for (int i = 0; i < lines.Count; i++)
            {
                // Skip blank lines
                if (lines[i].Replace("\t", "").Trim().Length == 0 || lines[i].Trim().StartsWith("--"))
                {
                    continue;
                }

                if (section == desiredsection)
                {
                    // Only process lines in the correct section
                    if (lines[i].StartsWith("\t"))
                    {
                        // New condition
                        conditions.Add(lines[i]);
                        output.Add(string.Format("{0:D3} {1} {2}", i + 1, origlines[i].Replace("\t", "    ").Replace("\"", "'"), lines[i].Replace("\t", "    ").Replace("\"", "'")));
                    }
                    else
                    {
                        // Finish off old action
                        bool ConditionsMatch = true;
                        if (action != null)
                        {
                            foreach (string check in conditions)
                            {
                                if (ConditionsMatch)
                                {
                                    //FTWLogger.debug(check + " - " + action + " - " + i);
                                    ConditionsMatch = EvaluateCondition(check, action, i);
                                }
                            }
                            if (!ConditionsMatch)
                            {
                                result = "SKIPPED";
                            }
                            else if (FTWCoreActions.ExecuteAction(action))
                            {
                                result = "TRUE";
                            }
                            else
                            {
                                result = "FALSE";
                            }

                            output.Add(string.Format("        {0}", result));
                            if (result == "TRUE")
                            {
                                //foreach (string xx in output)
                                //    FTWLogger.debug(xx);
                                MyTimer.Stop("FTWCore.EvaluateRules.Remainder");
                                MyTimer.Stop(fnname);
                                return(true);
                            }
                            //else
                            //{
                            //foreach (string xx in output)
                            //    FTWLogger.debug(result + " - " + xx);
                            //}
                            //if (action == "StopCasting")
                            //    foreach (string xx in output)
                            //        FTWLogger.debug(xx);
                        }
                        output = new List <string>();
                        conditions.Clear();
                        action = null;

                        // New action
                        if (!lines[i].StartsWith("@"))
                        {
                            action = lines[i];
                            output.Add(string.Format("{0:D3} {1}", i + 1, action));
                        }
                    }
                }
                if (lines[i].StartsWith("@"))
                {
                    // New section
                    section = lines[i];
                }
            }

            MyTimer.Stop("FTWCore.EvaluateRules.Remainder");
            MyTimer.Stop(fnname);
            return(false);
        }
Esempio n. 17
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);
        }
Esempio n. 18
0
        public static bool OnCooldown(string spellname, double seconds, bool debugspell)
        {
            bool   retval = false;
            string fnname = "FTWCore.OnCooldown";

            MyTimer.Start(fnname);
            Color    ds              = Color.Magenta;
            WoWSpell spell           = null;
            bool     WoWCooldown     = false;
            bool     FTWCooldown     = false;
            bool     RecentCooldown  = false;
            bool     ElapsedCooldown = false;
            double   elapsedtime     = -1;
            String   errmsg          = "";

            // Get the spell
            if (FTWProps.fakecooldowns.ContainsKey(spellname))
            {
                spell = WoWSpell.FromId(FTWProps.fakecooldowns[spellname].SpellID);
            }
            else if (SpellManager.Spells.ContainsKey(spellname))
            {
                spell = SpellManager.Spells[spellname];
            }
            else
            {
                spell = null;
            }

            // Get the elapsed time since the last cast.
            if (FTWProps.spellWasLastCast.ContainsKey(spellname))
            {
                elapsedtime = (DateTime.Now - FTWProps.spellWasLastCast[spellname]).Seconds;
            }

            // Check if it's on WoW cooldown
            //if (spell != null)
            //{
            //    if (spell.Cooldown)
            //    {
            //        WoWCooldown = spell.Cooldown;
            //    }
            //else
            //{
            //    // Do a harder check - make sure it's been at least BaseCooldown milliseconds since last cast
            //    // This avoids problems with spells that don't actually cast when you think they do, and eat the rotation.
            //    WoWCooldown = (elapsedtime * 1000) < spell.BaseCooldown;
            //    if (WoWCooldown)
            //        log("Elapsedtime {0} * 1000 < spell.BaseCooldown {1}", elapsedtime, spell.BaseCooldown);
            //}
            //}

            // Check if it's on recent cooldown
            uint cd = 1500;

            if (spell != null)
            {
                cd = Math.Min(spell.CastTime, 1500);
            }
            RecentCooldown = ((FTWProps.lastspellcastname == spellname) && (DateTime.Now - FTWProps.lastspellcasttime).TotalMilliseconds < cd);

            // Check if it's on FTW cooldown
            if (FTWProps.fakecooldowns.ContainsKey(spellname))
            {
                FTWCooldown = elapsedtime >= 0 && elapsedtime < FTWProps.fakecooldowns[spellname].Cooldown;
            }
            else if (spell != null)
            {
                WoWCooldown = spell.Cooldown;
            }

            // Check if it's on elapsed time cooldown
            ElapsedCooldown = elapsedtime < seconds;

            if (WoWCooldown)
            {
                errmsg = "WoW";
            }
            else if (RecentCooldown)
            {
                errmsg = "double-cast";
            }
            else if (FTWCooldown)
            {
                errmsg = "FTW";
            }
            else if (RecentCooldown)
            {
                errmsg = "Elapsed time";
            }

            if (errmsg != "")
            {
                if (debugspell)
                {
                    FTWLogger.log(ds, "... {0} on {1} cooldown", spellname, errmsg);
                }
                retval = true;
            }

            MyTimer.Stop(fnname);
            return(retval);
        }
Esempio n. 19
0
        public override void Pulse()
        {
            string fnname = "FTWRev.Pulse";

            MyTimer.Start(fnname);

            // Display startup message
            if (FTWProps.firstpulse == true)
            {
                FTWProps.firstpulse = false;
                // Eh, I don't like it. Uncomment if you really want it.
                //Mount.OnMountUp += UseTravelForm;
                FTWProps.core.Initialize();
                FTWLogger.log("FTW starting at {0}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"));
                FTWLogger.log("Current bot: {0}", Styx.CommonBot.BotManager.Current.Name);
            }

            // Unstick ourselves if necessary.
            CheckForStuck.Pulse();

            // Display last red text
            if (StyxWoW.LastRedErrorMessage != FTWProps.redtext)
            {
                FTWProps.redtext = StyxWoW.LastRedErrorMessage;
                FTWLogger.debug(Color.Red, "Red text: {0}", FTWProps.redtext);
            }

            // Leave early if not in valid state
            if (!FTWUtils.ValidState())
            {
                //FTWLogger.debug(Color.Red, "Invalid state: {0}", FTWUtils.printState());
            }
            else
            {
                // Save current class and spec
                //FTWProps.ClassAndSpec = StyxWoW.Me.ClassAndSpec();

                // List aura changes
                AuraWatcher.Pulse();

                // Load rules if they're not loaded
                //if (!FTWProps.rules.ContainsKey(FTWProps.ClassAndSpec))
                //    FTWProps.LoadRules();

                FTWProps.core.Pulse();

                if (FTWUtils.MeOrPartyMemberInCombat())
                {
                    //if (BotPoi.Current.Type == PoiType.Loot)
                    //{
                    //    debug("Not done with combat, clearing loot flag");
                    //    BotPoi.Clear();
                    //}
                    // Force combat because me OR party/raid members in combat)
                    Combat();
                }
            }

            // Perform dungeon stuff
            DungeonWatcher.Pulse();

            // Perform UI stuff
            UI.Pulse();

            MyTimer.Stop(fnname);
            MyTimer.Pulse();
        }
Esempio n. 20
0
        private bool EvaluateCondition(string condition, string action, int line)
        {
            string fnname = string.Format("FTWCore.EvaluateCondition {0}", FTWProps.mode);

            MyTimer.Start(fnname);
            bool retval = true;

            string[] lines;
            string   origcondition = condition;

            condition = condition.Replace("\t", "");
            while (condition.StartsWith(" "))
            {
                condition = condition.Substring(1, condition.Length - 1);
            }
            condition = condition.Replace("  ", " ");
            if (condition.Length < 2)
            {
                retval = true;
                goto done;
            }
            lines = condition.Split(new Char[] { ' ' });
            double value1 = 0;
            double value2 = 0;

            if (lines.Length != 3)
            {
                FTWLogger.log(Color.Red, "Invalid condition found when evaluating action {0} line {1} - need 3 words '{2}'", action, line.ToString(), origcondition);
                retval = false;
                goto done;
            }
            try
            {
                value1 = System.Double.Parse(lines[0]);
            }
            catch (Exception ex)
            {
                FTWLogger.log(Color.Red, "Bad number on left side found when evaluating action {0} line {1} - '{2}' ({3})", action, line.ToString(), lines[0], ex.Message);
                retval = false;
                goto done;
            }
            string op = lines[1];

            try
            {
                value2 = System.Double.Parse(lines[2]);
            }
            catch (Exception ex)
            {
                FTWLogger.log(Color.Red, "Bad number on right side found when evaluating action {0} line {1} - '{2}' ({3})", action, line.ToString(), lines[2], ex.Message);
                retval = false;
                goto done;
            }
            if (op == "=")
            {
                if (value1 == value2)
                {
                    retval = true;
                }
                else
                {
                    retval = false;
                }
                goto done;
            }
            if (op == "!=" || op == "<>")
            {
                if (value1 != value2)
                {
                    retval = true;
                }
                else
                {
                    retval = false;
                }
                goto done;
            }
            if (op == ">=")
            {
                if (value1 >= value2)
                {
                    retval = true;
                }
                else
                {
                    retval = false;
                }
                goto done;
            }
            if (op == "<=")
            {
                if (value1 <= value2)
                {
                    retval = true;
                }
                else
                {
                    retval = false;
                }
                goto done;
            }
            if (op == ">")
            {
                if (value1 > value2)
                {
                    retval = true;
                }
                else
                {
                    retval = false;
                }
                goto done;
            }
            if (op == "<")
            {
                if (value1 < value2)
                {
                    retval = true;
                }
                else
                {
                    retval = false;
                }
                goto done;
            }
            FTWLogger.log(Color.Red, "Unknown operator {0} when processing {1} line {2}!", op, action, line.ToString());
            retval = false;
            goto done;

done:
            MyTimer.Stop(fnname);
            return(retval);
        }
Esempio n. 21
0
        public FTWCore()
        {
            string fnname = "FTWCore.Constructor";

            MyTimer.Start(fnname);
            if (SpellManager.HasSpell("Detox"))
            {
                // Monk
                if (!FTWProps.dispels.Contains(WoWDispelType.Disease))
                {
                    FTWProps.dispels.Add(WoWDispelType.Disease);
                }
                if (!FTWProps.dispels.Contains(WoWDispelType.Poison))
                {
                    FTWProps.dispels.Add(WoWDispelType.Poison);
                }
            }
            if (SpellManager.HasSpell("Remove Corruption"))
            {
                // Druid
                if (!FTWProps.dispels.Contains(WoWDispelType.Curse))
                {
                    FTWProps.dispels.Add(WoWDispelType.Curse);
                }
                if (!FTWProps.dispels.Contains(WoWDispelType.Poison))
                {
                    FTWProps.dispels.Add(WoWDispelType.Poison);
                }
            }
            if (SpellManager.HasSpell("Remove Curse"))
            {
                // Mage
                if (!FTWProps.dispels.Contains(WoWDispelType.Curse))
                {
                    FTWProps.dispels.Add(WoWDispelType.Curse);
                }
            }
            if (SpellManager.HasSpell("Purify Spirit"))
            {
                // Shaman
                if (!FTWProps.dispels.Contains(WoWDispelType.Curse))
                {
                    FTWProps.dispels.Add(WoWDispelType.Curse);
                }
                if (!FTWProps.dispels.Contains(WoWDispelType.Magic))
                {
                    FTWProps.dispels.Add(WoWDispelType.Magic);
                }
            }
            if (SpellManager.HasSpell("Cleanse"))
            {
                // Paladin
                if (!FTWProps.dispels.Contains(WoWDispelType.Disease))
                {
                    FTWProps.dispels.Add(WoWDispelType.Disease);
                }
                if (!FTWProps.dispels.Contains(WoWDispelType.Poison))
                {
                    FTWProps.dispels.Add(WoWDispelType.Poison);
                }
            }
            if (SpellManager.HasSpell("Mass Dispel"))
            {
                // Priest
                if (!FTWProps.dispels.Contains(WoWDispelType.Curse))
                {
                    FTWProps.dispels.Add(WoWDispelType.Curse);
                }
                if (!FTWProps.dispels.Contains(WoWDispelType.Disease))
                {
                    FTWProps.dispels.Add(WoWDispelType.Disease);
                }
                if (!FTWProps.dispels.Contains(WoWDispelType.Magic))
                {
                    FTWProps.dispels.Add(WoWDispelType.Magic);
                }
                if (!FTWProps.dispels.Contains(WoWDispelType.Poison))
                {
                    FTWProps.dispels.Add(WoWDispelType.Poison);
                }
            }
            if (SpellManager.HasSpell("Purify"))
            {
                // Priest
                if (!FTWProps.dispels.Contains(WoWDispelType.Disease))
                {
                    FTWProps.dispels.Add(WoWDispelType.Disease);
                }
                if (!FTWProps.dispels.Contains(WoWDispelType.Magic))
                {
                    FTWProps.dispels.Add(WoWDispelType.Magic);
                }
            }
            if (SpellManager.HasSpell("Sacred Cleansing") ||
                SpellManager.HasSpell("Nature's Cure") ||
                SpellManager.HasSpell("Improved Cleanse Spirit"))
            {
                if (!FTWProps.dispels.Contains(WoWDispelType.Magic))
                {
                    FTWProps.dispels.Add(WoWDispelType.Magic);
                }
            }
            if (FTWProps.dispels.Count > 0)
            {
                FTWLogger.log("Player can dispel the following:");
                foreach (WoWDispelType d in FTWProps.dispels)
                {
                    FTWLogger.log("    {0}", d.ToString());
                }
            }

            MyTimer.Stop(fnname);
        }
Esempio n. 22
0
        public static bool On_PullMore(string firstpart, string spellname)
        {
            // Pulls another mob with the specified spell.
            if (!(BotPoi.Current.Type == PoiType.Kill || BotPoi.Current.Type == PoiType.None))
            {
                return(false);
            }
            if (FTWUtils.MovementDisabled())
            {
                return(false);
            }
            if (StyxWoW.Me.HealthPercent < 80)
            {
                return(false);
            }
            int      range = 5;
            WoWSpell spell = null;

            try
            {
                if (FTWProps.fakecooldowns.ContainsKey(spellname))
                {
                    spell = WoWSpell.FromId(FTWProps.fakecooldowns[spellname].SpellID);
                }
                else
                {
                    spell = SpellManager.Spells[spellname];
                }
            }
            catch (KeyNotFoundException ex) { }
            if (spell == null || spell.CooldownTimeLeft.TotalMilliseconds > 0)
            {
                return(false);
            }
            range = Math.Max(range, (int)spell.MaxRange);
            WoWUnit anothermob = (from u in ObjectManager.GetObjectsOfType <WoWUnit>(false, false)
                                  where u.IsValidUnit()
                                  where !u.TaggedByOther
                                  where !u.IsDead
                                  where !u.TaggedByOther
                                  where u.IsHostile
                                  where u.DistanceCalc() <= 40
                                  where !u.Mounted
                                  where u.InLineOfSight
                                  where u.Distance < range
                                  orderby u.Distance descending
                                  select u).FirstOrDefault();

            if (anothermob == null)
            {
                return(false);
            }
            if (FTWUtils.MovementDisabled())
            {
                FTWLogger.log(Color.Violet, "MOVEMENT DISABLED - Not facing target on pullmore!");
            }
            else
            {
                FTWCoreMovement.Face(anothermob);
            }
            bool retval = On_Cast(firstpart, spellname, anothermob, true, false);

            if (retval)
            {
                FTWLogger.log(Color.GreenYellow, "    Taunted {0} {1} dist {2:0.0} with {3} (addscount {4})", anothermob.SafeName(), anothermob.ShortGuid(), anothermob.Distance, spellname, FTWProps.adds.Count);
            }
            return(retval);
        }
Esempio n. 23
0
        public static bool On_Use(string itemname, WoWUnit target)
        {
            string fnname = "FTWCore.On_Use";

            MyTimer.Start(fnname);
            bool retval = false;

            using (StyxWoW.Memory.AcquireFrame())
            {
                if (itemname.ToLower() == "trinket1" && StyxWoW.Me.Inventory.Equipped.Trinket1 != null)
                {
                    WoWItem trinket = StyxWoW.Me.Inventory.Equipped.Trinket1;
                    if (trinket.Cooldown == 0 && trinket.Usable == true && trinket.TriggersSpell == true)
                    {
                        FTWLogger.log("Using trinket {0}", StyxWoW.Me.Inventory.Equipped.Trinket1.Name);
                        StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                    }
                }
                else if (itemname.ToLower() == "trinket2" && StyxWoW.Me.Inventory.Equipped.Trinket2 != null)
                {
                    WoWItem trinket = StyxWoW.Me.Inventory.Equipped.Trinket2;
                    if (trinket.Cooldown == 0 && trinket.Usable == true && trinket.TriggersSpell == true)
                    {
                        FTWLogger.log("Using trinket {0}", StyxWoW.Me.Inventory.Equipped.Trinket2.Name);
                        StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                    }
                }
                else
                {
                    WoWItem item = GetInventoryItem(itemname);
                    if (item == null)
                    {
                        FTWLogger.debug("Couldn't find item {0}", itemname);
                    }
                    else if (item.Usable == false)
                    {
                        FTWLogger.debug("Item {0} is not usable", item.Name);
                    }
                    else if (item.Cooldown > 0)
                    {
                        FTWLogger.debug("Item {0} is on cooldown. Time remaining: {1}", item.Name, item.CooldownTimeLeft.TotalSeconds);
                    }
                    else if (FTWCoreStatus.OnCooldown(item.Name))
                    {
                        FTWLogger.debug("Item {0} is on cooldown.", item.Name);
                    }
                    else
                    {
                        if (target != null && target.Guid != StyxWoW.Me.Guid)
                        {
                            target.Target();
                            Thread.Sleep(100);
                        }
                        FTWLogger.log("Using item '{0}'", item.Name);
                        item.Use();
                        retval = false;
                    }
                }
            }
            MyTimer.Stop(fnname);
            return(retval);
        }
Esempio n. 24
0
        public void Pulse()
        {
            string fnname = "FTWCore.Pulse";

            MyTimer.Start(fnname);
            try
            {
                if (!FTWUtils.ValidState())
                {
                    // Do nothing
                    FTWLogger.log(Color.Red, "Not valid state");
                }
                else
                {
                    // Get lists of interesting people

                    // Party or raid members
                    FTWProps.people = FTWCoreUnits.GetGroup();

                    // Tank
                    FTWProps.tank = FTWCoreUnits.GetTank();

                    // Healer
                    FTWProps.healer = FTWCoreUnits.GetHealer();

                    // Party members within range
                    FTWProps.closePeople = FTWProps.people.Where(p => p.DistanceCalc() <= 40).ToList();

                    // Party members within range, in line of sight, that need healing
                    FTWProps.healTarget = FTWCoreUnits.GetHealTarget();

                    // Diseased party member
                    // Only tanks and me get dispels, the rest can stay sick.
                    // A necessary optimization to keep the speed up.
                    FTWProps.cleanseTarget = (from unit in FTWProps.closePeople
                                              where unit.Role().Contains("Tank") || unit.Guid == StyxWoW.Me.Guid
                                              where unit.EligibleForCleanse() == true
                                              orderby unit.HealWeight()
                                              select unit).FirstOrDefault();

                    // Dead party member outside combat
                    FTWProps.reviveTarget = (from unit in FTWProps.closePeople
                                             where unit.IsDead || unit.IsGhost
                                             select unit).FirstOrDefault();
                    if (FTWProps.reviveTarget != null)
                    {
                        FTWLogger.log(Color.Red, "{0} is dead - revive him if you can.", FTWProps.reviveTarget.SafeName());
                    }

                    // Get average health of all party members.
                    try
                    {
                        FTWProps.avgHealth = (int)(from p in FTWProps.closePeople where p.IsDead == false select p.HealthPercent).Average();
                    }
                    catch (Exception ex)
                    {
                        FTWProps.avgHealth = (int)StyxWoW.Me.HealthPercent;
                    }

                    // Get mobs fighting us
                    FTWProps.adds = FTWCoreUnits.GetAdds();

                    // Get mobs fighting us, that we're not targeting
                    WoWUnit pettarget = null;
                    if (StyxWoW.Me.GotAlivePet)
                    {
                        pettarget = StyxWoW.Me.Pet.CurrentTarget;
                    }
                    FTWProps.nontargetadds = (from unit in FTWProps.adds
                                              where unit != StyxWoW.Me.CurrentTarget && unit != pettarget
                                              select unit).ToList();

                    // Get a mob fighting us, that we're not targeting.
                    FTWProps.add = FTWProps.nontargetadds.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                FTWLogger.log(Color.Red, ex.ToString());
            }
            MyTimer.Stop(fnname);
        }