Example #1
0
            public void CallReinforcement(TPlayer player)
            {
                Area area = GlobalGame.GetCameraArea();

                for (int i = 0; i < PlayerList.Count; i++)
                {
                    TPlayer pl = PlayerList[i];
                    if (pl != null && pl.IsActive() && pl != player && pl.Team == player.Team && !pl.IsAlive())
                    {
                        float   x           = GlobalRandom.Next((int)(area.Left + area.Width / 5), (int)(area.Right - area.Width / 5));
                        float   y           = WorldTop + 50;
                        IObject crate       = GlobalGame.CreateObject("SupplyCrate00", new Vector2(x, y));
                        IObject platf       = GlobalGame.CreateObject("Lift00A", new Vector2(x, y - 10));
                        IObject leftBorder  = GlobalGame.CreateObject("Lift00A", new Vector2(x - 10, y), (float)Math.PI / -2);
                        IObject rightBorder = GlobalGame.CreateObject("Lift00A", new Vector2(x + 10, y), (float)Math.PI / 2);
                        leftBorder.SetBodyType(BodyType.Dynamic);
                        rightBorder.SetBodyType(BodyType.Dynamic);
                        IObjectDestroyTargets destroy = (IObjectDestroyTargets)GlobalGame.CreateObject("DestroyTargets", new Vector2(x, y));
                        platf.SetMass(1e-3f);
                        leftBorder.SetMass(1e-3f);
                        rightBorder.SetMass(1e-3f);
                        IObjectWeldJoint joint = (IObjectWeldJoint)GlobalGame.CreateObject("WeldJoint", new Vector2(x, y));
                        joint.AddTargetObject(crate);
                        joint.AddTargetObject(platf);
                        joint.AddTargetObject(rightBorder);
                        joint.AddTargetObject(leftBorder);
                        destroy.AddTriggerDestroyObject(crate);
                        destroy.AddObjectToDestroy(joint);
                        destroy.AddObjectToDestroy(platf);
                        destroy.AddObjectToDestroy(leftBorder);
                        destroy.AddObjectToDestroy(rightBorder);
                        ObjectsToRemove.Add(destroy);
                        ObjectsToRemove.Add(platf);
                        ObjectsToRemove.Add(joint);
                        ObjectsToRemove.Add(leftBorder);
                        ObjectsToRemove.Add(rightBorder);
                        pl.Equipment.Clear();
                        pl.Armor.SetId(0);
                        pl.Revive(100, false, true, x, y);
                        player.AddExp(5, 5);
                    }
                }
            }
Example #2
0
            public TShieldGenerator(int power, Vector2 position, float radius, PlayerTeam team)
            {
                Team       = team;
                Power      = power;
                Radius     = radius;
                CoreObject = GlobalGame.CreateObject("Computer00", position, 0);
                TextName   = (IObjectText)GlobalGame.CreateObject("Text", position);
                TextName.SetTextAlignment(TextAlignment.Middle);
                TextName.SetTextScale(0.8f);
                IObject          leftLeg  = GlobalGame.CreateObject("Duct00C_D", position + new Vector2(-5, -2), (float)Math.PI / 2);
                IObject          rightLeg = GlobalGame.CreateObject("Duct00C_D", position + new Vector2(6, -2), (float)Math.PI / 2);
                IObjectWeldJoint joint    = (IObjectWeldJoint)GlobalGame.CreateObject("WeldJoint", position);

                joint.AddTargetObject(CoreObject);
                joint.AddTargetObject(leftLeg);
                joint.AddTargetObject(rightLeg);
                OtherObjects.Add(leftLeg);
                OtherObjects.Add(rightLeg);
                OtherObjects.Add(joint);
                OtherObjects.Add(TextName);
            }
