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 SpectatorInputMgr(Player p, SceneMgr sceneMgr, ISceneObject obj, ActionBarMgr actionMgr) : base(actionMgr, sceneMgr)
        {
            IControledDevice    d  = obj.GetControlOfType <IControledDevice>();
            MiningModuleControl mc = obj.GetControlOfType <MiningModuleControl>();

            if (mc == null)
            {
                throw new Exception("You must initialize SpectatorInputManager with object containig MiningModuleControl");
            }
            if (d == null)
            {
                throw new Exception("You must initialize SpectatorInputManager with object containig IControledDevice control");
            }

            plr           = p;
            device        = d;
            miningControl = mc;
        }
Beispiel #3
0
        private ISceneObject MakeObjectStatic(ISceneObject obj)
        {
            NewtonianMovementControl nmc = obj.GetControlOfType <NewtonianMovementControl>();

            nmc.Speed   = 0;
            nmc.Enabled = false;

            return(obj);
        }
        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);
        }
Beispiel #5
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);
        }
        private void ShootHook()
        {
            ICatchable target;


            if (targets.Count > 0)
            {
                target = targets.Dequeue().Asteroid;
            }
            else
            {
                target = GetHookTarget();
            }

            if (target == null)
            {
                return;
            }

            Vector contactPoint1 = AIUtils.ComputeDestinationPositionToHitTarget(target, me.Data.HookSpeed, baseLauncherPosition, me.SceneMgr.GetRandomGenerator());

            // nestrili, pokud tam nedosahne
            if ((baseLauncherPosition - contactPoint1).Length > me.Data.HookLenght - 10)
            {
                //  targets.Remove(nearest);
                return;
            }
            // nestrili pod bazi
            if (me.GetBaseLocation().Y < contactPoint1.Y)
            {
                //   targets.Remove(nearest);
                return;
            }

            // nestrili, pokud to je mimo scenu
            if (SceneMgr.IsPointInViewPort(contactPoint1.ToPoint()))
            {
                ISceneObject pr = me.Hook.Shoot(contactPoint1.ToPoint());

                hookslaunched.Add(new HookTarget(pr.GetControlOfType <HookControl>(), target.Id));

                // oncatche.Add(nearest);
                // if (targets.Contains(nearest)) targets.Remove(nearest);
            }
        }
Beispiel #7
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));
        }
        public virtual void DoCollideWith(ISceneObject other, float tpf)
        {
            if (!CanCollideWithObject(other))
            {
                return;
            }

            if (other is Asteroid)
            {
                bullet.DoRemoveMe();
                if (!bullet.Owner.IsCurrentPlayerOrBot())
                {
                    return;
                }

                HitAsteroid(other as IDestroyable);
                addHitStat();
            }
            else if (other is MiningModule)
            {
                ModuleDamageControl control = other.GetControlOfType <ModuleDamageControl>();
                if (!control.Vulnerable)
                {
                    return;
                }

                (other as IDestroyable).TakeDamage(bullet.Damage, bullet);
                bullet.DoRemoveMe();
                addHitStat();
            }
            else if (other is IDestroyable)
            {
                bullet.DoRemoveMe();
                (other as IDestroyable).TakeDamage(bullet.Damage, bullet);
                bullet.Owner.AddScoreAndShow(ScoreDefines.CANNON_HIT);
                addHitStat();
            }
        }
 protected override void InitControl(ISceneObject me)
 {
     hpControl = me.GetControlOfType <IHpControl>();
 }
Beispiel #10
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();
        }