Exemplo n.º 1
0
        public void NextBehaviorModeRule(bool _update = false)
        {
            if (!ActiveBehaviourIsValid)
            {
                PrintDebugLog(this, "NextBehaviorModeRule : invalid Behaviour '" + ActiveBehaviourModeKey + "', please check this mode and its rules!");
            }
            else
            {
                // NextRule will be false if there are no rules but also no new rule, the first
                // case should never be true so we can use _forced to run a simulated rule change
                // to refresh the parameter and/or start animation and audio files, effects and events
                // etc.
                if (m_ActiveBehaviourMode.NextRule() || _update)
                {
                    if (m_ActiveBehaviourMode.LastRule != null)
                    {
                        BehaviourAnimation.Stop(m_ActiveBehaviourMode.Rule.Animation);
                        m_ActiveBehaviourMode.LastRule.Stop();
                    }

                    if (m_ActiveBehaviourMode.Rule != null)
                    {
                        if (DebugLogIsEnabled)
                        {
                            PrintDebugLog(this, "NextBehaviorModeRule : Start rule #" + m_ActiveBehaviourMode.Rule.Index + " of Behaviour Mode " + ActiveBehaviourModeKey + "!");
                        }

                        m_ActiveBehaviourMode.Rule.Start(OwnerComponent);

                        BehaviourAnimation.Play(m_ActiveBehaviourMode.Rule.Animation);
                        BehaviourAudioPlayer.Play(m_ActiveBehaviourMode.Rule.Audio);
                        BehaviourLook.Adapt(m_ActiveBehaviourMode.Rule.Look);
                        //BehaviourMessage.Send( m_ActiveBehaviourMode.Rule.Message );
                    }

                    m_BehaviourModeRuleLength = m_ActiveBehaviourMode.RuleLength();
                    m_BehaviourModeRuleTimer  = 0;

                    m_BehaviourModeRuleChanged = m_ActiveBehaviourMode.RuleChanged;
                    if (OnBehaviourModeRuleChanged != null && m_BehaviourModeRuleChanged == true)
                    {
                        OnBehaviourModeRuleChanged(Owner, m_ActiveBehaviourMode.Rule, m_ActiveBehaviourMode.LastRule);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the behaviour mode by key.
        /// </summary>
        ///<description>Use this function to change the behaviour of your creature.</description>
        /// <param name="key">Key.</param>
        public bool SetBehaviourModeByKey(string _key)
        {
            bool _behaviour_mode_changed = false;

            if (string.IsNullOrEmpty(_key))
            {
                if (m_BehaviourModeKeyIsValid)
                {
                    PrintDebugLog(this, "SetBehaviourModeByKey : Invalid behaviour mode key, please check the behaviour modes!");
                }

                m_BehaviourModeKeyIsValid = false;
            }
            else
            {
                m_BehaviourModeKeyIsValid = true;

                if (ActiveBehaviourModeKey != _key || !ActiveBehaviourIsReady)
                {
                    if (SetDesignatedBehaviourModeByKey(_key) == null)
                    {
                        PrintDebugLog(this, "SetBehaviourModeByKey : Behaviour Mode '" + m_DesignatedBehaviourModeKey + "' not exists, please check this behaviour mode!");
                    }
                    else if (m_DesignatedBehaviourMode == null || m_DesignatedBehaviourMode.ValidRules.Count == 0)
                    {
                        PrintDebugLog(this, "SetBehaviourModeByKey : Behaviour Mode '" + m_DesignatedBehaviourModeKey + "' have no valid rules, please check its behaviour modes rules!");
                    }
                    else
                    {
                        // stops the current behaviour mode include its active rules
                        if (m_ActiveBehaviourMode != null)
                        {
                            BehaviourAnimation.Stop(m_ActiveBehaviourMode.Rule.Animation);
                            m_ActiveBehaviourMode.Stop();
                        }

                        //BehaviourAudioPlayer.Stop();

                        m_LastBehaviourMode   = m_ActiveBehaviourMode;
                        m_ActiveBehaviourMode = m_DesignatedBehaviourMode;

                        // initialize the active behaviour mode
                        m_ActiveBehaviourMode.Start(OwnerComponent);

                        // initialize the active behaviour mode rule
                        NextBehaviorModeRule(true);

                        m_BehaviourTimer = 0;

                        m_BehaviourModeRulesChanged = true;
                        m_BehaviourModeChanged      = true;
                        _behaviour_mode_changed     = true;

                        if (OnBehaviourModeChanged != null)
                        {
                            OnBehaviourModeChanged(Owner, m_ActiveBehaviourMode, m_LastBehaviourMode);
                        }
                    }
                }
            }

            return(_behaviour_mode_changed);
        }