public static void ResetScriptFile(string fileName, out string path) { ScriptFileMap.TryGetValue(fileName, out path); if (path == null) { path = Path.GetFullPath(Path.Combine(Core.BaseDirectory, ParsedScripts.UberScriptDirectory, fileName)); if (!File.Exists(path)) { throw new UberScriptException("Script file did not exist at " + path); } } if (Scripts.ContainsKey(path)) { Scripts.Remove(path); } foreach (KeyValuePair <string, string> filePair in ScriptFileMap) { foreach (KeyValuePair <XmlScript, bool> scriptPair in XmlScript.AllScripts) { XmlScript script = scriptPair.Key; if (ScriptFileMap.ContainsKey(script.ScriptFile) && ScriptFileMap[script.ScriptFile] == path) { // hacky way to resubscribe the timers if at all possible XmlScript.TimerSubscriptionFlag temp = script.TimerSubscriptions; // unsubscribe them script.TimerSubscriptions = XmlScript.TimerSubscriptionFlag.None; // resubscribe them to what they were previously subscribed to script.TimerSubscriptions = temp; script.UpdateScriptTriggerLookup(); } } } }
public static void ResetScripts_Command(CommandEventArgs e) { // first reset the gumps ParsedGumps.GumpFileMap = new Dictionary <string, string>(); ParsedGumps.Gumps = new Dictionary <string, UberGumpBase>(); List <XmlScript> deletedScripts = new List <XmlScript>(); if (e.Arguments.Length == 0) { ScriptFileMap = new Dictionary <string, string>(); Scripts = new Dictionary <string, RootNode>(); // should probably ensure all the timer stuff is restarted as appropriate UberScriptTimedScripts.ClearSubscriptions(); UberScriptFunctions.Methods.StopAllLineEffectTimers(); UberScriptFunctions.Methods.StopAllLineScriptTimers(); foreach (KeyValuePair <XmlScript, bool> scriptPair in XmlScript.AllScripts) { XmlScript script = scriptPair.Key; if (script.Deleted || script.AttachedTo == null || script.AttachedTo.Deleted) { deletedScripts.Add(script); continue; } // hacky way to resubscribe the timers if at all possible XmlScript.TimerSubscriptionFlag temp = script.TimerSubscriptions; // unsubscribe them script.TimerSubscriptions = XmlScript.TimerSubscriptionFlag.None; // resubscribe them to what they were previously subscribed to script.TimerSubscriptions = temp; script.UpdateScriptTriggerLookup(); } foreach (XmlScript script in deletedScripts) { XmlScript.AllScripts.Remove(script); } if (e.Mobile != null) { e.Mobile.SendMessage("All scripts have been reset."); } } else { try { // first, always clear out deleted scripts foreach (KeyValuePair <XmlScript, bool> scriptPair in XmlScript.AllScripts) { XmlScript script = scriptPair.Key; if (script.Deleted) { deletedScripts.Add(script); continue; } } foreach (XmlScript script in deletedScripts) { XmlScript.AllScripts.Remove(script); } string fileName = e.Arguments[0].ToLower(); string path = Path.GetFullPath(Path.Combine(Core.BaseDirectory, ParsedScripts.UberScriptDirectory, fileName));; if (Directory.Exists(path)) { // reset all uberscripts in that directory, allow to toggle subdirectory reset too bool resetSubdirectories = (e.Arguments.Length > 1 && e.Arguments[1].ToLower() == "true"); foreach (string file in Directory.GetFiles(path, "*.*", resetSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) { ResetScriptFile(file, out path); e.Mobile.SendMessage("All scripts connected to " + path + " were reset."); } if (e.Mobile != null) { e.Mobile.SendMessage("All scripts INSIDE the DIRECTORY " + fileName + (resetSubdirectories ? " AND its SUBDIRECTORIES" : "") + " were reset."); } } else { ResetScriptFile(fileName, out path); if (e.Mobile != null) { e.Mobile.SendMessage("All scripts connected to " + path + " were reset."); } } } catch (Exception except) { if (e.Mobile != null) { e.Mobile.SendMessage("Exception caught: " + except.Message); } } } }