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 void OnBlockRemoved()
        {
            base.OnBlockRemoved();
            if (renderer != null)
            {
                renderer.Dispose();
                renderer = null;
            }

            ambientSound?.Dispose();
        }
        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();

            if (Api.Side == EnumAppSide.Server)
            {
                ICoreServerAPI sapi = Api as ICoreServerAPI;
                sapi.ModLoader.GetModSystem <TeleporterManager>().DeleteLocation(Pos);
            }

            translocatingSound?.Dispose();
        }
        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;
            }
        }
 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. 6
0
        private void onTrackLoaded(ILoadedSound sound)
        {
            if (track == null)
            {
                sound?.Dispose();
                return;
            }
            if (sound == null)
            {
                return;
            }

            track.Sound = sound;

            // Needed so that the music engine does not dispose the sound
            Api.Event.EnqueueMainThreadTask(() => track.loading = true, "settrackloading");

            long longMsPassed = Api.World.ElapsedMilliseconds - startLoadingMs;

            handlerId = RegisterDelayedCallback((dt) => {
                if (sound.IsDisposed)
                {
                    Api.World.Logger.Notification("Echo chamber track is diposed? o.O");
                }

                if (!wasStopped)
                {
                    sound.Start();
                }

                track.loading = false;
            }, (int)Math.Max(0, 500 - longMsPassed));
        }
        public override void StartClientSide(ICoreClientAPI api)
        {
            capi = api;
            api.Event.RegisterEventBusListener(OnConfigEventClient, 0.5, "configTeleporter");

            clientChannel =
                api.Network.RegisterChannel("tpManager")
                .RegisterMessageType(typeof(TpLocations))
                .RegisterMessageType(typeof(TeleporterLocation))
                .SetMessageHandler <TpLocations>(OnLocationsReceived)
            ;

            if (teleportingSound == null)
            {
                teleportingSound = ((IClientWorldAccessor)api.World).LoadSound(new SoundParams()
                {
                    Location         = new AssetLocation("sounds/block/teleporter.ogg"),
                    ShouldLoop       = true,
                    Position         = null,
                    RelativePosition = true,
                    DisposeOnFinish  = false,
                    Volume           = 1
                });
            }

            api.Event.RegisterGameTickListener(OnClientTick, 50);
            api.Event.LeaveWorld += () => teleportingSound?.Dispose();
        }
Esempio n. 8
0
        public override void OnEntityDespawn(EntityDespawnReason despawn)
        {
            buzzSound?.Stop();
            buzzSound?.Dispose();

            base.OnEntityDespawn(despawn);
        }
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            pouringLoop?.Stop();
            pouringLoop?.Dispose();
            pouringLoop = null;

            slot.MarkDirty();
        }
        public void Dispose()
        {
            potRef?.Dispose();
            lidRef?.Dispose();

            cookingSound?.Stop();
            cookingSound?.Dispose();
        }
 public override void OnBlockRemoved()
 {
     StopMusic();
     if (ambientSound != null)
     {
         ambientSound.Stop();
         ambientSound.Dispose();
     }
 }
 void killAmbientSound()
 {
     if (ambientSound != null)
     {
         ambientSound?.Stop();
         ambientSound?.Dispose();
         ambientSound = null;
     }
 }
        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. 14
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. 15
0
        /// <summary>
        /// Is it cool for the current track to continue playing?
        /// </summary>
        /// <param name="dt">Delta Time/Change in time.</param>
        /// <param name="props">Track properties.</param>
        /// <returns>Cool or not cool?</returns>
        public virtual bool ContinuePlay(float dt, TrackedPlayerProperties props)
        {
            if (!IsActive)
            {
                Sound?.Dispose();
                Sound = null;
                return(false);
            }

            return(docontinue);
        }
Esempio n. 16
0
        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();

            if (ambientSound != null)
            {
                ambientSound?.Stop();
                ambientSound?.Dispose();
                ambientSound = null;
            }
        }
Esempio n. 17
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. 18
0
        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();

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

            renderer?.Dispose();
            renderer = null;
        }
Esempio n. 19
0
        /// <summary>
        /// Begins playing the Music track.
        /// </summary>
        /// <param name="props">Player Properties</param>
        public void BeginPlay(TrackedPlayerProperties props)
        {
            loading = true;
            Sound?.Dispose();

            musicEngine.LoadTrack(Location, (sound) => {
                if (sound != null)
                {
                    sound.Start();

                    if (!loading)
                    {
                        sound.Stop(); sound.Dispose();
                    }
                    else
                    {
                        Sound = sound;
                    }
                }

                loading = false;
            });
        }
        public void Dispose()
        {
            if (rainSounds != null)
            {
                foreach (var val in rainSounds)
                {
                    val?.Dispose();
                }
            }

            hailSound?.Dispose();
            lowTrembleSound?.Dispose();
            windSoundLeafy?.Dispose();
            windSoundLeafless?.Dispose();
        }
        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();

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

            if (renderer != null)
            {
                renderer.Unregister();
                renderer = null;
            }
        }
