Exemplo n.º 1
0
        public static bool GenerateLUAFile(bool reloadUI = true)
        {
            try
            {
                if (!Directory.Exists(AddonPath))
                {
                    Directory.CreateDirectory(AddonPath);
                }

                Log.Write($"Creating Addon from SpellBook, AddonName will be [{AddonName}]...");

                Log.Write($"Creating file: [{AddonName}.toc]", Color.Gray);

                using (var sr = new StreamWriter($"{AddonPath}\\{AddonName}.toc"))
                {
                    //  ## Author: WiNiFiX
                    //  ## Interface: 60200
                    //  ## Title: DoIt
                    //  ## Version: 1.0.0
                    //  ## SavedVariablesPerCharacter: DoItOptions
                    //  DoItBase.lua

                    sr.WriteLine($"## Author: {AddonAuthor.Replace("\r", "").Replace("\n", "")}");

                    if (InterfaceVersion.Contains("-"))
                    {
                        sr.WriteLine($"## Interface: {InterfaceVersion.Split('-')[1].Trim()}");
                    }
                    else
                    {
                        sr.WriteLine($"## Interface: {InterfaceVersion}");
                    }
                    sr.WriteLine($"## Title: {AddonName.Replace("\r", "").Replace("\n", "")}");
                    sr.WriteLine($"## Version: {Application.ProductVersion}");
                    sr.WriteLine($"## SavedVariablesPerCharacter: {AddonName.Replace("\r", "").Replace("\n", "")}_settings");
                    sr.WriteLine($"{AddonName.Replace("\r", "").Replace("\n", "")}.lua");
                    sr.Close();
                }

                Log.Write($"Creating file: [{AddonName}.lua]", Color.Gray);

                using (var sr = new StreamWriter($"{AddonPath}\\{AddonName}.lua"))
                {
                    //local cooldowns = { --These should be spellIDs for the spell you want to track for cooldowns
                    //    56641,    -- Steadyshot
                    //    3044,     -- Arcane Shot
                    //    34026     -- Kill Command
                    //}

                    var cooldowns = "local cooldowns = { --These should be spellIDs for the spell you want to track for cooldowns" + Environment.NewLine;

                    foreach (var spell in Spells)
                    {
                        if (spell.InternalSpellNo == Spells.Count)  // We are adding the last spell, dont include the comma
                        {
                            cooldowns += $"    {spell.SpellId} \t -- {spell.SpellName}" + Environment.NewLine;
                        }
                        else
                        {
                            cooldowns += $"    {spell.SpellId},\t -- {spell.SpellName}" + Environment.NewLine;
                        }
                    }

                    cooldowns += "}" + Environment.NewLine;

                    sr.Write(cooldowns);

                    var auras = "local buffs = { --These should be auraIDs for the spell you want to track " + Environment.NewLine;

                    foreach (var aura in Auras)
                    {
                        if (aura.InternalAuraNo == Auras.Count)  // We are adding the last aura, dont include the comma
                        {
                            auras += $"    {aura.AuraId} \t -- {aura.AuraName}" + Environment.NewLine;
                        }
                        else
                        {
                            auras += $"    {aura.AuraId},\t -- {aura.AuraName}" + Environment.NewLine;
                        }
                    }

                    auras += "}" + Environment.NewLine;

                    sr.Write(auras);

                    var debuffs = "local debuffs = { --These should be auraIDs for the spell you want to track " + Environment.NewLine;

                    foreach (var aura in Auras)
                    {
                        if (aura.InternalAuraNo == Auras.Count)  // We are adding the last aura, dont include the comma
                        {
                            debuffs += $"    {aura.AuraId} \t -- {aura.AuraName}" + Environment.NewLine;
                        }
                        else
                        {
                            debuffs += $"    {aura.AuraId},\t -- {aura.AuraName}" + Environment.NewLine;
                        }
                    }

                    debuffs += "}" + Environment.NewLine;

                    sr.Write(debuffs);

                    var luaContents = Addon.LuaContents;

                    luaContents = luaContents.Replace("DoIt", AddonName);

                    string AddonInterfaceVersion = InterfaceVersion;
                    if (InterfaceVersion.Contains("-"))
                    {
                        AddonInterfaceVersion = InterfaceVersion.Split('-')[1].Trim();
                    }

                    if (AddonInterfaceVersion == "70000") // Legion changes as per http://www.wowinterface.com/forums/showthread.php?t=53248
                    {
                        luaContents = luaContents.Replace("SetTexture", "SetColorTexture");

                        // For now the below are disabled till further testing is done
                        // luaContents = luaContents.Replace(@"UnitPower(""player"");", @"UnitPower(""player"", UnitPowerType(""player""))");
                        // luaContents = luaContents.Replace(@"UnitPowerMax(""player"");", @"UnitPowerMax(""player"", UnitPowerType(""player""))");
                    }

                    sr.WriteLine(luaContents);
                    sr.Close();
                }

                Log.Write("Addon file generated.", Color.Green);
                Log.Write($"Make sure that the addon: [{AddonName}] is enabled in your list of WoW Addons or the rotation bot will fail to work", Color.Black);

                if (reloadUI)
                {
                    WoW.SendMacro("/console scriptErrors 1"); // Show wow Lua errors
                    WoW.SendMacro("/reload");
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Write("Failed to generate addon file:", Color.Red);
                Log.Write(ex.Message, Color.Red);

                return(false);
            }
        }