Example #3
0
        public void OnStartup()
        {
            Game.RunCommand("/MSG Alt To Fly!");

            book     = new Dictionary <IPlayer, IObjectPullJoint>();
            Gbook    = new Dictionary <IPlayer, int>();
            Bbook    = new Dictionary <IPlayer, bool>();
            concrete = Game.CreateObject("InvisibleBlockNoCollision", new Vector2(0, 500));
            CreateTimer(300, 0, "JetPack", true);
            CreateTimer(100, 0, "FireEffect", true);
            foreach (IPlayer ply in Game.GetPlayers())
            {
                Gbook.Add(ply, 2);
                Bbook.Add(ply, true);
                IObjectWeldJoint       weld = (IObjectWeldJoint)Game.CreateObject("WeldJoint", ply.GetWorldPosition());
                IObjectActivateTrigger trig = (IObjectActivateTrigger)Game.CreateObject("ActivateTrigger", ply.GetWorldPosition() + new Vector2(0, 8));
                trig.SetBodyType(BodyType.Dynamic);
                trig.SetScriptMethod("Toggle");
                weld.AddTargetObject(trig);
                weld.AddTargetObject(ply);
            }
        }
Example #4
0
        private void CheckIfCollide()
        {
            var currentVec = Instance.GetLinearVelocity();

            if (currentVec.Length() - m_lastVelocity.Length() <= -6 ||
                MathExtension.Diff(Instance.GetAngle(), m_lastAngle) >= MathExtension.OneDeg * 3 ||
                TotalDistanceTraveled >= 15 && currentVec.Length() <= 1)
            {
                TargetedObject = Game.GetObjectsByArea(Instance.GetAABB())
                                 .Where(o => o.UniqueID != Instance.UniqueID && ScriptHelper.IsInteractiveObject(o))
                                 .FirstOrDefault();

                if (TargetedObject != null)
                {
                    m_timeElasped  = Game.TotalElapsedGameTime;
                    TargetedPlayer = ScriptHelper.CastPlayer(TargetedObject);

                    if (TargetedPlayer != null)
                    {
                        Instance.SetBodyType(BodyType.Static);
                        m_relPlayerPosition = TargetedPlayer.GetWorldPosition() - Instance.GetWorldPosition();
                    }
                    else
                    {
                        m_weldJoint = (IObjectWeldJoint)Game.CreateObject("WeldJoint");
                        m_weldJoint.SetWorldPosition(Instance.GetWorldPosition());
                        m_weldJoint.SetTargetObjects(new List <IObject>()
                        {
                            Instance, TargetedObject
                        });
                    }
                }
            }

            m_lastVelocity = currentVec;
            m_lastAngle    = Instance.GetAngle();
        }
Example #5
0
 public void JetPack(TriggerArgs args)
 {
     foreach (IPlayer ply in Game.GetPlayers())
     {
         IObjectPullJoint         pullit   = null;
         IObjectTargetObjectJoint targetit = null;
         float forc = 0;
         if (!Bbook.ContainsKey(ply) && !ply.IsDead)
         {
             ;
             Bbook.Add(ply, true);
             IObjectWeldJoint       weld = (IObjectWeldJoint)Game.CreateObject("WeldJoint", ply.GetWorldPosition());
             IObjectActivateTrigger trig = (IObjectActivateTrigger)Game.CreateObject("ActivateTrigger", ply.GetWorldPosition() + new Vector2(0, 8));
             trig.SetBodyType(BodyType.Dynamic);
             trig.SetScriptMethod("Toggle");
             weld.AddTargetObject(trig);
             weld.AddTargetObject(ply);
         }
         if (!Gbook.ContainsKey(ply) && !ply.IsDead)
         {
             ;
             Gbook.Add(ply, 2);
         }
         if (Gbook.ContainsKey(ply) && !ply.IsDead)
         {
             int c = Gbook[ply] % demforce.Length;
             forc = force * demforce[c] / 100;
             if (ply.IsBlocking && ply.IsWalking)
             {
                 Gbook[ply] = (c + 1) % demforce.Length;
                 Game.PlayEffect("CFTXT", ply.GetWorldPosition() + new Vector2(0, 8), demforce[Gbook[ply]].ToString() + " %");
             }
         }
         if (book.ContainsKey(ply))
         {
             pullit   = book[ply];
             targetit = pullit.GetTargetObjectJoint();
             book[ply].SetWorldPosition(targetit.GetWorldPosition() + new Vector2(0, 500));
         }
         bool jeton     = (ply.IsWalking && !ply.IsDead && !ply.IsStaggering && !ply.IsRolling && (!ply.IsBlocking || ply.IsInMidAir) && !ply.IsManualAiming);
         bool mapborder = WorkOutsideBorders || Game.GetCameraArea().Contains(ply.GetWorldPosition());
         if (jeton)
         {
             if (book.ContainsKey(ply))
             {
                 book[ply].Destroy();
                 book.Remove(ply);
             }
             pullit = (IObjectPullJoint)Game.CreateObject("PullJoint", ply.GetWorldPosition() + new Vector2(0, 500));
             book.Add(ply, pullit);
             if (!mapborder)
             {
                 forc = (float)(forc / 2);
             }
             pullit.SetForce(forc);
             targetit = (IObjectTargetObjectJoint)Game.CreateObject("TargetObjectJoint", ply.GetWorldPosition());
             targetit.SetTargetObject(ply);
             pullit.SetTargetObject(concrete);
             pullit.SetTargetObjectJoint(targetit);
         }
         if (!jeton)
         {
             if (pullit != null)
             {
                 //	pullit .SetWorldPosition(ply.GetWorldPosition() + new Vector2(0,50));
                 pullit.SetForce(0f);
             }
         }
     }
 }
