private static List <TDAttacker> LoadAttackersTable(DataTable t)
        {
            List <TDAttacker> results = new List <TDAttacker>();

            foreach (DataRow r in t.Rows)
            {
                int    ID        = Int32.Parse(r["ID"].ToString());
                string Name      = r["Name"].ToString();
                int    HP        = Int32.Parse(r["HP%"].ToString());
                int    Speed     = Int32.Parse(r["Speed%"].ToString());
                int    Damage    = Int32.Parse(r["Damage%"].ToString());
                int    Range     = Int32.Parse(r["Range%"].ToString());
                int    FireSpeed = Int32.Parse(r["FireSpeed%"].ToString());
                string ImageName = r["Image"].ToString();

                TDAttacker a = new TDAttacker(Name, HP, Speed, Damage, Range, 100 - FireSpeed);

                ImageName   = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Images" + Path.DirectorySeparatorChar + ImageName;
                a.MainImage = Image.FromFile(ImageName);

                results.Add(a);
            }

            return(results);
        }
Beispiel #2
0
        private void ShootAtAttacker(TDAttacker Attacker)
        {
            // create a TDAmmo object at this current location, and set it's speed toward target.
            TDAmmo newAmmo = new TDAmmo(this, Attacker);

            TDSession.thisSession.CurrentLevel.Ammo.Add(newAmmo);
        }
Beispiel #3
0
        private TDAttacker GetStrongAttacker(List <TDAttacker> atts)
        {
            TDAttacker result = atts[0];

            atts   = SortAttackersByHP(atts);
            result = atts[0];
            return(result);
        }
Beispiel #4
0
        private TDAttacker GetWeakAttacker(List <TDAttacker> atts)
        {
            TDAttacker result = atts[0];

            atts   = SortAttackersByHP(atts);
            result = atts[atts.Count - 1];
            return(result);
        }
Beispiel #5
0
        private TDAttacker GetFirstAttacker(List <TDAttacker> atts)
        {
            TDAttacker result = atts[0];

            atts   = SortAttackersByPath(atts);
            result = atts[atts.Count - 1];
            return(result);
        }
Beispiel #6
0
        private TDAttacker GetLastAttacker(List <TDAttacker> atts)
        {
            TDAttacker result = atts[0];

            atts   = SortAttackersByPath(atts);
            result = atts[0];
            return(result);
        }
Beispiel #7
0
 internal int CompareHPTo(TDAttacker a2)
 {
     if (this.HPCurrent < a2.HPCurrent)
     {
         return(1);
     }
     else if (this.HPCurrent > a2.HPCurrent)
     {
         return(-1);
     }
     else
     {
         return(0);
     }
 }
Beispiel #8
0
        private TDAttacker GetFarAttacker(List <TDAttacker> atts)
        {
            TDAttacker result        = atts[0];
            double     farthestRange = 0;
            double     rangeToThis   = 0;

            foreach (TDAttacker a in atts)
            {
                rangeToThis = TDMath.RangeToTarget(this.Location, a.Location);
                if (rangeToThis > farthestRange)
                {
                    farthestRange = rangeToThis;
                    result        = a;
                }
            }

            return(result);
        }
Beispiel #9
0
        private TDAttacker GetCloseAttacker(List <TDAttacker> atts)
        {
            TDAttacker result       = atts[0];
            double     closestRange = 0;
            double     rangeToThis  = 0;

            foreach (TDAttacker a in atts)
            {
                rangeToThis = TDMath.RangeToTarget(this.Location, a.Location);
                if (closestRange == 0 ||
                    rangeToThis < closestRange)
                {
                    closestRange = rangeToThis;
                    result       = a;
                }
            }

            return(result);
        }
Beispiel #10
0
        public TDAttacker(AttackerTypes t, int Level)
        {
            // get attacker template for enum
            TDAttacker a = TDResources.Attackers[((int)t - 1)];

            this.Name      = a.Name;
            this.MainColor = Color.Red;

            if (a.MainImage != null)
            {
                this.MainImage = a.MainImage;
            }

            // adjust stats for level

            // HP  - quickly increase
            this.HPMax     = a.HPMax + (Level * 10);
            this.HPCurrent = this.HPMax;

            // Range - slowly increase
            this.Range = (a.Range * 2) + (Level / 5);

            // Speed - slowly increase
            this.SpeedMax     = Math.Max(1, (a.SpeedMax + Level) / 4);
            this.SpeedCurrent = this.SpeedMax;

            // Damage - increase linearly
            this.BulletDamage = (a.BulletDamage / 10) + (Level);

            // bullet speed
            this.BulletSpeed = a.BulletSpeed;

            // cooldown remains constant
            this.Cooldown = new TimeSpan(0, 0, 0, 0, (int)(a.Cooldown.TotalMilliseconds * 100));

            // cost (loot)
            this.Cost = 5 + ((Level - 1) * 2);
        }
Beispiel #11
0
        internal int CompareTo(TDAttacker a2)
        {
            if (a2 == null)
            {
                return(1);
            }

            if (this.NextPoint != a2.NextPoint)
            {
                return(this.NextPoint - a2.NextPoint);
            }
            else
            {
                if (a2.DistanceToNextPoint() > this.DistanceToNextPoint())
                {
                    return(1);
                }
                else
                {
                    return(-1);
                }
            }
        }
