Ejemplo n.º 1
0
        private void CreateItem(string codename, int maxstack, LocalizedString name, LocalizedString desc, string guidstring, string recipecategoryname, Sprite icon)
        {
            var recipecategory = GameResources.Instance.Items.FirstOrDefault(s => s.name == recipecategoryname);

            var item = ScriptableObject.CreateInstance <ItemDefinition>();

            item.name     = codename;
            item.Category = recipecategory.Category;
            item.MaxStack = maxstack;
            item.Icon     = icon;
            LocalizedString nameStr = name;
            LocalizedString descStr = desc;

            Initialize(ref nameStr);
            Initialize(ref descStr);

            typeof(ItemDefinition).GetField("m_name", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, nameStr);
            typeof(ItemDefinition).GetField("m_description", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, descStr);

            var guid = GUID.Parse(guidstring);

            typeof(Definition).GetField("m_assetId", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, guid);

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = item, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);

            using (StreamWriter writer = new StreamWriter(QuestingMod.path, true))
            {
                writer.WriteLine("[Questing Update | Items]: Item " + codename + " has been loaded");
                writer.Dispose();
            }
        }
Ejemplo n.º 2
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Creates an item. </summary>
        ///
        /// <remarks>   MelodicAlbuild, 3/8/2021. </remarks>
        ///
        /// <param name="codename">             The codename. </param>
        /// <param name="maxstack">             The maxstack. </param>
        /// <param name="name">                 The name. </param>
        /// <param name="desc">                 The description. </param>
        /// <param name="guidstring">           The guidstring. </param>
        /// <param name="recipecategoryname">   The recipecategoryname. </param>
        /// <param name="icon">                 The icon. </param>
        ///-------------------------------------------------------------------------------------------------

        public static void CreateItem(string codename, int maxstack, LocalizedString name, LocalizedString desc, string guidstring, string recipecategoryname, Sprite icon)
        {
            var recipecategory = GameResources.Instance.Items.FirstOrDefault(s => s.name == recipecategoryname);

            var item = ScriptableObject.CreateInstance <ItemDefinition>();

            item.name     = codename;
            item.Category = recipecategory.Category;
            item.MaxStack = maxstack;
            item.Icon     = icon;
            LocalizedString nameStr = name;
            LocalizedString descStr = desc;

            Initialize(ref nameStr);
            Initialize(ref descStr);

            typeof(ItemDefinition).GetField("m_name", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, nameStr);
            typeof(ItemDefinition).GetField("m_description", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, descStr);

            var guid = GUID.Parse(guidstring);

            typeof(Definition).GetField("m_assetId", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, guid);

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = item, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);
        }
Ejemplo n.º 3
0
        private void CreateRecipe(string recipeName, data.Input[] inputs, Output[] outputs, string baseRecipe, string itemId, string[] requiredItems, string recipeCategory)
        {
            var outputItem = GameResources.Instance.Items.FirstOrDefault(s => s.name == outputs[0].output_name);
            var finalInput = new InventoryItemData[inputs.Length];
            var i          = 0;

            foreach (data.Input input in inputs)
            {
                var itemVar = GameResources.Instance.Items.FirstOrDefault(s => s.name == input.input_name);
                finalInput[i] = new InventoryItemData {
                    Item = itemVar, Amount = input.input_amount
                };
                i++;
            }

            var recipe = ScriptableObject.CreateInstance <Recipe>();

            recipe.name   = recipeName;
            recipe.Inputs = finalInput;
            recipe.Output = new InventoryItemData {
                Item = outputItem, Amount = outputs[0].output_amount
            };
            if (requiredItems[0] != "")
            {
                var requiredFinal = new ItemDefinition[inputs.Length];
                var iReq          = 0;
                foreach (string item in requiredItems)
                {
                    var instanceVar = GameResources.Instance.Items.FirstOrDefault(s => s.name == item);
                    requiredFinal[iReq] = instanceVar;
                    iReq++;
                }
                recipe.RequiredUpgrades = requiredFinal;
            }
            else
            {
                var baseRecipeTag = GameResources.Instance.Recipes.FirstOrDefault(s => s.name == baseRecipe);
                recipe.RequiredUpgrades = baseRecipeTag.RequiredUpgrades;
            }
            if (recipeCategory != "")
            {
                recipe.Categories = new RecipeCategory[] { FindCategories(recipeCategory) };
            }
            else
            {
                var baseRecipeTag = GameResources.Instance.Recipes.FirstOrDefault(s => s.name == baseRecipe);
                recipe.Categories = baseRecipeTag.Categories.ToArray();
            }

            var guid = GUID.Parse(itemId);

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = recipe, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);

            QuestingDict.questingRegistry[recipeName] = guid;
            QuestLog.Log("[Questing Update | Recipes]: Recipe " + recipeName + " has been Loaded");
        }
