Ejemplo n.º 1
0
        /// <summary>
        /// 读取事件表
        /// </summary>
        public static Dictionary <string, MapEvent> GetStaticEvent()
        {
            string path = (Constants.DEBUG ? Constants.EVENT_DEBUG_PATH : Constants.EVENT_PATH) + "Events/";
            Dictionary <string, MapEvent> eventTable = new Dictionary <string, MapEvent>();

            DebugLog.Log("读取事件表");
            foreach (TextAsset text in Resources.LoadAll <TextAsset>(path))
            {
                DebugLog.LogDone("读取:" + text.name);
                JsonData alldata = JsonMapper.ToObject(text.text);
                foreach (JsonData data in alldata)
                {
                    if (data.Contains("事件"))
                    {
                        MapEvent e = new MapEvent(data);
                        try
                        {
                            eventTable.Add(e.name, e);
                        }
                        catch (Exception ee)
                        {
                            DebugLog.LogError(ee + "事件重名,key:" + e.name);
                        }
                    }
                }
            }
            //【注意】具体事件逻辑添加
            LoadStaticEventLogic(eventTable);
            return(eventTable);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化事件的内在逻辑
        /// </summary>
        private static void LoadStaticEventLogic(Dictionary <string, MapEvent> eventTable)
        {
            // 读入事件逻辑文件
            string path = (Constants.DEBUG ? Constants.EVENT_DEBUG_PATH : Constants.EVENT_PATH) + "EventLogic/";

            DebugLog.Log("读取事件逻辑");
            foreach (TextAsset text in Resources.LoadAll <TextAsset>(path))
            {
                DebugLog.LogDone("读取:" + text.name);
                JsonData alldata = JsonMapper.ToObject(text.text);
                if (alldata.Contains("线性事件"))
                {
                    // 线性事件链的处理,对于i > 0, 将前一事件加入后事件的conditionAndEvent中
                    JsonData eventChain = alldata["线性事件"];
                    for (int i = 1; i < eventChain.Count; i++)
                    {
                        string eName = (string)eventChain[i];
                        if (!eventTable.ContainsKey(eName))
                        {
                            DebugLog.LogError("该事件未在库中,key:" + eName);
                        }

                        string prevName = (string)eventChain[i - 1];
                        if (!eventTable.ContainsKey(prevName))
                        {
                            DebugLog.LogError("后置事件未在库中,key:" + eName);
                        }
                        eventTable[eName].conditionAndEvents.Add(prevName);
                    }
                }
                else if (alldata.Contains("特殊条件"))
                {
                    JsonData nonChainEvents = alldata["特殊条件"];
                    foreach (JsonData data in nonChainEvents)
                    {
                        string eName = (string)data["事件"];
                        if (!eventTable.ContainsKey(eName))
                        {
                            DebugLog.LogError("该事件未定义,key:" + eName);
                            continue;
                        }
                        MapEvent me = eventTable[eName];
                        if (data.Contains("前置与"))
                        {
                            foreach (JsonData eventName in data["前置与"])
                            {
                                if (!eventTable.ContainsKey((string)eventName))
                                {
                                    DebugLog.LogError("前置与事件未在库中,key:" + eventName);
                                }
                                me.AddAndEvent((string)eventName);
                            }
                        }

                        if (data.Contains("前置或"))
                        {
                            foreach (JsonData eventName in data["前置或"])
                            {
                                if (!eventTable.ContainsKey((string)eventName))
                                {
                                    DebugLog.LogError("前置非事件未在库中,key:" + eventName);
                                }
                                me.AddOrEvent((string)eventName);
                            }
                        }

                        if (data.Contains("前置非"))
                        {
                            foreach (JsonData eventName in data["前置非"])
                            {
                                if (!eventTable.ContainsKey((string)eventName))
                                {
                                    DebugLog.LogError("前置或事件未在库中,key:" + eventName);
                                }
                                me.AddNotEvent((string)eventName);
                            }
                        }

                        if (data.Contains("选项需求"))
                        {
                            foreach (JsonData selectName in data["选项需求"])
                            {
                                me.AddSelection((string)selectName);
                            }
                        }
                    }
                }
            }
        }