Exemplo n.º 1
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null || !(byEntity is EntityPlayer))
            {
                return(false);
            }

            FpHandTransform.Rotation.Y = GameMath.Mod(byEntity.World.ElapsedMilliseconds / (50f - secondsUsed * 20), 360);
            TpHandTransform.Rotation.Y = GameMath.Mod(byEntity.World.ElapsedMilliseconds / (50f - secondsUsed * 20), 360);

            if (byEntity.World is IClientWorldAccessor)
            {
                particlesHeld.MinQuantity = 1;

                Vec3d pos = blockSel.Position.ToVec3d().Add(blockSel.HitPosition);
                SpawnParticles(byEntity.World, pos, false);

                (byEntity.World as IClientWorldAccessor).AddCameraShake(0.035f);


                ILoadedSound sound = ObjectCacheUtil.TryGet <ILoadedSound>(api, "temporalGearSound");
                sound?.SetPitch(0.7f + secondsUsed / 4);
            }

            return(secondsUsed < 3.5);
        }
        private void OnClientTick(float dt)
        {
            if (capi.World.ElapsedMilliseconds - lastTeleCollideMsOwnPlayer > 100)
            {
                teleVolume = Math.Max(0, teleVolume - 2 * dt);
            }
            else
            {
                teleVolume = Math.Min(0.5f, teleVolume + dt / 3);
            }

            teleportingSound.SetVolume(teleVolume);

            if (teleportingSound.IsPlaying)
            {
                if (teleVolume <= 0)
                {
                    teleportingSound.Stop();
                }
            }
            else
            {
                if (teleVolume > 0)
                {
                    teleportingSound.Start();
                }
            }



            if (capi.World.ElapsedMilliseconds - lastTranslocateCollideMsOwnPlayer > 200)
            {
                translocVolume = Math.Max(0, translocVolume - 2 * dt);
                translocPitch  = Math.Max(translocPitch - dt, 0.5f);
            }
            else
            {
                translocVolume = Math.Min(0.5f, translocVolume + dt / 3);
                translocPitch  = Math.Min(translocPitch + dt / 3, 2.5f);
                capi.World.ShakeCamera(0.0575f);
            }

            translocatingSound.SetVolume(translocVolume);
            translocatingSound.SetPitch(translocPitch);

            if (translocatingSound.IsPlaying)
            {
                if (translocVolume <= 0)
                {
                    translocatingSound.Stop();
                }
            }
            else
            {
                if (translocVolume > 0)
                {
                    translocatingSound.Start();
                }
            }
        }
Exemplo n.º 3
0
        public void UpdateBreakSounds()
        {
            if (Api.Side != EnumAppSide.Client)
            {
                return;
            }

            if (resistance > 0 && bebrake.Engaged && network != null && network.Speed > 0.1)
            {
                if (brakeSound == null || !brakeSound.IsPlaying)
                {
                    brakeSound = ((IClientWorldAccessor)Api.World).LoadSound(new SoundParams()
                    {
                        Location        = new AssetLocation("sounds/effect/woodgrind.ogg"),
                        ShouldLoop      = true,
                        Position        = Position.ToVec3f().Add(0.5f, 0.25f, 0.5f),
                        DisposeOnFinish = false,
                        Volume          = 1
                    });

                    brakeSound.Start();
                }

                brakeSound.SetPitch(GameMath.Clamp(network.Speed * 1.5f + 0.2f, 0.5f, 1));
            }
            else
            {
                brakeSound?.FadeOut(1, (s) => { brakeSound.Stop(); });
            }
        }
