Exemplo n.º 1
0
        internal Context()
        {
            mImplementPtr = ConversationAPI.CreateContext();

            IntPtr global = ConversationAPI.GetContextGlobalSave(ImplementPtr);

            if (global != IntPtr.Zero)
            {
                mGlobalSave = new Save(global);
            }

            IntPtr player = ConversationAPI.GetContextPlayerSave(ImplementPtr);

            if (player != IntPtr.Zero)
            {
                mPlayerSave = new Save(player);
            }

            // 长期持有自己的delegate防止被gc
            mFunctionHandler = new FunctionHandler(OnFunctoinCall);
            mProcessHandler  = new FunctionHandler(OnProcessCall);
            mFunctionQuery   = new FunctionQuery(OnFunctoinQuery);
            mProcessQuery    = new FunctionQuery(OnProcessQuery);

            ConversationAPI.SetFunctionHandler(ImplementPtr, mFunctionHandler);
            ConversationAPI.SetProcessHandler(ImplementPtr, mProcessHandler);
            ConversationAPI.SetFunctionQuery(ImplementPtr, mFunctionQuery);
            ConversationAPI.SetProcessQuery(ImplementPtr, mProcessQuery);
        }
Exemplo n.º 2
0
 public float GetParamAsFloat(int index)
 {
     if (index >= 0 && index < ParamCount)
     {
         return(ConversationAPI.GetFunctionStackParamAsFloat(ImplementPtr, index));
     }
     else
     {
         return(0.0f);
     }
 }
Exemplo n.º 3
0
 public bool GetParamAsBool(int index)
 {
     if (index >= 0 && index < ParamCount)
     {
         return(ConversationAPI.GetFunctionStackParamAsBool(ImplementPtr, index));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        internal FunctionStack(IntPtr implPtr)
        {
            mImplementPtr = implPtr;

            mReturnType   = ConversationAPI.GetFunctionStackPreferReturnType(ImplementPtr);
            mMaxParamType = ConversationAPI.GetFunctionStackMaxParamType(ImplementPtr);
            mParamCount   = ConversationAPI.GetFunctionStackParamCount(ImplementPtr);
            for (int i = 0; i < ParamCount; i++)
            {
                mParamTypes.Add(ConversationAPI.GetFunctionStackParamTypeByIndex(ImplementPtr, i));
            }
        }
Exemplo n.º 5
0
        bool HasValue(string name)
        {
            if (name == null || name == "")
            {
                return(false);
            }

            if (mValueTable.ContainsKey(name))
            {
                return(true);
            }

            return(ConversationAPI.SaveHasValue(ImplementPtr, name));
        }
Exemplo n.º 6
0
        private bool disposedValue = false; // 要检测冗余调用

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: 释放托管状态(托管对象)。
                }
                if (mImplementPtr != IntPtr.Zero)
                {
                    ConversationAPI.ReleaseCustomSave(mImplementPtr);
                    mImplementPtr = IntPtr.Zero;
                }
                disposedValue = true;
            }
        }
Exemplo n.º 7
0
 void CopyFrom(SaveBinary binary)
 {
     foreach (ValueBinary vb in binary.Values)
     {
         if (vb.Type == TValue.Boolean)
         {
             ConversationAPI.SetSaveValue(ImplementPtr, vb.Name, vb.bValue);
         }
         else if (vb.Type == TValue.Int)
         {
             ConversationAPI.SetSaveValue(ImplementPtr, vb.Name, vb.iValue);
         }
         else if (vb.Type == TValue.Float)
         {
             ConversationAPI.SetSaveValue(ImplementPtr, vb.Name, vb.fValue);
         }
     }
 }
Exemplo n.º 8
0
        private bool disposedValue = false; // 要检测冗余调用

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: 释放托管状态(托管对象)。
                }

                // TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器。
                // TODO: 将大型字段设置为 null。
                if (mImplementPtr != IntPtr.Zero)
                {
                    ConversationAPI.ReleaseConversation(mImplementPtr);
                    mImplementPtr = IntPtr.Zero;
                    questions.Clear();
                }
                disposedValue = true;
            }
        }
Exemplo n.º 9
0
        internal Question(IntPtr implPtr)
        {
            mImplementPtr = implPtr;
            mName         = ConversationAPI.GetQuestionName(Implement);
            mText         = ConversationAPI.GetQuestionText(Implement);
            int answerCount = ConversationAPI.GetQuestionAnswerCount(Implement);

            mAnswerList = new Answer[answerCount];
            for (int i = 0; i < answerCount; i++)
            {
                IntPtr answerPtr = ConversationAPI.GetQuestionAnswerByIndex(mImplementPtr, i);
                if (answerPtr != IntPtr.Zero)
                {
                    mAnswerList[i] = new Answer(answerPtr);
                }
                else
                {
                    mAnswerList[i] = null;
                }
            }
        }
Exemplo n.º 10
0
        public Question SelectNextConversationBranch(Answer selectedAnswer)
        {
            IntPtr questionPtr = ConversationAPI.SelectNextConversationBranch(mImplementPtr, selectedAnswer.ImplementPtr);

            return(GetQuestion(questionPtr));
        }
Exemplo n.º 11
0
        public Question StartConversation(Context context)
        {
            IntPtr questionPtr = ConversationAPI.StartConversation(context.ImplementPtr, ImplementPtr);

            return(GetQuestion(questionPtr));
        }
Exemplo n.º 12
0
        static public Conversation CreateFromXML(string filePath)
        {
            IntPtr convPtr = ConversationAPI.CreateConversationFromXML(filePath);

            return((convPtr != IntPtr.Zero) ? (new Conversation(convPtr)) : null);
        }
Exemplo n.º 13
0
        internal Conversation(IntPtr implPtr)
        {
            mImplementPtr = implPtr;

            save = new Save(ConversationAPI.GetConversationSave(ImplementPtr));
        }
Exemplo n.º 14
0
 internal Answer(IntPtr implPtr)
 {
     mImplementPtr = implPtr;
     mID           = ConversationAPI.GetAnswerID(mImplementPtr);
     mText         = ConversationAPI.GetAnswerText(mImplementPtr);
 }
Exemplo n.º 15
0
        public string GetValueNameByIndex(int index)
        {
            string name = ConversationAPI.GetSaveValueNameByIndex(ImplementPtr, index);

            return(name);
        }
Exemplo n.º 16
0
 public Save()
 {
     mImplementPtr = ConversationAPI.CreateCustomSave();
 }