Example #1
0
        /// <summary>
        /// Pick the next target.
        /// </summary>
        private void PickTarget()
        {
            if (Body.IsIncapacitated)
            {
                return;
            }

            GameLiving target = Aggression.PrimaryTarget;

            if (target == null)
            {
                AttackBehaviour.Retreat();
                Aggression.Clear();
                Body.TargetObject = null;
                AttackBehaviour   = PassiveBehaviour;
                Body.WalkToSpawn();
            }
            else
            {
                if (AttackBehaviour is PassiveBehaviour)
                {
                    AttackBehaviour = (Body.CanCastHarmfulSpells)
                        ? CastingBehaviour
                        : MeleeBehaviour;
                }
                else
                {
                    if (AttackBehaviour is MeleeBehaviour)
                    {
                        if (Body.CanCastHarmfulSpells && Util.Chance(Properties.GAMENPC_CHANCES_TO_CAST))
                        {
                            AttackBehaviour = CastingBehaviour;
                        }
                    }
                }

                AttackBehaviour.Attack(target);
            }
        }
Example #2
0
        /// <summary>
        /// Process game events.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public override void Notify(DOLEvent e, object sender, EventArgs args)
        {
            base.Notify(e, sender, args);

            // Process body only related events first.

            if (sender == Body)
            {
                if (e == GameNPCEvent.ArriveAtSpawnPoint)
                {
                    Body.TurnTo(Body.SpawnHeading);
                    return;
                }

                if (e == GameLivingEvent.Interrupted || e == GameLivingEvent.CastFailed ||
                    e == GameNPCEvent.CastFailed)
                {
                    AttackBehaviour = MeleeBehaviour;
                    PickTarget();
                    return;
                }

                if (e == GameLivingEvent.CastFinished || e == GameNPCEvent.CastFinished ||
                    e == GameLivingEvent.CrowdControlExpired ||
                    e == GameLivingEvent.InterruptExpired)
                {
                    PickTarget();
                    return;
                }

                if (e == GameLivingEvent.CrowdControlled)
                {
                    Body.TargetObject = null;
                    return;
                }
            }

            if (e == GameLivingEvent.AttackedByEnemy)
            {
                if (args is AttackedByEnemyEventArgs)
                {
                    AttackData attackData = (args as AttackedByEnemyEventArgs).AttackData;
                    OnAttacked(attackData);
                }

                return;
            }

            if (e == GameLivingEvent.EnemyHealed)
            {
                if (args is EnemyHealedEventArgs)
                {
                    EnemyHealedEventArgs healed = args as EnemyHealedEventArgs;

                    if (IsEnemy(healed.Enemy))
                    {
                        OnEnemyHealed(healed.HealSource, healed.HealAmount);
                    }
                }

                return;
            }

            if (e == GameLivingEvent.EnemyKilled)
            {
                if (args is EnemyKilledEventArgs)
                {
                    EnemyKilledEventArgs killed = args as EnemyKilledEventArgs;

                    if (IsEnemy(killed.Target))
                    {
                        OnEnemyKilled(killed.Target);
                    }
                }

                return;
            }

            if (e == GameLivingEvent.LowHealth)
            {
                OnLowHealth(sender as GameLiving);
                return;
            }

            if (e == GameLivingEvent.Dying)
            {
                if (sender == Body)
                {
                    Aggression.Clear();
                }

                // Aredhel: Although GameLivingEvent.Dying clearly is a GameLiving
                // event, DyingEventArgs.Killer is a mere GameObject. It might make
                // sense to send this event for GameObjects if, for example, the
                // GameObjects belonged to this brain's body and could be re-summoned.

                if (args is DyingEventArgs)
                {
                    OnDying(sender as GameObject, (args as DyingEventArgs).Killer);
                }

                return;
            }
        }