private void OnKeyDown(object sender, SDL.SDL_KeyboardEvent e)
        {
            if (TargetManager.IsTargeting && e.keysym.sym == SDL.SDL_Keycode.SDLK_ESCAPE && Input.Keyboard.IsModPressed(e.keysym.mod, SDL.SDL_Keymod.KMOD_NONE))
            {
                TargetManager.CancelTarget();
            }

            _isShiftDown = Input.Keyboard.IsModPressed(e.keysym.mod, SDL.SDL_Keymod.KMOD_SHIFT);

            if (e.keysym.sym == SDL.SDL_Keycode.SDLK_TAB)
            {
                if (!World.Player.InWarMode && Engine.Profile.Current.HoldDownKeyTab)
                {
                    GameActions.SetWarMode(true);
                }
            }

            if (_keycodeDirection.TryGetValue(e.keysym.sym, out Direction dWalk))
            {
                WorldViewportGump viewport = Engine.UI.GetByLocalSerial <WorldViewportGump>();
                SystemChatControl chat     = viewport?.FindControls <SystemChatControl>().SingleOrDefault();
                if (chat != null && chat.textBox.Text.Length == 0)
                {
                    World.Player.Walk(dWalk, false);
                }
            }

            if ((e.keysym.mod & SDL2.SDL.SDL_Keymod.KMOD_NUM) != SDL2.SDL.SDL_Keymod.KMOD_NUM)
            {
                if (_keycodeDirectionNum.TryGetValue(e.keysym.sym, out Direction dWalkN))
                {
                    World.Player.Walk(dWalkN, false);
                }
            }

            bool isshift = (e.keysym.mod & SDL.SDL_Keymod.KMOD_SHIFT) != SDL.SDL_Keymod.KMOD_NONE;
            bool isalt   = (e.keysym.mod & SDL.SDL_Keymod.KMOD_ALT) != SDL.SDL_Keymod.KMOD_NONE;
            bool isctrl  = (e.keysym.mod & SDL.SDL_Keymod.KMOD_CTRL) != SDL.SDL_Keymod.KMOD_NONE;


            _useObjectHandles = isshift && isctrl;

            Macro macro = _macroManager.FindMacro(e.keysym.sym, isalt, isctrl, isshift);

            if (macro != null)
            {
                _macroManager.SetMacroToExecute(macro.FirstNode);
                _macroManager.WaitForTargetTimer = 0;
                _macroManager.Update();
            }

            //if (_hotkeysManager.TryExecuteIfBinded(e.keysym.sym, e.keysym.mod, out Action action))
            //{
            //    action();
            //}
        }
예제 #2
0
        private int Process(MacroObject macro)
        {
            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;
                    }

                    Chat.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.ToggleWarMode();

                break;

            case MacroType.Paste:
                if (SDL.SDL_HasClipboardText() != SDL.SDL_bool.SDL_FALSE)
                {
                    string s = SDL.SDL_GetClipboardText();
                    if (!string.IsNullOrEmpty(s))
                    {
                        WorldViewportGump viewport = Engine.UI.GetByLocalSerial <WorldViewportGump>();
                        if (viewport != null)
                        {
                            SystemChatControl chat = viewport.FindControls <SystemChatControl>().SingleOrDefault();
                            if (chat != null)
                            {
                                chat.textBox.Text += s;
                            }
                        }
                    }
                }

                break;

            case MacroType.Open:
            case MacroType.Close:
            case MacroType.Minimize:
            case MacroType.Maximize:
                // TODO:
                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.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.LastGameObject));

                    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.LastGameObject.IsMobile)
                {
                    Mobile mob = World.Mobiles.Get(TargetManager.LastGameObject);

                    if (mob.HitsMax == 0)
                    {
                        NetClient.Socket.Send(new PStatusRequest(mob));
                    }

                    World.LastAttack = mob.Serial;
                }

                break;

            case MacroType.AttackLast:
                GameActions.Attack(World.LastAttack);
                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;

                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.LastGameObject));
                        }
                        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.ViewRange = res;
                }
                break;

            case MacroType.IncreaseUpdateRange:
                World.ViewRange++;
                if (World.ViewRange > Constants.MAX_VIEW_RANGE)
                {
                    World.ViewRange = Constants.MAX_VIEW_RANGE;
                }
                break;

            case MacroType.DecreaseUpdateRange:
                World.ViewRange--;
                if (World.ViewRange < Constants.MIN_VIEW_RANGE)
                {
                    World.ViewRange = Constants.MIN_VIEW_RANGE;
                }

                break;

            case MacroType.MaxUpdateRange:
                World.ViewRange = Constants.MAX_VIEW_RANGE;

                break;

            case MacroType.MinUpdateRange:
                World.ViewRange = Constants.MIN_VIEW_RANGE;

                break;

            case MacroType.DefaultUpdateRange:
                World.ViewRange = Constants.MAX_VIEW_RANGE;

                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.ToggleBuiconWindow:
                BuffGump buff = Engine.UI.GetByLocalSerial <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;
            }


            return(result);
        }