Example #1
0
        /// <summary>
        /// Spawns ore in the mine depending on a lot of given variables such as floor level and spawn chance.
        /// </summary>
        public void spawnOreInMine()
        {
            int floorLevel = LocationUtilities.CurrentMineLevel();

            if (this.hasVisitedFloor(floorLevel))
            {
                //Already has spawned ores for this visit.
                return;
            }
            else
            {
                this.visitedFloors.Add(floorLevel);
            }
            List <OreVein> spawnableOreVeins = new List <OreVein>();

            //Get a list of all of the ores that can spawn on this mine level.
            foreach (KeyValuePair <string, OreVein> pair in this.oreVeins)
            {
                if (pair.Value.resourceInfo.canSpawnAtLocation() && (pair.Value.resourceInfo as OreResourceInformation).canSpawnOnCurrentMineLevel())
                {
                    spawnableOreVeins.Add(pair.Value);
                }
            }

            foreach (OreVein ore in spawnableOreVeins)
            {
                if (ore.resourceInfo.shouldSpawn())
                {
                    int            amount    = ore.resourceInfo.getNumberOfNodesToSpawn();
                    List <Vector2> openTiles = LocationUtilities.GetOpenObjectTiles(Game1.player.currentLocation, (OreVein)ore.getOne());
                    amount = Math.Min(amount, openTiles.Count); //Only spawn for as many open tiles or the amount of nodes to spawn.
                    for (int i = 0; i < amount; i++)
                    {
                        int  position = Game1.random.Next(openTiles.Count);
                        bool didSpawn = this.spawnOreVein(ore.getItemInformation().id, openTiles[position]);
                        if (didSpawn == false)
                        {
                            i--; //If the tile didn't spawn due to some odd reason ensure that the amount is spawned.
                            openTiles.Remove(openTiles[position]);
                        }
                        else
                        {
                            openTiles.Remove(openTiles[position]); //Remove that tile from the list of open tiles.
                        }
                    }
                }
                else
                {
                    //Ore doesn't meet spawn chance.
                }
                //ModCore.log("Spawned :" + amount + " pancake test ores!");
            }
        }
        /// <summary>
        /// Checks to see if this ore can be spawned on the current mine level.
        /// </summary>
        /// <returns></returns>
        public bool canSpawnOnCurrentMineLevel()
        {
            int level = LocationUtilities.CurrentMineLevel();

            foreach (IntRange range in this.floorsToSpawnOn)
            {
                bool compareFun = false;
                if (this.canSpawnOnThisFloor == null)
                {
                    compareFun = false;
                }
                else
                {
                    compareFun = this.canSpawnOnThisFloor(level);
                }

                if (range.ContainsInclusive(level) || compareFun == true)
                {
                    foreach (IntRange exclude in this.floorsToExclude)
                    {
                        bool excludeFun = false;
                        if (this.excludeSpawnOnThisFloor == null)
                        {
                            excludeFun = false;
                        }
                        else
                        {
                            excludeFun = this.excludeSpawnOnThisFloor(level);
                        }
                        //Make this include exlude fun for regular mine. See above in this function.
                        if (exclude.ContainsInclusive(level) || excludeFun)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }