// This extracts information from the JSON database (through itemData) void CreateItemDatabase() { for (int i = 0; i < itemData["Items"].Count; i++) { if (!Contains((int)itemData["Items"][i]["ItemID"])) { GameItem newItem = new GameItem(); // Map each line in the ith JSON entry to a variable: newItem.ItemName = (string)itemData["Items"][i]["ItemName"]; newItem.ItemID = (int)itemData["Items"][i]["ItemID"]; newItem.ItemShortDesc = (string)itemData["Items"][i]["ItemShortDesc"]; newItem.ItemLongDesc = (string)itemData["Items"][i]["ItemLongDesc"]; newItem.ItemWeight = (int)itemData["Items"][i]["ItemWeight"]; newItem.ItemCost = (int)itemData["Items"][i]["ItemCost"]; newItem.ItemIconPath = (string)itemData["Items"][i]["ItemIconPath"]; newItem.ItemModelPath = (string)itemData["Items"][i]["ItemModelPath"]; newItem.ItemQuality = (ItemQuality)((int)itemData["Items"][i]["ItemQuality"]); newItem.ItemType = (ItemType)((int)itemData["Items"][i]["ItemType"]); // PERK requirements if (itemData["Items"][i]["ItemPerkReqIDs"].Count != 0) { for (int p = 0; p < itemData["Items"][i]["ItemPerkReqIDs"].Count; p++) { newItem.ItemPerkReqIDs.Add((int)itemData["Items"][i]["ItemPerkReqIDs"][p]); } } // Get the model and icon from the given paths newItem.LoadIcon(); newItem.LoadModel(); switch (newItem.ItemType) { // If the items is WEAPON... case (ItemType.Weapon): WeaponStats newWStats = new WeaponStats(); // Map each line in the weapons array to a weapon-only variable newWStats.AttackSpeed = (int)itemData["Items"][i]["WStats"]["AttackSpeed"]; newWStats.BaseDamage = (int)itemData["Items"][i]["WStats"]["BaseDamage"]; newWStats.BluntDamage = (int)itemData["Items"][i]["WStats"]["BluntDamage"]; newWStats.PierceDamage = (int)itemData["Items"][i]["WStats"]["PierceDamage"]; newWStats.SlashDamage = (int)itemData["Items"][i]["WStats"]["SlashDamage"]; newWStats.WeaponType = (WeaponType)((int)itemData["Items"][i]["WStats"]["WeaponType"]); for (int m = 0; m < itemData["Items"][i]["WStats"]["Auras"].Count; m++) { newWStats.Auras.Add((int)itemData["Items"][i]["WStats"]["Auras"][m]); } // Add this to the new item. newItem.WStats = newWStats; break; // If the item is ARMOUR... case (ItemType.Armour): ArmourStats newAStats = new ArmourStats(); // Map each line in the armour array to a armour-only variable newAStats.BaseDefence = (int)itemData["Items"][i]["AStats"]["BaseDefence"]; newAStats.BluntDefence = (int)itemData["Items"][i]["AStats"]["BluntDefence"]; newAStats.PierceDefence = (int)itemData["Items"][i]["AStats"]["PierceDefence"]; newAStats.SlashDefence = (int)itemData["Items"][i]["AStats"]["SlashDefence"]; newAStats.ThermalDefence = (int)itemData["Items"][i]["AStats"]["ThermalDefence"]; newAStats.NatureDefence = (int)itemData["Items"][i]["AStats"]["NatureDefence"]; newAStats.ArmourMaterial = (ArmourMaterial)((int)itemData["Items"][i]["AStats"]["ArmourMaterial"]); newAStats.ArmourType = (ArmourType)((int)itemData["Items"][i]["AStats"]["ArmourType"]); for (int n = 0; n < itemData["Items"][i]["AStats"]["Auras"].Count; n++) { newAStats.Auras.Add((int)itemData["Items"][i]["AStats"]["Auras"][n]); } // Add this to the new item. newItem.AStats = newAStats; break; // If the item is CONSUMABLE... case (ItemType.Consumable): ConsumableStats newConStats = new ConsumableStats(); // Map each line in the consumable array to a consumable-only variable newConStats.ConsumableType = (ConsumableType)((int)itemData["Items"][i]["ConStats"]["ConsumableType"]); newConStats.Charges = (int)itemData["Items"][i]["ConStats"]["Charges"]; for (int j = 0; j < itemData["Items"][i]["ConStats"]["Auras"].Count; j++) { newConStats.Auras.Add((int)itemData["Items"][i]["ConStats"]["Auras"][j]); } // Add this to the new item. newItem.ConStats = newConStats; break; // If the item is CONTAINER... case (ItemType.Container): ContainerStats newCtnStats = new ContainerStats(); // Map each line in the consumable array to a consumable-only variable for (int k = 0; k < itemData["Items"][i]["CtnStats"]["ContentItems"].Count; k++) { newCtnStats.ContentItems.Add((int)itemData["Items"][i]["CtnStats"]["ContentItems"][k]); newCtnStats.ContentQuantities.Add((int)itemData["Items"][i]["CtnStats"]["ContentQuantities"][k]); } newCtnStats.CombineContents(); // Add this to the new item. newItem.CtnStats = newCtnStats; break; // If the item is CONTAINER... case (ItemType.Ingredient): IngredientStats newIngStats = new IngredientStats(); // Map each line in the container array to a container-only variable newIngStats.IsStackable = (bool)itemData["Items"][i]["IngStats"]["IsStackable"]; // Add this to the new item. newItem.IngStats = newIngStats; break; // If the item is MISC... case (ItemType.Misc): MiscStats newMiscStats = new MiscStats(); // Map each line in the container array to a container-only variable newMiscStats.IsStackable = (bool)itemData["Items"][i]["MiscStats"]["IsStackable"]; // Add this to the new item. newItem.MiscStats = newMiscStats; break; } // Add this item to the database. AddItem(newItem); //Debug.Log("(ItemDB) " + newItem.ItemName + " loaded."); } } }
void SaveExistingItem(ItemType type) { //Item newItem = new Item(); if (!RequiremetsMet(itemID, selectedItem)) { Debug.LogError("An item with that ID (" + itemID + ") already exists."); return; } // Using the empty constructor so that more variables can be added easily. selectedItem.ItemName = itemName; selectedItem.ItemID = itemID; selectedItem.ItemShortDesc = itemShortDesc; selectedItem.ItemLongDesc = itemLongDesc; selectedItem.ItemWeight = itemWeight; selectedItem.ItemCost = itemCost; selectedItem.ItemQuality = itemQuality; selectedItem.ItemType = itemType; selectedItem.ItemPerkReqIDs = itemReqPerkIDs; // Set the model and icon selectedItem.SetIcon(itemIcon); selectedItem.SetModel(itemModel); // Find model path itemModelPath = AssetDatabase.GetAssetPath(itemModel); itemModelPath = GameUtility.CleanItemResourcePath(itemModelPath, "Assets/Resources/"); itemModelPath = GameUtility.CleanItemResourcePath(itemModelPath, ".prefab"); selectedItem.ItemModelPath = itemModelPath; // Find icon path itemIconPath = AssetDatabase.GetAssetPath(itemIcon); itemIconPath = GameUtility.CleanItemResourcePath(itemIconPath, "Assets/Resources/"); itemIconPath = GameUtility.CleanItemResourcePath(itemIconPath, ".png"); selectedItem.ItemIconPath = itemIconPath; switch (type) { case (ItemType.Weapon): WeaponStats wstats = selectedItem.WStats; wstats.AttackSpeed = attackSpeed; wstats.BaseDamage = baseDamage; wstats.BluntDamage = bluntDamage; wstats.PierceDamage = pierceDamage; wstats.SlashDamage = slashDamage; wstats.Auras = conditions; selectedItem.WStats = wstats; break; case (ItemType.Armour): ArmourStats astats = selectedItem.AStats; astats.ArmourMaterial = armourMaterial; astats.ArmourType = armourType; astats.BaseDefence = baseDefence; astats.BluntDefence = bluntDefence; astats.PierceDefence = pierceDefence; astats.SlashDefence = slashDefence; astats.NatureDefence = natureDefence; astats.ThermalDefence = thermalDefence; astats.Auras = conditions; selectedItem.AStats = astats; break; case (ItemType.Consumable): ConsumableStats constats = selectedItem.ConStats; constats.ConsumableType = consumableType; constats.Auras = conditions; constats.Charges = consumableCharges; selectedItem.ConStats = constats; break; case (ItemType.Container): ContainerStats ctnstats = selectedItem.CtnStats; ctnstats.ContentItems = contentItems; ctnstats.ContentQuantities = contentQuantities; selectedItem.CtnStats = ctnstats; break; case (ItemType.Ingredient): IngredientStats ingstats = selectedItem.IngStats; ingstats.IsStackable = isStackable; selectedItem.IngStats = ingstats; break; case (ItemType.Misc): MiscStats miscstats = selectedItem.MiscStats; miscstats.IsStackable = isStackable; selectedItem.MiscStats = miscstats; break; } EditorUtility.SetDirty(itemDatabase); AssetDatabase.SaveAssets(); }