public static void OpenSettings() { OptionsGump opt = UIManager.GetGump <OptionsGump>(); if (opt == null) { OptionsGump optionsGump = new OptionsGump { X = (Client.Game.Window.ClientBounds.Width >> 1) - 300, Y = (Client.Game.Window.ClientBounds.Height >> 1) - 250 }; UIManager.Add(optionsGump); optionsGump.SetInScreen(); } else { opt.SetInScreen(); opt.BringOnTop(); } }
private int Process(MacroObject macro) { if (macro == null) { return(0); } int result = 0; switch (macro.Code) { case MacroType.Say: case MacroType.Emote: case MacroType.Whisper: case MacroType.Yell: MacroObjectString mos = (MacroObjectString)macro; if (!string.IsNullOrEmpty(mos.Text)) { MessageType type = MessageType.Regular; ushort hue = Engine.Profile.Current.SpeechHue; switch (macro.Code) { case MacroType.Emote: type = MessageType.Emote; hue = Engine.Profile.Current.EmoteHue; break; case MacroType.Whisper: type = MessageType.Whisper; hue = Engine.Profile.Current.WhisperHue; break; case MacroType.Yell: type = MessageType.Yell; break; } GameActions.Say(mos.Text, hue, type); } break; case MacroType.Walk: byte dt = (byte)Direction.Up; if (macro.SubCode != MacroSubType.NW) { dt = (byte)(macro.SubCode - 2); if (dt > 7) { dt = 0; } } if (!Pathfinder.AutoWalking) { World.Player.Walk((Direction)dt, false); } break; case MacroType.WarPeace: GameActions.ChangeWarMode(); break; case MacroType.Paste: if (SDL.SDL_HasClipboardText() != SDL.SDL_bool.SDL_FALSE) { string s = SDL.SDL_GetClipboardText(); if (!string.IsNullOrEmpty(s)) { Engine.UI.SystemChat.textBox.Text += s; } } break; case MacroType.Open: case MacroType.Close: case MacroType.Minimize: case MacroType.Maximize: switch (macro.Code) { case MacroType.Open: switch (macro.SubCode) { case MacroSubType.Configuration: OptionsGump opt = Engine.UI.GetGump <OptionsGump>(); if (opt == null) { Engine.UI.Add(opt = new OptionsGump()); opt.SetInScreen(); } else { opt.SetInScreen(); opt.BringOnTop(); } break; case MacroSubType.Paperdoll: GameActions.OpenPaperdoll(World.Player); break; case MacroSubType.Status: if (StatusGumpBase.GetStatusGump() == null) { StatusGumpBase.AddStatusGump(100, 100); } break; case MacroSubType.Journal: JournalGump journalGump = Engine.UI.GetGump <JournalGump>(); if (journalGump == null) { Engine.UI.Add(new JournalGump { X = 64, Y = 64 }); } else { journalGump.SetInScreen(); journalGump.BringOnTop(); } break; case MacroSubType.Skills: World.SkillsRequested = true; NetClient.Socket.Send(new PSkillsRequest(World.Player)); break; case MacroSubType.MageSpellbook: case MacroSubType.NecroSpellbook: case MacroSubType.PaladinSpellbook: case MacroSubType.BushidoSpellbook: case MacroSubType.NinjitsuSpellbook: case MacroSubType.SpellWeavingSpellbook: case MacroSubType.MysticismSpellbook: SpellBookType type = SpellBookType.Magery; switch (macro.SubCode) { case MacroSubType.NecroSpellbook: type = SpellBookType.Necromancy; break; case MacroSubType.PaladinSpellbook: type = SpellBookType.Chivalry; break; case MacroSubType.BushidoSpellbook: type = SpellBookType.Bushido; break; case MacroSubType.NinjitsuSpellbook: type = SpellBookType.Ninjitsu; break; case MacroSubType.SpellWeavingSpellbook: type = SpellBookType.Spellweaving; break; case MacroSubType.MysticismSpellbook: type = SpellBookType.Mysticism; break; case MacroSubType.BardSpellbook: type = SpellBookType.Bardic; break; } NetClient.Socket.Send(new POpenSpellBook((byte)type)); break; case MacroSubType.Chat: Log.Message(LogTypes.Warning, $"Macro '{macro.SubCode}' not implemented"); break; case MacroSubType.Backpack: Item backpack = World.Player.Equipment[(int)Layer.Backpack]; if (backpack != null) { GameActions.DoubleClick(backpack); } break; case MacroSubType.Overview: MiniMapGump miniMapGump = Engine.UI.GetGump <MiniMapGump>(); if (miniMapGump == null) { Engine.UI.Add(new MiniMapGump()); } else { miniMapGump.ToggleSize(); miniMapGump.SetInScreen(); miniMapGump.BringOnTop(); } break; case MacroSubType.WorldMap: Log.Message(LogTypes.Warning, $"Macro '{macro.SubCode}' not implemented"); break; case MacroSubType.Mail: case MacroSubType.PartyManifest: var party = Engine.UI.GetGump <PartyGumpAdvanced>(); if (party == null) { Engine.UI.Add(new PartyGumpAdvanced()); } else { party.BringOnTop(); } break; case MacroSubType.Guild: GameActions.OpenGuildGump(); break; case MacroSubType.QuestLog: GameActions.RequestQuestMenu(); break; case MacroSubType.PartyChat: case MacroSubType.CombatBook: case MacroSubType.RacialAbilitiesBook: case MacroSubType.BardSpellbook: Log.Message(LogTypes.Warning, $"Macro '{macro.SubCode}' not implemented"); break; } break; case MacroType.Close: case MacroType.Minimize: // TODO: miniminze/maximize case MacroType.Maximize: switch (macro.SubCode) { case MacroSubType.Configuration: if (macro.Code == MacroType.Close) { Engine.UI.GetGump <OptionsGump>()?.Dispose(); } break; case MacroSubType.Paperdoll: if (macro.Code == MacroType.Close) { Engine.UI.GetGump <PaperDollGump>()?.Dispose(); } break; case MacroSubType.Status: if (macro.Code == MacroType.Close) { StatusGumpBase.GetStatusGump()?.Dispose(); } break; case MacroSubType.Journal: if (macro.Code == MacroType.Close) { Engine.UI.GetGump <JournalGump>()?.Dispose(); } break; case MacroSubType.Skills: if (macro.Code == MacroType.Close) { Engine.UI.GetGump <SkillGumpAdvanced>()?.Dispose(); } break; case MacroSubType.MageSpellbook: case MacroSubType.NecroSpellbook: case MacroSubType.PaladinSpellbook: case MacroSubType.BushidoSpellbook: case MacroSubType.NinjitsuSpellbook: case MacroSubType.SpellWeavingSpellbook: case MacroSubType.MysticismSpellbook: if (macro.Code == MacroType.Close) { Engine.UI.GetGump <SpellbookGump>()?.Dispose(); } break; case MacroSubType.Chat: Log.Message(LogTypes.Warning, $"Macro '{macro.SubCode}' not implemented"); break; case MacroSubType.Overview: if (macro.Code == MacroType.Close) { Engine.UI.GetGump <MiniMapGump>()?.Dispose(); } break; case MacroSubType.Mail: Log.Message(LogTypes.Warning, $"Macro '{macro.SubCode}' not implemented"); break; case MacroSubType.PartyManifest: if (macro.Code == MacroType.Close) { Engine.UI.GetGump <PartyGumpAdvanced>()?.Dispose(); } break; case MacroSubType.PartyChat: case MacroSubType.CombatBook: case MacroSubType.RacialAbilitiesBook: case MacroSubType.BardSpellbook: Log.Message(LogTypes.Warning, $"Macro '{macro.SubCode}' not implemented"); break; } break; } break; case MacroType.OpenDoor: GameActions.OpenDoor(); break; case MacroType.UseSkill: int skill = macro.SubCode - MacroSubType.Anatomy; if (skill >= 0 && skill < 24) { skill = _skillTable[skill]; if (skill != 0xFF) { GameActions.UseSkill(skill); } } break; case MacroType.LastSkill: GameActions.UseSkill(GameActions.LastSkillIndex); break; case MacroType.CastSpell: int spell = macro.SubCode - MacroSubType.Clumsy + 1; if (spell > 0 && spell <= 151) { int totalCount = 0; int spellType = 0; for (spellType = 0; spellType < 7; spellType++) { totalCount += _spellsCountTable[spellType]; if (spell < totalCount) { break; } } if (spellType < 7) { spell += spellType * 100; if (spellType > 2) { spell += 100; } GameActions.CastSpell(spell); } } break; case MacroType.LastSpell: GameActions.CastSpell(GameActions.LastSpellIndex); break; case MacroType.Bow: case MacroType.Salute: int index = macro.Code - MacroType.Bow; const string BOW = "bow"; const string SALUTE = "salute"; GameActions.EmoteAction(index == 0 ? BOW : SALUTE); break; case MacroType.QuitGame: Engine.SceneManager.GetScene <GameScene>()?.RequestQuitGame(); break; case MacroType.AllNames: GameActions.AllNames(); break; case MacroType.LastObject: if (World.Get(GameActions.LastObject) != null) { GameActions.DoubleClick(GameActions.LastObject); } break; case MacroType.UseItemInHand: Item itemInLeftHand = World.Player.Equipment[(int)Layer.OneHanded]; if (itemInLeftHand != null) { GameActions.DoubleClick(itemInLeftHand.Serial); } else { Item itemInRightHand = World.Player.Equipment[(int)Layer.TwoHanded]; if (itemInRightHand != null) { GameActions.DoubleClick(itemInRightHand.Serial); } } break; case MacroType.LastTarget: //if (WaitForTargetTimer == 0) // WaitForTargetTimer = Engine.Ticks + Constants.WAIT_FOR_TARGET_DELAY; if (TargetManager.IsTargeting) { //if (TargetManager.TargetingState != TargetType.Object) //{ // TargetManager.TargetGameObject(TargetManager.LastGameObject); //} //else TargetManager.TargetGameObject(World.Get(TargetManager.LastTarget)); WaitForTargetTimer = 0; } else if (WaitForTargetTimer < Engine.Ticks) { WaitForTargetTimer = 0; } else { result = 1; } break; case MacroType.TargetSelf: //if (WaitForTargetTimer == 0) // WaitForTargetTimer = Engine.Ticks + Constants.WAIT_FOR_TARGET_DELAY; if (TargetManager.IsTargeting) { TargetManager.TargetGameObject(World.Player); WaitForTargetTimer = 0; } else if (WaitForTargetTimer < Engine.Ticks) { WaitForTargetTimer = 0; } else { result = 1; } break; case MacroType.ArmDisarm: int handIndex = 1 - (macro.SubCode - MacroSubType.LeftHand); GameScene gs = Engine.SceneManager.GetScene <GameScene>(); if (handIndex < 0 || handIndex > 1 || gs.IsHoldingItem) { break; } if (_itemsInHand[handIndex] != 0) { Item item = World.Items.Get(_itemsInHand[handIndex]); if (item != null) { GameActions.PickUp(item, 1); gs.WearHeldItem(World.Player); } _itemsInHand[handIndex] = 0; } else { Item backpack = World.Player.Equipment[(int)Layer.Backpack]; if (backpack == null) { break; } Item item = World.Player.Equipment[(int)Layer.OneHanded + handIndex]; if (item != null) { _itemsInHand[handIndex] = item.Serial; GameActions.PickUp(item, 1); GameActions.DropItem(item, Position.INVALID, backpack); } } break; case MacroType.WaitForTarget: if (WaitForTargetTimer == 0) { WaitForTargetTimer = Engine.Ticks + Constants.WAIT_FOR_TARGET_DELAY; } if (TargetManager.IsTargeting || WaitForTargetTimer < Engine.Ticks) { WaitForTargetTimer = 0; } else { result = 1; } break; case MacroType.TargetNext: if (TargetManager.LastTarget.IsMobile) { Mobile mob = World.Mobiles.Get(TargetManager.LastTarget); if (mob == null) { break; } if (mob.HitsMax == 0) { NetClient.Socket.Send(new PStatusRequest(mob)); } TargetManager.LastAttack = mob.Serial; } break; case MacroType.AttackLast: GameActions.Attack(TargetManager.LastTarget); break; case MacroType.Delay: MacroObjectString mosss = (MacroObjectString)macro; string str = mosss.Text; if (!string.IsNullOrEmpty(str) && int.TryParse(str, out int rr)) { _nextTimer = Engine.Ticks + rr; } break; case MacroType.CircleTrans: Engine.Profile.Current.UseCircleOfTransparency = !Engine.Profile.Current.UseCircleOfTransparency; break; case MacroType.CloseGump: Engine.UI.Gumps .Where(s => !(s is TopBarGump) && !(s is BuffGump) && !(s is WorldViewportGump)) .ToList() .ForEach(s => s.Dispose()); break; case MacroType.AlwaysRun: Engine.Profile.Current.AlwaysRun = !Engine.Profile.Current.AlwaysRun; GameActions.Print($"Always run is now {(Engine.Profile.Current.AlwaysRun ? "on" : "off")}."); break; case MacroType.SaveDesktop: Engine.Profile.Current?.Save(Engine.UI.Gumps.OfType <Gump>().Where(s => s.CanBeSaved).Reverse().ToList()); break; case MacroType.EnableRangeColor: Engine.Profile.Current.NoColorObjectsOutOfRange = true; break; case MacroType.DisableRangeColor: Engine.Profile.Current.NoColorObjectsOutOfRange = false; break; case MacroType.ToggleRangeColor: Engine.Profile.Current.NoColorObjectsOutOfRange = !Engine.Profile.Current.NoColorObjectsOutOfRange; break; case MacroType.AttackSelectedTarget: // TODO: break; case MacroType.UseSelectedTarget: // TODO: break; case MacroType.CurrentTarget: // TODO: break; case MacroType.TargetSystemOnOff: // TODO: break; case MacroType.BandageSelf: case MacroType.BandageTarget: if (FileManager.ClientVersion < ClientVersions.CV_5020 || Engine.Profile.Current.BandageSelfOld) { if (WaitingBandageTarget) { if (WaitForTargetTimer == 0) { WaitForTargetTimer = Engine.Ticks + Constants.WAIT_FOR_TARGET_DELAY; } if (TargetManager.IsTargeting) { TargetManager.TargetGameObject(macro.Code == MacroType.BandageSelf ? World.Player : World.Mobiles.Get(TargetManager.LastTarget)); } else { result = 1; } WaitingBandageTarget = false; WaitForTargetTimer = 0; } else { var bandage = World.Player.FindBandage(); if (bandage != null) { WaitingBandageTarget = true; GameActions.DoubleClick(bandage); result = 1; } } } else { var bandage = World.Player.FindBandage(); if (bandage != null) { if (macro.Code == MacroType.BandageSelf) { NetClient.Socket.Send(new PTargetSelectedObject(bandage.Serial, World.Player.Serial)); } else { // TODO: NewTargetSystem Log.Message(LogTypes.Warning, "BandageTarget (NewTargetSystem) not implemented yet."); } } } break; case MacroType.SetUpdateRange: case MacroType.ModifyUpdateRange: if (macro is MacroObjectString moss && !string.IsNullOrEmpty(moss.Text) && byte.TryParse(moss.Text, out byte res)) { if (res < Constants.MIN_VIEW_RANGE) { res = Constants.MIN_VIEW_RANGE; } else if (res > Constants.MAX_VIEW_RANGE) { res = Constants.MAX_VIEW_RANGE; } World.ClientViewRange = res; GameActions.Print($"ClientViewRange is now {res}."); } break; case MacroType.IncreaseUpdateRange: World.ClientViewRange++; if (World.ClientViewRange > Constants.MAX_VIEW_RANGE) { World.ClientViewRange = Constants.MAX_VIEW_RANGE; } GameActions.Print($"ClientViewRange is now {World.ClientViewRange}."); break; case MacroType.DecreaseUpdateRange: World.ClientViewRange--; if (World.ClientViewRange < Constants.MIN_VIEW_RANGE) { World.ClientViewRange = Constants.MIN_VIEW_RANGE; } GameActions.Print($"ClientViewRange is now {World.ClientViewRange}."); break; case MacroType.MaxUpdateRange: World.ClientViewRange = Constants.MAX_VIEW_RANGE; GameActions.Print($"ClientViewRange is now {World.ClientViewRange}."); break; case MacroType.MinUpdateRange: World.ClientViewRange = Constants.MIN_VIEW_RANGE; GameActions.Print($"ClientViewRange is now {World.ClientViewRange}."); break; case MacroType.DefaultUpdateRange: World.ClientViewRange = Constants.MAX_VIEW_RANGE; GameActions.Print($"ClientViewRange is now {World.ClientViewRange}."); break; case MacroType.SelectNext: case MacroType.SelectPrevious: case MacroType.SelectNearest: // TODO: int scantype = macro.SubCode - MacroSubType.Hostile; int scanRange = macro.Code - MacroType.SelectNext; switch (scanRange) { case 0: break; case 1: break; case 2: break; } break; case MacroType.ToggleBuffIconGump: BuffGump buff = Engine.UI.GetGump <BuffGump>(); if (buff != null) { buff.Dispose(); } else { Engine.UI.Add(new BuffGump(100, 100)); } break; case MacroType.InvokeVirtue: byte id = (byte)(macro.SubCode - MacroSubType.Honor + 31); NetClient.Socket.Send(new PInvokeVirtueRequest(id)); break; case MacroType.PrimaryAbility: GameActions.UsePrimaryAbility(); break; case MacroType.SecondaryAbility: GameActions.UseSecondaryAbility(); break; case MacroType.ToggleGargoyleFly: if (World.Player.Race == RaceType.GARGOYLE) { NetClient.Socket.Send(new PToggleGargoyleFlying()); } break; case MacroType.EquipLastWeapon: NetClient.Socket.Send(new PEquipLastWeapon()); break; case MacroType.KillGumpOpen: // TODO: break; case MacroType.DefaultScale: Engine.SceneManager.GetScene <GameScene>().Scale = 1; break; case MacroType.ToggleChatVisibility: Engine.UI.SystemChat?.ToggleChatVisibility(); break; case MacroType.MovePlayer: switch (macro.SubCode) { case MacroSubType.Top: break; case MacroSubType.Right: break; case MacroSubType.Down: break; case MacroSubType.Left: break; } break; case MacroType.Aura: // hold to draw break; case MacroType.AuraOnOff: Engine.AuraManager.ToggleVisibility(); break; case MacroType.Grab: GameActions.Print("Target an Item to grab it."); TargetManager.SetTargeting(CursorTarget.Grab, Serial.INVALID, TargetType.Neutral); break; case MacroType.SetGrabBag: GameActions.Print("Target the container to Grab items into."); TargetManager.SetTargeting(CursorTarget.SetGrabBag, Serial.INVALID, TargetType.Neutral); break; case MacroType.NamesOnOff: NameOverHeadManager.ToggleOverheads(); break; case MacroType.UsePotion: scantype = macro.SubCode - MacroSubType.ConfusionBlastPotion; ushort start = (ushort)(0x0F06 + scantype); Item potion = World.Player.FindItemByGraphic(start); if (potion != null) { GameActions.DoubleClick(potion); } break; } return(result); }