private void OnBoltFireAttempt(EntityUid uid, BoltActionBarrelComponent component, GunFireAttemptEvent args)
    {
        if (args.Cancelled)
        {
            return;
        }

        if (component.BoltOpen || component.ChamberContainer.ContainedEntity == null)
        {
            args.Cancel();
        }
    }
Exemple #2
0
    /// <summary>
    /// Tries to fire a round of ammo out of the weapon.
    /// </summary>
    private void TryFire(EntityUid user, EntityCoordinates targetCoords, ServerRangedWeaponComponent gun)
    {
        if (!TryComp(gun.Owner, out ServerRangedBarrelComponent? barrel))
        {
            return;
        }

        if (!TryComp(user, out HandsComponent? hands) || hands.ActiveHand?.HeldEntity != gun.Owner)
        {
            return;
        }

        if (!TryComp(user, out CombatModeComponent? combat) ||
            !combat.IsInCombatMode ||
            !_blocker.CanInteract(user, gun.Owner))
        {
            return;
        }

        var fireAttempt = new GunFireAttemptEvent(user, gun);

        EntityManager.EventBus.RaiseLocalEvent(gun.Owner, fireAttempt);

        if (fireAttempt.Cancelled)
        {
            return;
        }

        var curTime = _gameTiming.CurTime;
        var span    = curTime - gun.LastFireTime;

        if (span.TotalSeconds < 1 / barrel.FireRate)
        {
            return;
        }

        // TODO: Clumsy should be eventbus I think?

        gun.LastFireTime = curTime;
        var coordinates = Transform(gun.Owner).Coordinates;

        if (gun.ClumsyCheck && EntityManager.TryGetComponent <ClumsyComponent>(user, out var clumsyComponent) && ClumsyComponent.TryRollClumsy(user, gun.ClumsyExplodeChance))
        {
            //Wound them
            _damageable.TryChangeDamage(user, clumsyComponent.ClumsyDamage);
            _stun.TryParalyze(user, TimeSpan.FromSeconds(3f), true);

            // Apply salt to the wound ("Honk!")
            SoundSystem.Play(
                Filter.Pvs(gun.Owner), gun.ClumsyWeaponHandlingSound.GetSound(),
                coordinates, AudioParams.Default.WithMaxDistance(5));

            SoundSystem.Play(
                Filter.Pvs(gun.Owner), gun.ClumsyWeaponShotSound.GetSound(),
                coordinates, AudioParams.Default.WithMaxDistance(5));

            user.PopupMessage(Loc.GetString("server-ranged-weapon-component-try-fire-clumsy"));

            EntityManager.DeleteEntity(gun.Owner);
            return;
        }

        // Firing confirmed

        if (gun.CanHotspot)
        {
            _atmos.HotspotExpose(coordinates, 700, 50);
        }

        EntityManager.EventBus.RaiseLocalEvent(gun.Owner, new GunShotEvent());
        Fire(user, barrel, targetCoords);
    }