Beispiel #1
0
        protected override void OnHover()
        {
            base.OnHover();
            Instance.FlagForRemoval();

            // no blackhole too close with other blackholes
            foreach (var hole in BlackholeLocations)
            {
                if (ScriptHelper.GrowFromCenter(hole, DestroyRadius * 2).Contains(HoverPosition))
                {
                    Destroy();
                    return;
                }
            }
            BlackholeLocations.Add(HoverPosition);

            var noCollision = Constants.NoCollision;

            if (Size == BlackholeSize.Big)
            {
                Game.RunCommand("/settime .1");
                ScriptHelper.Timeout(() => Game.RunCommand("/settime 1"), 2000);
            }

            m_blackhole = Game.CreateObject("Shadow00A");
            m_blackhole.SetBodyType(BodyType.Dynamic);
            m_blackhole.SetCollisionFilter(noCollision);
            m_blackhole.SetWorldPosition(HoverPosition);

            ScriptHelper.RunIn(() => Game.DrawCircle(HoverPosition, .5f, Color.Green), 10000);

            for (var i = 1; i < 40; i++)
            {
                var egg = Game.CreateObject("Shadow00A");
                egg.SetAngle(MathHelper.TwoPI * i / 39);
                egg.SetBodyType(BodyType.Static);
                egg.SetCollisionFilter(noCollision);
                egg.SetWorldPosition(HoverPosition);
                m_blackholes.Add(egg);
            }

            m_magnetJoint = (IObjectTargetObjectJoint)Game.CreateObject("TargetObjectJoint");
            m_magnetJoint.SetWorldPosition(HoverPosition);
            m_magnetJoint.SetTargetObject(m_blackhole);

            m_revoluteJoint = (IObjectRevoluteJoint)Game.CreateObject("RevoluteJoint");
            m_revoluteJoint.SetWorldPosition(HoverPosition);
            m_revoluteJoint.SetTargetObjectA(m_blackhole);
            //m_revoluteJoint.SetMotorEnabled(true);
            m_revoluteJoint.SetMotorSpeed(3000);
            m_revoluteJoint.SetMaxMotorTorque(50000);

            m_activeTime = Game.TotalElapsedGameTime;
        }
Beispiel #2
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();
            }
