Пример #1
0
        public static bool MatchRecipe(string[] requiredIngredients, string[] actualIngredients)
        {
            var array = new string[36];

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j <= 6; j++)
                {
                    for (int k = 0; k <= 6; k++)
                    {
                        bool flip = i != 0;
                        if (CraftingRecipesManager.TransformRecipe(array, requiredIngredients, k, j, flip))
                        {
                            bool flag = true;
                            for (int l = 0; l < 36; l++)
                            {
                                if (!CraftingRecipesManager.CompareIngredients(array[l], actualIngredients[l]))
                                {
                                    flag = false;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Пример #2
0
 public override void MeasureOverride(Vector2 parentAvailableSize)
 {
     m_blockIconWidget.IsVisible = false;
     m_labelWidget.IsVisible     = false;
     if (!string.IsNullOrEmpty(m_ingredient))
     {
         CraftingRecipesManager.DecodeIngredient(m_ingredient, out string craftingId, out int?data);
         Block[] array = BlocksManager.FindBlocksByCraftingId(craftingId);
         if (array.Length != 0)
         {
             Block block = array[(int)(1.0 * Time.RealTime) % array.Length];
             if (block != null)
             {
                 m_blockIconWidget.Value     = Terrain.MakeBlockValue(block.BlockIndex, 0, data.HasValue ? data.Value : 4);
                 m_blockIconWidget.Light     = 15;
                 m_blockIconWidget.IsVisible = true;
             }
         }
     }
     else if (m_resultValue != 0)
     {
         m_blockIconWidget.Value     = m_resultValue;
         m_blockIconWidget.Light     = 15;
         m_labelWidget.Text          = m_resultCount.ToString();
         m_blockIconWidget.IsVisible = true;
         m_labelWidget.IsVisible     = true;
     }
     base.MeasureOverride(parentAvailableSize);
 }
Пример #3
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.");
 }
Пример #4
0
        public void UpdateCraftingResult()
        {
            int num = int.MaxValue;

            for (int i = 0; i < m_craftingGridSize; i++)
            {
                for (int j = 0; j < m_craftingGridSize; j++)
                {
                    int num2      = i + j * 3;
                    int slotIndex = i + j * m_craftingGridSize;
                    int slotValue = GetSlotValue(slotIndex);
                    int num3      = Terrain.ExtractContents(slotValue);
                    int num4      = Terrain.ExtractData(slotValue);
                    int slotCount = GetSlotCount(slotIndex);
                    if (slotCount > 0)
                    {
                        Block block = BlocksManager.Blocks[num3];
                        m_matchedIngredients[num2] = block.CraftingId + ":" + num4.ToString(CultureInfo.InvariantCulture);
                        num = MathUtils.Min(num, slotCount);
                    }
                    else
                    {
                        m_matchedIngredients[num2] = null;
                    }
                }
            }
            ComponentPlayer componentPlayer = FindInteractingPlayer();
            float           playerLevel     = componentPlayer?.PlayerData.Level ?? 1f;
            CraftingRecipe  craftingRecipe  = CraftingRecipesManager.FindMatchingRecipe(base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true), m_matchedIngredients, 0f, playerLevel);

            if (craftingRecipe != null && craftingRecipe.ResultValue != 0)
            {
                m_matchedRecipe = craftingRecipe;
                m_slots[ResultSlotIndex].Value = craftingRecipe.ResultValue;
                m_slots[ResultSlotIndex].Count = craftingRecipe.ResultCount * num;
            }
            else
            {
                m_matchedRecipe = null;
                m_slots[ResultSlotIndex].Value = 0;
                m_slots[ResultSlotIndex].Count = 0;
            }
            if (craftingRecipe != null && !string.IsNullOrEmpty(craftingRecipe.Message))
            {
                componentPlayer?.ComponentGui.DisplaySmallMessage(craftingRecipe.Message, Color.White, blinking: true, playNotificationSound: true);
            }
        }
        public LoadingScreen()
        {
            WidgetsManager.LoadWidgetContents((Widget)this.ScreenWidget, (object)this, ContentManager.Get <XElement>("Screens/LoadingScreen"));

            LabelWidget ExternalAssemblyInfo = new LabelWidget();

            ExternalAssemblyInfo.Text = "Powered By GScience Studio\n";
            //下列两行代码请勿随意删除
            ExternalAssemblyInfo.Text += "Author:" + Info.author + "\n";
            ExternalAssemblyInfo.Text += "Version:" + Info.version;

            ExternalAssemblyInfo.Color     = Color.LightBlue;
            ExternalAssemblyInfo.FontScale = 0.5f;
            this.ScreenWidget.Children.Add(ExternalAssemblyInfo);

            this.AddLoadAction((Action)(() => CommunityContentManager.Initialize()));
            this.AddLoadAction((Action)(() => MotdManager.Initialize()));
            this.AddLoadAction((Action)(() => LightingManager.Initialize()));
            this.AddLoadAction((Action)(() => StringsManager.LoadStrings()));
            this.AddLoadAction((Action)(() => TextureAtlasManager.LoadAtlases()));
            ReadOnlyList <ContentInfo> readOnlyList = ContentManager.List();

            // ISSUE: explicit reference operation
            using (ReadOnlyList <ContentInfo> .Enumerator enumerator = ((ReadOnlyList <ContentInfo>)@readOnlyList).GetEnumerator())
            {
                // ISSUE: explicit reference operation
                while (((ReadOnlyList <ContentInfo> .Enumerator)@enumerator).MoveNext())
                {
                    // ISSUE: explicit reference operation
                    ContentInfo localContentInfo = ((ReadOnlyList <ContentInfo> .Enumerator)@enumerator).Current;
                    this.AddLoadAction((Action)(() => ContentManager.Get((string)localContentInfo.Name)));
                }
            }
            this.AddLoadAction((Action)(() => DatabaseManager.LoadDatabase()));
            this.AddLoadAction((Action)(() => WorldsManager.Initialize()));
            this.AddLoadAction((Action)(() => BlocksTexturesManager.Initialize()));
            this.AddLoadAction((Action)(() => CharacterSkinsManager.Initialize()));
            this.AddLoadAction((Action)(() => FurniturePacksManager.Initialize()));
            this.AddLoadAction((Action)(() => BlocksManager.Initialize()));
            this.AddLoadAction((Action)(() => CraftingRecipesManager.Initialize()));
            this.AddLoadAction((Action)(() => GScienceStudio.InputManager.Initialize()));
        }
Пример #6
0
        public new void UpdateCraftingResult()
        {
            int num = 2147483647;

            for (int i = 0; i < m_craftingGridSize; i++)
            {
                for (int j = 0; j < m_craftingGridSize; j++)
                {
                    int num2      = i + j * 6;
                    int slotIndex = i + j * m_craftingGridSize;
                    int slotValue = GetSlotValue(slotIndex);
                    int slotCount = GetSlotCount(slotIndex);
                    if (slotCount > 0)
                    {
                        m_matchedIngredients[num2] = BlocksManager.Blocks[Terrain.ExtractContents(slotValue)].CraftingId + ":" + Terrain.ExtractData(slotValue).ToString(CultureInfo.InvariantCulture);
                        num = MathUtils.Min(num, slotCount);
                    }
                    else
                    {
                        m_matchedIngredients[num2] = null;
                    }
                }
            }
            var craftingRecipe = CraftingRecipesManager.FindMatchingRecipe(Utils.SubsystemTerrain, m_matchedIngredients, 0f);

            if (craftingRecipe != null)
            {
                m_matchedRecipe = craftingRecipe;
                m_slots[ResultSlotIndex].Value = craftingRecipe.ResultValue;
                m_slots[ResultSlotIndex].Count = craftingRecipe.ResultCount * num;
            }
            else
            {
                m_matchedRecipe = null;
                m_slots[ResultSlotIndex].Value = 0;
                m_slots[ResultSlotIndex].Count = 0;
            }
        }
Пример #7
0
        public override CraftingRecipe GetAdHocCraftingRecipe(SubsystemTerrain terrain, string[] ingredients, float heatLevel, float playerLevel)
        {
            if (heatLevel < 1f)
            {
                return(null);
            }
            List <string> list = ingredients.Where((string i) => !string.IsNullOrEmpty(i)).ToList();

            if (list.Count == 2)
            {
                int num  = 0;
                int num2 = 0;
                int num3 = 0;
                foreach (string item in list)
                {
                    CraftingRecipesManager.DecodeIngredient(item, out string craftingId, out int?data);
                    if (craftingId == BlocksManager.Blocks[203].CraftingId)
                    {
                        num3 = Terrain.MakeBlockValue(203, 0, data.HasValue ? data.Value : 0);
                    }
                    else if (craftingId == BlocksManager.Blocks[129].CraftingId)
                    {
                        num = Terrain.MakeBlockValue(129, 0, data.HasValue ? data.Value : 0);
                    }
                    else if (craftingId == BlocksManager.Blocks[128].CraftingId)
                    {
                        num2 = Terrain.MakeBlockValue(128, 0, data.HasValue ? data.Value : 0);
                    }
                }
                if (num != 0 && num3 != 0)
                {
                    int   data2         = Terrain.ExtractData(num3);
                    int   clothingColor = GetClothingColor(data2);
                    int   clothingIndex = GetClothingIndex(data2);
                    bool  canBeDyed     = GetClothingData(data2).CanBeDyed;
                    int   damage        = BlocksManager.Blocks[203].GetDamage(num3);
                    int   color         = PaintBucketBlock.GetColor(Terrain.ExtractData(num));
                    int   damage2       = BlocksManager.Blocks[129].GetDamage(num);
                    Block block         = BlocksManager.Blocks[129];
                    Block block2        = BlocksManager.Blocks[203];
                    if (!canBeDyed)
                    {
                        return(null);
                    }
                    int num4 = PaintBucketBlock.CombineColors(clothingColor, color);
                    if (num4 != clothingColor)
                    {
                        return(new CraftingRecipe
                        {
                            ResultCount = 1,
                            ResultValue = block2.SetDamage(Terrain.MakeBlockValue(203, 0, SetClothingIndex(SetClothingColor(0, num4), clothingIndex)), damage),
                            RemainsCount = 1,
                            RemainsValue = BlocksManager.DamageItem(Terrain.MakeBlockValue(129, 0, color), damage2 + MathUtils.Max(block.Durability / 4, 1)),
                            RequiredHeatLevel = 1f,
                            Description = $"{LanguageControl.Get("BlocksManager", "Dyed")} {SubsystemPalette.GetName(terrain, color, null)}",
                            Ingredients = (string[])ingredients.Clone()
                        });
                    }
                }
                if (num2 != 0 && num3 != 0)
                {
                    int   data3          = Terrain.ExtractData(num3);
                    int   clothingColor2 = GetClothingColor(data3);
                    int   clothingIndex2 = GetClothingIndex(data3);
                    bool  canBeDyed2     = GetClothingData(data3).CanBeDyed;
                    int   damage3        = BlocksManager.Blocks[203].GetDamage(num3);
                    int   damage4        = BlocksManager.Blocks[128].GetDamage(num2);
                    Block block3         = BlocksManager.Blocks[128];
                    Block block4         = BlocksManager.Blocks[203];
                    if (!canBeDyed2)
                    {
                        return(null);
                    }
                    if (clothingColor2 != 0)
                    {
                        return(new CraftingRecipe
                        {
                            ResultCount = 1,
                            ResultValue = block4.SetDamage(Terrain.MakeBlockValue(203, 0, SetClothingIndex(SetClothingColor(0, 0), clothingIndex2)), damage3),
                            RemainsCount = 1,
                            RemainsValue = BlocksManager.DamageItem(Terrain.MakeBlockValue(128, 0, 0), damage4 + MathUtils.Max(block3.Durability / 4, 1)),
                            RequiredHeatLevel = 1f,
                            Description = LanguageControl.Get("BlocksManager", "Not Dyed") + " " + LanguageControl.Get("BlocksManager", "Clothes"),
                            Ingredients = (string[])ingredients.Clone()
                        });
                    }
                }
            }
            return(null);
        }
Пример #8
0
        public override CraftingRecipe GetAdHocCraftingRecipe(SubsystemTerrain subsystemTerrain, string[] ingredients, float heatLevel, float playerLevel)
        {
            if (heatLevel < 1f)
            {
                return(null);
            }
            List <string> list = ingredients.Where((string i) => !string.IsNullOrEmpty(i)).ToList();

            if (list.Count == 2)
            {
                int num  = 0;
                int num2 = 0;
                int num3 = 0;
                foreach (string item in list)
                {
                    CraftingRecipesManager.DecodeIngredient(item, out string craftingId, out int?data);
                    if (craftingId == BlocksManager.Blocks[208].CraftingId)
                    {
                        num3 = Terrain.MakeBlockValue(208, 0, data.HasValue ? data.Value : 0);
                    }
                    else if (craftingId == BlocksManager.Blocks[129].CraftingId)
                    {
                        num = Terrain.MakeBlockValue(129, 0, data.HasValue ? data.Value : 0);
                    }
                    else if (craftingId == BlocksManager.Blocks[128].CraftingId)
                    {
                        num2 = Terrain.MakeBlockValue(128, 0, data.HasValue ? data.Value : 0);
                    }
                }
                if (num != 0 && num3 != 0)
                {
                    int   num4   = Terrain.ExtractData(num3);
                    int   color  = PaintBucketBlock.GetColor(Terrain.ExtractData(num));
                    int   damage = BlocksManager.Blocks[129].GetDamage(num);
                    Block block  = BlocksManager.Blocks[129];
                    int   num5   = PaintBucketBlock.CombineColors(num4, color);
                    if (num5 != num4)
                    {
                        return(new CraftingRecipe
                        {
                            ResultCount = 1,
                            ResultValue = Terrain.MakeBlockValue(208, 0, num5),
                            RemainsCount = 1,
                            RemainsValue = BlocksManager.DamageItem(Terrain.MakeBlockValue(129, 0, color), damage + MathUtils.Max(block.Durability / 4, 1)),
                            RequiredHeatLevel = 1f,
                            Description = $"Dye carpet {SubsystemPalette.GetName(subsystemTerrain, color, null)}",
                            Ingredients = (string[])ingredients.Clone()
                        });
                    }
                }
                if (num2 != 0 && num3 != 0)
                {
                    int   num6    = Terrain.ExtractData(num3);
                    int   damage2 = BlocksManager.Blocks[128].GetDamage(num2);
                    Block block2  = BlocksManager.Blocks[128];
                    if (num6 != 0)
                    {
                        return(new CraftingRecipe
                        {
                            ResultCount = 1,
                            ResultValue = Terrain.MakeBlockValue(208, 0, 0),
                            RemainsCount = 1,
                            RemainsValue = BlocksManager.DamageItem(Terrain.MakeBlockValue(128, 0, 0), damage2 + MathUtils.Max(block2.Durability / 4, 1)),
                            RequiredHeatLevel = 1f,
                            Description = "Undye carpet",
                            Ingredients = (string[])ingredients.Clone()
                        });
                    }
                }
            }
            return(null);
        }
Пример #9
0
        public static CraftingRecipe GetAdHocCraftingRecipe(int index, SubsystemTerrain subsystemTerrain, string[] ingredients, float heatLevel)
        {
            if (heatLevel < 1f)
            {
                return(null);
            }
            int i = 0, num = 0;
            var array = new string[2];

            for (; i < ingredients.Length; i++)
            {
                if (!string.IsNullOrEmpty(ingredients[i]))
                {
                    if (num > 1)
                    {
                        return(null);
                    }
                    array[num] = ingredients[i];
                    num++;
                }
            }
            if (num != 2)
            {
                return(null);
            }
            num = 0;
            int num2 = 0;
            int num3 = 0;

            for (i = 0; i < array.Length; i++)
            {
                string item = array[i];
                CraftingRecipesManager.DecodeIngredient(item, out string craftingId, out int?data);
                int d = data ?? 0;
                if (craftingId == BlocksManager.Blocks[index].CraftingId)
                {
                    num3 = Terrain.MakeBlockValue(index, 0, d);
                }
                else if (craftingId == BlocksManager.Blocks[129].CraftingId)
                {
                    num = Terrain.MakeBlockValue(129, 0, d);
                }
                else if (craftingId == BlocksManager.Blocks[128].CraftingId)
                {
                    num2 = Terrain.MakeBlockValue(128, 0, d);
                }
            }
            if (num != 0 && num3 != 0)
            {
                int num4  = GetColor(Terrain.ExtractData(num3));
                int color = PaintBucketBlock.GetColor(Terrain.ExtractData(num));
                int num5  = PaintBucketBlock.CombineColors(num4, color);
                if (num5 != num4)
                {
                    return(new CraftingRecipe
                    {
                        ResultCount = 1,
                        ResultValue = Terrain.MakeBlockValue(index, 0, SetColor(Terrain.ExtractData(num3), num5)),
                        RemainsCount = 1,
                        RemainsValue = BlocksManager.DamageItem(Terrain.MakeBlockValue(129, 0, color), BlocksManager.Blocks[129].GetDamage(num) + 1),
                        RequiredHeatLevel = 1f,
                        Description = "Dye tool " + SubsystemPalette.GetName(subsystemTerrain, color, null),
                        Ingredients = (string[])ingredients.Clone()
                    });
                }
            }
            if (num2 != 0 && num3 != 0)
            {
                if (GetColor(num3) != 0)
                {
                    return(new CraftingRecipe
                    {
                        ResultCount = 1,
                        ResultValue = Terrain.MakeBlockValue(index, 0, SetColor(Terrain.ExtractData(num3), 0)),
                        RemainsCount = 1,
                        RemainsValue = BlocksManager.DamageItem(128, BlocksManager.Blocks[128].GetDamage(num2) + 1),
                        RequiredHeatLevel = 1f,
                        Description = "Undye tool",
                        Ingredients = (string[])ingredients.Clone()
                    });
                }
            }
            return(null);
        }
Пример #10
0
        public LoadingScreen()
        {
            XElement node = ContentManager.Get <XElement>("Screens/LoadingScreen");

            LoadContents(this, node);
            AddLoadAction(delegate
            {
                VrManager.Initialize();
            });
            AddLoadAction(delegate
            {
                CommunityContentManager.Initialize();
            });
            AddLoadAction(delegate
            {
                MotdManager.Initialize();
            });
            AddLoadAction(delegate
            {
                LightingManager.Initialize();
            });
            AddLoadAction(delegate
            {
                StringsManager.LoadStrings();
            });
            AddLoadAction(delegate
            {
                TextureAtlasManager.LoadAtlases();
            });
            foreach (ContentInfo item in ContentManager.List())
            {
                ContentInfo localContentInfo = item;
                AddLoadAction(delegate
                {
                    ContentManager.Get(localContentInfo.Name);
                });
            }
            AddLoadAction(delegate
            {
                DatabaseManager.Initialize();
            });
            AddLoadAction(delegate
            {
                WorldsManager.Initialize();
            });
            AddLoadAction(delegate
            {
                BlocksTexturesManager.Initialize();
            });
            AddLoadAction(delegate
            {
                CharacterSkinsManager.Initialize();
            });
            AddLoadAction(delegate
            {
                FurniturePacksManager.Initialize();
            });
            AddLoadAction(delegate
            {
                BlocksManager.Initialize();
            });
            AddLoadAction(delegate
            {
                CraftingRecipesManager.Initialize();
            });
            AddLoadAction(delegate
            {
                MusicManager.CurrentMix = MusicManager.Mix.Menu;
            });
        }
Пример #11
0
 public CraftingRecipe FindSmeltingRecipe(float heatLevel)
 {
     if (heatLevel > 0f)
     {
         for (int i = 0; i < m_furnaceSize; i++)
         {
             int slotValue = GetSlotValue(i);
             int num       = Terrain.ExtractContents(slotValue);
             int num2      = Terrain.ExtractData(slotValue);
             if (GetSlotCount(i) > 0)
             {
                 Block block = BlocksManager.Blocks[num];
                 m_matchedIngredients[i] = block.CraftingId + ":" + num2.ToString(CultureInfo.InvariantCulture);
             }
             else
             {
                 m_matchedIngredients[i] = null;
             }
         }
         ComponentPlayer componentPlayer = FindInteractingPlayer();
         float           playerLevel     = componentPlayer?.PlayerData.Level ?? 1f;
         CraftingRecipe  craftingRecipe  = null;
         craftingRecipe = CraftingRecipesManager.FindMatchingRecipe(m_subsystemTerrain, m_matchedIngredients, heatLevel, playerLevel);
         if (craftingRecipe != null && craftingRecipe.ResultValue != 0)
         {
             if (craftingRecipe.RequiredHeatLevel <= 0f)
             {
                 craftingRecipe = null;
             }
             if (craftingRecipe != null)
             {
                 Slot slot = m_slots[ResultSlotIndex];
                 int  num3 = Terrain.ExtractContents(craftingRecipe.ResultValue);
                 if (slot.Count != 0 && (craftingRecipe.ResultValue != slot.Value || craftingRecipe.ResultCount + slot.Count > BlocksManager.Blocks[num3].MaxStacking))
                 {
                     craftingRecipe = null;
                 }
             }
             if (craftingRecipe != null && craftingRecipe.RemainsValue != 0 && craftingRecipe.RemainsCount > 0)
             {
                 if (m_slots[RemainsSlotIndex].Count == 0 || m_slots[RemainsSlotIndex].Value == craftingRecipe.RemainsValue)
                 {
                     if (BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.RemainsValue)].MaxStacking - m_slots[RemainsSlotIndex].Count < craftingRecipe.RemainsCount)
                     {
                         craftingRecipe = null;
                     }
                 }
                 else
                 {
                     craftingRecipe = null;
                 }
             }
         }
         if (craftingRecipe != null && !string.IsNullOrEmpty(craftingRecipe.Message))
         {
             componentPlayer?.ComponentGui.DisplaySmallMessage(craftingRecipe.Message, Color.White, blinking: true, playNotificationSound: true);
         }
         return(craftingRecipe);
     }
     return(null);
 }
Пример #12
0
        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);
        }