Ejemplo n.º 4
0
        private void CreateRecipe(RecipeCategory recipeCategory, string recipeName, string inputName1, string inputName2, string outputName, string baseRecipeName, int inputAmount1, int inputAmount2, int outputAmount, string itemId)
        {
            var input1     = GameResources.Instance.Items.FirstOrDefault(s => s.name == inputName1);
            var input2     = GameResources.Instance.Items.FirstOrDefault(s => s.name == inputName2);
            var output     = GameResources.Instance.Items.FirstOrDefault(s => s.name == outputName);
            var baseRecipe = GameResources.Instance.Recipes.FirstOrDefault(s => s.name == baseRecipeName);

            var recipe = ScriptableObject.CreateInstance <Recipe>();

            recipe.name   = recipeName;
            recipe.Inputs = new InventoryItemData[] { new InventoryItemData {
                                                          Item = input1, Amount = inputAmount1
                                                      }, new InventoryItemData {
                                                          Item = input2, Amount = inputAmount2
                                                      } };
            recipe.Output = new InventoryItemData {
                Item = output, Amount = outputAmount
            };
            recipe.RequiredUpgrades = baseRecipe.RequiredUpgrades;

            recipe.Categories = new RecipeCategory[] { recipeCategory };

            var guid = GUID.Parse(itemId);

            typeof(Definition).GetField("m_assetId", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(recipe, guid);

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = recipe, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);

            QuestingDict.questingRegistry[recipeName] = guid;
            QuestLog.Log("[Questing Update | Recipes]: Recipe " + recipeName + " has been Loaded");
        }
Ejemplo n.º 5
0
        private void CreateStation(FactoryType factoryType, string codename, int maxStack, LocalizedString name, LocalizedString desc, string guidString, Sprite icon, string variantname, RecipeCategory[] categories)
        {
            var category = GameResources.Instance.Items.FirstOrDefault(s => s.AssetId == productionStationGUID)?.Category;
            var item     = ScriptableObject.CreateInstance <ItemDefinition>();

            if (item == null)
            {
                Debug.Log("Item is null"); return;
            }
            if (category == null)
            {
                Debug.Log("Category is null"); return;
            }
            item.name     = codename;
            item.Category = category;
            item.MaxStack = maxStack;
            item.Icon     = icon;

            var prefabParent = new GameObject();
            var olditem      = GameResources.Instance.Items.FirstOrDefault(s => s.AssetId == productionStationGUID);

            prefabParent.SetActive(false);
            var newmodule = Instantiate(olditem.Prefabs[0], prefabParent.transform);
            var module    = newmodule.GetComponentInChildren <FactoryStation>();
            var producer  = newmodule.GetComponentInChildren <Producer>();

            newmodule.SetName("AlloyForgeStation");
            var gridmodule = newmodule.GetComponent <GridModule>();

            gridmodule.VariantName = variantname;
            gridmodule.Item        = item;

            var productionGroup = QuestingReferences.GetOrCreateTyping(factoryType);

            LocalizedString nameStr = name;
            LocalizedString descStr = desc;

            Initialize(ref nameStr);
            Initialize(ref descStr);

            item.SetPrivateField("m_name", nameStr);
            item.SetPrivateField("m_description", descStr);
            typeof(FactoryStation).GetField("m_factoryType", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, factoryType);
            typeof(FactoryStation).GetField("m_productionGroup", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, productionGroup);
            typeof(Producer).GetField("m_categories", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(producer, categories);

            var guid = GUID.Parse(guidString);

            typeof(Definition).GetField("m_assetId", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, guid);

            item.Prefabs = new GameObject[] { newmodule };

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = item, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);

            QuestingDict.questingRegistry[codename] = guid;
        }