Example #6
0
        protected override void Update(float elapsed)
        {
            base.Update(elapsed);

            if (TargetedObject == null)
            {
                CheckIfCollide();
            }

            if (TargetedObject != null)
            {
                Game.DrawArea(TargetedObject.GetAABB(), Color.Red);
            }
            if (TargetedPlayer != null)
            {
                if (TargetedPlayer.IsOnGround)
                {
                    if (m_weldJoint != null)
                    {
                        Instance.SetBodyType(BodyType.Static);
                        m_weldJoint.Remove();
                        m_weldJoint = null;
                    }

                    if (TargetedPlayer.IsCrouching)
                    {
                        Instance.SetWorldPosition(TargetedPlayer.GetWorldPosition() - m_relPlayerPosition - Vector2.UnitY * 5);
                    }
                    else if (TargetedPlayer.IsRolling)
                    {
                        Instance.SetWorldPosition(TargetedPlayer.GetAABB().Center);
                    }
                    else
                    {
                        Instance.SetWorldPosition(TargetedPlayer.GetWorldPosition() - m_relPlayerPosition);
                    }
                }
                else if (TargetedPlayer.IsInMidAir) // cannot track position accurately when player is in mid air
                {
                    if (m_weldJoint == null)
                    {
                        Instance.SetBodyType(BodyType.Dynamic);
                        m_weldJoint = (IObjectWeldJoint)Game.CreateObject("WeldJoint");
                        m_weldJoint.SetWorldPosition(Instance.GetWorldPosition());
                        m_weldJoint.SetTargetObjects(new List <IObject>()
                        {
                            Instance, TargetedPlayer
                        });
                    }
                }
            }

            if (m_timeElasped != 0 && ScriptHelper.IsElapsed(m_timeElasped, 2000))
            {
                if (m_weldJoint != null)
                {
                    m_weldJoint.Remove();
                }
                DealExplosionDamage();
                Instance.Destroy();
            }
        }
