story(1) { onmessage(start) { dialog(1); }; onmessage(enterarea, 1) { dialog(2); }; onmessage(enddialog, 2) { createnpc(10,11,12); movenpc(10,vector2(10,20)); aienable(10,11,12); }; onmessage(killnpc,12) { missioncomplete(); }; };
Beispiel #1
0
    public bool ExecCommandWithArgs(StorySystem.StoryInstance instance, StorySystem.StoryMessageHandler handler, System.Int64 delta, System.Object iterator, params object[] args)
    {
        var err = LuaFunctionHelper.BeginCall(m_Cs2Lua_ExecCommandWithArgs);

        LuaFunctionHelper.PushValue(Self);
        LuaFunctionHelper.PushValue(instance);
        LuaFunctionHelper.PushValue(handler);
        LuaFunctionHelper.PushValue(delta);
        LuaFunctionHelper.PushValue(iterator);
        LuaFunctionHelper.PushParams(args);
        var end_call_res = LuaFunctionHelper.EndCall(err);

        if (end_call_res)
        {
            LuaFunctionHelper.BeginGetResult(err);
            bool __cs2lua_ret;
            LuaFunctionHelper.GetResult(out __cs2lua_ret);
            LuaFunctionHelper.EndGetResult();
            return(__cs2lua_ret);
        }
        else
        {
            return(false);
        }
    }
