Exemple #1
0
        public static BaseExplodeEffect CreateInstance(
            this ExplodeFX type,
            IPoint3D start,
            Map map,
            int range         = 5,
            int repeat        = 0,
            TimeSpan?interval = null,
            Action <EffectInfo> effectHandler = null,
            Action callback = null)
        {
            switch (type)
            {
            case ExplodeFX.None:
                return(null);

            case ExplodeFX.Smoke:
                return(new SmokeExplodeEffect(start, map, range, repeat, interval, effectHandler, callback));

            case ExplodeFX.Water:
                return(new WaterRippleEffect(start, map, range, repeat, interval, effectHandler, callback));

            case ExplodeFX.Fire:
                return(new FireExplodeEffect(start, map, range, repeat, interval, effectHandler, callback));

            case ExplodeFX.Earth:
                return(new EarthExplodeEffect(start, map, range, repeat, interval, effectHandler, callback));

            case ExplodeFX.Air:
                return(new AirExplodeEffect(start, map, range, repeat, interval, effectHandler, callback));

            case ExplodeFX.Energy:
                return(new EnergyExplodeEffect(start, map, range, repeat, interval, effectHandler, callback));

            case ExplodeFX.Poison:
                return(new PoisonExplodeEffect(start, map, range, repeat, interval, effectHandler, callback));

            default:
            {
                var rfx = (ExplodeFX[])Enum.GetValues(typeof(ExplodeFX));

                do
                {
                    type = rfx.GetRandom();
                }while (type == ExplodeFX.Random || type == ExplodeFX.None);

                return(CreateInstance(type, start, map, range, repeat, interval, effectHandler, callback));
            }
            }
        }
        public static void BeginGoldExplosion(
            ExplodeFX fx,
            Point3D center,
            Map map,
            int range,
            int minGold,
            int maxGold,
            int[] explodeSounds = null,
            int[] dropSounds = null)
        {
            BaseExplodeEffect efx = fx.CreateInstance(center, map, 2, 3);

            if (efx == null)
            {
                return;
            }

            minGold = Math.Max(10, Math.Min(60000, minGold));
            maxGold = Math.Max(minGold, Math.Min(60000, maxGold));

            explodeSounds = explodeSounds ?? new[] {284, 285, 286, 776, 1231};

            efx.AverageZ = false;

            efx.EffectHandler = e =>
            {
                if (Utility.RandomDouble() < 0.25)
                {
                    Effects.PlaySound(e.Source, e.Map, explodeSounds.GetRandom());
                }
            };

            efx.Callback = () =>
            {
                efx.Start = efx.Start.Clone3D(0, 0, 10);

                if (efx.CurProcess >= efx.Repeat)
                {
                    EndGoldExplosion(fx, center.Clone3D(0, 0, 10 * efx.Repeat), map, range, minGold, maxGold, dropSounds);
                }
            };

            efx.Send();
        }
        public static void BeginGoldExplosion(
            ExplodeFX fx,
            Point3D center,
            Map map,
            int range,
            int minGold,
            int maxGold,
            int[] explodeSounds = null,
            int[] dropSounds    = null)
        {
            BaseExplodeEffect efx = fx.CreateInstance(center, map, 2, 3);

            if (efx == null)
            {
                return;
            }

            minGold = Math.Max(10, Math.Min(60000, minGold));
            maxGold = Math.Max(minGold, Math.Min(60000, maxGold));

            explodeSounds = explodeSounds ?? new[] { 284, 285, 286, 776, 1231 };

            efx.AverageZ = false;

            efx.EffectHandler = e =>
            {
                if (Utility.RandomDouble() < 0.25)
                {
                    Effects.PlaySound(e.Source, e.Map, explodeSounds.GetRandom());
                }
            };

            efx.Callback = () =>
            {
                efx.Start = efx.Start.Clone3D(0, 0, 10);

                if (efx.CurProcess >= efx.Repeat)
                {
                    EndGoldExplosion(fx, center.Clone3D(0, 0, 10 * efx.Repeat), map, range, minGold, maxGold, dropSounds);
                }
            };

            efx.Send();
        }
        public static void EndGoldExplosion(
            ExplodeFX fx, Point3D center, Map map, int range, int minGold, int maxGold, int[] dropSounds = null)
        {
            BaseExplodeEffect efx = fx.CreateInstance(center, map, range);

            if (efx == null)
            {
                return;
            }

            efx.AverageZ = false;

            efx.Callback = () =>
            {
                var points = new List<Point3D>();

                center.ScanRange(
                    map,
                    range,
                    r =>
                    {
                        if (!r.Excluded)
                        {
                            if (r.QueryMap.CanFit(r.Current, 1, false, false) || r.QueryMap.HasWater(r.Current))
                            {
                                points.Add(r.Current);
                            }
                            else
                            {
                                r.Exclude();
                            }
                        }

                        return false;
                    });

                if (points.Count == 0)
                {
                    return;
                }

                dropSounds = dropSounds ?? new[] {553, 554};

                Timer goldTimer = null;

                goldTimer = Timer.DelayCall(
                    TimeSpan.FromSeconds(1),
                    TimeSpan.FromMilliseconds(100),
                    points.Count,
                    () =>
                    {
                        if (points.Count == 0)
                        {
                            if (goldTimer != null)
                            {
                                goldTimer.Running = false;
                                goldTimer = null;
                            }

                            return;
                        }

                        Point3D p = points.GetRandom();
                        points.Remove(p);

                        Effects.PlaySound(p, map, dropSounds.GetRandom());

                        new MovingEffectInfo(p.Clone3D(0, 0, Utility.RandomMinMax(30, 50)), p, map, 3823, 0, 10,
                            EffectRender.Lighten)
                            .MovingImpact(
                                e =>
                                {
                                    int amount = Utility.RandomMinMax(minGold, maxGold);

                                    if (amount <= 0)
                                    {
                                        return;
                                    }

                                    var g = new Gold(amount);
                                    g.MoveToWorld(e.Target.Location, e.Map);

                                    new EffectInfo(e.Target, e.Map, 14202, 51, 10, 40, EffectRender.Lighten).Send();
                                    Effects.PlaySound(e.Target, e.Map, g.GetDropSound());
                                });
                    });
            };

            efx.Send();
        }
        public static void EndGoldExplosion(
            ExplodeFX fx, Point3D center, Map map, int range, int minGold, int maxGold, int[] dropSounds = null)
        {
            BaseExplodeEffect efx = fx.CreateInstance(center, map, range);

            if (efx == null)
            {
                return;
            }

            efx.AverageZ = false;

            efx.Callback = () =>
            {
                var points = new List <Point3D>();

                center.ScanRange(
                    map,
                    range,
                    r =>
                {
                    if (!r.Excluded)
                    {
                        if (r.QueryMap.CanFit(r.Current, 1, false, false) || r.QueryMap.HasWater(r.Current))
                        {
                            points.Add(r.Current);
                        }
                        else
                        {
                            r.Exclude();
                        }
                    }

                    return(false);
                });

                if (points.Count == 0)
                {
                    return;
                }

                dropSounds = dropSounds ?? new[] { 553, 554 };

                Timer goldTimer = null;

                goldTimer = Timer.DelayCall(
                    TimeSpan.FromSeconds(1),
                    TimeSpan.FromMilliseconds(100),
                    points.Count,
                    () =>
                {
                    if (points.Count == 0)
                    {
                        if (goldTimer != null)
                        {
                            goldTimer.Running = false;
                            goldTimer         = null;
                        }

                        return;
                    }

                    Point3D p = points.GetRandom();
                    points.Remove(p);

                    Effects.PlaySound(p, map, dropSounds.GetRandom());

                    new MovingEffectInfo(p.Clone3D(0, 0, Utility.RandomMinMax(30, 50)), p, map, 3823, 0, 10,
                                         EffectRender.Lighten)
                    .MovingImpact(
                        e =>
                    {
                        int amount = Utility.RandomMinMax(minGold, maxGold);

                        if (amount <= 0)
                        {
                            return;
                        }

                        var g = new Gold(amount);
                        g.MoveToWorld(e.Target.Location, e.Map);

                        new EffectInfo(e.Target, e.Map, 14202, 51, 10, 40, EffectRender.Lighten).Send();
                        Effects.PlaySound(e.Target, e.Map, g.GetDropSound());
                    });
                });
            };

            efx.Send();
        }