示例#1
0
文件: Crops.cs 项目: YaBoiLewis/MiNET
		private static bool CalculateGrowthChance(Level level, Block target)
		{
			//1 / (floor(25 / points) + 1)
			double points = 0;

			// The farmland block the crop is planted in gives 2 points if dry or 4 if hydrated.
			Block under = level.GetBlock(target.Coordinates + BlockCoordinates.Down);
			points += under.Metadata == 0 ? 2 : 4;

			Block west = level.GetBlock(target.Coordinates + BlockCoordinates.West);
			Block east = level.GetBlock(target.Coordinates + BlockCoordinates.East);
			Block south = level.GetBlock(target.Coordinates + BlockCoordinates.North);
			Block north = level.GetBlock(target.Coordinates + BlockCoordinates.South);
			Block southWest = level.GetBlock(target.Coordinates + BlockCoordinates.West + BlockCoordinates.South);
			Block southEast = level.GetBlock(target.Coordinates + BlockCoordinates.East + BlockCoordinates.South);
			Block northWest = level.GetBlock(target.Coordinates + BlockCoordinates.North + BlockCoordinates.North);
			Block northEast = level.GetBlock(target.Coordinates + BlockCoordinates.South + BlockCoordinates.North);

			// For each of the 8 blocks around the block in which the crop is planted, dry farmland gives 0.25 points, and hydrated farmland gives 0.75
			points += west is Farmland ? west.Metadata == 0 ? 0.25 : 0.75 : 0;
			points += east is Farmland ? east.Metadata == 0 ? 0.25 : 0.75 : 0;
			points += south is Farmland ? south.Metadata == 0 ? 0.25 : 0.75 : 0;
			points += north is Farmland ? north.Metadata == 0 ? 0.25 : 0.75 : 0;
			points += northWest is Farmland ? northWest.Metadata == 0 ? 0.25 : 0.75 : 0;
			points += northEast is Farmland ? northEast.Metadata == 0 ? 0.25 : 0.75 : 0;
			points += southWest is Farmland ? southWest.Metadata == 0 ? 0.25 : 0.75 : 0;
			points += southEast is Farmland ? southEast.Metadata == 0 ? 0.25 : 0.75 : 0;

			// If any plants of the same type are growing in the eight surrounding blocks, the point total is cut in half unless the crops are arranged in rows.
			// TODO: Check rows .. muuhhhuu
			bool cutHalf = false;
			cutHalf |= west.GetType() == target.GetType();
			cutHalf |= east.GetType() == target.GetType();
			cutHalf |= south.GetType() == target.GetType();
			cutHalf |= north.GetType() == target.GetType();
			cutHalf |= northEast.GetType() == target.GetType();
			cutHalf |= northWest.GetType() == target.GetType();
			cutHalf |= southEast.GetType() == target.GetType();
			cutHalf |= southWest.GetType() == target.GetType();
			points /= cutHalf ? 2 : 1;

			//1 / (floor(25 / points) + 1)

			double chance = 1/(Math.Floor(25/points) + 1);

			var calculateGrowthChance = level.Random.NextDouble() <= chance;
			//Log.Debug($"Calculated growth chance. Will grow={calculateGrowthChance} on a chance score of {chance}");
			return calculateGrowthChance;
		}
示例#2
0
        private static Dictionary <string, byte> BuildNameToId()
        {
            var nameToId = new Dictionary <string, byte>();

            for (byte idx = 0; idx < byte.MaxValue; idx++)
            {
                Block  block = GetBlockById(idx);
                string name  = block.GetType().Name.ToLowerInvariant();

                if (name.Equals("block"))
                {
                    Log.Debug($"Missing implementation for block ID={idx}");
                    continue;
                }

                nameToId.Add(name, idx);
            }

            return(nameToId);
        }
示例#3
0
        private static Dictionary <string, int> BuildNameToId()
        {
            var nameToId = new Dictionary <string, int>();

            for (int idx = 0; idx < 1000; idx++)
            {
                Block  block = GetBlockById(idx);
                string name  = block.GetType().Name.ToLowerInvariant();

                if (name.Equals("block"))
                {
                    //if (Log.IsDebugEnabled)
                    //	Log.Debug($"Missing implementation for block ID={idx}");
                    continue;
                }

                nameToId.Add(name, idx);
            }

            return(nameToId);
        }
