Example #1
0
        public TowerAI(FatherBuilding tower)
        {
            this.tower = tower;
            state      = BuildingAIState.Idleing;

            if (tower.RangedAttack != null)
            {
                rangeTimer            = new Timer(tower.RangedAttack.Period, true);
                rangeTimer.Triggered += new TimerEventHandler(rangeTimer_Triggered);
            }
            if (tower.MeleeAttack != null)
            {
                meleeTimer            = new Timer(tower.MeleeAttack.Period, true);
                meleeTimer.Triggered += new TimerEventHandler(meleeTimer_Triggered);
            }
        }
Example #2
0
        public void UpdateFast(GameTime gameTime)
        {
            if (rangeTimer != null)
            {
                rangeTimer.Update(gameTime);
            }
            if (meleeTimer != null)
            {
                meleeTimer.Update(gameTime);
            }

            switch (state)
            {
            case BuildingAIState.Idleing:

                if (engagement == null)
                {
                    engagement = queryRadiusAll(tower.SightRange).FirstOrDefault(actor => tower.Faction.GetRelationship(actor.Faction) == FactionRelationship.Hostile && !actor.IsDead);
                }

                if (engagement == null)
                {
                    break;
                }


                if (tower.MeleeAttack != null && withinRad(engagement, tower.MeleeAttack.Range))
                {
                    state = BuildingAIState.EngagingMelee;
                }
                else if (tower.RangedAttack != null && withinRad(engagement, tower.RangedAttack.Range))
                {
                    state = BuildingAIState.EngagingRange;
                }


                break;

            case BuildingAIState.EngagingMelee:

                if (engagement == null)
                {
                    state = BuildingAIState.Idleing;     //should never be hit, but just in case
                }
                if (!engagement.IsDead)
                {
                    if (withinRad(engagement, tower.MeleeAttack.Range))
                    {
                        meleeTimer.Start();
                    }
                    else
                    {
                        meleeTimer.Pause();
                        state = BuildingAIState.Idleing;
                    }
                }
                else
                {
                    //killed engagement
                    meleeTimer.Pause();
                    engagement = null;

                    state = BuildingAIState.Idleing;
                }


                break;

            case BuildingAIState.EngagingRange:

                if (engagement == null)
                {
                    state = BuildingAIState.Idleing;     //should never be hit, but just in case
                }
                if (!engagement.IsDead)
                {
                    if (withinRad(engagement, tower.RangedAttack.Range))
                    {
                        rangeTimer.Start();
                    }
                    else
                    {
                        rangeTimer.Pause();
                        state = BuildingAIState.Idleing;
                    }
                }
                else
                {
                    //killed engagement
                    rangeTimer.Pause();
                    engagement = null;

                    state = BuildingAIState.Idleing;
                }


                break;
            }
        }