Exemplo n.º 1
0
        private static RequirementConfig[] LoadJsonFile(string filename)
        {
            RequirementConfig[] defaultRecipe = new RequirementConfig[] {
                new RequirementConfig()
                {
                    Item    = "FineWood",
                    Amount  = 5,
                    Recover = true
                },
                new RequirementConfig()
                {
                    Item    = "GreydwarfEye",
                    Amount  = 5,
                    Recover = true
                },
                new RequirementConfig()
                {
                    Item    = "SurtlingCore",
                    Amount  = 1,
                    Recover = true
                },
                new RequirementConfig()
                {
                    Item    = "AncientSeed",
                    Amount  = 1,
                    Recover = true
                }
            };
            if (SeedTotem.configCustomRecipe.Value)
            {
                string assetPath = SeedTotemMod.GetAssetPath(filename);
                bool   fileFound = string.IsNullOrEmpty(assetPath);
                if (fileFound)
                {
                    logger.LogWarning("File not found: " + filename + " using default recipe");
                    return(defaultRecipe);
                }

                Dictionary <string, int> reqDict = ReadDict(assetPath);
                RequirementConfig[]      result  = new RequirementConfig[reqDict.Count];
                int i = 0;
                foreach (KeyValuePair <string, int> pair in reqDict)
                {
                    result[i] = new RequirementConfig()
                    {
                        Item    = pair.Key,
                        Amount  = pair.Value,
                        Recover = true
                    };
                }
                return(result);
            }
            else
            {
                return(defaultRecipe);
            }
        }
Exemplo n.º 2
0
        private static void RegisterPrefab(string ResourceName)
        {
            try
            {
                // read the json and parse it into it's respective json class
                string jsonData             = ReadEmbeddedJSON(ResourceName);
                Models.JSON.JSON_Prefab obj = SimpleJson.SimpleJson.DeserializeObject <Models.JSON.JSON_Prefab>(jsonData);
                GameObject prefab           = PrefabBundle.LoadAsset <GameObject>(obj.Prefab);

                switch (obj.Type)
                {
                case "Piece":
                    // create the piece config and prep it
                    var pieceConfig = new PieceConfig();
                    pieceConfig.PieceTable = obj.PieceConfig.PieceTable;

                    // Add the ingredient requirements to the recipe
                    var requirements = new List <RequirementConfig>();
                    foreach (KeyValuePair <string, int> requirement in obj.PieceConfig.Requirements)
                    {
                        var newRequirement = new RequirementConfig();
                        newRequirement.Item   = requirement.Key;
                        newRequirement.Amount = requirement.Value;
                        requirements.Add(newRequirement);
                    }
                    pieceConfig.Requirements = requirements.ToArray();

                    // init the piece and add it to the game with jotunn
                    CustomPiece newPiece = new CustomPiece(prefab, pieceConfig);
                    PieceManager.Instance.AddPiece(newPiece);
                    break;

                case "Item":
                    // init the item and add it to the game with jotunn
                    CustomItem newItem = new CustomItem(prefab, false);
                    ItemManager.Instance.AddItem(newItem);

                    // create the item recipe and prep some details
                    Recipe newRecipe = ScriptableObject.CreateInstance <Recipe>();
                    newRecipe.name              = "Recipe_" + newItem.ItemDrop.name;
                    newRecipe.m_item            = prefab.GetComponent <ItemDrop>();
                    newRecipe.m_craftingStation = Mock <CraftingStation> .Create(obj.RecipeConfig.CraftingStation);

                    // Add the ingredient requirements to the recipe
                    var ingredients = new List <Piece.Requirement>();
                    foreach (KeyValuePair <string, int> ingredient in obj.RecipeConfig.Ingredients)
                    {
                        ingredients.Add(MockRequirement.Create(ingredient.Key, ingredient.Value));
                    }
                    newRecipe.m_resources = ingredients.ToArray();

                    // add the custom recipe to the game with jotunn
                    CustomRecipe customRecipe = new CustomRecipe(newRecipe, true, true);
                    ItemManager.Instance.AddRecipe(customRecipe);
                    break;
                }

                // add the translations to our system list
                foreach (KeyValuePair <string, string> entry in obj.Translations)
                {
                    EnglishTranslations.Add(entry.Key, entry.Value);
                }
            }
            catch (Exception err)
            {
                Console.print("Unable to register prefab: " + ResourceName + " => " + err);
            }
        }