Наследование: StaticTileObject
Пример #1
0
 public void RegisterAttackUnit(GameEventArgs args)
 {
     if (unitToAttack == null || args.Unit.GetPathLength() < unitToAttack.GetPathLength())
     {
         unitToAttack = args.Unit;
         unitToAttack.Died += GetNewAttackUnit;
     }
 }
Пример #2
0
 public Tower(Model model, Tile tile)
     : base(model)
 {
     attackTime = new TimeSpan(0, 0, 0,0,500);
     elapsedTime = new TimeSpan(0,0,1);
     unitToAttack = null;
     attackPower = 10;
     this.tile = tile;
     this.position = tile.Position;
 }
Пример #3
0
        public void RemoveUnit(ref Unit unit)
        {
            /* if (unit.CurrentTileID != this.ID)
            {
                unitIndexes.Remove(unit.ID);
                return;
            }*/
             //   //!unitsInTile[unit.ID])
              //  return;

            unitIndexes.Remove(unit.ID);
            //unitsCount--;
            //units.Remove(unit);
            //Set new unit to attack
            OnUnitExit(ref unit);
            //unit.Died -= RemoveUnit;
            //if (units.Count > 0)
            //{
            //    Unit u = units[0];
            //    OnUnitEnter(ref u);
            //}
            //else
              //  OnUnitEnter(null);
            //Unit u;
            //if (unitsCount > 0)
            //{
            //    for (int i = 0; i < unitsCount; i++)
            //    {
            //        u = UnitCollection.GetUnitByID(unitIndexes[i]);
            //        if (u.CurrentTileID == this.ID
            //            && u.IsDeployed())
            //        //unitsInTile[unitIndexes[i]])
            //        {

            /*Unit u;
            if (unitIndexes.Count > 0)
            {
                for (int i = 0; i < unitIndexes.Count; i++)
                {
                    u = UnitCollection.GetUnitByID(unitIndexes[i]);
                    if (u.CurrentTileID == this.ID
                        && u.IsDeployed())
                        //unitsInTile[unitIndexes[i]])
                    {

                        OnUnitEnter(ref u);
                        break;
                    }
                }

            //            OnUnitEnter(ref u);
            //            break;
            //        }
            //    }
            //}
            }*/
        }
Пример #4
0
        public void AddUnit(ref Unit unit)
        {
            //if (unitIndexes.Count <= 0)
            //    return;
            if(!unitIndexes.Contains(unit.ID))
                unitIndexes.Add(unit.ID);

            OnUnitEnter(ref unit);
        }
Пример #5
0
 public void RemoveUnit(Unit unit)
 {
     units.Remove(unit);
     if(units.Count >0)
         OnUnitEnter(new GameEventArgs(units[0]));
 }
Пример #6
0
 public void AddUnit(Unit unit)
 {
     units.Add(unit);
     unit.Died += RemoveUnit;
     OnUnitEnter(new GameEventArgs(unit));
 }
Пример #7
0
 private void GetNewAttackUnit(Unit unit)
 {
     unitToAttack = null;
 }
Пример #8
0
 public void AddUnit(Unit unit)
 {
     unit.Died += RemoveUnit;
     units.Add(unit);
     TileMap.TowerCreated += unit.UpdatePath;
 }
Пример #9
0
        private void Attack(GameTime gameTime)
        {
            if (!PlayerCollection.CheckEMPFor(this.PlayerNum))
            {
                if (currentTimeToAttack > timeToAttack)
                {

                    if (unitToAttack != null && unitToAttack.Health > 0)
                    {
                        currentTimeToAttack = TimeSpan.Zero;
                        ProjectileManager.AddParticle(this.Position, unitToAttack.Position);
                        moneyToGive = unitToAttack.MoneyToGive;
                        bool kill = unitToAttack.TakeDamage(attackStrength);

                        if (kill)
                        {
                            PlayerCollection.EarnedMoneyForPlayer(PlayerNum, moneyToGive);
                            killEffect.Play(0.4f, 1.0f, 0.0f);

                        }
                        if (Level < 4 && kill)
                        {
                            XP += currentXPToGive + (int)((Level / 4.0f) * currentXPToGive);
                            if (XP >= 100)
                            {
                                XPUpgrade();
                            }
                        }

                    }
                    else if (towersToAttack.Count > 0)
                    {
                        currentTimeToAttack = TimeSpan.Zero;
                        ProjectileManager.AddParticle(this.Position, towersToAttack[0].Position);
                        bool kill = towersToAttack[0].TakeDamage(attackStrength);

                        if (kill)
                        {
                            if (PlayScreen.GameType == PlayerScreenType.Scenario)
                            {
                                ScenarioManager.RegisterAction(ScenarioItemType.DestroyEnemyTower);
                            }
                        }
                        //if (kill)
                        // towersToAttack.Remove(towersToAttack[0]);
                    }

                    if (towersToAttack.Count > 0 && towersToAttack[0].Health <= 0)
                    {
                        towersToAttack.RemoveAt(0);
                    }

                    if (unitToAttack != null && unitToAttack.Health <= 0)
                    {
                        unitToAttack = null;
                    }
                    return;
                }
                currentTimeToAttack += gameTime.ElapsedGameTime;
            }
        }