Esempio n. 22
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. 23
0
        public override void StartClientSide(ICoreClientAPI api)
        {
            capi = api;
            api.Event.RegisterEventBusListener(OnConfigEventClient, 0.5, "configTeleporter");

            clientChannel =
                api.Network.RegisterChannel("tpManager")
                .RegisterMessageType(typeof(TpLocations))
                .RegisterMessageType(typeof(TeleporterLocation))
                .RegisterMessageType(typeof(DidTeleport))
                .SetMessageHandler <TpLocations>(OnLocationsReceived)
                .SetMessageHandler <DidTeleport>(OnTranslocateClient)
            ;


            api.Event.BlockTexturesLoaded += Event_BlockTexturesLoaded;
            api.Event.RegisterGameTickListener(OnClientTick, 50);
            api.Event.LeaveWorld += () => teleportingSound?.Dispose();
        }
Esempio n. 24
0
        private void onTrackLoaded(ILoadedSound sound)
        {
            if (track == null)
            {
                sound?.Dispose();
                return;
            }

            track.Sound = sound;

            long longMsPassed = api.World.ElapsedMilliseconds - startLoadingMs;

            handlerId = RegisterDelayedCallback((dt) => {
                if (!wasStopped)
                {
                    sound.Start();
                }
            }, (int)Math.Max(0, 500 - longMsPassed));
        }
Esempio n. 25
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;
            }
        }
Esempio n. 26
0
        public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.World.Side == EnumAppSide.Client)
            {
                ILoadedSound sound = byEntity.World.Api.ObjectCache["temporalGearSound"] as ILoadedSound;
                sound?.Stop();
                sound?.Dispose();
                //Console.WriteLine("sound stop");
            }

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

            slot.TakeOut(1);
            slot.MarkDirty();

            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;
                ICoreServerAPI sapi = byEntity.World.Api as ICoreServerAPI;

                plr.SetSpawnPosition(new PlayerSpawnPos(byEntity.ServerPos.XYZInt.X, byEntity.ServerPos.XYZInt.Y, byEntity.ServerPos.XYZInt.Z)
                {
                    yaw = byEntity.ServerPos.Yaw, pitch = byEntity.ServerPos.Pitch
                });
            }
        }
Esempio n. 27
0
        public bool TryBeginMilking()
        {
            lastIsMilkingStateTotalMs = entity.World.ElapsedMilliseconds;

            bhmul = entity.GetBehavior <EntityBehaviorMultiply>();
            // Can not be milked when stressed (= caused by aggressive or fleeing emotion states)
            float stressLevel = entity.WatchedAttributes.GetFloat("stressLevel");

            if (stressLevel > 0.1)
            {
                if (entity.World.Api is ICoreClientAPI capi)
                {
                    capi.TriggerIngameError(this, "notready", Lang.Get("Currently too stressed to be milkable"));
                }
                return(false);
            }

            // Can only be milked for 21 days after giving birth
            double daysSinceBirth = Math.Max(0, entity.World.Calendar.TotalDays - bhmul.TotalDaysLastBirth);

            if (bhmul != null && daysSinceBirth >= lactatingDaysAfterBirth)
            {
                return(false);
            }

            // Can only be milked once every day
            if (entity.World.Calendar.TotalHours - lastMilkedTotalHours < entity.World.Calendar.HoursPerDay)
            {
                return(false);
            }
            int generation = entity.WatchedAttributes.GetInt("generation", 0);

            aggroChance = Math.Min(1 - generation / 3f, 0.95f);
            aggroTested = false;
            clientCanContinueMilking = true;


            if (entity.World.Side == EnumAppSide.Server)
            {
                AiTaskManager tmgr = entity.GetBehavior <EntityBehaviorTaskAI>().TaskManager;
                tmgr.StopTask(typeof(AiTaskWander));
                tmgr.StopTask(typeof(AiTaskSeekEntity));
                tmgr.StopTask(typeof(AiTaskSeekFoodAndEat));
                tmgr.StopTask(typeof(AiTaskStayCloseToEntity));
            }
            else
            {
                if (entity.World is IClientWorldAccessor cworld)
                {
                    milkSound?.Dispose();
                    milkSound = cworld.LoadSound(new SoundParams()
                    {
                        DisposeOnFinish = true,
                        Location        = new AssetLocation("sounds/creature/sheep/milking.ogg"),
                        Position        = entity.Pos.XYZFloat,
                        SoundType       = EnumSoundType.Sound
                    });

                    milkSound.Start();
                }
            }

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

            ambientSound?.Dispose();
        }