GetRandomInRange() public method

Returns random position in radius around this position.
public GetRandomInRange ( int radius, Random rnd ) : Position
radius int
rnd System.Random
return Position
Ejemplo n.º 1
0
		public void GetRandomInRange()
		{
			var rnd = new Random(Environment.TickCount);
			var pos = new Position(10, 10);

			for (int i = 0; i < 10000; ++i)
			{
				var rndPos1 = pos.GetRandomInRange(10, rnd);
				Assert.InRange(pos.GetDistance(rndPos1), 0, 11);

				var rndPos2 = pos.GetRandomInRange(5, 10, rnd);
				Assert.InRange(pos.GetDistance(rndPos2), 4, 11);
			}
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Spawns creature(s)
        /// </summary>
        /// <param name="raceId"></param>
        /// <param name="amount"></param>
        /// <param name="regionId"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="radius">Radius around position for random spawn</param>
        /// <param name="effect">Whether to display spawn effect</param>
        /// <param name="onDeath">Runs when one of the creatures dies</param>
        protected void Spawn(int raceId, int amount, int regionId, Position pos, int radius, bool effect, Action<Creature, Creature> onDeath)
        {
            amount = Math2.MinMax(1, 100, amount);

            var rnd = RandomProvider.Get();

            for (int i = 0; i < amount; ++i)
            {
                if (radius > 0)
                    pos = pos.GetRandomInRange(radius, rnd);

                var creature = ChannelServer.Instance.ScriptManager.Spawn(raceId, regionId, pos.X, pos.Y, -1, true, effect);

                if (onDeath != null)
                    creature.Death += onDeath;
            }
        }