Example #1
0
        //private static void CreateRecipes(JArray recipeArray) {
        //  foreach (JObject jRecipe in recipeArray) {
        //    CreateRecipePrototype(jRecipe);

        //  }

        //}

        private static void CreateRecipePrototype(JObject jRecipe)
        {
            Recipe recipe = new Recipe();

            recipe.name     = Funcs.jsonGetString(jRecipe["name"], "");
            recipe.niceName = Funcs.jsonGetString(jRecipe["niceName"], "");
            //recipe.id = Funcs.jsonGetInt(jRecipe["id"], -1);
            recipe.buildTime = Funcs.jsonGetFloat(jRecipe["buildTime"], 1);

            recipe.products  = new Dictionary <string, RecipeProduct>();
            recipe.resources = new Dictionary <string, RecipeResource>();
            recipe.cost      = Funcs.jsonGetFloat(jRecipe["cost"], 0);
            recipe.onDemand  = Funcs.jsonGetBool(jRecipe["onDemand"], false);
            recipe.btnText   = Funcs.jsonGetString(jRecipe["btnText"], "");

            JArray jaResources = Funcs.jsonGetArray(jRecipe, "resources");

            if (jaResources != null)
            {
                foreach (JObject jResource in jaResources)
                {
                    string rname = Funcs.jsonGetString(jResource["name"], null);
                    int    rqty  = Funcs.jsonGetInt(jResource["qty"], -1);



                    if (rname != null && rqty > 0)
                    {
                        RecipeResource r = new RecipeResource(rname, rqty);

                        recipe.resources[rname] = r;
                    }
                }
            }


            JArray jaProducts = Funcs.jsonGetArray(jRecipe, "products");

            if (jaProducts != null)
            {
                foreach (JObject jProduct in jaProducts)
                {
                    string rname   = Funcs.jsonGetString(jProduct["name"], null);
                    int    rminQty = Funcs.jsonGetInt(jProduct["qtyMin"], -1);
                    int    rmaxQty = Funcs.jsonGetInt(jProduct["qtyMax"], -1);
                    float  rchance = Funcs.jsonGetFloat(jProduct["chance"], 0);



                    if (rname != null && rminQty >= 0 && rmaxQty > 0)
                    {
                        RecipeProduct r = new RecipeProduct(rname, rminQty, rmaxQty, rchance);

                        recipe.products[rname] = r;
                    }
                }
            }

            recipes[recipe.name] = recipe;
            //Debug.Log("recipe Added: " + recipe.ToString(true) + " " + recipe.buildTime);
        }
Example #2
0
 public RecipeResource(RecipeResource o)
 {
     this.name         = o.name;
     this.qtyRequired  = o.qtyRequired;
     this.qtyRemaining = o.qtyRequired;
 }