Ejemplo n.º 6
0
        private void CreateRecipe(string recipeName, string inputName, string outputName, string baseRecipeName, int inputAmount, int outputAmount, string itemId, RecipeCategory recipeCategory)
        {
            var input      = GameResources.Instance.Items.FirstOrDefault(s => s.name == inputName);
            var output     = GameResources.Instance.Items.FirstOrDefault(s => s.name == outputName);
            var baseRecipe = GameResources.Instance.Recipes.FirstOrDefault(s => s.name == baseRecipeName);

            var recipe = ScriptableObject.CreateInstance <Recipe>();

            recipe.name   = recipeName;
            recipe.Inputs = new InventoryItemData[] { new InventoryItemData {
                                                          Item = input, Amount = inputAmount
                                                      } };
            recipe.Output = new InventoryItemData {
                Item = output, Amount = outputAmount
            };
            recipe.RequiredUpgrades = baseRecipe.RequiredUpgrades;

            recipe.Categories = new RecipeCategory[] { recipeCategory };

            var guid = GUID.Parse(itemId);

            typeof(Definition).GetField("m_assetId", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(recipe, guid);

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = recipe, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);
            using (StreamWriter writer = new StreamWriter(QuestingMod.path, true))
            {
                writer.WriteLine("[Questing Update | Recipes]: Recipe " + recipeName + " has been Loaded");
                writer.Dispose();
            }
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Creates a recipe. </summary>
        ///
        /// <remarks>   MelodicAlbuild, 3/8/2021. </remarks>
        ///
        /// <param name="recipeName">       Name of the recipe. </param>
        /// <param name="inputs">           The inputs. </param>
        /// <param name="outputs">          The outputs. </param>
        /// <param name="baseRecipe">       The base recipe. </param>
        /// <param name="itemId">           Identifier for the item. </param>
        /// <param name="requiredItems">    The required items. </param>
        /// <param name="recipeCategory">   Category the recipe belongs to. </param>
        ///-------------------------------------------------------------------------------------------------

        public static void CreateRecipe(string recipeName, classes.Input[] inputs, object[] outputs, string baseRecipe, string itemId, string[] requiredItems, string recipeCategory)
        {
            var outputItem = GameResources.Instance.Items.FirstOrDefault(s => s.name == outputs[0].ToString());
            var finalInput = new InventoryItemData[inputs.Length];
            var i          = 0;

            foreach (classes.Input input in inputs)
            {
                var itemVar = GameResources.Instance.Items.FirstOrDefault(s => s.name == input.input_name);
                finalInput[i] = new InventoryItemData {
                    Item = itemVar, Amount = input.input_amount
                };
                i++;
            }

            var recipe = ScriptableObject.CreateInstance <Recipe>();

            recipe.name   = recipeName;
            recipe.Inputs = finalInput;
            recipe.Output = new InventoryItemData {
                Item = outputItem, Amount = Convert.ToInt32(outputs[1])
            };
            if (requiredItems[0] != "")
            {
                var requiredFinal = new ItemDefinition[inputs.Length];
                var iReq          = 0;
                foreach (string item in requiredItems)
                {
                    var instanceVar = GameResources.Instance.Items.FirstOrDefault(s => s.name == item);
                    requiredFinal[iReq] = instanceVar;
                    iReq++;
                }
                recipe.RequiredUpgrades = requiredFinal;
            }
            else
            {
                var baseRecipeTag = GameResources.Instance.Recipes.FirstOrDefault(s => s.name == baseRecipe);
                recipe.RequiredUpgrades = baseRecipeTag.RequiredUpgrades;
            }
            if (recipeCategory != "")
            {
                recipe.Categories = new RecipeCategory[] { FindCategory.FindCategoryName(recipeCategory) };
            }
            else
            {
                var baseRecipeTag = GameResources.Instance.Recipes.FirstOrDefault(s => s.name == baseRecipe);
                recipe.Categories = baseRecipeTag.Categories.ToArray();
            }

            var guid = GUID.Parse(itemId);

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = recipe, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);
        }
