Esempio n. 1
0
        public virtual void ToggleAmbientSounds(bool on)
        {
            if (Api.Side != EnumAppSide.Client)
            {
                return;
            }

            if (on)
            {
                if (ambientSound == null || !ambientSound.IsPlaying)
                {
                    ambientSound = ((IClientWorldAccessor)Api.World).LoadSound(new SoundParams()
                    {
                        Location        = new AssetLocation("sounds/environment/fireplace.ogg"),
                        ShouldLoop      = true,
                        Position        = Pos.ToVec3f().Add(0.5f, 0.1f, 0.5f),
                        DisposeOnFinish = false,
                        Volume          = 0.66f
                    });

                    ambientSound.Start();
                }
            }
            else
            {
                ambientSound.Stop();
                ambientSound.Dispose();
                ambientSound = null;
            }
        }
Esempio n. 2
0
 public override bool OnHeldInteractCancel(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason)
 {
     if (api.Side == EnumAppSide.Client)
     {
         sound?.Stop();
         sound = null;
     }
     return(true);
 }
Esempio n. 3
0
        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
        {
            base.FromTreeAttributes(tree, worldForResolving);
            remainingSeconds = tree.GetFloat("remainingSeconds", 0);
            lit = tree.GetInt("lit") > 0;
            ignitedByPlayerUid = tree.GetString("ignitedByPlayerUid");

            if (!lit && Api?.Side == EnumAppSide.Client)
            {
                fuseSound.Stop();
            }
        }
        private void OnClientTick(float dt)
        {
            if (capi.World.ElapsedMilliseconds - lastCollideMsOwnPlayer > 100)
            {
                volume = Math.Max(0, volume - 2 * dt);
            }
            else
            {
                volume = Math.Min(1, volume + dt / 3);
            }

            teleportingSound.SetVolume(volume);

            if (teleportingSound.IsPlaying)
            {
                if (volume <= 0)
                {
                    teleportingSound.Stop();
                }
            }
            else
            {
                if (volume > 0)
                {
                    teleportingSound.Start();
                }
            }
        }
Esempio n. 5
0
        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve)
        {
            base.FromTreeAttributes(tree, worldAccessForResolve);

            bool wasBurning = burning;

            burning             = tree.GetBool("burning");
            burnStartTotalHours = tree.GetDouble("lastTickTotalHours");
            isCokable           = tree.GetBool("isCokable");

            if (!burning)
            {
                if (listenerId != 0)
                {
                    UnregisterGameTickListener(listenerId);
                }
                ambientSound?.Stop();
                listenerId = 0;
            }

            if (Api != null && Api.Side == EnumAppSide.Client && !wasBurning && burning)
            {
                updateBurningState();
            }
        }
 public void SetCookingSoundVolume(float volume)
 {
     if (volume > 0)
     {
         if (cookingSound == null)
         {
             cookingSound = capi.World.LoadSound(new SoundParams()
             {
                 Location        = new AssetLocation("sounds/effect/cooking.ogg"),
                 ShouldLoop      = true,
                 Position        = pos.ToVec3f().Add(0.5f, 0.25f, 0.5f),
                 DisposeOnFinish = false,
                 Volume          = volume
             });
             cookingSound.Start();
         }
         else
         {
             cookingSound.SetVolume(volume);
         }
     }
     else
     {
         if (cookingSound != null)
         {
             cookingSound.Stop();
             cookingSound.Dispose();
             cookingSound = null;
         }
     }
 }
Esempio n. 7
0
        public override void OnEntityDespawn(EntityDespawnReason despawn)
        {
            buzzSound?.Stop();
            buzzSound?.Dispose();

            base.OnEntityDespawn(despawn);
        }