Exemplo n.º 4
0
        private void Every100ms(float dt)
        {
            float grindSpeed = GrindSpeed;

            if (Api.Side == EnumAppSide.Client)
            {
                if (InputStack != null)
                {
                    float dustMinQ      = 1 * grindSpeed;
                    float dustAddQ      = 5 * grindSpeed;
                    float flourPartMinQ = 1 * grindSpeed;
                    float flourPartAddQ = 20 * grindSpeed;

                    FlourDustParticles.Color       = FlourParticles.Color = InputStack.Collectible.GetRandomColor(Api as ICoreClientAPI, InputStack);
                    FlourDustParticles.Color      &= 0xffffff;
                    FlourDustParticles.Color      |= (200 << 24);
                    FlourDustParticles.MinQuantity = dustMinQ;
                    FlourDustParticles.AddQuantity = dustAddQ;
                    FlourDustParticles.MinPos.Set(Pos.X - 1 / 32f, Pos.Y + 11 / 16f, Pos.Z - 1 / 32f);
                    FlourDustParticles.MinVelocity.Set(-0.1f, 0, -0.1f);
                    FlourDustParticles.AddVelocity.Set(0.2f, 0.2f, 0.2f);

                    FlourParticles.MinPos.Set(Pos.X - 1 / 32f, Pos.Y + 11 / 16f, Pos.Z - 1 / 32f);
                    FlourParticles.AddQuantity = flourPartAddQ;
                    FlourParticles.MinQuantity = flourPartMinQ;

                    Api.World.SpawnParticles(FlourParticles);
                    Api.World.SpawnParticles(FlourDustParticles);
                }

                if (ambientSound != null && automated)
                {
                    ambientSound.SetPitch((0.5f + mpc.TrueSpeed) * 0.9f);
                    ambientSound.SetVolume(Math.Min(1f, mpc.TrueSpeed * 3f));
                }

                return;
            }


            // Only tick on the server and merely sync to client

            // Use up fuel
            if (CanGrind() && grindSpeed > 0)
            {
                inputGrindTime += dt * grindSpeed;

                if (inputGrindTime >= maxGrindingTime())
                {
                    grindInput();
                    inputGrindTime = 0;
                }

                MarkDirty();
            }
        }
        protected virtual void HandleSoundClient(float dt)
        {
            var  capi             = Api as ICoreClientAPI;
            bool ownTranslocate   = !(capi.World.ElapsedMilliseconds - lastOwnPlayerCollideMs > 200);
            bool otherTranslocate = !(capi.World.ElapsedMilliseconds - lastEntityCollideMs > 200);

            if (ownTranslocate || otherTranslocate)
            {
                translocVolume = Math.Min(0.5f, translocVolume + dt / 3);
                translocPitch  = Math.Min(translocPitch + dt / 3, 2.5f);
                if (ownTranslocate)
                {
                    capi.World.AddCameraShake(0.0575f);
                }
            }
            else
            {
                translocVolume = Math.Max(0, translocVolume - 2 * dt);
                translocPitch  = Math.Max(translocPitch - dt, 0.5f);
            }


            if (translocatingSound.IsPlaying)
            {
                translocatingSound.SetVolume(translocVolume);
                translocatingSound.SetPitch(translocPitch);
                if (translocVolume <= 0)
                {
                    translocatingSound.Stop();
                }
            }
            else
            {
                if (translocVolume > 0)
                {
                    translocatingSound.Start();
                }
            }
        }
