/// <summary> /// Read & Load the scripts /// </summary> public void load() { _scripts.Clear(); XDocument doc = XDocument.Load(XmlDirectory); var scripts = from script in doc.Descendants("Scripts") select script; foreach (XElement script in scripts.Elements("Script")) { Quest quest = null; string file = DefaultDirectory + @script.Attribute("File").Value; string language = script.Attribute("Language").Value; string classSpace = script.Attribute("ClassSpace").Value; XElement xreferences = script.Element("References"); var references = from reference in xreferences.Descendants("Reference") select reference; if (file.EndsWith(".cs")) { CSharpScriptEngine engine = new CSharpScriptEngine(file); engine.AssemblySpaceName = classSpace; AddMetaRefs(ref engine, references); engine.Build(); try { Quest q = engine.NewInstance() as Quest;//loaded quest _scripts.Add(q); if (q.PrintDebug) { Logger.WriteLine("Quest: [{0}]: Loaded Quest. [C#]", q.Name); } engine.Dispose(); } catch (Exception e) { Logger.WriteLine("Error in Script not instance of Quest: " + file); Logger.WriteLine("Error es: " + e.Message); } } else if (file.EndsWith(".vb")) { VBScriptEngine engine = new VBScriptEngine(file); engine.AssemblySpaceName = classSpace; AddMetaRefs(ref engine, references); engine.Build(); try { Quest q = (Quest)engine.NewInstance(); _scripts.Add(q); if (q.PrintDebug) { Logger.WriteLine("Quest: [{0}]: Loaded Quest. [VB]", q.Name); } engine.Dispose(); } catch { Logger.WriteLine("Error in Script not instance of Quest: " + file); } } else if (file.EndsWith(".lua", StringComparison.OrdinalIgnoreCase)) { LuaEngine engine = new LuaEngine(file); int q_Id = (int)engine.GetProperties("QuestId"); string name = (string)engine.GetProperties("Name"); string descr = (string)engine.GetProperties("Descr"); quest = new Quest(q_Id, name, descr); quest.loadByScriptEngine(engine); } else if (file.EndsWith(".py")) { //action } } Logger.WriteLine("[Scripting]: Loaded {0} Quests.", _scripts.Where(q => q.IsRealQuest).Count()); }
/// <summary> /// No repeating timer /// </summary> /// <param name="quest"></param> /// <param name="name"></param> /// <param name="npc"></param> /// <param name="player"></param> /// <param name="time"></param> public QuestTimer(Quest quest, string name, object npc, object player, long time) : this(quest, name, npc, player, time, false) { }
/// <summary> /// public method to compare if this timer matches with the key attributes passed. /// </summary> /// <param name="quest"></param> /// <param name="name"></param> /// <param name="npc"></param> /// <param name="player"></param> /// <returns></returns> public bool Equals(Quest quest, String name, object npc, object player) { if (quest == null || quest != _quest) return false; if (name == null || !name.Equals(_name)) return false; return ((npc == _npc) && (player == _player)); }
/// <summary> /// Create a timer /// </summary> /// <param name="quest"></param> /// <param name="name"></param> /// <param name="npc"></param> /// <param name="player"></param> /// <param name="time"></param> /// <param name="repeating"></param> public QuestTimer(Quest quest, string name, object npc, object player, long time, bool repeating) { _quest = quest; _name = name; _npc = npc; _player = player; _isRepeating = repeating; _timer = new Timer(time); _timer.Elapsed += new ElapsedEventHandler(TimerAction); _timer.AutoReset = _isRepeating; _timer.Start(); }