Esempio n. 8
0
        void updateGrindingState()
        {
            if (Api?.World == null)
            {
                return;
            }

            bool nowGrinding = quantityPlayersGrinding > 0 || (automated && mpc.TrueSpeed > 0f);

            if (nowGrinding != beforeGrinding)
            {
                if (renderer != null)
                {
                    renderer.ShouldRotateManual = quantityPlayersGrinding > 0;
                }

                Api.World.BlockAccessor.MarkBlockDirty(Pos, OnRetesselated);

                if (nowGrinding)
                {
                    ambientSound?.Start();
                }
                else
                {
                    ambientSound?.Stop();
                }

                if (Api.Side == EnumAppSide.Server)
                {
                    MarkDirty();
                }
            }

            beforeGrinding = nowGrinding;
        }
        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();
                }
            }
        }
        void updateGrindingState(bool beforeGrinding)
        {
            bool nowGrinding = IsGrinding;

            if (nowGrinding != beforeGrinding)
            {
                if (renderer != null)
                {
                    renderer.ShouldRotate = nowGrinding;
                }

                api.World.BlockAccessor.MarkBlockDirty(pos, OnRetesselated);

                if (nowGrinding)
                {
                    ambientSound?.Start();
                }
                else
                {
                    ambientSound?.Stop();
                }

                if (api.Side == EnumAppSide.Server)
                {
                    MarkDirty();
                }
            }
        }
        private void updateSoundsAndEffects(double hereStability, double ownStability)
        {
            if (!isSelf || tempStabSoundDrain == null)
            {
                return;
            }

            // Effects

            float fadeSpeed = 3f;

            // Sounds

            if (hereStability < 0.95f && ownStability < 0.65f)
            {
                if (!tempStabSoundDrain.IsPlaying)
                {
                    tempStabSoundDrain.Start();
                }

                tempStabSoundDrain.FadeTo(Math.Min(1, 3 * (1 - hereStability)), 0.95f * fadeSpeed, (s) => {  });
            }
            else
            {
                tempStabSoundDrain.FadeTo(0, 0.95f * fadeSpeed, (s) => { tempStabSoundDrain.Stop(); });
            }

            SurfaceMusicTrack.ShouldPlayMusic  = ownStability > 0.45f;
            CaveMusicTrack.ShouldPlayCaveMusic = ownStability > 0.2f;

            if (ownStability < 0.4f)
            {
                if (!tempStabSoundLow.IsPlaying)
                {
                    tempStabSoundLow.Start();
                }

                float volume = (0.4f - (float)ownStability) * 1 / 0.4f;
                tempStabSoundLow.FadeTo(Math.Min(1, volume), 0.95f * fadeSpeed, (s) => {  });
            }
            else
            {
                tempStabSoundLow.FadeTo(0, 0.95f * fadeSpeed, (s) => { tempStabSoundLow.Stop(); });
            }

            if (ownStability < 0.25f)
            {
                if (!tempStabSoundVeryLow.IsPlaying)
                {
                    tempStabSoundVeryLow.Start();
                }

                float volume = (0.25f - (float)ownStability) * 1 / 0.25f;
                tempStabSoundVeryLow.FadeTo(Math.Min(1, volume) / 5f, 0.95f * fadeSpeed, (s) => { });
            }
            else
            {
                tempStabSoundVeryLow.FadeTo(0, 0.95f * fadeSpeed, (s) => { tempStabSoundVeryLow.Stop(); });
            }
        }
        public void ToggleAmbientSounds(bool on)
        {
            if (Api.Side != EnumAppSide.Client)
            {
                return;
            }

            if (on)
            {
                if (ambientSound == null || !ambientSound.IsPlaying)
                {
                    ambientSound = ((IClientWorldAccessor)Api.World).LoadSound(new SoundParams()
                    {
                        Location        = new AssetLocation("sounds/environment/fireplace.ogg"),
                        ShouldLoop      = true,
                        Position        = be.Pos.ToVec3f().Add(0.5f, 0.25f, 0.5f),
                        DisposeOnFinish = false,
                        Volume          = SoundLevel
                    });

                    if (ambientSound != null)
                    {
                        ambientSound.Start();
                        ambientSound.PlaybackPosition = ambientSound.SoundLengthSeconds * (float)Api.World.Rand.NextDouble();
                    }
                }
            }
            else
            {
                ambientSound?.Stop();
                ambientSound?.Dispose();
                ambientSound = null;
            }
        }
