void SaveMacroState(PlayerMacroState macro) { if (macro == null) throw new ArgumentNullException("macro"); var filename = Path.Combine("saves", string.Format("{0}.xml", macro.Client.Name.Trim())); var state = new SavedMacroState(macro); state.SaveToFile(filename); }
public void ImportMacroState(Player player, SavedMacroState state) { if (player == null) { throw new ArgumentNullException("player"); } if (state == null) { throw new ArgumentNullException("state"); } var macro = GetMacroState(player); if (macro == null) { return; } macro.Stop(); var process = Process.GetCurrentProcess(); if (player.HasHotkey) { HotkeyManager.Instance.UnregisterHotkey(process.MainWindowHandle, player.Hotkey); player.Hotkey = null; } player.Skillbook.ClearActiveSkills(); macro.ClearSpellQueue(); macro.ClearFlowerQueue(); player.Update(PlayerFieldFlags.Spellbook); macro.UseLyliacVineyard = player.HasLyliacVineyard && state.UseLyliacVineyard; macro.FlowerAlternateCharacters = player.HasLyliacPlant && state.FlowerAlternateCharacters; player.Update(PlayerFieldFlags.Skillbook); foreach (var skill in state.Skills) { if (!player.Skillbook.ContainSkill(skill.SkillName)) { continue; } player.Skillbook.ToggleActive(skill.SkillName, true); } foreach (var spell in state.Spells) { if (!player.Spellbook.ContainSpell(spell.SpellName)) { continue; } var spellInfo = player.Spellbook.GetSpell(spell.SpellName); if (spellInfo == null) { continue; } var queueItem = new SpellQueueItem(spellInfo, spell); macro.AddToSpellQueue(queueItem); } if (player.HasLyliacPlant) { foreach (var flower in state.Flowers) { if (flower.TargetMode == TargetCoordinateUnits.None) { continue; } var queueItem = new FlowerQueueItem(flower); macro.AddToFlowerQueue(queueItem); } } var windowHandle = Process.GetCurrentProcess().MainWindowHandle; if (state.HotkeyKey != Key.None && (state.HotkeyModifiers != ModifierKeys.None || Hotkey.IsFunctionKey(state.HotkeyKey))) { var hotkey = new Hotkey(state.HotkeyModifiers, state.HotkeyKey); if (HotkeyManager.Instance.RegisterHotkey(windowHandle, hotkey)) { player.Hotkey = hotkey; } } }
public void ImportMacroState(Player player, SavedMacroState state) { if (player == null) throw new ArgumentNullException("player"); if (state == null) throw new ArgumentNullException("state"); var macro = GetMacroState(player); if (macro == null) return; macro.Stop(); var process = Process.GetCurrentProcess(); if (player.HasHotkey) { HotkeyManager.Instance.UnregisterHotkey(process.MainWindowHandle, player.Hotkey); player.Hotkey = null; } player.Skillbook.ClearActiveSkills(); macro.ClearSpellQueue(); macro.ClearFlowerQueue(); player.Update(PlayerFieldFlags.Spellbook); macro.UseLyliacVineyard = player.HasLyliacVineyard && state.UseLyliacVineyard; macro.FlowerAlternateCharacters = player.HasLyliacPlant && state.FlowerAlternateCharacters; player.Update(PlayerFieldFlags.Skillbook); foreach (var skill in state.Skills) { if (!player.Skillbook.ContainSkill(skill.SkillName)) continue; player.Skillbook.ToggleActive(skill.SkillName, true); } foreach (var spell in state.Spells) { if (!player.Spellbook.ContainSpell(spell.SpellName)) continue; var spellInfo = player.Spellbook.GetSpell(spell.SpellName); if (spellInfo == null) continue; var queueItem = new SpellQueueItem(spellInfo, spell); macro.AddToSpellQueue(queueItem); } if (player.HasLyliacPlant) foreach (var flower in state.Flowers) { if (flower.TargetMode == TargetCoordinateUnits.None) continue; var queueItem = new FlowerQueueItem(flower); macro.AddToFlowerQueue(queueItem); } var windowHandle = Process.GetCurrentProcess().MainWindowHandle; if (state.HotkeyKey != Key.None && (state.HotkeyModifiers != ModifierKeys.None || Hotkey.IsFunctionKey(state.HotkeyKey))) { var hotkey = new Hotkey(state.HotkeyModifiers, state.HotkeyKey); if (HotkeyManager.Instance.RegisterHotkey(windowHandle, hotkey)) player.Hotkey = hotkey; } }