Пример #13
0
        public override CraftingRecipe GetAdHocCraftingRecipe(SubsystemTerrain terrain, string[] ingredients, float heatLevel, float playerLevel)
        {
            if (heatLevel != 0f)
            {
                return(null);
            }
            int num  = 0;
            int num2 = 0;
            int num3 = 0;
            List <FurnitureDesign> list = new List <FurnitureDesign>();

            for (int i = 0; i < ingredients.Length; i++)
            {
                if (string.IsNullOrEmpty(ingredients[i]))
                {
                    continue;
                }
                CraftingRecipesManager.DecodeIngredient(ingredients[i], out string craftingId, out int?data);
                if (craftingId == BlocksManager.Blocks[227].CraftingId)
                {
                    FurnitureDesign design = terrain.SubsystemFurnitureBlockBehavior.GetDesign(GetDesignIndex(data.GetValueOrDefault()));
                    if (design == null)
                    {
                        return(null);
                    }
                    list.Add(design);
                }
                else if (craftingId == BlocksManager.Blocks[142].CraftingId)
                {
                    num++;
                }
                else if (craftingId == BlocksManager.Blocks[141].CraftingId)
                {
                    num2++;
                }
                else
                {
                    if (!(craftingId == BlocksManager.Blocks[133].CraftingId))
                    {
                        return(null);
                    }
                    num3++;
                }
            }
            if (list.Count == 1 && num == 1 && num2 == 0 && num3 == 0)
            {
                FurnitureDesign furnitureDesign = list[0].Clone();
                furnitureDesign.InteractionMode = FurnitureInteractionMode.ElectricButton;
                FurnitureDesign furnitureDesign2 = terrain.SubsystemFurnitureBlockBehavior.TryAddDesignChain(furnitureDesign, garbageCollectIfNeeded: true);
                if (furnitureDesign2 == null)
                {
                    DisplayError();
                    return(null);
                }
                return(new CraftingRecipe
                {
                    ResultValue = Terrain.MakeBlockValue(227, 0, SetDesignIndex(0, furnitureDesign2.Index, furnitureDesign2.ShadowStrengthFactor, furnitureDesign2.IsLightEmitter)),
                    ResultCount = 1,
                    Description = "Combine furniture into interactive design",
                    Ingredients = (string[])ingredients.Clone()
                });
            }
            if (list.Count == 2 && num == 0 && num2 == 1 && num3 == 0)
            {
                List <FurnitureDesign> list2 = list.Select((FurnitureDesign d) => d.Clone()).ToList();
                for (int j = 0; j < list2.Count; j++)
                {
                    list2[j].InteractionMode = FurnitureInteractionMode.ElectricSwitch;
                    list2[j].LinkedDesign    = list2[(j + 1) % list2.Count];
                }
                FurnitureDesign furnitureDesign3 = terrain.SubsystemFurnitureBlockBehavior.TryAddDesignChain(list2[0], garbageCollectIfNeeded: true);
                if (furnitureDesign3 == null)
                {
                    DisplayError();
                    return(null);
                }
                return(new CraftingRecipe
                {
                    ResultValue = Terrain.MakeBlockValue(227, 0, SetDesignIndex(0, furnitureDesign3.Index, furnitureDesign3.ShadowStrengthFactor, furnitureDesign3.IsLightEmitter)),
                    ResultCount = 1,
                    Description = "Combine furniture into interactive design",
                    Ingredients = (string[])ingredients.Clone()
                });
            }
            if (list.Count >= 2 && num == 0 && num2 == 0 && num3 <= 1)
            {
                List <FurnitureDesign> list3 = list.Select((FurnitureDesign d) => d.Clone()).ToList();
                for (int k = 0; k < list3.Count; k++)
                {
                    list3[k].InteractionMode = ((num3 == 0) ? FurnitureInteractionMode.Multistate : FurnitureInteractionMode.ConnectedMultistate);
                    list3[k].LinkedDesign    = list3[(k + 1) % list3.Count];
                }
                FurnitureDesign furnitureDesign4 = terrain.SubsystemFurnitureBlockBehavior.TryAddDesignChain(list3[0], garbageCollectIfNeeded: true);
                if (furnitureDesign4 == null)
                {
                    DisplayError();
                    return(null);
                }
                return(new CraftingRecipe
                {
                    ResultValue = Terrain.MakeBlockValue(227, 0, SetDesignIndex(0, furnitureDesign4.Index, furnitureDesign4.ShadowStrengthFactor, furnitureDesign4.IsLightEmitter)),
                    ResultCount = 1,
                    Description = "Combine furniture into interactive design",
                    Ingredients = (string[])ingredients.Clone()
                });
            }
            return(null);
        }