Example #1
0
    private void Update()
    {
        if (_canCreateFirework)
        {
            _timeToCreateFirework -= Time.deltaTime;
            if (_timeToCreateFirework <= 0)
            {
                _timeToCreateFirework += Interval;

                FireworkType type           = (FireworkType)Utility.RandomEnum <FireworkType>();
                Vector2      position       = Utility.RandomVector2(FireworkMinPosition, FireworkMaxPosition);
                float        scale          = Random.Range(FireworkMinScale, FireworkMaxScale);
                GameObject   fireworkObject = Utils.Spawn(FireworkPrefab, FireworkParent);
                Firework     firework       = fireworkObject.GetComponent <Firework>();
                firework.Init(type, position, new Vector3(scale, scale, scale));
                if (IsShowing)
                {
                    firework.Show();
                }
                else
                {
                    firework.Hide();
                }
                _fireworkList.Add(firework);
            }
        }
    }
Example #2
0
        protected void ShootFirework(Location location, FireworkType type, string message)
        {
            var region = ChannelServer.Instance.World.GetRegion(location.RegionId);

            if (region == null)
            {
                Log.Warning(this.GetType().Name + ".ShootFirework: Unknown region.");
                return;
            }

            if (message == null)
            {
                message = "";
            }

            var delay   = 500;
            var rnd     = RandomProvider.Get();
            var height  = rnd.Between(750, 2000);
            var heightf = height / 100f;

            var prop = new Prop(208, location.RegionId, location.X, location.Y, 0);

            prop.DisappearTime = DateTime.Now.AddMilliseconds(20000 + delay);
            region.AddProp(prop);

            Task.Delay(delay).ContinueWith(__ =>
            {
                prop.Xml.SetAttributeValue("height", height);
                prop.Xml.SetAttributeValue("message", message + " (" + heightf.ToString("0.##") + "m)");
                prop.Xml.SetAttributeValue("type", (int)type);
                prop.Xml.SetAttributeValue("seed", Interlocked.Increment(ref _fireworkSeed));
                Send.PropUpdate(prop);
            });
        }
        public void Firework_NegaviteAs2ndParam_ExceptionThrown()
        {
            int          birthStepNumber = -1;
            FireworkType fireworkType    = FireworkType.Initial;
            IDictionary <Dimension, double> coordinates = new Dictionary <Dimension, double>();
            string expectedParamName = "birthStepNumber";

            ArgumentOutOfRangeException actualException = Assert.Throws <ArgumentOutOfRangeException>(() => new Firework(fireworkType, birthStepNumber, coordinates));

            Assert.NotNull(actualException);
            Assert.Equal(expectedParamName, actualException.ParamName);
        }
        public void Firework_NullAs3tdParam_ExceptionThrown()
        {
            int          birthStepNumber = 1;
            FireworkType fireworkType    = FireworkType.Initial;
            IDictionary <Dimension, double> coordinates = null;
            string expectedParamName = "coordinates";

            ArgumentNullException actualException = Assert.Throws <ArgumentNullException>(() => new Firework(fireworkType, birthStepNumber, coordinates));

            Assert.NotNull(actualException);
            Assert.Equal(expectedParamName, actualException.ParamName);
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Firework"/> class.
        /// </summary>
        /// <param name="fireworkType">The type of the firework (or spark this firework
        /// has been originated from).</param>
        /// <param name="birthStepNumber">The number of step this firework was created at.</param>
        /// <param name="coordinates">The firework coordinates.</param>
        /// <exception cref="System.ArgumentOutOfRangeException"> if <paramref name="birthStepNumber"/>
        /// is less than zero.</exception>
        /// <exception cref="System.ArgumentNullException"> if <paramref name="coordinates"/>
        /// is <c>null</c>.</exception>
        public Firework(FireworkType fireworkType, int birthStepNumber, IDictionary <Dimension, double> coordinates)
            : base(coordinates, double.NaN)
        {
            if (birthStepNumber < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(birthStepNumber));
            }

            if (coordinates == null)
            {
                throw new ArgumentNullException(nameof(coordinates));
            }

            this.Id              = new TId();
            this.FireworkType    = fireworkType;
            this.BirthStepNumber = birthStepNumber;
        }
        public FireworkPaintingAction(FireworkType fireworkType)
        {
            type = fireworkType;

            //randomize location
            RandomGenerator randomGenerator = ServiceManager.Instance.GetService<RandomGenerator>(ServiceType.RandomGenerator);

            //rotation = (float)randomGenerator.NextDouble(-.174, .174); //-10 degress to +10 degrees
            rotation = (float)randomGenerator.NextDouble(-.524, .524); //-30 degress to +30 degrees
            xcoord = randomGenerator.NextXLocation();
            ycoord = randomGenerator.NextYLocation();

            double sizeMultiplier = randomGenerator.NextDouble(.05, .10); //firework texture is large.  random size 5% to 10% of texture
            width = (int)(fireworkType1StrokeTexture.Width * sizeMultiplier);
            height = (int)(fireworkType1StrokeTexture.Height * sizeMultiplier);

            _deathDate = DateTime.Now + LifeSpan;
        }