Example #7
0
            public TTurret(int id, Vector2 position, int dir, PlayerTeam team)
            {
                Id   = id;
                Team = team;
                if (dir < 0)
                {
                    MainBlockAngle = (float)Math.PI / 2;
                    DefaultAngle   = (float)Math.PI;
                }
                else
                {
                    MainBlockAngle = (float)Math.PI / 2;
                    DefaultAngle   = 0;
                }
                IObject leftLeg  = null;
                IObject rightLeg = null;
                IObject hull2    = null;
                IObject hull3    = null;
                IObject hull4    = null;

                if (Id < 4)
                {
                    leftLeg  = GlobalGame.CreateObject("Duct00C_D", position + new Vector2(-3, -9), 1.2f);
                    rightLeg = GlobalGame.CreateObject("Duct00C_D", position + new Vector2(3, -9), -1.2f);
                    leftLeg.SetMass(leftLeg.GetMass() * 20);
                    rightLeg.SetMass(rightLeg.GetMass() * 20);
                }
                else if (Id == 4 || Id == 5 || Id == 6 || Id == 7)
                {
                    RotationLimit = 0;
                    Hull          = GlobalGame.CreateObject("BgMetal08H", position + new Vector2(-4, 4), (float)Math.PI / 2);
                    hull2         = GlobalGame.CreateObject("BgMetal08H", position + new Vector2(4, 4), 0);
                    hull3         = GlobalGame.CreateObject("BgMetal08H", position + new Vector2(4, -4), -(float)Math.PI / 2);
                    hull4         = GlobalGame.CreateObject("BgMetal08H", position + new Vector2(-4, -4), -(float)Math.PI);
                    hull2.SetBodyType(BodyType.Dynamic);
                    hull3.SetBodyType(BodyType.Dynamic);
                    hull4.SetBodyType(BodyType.Dynamic);
                }
                else if (Id == 6 || Id == 7)
                {
                    RotationLimit = 0;
                    Hull          = GlobalGame.CreateObject("BgMetal08H", position + new Vector2(-4, 4), (float)Math.PI / 2);
                    hull2         = GlobalGame.CreateObject("BgMetal08H", position + new Vector2(4, 4), 0);
                    hull3         = GlobalGame.CreateObject("BgMetal08H", position + new Vector2(4, -4), -(float)Math.PI / 2);
                    hull4         = GlobalGame.CreateObject("BgMetal08H", position + new Vector2(-4, -4), -(float)Math.PI);
                    hull2.SetBodyType(BodyType.Dynamic);
                    hull3.SetBodyType(BodyType.Dynamic);
                    hull4.SetBodyType(BodyType.Dynamic);
                }


                if (Id == 6 || Id == 7)
                {
                    MainBlock = GlobalGame.CreateObject("CrabCan00", position, -(float)Math.PI / 2 * dir);
                }
                else
                {
                    MainBlock = GlobalGame.CreateObject("Computer00", position, -(float)Math.PI / 2 * dir);
                }

                MainBlock.SetHealth(1000);

                if (Id >= 4)
                {
                    IObjectAlterCollisionTile collisionDisabler = (IObjectAlterCollisionTile)GlobalGame.CreateObject("AlterCollisionTile", position);
                    collisionDisabler.SetDisableCollisionTargetObjects(true);
                    collisionDisabler.SetDisableProjectileHit(false);
                    collisionDisabler.AddTargetObject(MainBlock);
                    IObject[] platforms = GlobalGame.GetObjectsByName(new string[] { "MetalPlat01A", "Lift00C", "Lift00B", "MetalPlat00G", "Elevator02B", "InvisiblePlatform", "MetalPlat01F" });
                    for (int i = 0; i < platforms.Length; ++i)
                    {
                        collisionDisabler.AddTargetObject(platforms[i]);
                    }
                }
                IObject antenna = GlobalGame.CreateObject("BgAntenna00B", position + new Vector2(-2 * dir, 9));

                antenna.SetBodyType(BodyType.Dynamic);
                antenna.SetMass(0.0000001f);
                IObjectWeldJoint bodyJoint = (IObjectWeldJoint)GlobalGame.CreateObject("WeldJoint", position);
                IObjectWeldJoint hullJoint = (IObjectWeldJoint)GlobalGame.CreateObject("WeldJoint", position);

                if (Id < 4)
                {
                    hullJoint.AddTargetObject(leftLeg);
                    hullJoint.AddTargetObject(rightLeg);
                    OtherObjects.Add(leftLeg);
                    OtherObjects.Add(rightLeg);
                }
                else if (Id == 4 || Id == 5 || Id == 6 || Id == 7)
                {
                    hullJoint.AddTargetObject(Hull);
                    hullJoint.AddTargetObject(hull2);
                    hullJoint.AddTargetObject(hull3);
                    hullJoint.AddTargetObject(hull4);
                    OtherObjects.Add(Hull);
                    OtherObjects.Add(hull2);
                    OtherObjects.Add(hull3);
                    OtherObjects.Add(hull4);
                }
                bodyJoint.AddTargetObject(MainBlock);
                bodyJoint.AddTargetObject(antenna);
                bodyJoint.SetPlatformCollision(WeldJointPlatformCollision.PerObject);
                OtherObjects.Add(antenna);
                OtherObjects.Add(bodyJoint);
                OtherObjects.Add(hullJoint);
                DamagedObjects.Add(MainBlock);
                if (Id == 4 || Id == 5)
                {
                    HackingProtection = true;
                    EnableMovement    = true;
                    PathSize          = 2;
                    Speed             = 3;
                    RotationSpeed     = 3f;
                    DamageFactor      = 1f;
                    DroneMinDistance  = 5 * 8;
                }
                else if (Id == 6)
                {
                    HackingProtection = false;
                    EnableMovement    = true;
                    PathSize          = 2;
                    Speed             = 4;
                    RotationSpeed     = 2f;
                    DamageFactor      = 1.5f;
                    DroneMinDistance  = 4 * 8;
                }
                else if (Id == 7)
                {
                    HackingProtection = false;
                    EnableMovement    = true;
                    PathSize          = 2;
                    Speed             = 4;
                    RotationSpeed     = 2f;
                    DamageFactor      = 1f;
                    DroneMinDistance  = 4 * 8;
                }

                if (id == 0)
                {
                    Name = "Light Turret";
                }
                else if (id == 1)
                {
                    Name = "Rocket Turret";
                }
                else if (id == 2)
                {
                    Name = "Heavy Turret";
                }
                else if (id == 3)
                {
                    Name = "Sniper Turret";
                }
                else if (id == 4)
                {
                    Name = "Assault Drone";
                }
                else if (id == 5)
                {
                    Name = "Fire Drone";
                }
                else if (id == 6)
                {
                    Name = "Tazer Drone";
                }
                else if (id == 7)
                {
                    Name = "Melee Drone";
                }
                if (id == 1 || id == 2)
                { //@0:5B=8F0
                    IObject gun2 = GlobalGame.CreateObject("BgBarberPole00", position + new Vector2(dir, -2), (float)Math.PI / 2);
                    IObject gun1 = GlobalGame.CreateObject("BgBarberPole00", position + new Vector2(dir, 3), (float)Math.PI / 2);
                    gun1.SetBodyType(BodyType.Dynamic);
                    gun2.SetBodyType(BodyType.Dynamic);
                    gun1.SetMass(0.0000001f);
                    gun2.SetMass(0.0000001f);
                    bodyJoint.AddTargetObject(gun1);
                    bodyJoint.AddTargetObject(gun2);
                    OtherObjects.Add(gun1);
                    OtherObjects.Add(gun2);
                    TTurretWeapon weapon = new TTurretWeapon
                    {
                        BulletType    = (int)ProjectileItem.BAZOOKA,
                        Sound         = "Bazooka",
                        ReloadingTime = 200
                    };
                    if (id == 2)
                    {
                        weapon.Ammo = 4;
                    }
                    else
                    {
                        weapon.Ammo            = 6;
                        weapon.SuppressiveFire = true;
                        weapon.MaxFireDelay    = 1;
                        weapon.MaxBulletCount  = 1;
                    }
                    weapon.Scatter = 0;
                    WeaponList.Add(weapon);
                }
                if (id == 0 || id == 2 || id == 4)
                { //?C;5<5B
                    IObject gun00 = GlobalGame.CreateObject("BgPipe02A", position + new Vector2(8 * dir, 0));
                    IObject gun01 = GlobalGame.CreateObject("BgPipe02B", position + new Vector2(14 * dir, 0));
                    IObject gun10 = GlobalGame.CreateObject("BgPipe02A", position + new Vector2(8 * dir, 2));
                    IObject gun11 = GlobalGame.CreateObject("BgPipe02B", position + new Vector2(14 * dir, 2));
                    gun00.SetBodyType(BodyType.Dynamic);
                    gun01.SetBodyType(BodyType.Dynamic);
                    gun10.SetBodyType(BodyType.Dynamic);
                    gun11.SetBodyType(BodyType.Dynamic);
                    gun00.SetMass(0.0000001f);
                    gun01.SetMass(0.0000001f);
                    gun10.SetMass(0.0000001f);
                    gun11.SetMass(0.0000001f);
                    bodyJoint.AddTargetObject(gun00);
                    bodyJoint.AddTargetObject(gun01);
                    bodyJoint.AddTargetObject(gun10);
                    bodyJoint.AddTargetObject(gun11);
                    OtherObjects.Add(gun00);
                    OtherObjects.Add(gun01);
                    OtherObjects.Add(gun10);
                    OtherObjects.Add(gun11);
                    TTurretWeapon weapon = new TTurretWeapon
                    {
                        BulletType      = (int)ProjectileItem.UZI,
                        Sound           = "AssaultRifle",
                        ReloadingTime   = 7,
                        Ammo            = 150,
                        Scatter         = 2,
                        SuppressiveFire = true,
                        MaxFireDelay    = 30,
                        MaxBulletCount  = 3
                    };
                    WeaponList.Add(weapon);
                }
                if (id == 3)
                { //A=09?5@:0
                    IObject gun1 = GlobalGame.CreateObject("BgPipe02A", position + new Vector2((dir == -1) ? -14 : 6, 0));
                    IObject gun2 = GlobalGame.CreateObject("BgPipe02B", position + new Vector2(22 * dir, 0));
                    IObject gun3 = GlobalGame.CreateObject("BgPipe02B", position + new Vector2(7 * dir, 2));
                    gun1.SetSizeFactor(new Point(2, 1));
                    gun1.SetBodyType(BodyType.Dynamic);
                    gun2.SetBodyType(BodyType.Dynamic);
                    gun3.SetBodyType(BodyType.Dynamic);
                    gun1.SetMass(0.0000001f);
                    gun2.SetMass(0.0000001f);
                    gun3.SetMass(0.0000001f);
                    bodyJoint.AddTargetObject(gun1);
                    bodyJoint.AddTargetObject(gun2);
                    bodyJoint.AddTargetObject(gun3);
                    OtherObjects.Add(gun1);
                    OtherObjects.Add(gun2);
                    OtherObjects.Add(gun3);
                    TTurretWeapon weapon = new TTurretWeapon
                    {
                        BulletType    = (int)ProjectileItem.SNIPER,
                        Sound         = "Sniper",
                        ReloadingTime = 150,
                        Ammo          = 10,
                        Scatter       = 0
                    };
                    WeaponList.Add(weapon);
                }
                if (id == 5)
                { //>3=5<QB
                    IObject gun1 = GlobalGame.CreateObject("BgPipe02A", position + new Vector2((dir == -1) ? -14 : 6, 0));
                    IObject gun2 = GlobalGame.CreateObject("BgPipe02B", position + new Vector2(14 * dir, 0));
                    IObject gun3 = GlobalGame.CreateObject("BgPipe02B", position + new Vector2(7 * dir, 2));
                    IObject gun4 = GlobalGame.CreateObject("BgPipe02B", position + new Vector2(7 * dir, -2));
                    gun1.SetBodyType(BodyType.Dynamic);
                    gun2.SetBodyType(BodyType.Dynamic);
                    gun3.SetBodyType(BodyType.Dynamic);
                    gun4.SetBodyType(BodyType.Dynamic);
                    gun1.SetMass(0.0000001f);
                    gun2.SetMass(0.0000001f);
                    gun3.SetMass(0.0000001f);
                    gun4.SetMass(0.0000001f);
                    bodyJoint.AddTargetObject(gun1);
                    bodyJoint.AddTargetObject(gun2);
                    bodyJoint.AddTargetObject(gun3);
                    bodyJoint.AddTargetObject(gun4);
                    OtherObjects.Add(gun1);
                    OtherObjects.Add(gun2);
                    OtherObjects.Add(gun3);
                    OtherObjects.Add(gun4);
                    TTurretWeapon weapon = new TTurretWeapon
                    {
                        Distance        = 150,
                        BulletType      = -1,
                        Sound           = "Flamethrower",
                        ReloadingTime   = 3,
                        Ammo            = 300,
                        SuppressiveFire = true,
                        Scatter         = 10,
                        TurretTarget    = false
                    };
                    WeaponList.Add(weapon);
                }
                if (Id == 6)
                {
                    TTurretWeapon weapon = new TTurretWeapon
                    {
                        Distance        = 50,
                        BulletType      = -2,
                        Sound           = "Splash",
                        ReloadingTime   = 150,
                        SuppressiveFire = true,
                        Ammo            = 25,
                        TurretTarget    = false
                    };
                    WeaponList.Add(weapon);
                }
                if (Id == 7)
                {
                    TTurretWeapon weapon = new TTurretWeapon
                    {
                        Distance        = 60,
                        BulletType      = -3,
                        Sound           = "MeleeSwing",
                        ReloadingTime   = 50,
                        SuppressiveFire = true,
                        Ammo            = 15,
                        TurretTarget    = false
                    };
                    WeaponList.Add(weapon);
                }
                TextName = (IObjectText)GlobalGame.CreateObject("Text", position);
                TextName.SetTextAlignment(TextAlignment.Middle);
                TextName.SetText(Name);
                TextName.SetTextScale(0.8f);
                OtherObjects.Add(TextName);
                MainMotor = (IObjectRevoluteJoint)GlobalGame.CreateObject("RevoluteJoint", position);
                MainMotor.SetTargetObjectB(MainBlock);
                if (Id < 4)
                {
                    MainMotor.SetTargetObjectA(leftLeg);
                }
                else
                {
                    MainMotor.SetTargetObjectA(hull2);
                }
                MainMotor.SetMotorEnabled(true);
                MainMotor.SetMaxMotorTorque(100000);
                MainMotor.SetMotorSpeed(0);
                OtherObjects.Add(MainMotor);
                InitHealth();
            }