Ejemplo n.º 8
0
        public void CreateProductionModule(string codename, string variantname, int maxstack, string baseitem, LocalizedString name, LocalizedString desc, string guidstring, string categoryname, string factorytypename, Sprite icon, RecipeCategory[] categories)
        {
            var category = GameResources.Instance.Items.FirstOrDefault(s => s.name == categoryname).Category;
            var item     = ScriptableObject.CreateInstance <ItemDefinition>();

            item.name     = codename;
            item.Category = category;
            item.MaxStack = maxstack;
            item.Icon     = icon;

            var prefabParent = new GameObject();
            var olditem      = GameResources.Instance.Items.FirstOrDefault(s => s.name == baseitem);
            var factorytype  = GameResources.Instance.FactoryTypes.FirstOrDefault(s => s.name == factorytypename);

            prefabParent.SetActive(false);
            var newmodule  = Instantiate(olditem.Prefabs[0], prefabParent.transform);
            var module     = newmodule.GetComponentInChildren <ProductionModule>();
            var gridmodule = newmodule.GetComponent <GridModule>();

            gridmodule.VariantName = variantname;
            gridmodule.Item        = item;
            item.Prefabs           = new GameObject[] { newmodule };
            var modulecategory = RuntimeAssetCacheLookup.Get <ModuleCategory>().First(s => s.name == factorytypename);

            modulecategory.Modules = modulecategory.Modules.Concat(new ItemDefinition[] { item }).ToArray();

            var productionGroup = QuestingReferences.GetOrCreateTyping(factorytype);

            LocalizedString nameStr = name;
            LocalizedString descStr = desc;

            Initialize(ref nameStr);
            Initialize(ref descStr);

            typeof(ProductionModule).GetField("m_factoryType", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, factorytype);
            typeof(ProductionModule).GetField("m_module", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, gridmodule);
            typeof(ProductionModule).GetField("m_categories", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, categories);
            typeof(ProductionModule).GetField("m_productionGroup", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, productionGroup);
            typeof(ItemDefinition).GetField("m_name", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, nameStr);
            typeof(ItemDefinition).GetField("m_description", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, descStr);

            var guid = GUID.Parse(guidstring);

            typeof(Definition).GetField("m_assetId", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, guid);

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = item, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);

            using (StreamWriter writer = new StreamWriter(QuestingMod.path, true))
            {
                writer.WriteLine("[Questing Update | Modules]: Module " + codename + " has been loaded");
                writer.Dispose();
            }
        }
        private void CreateRecipeCategory(string name, string categoryId)
        {
            var Forge = ScriptableObject.CreateInstance <RecipeCategory>();

            Forge.name = name;
            var guid = GUID.Parse(categoryId);

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = Forge, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);

            QuestingDict.questingRegistry[name] = guid;
            QuestLog.Log("[Questing Update | Categories]: Recipe Category with name " + name + " has been loaded");
        }
Ejemplo n.º 10
0
        private void CreateRecipeCategory(string name, string categoryId)
        {
            var Forge = ScriptableObject.CreateInstance <RecipeCategory>();

            Forge.name = name;
            var guid = GUID.Parse(categoryId);

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = Forge, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);

            using (StreamWriter writer = new StreamWriter(QuestingMod.path, true))
            {
                writer.WriteLine("[Questing Update | Categories]: Recipe Category with name " + name + " has been loaded");
                writer.Dispose();
            }
        }
Ejemplo n.º 11
0
        public static void CopyRevolver()
        {
            var revolver = GameResources.Instance.Items.FirstOrDefault(s => s.name == "Revolver");

            QuestLog.Log("" + revolver.Category);

            var guid = GUID.Parse("CA25D7B116F14B97A7D51EFB94406B93");

            var item = UnityEngine.Object.Instantiate(revolver);

            item.name     = "Super Revolver";
            item.Category = revolver.Category;
            item.MaxStack = revolver.MaxStack;
            item.Icon     = revolver.Icon;

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = item, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);
        }