Beispiel #3
0
            public void Update()
            {
                if (SmokeEffectTime > 0)
                {
                    SmokeEffectTime--;
                }
                if (MainBlock.GetHealth() <= 5 && SmokeEffectTime == 0)
                {
                    GlobalGame.PlayEffect("TR_S", MainMotor.GetWorldPosition());
                    GlobalGame.PlayEffect("TR_S", MainMotor.GetWorldPosition() + new Vector2(0, 5));
                    SmokeEffectTime = 5;
                }
                TextName.SetWorldPosition(MainMotor.GetWorldPosition() + new Vector2(0, 10));
                string name = Name;

                for (int i = 0; i < WeaponList.Count; i++)
                {
                    name += "[" + WeaponList[i].Ammo + "]";
                }
                TextName.SetText(name);
                if (!HackingProtection && IsJamming(Team))
                {
                    TextName.SetTextColor(Color.White);
                    if (GlobalRandom.Next(100) <= 10)
                    {
                        string line = " ";
                        for (int i = 0; i < 10; i++)
                        {
                            switch (GlobalRandom.Next(5))
                            {
                            case 0: line += "#"; break;

                            case 1: line += "@"; break;

                            case 2: line += "%"; break;

                            case 3: line += "_"; break;

                            case 4: line += "*"; break;
                            }
                        }
                        TextName.SetText(line);
                    }
                }
                else if (Team == PlayerTeam.Independent || (!HackingProtection && IsHacking(Team)))
                {
                    TextName.SetTextColor(Color.White);
                }
                else if (Team == PlayerTeam.Team1)
                {
                    TextName.SetTextColor(new Color(122, 122, 224));
                }
                else if (Team == PlayerTeam.Team2)
                {
                    TextName.SetTextColor(new Color(224, 122, 122));
                }
                else if (Team == PlayerTeam.Team3)
                {
                    TextName.SetTextColor(new Color(112, 224, 122));
                }
                if (UpdateHealth())
                {
                    return;
                }
                UpdateWeapon();
                if (!HaveAmmo() || (IsJamming(Team) && !HackingProtection))
                {
                    return;
                }
                if (LastTargetFinding == 0)
                {
                    PlayerTeam team = Team;
                    if (IsHacking(Team) && !HackingProtection)
                    {
                        team = PlayerTeam.Independent;
                    }
                    List <IObject> targetList;
                    if (IsProtector)
                    {
                        targetList = GetFriendList(team, MainMotor.GetWorldPosition(), GetMaxDistance());
                    }
                    else
                    {
                        targetList = GetTargetList(team, MainMotor.GetWorldPosition(), GetMaxDistance(), CanHitTurret(), HackingProtection);
                    }
                    Target       = null;
                    TargetVision = 3;
                    for (int i = 0; i < targetList.Count; i++)
                    {
                        IObject obj = targetList[i];
                        if (obj == MainMotor)
                        {
                            continue;
                        }
                        if (RotationLimit > 0)
                        {
                            float angle = TwoPointAngle(MainMotor.GetWorldPosition(), obj.GetWorldPosition());
                            if (Math.Abs(GetAngleDistance(angle, DefaultAngle + MainMotor.GetAngle())) > RotationLimit)
                            {
                                continue;
                            }
                        }
                        int trace = TraceToObject(obj);
                        if (trace < TargetVision)
                        {
                            TargetVision = trace;
                            Target       = obj;
                            break;
                        }
                    }
                    LastTargetFinding = 10;
                }
                else
                {
                    LastTargetFinding--;
                }
                if (EnableMovement)
                {
                    if (Target != null && (MainMotor.GetWorldPosition() - Target.GetWorldPosition()).Length() <= DroneMinDistance && CanFire)
                    {
                        CurrentPath.Clear();
                        StopMovement();
                    }
                    else if (LastPathFinding == 0)
                    {
                        CurrentPath.Clear();
                        StopMovement();
                        FindPathToTarget(randomTarget: ChangingRoute);
                        LastPathFinding = 200;
                    }
                    if (LastPathFinding > 0)
                    {
                        LastPathFinding--;
                    }
                    Movement();
                }
                if (Target == null)
                {
                    MainMotor.SetMotorSpeed(0);
                    return;
                }
                Vector2 targetPos = Target.GetWorldPosition();

                if (IsPlayer(Target.Name))
                {
                    targetPos = GetPlayerCenter((IPlayer)Target);
                }
                float targetAngle = TwoPointAngle(MainMotor.GetWorldPosition(), targetPos);

                targetAngle = GetAngleDistance(targetAngle, MainBlockAngle + MainBlock.GetAngle());


                if (Math.Abs(targetAngle) > 0.01f * RotationSpeed)
                {
                    if (targetAngle > 0)
                    {
                        MainMotor.SetMotorSpeed(RotationSpeed);
                    }
                    else
                    {
                        MainMotor.SetMotorSpeed(-RotationSpeed);
                    }
                }
                else
                {
                    MainMotor.SetMotorSpeed(0);
                    MainBlock.SetAngle(MainBlock.GetAngle() + targetAngle);

                    var startPos = MainMotor.GetWorldPosition();
                    var endPos   = targetPos;
                    Game.DrawLine(startPos, endPos, Color.Red);
                    var rci = new RayCastInput()
                    {
                        // doesn't include the objects that are overlaping the source of the raycast (the drone)
                        IncludeOverlap = true,
                        // only look at the closest hit
                        ClosestHitOnly = false,
                        // mark as hit the objects that projectiles hit
                        ProjectileHit = RayCastFilterMode.True,
                        // mark as hit the objects that absorb the projectile
                        AbsorbProjectile = RayCastFilterMode.Any
                    };

                    var raycastResult = Game.RayCast(startPos, endPos, rci);

                    foreach (var result in raycastResult)
                    {
                        Game.DrawCircle(result.Position, 1f, Color.Yellow);
                        Game.DrawLine(result.Position, result.Position + result.Normal * 5f, Color.Yellow);
                        Game.DrawArea(result.HitObject.GetAABB(), Color.Yellow);
                        Game.DrawText((MainMotor.GetWorldPosition() - Target.GetWorldPosition()).Length().ToString(), result.Position, Color.Green);
                        var raycastResultPlayersCount = raycastResult.Where(r => r.IsPlayer).Count();

                        if (raycastResult.Length > 2 + raycastResultPlayersCount && (MainMotor.GetWorldPosition() - Target.GetWorldPosition()).Length() <= 50)
                        {
                            // if there's more than 2 objects between drone and player, don't shoot
                            // and choose another target
                            ChangingRoute = true;
                            IPlayer ply = Target as IPlayer;
                            if (ply == null)
                            {
                                continue;
                            }
                            var originalTarget  = Target;
                            var possibleTargets = PlayerList.Where(pl => pl.Team != Team && !pl.Name.Equals(ply.Name));
                            var i      = GlobalRandom.Next(0, possibleTargets.Count());
                            var player = possibleTargets.ElementAt(i);
                            Target = player.Body;
                            DebugLogger.DebugOnlyDialogLog("Target changed from " + ply.Name + " to " + player.Name);
                            break;
                        }
                        else if (result.Hit &&
                                 !(raycastResult.Length > 2 + raycastResultPlayersCount) &&
                                 (result.IsPlayer ||
                                  result.HitObject.Name.IndexOf("crab", StringComparison.OrdinalIgnoreCase) >= 0 ||
                                  result.HitObject.Name.IndexOf("computer", StringComparison.OrdinalIgnoreCase) >= 0))
                        {
                            CanFire       = true;
                            ChangingRoute = false;
                            // no obstacles in the way, fire!
                            Fire(TargetVision);
                        }
                        else
                        {
                            CanFire = false;
                        }

                        if (result.Fraction < 0.3f && result.HitObject.Name.IndexOf("glass", StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            result.HitObject.Destroy();
                        }
                    }
                }
            }