public virtual void StartDetonation()
        {
            // nevybuchne vickrat
            if (hitSomething)
            {
                return;
            }

            hitSomething = true;

            events.AddEvent(1, new Event(SharedDef.MINE_LIFE_TIME, EventType.ONE_TIME, new Action(() => { Die(); })));

            //SoundManager.Instance.StartPlayingOnce(SharedDef.MUSIC_EXPLOSION);

            IMovementControl c = me.GetControlOfType <IMovementControl>();

            if (c != null)
            {
                c.Speed = c.Speed / 4;
            }

            meMine.GetGeometry().Dispatcher.Invoke(DispatcherPriority.DataBind, new Action(() =>
            {
                meMine.FillBrush = new RadialGradientBrush(Colors.Black, Color.FromRgb(0x66, 0x00, 0x80));
            }));
        }
        private void Slow(Asteroid ast, bool exact)
        {
            IMovementControl      c  = ast.GetControlOfType <IMovementControl>();
            LinearRotationControl c1 = ast.GetControlOfType <LinearRotationControl>();

            if (c == null || c1 == null)
            {
                return;
            }

            float time = exact ? 1.5f * exactBonus : 1.5f;

            List <IControl> controls = new List <IControl>();

            controls.Add(c);
            controls.Add(c1);

            AsteroidFreezeControl removal = new AsteroidFreezeControl();

            removal.SetControlsForDisable(controls);
            removal.Time = time;

            ast.AddControl(removal);

            // led je posunut o pulku radiusu doleva
            Vector p = new Vector(ast.Position.X - (ast.Radius / 2), ast.Position.Y - (ast.Radius / 2));
            // potom jeho sirka musi byt prumer + 2 * posunuti (vlevo a vpravo) => r * (2 + 0.5 + 0.5)
            IceSquare s = SceneObjectFactory.CreateIceSquare(SceneMgr, p, new Size(ast.Radius * 3, ast.Radius * 3));

            s.AddControl(new LimitedLifeControl(time));
            SceneMgr.DelayedAttachToScene(s);
        }
        protected override void InitControl(ISceneObject me)
        {
            if (perpendicular && !(me is IMovable))
            {
                throw new ArgumentException("ShakingControl must be attached an IMovable object or it has to have perpendicularToDirection flag set to false");
            }

            if (perpendicular)
            {
                control = me.GetControlOfType <IMovementControl>();
                if (control != null)
                {
                    dir = control.RealDirection;
                }
                else
                {
                    dir = (me as IMovable).Direction;
                }
            }
            else
            {
                dir = new Vector(0, 1);
            }

            events.AddEvent(1, new Event(speed, EventType.REPEATABLE, new Action(() => DoShake())));
        }
        public virtual void DoCollideWith(ISceneObject other, float tpf)
        {
            if (other is SingularityMine || !(other is IMovable))
            {
                return;
            }

            StartDetonation();

            if (!meMine.Owner.IsCurrentPlayerOrBot())
            {
                return;
            }

            if (hitObjects.Contains((other as ISceneObject).Id))
            {
                return;
            }

            if (meMine.Owner.IsCurrentPlayer())
            {
                me.SceneMgr.FloatingTextMgr.AddFloatingText(ScoreDefines.MINE_HIT, meMine.Center, FloatingTextManager.TIME_LENGTH_1,
                                                            FloatingTextType.SCORE);
            }

            meMine.Owner.AddScoreAndShow(ScoreDefines.MINE_HIT);

            hitObjects.Add(other.Id);

            float            speed   = 0;
            IMovementControl control = other.GetControlOfType <IMovementControl>();

            if (control != null)
            {
                Vector newDir = other.Center - me.Position;
                newDir.Normalize();
                newDir *= Strength;
                newDir  = newDir + ((other as IMovable).Direction * control.Speed);

                speed         = (float)newDir.Length;
                control.Speed = speed;
                newDir.Normalize();
                (other as IMovable).Direction = newDir;
            }

            NetOutgoingMessage msg = me.SceneMgr.CreateNetMessage();

            msg.Write((int)PacketType.SINGULARITY_MINE_HIT);
            msg.Write(me.Id);
            msg.Write(other.Id);
            msg.Write(other.Position);
            msg.Write((other as IMovable).Direction);
            msg.Write(speed);
            me.SceneMgr.SendMessage(msg);
        }
 protected override void UpdateControl(float tpf)
 {
     control = cloned.GetControlOfType <IMovementControl>();
     if (control != null)
     {
         (me as IMovable).Direction = control.RealDirection;
     }
     else
     {
         (me as IMovable).Direction = cloned.Direction;
     }
 }