Example #8
0
        public Turret(Vector2 worldPosition, TurretDirection direction, IPlayer owner = null)
        {
            Direction   = (direction == TurretDirection.Left) ? -1 : 1;
            Owner       = owner;
            Team        = owner.GetTeam();
            IsDestroyed = false;

            var ux = Vector2.UnitX * -Direction;
            var uy = Vector2.UnitY;

            // worldPosition works best when get from TurretPlaceholder.Position
            RotationCenter = worldPosition;
            var legLeft1Position      = RotationCenter - ux * 4 + uy * 1;
            var legLeft2Position      = RotationCenter - ux * 7 - uy * 5;
            var legRight1Position     = RotationCenter + ux * 0 - uy * 5;
            var legRight2Position     = RotationCenter + ux * 4 - uy * 13;
            var legMiddle1Position    = RotationCenter - ux * 2.8f - uy * 3;
            var legMiddle2Position    = RotationCenter - ux * 2.8f - uy * 6;
            var ammoPosition          = RotationCenter + ux * 2 - uy * 2;
            var comp1Position         = RotationCenter - ux * 5 + uy * 2;
            var controllerPosition    = RotationCenter + ux * 0 + uy * 1;
            var sensorPosition        = RotationCenter + ux * 5 + uy * 2;
            var rotorPosition         = RotationCenter + ux * 0 - uy * 1;
            var barrelSolid1Position  = RotationCenter - ux * 8 - uy * 2;
            var barrelSolid2Position  = RotationCenter - ux * 16 - uy * 2;
            var barrelPosition        = RotationCenter - ux * 6 + uy * 2;
            var tipPosition           = RotationCenter - ux * 24 + uy * 0;
            var teamIndicatorPosition = RotationCenter - ux * 11f - uy * 1;

            // Object creation order is important. It will determine the z-layer the object will be located to
            var teamIndicator = Game.CreateObject("BgBottle00D", teamIndicatorPosition, -Direction * MathHelper.PIOver2);

            teamIndicator.SetColor1(GetColor(owner.GetTeam()));

            var legMiddle1 = (IObjectActivateTrigger)Game.CreateObject("Lever01", legMiddle1Position, -Direction * 0.41f);
            var legMiddle2 = (IObjectActivateTrigger)Game.CreateObject("Lever01", legMiddle2Position, -Direction * 0.41f);
            var legLeft1   = (IObjectActivateTrigger)Game.CreateObject("Lever01", legLeft1Position);
            var legLeft2   = (IObjectActivateTrigger)Game.CreateObject("Lever01", legLeft2Position);
            var legRight1  = (IObjectActivateTrigger)Game.CreateObject("Lever01", legRight1Position, MathHelper.PI);
            var legRight2  = (IObjectActivateTrigger)Game.CreateObject("Lever01", legRight2Position, MathHelper.PI);
            var ammo       = (IObjectActivateTrigger)Game.CreateObject("AmmoStash00", ammoPosition);

            var comp1 = Game.CreateObject("ItemDebrisDark00", comp1Position);

            m_controller = new Component("ItemDebrisShiny00", controllerPosition);
            m_sensor     = new Component("ItemDebrisDark00", sensorPosition);
            m_rotor      = new Component("MetalDebris00A", rotorPosition);

            var barrel1 = Game.CreateObject("MetalPlat01A", barrelSolid1Position);
            var barrel2 = Game.CreateObject("MetalPlat01B", barrelSolid2Position);

            m_barrel = new Component("JusticeStatue00Scales", barrelPosition);
            m_tip    = Game.CreateObject("LedgeGrab", tipPosition);
            m_ground = GetGround(RotationCenter);

            legMiddle1.SetEnabled(false);
            legMiddle2.SetEnabled(false);
            legLeft1.SetEnabled(false);
            legLeft2.SetEnabled(false);
            legRight1.SetEnabled(false);
            legRight2.SetEnabled(false);
            ammo.SetEnabled(false);

            legLeft1.SetFaceDirection(-Direction);
            legLeft2.SetFaceDirection(-Direction);
            legRight1.SetFaceDirection(Direction);
            legRight2.SetFaceDirection(Direction);
            legMiddle1.SetFaceDirection(-Direction);
            legMiddle2.SetFaceDirection(-Direction);

            ammo.SetFaceDirection(-Direction);
            barrel1.SetFaceDirection(-Direction);
            barrel2.SetFaceDirection(-Direction);
            m_barrel.Object.SetFaceDirection(-Direction);
            m_tip.SetFaceDirection(-Direction);
            comp1.SetFaceDirection(-Direction);
            m_controller.Object.SetFaceDirection(-Direction);
            m_sensor.Object.SetFaceDirection(-Direction);
            m_rotor.Object.SetFaceDirection(-Direction);
            teamIndicator.SetFaceDirection(-Direction);

            m_bodyJoint          = (IObjectWeldJoint)Game.CreateObject("WeldJoint");
            m_alterCollisionTile = (IObjectAlterCollisionTile)Game.CreateObject("AlterCollisionTile");

            legMiddle1.CustomID    = "TurretLegMiddle1";
            legMiddle2.CustomID    = "TurretLegMiddle2";
            legLeft1.CustomID      = "TurretLegLeft1";
            legLeft2.CustomID      = "TurretLegLeft2";
            legRight1.CustomID     = "TurretLegRight1";
            legRight2.CustomID     = "TurretLegRight2";
            ammo.CustomID          = "TurretAmmo";
            barrel1.CustomID       = "TurretBarrel1";
            barrel2.CustomID       = "TurretBarrel2";
            m_barrel.CustomID      = "TurretBarrel3";
            m_tip.CustomID         = "TurretTip";
            teamIndicator.CustomID = "TurretTeamIndicator";
            comp1.CustomID         = "TurretComp1";
            m_controller.CustomID  = "TurretController";
            m_sensor.CustomID      = "TurretSensor";
            m_rotor.CustomID       = "TurretRotor";

            m_components.Add(legMiddle1.CustomID, legMiddle1);
            m_components.Add(legMiddle2.CustomID, legMiddle2);
            m_components.Add(legLeft1.CustomID, legLeft1);
            m_components.Add(legLeft2.CustomID, legLeft2);
            m_components.Add(legRight1.CustomID, legRight1);
            m_components.Add(legRight2.CustomID, legRight2);
            m_components.Add(ammo.CustomID, ammo);
            m_components.Add(barrel1.CustomID, barrel1);
            m_components.Add(barrel2.CustomID, barrel2);
            m_components.Add(m_barrel.CustomID, m_barrel.Object);
            m_components.Add(m_tip.CustomID, m_tip);
            m_components.Add(teamIndicator.CustomID, teamIndicator);
            m_components.Add(comp1.CustomID, comp1);
            m_components.Add(m_controller.CustomID, m_controller.Object);
            m_components.Add(m_sensor.CustomID, m_sensor.Object);
            m_components.Add(m_rotor.CustomID, m_rotor.Object);

            // The reason I randomize health for each part is because bullets will likely shoot
            // through all the parts at once, so part with lowest hp will be destroyed first,
            // which is predictable, which is bad
            var healths = RandomHelper.Shuffle(new List <float>()
            {
                50, 100, 125, 150
            });

            m_barrel.MaxHealth     = healths[0];
            m_rotor.MaxHealth      = healths[1];
            m_sensor.MaxHealth     = healths[2];
            m_controller.MaxHealth = healths[3];

            m_damageableComponents.Add(m_barrel);
            m_damageableComponents.Add(m_rotor);
            m_damageableComponents.Add(m_sensor);
            m_damageableComponents.Add(m_controller);

            foreach (var dc in m_damageableComponents)
            {
                dc.RemoveWhenDestroyed = false;
            }

            foreach (var component in m_components.Values)
            {
                RegisterComponent(component);
            }

            m_alterCollisionTile.SetDisableCollisionTargetObjects(true);
            RotateTo(Direction > 0 ? 0 : MathHelper.PI);
        }