private void GenPointsMasked(Image <Rgba32> buffer)
            {
                var o      = PointSize - 1;
                var random = new Random(Seed);
                var noise  = new NoiseGenerator(MaskNoiseType);

                noise.SetSeed(MaskSeed);
                noise.SetFrequency(MaskFrequency);
                noise.SetPersistence(MaskPersistence);
                noise.SetLacunarity(MaskLacunarity);
                noise.SetOctaves(MaskOctaves);
                noise.SetPeriodX(buffer.Width);
                noise.SetPeriodY(buffer.Height);

                var threshVal = 1 / (1 - MaskThreshold);
                var powFactor = 1 / MaskPower;

                const int maxPointAttemptCount = 9999;
                var       pointAttemptCount    = 0;

                var span = buffer.GetPixelSpan();

                for (var i = 0; i < PointCount; i++)
                {
                    var x = random.Next(0, buffer.Width);
                    var y = random.Next(0, buffer.Height);

                    // Grab noise at this point.
                    var noiseVal = MathF.Min(1, MathF.Max(0, (noise.GetNoiseTiled(x, y) + 1) / 2));
                    // Threshold
                    noiseVal  = MathF.Max(0, noiseVal - MaskThreshold);
                    noiseVal *= threshVal;
                    noiseVal  = (float)MathF.Pow(noiseVal, powFactor);

                    var randomThresh = random.NextFloat();
                    if (randomThresh > noiseVal)
                    {
                        if (++pointAttemptCount <= maxPointAttemptCount)
                        {
                            i--;
                        }

                        continue;
                    }

                    var dist = random.NextFloat();

                    for (var oy = y - o; oy <= y + o; oy++)
                    {
                        for (var ox = x - o; ox <= x + o; ox++)
                        {
                            var ix = MathHelper.Mod(ox, buffer.Width);
                            var iy = MathHelper.Mod(oy, buffer.Height);

                            var color = Color.InterpolateBetween(FarColor, CloseColor, dist).ConvertImgSharp();
                            span[iy * buffer.Width + ix] = color;
                        }
                    }
                }
            }
示例#2
0
        public void React(IEntity solutionEntity, double intensity)
        {
            float floatIntensity = (float)intensity;

            if (solutionEntity == null)
            {
                return;
            }
            if (!solutionEntity.TryGetComponent(out SolutionComponent solution))
            {
                return;
            }

            //Handle scaling
            if (_scaled)
            {
                floatIntensity = MathF.Min(floatIntensity, _maxScale);
            }
            else
            {
                floatIntensity = 1;
            }

            //Calculate intensities
            int finalDevastationRange = (int)MathF.Round(_devastationRange * floatIntensity);
            int finalHeavyImpactRange = (int)MathF.Round(_heavyImpactRange * floatIntensity);
            int finalLightImpactRange = (int)MathF.Round(_lightImpactRange * floatIntensity);
            int finalFlashRange       = (int)MathF.Round(_flashRange * floatIntensity);

            ExplosionHelper.SpawnExplosion(solutionEntity.Transform.GridPosition, finalDevastationRange,
                                           finalHeavyImpactRange, finalLightImpactRange, finalFlashRange);
        }
示例#3
0
        /// <summary>
        ///     Stuns the entity, disallowing it from doing many interactions temporarily.
        /// </summary>
        /// <param name="seconds">How many seconds the mob will stay stunned</param>
        public void Stun(float seconds)
        {
            seconds = MathF.Min(_stunnedTimer + (seconds * StunTimeModifier), _stunCap);

            if (seconds <= 0f)
            {
                return;
            }

            StandingStateHelper.DropAllItemsInHands(Owner, false);

            _stunnedTimer = seconds;
            _lastStun     = _gameTiming.CurTime;

            SetStatusEffect();
        }
示例#4
0
        /// <summary>
        ///     Knocks down the mob, making it fall to the ground.
        /// </summary>
        /// <param name="seconds">How many seconds the mob will stay on the ground</param>
        public void Knockdown(float seconds)
        {
            seconds = MathF.Min(_knockdownTimer + (seconds * KnockdownTimeModifier), _knockdownCap);

            if (seconds <= 0f)
            {
                return;
            }

            StandingStateHelper.Down(Owner);

            _knockdownTimer = seconds;
            _lastStun       = _gameTiming.CurTime;

            SetStatusEffect();
        }