Пример #10
0
        public void UnregisterAttackUnit(ref Unit unit)
        {
            if (unitToAttack != null && unitToAttack.ID == unit.ID)
            Unit u;
            if ((unitToAttack != null && unitToAttack.ID == unit.ID) || unitToAttack == null)
            {
                unitToAttack = null;

                Unit u;
                for (int i = 0; i < this.tile.tileNeighbors.Count; i++)
                {
                    u = this.tile.tileNeighbors[i].FindNewUnitToAttack();
                    if (u != null)
                    {
                        unitToAttack = u;
                        break;
                    }
                }
                for (int i = 0; i < this.tile.tileNeighbors.Count; i++)
                {
                    u = this.tile.tileNeighbors[i].GetUnitFromTile();
                    if (u != null && u.TeamNum != TeamNum)
                    {
                        unitToAttack = u;
                        currentXPToGive = unitToAttack.XPToGive;
                        return;
                    }
                }
            }
        }
Пример #11
0
        public void RegisterAttackUnit(ref Unit unit)
        {
            if ((unitToAttack == null && unit == null) ||
                (unitToAttack != null && unitToAttack.IsDeployed() && unit == null))
                return;

            if (unitToAttack != null && unitToAttack.Health <= 0)
                unitToAttack = null;

            if (unitToAttack != null && !unitToAttack.IsDeployed())
            {
                if (unit.TeamNum != TeamNum)
                {
                    unitToAttack = unit;
                    currentXPToGive = unitToAttack.XPToGive;
                }
                return;
            }

            if (unit.TeamNum != TeamNum)
            {
                if (unitToAttack == null || unit.PathLength < unitToAttack.PathLength)
                {
                    unitToAttack = unit;
                    currentXPToGive = unitToAttack.XPToGive;
                    //unitToAttack.Died += GetNewAttackUnit;
                }
            }
        }
Пример #12
0
        public Tower(TowerType type)
        {
            this.rotationMatrixX = Matrix.Identity;
            this.rotationMatrixY = Matrix.Identity;
            this.rotationMatrixZ = Matrix.Identity;
            this.scaleRot = Matrix.Identity;
            this.scaleMatrix = Matrix.Identity;
            this.Type = type;
            this.Status = TowerStatus.Inactive;
            unitToAttack = null;
            towersToAttack = new List<Tower>();

               // timeToAttack = new TimeSpan(0, 0, 1);
            currentTimeToAttack = new TimeSpan();

            //Depends on Type
            switch (Type)
            {
                case TowerType.Plasma:
                    HealthCapacity = 500;
                    Cost = 100;
                    attackStrength = 15;
                    timeToAttack = new TimeSpan(0,0,0,0, 500);
                    break;
                case TowerType.Electric:
                    HealthCapacity = 800;
                    Cost = 250;
                    attackStrength = 80;
                    timeToAttack = new TimeSpan(0,0,3);
                    break;
                case TowerType.Cannon:
                    HealthCapacity = 700;
                    Cost = 170;
                    attackStrength = 30;
                    timeToAttack = new TimeSpan(0,0,1);
                    break;
                case TowerType.SmallUnit:
                    HealthCapacity = 600;
                    Cost = 200;
                    attackStrength = 20;
                    unitBuild = new TimeSpan(0,0,2);
                    break;
                case TowerType.LargeUnit:
                    HealthCapacity = 1000;
                    Cost = 450;
                    attackStrength = 20;
                    unitBuild = new TimeSpan(0,0,2);
                    break;
            }

            Health = HealthCapacity;
            XP = 0;
            Level = 1;

            TotalInvestedCost = Cost;

            ID = currentID;
            currentID++;
        }
 public GameEventArgs(Unit unit)
 {
     this.unit = unit;
     this.tilesToGoal = unit.GetPathLength();
 }
Пример #14
0
 public void RemoveUnit(UnitType type, Unit unit)
 {
     units.Remove(unit);
     //Set new unit to attack
     if(units.Count >0)
         OnUnitEnter(new GameEventArgs(units[0]));
 }
Пример #15
0
 private void OnUnitEnter(ref Unit unit)
 {
     if (UnitEnter != null)
     {
         UnitEnter(ref unit);
     }
 }
Пример #16
0
 private void OnUnitExit(ref Unit unit)
 {
     if (UnitExit != null)
     {
         UnitExit(ref unit);
     }
 }
Пример #17
0
 public void RemoveUnit(Unit unit)
 {
     units.Remove(unit);
     TileMap.TowerCreated -= unit.UpdatePath;
 }