Exemple #1
0
        private void OnKeyBindStateChanged(ViewportBoundKeyEventArgs args)
        {
            if (_baseClient.RunLevel != ClientRunLevel.InGame)
            {
                return;
            }

            if (!_entitySystemManager.TryGetEntitySystem <InputSystem>(out var inputSystem))
            {
                return;
            }

            var keyArgs       = args.KeyEventArgs;
            var inputFunction = _inputManager.NetworkBindMap.KeyFunctionID(keyArgs.Function);

            EntityCoordinates coords = EntityCoordinates.Invalid;
            EntityUid         entity = EntityUid.Invalid;

            if (args.Viewport is ScalingViewport viewport)
            {
                MapCoordinates mapCoords = viewport.ScreenToMap(keyArgs.PointerLocation.Position);

                entity = GetEntityUnderMouse(viewport, keyArgs.PointerLocation.Position, mapCoords);
                coords = _mapManager.TryFindGridAt(mapCoords, out var grid) ? grid.MapToGrid(mapCoords) :
                         EntityCoordinates.FromMap(_mapManager, mapCoords);
            }

            var message = new FullInputCmdMessage(_gameTiming.CurTick, _gameTiming.TickFraction, inputFunction, keyArgs.State, coords, keyArgs.PointerLocation, entity);

            if (inputSystem.HandleInputCommand(_playerManager.LocalPlayer.Session, keyArgs.Function, message))
            {
                keyArgs.Handle();
            }
        }
 public PointerInputCmdArgs(ICommonSession?session, GridCoordinates coordinates,
                            ScreenCoordinates screenCoordinates, EntityUid entityUid, BoundKeyState state,
                            FullInputCmdMessage originalMessage)
 {
     Session           = session;
     Coordinates       = coordinates;
     ScreenCoordinates = screenCoordinates;
     EntityUid         = entityUid;
     State             = state;
     OriginalMessage   = originalMessage;
 }
Exemple #3
0
        public bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity?item)
        {
            if (item == null)
            {
                return(false);
            }

            if (args.Function == ContentKeyFunctions.ExamineEntity)
            {
                _entitySystemManager.GetEntitySystem <ExamineSystem>()
                .DoExamine(item);
            }
            else if (args.Function == ContentKeyFunctions.OpenContextMenu)
            {
                _entitySystemManager.GetEntitySystem <VerbSystem>()
                .OpenContextMenu(item, _uiMgr.ScreenToUIPosition(args.PointerLocation));
            }
            else if (args.Function == ContentKeyFunctions.ActivateItemInWorld)
            {
                var inputSys = _entitySystemManager.GetEntitySystem <InputSystem>();

                var func   = args.Function;
                var funcId = _inputManager.NetworkBindMap.KeyFunctionID(args.Function);


                var mousePosWorld = _eyeManager.ScreenToMap(args.PointerLocation);

                var coordinates = _mapManager.TryFindGridAt(mousePosWorld, out var grid) ? grid.MapToGrid(mousePosWorld) :
                                  EntityCoordinates.FromMap(_mapManager, mousePosWorld);

                var message = new FullInputCmdMessage(_gameTiming.CurTick, _gameTiming.TickFraction, funcId, BoundKeyState.Down,
                                                      coordinates, args.PointerLocation, item.Uid);

                // client side command handlers will always be sent the local player session.
                var session = _playerManager.LocalPlayer?.Session;
                if (session == null)
                {
                    return(false);
                }

                inputSys.HandleInputCommand(session, func, message);
            }
            else
            {
                return(false);
            }
            args.Handle();
            return(true);
        }
        private bool HandleInputMessage(ICommonSession session, InputCmdMessage message)
        {
            if (!(message is FullInputCmdMessage msg))
            {
                return(false);
            }

            void SendMsg(BoundKeyFunction function, BoundKeyState state)
            {
                var functionId = _inputManager.NetworkBindMap.KeyFunctionID(function);

                var sendMsg = new FullInputCmdMessage(msg.Tick, functionId, state,
                                                      msg.Coordinates, msg.ScreenCoordinates, msg.Uid);

                _inputSystem.HandleInputCommand(session, function, sendMsg);
            }

            // If we are not in combat mode, relay it as a regular Use instead.
            if (!IsInCombatMode())
            {
                SendMsg(EngineKeyFunctions.Use, msg.State);
                return(true);
            }

            if (msg.State == BoundKeyState.Down)
            {
                UseOrAttackIsDown = true;
                _timeHeld         = 0;
                return(true);
            }

            // Up.
            if (UseOrAttackIsDown && _timeHeld >= AttackTimeThreshold)
            {
                // Attack.
                SendMsg(ContentKeyFunctions.Attack, BoundKeyState.Down);
                SendMsg(ContentKeyFunctions.Attack, BoundKeyState.Up);
            }
            else
            {
                // Use.
                SendMsg(EngineKeyFunctions.Use, BoundKeyState.Down);
                SendMsg(EngineKeyFunctions.Use, BoundKeyState.Up);
            }

            UseOrAttackIsDown = false;

            return(true);
        }
