private void Initialize() { try { Util.WriteToChat("Loading profile"); //Find profiles MasterProfile = Profile.GetProfile(); CharProfile = MasterProfile.GetCharacterProfile(); //Set up command parser SetupCommandParser(); //Start experience policy CharProfile.Policy.Start(MasterProfile.Interval); //Start spell manager spellManager = new SpellTabManager(); spellManager.Start(MasterProfile.Interval); //Watch for changes to profiles masterProfileWatcher = new FileSystemWatcher() { Path = System.IO.Path.GetDirectoryName(Profile.ConfigurationPath), Filter = System.IO.Path.GetFileName(Profile.ConfigurationPath), EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite, }; charProfileWatcher = new FileSystemWatcher() { Path = System.IO.Path.GetDirectoryName(CharProfile.Path), Filter = System.IO.Path.GetFileName(CharProfile.Path), EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite, }; if (isFirstLogin) { //Run login commands CharProfile.ExecuteLoginCommands(); //Add events if they haven't already been added Globals.Core.CommandLineText += Core_CommandLineText; masterProfileWatcher.Changed += RequestReload; charProfileWatcher.Changed += RequestReload; isFirstLogin = false; } } catch (Exception ex) { Util.LogError(ex); } }
private void TryReload(object sender, ElapsedEventArgs e) { try { Initialize(); Util.WriteToChat("Reloaded settings successfully."); reloadTimer.Enabled = false; } catch (Exception ex) { //File most likely in use Util.LogError(ex); } }
private void ProcessCommand(Command command) { switch (command) { //case Command.Load: // Initialize(); // break; case Command.Policy: CharProfile.Policy.PrintPolicy(); break; case Command.Plan: CharProfile.Policy.PrintExperiencePlan(); break; case Command.Spend: case Command.Level: CharProfile.Policy.SpendExperience(); break; case Command.EditConfig: try { Process.Start(Profile.ConfigurationPath); } catch (Exception e) { Util.LogError(e); } break; case Command.EditPolicy: try { Process.Start(CharProfile.Path); } catch (Exception e) { Util.LogError(e); } break; case Command.SS: spellManager.SaveAllSpells(); break; case Command.CS: spellManager.ClearAllSpells(); break; case Command.LS: spellManager.LoadSpells(); break; case Command.Help: default: Util.WriteToChat("Valid commands are: " + commandPattern); break; } }
private void Core_CommandLineText(object sender, ChatParserInterceptEventArgs e) { try { //Just the trigger dumps the list of commands var match = commandParser.Match(e.Text); //Seems like there's a weird time-sensistize need to set e.Eat if (match.Success) { //Util.WriteToChat("Successful match"); //for (var i = 0; i < match.Groups.Count; i++) // Util.WriteToChat($"Group {i}: {match.Groups[i].Success}\t{match.Groups[i].Value}"); //Don't propagate if command was matched e.Eat = true; //Just the trigger if (!match.Groups[1].Success) { //Util.WriteToChat("Trigger hit: " + CommandTrigger); ProcessCommand(Command.Help); return; } var command = (Command)Enum.Parse(typeof(Command), match.Groups[1].Value, true); //There aren't parameters but a command if (!match.Groups[2].Success) { //Util.WriteToChat("Command: " + match.Groups[1].Value); ProcessCommand(command); return; } //There are parameters else { //Util.WriteToChat("Command: " + match.Groups[1].Value + "\t" + command); //Util.WriteToChat("Params: " + match.Groups[2].Value); ProcessCommand(command, match.Groups[2].Value); } } } catch (Exception ex) { Util.LogError(ex); Util.WriteToChat("Error parsing command"); } }
//Could split this into a separate ParamCommand enum private void ProcessCommand(Command command, string parameters) { switch (command) { case Command.SS: spellManager.SaveAllSpells(parameters); break; case Command.LS: spellManager.LoadSpells(parameters); break; default: Util.WriteToChat("Valid commands are: " + commandPattern); break; } }
private void DelayedLoginCOmmands(object sender, ElapsedEventArgs e) { var path = System.IO.Path.GetFullPath(LoginCommands); try { if (File.Exists(LoginCommands)) { //Util.WriteToChat($"Running batch commands at: {path}"); DecalHelper.DispatchChatToBoxWithPluginIntercept($"/loadfile {path}"); } } catch (Exception ex) { Util.WriteToChat($"Unable to run login commands at: {path}"); Util.LogError(ex); } }
public void PrintExperiencePlan(long expToSpend) { var plan = GetPlan(expToSpend); Util.WriteToChat($"Experience plan for {expToSpend} exp:"); foreach (var t in plan) { var steps = t.Value.Count; var description = new StringBuilder($"{t.Key.ToString()} ({steps}): "); for (var i = 0; i < t.Value.Count; i++) { description.Append($"{t.Value[i]}\t"); } Util.WriteToChat(description.ToString()); } }
/// <summary> /// Spends experience on the next target in the plan /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SpendExperienceTick(object sender, ElapsedEventArgs e) { //Util.WriteToChat($"{FlatPlan.Count} | {PlanIndex} | {FlatPlan.Count < PlanIndex}"); //Check if plan finished if (flatPlan.Count <= planIndex) { Util.WriteToChat($"Finished leveling {planIndex} targets."); timer.Enabled = false; } //Otherwise level the next thing else { var target = flatPlan[planIndex].Key; var exp = flatPlan[planIndex].Value; //Util.WriteToChat($"Adding {exp} to {target}"); target.AddExp(exp); planIndex++; } }
public void LoadSpells(string parameters) { //TODO: Wait until spells are all gone / implement something that only deletes/inserts what you need to ClearAllSpells(); var path = Path.GetFullPath(parameters); try { var json = File.ReadAllText(path); var tabs = JsonConvert.DeserializeObject <SpellTab[]>(json); //Populate list of spells to be leveled spellsToLoad = new List <Spell>(); for (var i = 0; i < tabs.Length; i++) { var tab = tabs[i]; for (var j = 0; j < tab.Spells.Length; j++) { var spell = new Spell { Tab = i, Index = j, SpellID = tab.Spells[j] }; spellsToLoad.Add(spell); //Util.WriteToChat($"Planning to load ID {spell.SpellID} to tab {spell.Tab}, Slot {spell.Index}"); } } //Start leveling spellIndex = 0; timer.Enabled = true; Util.WriteToChat($"Loading {spellsToLoad.Count} spells from {path}"); } catch (Exception ex) { Util.WriteToChat($"Failed to load spells from: {path}"); Util.LogError(ex); } }
internal void SpendExperience(long expToSpend) { //Already spending experience? Continue? if (timer.Enabled) { Util.WriteToChat("Stopping spending experience."); timer.Enabled = false; flatPlan = null; return; } //Get plan for leveling flatPlan = new List <KeyValuePair <ExpTarget, int> >(); foreach (var t in GetPlan(expToSpend)) { for (var i = 0; i < t.Value.Count; i++) { //TODO: Optionally add logic here for things like grouping levels of 10, if that works with Decal? Doesn't seem to work... //if ((t.Value.Count - i) >= 10) //{ // var exp = t.Value.Skip(i).Take(10).Sum(); // Util.WriteToChat($"Planning to level {t.Key} from {i+1} to {i + 10} for {exp}"); // //Skip next 9 steps // i += 9; // continue; //} flatPlan.Add(new KeyValuePair <ExpTarget, int>(t.Key, t.Value[i])); } } //Sort by cost? flatPlan = flatPlan.OrderBy(t => t.Value).ToList(); //Start at beginning of plan planIndex = 0; Util.WriteToChat($"Spending on a plan consisting of {flatPlan.Count} steps with {expToSpend} available exp."); //Start leveling timer.Enabled = true; }
public void SaveAllSpells(string path) { path = Path.GetFullPath(path); SpellTab[] tabs = new SpellTab[MAX_SPELL_TAB]; for (var i = 0; i < tabs.Length; i++) { tabs[i] = GetSpellTab(i); } string json = JsonConvert.SerializeObject(tabs); try { File.WriteAllText(path, json); Util.WriteToChat($"Saved spells to {path}"); } catch (Exception e) { Util.WriteToChat($"Unable to save spells to: {System.IO.Path.GetFullPath(path)}"); Util.LogError(e); } }
internal CharacterProfile GetCharacterProfile() { var characterProfile = CharacterProfile.Default; foreach (var p in Profiles.OrderByDescending(t => t.Priority)) { //TODO: Do this but more smart. Missing/null interpreted as always a match? var namePattern = p.CharName ?? ".*"; var accountPattern = p.Account ?? ".*"; var serverPattern = p.Server ?? ".*"; var name = Regex.Escape(Globals.Core.CharacterFilter.Name); var account = Regex.Escape(Globals.Core.CharacterFilter.AccountName); var server = Regex.Escape(Globals.Core.CharacterFilter.Server); //Util.WriteToChat($"Looking at policy: {name}\t{namePattern} {account}\t{accountPattern} {server}\t{serverPattern}"); //Check for match if (!Regex.IsMatch(name, namePattern, RegexOptions.IgnoreCase)) { continue; } if (!Regex.IsMatch(account, accountPattern, RegexOptions.IgnoreCase)) { continue; } if (!Regex.IsMatch(server, serverPattern, RegexOptions.IgnoreCase)) { continue; } var fullPath = Path.GetFullPath(p.Path); if (File.Exists(fullPath)) { //Util.WriteToChat($"Matched profile {p.FriendlyName} at: {fullPath}"); try { characterProfile = JsonConvert.DeserializeObject <CharacterProfile>(File.ReadAllText(fullPath)); characterProfile.Path = fullPath; return(characterProfile); } catch (Exception e) { throw e; //Util.WriteToChat($"Unable to load character profile at: {fullPath}"); //Util.LogError(e); } } //TODO: Decide whether to create missing profile or skip //Profile doesn't exist else { //Util.WriteToChat($"Matched profile {p.FriendlyName} but missing at: {fullPath}"); try { characterProfile = CharacterProfile.Default; characterProfile.Path = fullPath; var json = JsonConvert.SerializeObject(characterProfile, Formatting.Indented); File.WriteAllText(fullPath, json); Util.WriteToChat($"Default profile created at: {fullPath}"); } catch (Exception e) { Util.WriteToChat("Unable to write default profile."); Util.LogError(e); } Util.WriteToChat($"Loaded character " + $"profile {p.FriendlyName}"); return(characterProfile); } } return(characterProfile); }