示例#4
0
        private static bool CalculateGrowthChance(Level level, Block target)
        {
            //1 / (floor(25 / points) + 1)
            double points = 0;

            // The farmland block the crop is planted in gives 2 points if dry or 4 if hydrated.
            var under = level.GetBlock(target.Coordinates.BlockDown()) as Farmland;

            if (under == null)
            {
                return(false);
            }

            points += under.MoisturizedAmount == 0 ? 2 : 4;

            {
                var west      = level.GetBlock(under.Coordinates.BlockWest()) as Farmland;
                var east      = level.GetBlock(under.Coordinates.BlockEast()) as Farmland;
                var south     = level.GetBlock(under.Coordinates.BlockNorth()) as Farmland;
                var north     = level.GetBlock(under.Coordinates.BlockSouth()) as Farmland;
                var southWest = level.GetBlock(under.Coordinates.BlockSouthWest()) as Farmland;
                var southEast = level.GetBlock(under.Coordinates.BlockSouthEast()) as Farmland;
                var northWest = level.GetBlock(under.Coordinates.BlockNorthWest()) as Farmland;
                var northEast = level.GetBlock(under.Coordinates.BlockNorthEast()) as Farmland;

                // For each of the 8 blocks around the block in which the crop is planted, dry farmland gives 0.25 points, and hydrated farmland gives 0.75
                points += west != null ? west.MoisturizedAmount == 0 ? 0.25 : 0.75 : 0;
                points += east != null ? east.MoisturizedAmount == 0 ? 0.25 : 0.75 : 0;
                points += south != null ? south.MoisturizedAmount == 0 ? 0.25 : 0.75 : 0;
                points += north != null ? north.MoisturizedAmount == 0 ? 0.25 : 0.75 : 0;
                points += northWest != null ? northWest.MoisturizedAmount == 0 ? 0.25 : 0.75 : 0;
                points += northEast != null ? northEast.MoisturizedAmount == 0 ? 0.25 : 0.75 : 0;
                points += southWest != null ? southWest.MoisturizedAmount == 0 ? 0.25 : 0.75 : 0;
                points += southEast != null ? southEast.MoisturizedAmount == 0 ? 0.25 : 0.75 : 0;
            }

            {
                // If any plants of the same type are growing in the eight surrounding blocks, the point total is cut in half unless the crops are arranged in rows.
                // TODO: Check rows .. muuhhhuu

                var west      = level.GetBlock(target.Coordinates.BlockWest()) as Crops;
                var east      = level.GetBlock(target.Coordinates.BlockEast()) as Crops;
                var south     = level.GetBlock(target.Coordinates.BlockNorth()) as Crops;
                var north     = level.GetBlock(target.Coordinates.BlockSouth()) as Crops;
                var southWest = level.GetBlock(target.Coordinates.BlockSouthWest()) as Crops;
                var southEast = level.GetBlock(target.Coordinates.BlockSouthEast()) as Crops;
                var northWest = level.GetBlock(target.Coordinates.BlockNorthWest()) as Crops;
                var northEast = level.GetBlock(target.Coordinates.BlockNorthEast()) as Crops;

                bool cutHalf = false;
                cutHalf |= west != null && west.GetType() == target.GetType();
                cutHalf |= east != null && east.GetType() == target.GetType();
                cutHalf |= south != null && south.GetType() == target.GetType();
                cutHalf |= north != null && north.GetType() == target.GetType();
                cutHalf |= northEast != null && northEast.GetType() == target.GetType();
                cutHalf |= northWest != null && northWest.GetType() == target.GetType();
                cutHalf |= southEast != null && southEast.GetType() == target.GetType();
                cutHalf |= southWest != null && southWest.GetType() == target.GetType();
                points  /= cutHalf ? 2 : 1;
            }

            //1 / (floor(25 / points) + 1)

            double chance = 1 / (Math.Floor(25 / points) + 1);

            var calculateGrowthChance = level.Random.NextDouble() <= chance;

            //Log.Debug($"Calculated growth chance. Will grow={calculateGrowthChance} on a chance score of {chance}");
            return(calculateGrowthChance);
        }