public static string GetSpice(string input, string lookfor)
 {
     HistoricSpice.Init();
     input   = input.ToLower();
     lookfor = lookfor.ToLower();
     return(HistoricSpice.root["elements"][input][lookfor][Stat.Rnd2.Next(HistoricSpice.root["elements"][input][lookfor].Count)]);
 }
Esempio n. 2
0
        public static bool Patch(string filename)
        {
            if (loadedPatches.ContainsKey(filename))
            {
                return(true);
            }

            HistoricSpice.CheckInit();

            Logger.gameLog.Info("Loading spice patch: " + filename);

            string Data = "";

            using (StreamReader sr = XRL.DataManager.GetStreamingAssetsStreamReader(filename))
            {
                Data = sr.ReadToEnd();
            }

            if (Data != "")
            {
                // Strip comments
                Data = Regex.Replace(Data, "//.*$", "", RegexOptions.Multiline);


                JSONClass patch = (JSON.Parse(Data) as JSONClass)["spice"] as JSONClass;

                foreach (KeyValuePair <string, JSONNode> child in patch.ChildNodes)
                {
                    // Resolve relative links in the loaded ruleset
                    List <string> parents = new List <string>();
                    parents.Add("spice");
                    parents.Add(child.Key);
                    ResolveRelativeLinks(parents, child.Value);
                    parents.RemoveAt(parents.Count - 1);

                    // Inject the ruleset into HistoricSpice.
                    if (HistoricSpice.roots.ContainsKey(child.Key))
                    {
                        // Merge with an existing root..?
                        //UnityEngine.Debug.Log("   ...Ignoring already-existing root '" + child.Key
                        //    + "'... JSON merge is not supported.");
                        Logger.gameLog.Info("| ...Merge root '" + child.Key + "'.");
                        int errors = MergeJSON(child.Key, HistoricSpice.roots[child.Key], child.Value);
                        if (errors != 0)
                        {
                            Logger.gameLog.Info("| ...Merged, but with " + errors.ToString() + " errors.");
                        }
                    }
                    else
                    {
                        // Simply add the new root
                        Logger.gameLog.Info("| ...Add root '" + child.Key + "'.");
                        HistoricSpice.roots.Add(child.Key, child.Value);
                        HistoricSpice.root.Add(child.Key, child.Value);

                        foreach (KeyValuePair <string, JSONNode> grandchild in
                                 (HistoricSpice.roots[child.Key] as JSONClass).ChildNodes)
                        {
                            Logger.gameLog.Info("| | ...Grandchild: " + grandchild.Key);
                        }
                    }
                }

                Logger.gameLog.Info("Applied spice patch: " + filename);
                loadedPatches.Add(filename, true);
                return(true);
            }
            else
            {
                Logger.gameLog.Info("Failed to load spice patch: " + filename);
                loadedPatches.Add(filename, false);
                return(false);
            }
        }