コード例 #1
0
 private void OnGetState(EntityUid uid, FlyBySoundComponent component, ref ComponentGetState args)
 {
     args.State = new FlyBySoundComponentState()
     {
         Sound = component.Sound,
         Range = component.Range,
     };
 }
コード例 #2
0
    private void OnShutdown(EntityUid uid, FlyBySoundComponent component, ComponentShutdown args)
    {
        if (!TryComp <PhysicsComponent>(uid, out var body))
        {
            return;
        }

        _fixtures.DestroyFixture(body, FlyByFixture);
    }
コード例 #3
0
    private void OnHandleState(EntityUid uid, FlyBySoundComponent component, ref ComponentHandleState args)
    {
        if (args.Current is not FlyBySoundComponentState state)
        {
            return;
        }

        component.Sound = state.Sound;
        component.Range = state.Range;
    }
コード例 #4
0
    private void OnCollide(EntityUid uid, FlyBySoundComponent component, StartCollideEvent args)
    {
        var attachedEnt = _player.LocalPlayer?.ControlledEntity;

        // If it's not our ent or we shot it.
        if (attachedEnt == null ||
            args.OtherFixture.Body.Owner != attachedEnt ||
            TryComp <ProjectileComponent>(args.OurFixture.Body.Owner, out var projectile) &&
            projectile.Shooter == attachedEnt)
        {
            return;
        }

        if (args.OurFixture.ID != FlyByFixture ||
            !_random.Prob(component.Prob))
        {
            return;
        }

        SoundSystem.Play(component.Sound.GetSound(), Filter.Local(), uid, component.Sound.Params);
    }
コード例 #5
0
    private void OnStartup(EntityUid uid, FlyBySoundComponent component, ComponentStartup args)
    {
        if (!TryComp <PhysicsComponent>(uid, out var body))
        {
            return;
        }

        var shape = new PhysShapeCircle()
        {
            Radius = component.Range,
        };

        var fixture = new Fixture(body, shape)
        {
            Hard           = false,
            ID             = FlyByFixture,
            CollisionLayer = (int)CollisionGroup.MobMask,
        };

        _fixtures.TryCreateFixture(body, fixture);
    }