Beispiel #6
0
        protected override void UpdateControl(float tpf)
        {
            control = cloned.GetControlOfType <IMovementControl>();
            Vector direction = control != null ? control.RealDirection : cloned.Direction;

            if (DirectionOfsetRotation > 0)
            {
                direction = direction.Rotate(DirectionOfsetRotation);
            }

            (me as ParticleEmmitor).EmmitingDirection = direction;
        }
        private void ReceivedSingularityMineHitMsg(NetIncomingMessage msg)
        {
            long   mineId = msg.ReadInt64();
            long   id     = msg.ReadInt64();
            Vector pos    = msg.ReadVector();
            Vector dir    = msg.ReadVector();
            float  speed  = msg.ReadFloat();

            foreach (ISceneObject obj in objects)
            {
                if (obj.Id == mineId)
                {
                    DroppingSingularityControl c = obj.GetControlOfType <DroppingSingularityControl>();
                    if (c == null)
                    {
                        ExplodingSingularityBulletControl c2 = obj.GetControlOfType <ExplodingSingularityBulletControl>();
                        if (c2 == null)
                        {
                            Logger.Error("Object id " + mineId + " (" + obj.GetType().Name +
                                         ") is supposed to be a SingularityMine and have DroppingSingularityControl " +
                                         "or SingularityExplodingBullet and have ExplodingSingularityBulletControl, but control is null");
                        }
                        else
                        {
                            c2.StartDetonation();
                        }
                    }
                    else
                    {
                        c.StartDetonation();
                    }
                    continue;
                }

                if (obj.Id != id)
                {
                    continue;
                }

                obj.Position = pos;
                (obj as IMovable).Direction = dir;

                IMovementControl control = obj.GetControlOfType <IMovementControl>();
                if (control != null)
                {
                    control.Speed = speed;
                }
            }

            //SoundManager.Instance.StartPlayingOnce(SharedDef.MUSIC_EXPLOSION);
        }
 protected override void UpdateControl(float tpf)
 {
     if (perpendicular)
     {
         control = me.GetControlOfType <IMovementControl>();
         if (control != null)
         {
             dir = control.RealDirection;
         }
         else
         {
             dir = (me as IMovable).Direction;
         }
     }
 }
Beispiel #9
0
        public void StartPullingObject(ISceneObject o)
        {
            IMovementControl c = o.GetControlOfType <IMovementControl>();

            if (c != null)
            {
                c.Enabled = false;
            }

            FollowingControl follow = new FollowingControl(me);

            follow.Speed = Speed * 2;

            o.AddControl(follow);
        }
        protected override void InitControl(ISceneObject me)
        {
            if (!(me is IMovable))
            {
                throw new ArgumentException("DirectionCloneControl must by attached to an IMovable object");
            }

            control = cloned.GetControlOfType <IMovementControl>();
            if (control != null)
            {
                (me as IMovable).Direction = control.RealDirection;
            }
            else
            {
                (me as IMovable).Direction = cloned.Direction;
            }
        }
Beispiel #11
0
        protected override void InitControl(ISceneObject me)
        {
            if (!(me is ParticleEmmitor))
            {
                throw new ArgumentException("EmmitorDirectionCloneControl must by attached to an ParticleEmmitor object");
            }

            control = cloned.GetControlOfType <IMovementControl>();
            Vector direction = control != null ? control.RealDirection : cloned.Direction;

            if (DirectionOfsetRotation > 0)
            {
                direction = direction.Rotate(DirectionOfsetRotation);
            }

            (me as ParticleEmmitor).EmmitingDirection = direction;
        }
