Exemple #1
0
        private bool ActivateBehaviors(
            MobUpdateContext context,
            MobBehavior behavior)
        {
            bool foundBehaviorToActivate = false;

            // Can the behavior be activated
            if (behavior.CanActivate(context))
            {
                foundBehaviorToActivate = true;

                // Perform the behavior we can activate
                behavior.Perform(context);

                // Add the behavior to the list of behaviors that was activated
                if (context.mob.AIState.behavior_data.active_behavior_stack.Length > 0)
                {
                    context.mob.AIState.behavior_data.active_behavior_stack += ".";
                }
                context.mob.AIState.behavior_data.active_behavior_stack += behavior.GetType().Name;

                // Try to activate children behaviors
                if (behavior.Children != null)
                {
                    foreach (MobBehavior childBehavior in behavior.Children)
                    {
                        // Stop searching if this child behavior could be activated
                        if (ActivateBehaviors(context, childBehavior))
                        {
                            break;
                        }
                    }
                }
            }

            return(foundBehaviorToActivate);
        }
        private bool ActivateBehaviors(
            MobUpdateContext context,
            MobBehavior behavior)
        {
            bool foundBehaviorToActivate = false;

            // Can the behavior be activated
            if (behavior.CanActivate(context))
            {
                foundBehaviorToActivate = true;

                // Perform the behavior we can activate
                behavior.Perform(context);

                // Add the behavior to the list of behaviors that was activated
                if (context.mob.AIState.behavior_data.active_behavior_stack.Length > 0)
                {
                    context.mob.AIState.behavior_data.active_behavior_stack += ".";
                }
                context.mob.AIState.behavior_data.active_behavior_stack += behavior.GetType().Name;

                // Try to activate children behaviors
                if (behavior.Children != null)
                {
                    foreach (MobBehavior childBehavior in behavior.Children)
                    {
                        // Stop searching if this child behavior could be activated
                        if (ActivateBehaviors(context, childBehavior))
                        {
                            break;
                        }
                    }
                }
            }

            return foundBehaviorToActivate;
        }