Example #7
0
        public void CreateSpark_MustReturnNotNullFirework()
        {
            const int          expectedBirthStepNumber = 1;
            const FireworkType expectedFireworkType    = FireworkType.SpecificSpark;

            Solution          bestSolution = Substitute.For <Solution>(0);
            IList <Dimension> dimensions   = Substitute.For <IList <Dimension> >();

            System.Random randomizer = Substitute.For <System.Random>();
            ContinuousUniformDistribution distribution = Substitute.For <ContinuousUniformDistribution>(AbstractSourceData.Amplitude - AbstractSourceData.Delta, AbstractSourceData.Amplitude + AbstractSourceData.Delta);
            Firework                       epicenter   = Substitute.For <Firework>(expectedFireworkType, expectedBirthStepNumber - 1);
            IEnumerable <double>           qualities   = Substitute.For <IEnumerable <double> >();
            Dictionary <FireworkType, int> sparks      = Substitute.For <Dictionary <FireworkType, int> >();
            FireworkExplosion              explosion   = Substitute.For <FireworkExplosion>(epicenter, expectedBirthStepNumber, AbstractSourceData.Amplitude, sparks);

            AttractRepulseSparkGenerator sparkGenerator = new AttractRepulseSparkGenerator(bestSolution, dimensions, distribution, randomizer);

            Firework spark = sparkGenerator.CreateSpark(explosion);

            Assert.NotNull(spark);
            Assert.Equal(expectedFireworkType, spark.FireworkType);
            Assert.Equal(expectedBirthStepNumber, spark.BirthStepNumber);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MutableFirework"/> class.
 /// </summary>
 /// <param name="fireworkType">The type of the firework (or spark this firework has been originated from).</param>
 /// <param name="birthStepNumber">The number of step this firework was created at.</param>
 /// <param name="coordinates">The firework coordinates.</param>
 /// <exception cref="System.ArgumentOutOfRangeException"> if <paramref name="birthStepNumber"/>is less than zero.</exception>
 /// <exception cref="System.ArgumentNullException"> if <paramref name="coordinates"/>is <c>null</c>.</exception>
 public MutableFirework(FireworkType fireworkType, int birthStepNumber, IDictionary <Dimension, double> coordinates)
     : base(fireworkType, birthStepNumber, coordinates)
 {
 }
Example #9
0
		protected void ShootFirework(Location location, FireworkType type, string message)
		{
			var region = ChannelServer.Instance.World.GetRegion(location.RegionId);
			if (region == null)
			{
				Log.Warning(this.GetType().Name + ".ShootFirework: Unknown region.");
				return;
			}

			if (message == null)
				message = "";

			var delay = 500;
			var rnd = RandomProvider.Get();
			var height = rnd.Between(750, 2000);
			var heightf = height / 100f;

			var prop = new Prop(208, location.RegionId, location.X, location.Y, 0);
			prop.DisappearTime = DateTime.Now.AddMilliseconds(20000 + delay);
			region.AddProp(prop);

			Task.Delay(delay).ContinueWith(__ =>
			{
				prop.Xml.SetAttributeValue("height", height);
				prop.Xml.SetAttributeValue("message", message + " (" + heightf.ToString("0.##") + "m)");
				prop.Xml.SetAttributeValue("type", (int)type);
				prop.Xml.SetAttributeValue("seed", Interlocked.Increment(ref _fireworkSeed));
				Send.PropUpdate(prop);
			});
		}
Example #10
0
 public void Init(FireworkType fireworkType, Vector2 position, Vector3 scale)
 {
     _rectTransform.anchoredPosition = position;
     _rectTransform.localScale       = scale;
     _animator.SetTrigger(fireworkType.ToString());
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Firework"/> class.
 /// </summary>
 /// <param name="fireworkType">The type of the firework (or spark this firework
 /// has been originated from).</param>
 /// <param name="birthStepNumber">The number of step this firework was created at.</param>
 public Firework(FireworkType fireworkType, int birthStepNumber)
     : this(fireworkType, birthStepNumber, new Dictionary <Dimension, double>())
 {
 }