Example #1
0
        private void onClientTick(float dt)
        {
            if (!riftsEnabled)
            {
                return;
            }

            Vec3d plrPos = capi.World.Player.Entity.Pos.XYZ;

            nearestRifts = rifts.OrderBy(rift => rift.Position.SquareDistanceTo(plrPos)).ToArray();

            for (int i = 0; i < Math.Min(4, nearestRifts.Length); i++)
            {
                Rift         rift  = nearestRifts[i];
                ILoadedSound sound = riftSounds[i];
                if (!sound.IsPlaying)
                {
                    sound.Start();
                    sound.PlaybackPosition = sound.SoundLengthSeconds * (float)capi.World.Rand.NextDouble();
                }

                sound.SetVolume(GameMath.Clamp(rift.GetNowSize(capi) / 3f, 0.1f, 1f));
                sound.SetPosition((float)rift.Position.X, (float)rift.Position.Y, (float)rift.Position.Z);
            }

            for (int i = nearestRifts.Length; i < 4; i++)
            {
                if (riftSounds[i].IsPlaying)
                {
                    riftSounds[i].Stop();
                }
            }
        }
Example #2
0
        public override void OnGameTick(float dt)
        {
            if (soundpos != null)
            {
                soundpos.X = (float)Pos.X;
                soundpos.Y = (float)Pos.Y;
                soundpos.Z = (float)Pos.Z;
                buzzSound.SetPosition(soundpos);
            }

            base.OnGameTick(dt);
        }
Example #3
0
        public override void OnGameTick(float dt)
        {
            base.OnGameTick(dt);

            if (alarmSound != null && alarmSound.IsPlaying)
            {
                alarmSound.SetPosition((float)Pos.X, (float)Pos.Y, (float)Pos.Z);

                if (!Alive)
                {
                    alarmSound.FadeOutAndStop(0.25f);
                }
            }
        }
Example #4
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);
        }
        /// <summary>
        /// Delays behaviors from ticking to reduce flickering
        /// </summary>
        /// <param name="dt"></param>
        public override void OnGameTick(float dt)
        {
            // (1 - 0.95^(x/100)) / 2
            // http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIoMS0wLjk1Xih4LzEwMCkpLzIiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjEwMDAsIndpbmRvdyI6WyIwIiwiMzAwMCIsIjAiLCIxIl19XQ--
            if (physicsBh != null)
            {
                physicsBh.clientPhysicsTickTimeThreshold = (float)((1 - Math.Pow(0.95, particleSys.ActiveFallingBlocks / 100.0)) / 4.0);
            }

            if (soundStartDelay > 0)
            {
                soundStartDelay -= dt;
                if (soundStartDelay <= 0)
                {
                    sound.Start();
                }
            }
            if (sound != null)
            {
                sound.SetPosition((float)Pos.X, (float)Pos.Y, (float)Pos.Z);
            }


            if (lingerTicks > 0)
            {
                lingerTicks--;
                if (lingerTicks == 0)
                {
                    if (Api.Side == EnumAppSide.Client && sound != null)
                    {
                        sound.FadeOut(3f, (s) => { s.Dispose(); });
                    }
                    Die();
                }

                return;
            }

            if (!Collided && !fallHandled)
            {
                nowDustIntensity = 1;
                //spawnParticles(0);
            }
            else
            {
                nowDustIntensity = 0;
            }


            ticksAlive++;
            if (ticksAlive >= 2 || Api.World.Side == EnumAppSide.Client) // Seems like we have to do it instantly on the client, otherwise we miss the OnChunkRetesselated Event
            {
                if (!InitialBlockRemoved)
                {
                    InitialBlockRemoved = true;
                    UpdateBlock(true, initialPos);
                }

                foreach (EntityBehavior behavior in SidedProperties.Behaviors)
                {
                    behavior.OnGameTick(dt);
                }
            }

            pushaccum    += dt;
            fallMotion.X *= 0.99f;
            fallMotion.Z *= 0.99f;
            if (pushaccum > 0.2f)
            {
                pushaccum = 0;
                if (!Collided)
                {
                    Entity[] entities = World.GetEntitiesAround(SidedPos.XYZ, 1.1f, 1.1f, (e) => !(e is EntityBlockFalling));
                    for (int i = 0; i < entities.Length; i++)
                    {
                        if (Api.Side == EnumAppSide.Server || entities[i] is EntityPlayer)
                        {
                            entities[i].SidedPos.Motion.Add(fallMotion.X / 10f, 0, fallMotion.Z / 10f);
                        }
                    }
                }
            }


            if (Api.Side == EnumAppSide.Server && !Collided && World.Rand.NextDouble() < 0.01)
            {
                World.BlockAccessor.TriggerNeighbourBlockUpdate(ServerPos.AsBlockPos);
            }

            if (CollidedVertically && Pos.Motion.Length() == 0)
            {
                OnFallToGround(0);
            }
        }
Example #6
0
        /// <summary>
        /// Delays behaviors from ticking to reduce flickering
        /// </summary>
        /// <param name="dt"></param>
        public override void OnGameTick(float dt)
        {
            if (soundStartDelay > 0)
            {
                soundStartDelay -= dt;
                if (soundStartDelay <= 0)
                {
                    sound.Start();
                }
            }
            if (sound != null)
            {
                sound.SetPosition((float)Pos.X, (float)Pos.Y, (float)Pos.Z);
            }


            if (lingerTicks > 0)
            {
                lingerTicks--;
                if (lingerTicks == 0)
                {
                    if (Api.Side == EnumAppSide.Client && sound != null)
                    {
                        sound.FadeOut(3f, (s) => { s.Dispose(); });
                    }
                    Die();
                }

                return;
            }

            if (!Collided && !fallHandled)
            {
                spawnParticles(0);
            }


            ticksAlive++;
            if (ticksAlive >= 2 || Api.World.Side == EnumAppSide.Client) // Seems like we have to do it instantly on the client, otherwise we miss the OnChunkRetesselated Event
            {
                if (!InitialBlockRemoved)
                {
                    InitialBlockRemoved = true;
                    UpdateBlock(true, initialPos);
                }

                foreach (EntityBehavior behavior in SidedProperties.Behaviors)
                {
                    behavior.OnGameTick(dt);
                }
            }

            pushaccum    += dt;
            fallMotion.X *= 0.99f;
            fallMotion.Z *= 0.99f;
            if (pushaccum > 0.2f)
            {
                pushaccum = 0;
                if (!Collided)
                {
                    Entity[] entities = World.GetEntitiesAround(LocalPos.XYZ, 1.1f, 1.1f, (e) => !(e is EntityBlockFalling));
                    for (int i = 0; i < entities.Length; i++)
                    {
                        if (Api.Side == EnumAppSide.Server || entities[i] is EntityPlayer)
                        {
                            entities[i].LocalPos.Motion.Add(fallMotion.X / 10f, 0, fallMotion.Z / 10f);
                        }
                    }
                }
            }


            if (Api.Side == EnumAppSide.Server && !Collided && World.Rand.NextDouble() < 0.01)
            {
                World.BlockAccessor.TriggerNeighbourBlockUpdate(ServerPos.AsBlockPos);
            }

            if (CollidedVertically && Pos.Motion.Length() == 0)
            {
                OnFallToGround(0);
            }
        }