Exemple #5
0
        /// <summary>
        /// Handle a predicted input command.
        /// </summary>
        /// <param name="inputCmd">Input command to handle as predicted.</param>
        public void PredictInputCommand(FullInputCmdMessage inputCmd)
        {
            var keyFunc = _inputManager.NetworkBindMap.KeyFunctionName(inputCmd.InputFunctionId);

            if (!_bindMap.TryGetHandler(keyFunc, out var handler))
            {
                return;
            }

            Predicted = true;

            var session = _playerManager.LocalPlayer.Session;

            handler.HandleCmdMessage(session, inputCmd);

            Predicted = false;
        }
Exemple #6
0
        /// <summary>
        /// Handle a predicted input command.
        /// </summary>
        /// <param name="inputCmd">Input command to handle as predicted.</param>
        public void PredictInputCommand(FullInputCmdMessage inputCmd)
        {
            DebugTools.AssertNotNull(_playerManager.LocalPlayer);

            var keyFunc = _inputManager.NetworkBindMap.KeyFunctionName(inputCmd.InputFunctionId);

            Predicted = true;
            var session = _playerManager.LocalPlayer !.Session;

            foreach (var handler in BindRegistry.GetHandlers(keyFunc))
            {
                if (handler.HandleCmdMessage(session, inputCmd))
                {
                    break;
                }
            }
            Predicted = false;
        }
Exemple #7
0
        private void OnKeyBindStateChanged(ViewportBoundKeyEventArgs args)
        {
            if (_baseClient.RunLevel < ClientRunLevel.InGame)
            {
                return;
            }

            if (!_entitySystemManager.TryGetEntitySystem <InputSystem>(out var inputSystem))
            {
                return;
            }

            var message = new FullInputCmdMessage(_gameTiming.CurTick, _gameTiming.TickFraction, _inputManager.NetworkBindMap.KeyFunctionID(args.KeyEventArgs.Function), args.KeyEventArgs.State, EntityCoordinates.Invalid, args.KeyEventArgs.PointerLocation, EntityUid.Invalid);

            if (inputSystem.HandleInputCommand(_playerManager.LocalPlayer !.Session, args.KeyEventArgs.Function, message))
            {
                args.KeyEventArgs.Handle();
            }
        }
        public bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity item)
        {
            args.Handle();

            if (item == null)
            {
                return(false);
            }

            if (args.Function == ContentKeyFunctions.ExamineEntity)
            {
                _entitySystemManager.GetEntitySystem <ExamineSystem>()
                .DoExamine(item);
            }
            else if (args.Function == ContentKeyFunctions.OpenContextMenu)
            {
                _entitySystemManager.GetEntitySystem <VerbSystem>()
                .OpenContextMenu(item, new ScreenCoordinates(args.PointerLocation.Position));
            }
            else if (args.Function == ContentKeyFunctions.ActivateItemInWorld)
            {
                var inputSys = _entitySystemManager.GetEntitySystem <InputSystem>();

                var func   = args.Function;
                var funcId = _inputManager.NetworkBindMap.KeyFunctionID(args.Function);

                var mousePosWorld = _eyeManager.ScreenToWorld(args.PointerLocation);
                var message       = new FullInputCmdMessage(_gameTiming.CurTick, funcId, BoundKeyState.Down, mousePosWorld,
                                                            args.PointerLocation, item.Uid);

                // client side command handlers will always be sent the local player session.
                var session = _playerManager.LocalPlayer.Session;
                inputSys.HandleInputCommand(session, func, message);
            }
            else
            {
                return(false);
            }
            return(true);
        }