示例#5
0
        protected override void Draw(DrawingHandleScreen handle)
        {
            Color color;

            var lerp = 1f - MathF.Abs(Progress); // for future bikeshedding purposes

            if (Progress >= 0f)
            {
                var hue = (5f / 18f) * lerp;
                color = Color.FromHsv((hue, 0.75f, 0.75f, 0.50f));
            }
            else
            {
                var alpha = MathF.Clamp(0.5f * lerp, 0f, 0.5f);
                color = new Color(1f, 1f, 1f, alpha);
            }

            _shader.SetParameter("progress", Progress);
            handle.UseShader(_shader);
            handle.DrawRect(PixelSizeBox, color);
        }
            public override void Apply(Image <Rgba32> bitmap)
            {
                var noise = new NoiseGenerator(NoiseType);

                noise.SetSeed(Seed);
                noise.SetFrequency(Frequency);
                noise.SetPersistence(Persistence);
                noise.SetLacunarity(Lacunarity);
                noise.SetOctaves(Octaves);
                noise.SetPeriodX(bitmap.Width);
                noise.SetPeriodY(bitmap.Height);
                var threshVal = 1 / (1 - Threshold);
                var powFactor = 1 / Power;

                var span = bitmap.GetPixelSpan();

                for (var y = 0; y < bitmap.Height; y++)
                {
                    for (var x = 0; x < bitmap.Width; x++)
                    {
                        // Do noise calculations.
                        var noiseVal = MathF.Min(1, MathF.Max(0, (noise.GetNoiseTiled(x, y) + 1) / 2));

                        // Threshold
                        noiseVal  = MathF.Max(0, noiseVal - Threshold);
                        noiseVal *= threshVal;
                        noiseVal  = (float)MathF.Pow(noiseVal, powFactor);

                        // Get colors based on noise values.
                        var srcColor = Color.InterpolateBetween(OuterColor, InnerColor, noiseVal)
                                       .WithAlpha(noiseVal);

                        // Apply blending factors & write back.
                        var i        = y * bitmap.Width + x;
                        var dstColor = span[i].ConvertImgSharp();
                        span[i] = Color.Blend(dstColor, srcColor, DstFactor, SrcFactor).ConvertImgSharp();
                    }
                }
            }
示例#7
0
        /// <summary>
        ///     Slows down the mob's walking/running speed temporarily
        /// </summary>
        /// <param name="seconds">How many seconds the mob will be slowed down</param>
        /// <param name="walkModifierOverride">Walk speed modifier. Set to 0 or negative for default value. (0.5f)</param>
        /// <param name="runModifierOverride">Run speed modifier. Set to 0 or negative for default value. (0.5f)</param>
        public void Slowdown(float seconds, float walkModifierOverride = 0f, float runModifierOverride = 0f)
        {
            seconds = MathF.Min(_slowdownTimer + (seconds * SlowdownTimeModifier), _slowdownCap);

            if (seconds <= 0f)
            {
                return;
            }

            _walkModifierOverride = walkModifierOverride;
            _runModifierOverride  = runModifierOverride;

            _slowdownTimer = seconds;
            _lastStun      = _gameTiming.CurTime;

            if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
            {
                movement.RefreshMovementSpeedModifiers();
            }

            SetStatusEffect();
        }
示例#8
0
        /// <summary>
        ///     Throw an entity at the position of <paramref name="targetLoc"/> from <paramref name="sourceLoc"/>,
        ///     without overshooting.
        /// </summary>
        /// <param name="thrownEnt">The entity to throw.</param>
        /// <param name="throwForceMax">
        /// The MAXIMUM force to throw the entity with.
        /// Throw force increases with distance to target, this is the maximum force allowed.
        /// </param>
        /// <param name="targetLoc">
        /// The target location to throw at.
        /// This function will try to land at this exact spot,
        /// if <paramref name="throwForceMax"/> is large enough to allow for it to be reached.
        /// </param>
        /// <param name="sourceLoc">
        /// The position to start the throw from.
        /// </param>
        /// <param name="spread">
        /// If true, slightly spread the actual throw angle.
        /// </param>
        /// <param name="throwSourceEnt">
        /// The entity that did the throwing. An opposite impulse will be applied to this entity if passed in.
        /// </param>
        public static void ThrowTo(IEntity thrownEnt, float throwForceMax, GridCoordinates targetLoc,
                                   GridCoordinates sourceLoc, bool spread = false, IEntity throwSourceEnt = null)
        {
            var mapManager = IoCManager.Resolve <IMapManager>();
            var timing     = IoCManager.Resolve <IGameTiming>();

            // Calculate the force necessary to land a throw based on throw duration, mass and distance.
            var distance      = (targetLoc.ToMapPos(mapManager) - sourceLoc.ToMapPos(mapManager)).Length;
            var throwDuration = ThrowController.DefaultThrowTime;
            var mass          = 1f;

            if (thrownEnt.TryGetComponent(out PhysicsComponent physicsComponent))
            {
                mass = physicsComponent.Mass;
            }

            var velocityNecessary = distance / throwDuration;
            var impulseNecessary  = velocityNecessary * mass;
            var forceNecessary    = impulseNecessary * (1f / timing.TickRate);

            // Then clamp it to the max force allowed and call Throw().
            Throw(thrownEnt, MathF.Min(forceNecessary, throwForceMax), targetLoc, sourceLoc, spread, throwSourceEnt);
        }