Beispiel #12
0
        public static Vector ComputeDestinationPositionToHitTarget(ISceneObject targetObject, double sourceSpeed, Vector sourceCenter, Random randomGenerator)
        {
            Vector randomResultDirection = new Vector(1, 0).Rotate(FastMath.GetRandomRotation(randomGenerator));

            if (targetObject == null)
            {
                return(randomResultDirection);
            }

            // rychlost bulletu
            double v1 = sourceSpeed;
            // rychlost objektu
            IMovementControl mc = targetObject.GetControlOfType <IMovementControl>();
            double           v2 = mc == null ? 0 : mc.Speed;
            // vektor od objektu k launcheru hooku
            Vector cVec = sourceCenter - targetObject.Center;
            // vektor smeru objektu
            Vector dVec = (targetObject as IMovable).Direction;

            // vzdalenost mezi nabojem a objektem
            double c = cVec.Length;
            // cosinus uhlu, ktery sviraji vektory pohybu objektu a smeru k launcheru
            double cosAlpha = (cVec.X * dVec.X + cVec.Y * dVec.Y) / (cVec.Length * dVec.Length);

            // diskriminant pro kvadratickou rovnici cosinovy vety
            double D = Math.Pow(2 * c * cosAlpha, 2) - 4 * c * c * (1 - Math.Pow(v1 / v2, 2));

            // nebyl nalezen trojuhelnik (komplexni cisla)
            if (D < 0)
            {
                return(randomResultDirection);
            }

            double sqrtD = Math.Sqrt(D);

            // kvadraticka rovnice cosinovy vety
            // odectenim D ziskame bod pred telesem, prictenim bychom ziskali bod za telesem (ve smeru jeho pohybu)
            double x1 = (2 * c * cosAlpha - sqrtD) / (2 - 2 * Math.Pow(v1 / v2, 2));

            dVec.Normalize();

            return(targetObject.Center + (dVec * x1));
        }
Beispiel #13
0
        public override void StartAction(List <Asteroid> afflicted, bool exact)
        {
            int count = 0;

            Vector v;
            float  speed = exact ? SharedDef.SPECTATOR_ASTEROID_THROW_SPEED * exactBonus : SharedDef.SPECTATOR_ASTEROID_THROW_SPEED;

            foreach (Asteroid ast in afflicted)
            {
                v = Owner.Device.Position - ast.Position;
                v = v.NormalizeV();
                IMovementControl mc = ast.GetControlOfType <IMovementControl>();
                if (mc != null)
                {
                    mc.Speed = speed;
                }

                ast.Direction = v;
                count++;
            }
        }
        private void Collide(IMovable obj, float tpf)
        {
            IMovementControl control = obj.GetControlOfType <IMovementControl>();

            if (control == null)
            {
                return;
            }

            Vector v = obj.Center - me.Center;

            v = v.NormalizeV();
            v = v * (Force * tpf);

            Vector dir = obj.Direction * control.Speed;

            v = v + dir;

            control.Speed = (float)v.Length;
            obj.Direction = v.NormalizeV();
        }
        private void ReceiveAsteroidsDirectionChange(NetIncomingMessage msg)
        {
            int      count = msg.ReadInt32();
            Asteroid ast   = null;
            Vector   dir;

            for (int i = 0; i < count; i++)
            {
                ast = GetSceneObject(msg.ReadInt64()) as Asteroid;
                dir = msg.ReadVector();

                if (ast != null)
                {
                    ast.Direction = dir;
                    IMovementControl control = ast.GetControlOfType <IMovementControl>();
                    if (control != null)
                    {
                        control.Speed = SharedDef.SPECTATOR_ASTEROID_THROW_SPEED;
                    }
                }
            }
        }
        protected ParticleEmmitor CreateAndAddSmokeEmmitor(int num)
        {
            ParticleEmmitor smallSmokeEmmitor1 = ParticleEmmitorFactory.CreateSmokeParticleEmmitor(me.SceneMgr, asteroid.Position);

            smallSmokeEmmitor1.EmmitingDirection = asteroid.Direction.Rotate(Math.PI);
            smallSmokeEmmitor1.Infinite          = true;
            smallSmokeEmmitor1.MinAngle          = (float)FastMath.DegToRad(15);
            smallSmokeEmmitor1.MaxAngle          = (float)FastMath.DegToRad(-15);
            smallSmokeEmmitor1.MinLife           = 1.2f;
            smallSmokeEmmitor1.MaxLife           = 1.5f;
            smallSmokeEmmitor1.Amount            = 30;
            smallSmokeEmmitor1.MinSize          *= 1.2f;
            smallSmokeEmmitor1.MaxSize          *= 1.2f;

            EmmitorDirectionCloneControl control = new EmmitorDirectionCloneControl(me);

            control.DirectionOfsetRotation = (float)Math.PI;
            smallSmokeEmmitor1.AddControl(control);

            IMovementControl c = asteroid.GetControlOfType <IMovementControl>();

            if (num == 0)
            {
                meNode.AddEmmitor(smallSmokeEmmitor1, new Vector(asteroid.Radius * 0.85, 0), false);
            }
            else if (num == 1)
            {
                meNode.AddEmmitor(smallSmokeEmmitor1, new Vector(asteroid.Radius * 0.85, asteroid.Radius * 0.2).Rotate((Math.PI / 4)), false);
            }
            else if (num == 2)
            {
                meNode.AddEmmitor(smallSmokeEmmitor1, new Vector(asteroid.Radius * 0.85, asteroid.Radius * 0.2).Rotate(-(Math.PI / 4)), false);
            }

            return(smallSmokeEmmitor1);
        }
 public NavigationControl(IMovementControl movementControl, IDirectionControl directionControl, ILogger logger)
 {
     _movementControl  = movementControl;
     _directionControl = directionControl;
     _logger           = logger;
 }