Exemplo n.º 6
0
        protected virtual void HandleSoundClient(float dt)
        {
            var capi = Api as ICoreClientAPI;

            long msEllapsed = capi.World.ElapsedMilliseconds - lastEntityCollideMs;

            if (msEllapsed > 100)
            {
                teleSoundVolume = Math.Max(0, teleSoundVolume - 2 * dt);
                teleSoundPitch  = Math.Max(0.7f, teleSoundPitch - 2 * dt);
            }
            else
            {
                teleSoundVolume = Math.Min(0.5f, teleSoundVolume + dt / 3);
                teleSoundPitch  = Math.Min(6, teleSoundPitch + dt);
            }

            if (teleportingSound != null)
            {
                teleportingSound.SetVolume(teleSoundVolume);
                teleportingSound.SetPitch(teleSoundPitch);

                if (teleportingSound.IsPlaying)
                {
                    if (teleSoundVolume <= 0)
                    {
                        teleportingSound.Stop();
                    }
                }
                else
                {
                    if (teleSoundVolume > 0)
                    {
                        teleportingSound.Start();
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void updateSounds(float dt)
        {
            float targetRainVolumeLeafy    = 0;
            float targetRainVolumeLeafless = 0;
            float targetHailVolume         = 0;
            float targetTrembleVolume      = 0;

            float targetRainPitch = 1;
            float targetHailPitch = 1;

            WeatherDataSnapshot weatherData = weatherSys.BlendedWeatherData;

            if (searchComplete)
            {
                EntityPlayer eplr = capi.World.Player.Entity;
                plrPos.Set((int)eplr.Pos.X, (int)eplr.Pos.Y, (int)eplr.Pos.Z);
                searchComplete = false;

                TyronThreadPool.QueueTask(() =>
                {
                    float val           = (float)Math.Pow(Math.Max(0, (capi.World.BlockAccessor.GetDistanceToRainFall(plrPos, 12, 4) - 2) / 10f), 2);
                    roomVolumePitchLoss = GameMath.Clamp(val, 0, 1);
                    searchComplete      = true;
                });
            }

            EnumPrecipitationType precType = weatherData.BlendedPrecType;

            if (precType == EnumPrecipitationType.Auto)
            {
                precType = weatherSys.clientClimateCond?.Temperature < weatherData.snowThresholdTemp ? EnumPrecipitationType.Snow : EnumPrecipitationType.Rain;
            }

            float nearbyLeaviness = GameMath.Clamp(GlobalConstants.CurrentNearbyRelLeavesCountClient * 60, 0, 1);

            ClimateCondition conds = weatherSys.clientClimateCond;

            if (conds.Rainfall > 0)
            {
                if (precType == EnumPrecipitationType.Rain || weatherSys.clientClimateCond.Temperature < weatherData.snowThresholdTemp)
                {
                    targetRainVolumeLeafy = nearbyLeaviness * GameMath.Clamp(conds.Rainfall * 2f - Math.Max(0, 2f * (weatherData.snowThresholdTemp - weatherSys.clientClimateCond.Temperature)), 0, 1);
                    targetRainVolumeLeafy = GameMath.Max(0, targetRainVolumeLeafy - roomVolumePitchLoss);

                    targetRainVolumeLeafless = Math.Max(0.3f, 1 - nearbyLeaviness) * GameMath.Clamp(conds.Rainfall * 2f - Math.Max(0, 2f * (weatherData.snowThresholdTemp - weatherSys.clientClimateCond.Temperature)), 0, 1);
                    targetRainVolumeLeafless = GameMath.Max(0, targetRainVolumeLeafless - roomVolumePitchLoss);

                    targetRainPitch = Math.Max(0.7f, 1.25f - conds.Rainfall * 0.7f);
                    targetRainPitch = Math.Max(0, targetRainPitch - roomVolumePitchLoss / 4f);

                    targetTrembleVolume = GameMath.Clamp(conds.Rainfall * 1.6f - 0.8f - roomVolumePitchLoss * 0.25f, 0, 1);

                    if (!rainSoundsOn && (targetRainVolumeLeafy > 0.01 || targetRainVolumeLeafless > 0.01))
                    {
                        for (int i = 0; i < rainSoundsLeafless.Length; i++)
                        {
                            rainSoundsLeafless[i]?.Start();
                        }
                        for (int i = 0; i < rainSoundsLeafy.Length; i++)
                        {
                            rainSoundsLeafy[i]?.Start();
                        }

                        lowTrembleSound?.Start();
                        rainSoundsOn = true;

                        curRainPitch = targetRainPitch;
                    }

                    if (capi.World.Player.Entity.IsEyesSubmerged())
                    {
                        curRainPitch              = targetRainPitch / 2;
                        targetRainVolumeLeafy    *= 0.75f;
                        targetRainVolumeLeafless *= 0.75f;
                    }
                }

                if (precType == EnumPrecipitationType.Hail)
                {
                    targetHailVolume = GameMath.Clamp(conds.Rainfall * 2f - roomVolumePitchLoss, 0, 1);
                    targetHailVolume = GameMath.Max(0, targetHailVolume - roomVolumePitchLoss);

                    targetHailPitch = Math.Max(0.7f, 1.25f - conds.Rainfall * 0.7f);
                    targetHailPitch = Math.Max(0, targetHailPitch - roomVolumePitchLoss / 4f);

                    if (!hailSoundsOn && targetHailVolume > 0.01)
                    {
                        hailSound?.Start();
                        hailSoundsOn = true;
                        curHailPitch = targetHailPitch;
                    }
                }
            }


            curRainVolumeLeafy    += (targetRainVolumeLeafy - curRainVolumeLeafy) * dt / 2;
            curRainVolumeLeafless += (targetRainVolumeLeafless - curRainVolumeLeafless) * dt / 2;

            curTrembleVolume += (targetTrembleVolume - curTrembleVolume) * dt;
            curHailVolume    += (targetHailVolume - curHailVolume) * dt;

            curHailPitch += (targetHailPitch - curHailPitch) * dt;
            curRainPitch += (targetRainPitch - curRainPitch) * dt;



            if (rainSoundsOn)
            {
                for (int i = 0; i < rainSoundsLeafless.Length; i++)
                {
                    rainSoundsLeafless[i]?.SetVolume(curRainVolumeLeafless);
                    rainSoundsLeafless[i]?.SetPitch(curRainPitch);
                }
                for (int i = 0; i < rainSoundsLeafy.Length; i++)
                {
                    rainSoundsLeafy[i]?.SetVolume(curRainVolumeLeafy);
                    rainSoundsLeafy[i]?.SetPitch(curRainPitch);
                }

                lowTrembleSound?.SetVolume(curTrembleVolume);
            }
            if (hailSoundsOn)
            {
                hailSound?.SetVolume(curHailVolume);
                hailSound?.SetPitch(curHailPitch);
            }


            if (curRainVolumeLeafless < 0.01 && curRainVolumeLeafy < 0.01)
            {
                for (int i = 0; i < rainSoundsLeafless.Length; i++)
                {
                    rainSoundsLeafless[i]?.Stop();
                }
                for (int i = 0; i < rainSoundsLeafy.Length; i++)
                {
                    rainSoundsLeafy[i]?.Stop();
                }
                rainSoundsOn = false;
            }

            if (curHailVolume < 0.01)
            {
                hailSound?.Stop();
                hailSoundsOn = false;
            }



            float wstr = (1 - roomVolumePitchLoss) * weatherData.curWindSpeed.X - 0.3f;

            if (wstr > 0.03f || curWindVolumeLeafy > 0.01f || curWindVolumeLeafless > 0.01f)
            {
                if (!windSoundsOn)
                {
                    windSoundLeafy?.Start();
                    windSoundLeafless?.Start();
                    windSoundsOn = true;
                }

                float targetVolumeLeafy    = nearbyLeaviness * 1.2f * wstr;
                float targetVolumeLeafless = (1 - nearbyLeaviness) * 1.2f * wstr;

                curWindVolumeLeafy    += (targetVolumeLeafy - curWindVolumeLeafy) * dt;
                curWindVolumeLeafless += (targetVolumeLeafless - curWindVolumeLeafless) * dt;

                windSoundLeafy?.SetVolume(curWindVolumeLeafy);
                windSoundLeafless?.SetVolume(curWindVolumeLeafless);
            }
            else
            {
                if (windSoundsOn)
                {
                    windSoundLeafy?.Stop();
                    windSoundLeafless?.Stop();
                    windSoundsOn = false;
                }
            }
        }