Exemplo n.º 1
0
        private static Ambush CreateRandomWorldAmbush(int maxAttempts)
        {
            int           attempts = 0;
            int           randTileX, randTileY;
            UnifiedRandom rand = TmlHelpers.SafelyGetRand();

            do
            {
                randTileX = rand.Next(64, Main.maxTilesX - 64);
                randTileY = rand.Next((int)Main.worldSurface, Main.maxTilesY - 220);

                if (Ambush.CheckForAmbushElegibility(randTileX, randTileY))
                {
                    break;
                }
            } while(attempts++ < maxAttempts);

            if (attempts >= maxAttempts)
            {
                return(null);
            }

            Ambush.AdjustAmbushTileCenter(randTileX, ref randTileY);
            return(Ambush.CreateRandomType(randTileX, randTileY));
        }
Exemplo n.º 2
0
        ////

        private bool RunBloom()
        {
            if (this.Cooldown++ > 20)
            {
                this.Cooldown = 0;
            }
            else
            {
                return(false);
            }

            int           nearby;
            UnifiedRandom rand = TmlHelpers.SafelyGetRand();

            foreach (BrambleBloomTendril tendril in this.Tendrils.ToArray())
            {
                if (tendril.IsSplit())
                {
                    this.Tendrils.Add(tendril.CloneAsSplit());
                }

                (int x, int y)growAt = tendril.Grow();
                nearby = this.CountBramblesNear(growAt.x, growAt.y) + 1;

                if (nearby <= 1 || rand.NextFloat() < (1f - ((float)nearby / 10f)))
                {
                    CursedBrambleTile.CreateBrambleAt(growAt.x, growAt.y);
                }
            }

            return(true);
        }
        public static ElementDefinition PickDefinitionForNPC(float chanceForAny)
        {
            UnifiedRandom rand = TmlHelpers.SafelyGetRand();

            if (rand.NextFloat() > chanceForAny)
            {
                return(null);
            }

            var   elements    = ElementsConfig.Instance.Elements;
            float totalWeight = ElementDefinition.GetTotalElementNPCAutoAssignWeight();
            float weight      = rand.NextFloat() * totalWeight;

            float countedWeights = 0f;

            for (int i = 0; i < elements.Count; i++)
            {
                countedWeights += elements[i].AutoAssignNPCWeight;
                if (weight < countedWeights)
                {
                    return(elements[i]);
                }
            }

            return(null);
        }
        ////

        private static ChestImplanterDefinition GetRandomImplanterFromSet(ChestImplanterSetDefinition setDef)
        {
            if (setDef.Value.Count == 0)
            {
                return(null);
            }

            UnifiedRandom rand           = TmlHelpers.SafelyGetRand();
            float         totalWeight    = setDef.TotalWeight();
            float         randPick       = rand.NextFloat() * totalWeight;
            float         countedWeights = 0;

            for (int i = 0; i < setDef.Value.Count; i++)
            {
                countedWeights += setDef.Value[i].Value.Weight;

                if (countedWeights > randPick)
                {
                    return(setDef.Value[i].Value);
                }
            }

            LogHelpers.Warn("Could not randomly pick from implanter set. Total weight " + countedWeights + " of " + setDef.Value.Count + " implanters.");
            return(null);
        }
Exemplo n.º 5
0
        ////

        protected override Ambush CloneRandomized(int tileX, int tileY)
        {
            bool isEntrapping = AmbushesMod.Config.AmbushEntrapmentOdds <= 0
                                ? false
                                : TmlHelpers.SafelyGetRand().Next(AmbushesMod.Config.AmbushEntrapmentOdds) == 0;

            isEntrapping = isEntrapping && !WorldHelpers.IsWithinUnderworld(new Vector2(tileX << 4, tileY << 4));

            return(new FlyerSwarmAmbush(tileX, tileY, isEntrapping));
        }
Exemplo n.º 6
0
        public static bool ErodeRandomBrambleWithinRadius(int tileX, int tileY, int radius)
        {
            radius += AmbushesMod.Config.BrambleThickness;

            int randX     = TmlHelpers.SafelyGetRand().Next(radius * 2);
            int randY     = TmlHelpers.SafelyGetRand().Next(radius * 2);
            int randTileX = tileX + (randX - radius);
            int randTileY = tileY + (randY - radius);

            return(CursedBrambleTile.RemoveBrambleAt(randTileX, randTileY));
        }
Exemplo n.º 7
0
        ////////////////

        private Vector2 GetDirection()
        {
            float variance = (TmlHelpers.SafelyGetRand().NextFloat() * 180f) - 90f;

            this.CurrentDegrees  = this.CurrentDegrees + variance;
            this.CurrentDegrees += this.InitialDegrees;
            this.CurrentDegrees *= 0.5f;

            float radians = MathHelper.ToRadians(this.CurrentDegrees);

            return(new Vector2((float)Math.Cos(radians), (float)Math.Sin(radians)));
        }
        private static int GetImplantQuantity(ChestImplanterItemDefinition info)
        {
            int range = info.MaxQuantity - info.MinQuantity;

            if (range == 0)
            {
                return(info.MinQuantity);
            }

            UnifiedRandom rand = TmlHelpers.SafelyGetRand();

            return(info.MinQuantity + rand.Next(range));
        }
        ////////////////

        public static Ambush CreateRandomType(int tileX, int tileY)
        {
            float  rand       = TmlHelpers.SafelyGetRand().NextFloat() * (float)Ambush.TotalWeight;
            Ambush randAmbush = null;

            float counted = 0f;

            foreach (Ambush ambush in Ambush.StaticInstances)
            {
                if (rand >= counted && rand < (ambush.WorldGenWeight + counted))
                {
                    randAmbush = ambush;
                    break;
                }
                counted += ambush.WorldGenWeight;
            }

            return(randAmbush?.CloneRandomized(tileX, tileY));
        }
Exemplo n.º 10
0
        ////

        protected override Ambush CloneRandomized(int tileX, int tileY)
        {
            bool isHorizontal = TmlHelpers.SafelyGetRand().NextBool();

            return(new BrambleWallAmbush(tileX, tileY, isHorizontal));
        }
Exemplo n.º 11
0
        ////////////////

        private BrambleWallAmbush() : base(0, 0)
        {
            this.IsHorizontal = TmlHelpers.SafelyGetRand().NextBool();
        }
Exemplo n.º 12
0
        ////////////////

        public bool IsSplit()
        {
            return(TmlHelpers.SafelyGetRand().Next(this.SplitOdds) == 0);
        }