Beispiel #18
0
        public override void DoCollideWith(ISceneObject other, float tpf)
        {
            if (!CanCollideWithObject(other))
            {
                return;
            }

            if (meBullet.SceneMgr.GameType != Gametype.SOLO_GAME && !meBullet.Owner.IsCurrentPlayer())
            {
                return;
            }

            if (hitObjects.Contains(other.Id))
            {
                return;
            }

            if (meBullet.Owner.IsCurrentPlayer())
            {
                me.SceneMgr.FloatingTextMgr.AddFloatingText(ScoreDefines.MINE_HIT, meBullet.Center, FloatingTextManager.TIME_LENGTH_1,
                                                            FloatingTextType.SCORE);
            }

            if (meBullet.Owner.IsCurrentPlayerOrBot())
            {
                meBullet.Owner.AddScoreAndShow(ScoreDefines.MINE_HIT);
            }

            hitObjects.Add(other.Id);

            if (!(other is UnstableAsteroid))
            {
                if (other.GetControlOfType <ModuleDamageControl>() != null && !other.GetControlOfType <ModuleDamageControl>().Vulnerable)
                {
                    return;
                }

                float            speed   = 0;
                IMovementControl control = other.GetControlOfType <IMovementControl>();

                if (control != null)
                {
                    Vector newDir = (other as Sphere).Center - me.Position;
                    newDir.Normalize();
                    newDir *= Strength;
                    newDir  = newDir + ((other as IMovable).Direction * control.Speed);

                    speed         = (float)newDir.Length;
                    control.Speed = speed;
                    newDir.Normalize();
                    (other as IMovable).Direction = newDir;
                }

                NetOutgoingMessage msg = me.SceneMgr.CreateNetMessage();
                msg.Write((int)PacketType.SINGULARITY_MINE_HIT);
                msg.Write(me.Id);
                msg.Write(other.Id);
                msg.Write(other.Position);
                msg.Write((other as IMovable).Direction);
                msg.Write(speed);
                me.SceneMgr.SendMessage(msg);
            }

            if (other is IDestroyable)
            {
                if (!(me as SingularityBullet).Owner.IsCurrentPlayerOrBot())
                {
                    return;
                }

                if (other.GetControlOfType <ModuleDamageControl>() != null && !other.GetControlOfType <ModuleDamageControl>().Vulnerable)
                {
                    return;
                }

                HitAsteroid(other as IDestroyable);

                addHitStat();
            }

            StartDetonation();
        }