Beispiel #2
0
 static public int Load(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(Dsl.StatementData)))
         {
             StorySystem.StoryMessageHandler self = (StorySystem.StoryMessageHandler)checkSelf(l);
             Dsl.StatementData a1;
             checkType(l, 2, out a1);
             self.Load(a1);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(Dsl.FunctionData)))
         {
             StorySystem.StoryMessageHandler self = (StorySystem.StoryMessageHandler)checkSelf(l);
             Dsl.FunctionData a1;
             checkType(l, 2, out a1);
             self.Load(a1);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #3
0
 static public int get_StackVariables(IntPtr l)
 {
     try {
         StorySystem.StoryMessageHandler self = (StorySystem.StoryMessageHandler)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.StackVariables);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #4
0
 static public int Prepare(IntPtr l)
 {
     try {
         StorySystem.StoryMessageHandler self = (StorySystem.StoryMessageHandler)checkSelf(l);
         self.Prepare();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #5
0
 static public int get_IsTriggered(IntPtr l)
 {
     try {
         StorySystem.StoryMessageHandler self = (StorySystem.StoryMessageHandler)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.IsTriggered);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #6
0
 static public int constructor(IntPtr l)
 {
     try {
         StorySystem.StoryMessageHandler o;
         o = new StorySystem.StoryMessageHandler();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #7
0
 static public int set_IsPaused(IntPtr l)
 {
     try {
         StorySystem.StoryMessageHandler self = (StorySystem.StoryMessageHandler)checkSelf(l);
         bool v;
         checkType(l, 2, out v);
         self.IsPaused = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #8
0
 static public int Trigger(IntPtr l)
 {
     try {
         StorySystem.StoryMessageHandler self = (StorySystem.StoryMessageHandler)checkSelf(l);
         StorySystem.StoryInstance       a1;
         checkType(l, 2, out a1);
         System.Object[] a2;
         checkArray(l, 3, out a2);
         self.Trigger(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    public void Evaluate(StorySystem.StoryInstance instance, StorySystem.StoryMessageHandler handler, StorySystem.StoryValueParams _params)
    {
        var err = LuaFunctionHelper.BeginCall(m_Cs2Lua_Evaluate);

        LuaFunctionHelper.PushValue(Self);
        LuaFunctionHelper.PushValue(instance);
        LuaFunctionHelper.PushValue(handler);
        LuaFunctionHelper.PushValue(_params);
        var end_call_res = LuaFunctionHelper.EndCall(err);

        if (end_call_res)
        {
            LuaFunctionHelper.BeginGetResult(err);
            LuaFunctionHelper.EndGetResult();
        }
        else
        {
        }
    }
Beispiel #10
0
 public bool Execute(StoryInstance instance, StoryMessageHandler handler, long delta, BoxedValue iterator, BoxedValueList args)
 {
     if (IsCompositeCommand)
     {
         try {
             return(ExecCommand(instance, handler, delta, iterator, args));
         }
         catch (Exception ex) {
             GameFramework.LogSystem.Error("AbstractStoryCommand Composite Command ExecCommand Exception:{0}\n{1}", ex.Message, ex.StackTrace);
             return(false);
         }
     }
     else
     {
         if (!m_LastExecResult)
         {
             //重复执行时不需要每个tick都更新变量值,每个命令每次执行,变量值只读取一次。
             try {
                 Evaluate(instance, handler, iterator, args);
             }
             catch (Exception ex) {
                 GameFramework.LogSystem.Error("AbstractStoryCommand Evaluate Exception:{0}\n{1}", ex.Message, ex.StackTrace);
                 return(false);
             }
         }
         try {
             if (instance.IsDebug && ExecDebugger(instance, handler, delta, iterator, args))
             {
                 return(true);
             }
             m_LastExecResult = ExecCommand(instance, handler, delta);
         }
         catch (Exception ex) {
             GameFramework.LogSystem.Error("AbstractStoryCommand ExecCommand Exception:{0}\n{1}", ex.Message, ex.StackTrace);
             m_LastExecResult = false;
         }
         return(m_LastExecResult);
     }
 }
 public bool Execute(StoryInstance instance, StoryMessageHandler handler, long delta, object iterator, object[] args)
 {
     if (!m_LastExecResult)
     {
         //重复执行时不需要每个tick都更新变量值,每个命令每次执行,变量值只读取一次。
         try {
             m_Params.Evaluate(instance, handler, iterator, args);
         } catch (Exception ex) {
             GameFramework.LogSystem.Error("SimpleStoryCommand Evaluate Exception:{0}\n{1}", ex.Message, ex.StackTrace);
             return(false);
         }
     }
     try {
         if (instance.IsDebug && ExecDebugger(instance, handler, delta, iterator, args))
         {
             return(true);
         }
         m_LastExecResult = ExecCommand(instance, (ValueParamType)m_Params, delta);
     } catch (Exception ex) {
         GameFramework.LogSystem.Error("SimpleStoryCommand ExecCommand Exception:{0}\n{1}", ex.Message, ex.StackTrace);
         m_LastExecResult = false;
     }
     return(m_LastExecResult);
 }
Beispiel #12
0
 public void Evaluate(StoryInstance instance, StoryMessageHandler handler, object iterator, object[] args)
 {
     m_Original.Evaluate(instance, handler, iterator, args);
 }
 protected virtual bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta, object iterator, object[] args)
 {
     return(false);
 }
 protected virtual bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
 {
     return(false);
 }
 protected virtual void Evaluate(StoryInstance instance, StoryMessageHandler handler, object iterator, object[] args)
 {
 }
 public void Tick(long curTime)
 {
     if (m_IsPaused)
     {
         m_LastTickTime = curTime;
         return;
     }
     try {
         m_IsInTick = true;
         const int c_MaxMsgCountPerTick           = 256;
         const int c_MaxConcurrentMsgCountPerTick = 256;
         long      delta = 0;
         if (m_LastTickTime == 0)
         {
             m_LastTickTime = curTime;
         }
         else
         {
             delta          = curTime - m_LastTickTime;
             m_LastTickTime = curTime;
             m_CurTime     += delta;
         }
         int ct = m_MessageHandlers.Count;
         for (int ix = ct - 1; ix >= 0; --ix)
         {
             long dt = delta;
             StoryMessageHandler handler = m_MessageHandlers[ix];
             if (handler.IsTriggered)
             {
                 handler.Tick(this, dt);
                 dt = 0;
             }
             if (!handler.IsTriggered)
             {
                 string msgId = handler.MessageId;
                 Queue <MessageInfo> queue;
                 if (m_MessageQueues.TryGetValue(msgId, out queue))
                 {
                     for (int msgCt = 0; msgCt < c_MaxMsgCountPerTick && queue.Count > 0 && !handler.IsTriggered; ++msgCt)
                     {
                         MessageInfo info = queue.Dequeue();
                         UpdateMessageTriggerTime(info.m_MsgId, curTime);
                         handler.Trigger(this, info.m_Args);
                         handler.Tick(this, dt);
                         dt = 0;
                     }
                 }
             }
         }
         ct = m_ConcurrentMessageHandlers.Count;
         int concurrentMsgCt = 0;
         foreach (var pair in m_ConcurrentMessageQueues)
         {
             Queue <MessageInfo> queue = pair.Value;
             if (concurrentMsgCt < c_MaxConcurrentMsgCountPerTick && queue.Count > 0)
             {
                 MessageInfo         info    = queue.Dequeue();
                 StoryMessageHandler handler = NewConcurrentMessageHandler(info.m_MsgId);
                 if (null != handler)
                 {
                     UpdateMessageTriggerTime(info.m_MsgId, curTime);
                     handler.Trigger(this, info.m_Args);
                     handler.Tick(this, 0);
                     if (handler.IsTriggered)
                     {
                         m_ConcurrentMessageHandlers.Add(handler);
                     }
                     else
                     {
                         RecycleConcurrentMessageHandler(handler);
                     }
                 }
             }
         }
         for (int ix = ct - 1; ix >= 0; --ix)
         {
             long dt = delta;
             StoryMessageHandler handler = m_ConcurrentMessageHandlers[ix];
             if (handler.IsTriggered)
             {
                 handler.Tick(this, dt);
                 dt = 0;
             }
             if (!handler.IsTriggered)
             {
                 m_ConcurrentMessageHandlers.RemoveAt(ix);
                 RecycleConcurrentMessageHandler(handler);
             }
         }
     } finally {
         m_IsInTick = false;
     }
 }
Beispiel #17
0
 protected virtual void Evaluate(StoryInstance instance, StoryMessageHandler handler, BoxedValue iterator, BoxedValueList args)
 {
 }
Beispiel #18
0
 protected virtual bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta, BoxedValue iterator, BoxedValueList args)
 {
     return(false);
 }
        public bool Init(Dsl.DslInfo config)
        {
            if (null == config || null == config.First)
            {
                return(false);
            }
            bool ret = false;

            Dsl.FunctionData story = config.First;
            if (story.GetId() == "story" || story.GetId() == "script")
            {
                ret = true;
                Dsl.CallData callData = story.Call;
                if (null != callData && callData.HaveParam())
                {
                    m_StoryId = callData.GetParamId(0);
                }
                for (int i = 0; i < story.Statements.Count; i++)
                {
                    if (story.Statements[i].GetId() == "local")
                    {
                        Dsl.FunctionData sectionData = story.Statements[i] as Dsl.FunctionData;
                        if (null != sectionData)
                        {
                            for (int j = 0; j < sectionData.Statements.Count; j++)
                            {
                                Dsl.CallData defData = sectionData.Statements[j] as Dsl.CallData;
                                if (null != defData && defData.HaveId() && defData.HaveParam())
                                {
                                    string id = defData.GetId();
                                    if (id.StartsWith("@") && !id.StartsWith("@@"))
                                    {
                                        StoryValue val = new StoryValue();
                                        val.InitFromDsl(defData.GetParam(0));
                                        if (!m_PreInitedLocalVariables.ContainsKey(id))
                                        {
                                            m_PreInitedLocalVariables.Add(id, val.Value);
                                        }
                                        else
                                        {
                                            m_PreInitedLocalVariables[id] = val.Value;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
#if DEBUG
                            string err = string.Format("Story {0} DSL, local must be a function ! line:{1} local:{2}", m_StoryId, story.Statements[i].GetLine(), story.Statements[i].ToScriptString(false));
                            throw new Exception(err);
#else
                            LogSystem.Error("Story {0} DSL, local must be a function !", m_StoryId);
#endif
                        }
                    }
                    else if (story.Statements[i].GetId() == "onmessage" || story.Statements[i].GetId() == "onnamespacedmessage")
                    {
                        StoryMessageHandler handler = null;
                        Dsl.StatementData   msgData = story.Statements[i] as Dsl.StatementData;
                        if (null != msgData)
                        {
                            handler = new StoryMessageHandler();
                            handler.Load(msgData);
                        }
                        else
                        {
                            Dsl.FunctionData sectionData = story.Statements[i] as Dsl.FunctionData;
                            if (null != sectionData)
                            {
                                handler = new StoryMessageHandler();
                                handler.Load(sectionData);
                            }
                        }
                        if (null != handler)
                        {
                            string msgId;
                            if (!string.IsNullOrEmpty(m_Namespace) && story.Statements[i].GetId() == "onnamespacedmessage")
                            {
                                msgId             = string.Format("{0}:{1}", m_Namespace, handler.MessageId);
                                handler.MessageId = msgId;
                            }
                            else
                            {
                                msgId = handler.MessageId;
                            }
                            if (!m_LoadedMessageHandlers.ContainsKey(msgId))
                            {
                                m_LoadedMessageHandlers.Add(msgId, handler);
                                m_MessageHandlers.Add(handler.Clone());
                                m_MessageQueues.Add(msgId, new Queue <MessageInfo>());
                                m_ConcurrentMessageQueues.Add(msgId, new Queue <MessageInfo>());
                                m_ConcurrentMessageHandlerPool.Add(msgId, new Queue <StoryMessageHandler>());
                            }
                            else
                            {
#if DEBUG
                                string err = string.Format("Story {0} DSL, onmessage or onnamespacedmessage {1} duplicate, discard it ! line:{2}", m_StoryId, msgId, story.Statements[i].GetLine());
                                throw new Exception(err);
#else
                                LogSystem.Error("Story {0} DSL, onmessage {1} duplicate, discard it !", m_StoryId, msgId);
#endif
                            }
                        }
                        else
                        {
#if DEBUG
                            string err = string.Format("Story {0} DSL, onmessage must be a function or statement ! line:{1} onmessage:{2}", m_StoryId, story.Statements[i].GetLine(), story.Statements[i].ToScriptString(false));
                            throw new Exception(err);
#else
                            LogSystem.Error("Story {0} DSL, onmessage must be a function !", m_StoryId);
#endif
                        }
                    }
                    else
                    {
#if DEBUG
                        string err = string.Format("StoryInstance::Init, Story {0} unknown part {1}, line:{2} section:{3}", m_StoryId, story.Statements[i].GetId(), story.Statements[i].GetLine(), story.Statements[i].ToScriptString(false));
                        throw new Exception(err);
#else
                        LogSystem.Error("StoryInstance::Init, Story {0} unknown part {1}", m_StoryId, story.Statements[i].GetId());
#endif
                    }
                }
            }
            else
            {
#if DEBUG
                string err = string.Format("StoryInstance::Init, isn't story DSL, line:{0} story:{1}", story.GetLine(), story.ToScriptString(false));
                throw new Exception(err);
#else
                LogSystem.Error("StoryInstance::Init, isn't story DSL");
#endif
            }
            LogSystem.Debug("StoryInstance.Init message handler num:{0} {1}", m_MessageHandlers.Count, ret);
            return(ret);
        }
 public void Evaluate(StoryInstance instance, StoryMessageHandler handler, BoxedValue iterator, BoxedValueList args)
 {
 }
Beispiel #21
0
 public void Evaluate(StoryInstance instance, StoryMessageHandler handler, object iterator, object[] args)
 {
 }