using System; using System.ComponentModel; using System.Configuration; using System.Drawing.Design; using System.IO; using System.Threading; using robotManager.Helpful; using robotManager.Products; using wManager; using wManager.Plugin; using wManager.Wow.Class; using wManager.Wow.Enums; using wManager.Wow.Helpers; using wManager.Wow.ObjectManager; public class Main : IPlugin { private bool _isLaunched; public void Initialize() { _isLaunched = true; PartyChatCommandSettings.Load(); Logging.Write("[PartyChatCommand] Started."); var chat = new Channel(); while (_isLaunched && Products.IsStarted) { try { while (chat.ActuelRead != Channel.GetMsgActuelInWow && Products.IsStarted) { var msg = chat.ReadMsg(); if (!string.IsNullOrWhiteSpace(msg.Msg) && ((int)msg.Channel == 49 || msg.Channel == ChatTypeId.PARTY)) { foreach (var c in PartyChatCommandSettings.CurrentSetting.Commands) { if (c.IsValid() && string.Equals(c.CommandChat.Trim(), msg.Msg.Trim(), StringComparison.CurrentCultureIgnoreCase)) { c.Run(); break; } } } } } catch (Exception e) { Logging.WriteError("[PartyChatCommand]: " + e); } Thread.Sleep(150); } } public void Dispose() { _isLaunched = false; Logging.Write("[PartyChatCommand] Stoped."); } public void Settings() { PartyChatCommandSettings.Load(); PartyChatCommandSettings.CurrentSetting.ToForm(); PartyChatCommandSettings.CurrentSetting.Save(); Logging.Write("[PartyChatCommand] Settings saved."); } } public class PartyChatCommandSettings : Settings { public PartyChatCommandSettings() { Commands = new Command[0]; } public static PartyChatCommandSettings CurrentSetting { get; set; } public bool Save() { try { return Save(AdviserFilePathAndName("PartyChatCommand", ObjectManager.Me.Name + "." + Usefuls.RealmName)); } catch (Exception e) { Logging.WriteError("PartyChatCommandSettings > Save(): " + e); return false; } } public static bool Load() { try { if (File.Exists(AdviserFilePathAndName("PartyChatCommand", ObjectManager.Me.Name + "." + Usefuls.RealmName))) { CurrentSetting = Load(AdviserFilePathAndName("PartyChatCommand", ObjectManager.Me.Name + "." + Usefuls.RealmName)); return true; } else { CurrentSetting = new PartyChatCommandSettings { Commands = new[] { new Command { CommandChat = "gohome", CommandAction = "6948", Type = CommandType.UseItem }, } }; } } catch (Exception e) { Logging.WriteError("PartyChatCommandSettings > Load(): " + e); } return false; } [Setting] [Category("Settings")] [DisplayName("Command")] [Description("Put command here")] public Command[] Commands { get; set; } [Serializable] public class Command { public Command() { CommandChat = string.Empty; CommandAction = string.Empty; Type = CommandType.Lua; } [Setting] [DisplayName("Command")] [Description("Put here command received in chat (party channel)")] public string CommandChat { get; set; } [Setting] [DisplayName("Command action")] [Description("Put here action triggered by the command")] [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] public string CommandAction { get; set; } [Setting] [DisplayName("Action command type")] [Description("Select action type")] public CommandType Type { get; set; } public bool IsValid() { try { return !string.IsNullOrWhiteSpace(CommandChat) && !string.IsNullOrWhiteSpace(CommandAction); } catch { return false; } } public void Run() { try { Logging.Write("[PartyChatCommand] Run " + ToString()); switch (Type) { case CommandType.Lua: Lua.LuaDoString(CommandAction); break; case CommandType.LuaMacro: Lua.RunMacroText(CommandAction); break; case CommandType.UseItem: var n = Others.ParseUInt(CommandAction); if (n > 0) ItemsManager.UseItem(n); else ItemsManager.UseItem(CommandAction); break; case CommandType.CastSpell: var s = new Spell(CommandAction); s.Launch(); break; } } catch { } } public override string ToString() { try { return "[" + Type + "] " + CommandChat + " > " + CommandAction; } catch (Exception) { return base.ToString(); } } } public enum CommandType { Lua, LuaMacro, UseItem, CastSpell, } }