Ejemplo n.º 1
0
        public override void FireInternal()
        {
            Sound.Play("thrownet");

            var matterList = new List <NetMatter>();
            StructuralIntegrity <NetMatter> matterIntegrity = null;

            for (var y = 0; y < 3; y++)
            {
                for (var x = 0; x < 7; x++)
                {
                    var matter = new NetMatter();

                    var force   = new Force(matter.Speed, SpaceExtensions.NormalizeQuantity(45, CalculateAngleToTarget()), CalculateAngleToTarget());
                    var matterX = this.Holder.Left + 1 + x;
                    var matterY = this.Holder.Top - 1 + y;
                    matter.MoveTo(matterX, matterY, 1);
                    matterList.Add(matter);

                    matter.Speed.HitDetectionTypes.Add(typeof(Character));
                    matter.Speed.HitDetectionTypes.Add(typeof(Wall));

                    // wraps the character in the net if it hits them
                    matter.Speed.ImpactOccurred.SubscribeForLifetime((i) =>
                    {
                        if (i.ElementHit != Holder && i.ElementHit is Character)
                        {
                            Sound.Play("wrapped");
                            matterList.ForEach(m => m.Lifetime.Dispose());
                            matterList.Clear();
                            matterIntegrity.Lifetime.Dispose();
                            for (var newX = i.ElementHit.Left - 2; newX <= i.ElementHit.Left + 2; newX++)
                            {
                                for (var newY = i.ElementHit.Top - 1; newY <= i.ElementHit.Top + 1; newY++)
                                {
                                    var newMatter = new NetMatter();
                                    newMatter.MoveTo(newX, newY);
                                    matterList.Add(newMatter);
                                }
                            }

                            matterList.ForEach(m =>
                            {
                                m.Composite = matterList;
                                SpaceTime.CurrentSpaceTime.Add(m);
                            });
                        }
                    }, matter.Lifetime);
                }
            }

            matterList.ForEach(m =>
            {
                m.Composite = matterList;
                SpaceTime.CurrentSpaceTime.Add(m);
            });

            matterIntegrity = new StructuralIntegrity <NetMatter>(matterList);
            SpaceTime.CurrentSpaceTime.Add(matterIntegrity);
        }
Ejemplo n.º 2
0
        public override void FireInternal(bool alt)
        {
            var matterList = new List <NetMatter>();
            StructuralIntegrity <NetMatter> matterIntegrity = null;

            for (var y = 0; y < 3; y++)
            {
                for (var x = 0; x < 7; x++)
                {
                    var matter = new NetMatter(this);

                    var force   = new Force(matter.Speed, 45f.NormalizeQuantity(Holder.CalculateAngleToTarget()), Holder.CalculateAngleToTarget());
                    var matterX = this.Holder.Left + 1 + x;
                    var matterY = this.Holder.Top - 1 + y;
                    matter.MoveTo(matterX, matterY, 1);
                    matterList.Add(matter);

                    // wraps the character in the net if it hits them
                    matter.Speed.ImpactOccurred.SubscribeForLifetime((i) =>
                    {
                        if (i.ObstacleHit != Holder && i.ObstacleHit is Character)
                        {
                            OnWrappedCharacter.Fire(new NetWrappedEventArgs()
                            {
                                Net = this, Wrapped = i.ObstacleHit as Character
                            });
                            matterList.ForEach(m => m.Lifetime.Dispose());
                            matterList.Clear();
                            matterIntegrity.Lifetime.Dispose();
                            for (var newX = i.ObstacleHit.Left - 2; newX <= i.ObstacleHit.Left + 2; newX++)
                            {
                                for (var newY = i.ObstacleHit.Top - 1; newY <= i.ObstacleHit.Top + 1; newY++)
                                {
                                    var newMatter = new NetMatter(this);
                                    newMatter.MoveTo(newX, newY);
                                    matterList.Add(newMatter);
                                }
                            }

                            matterList.ForEach(m =>
                            {
                                m.Composite = matterList;
                                SpaceTime.CurrentSpaceTime.Add(m);
                                OnWeaponElementEmitted.Fire(m);
                            });
                        }
                    }, matter.Lifetime);
                }
            }

            matterList.ForEach(m =>
            {
                m.Composite = matterList;
                SpaceTime.CurrentSpaceTime.Add(m);
            });

            matterIntegrity = new StructuralIntegrity <NetMatter>(matterList);
            SpaceTime.CurrentSpaceTime.Add(matterIntegrity);
        }