Esempio n. 13
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(); });
            }
        }
Esempio n. 14
0
        public bool CanContinueMilking(IPlayer milkingPlayer, float secondsUsed)
        {
            lastIsMilkingStateTotalMs = entity.World.ElapsedMilliseconds;

            if (entity.World.Side == EnumAppSide.Client)
            {
                if (!clientCanContinueMilking)
                {
                    milkSound?.Stop();
                    milkSound?.Dispose();
                }
                else
                {
                    milkSound.SetPosition((float)entity.Pos.X, (float)entity.Pos.Y, (float)entity.Pos.Z);
                }

                return(clientCanContinueMilking);
            }

            if (secondsUsed > 1 && !aggroTested && entity.World.Side == EnumAppSide.Server)
            {
                aggroTested = true;
                if (entity.World.Rand.NextDouble() < aggroChance)
                {
                    entity.GetBehavior <EntityBehaviorEmotionStates>().TryTriggerState("aggressiveondamage", 1);
                    entity.WatchedAttributes.SetFloat("stressLevel", Math.Max(entity.WatchedAttributes.GetFloat("stressLevel"), 0.25f));

                    if (entity.Properties.Sounds.ContainsKey("hurt"))
                    {
                        entity.World.PlaySoundAt(entity.Properties.Sounds["hurt"].Clone().WithPathPrefixOnce("sounds/").WithPathAppendixOnce(".ogg"), entity);
                    }

                    (entity.Api as ICoreServerAPI).Network.SendEntityPacket(milkingPlayer as IServerPlayer, entity.EntityId, 1337);

                    if (entity.World.Api is ICoreClientAPI capi)
                    {
                        capi.TriggerIngameError(this, "notready", Lang.Get("Became stressed from the milking attempt. Not milkable while stressed."));
                    }

                    return(false);
                }
            }



            return(true);
        }
Esempio n. 15
0
 public override void OnBlockRemoved()
 {
     base.OnBlockRemoved();
     if (fuseSound != null)
     {
         fuseSound.Stop();
     }
 }
        public void Dispose()
        {
            potRef?.Dispose();
            lidRef?.Dispose();

            cookingSound?.Stop();
            cookingSound?.Dispose();
        }
Esempio n. 17
0
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            pouringLoop?.Stop();
            pouringLoop?.Dispose();
            pouringLoop = null;

            slot.MarkDirty();
        }
 void killAmbientSound()
 {
     if (ambientSound != null)
     {
         ambientSound?.Stop();
         ambientSound?.Dispose();
         ambientSound = null;
     }
 }
Esempio n. 19
0
        public void FastForward(float seconds)
        {
            if (Sound.PlaybackPosition + seconds > Sound.SoundLengthSeconds)
            {
                Sound.Stop();
            }

            Sound.PlaybackPosition += seconds;
        }
 public override void OnBlockRemoved()
 {
     StopMusic();
     if (ambientSound != null)
     {
         ambientSound.Stop();
         ambientSound.Dispose();
     }
 }
        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();

            if (Api.Side == EnumAppSide.Server)
            {
                Api.World.UnregisterCallback(coolingCallback);
            }
            else
            {
                Api.World.UnregisterGameTickListener(particlesListener);

                if (smoulderSound != null)
                {
                    smoulderSound.Stop();
                    smoulderSound.Dispose();
                }
            }
        }
Esempio n. 22
0
        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();

            if (ambientSound != null)
            {
                ambientSound?.Stop();
                ambientSound?.Dispose();
                ambientSound = null;
            }
        }
Esempio n. 23
0
        public override bool OnHeldInteractCancel(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason)
        {
            if (byEntity.World.Side == EnumAppSide.Client)
            {
                ILoadedSound sound = ObjectCacheUtil.TryGet <ILoadedSound>(api, "temporalGearSound");
                sound?.Stop();
                sound?.Dispose();
            }

            return(true);
        }
