예제 #1
0
 public static Loot ParseLoot(string lootString)
 {
     string[] array = lootString.Split(new string[] { ";" }, StringSplitOptions.None);
     if (array.Length >= 3)
     {
         int  v      = CraftingRecipesManager.DecodeResult(array[0]);
         Loot result = default(Loot);
         result.Value       = v;
         result.MinCount    = int.Parse(array[1], CultureInfo.InvariantCulture);
         result.MaxCount    = int.Parse(array[2], CultureInfo.InvariantCulture);
         result.Probability = ((array.Length >= 4) ? float.Parse(array[3], CultureInfo.InvariantCulture) : 1f);
         return(result);
     }
     throw new InvalidOperationException("Invalid loot string.");
 }
예제 #2
0
파일: ItemBlock.cs 프로젝트: Lixue9jiu/SCIE
        public static void CRInitialize()
        {
            CraftingRecipesManager.m_recipes = new List <CraftingRecipe>();
            var recipes    = new List <CraftingRecipe>();
            var enumerator = ContentManager.CombineXml(ContentManager.Get <XElement>("CraftingRecipes"), ModsManager.GetEntries(".cr"), "Description", "Result", "Recipes").Descendants("Recipe").GetEnumerator();

            while (enumerator.MoveNext())
            {
                XElement xelement       = enumerator.Current;
                var      craftingRecipe = new CraftingRecipe
                {
                    Ingredients = new string[36]
                };
                string attributeValue = XmlUtils.GetAttributeValue <string>(xelement, "Result");
                craftingRecipe.ResultValue = CraftingRecipesManager.DecodeResult(attributeValue);
                craftingRecipe.ResultCount = XmlUtils.GetAttributeValue <int>(xelement, "ResultCount");
                string attributeValue2 = XmlUtils.GetAttributeValue(xelement, "Remains", string.Empty);
                if (!string.IsNullOrEmpty(attributeValue2))
                {
                    craftingRecipe.RemainsValue = CraftingRecipesManager.DecodeResult(attributeValue2);
                    craftingRecipe.RemainsCount = XmlUtils.GetAttributeValue <int>(xelement, "RemainsCount");
                }
                craftingRecipe.RequiredHeatLevel = XmlUtils.GetAttributeValue <float>(xelement, "RequiredHeatLevel");
                craftingRecipe.Description       = XmlUtils.GetAttributeValue <string>(xelement, "Description");
                if (craftingRecipe.ResultCount > BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.ResultValue)].MaxStacking)
                {
                    throw new InvalidOperationException($"In recipe for \"{attributeValue}\" ResultCount is larger than max stacking of result block.");
                }
                if (craftingRecipe.RemainsValue != 0 && craftingRecipe.RemainsCount > BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.RemainsValue)].MaxStacking)
                {
                    throw new InvalidOperationException($"In Recipe for \"{attributeValue2}\" RemainsCount is larger than max stacking of remains block.");
                }
                var dictionary = new Dictionary <char, string>();
                foreach (XAttribute item in xelement.Attributes().Where(CraftingRecipesManager.c._.Initialize_b__3_1))
                {
                    CraftingRecipesManager.DecodeIngredient(item.Value, out string craftingId, out int?data);
                    if (BlocksManager.FindBlocksByCraftingId(craftingId).Length == 0)
                    {
                        throw new InvalidOperationException($"Block with craftingId \"{item.Value}\" not found.");
                    }
                    if (data.HasValue && (data.Value < 0 || data.Value > 262143))
                    {
                        throw new InvalidOperationException($"Data in recipe ingredient \"{item.Value}\" must be between 0 and 0x3FFFF.");
                    }
                    dictionary.Add(item.Name.LocalName[0], item.Value);
                }
                string[] array       = xelement.Value.Trim().Split('\n');
                string[] ingredients = craftingRecipe.Ingredients;
                for (int i = 0; i < array.Length; i++)
                {
                    int num2 = array[i].IndexOf('"');
                    int num3 = array[i].LastIndexOf('"');
                    if (num2 < 0 || num3 < 0 || num3 <= num2)
                    {
                        throw new InvalidOperationException("Invalid recipe line.");
                    }
                    string text = array[i].Substring(num2 + 1, num3 - num2 - 1);
                    for (int j = 0; j < text.Length; j++)
                    {
                        char c = text[j];
                        if (char.IsLower(c))
                        {
                            string text2 = dictionary[c];
                            if (ItemBlock.IdTable.TryGetValue(text2, out int value))
                            {
                                text2 = BlocksManager.Blocks[Terrain.ExtractContents(value)].CraftingId + ":" + Terrain.ExtractData(value);
                            }
                            ingredients[j + i * 6] = text2;
                        }
                    }
                }
                CraftingRecipesManager.m_recipes.Add(craftingRecipe);
                if (craftingRecipe.RequiredHeatLevel >= 300f)
                {
                    CraftingRecipesManager.DecodeIngredient(ingredients[0], out string craftingId, out int?num);
                    if (!num.HasValue)
                    {
                        continue;
                    }
                    recipes.Add(new CraftingRecipe
                    {
                        ResultValue       = Terrain.ReplaceData(BlocksManager.FindBlocksByCraftingId(craftingId)[0].BlockIndex, num.Value),
                        ResultCount       = GetCount(ingredients),
                        RemainsValue      = craftingRecipe.RemainsValue,
                        RemainsCount      = craftingRecipe.RemainsCount,
                        RequiredHeatLevel = 1f,
                        Ingredients       = (string[])ingredients.Clone(),
                        Description       = craftingRecipe.Description + Utils.Get(" (温度过低)")
                    });
                }
            }
            var blocks = BlocksManager.Blocks;

            for (int i = 0; i < blocks.Length; i++)
            {
                using (var enumerator2 = blocks[i].GetProceduralCraftingRecipes().GetEnumerator())
                    while (enumerator2.MoveNext())
                    {
                        var old = enumerator2.Current.Ingredients;
                        if (old.Length == 9)
                        {
                            var ingredients = new string[36];
                            ingredients[0]  = old[0];
                            ingredients[1]  = old[1];
                            ingredients[2]  = old[2];
                            ingredients[6]  = old[3];
                            ingredients[7]  = old[4];
                            ingredients[8]  = old[5];
                            ingredients[12] = old[6];
                            ingredients[13] = old[7];
                            ingredients[14] = old[8];
                            enumerator2.Current.Ingredients = ingredients;
                        }
                        CraftingRecipesManager.m_recipes.Add(enumerator2.Current);
                    }
            }
            CraftingRecipesManager.m_recipes.Sort(CraftingRecipesManager.c._.Initialize_b__3_0);
            CraftingRecipesManager.m_recipes.AddRange(recipes);
        }