Beispiel #12
0
        private void GenerateAttackersForLevel(int lvl, List <TDPath> Paths)
        {
            // waves
            this._WaveCount = 9 + (lvl);

            if (testing)
            {
                _WaveCount = 0;
            }

            // wave attacker type
            bool mixed = (TDMath.D(100) > 70); // 30% mixed

            // attackers per wave
            int attPerWave = 5 + TDMath.D(10 * lvl);

            if (testing)
            {
                attPerWave = 0;
            }

            // if 80, then betwen 41 and 80;
            int ThisWaveDelay = (WaveDelay / 2) + TDMath.D(WaveDelay / 2);

            if (testing)
            {
                ThisWaveDelay = WaveDelay;
            }

            int MaxDelay = 0;

            // for each wave
            for (int i = 0; i < this._WaveCount; i++)
            {
                // set the type and path for this wave
                AttackerTypes t = GetWeightedAttackerType(false);
                TDPath        p = Paths[TDMath.D(Paths.Count) - 1];

                // vary the attacker separation for this wave (between 1/2 and full value)
                int AttackerDelayWithinThisWave = (AttackerDelayWithinWave / 2) + TDMath.D((AttackerDelayWithinWave / 2));

                if (testing)
                {
                    AttackerDelayWithinThisWave = AttackerDelayWithinWave;
                }

                for (int j = 0; j < attPerWave; j++)
                {
                    // check for mixed attacker type
                    if (mixed && lvl > 3) // don't mix until lvl 4+
                    {
                        // randomized the type for the next attacker
                        t = GetWeightedAttackerType(true);
                        p = Paths[TDMath.D(Paths.Count) - 1];
                    }

                    // generate the new attacker
                    TDAttacker a = new TDAttacker(t, lvl);
                    a.WaveIndex = i + 1;

                    int delayMS = Math.Max(1, (i * ThisWaveDelay) + (j * AttackerDelayWithinThisWave)); // slightly stagger each attacker within the wave (j)
                    a.Effects.Add(new TDEffect(TDEffectTypes.WaveDelay, 0, new TimeSpan(0, 0, 0, 0, delayMS), false));
                    a.SetPath(p);

                    this.Attackers.Add(a);

                    // remember the MaxDelay for the Boss
                    MaxDelay = Math.Max(MaxDelay, delayMS);
                }
            }

            // and finally, add the level boss
            TDAttacker boss = new TDAttacker(AttackerTypes.Boss, lvl + 10);

            boss.Size     += 4;
            boss.HPMax     = boss.HPMax * 6;
            boss.HPCurrent = boss.HPMax;
            int AdditionalBossDelay = 500;

            if (testing)
            {
                AdditionalBossDelay = 10000;
            }
            boss.Effects.Add(new TDEffect(TDEffectTypes.WaveDelay, 0, new TimeSpan(0, 0, 0, 0, MaxDelay + AdditionalBossDelay), false)); // 1/2 second after last attacker
            TDPath pBoss = Paths[TDMath.D(Paths.Count) - 1];

            boss.SetPath(pBoss);
            this.Attackers.Add(boss);
        }
Beispiel #13
0
        public override void Update()
        {
            // check cooldown to see if can fire
            if (DateTime.Now > this.LastFire + new TimeSpan(0, 0, 0, 0, (int)(this.Cooldown.TotalMilliseconds / TDSession.SpeedFactor)))
            {
                List <TDAttacker> attackersInRange = GetAttackersInRange();

                // check towers in range to fire at
                if (attackersInRange.Count == 0)
                {
                    // do nothing - no towers
                }
                else
                {
                    if (attackersInRange.Count == 1)
                    {
                        // if one is the destination tower, hit it
                        ShootAtAttacker(attackersInRange[0]);
                    }
                    else if (attackersInRange.Count > 1)
                    {
                        // if multiples
                        // future: pick a tower (weakest, strongest, first?)
                        TDAttacker a = attackersInRange[0];

                        switch (this.AISetting)
                        {
                        case AISettings.First:
                            // sort list by who is closest to the end
                            a = GetFirstAttacker(attackersInRange);
                            break;

                        case AISettings.Last:
                            // sort list by who is closest to the start
                            a = GetLastAttacker(attackersInRange);
                            break;

                        case AISettings.Strong:
                            // sort by current HP - get strongest
                            a = GetStrongAttacker(attackersInRange);
                            break;

                        case AISettings.Weak:
                            // sort by current HP - get weakest
                            a = GetWeakAttacker(attackersInRange);
                            break;

                        case AISettings.Close:
                            // sort by current HP - get weakest
                            a = GetCloseAttacker(attackersInRange);
                            break;

                        case AISettings.Far:
                            // sort by current HP - get weakest
                            a = GetFarAttacker(attackersInRange);
                            break;
                        }

                        ShootAtAttacker(a);
                    }

                    LastFire = DateTime.Now;
                } // end else - there are attackers in range
            }     // end if met cooldown
        }
Beispiel #14
0
 private bool AttackerrWithinRange(TDAttacker a)
 {
     return(TDMath.PointInRange(this.Location, a.Location, this.Range));
 }