Exemple #9
0
        /// <summary>
        ///     Inserts an Input Command into the simulation.
        /// </summary>
        /// <param name="session">Player session that raised the command. On client, this is always the LocalPlayer session.</param>
        /// <param name="function">Function that is being changed.</param>
        /// <param name="message">Arguments for this event.</param>
        /// <param name="replay">if true, current cmd state will not be checked or updated - use this for "replaying" an
        /// old input that was saved or buffered until further processing could be done</param>
        public bool HandleInputCommand(ICommonSession session, BoundKeyFunction function, FullInputCmdMessage message, bool replay = false)
        {
            #if DEBUG
            var funcId = _inputManager.NetworkBindMap.KeyFunctionID(function);
            DebugTools.Assert(funcId == message.InputFunctionId, "Function ID in message does not match function.");
            #endif

            if (!replay)
            {
                // set state, state change is updated regardless if it is locally bound
                if (_cmdStates.GetState(function) == message.State)
                {
                    return(false);
                }
                _cmdStates.SetState(function, message.State);
            }

            // handle local binds before sending off
            foreach (var handler in BindRegistry.GetHandlers(function))
            {
                // local handlers can block sending over the network.
                if (handler.HandleCmdMessage(session, message))
                {
                    return(true);
                }
            }

            // send it off to the server
            DispatchInputCommand(message);
            return(false);
        }
Exemple #10
0
 private void DispatchInputCommand(FullInputCmdMessage message)
 {
     _stateManager.InputCommandDispatched(message);
     EntityNetworkManager.SendSystemNetworkMessage(message, message.InputSequence);
 }
Exemple #11
0
        /// <summary>
        ///     Inserts an Input Command into the simulation.
        /// </summary>
        /// <param name="session">Player session that raised the command. On client, this is always the LocalPlayer session.</param>
        /// <param name="function">Function that is being changed.</param>
        /// <param name="message">Arguments for this event.</param>
        public void HandleInputCommand(ICommonSession session, BoundKeyFunction function, FullInputCmdMessage message)
        {
            // set state, state change is updated regardless if it is locally bound
            _cmdStates.SetState(function, message.State);

            // handle local binds before sending off
            if (_bindMap.TryGetHandler(function, out var handler))
            {
                // local handlers can block sending over the network.
                if (handler.HandleCmdMessage(session, message))
                {
                    return;
                }
            }

            RaiseNetworkEvent(message);
        }
Exemple #12
0
        /// <summary>
        ///     Inserts an Input Command into the simulation.
        /// </summary>
        /// <param name="session">Player session that raised the command. On client, this is always the LocalPlayer session.</param>
        /// <param name="function">Function that is being changed.</param>
        /// <param name="message">Arguments for this event.</param>
        public void HandleInputCommand(ICommonSession session, BoundKeyFunction function, FullInputCmdMessage message)
        {
            #if DEBUG
            var funcId = _inputManager.NetworkBindMap.KeyFunctionID(function);
            DebugTools.Assert(funcId == message.InputFunctionId, "Function ID in message does not match function.");
            #endif

            // set state, state change is updated regardless if it is locally bound
            if (_cmdStates.GetState(function) == message.State)
            {
                return;
            }

            _cmdStates.SetState(function, message.State);

            // handle local binds before sending off
            if (_bindMap.TryGetHandler(function, out var handler))
            {
                // local handlers can block sending over the network.
                if (handler.HandleCmdMessage(session, message))
                {
                    return;
                }
            }

            // send it off to the client
            DispatchInputCommand(message);
        }
Exemple #13
0
 private void DispatchInputCommand(FullInputCmdMessage message)
 {
     _stateManager.InputCommandDispatched(message);
     RaiseNetworkEvent(message);
 }
Exemple #14
0
 private void HandleCommandMessage(IPlayerSession session, InputCmdHandler cmdHandler, FullInputCmdMessage msg)
 {
     cmdHandler.HandleCmdMessage(session, msg);
 }