Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        private string Replace(string prefix, string s, WoWUnit theunit)
        {
            string fnname = "FTWCore.Replace";

            MyTimer.Start(fnname);
            if (theunit != null && theunit.Guid == StyxWoW.Me.Guid)
            {
                if (StyxWoW.Me.HasAura("Eclipse (Solar)"))
                {
                    FTWProps._eclipsedirection = -1;
                }
                else if (StyxWoW.Me.HasAura("Eclipse (Lunar)"))
                {
                    FTWProps._eclipsedirection = 1;
                }
            }

            // Replace aura checks with parenthese (Target.HasMyAura("Bad Aura") > 3)
            string findstring             = string.Format(@"{0}\.(?<action>.*)\(""(?<aura>.*)""\)", prefix);
            Regex  rg                     = new Regex(findstring);
            Match  match                  = rg.Match(s);
            Dictionary <String, Object> d = new Dictionary <String, Object>();

            while (match.Success)
            {
                if (!d.ContainsKey(match.Value))
                {
                    string action = match.Groups["action"].Value;
                    string aura   = match.Groups["aura"].Value;
                    int    value  = 0;
                    if (false)
                    {
                    }
                    else if (action == "Weapon1HasAura")
                    {
                        value = (theunit != null && FTWCoreItems.WeaponEnchant(1) == aura) ? 1 : 0;
                    }
                    else if (action == "Weapon2HasAura")
                    {
                        value = (theunit != null && FTWCoreItems.WeaponEnchant(2) == aura) ? 1 : 0;
                    }
                    else if (action == "AuraExpiring")
                    {
                        value = (theunit != null) ? theunit.AuraExpiring(aura) : 0;
                    }
                    else if (action == "CanCast")
                    {
                        value = (theunit != null && SpellManager.CanCast(aura, theunit)) ? 1 : 0;
                    }
                    else if (action == "ClearBehindMe")
                    {
                        value = (theunit != null && StyxWoW.Me.ClearBehindMe(aura) ? 1 : 0);
                    }
                    else if (action == "HasAura")
                    {
                        value = (theunit != null && theunit.HasAura(aura)) ? 1 : 0;
                    }
                    else if (action == "HasItem")
                    {
                        value = StyxWoW.Me.HasItem(aura) ? 1 : 0;
                    }
                    else if (action == "HasMyAura")
                    {
                        value = (theunit != null && theunit.HasMyAura(aura)) ? 1 : 0;
                    }
                    else if (action == "HasSpell")
                    {
                        value = (StyxWoW.Me.HasSpell(aura)) ? 1 : 0;
                    }
                    else if (action == "HasTotem")
                    {
                        value = FTWCoreStatus.HasTotem(aura) ? 1 : 0;
                    }
                    else if (action == "IsCasting")
                    {
                        value = (theunit != null && theunit.CurrentSpellName() == aura) ? 1 : 0;
                    }
                    else if (action == "ItemOnCooldown")
                    {
                        value = FTWCoreItems.ItemOnCooldown(aura) ? 1 : 0;
                    }
                    else if (action == "MyAuraExpiring")
                    {
                        value = (theunit != null) ? theunit.MyAuraExpiring(aura) : 0;
                    }
                    else if (action == "MyStackCount")
                    {
                        value = (theunit != null) ? theunit.MyStackCount(aura) : 0;
                    }
                    else if (action == "OnCooldown")
                    {
                        value = FTWCoreStatus.OnCooldown(aura) ? 1 : 0;
                    }
                    else if (action == "PartyWithAura")
                    {
                        value = FTWCoreUnits.GetPartyWithAura(aura);
                    }
                    else if (action == "PartyWithHealth")
                    {
                        value = FTWCoreUnits.GetPartyWithHealth(aura);
                    }
                    else if (action == "StackCount")
                    {
                        value = (theunit != null) ? theunit.StackCount(aura) : 0;
                    }
                    else if (action == "NumItems")
                    {
                        value = (theunit != null) ? FTWCoreItems.NumItems(aura) : 0;
                    }
                    else
                    {
                        throw new Exception(string.Format("Unknown action {0}!", action));
                    }
                    d.Add(match.Value, 0);
                    s = s.Replace(match.Value, value.ToString());
                }
                match = match.NextMatch();
            }

            // Replace simple properties
            for (int i = 0; i < FTWProps.PropertyNames.Count(); i++)
            {
                string propname = FTWProps.PropertyNames[i].Trim();
                if (propname.Length > 0)
                {
                    string search = prefix + "." + propname;
                    if (s.Contains(search))
                    {
                        s = s.Replace(search, GetProperty(theunit, propname).ToString());
                    }
                }
            }

            // Stop the timer
            MyTimer.Stop(fnname);

            return(s);
        }