Esempio n. 24
0
        public override bool OnHeldInteractCancel(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason)
        {
            if (byEntity.World.Side == EnumAppSide.Client)
            {
                ILoadedSound sound = byEntity.World.Api.ObjectCache["temporalGearSound"] as ILoadedSound;
                sound?.Stop();
                sound?.Dispose();
                // Console.WriteLine("sound stop");
            }

            return(true);
        }
Esempio n. 25
0
        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();

            if (ambientSound != null)
            {
                ambientSound.Stop();
                ambientSound.Dispose();
            }

            renderer?.Dispose();
            renderer = null;
        }
        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();

            if (ambientSound != null)
            {
                ambientSound.Stop();
                ambientSound.Dispose();
            }

            if (renderer != null)
            {
                renderer.Unregister();
                renderer = null;
            }
        }
Esempio n. 27
0
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.World.Side == EnumAppSide.Client)
            {
                ILoadedSound sound = ObjectCacheUtil.TryGet <ILoadedSound>(api, "temporalGearSound");
                sound?.Stop();
                sound?.Dispose();
            }

            if (blockSel == null || secondsUsed < 3.45)
            {
                return;
            }

            slot.TakeOut(1);
            slot.MarkDirty();
            //(byEntity as EntityPlayer)?.Player?.InventoryManager.BroadcastHotbarSlot();

            if (byEntity.World.Side == EnumAppSide.Client)
            {
                byEntity.World.PlaySoundAt(new AssetLocation("sounds/effect/portal.ogg"), byEntity, null, false);

                particlesHeld.MinSize     = 0.25f;
                particlesHeld.MaxSize     = 0.5f;
                particlesHeld.MinQuantity = 300;
                Vec3d pos = blockSel.Position.ToVec3d().Add(blockSel.HitPosition);
                SpawnParticles(byEntity.World, pos, true);
            }

            if (byEntity.World.Side == EnumAppSide.Server && byEntity is EntityPlayer)
            {
                IServerPlayer plr = byEntity.World.PlayerByUid((byEntity as EntityPlayer).PlayerUID) as IServerPlayer;

                int uses = api.World.Config.GetString("temporalGearRespawnUses", "-1").ToInt();
                plr.SetSpawnPosition(new PlayerSpawnPos()
                {
                    x             = byEntity.ServerPos.XYZInt.X,
                    y             = byEntity.ServerPos.XYZInt.Y,
                    z             = byEntity.ServerPos.XYZInt.Z,
                    yaw           = byEntity.ServerPos.Yaw,
                    pitch         = byEntity.ServerPos.Pitch,
                    RemainingUses = uses
                });
            }
        }
Esempio n. 28
0
        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve)
        {
            base.FromTreeAttributes(tree, worldAccessForResolve);

            burning             = tree.GetBool("burning");
            burnStartTotalHours = tree.GetDouble("lastTickTotalHours");
            isCokable           = tree.GetBool("isCokable");

            if (!burning)
            {
                if (listenerId != 0)
                {
                    UnregisterGameTickListener(listenerId);
                }
                ambientSound?.Stop();
                listenerId = 0;
            }
        }
Esempio n. 29
0
        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
        {
            base.FromTreeAttributes(tree, worldForResolving);

            bloomeryInv.FromTreeAttributes(tree);
            burning = tree.GetInt("burning") > 0;
            burningUntilTotalDays = tree.GetDouble("burningUntilTotalDays");
            burningStartTotalDays = tree.GetDouble("burningStartTotalDays");

            if (burning)
            {
                ambientSound?.Start();
            }
            else
            {
                ambientSound?.Stop();
            }
        }
Esempio n. 30
0
        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();

            if (ambientSound != null)
            {
                ambientSound.Stop();
                ambientSound.Dispose();
            }

            renderer?.Dispose();
            renderer = null;

            if (clientDialog != null)
            {
                clientDialog.TryClose();
                clientDialog?.Dispose();
                clientDialog = null;
            }
        }