コード例 #1
0
        public override void Update(float frameTime)
        {
            base.Update(frameTime);

            if (!_gameTiming.IsFirstTimePredicted)
            {
                return;
            }

            var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);

            if (!_combatModeSystem.IsInCombatMode() || state != BoundKeyState.Down)
            {
                _shotCounter = 0;
                _blocked     = false;
                return;
            }

            var entity = _playerManager.LocalPlayer?.ControlledEntity;

            if (!EntityManager.TryGetComponent(entity, out SharedHandsComponent? hands))
            {
                return;
            }

            if (!hands.TryGetActiveHeldEntity(out var held) || !EntityManager.TryGetComponent(held, out ClientRangedWeaponComponent? weapon))
            {
                _blocked = true;
                return;
            }

            switch (weapon.FireRateSelector)
            {
            case FireRateSelector.Safety:
                _blocked = true;
                return;

            case FireRateSelector.Single:
                if (_shotCounter >= 1)
                {
                    _blocked = true;
                    return;
                }

                break;

            case FireRateSelector.Automatic:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (_blocked)
            {
                return;
            }

            var worldPos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);

            if (!_mapManager.TryFindGridAt(worldPos, out var grid))
            {
                weapon.SyncFirePos(GridId.Invalid, worldPos.Position);
            }
            else
            {
                weapon.SyncFirePos(grid.Index, grid.MapToGrid(worldPos).Position);
            }
        }
コード例 #2
0
        public override void Update(float frameTime)
        {
            base.Update(frameTime);

            if (!_gameTiming.IsFirstTimePredicted)
            {
                return;
            }

            var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);

            if (!_combatModeSystem.IsInCombatMode() || state != BoundKeyState.Down)
            {
                _shotCounter = 0;
                _blocked     = false;
                return;
            }

            var entity = _playerManager.LocalPlayer?.ControlledEntity;

            if (!EntityManager.TryGetComponent(entity, out SharedHandsComponent? hands))
            {
                return;
            }

            if (hands.ActiveHandEntity is not EntityUid held || !EntityManager.TryGetComponent(held, out ClientRangedWeaponComponent? weapon))
            {
                _blocked = true;
                return;
            }

            switch (weapon.FireRateSelector)
            {
            case FireRateSelector.Safety:
                _blocked = true;
                return;

            case FireRateSelector.Single:
                if (_shotCounter >= 1)
                {
                    _blocked = true;
                    return;
                }

                break;

            case FireRateSelector.Automatic:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (_blocked)
            {
                return;
            }

            var mapCoordinates = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
            EntityCoordinates coordinates;

            if (_mapManager.TryFindGridAt(mapCoordinates, out var grid))
            {
                coordinates = EntityCoordinates.FromMap(grid.GridEntityId, mapCoordinates);
            }
            else
            {
                coordinates = EntityCoordinates.FromMap(_mapManager.GetMapEntityId(mapCoordinates.MapId), mapCoordinates);
            }

            SyncFirePos(coordinates);
        }