Beispiel #1
0
    IEnumerator Start()
    {
        RNotification notification = FindObjectOfType <RNotify>().AddNotification(RNotify.NotificationType.spinning, "Loading MoreStorages...");

        var bundleLoadRequest = AssetBundle.LoadFromFileAsync("mods\\ModData\\MoreStorages\\morestorages.assets");

        yield return(bundleLoadRequest);

        assetbundle = bundleLoadRequest.assetBundle;
        if (assetbundle == null)
        {
            RConsole.LogError("Failed to load AssetBundle for MoreStorages!");
            notification.Close();
            yield return(null);
        }

        List <Item_Base> list = Traverse.Create(typeof(ItemManager)).Field("allAvailableItems").GetValue <List <Item_Base> >();

        Item_Base Placeable_MoreStorages_MinecraftChest = (Item_Base)assetbundle.LoadAsset <ScriptableObject>("Placeable_MoreStorages_MinecraftChest");

        Placeable_MoreStorages_MinecraftChest.Initialize(9845, "Placeable_MoreStorages_MinecraftChest", 1);
        list.Add(Placeable_MoreStorages_MinecraftChest);
        RegisterChest(Placeable_MoreStorages_MinecraftChest);

        Item_Base Placeable_MoreStorages_Barrel = (Item_Base)assetbundle.LoadAsset <ScriptableObject>("Placeable_MoreStorages_Barrel");

        Placeable_MoreStorages_Barrel.Initialize(9846, "Placeable_MoreStorages_Barrel", 1);
        list.Add(Placeable_MoreStorages_Barrel);
        RegisterChest(Placeable_MoreStorages_Barrel);

        Item_Base Placeable_MoreStorages_Crate = (Item_Base)assetbundle.LoadAsset <ScriptableObject>("Placeable_MoreStorages_Crate");

        Placeable_MoreStorages_Crate.Initialize(9847, "Placeable_MoreStorages_Crate", 1);
        list.Add(Placeable_MoreStorages_Crate);
        RegisterChest(Placeable_MoreStorages_Crate);

        Item_Base Placeable_MoreStorages_Luggage = (Item_Base)assetbundle.LoadAsset <ScriptableObject>("Placeable_MoreStorages_Luggage");

        Placeable_MoreStorages_Luggage.Initialize(9848, "Placeable_MoreStorages_Luggage", 1);
        list.Add(Placeable_MoreStorages_Luggage);
        RegisterChest(Placeable_MoreStorages_Luggage);

        Item_Base Placeable_MoreStorages_MedievalChest = (Item_Base)assetbundle.LoadAsset <ScriptableObject>("Placeable_MoreStorages_MedievalChest");

        Placeable_MoreStorages_MedievalChest.Initialize(9849, "Placeable_MoreStorages_MedievalChest", 1);
        list.Add(Placeable_MoreStorages_MedievalChest);
        RegisterChest(Placeable_MoreStorages_MedievalChest);

        Item_Base Placeable_MoreStorages_Package = (Item_Base)assetbundle.LoadAsset <ScriptableObject>("Placeable_MoreStorages_Package");

        Placeable_MoreStorages_Package.Initialize(9850, "Placeable_MoreStorages_Package", 1);
        list.Add(Placeable_MoreStorages_Package);
        RegisterChest(Placeable_MoreStorages_Package);


        Traverse.Create(typeof(ItemManager)).Field("allAvailableItems").SetValue(list);

        notification.Close();
        RConsole.Log("MoreStorages has been successfully loaded!");
    }
Beispiel #2
0
    IEnumerator Start()
    {
        RNotification notification = FindObjectOfType <RNotify>().AddNotification(RNotify.NotificationType.spinning, "Loading SolarPanelMod...");

        var bundleLoadRequest = AssetBundle.LoadFromFileAsync("mods\\ModData\\SolarPanel\\solarpanel.assets");

        yield return(bundleLoadRequest);

        assetbundle = bundleLoadRequest.assetBundle;
        if (assetbundle == null)
        {
            RConsole.LogError("Failed to load AssetBundle for solarpanel!");
            notification.Close();
            yield return(null);
        }

        List <Item_Base> list = Traverse.Create(typeof(ItemManager)).Field("allAvailableItems").GetValue <List <Item_Base> >();

        Item_Base placeable_solarpanel = (Item_Base)assetbundle.LoadAsset <ScriptableObject>("placeable_solarpanel");

        placeable_solarpanel.settings_buildable.GetBlockPrefab(0).gameObject.AddComponent <SolarPanelObject>();
        SolarPanelObject obj = placeable_solarpanel.settings_buildable.GetBlockPrefab(0).gameObject.AddComponent <SolarPanelObject>();

        Traverse.Create(placeable_solarpanel.settings_buildable.GetBlockPrefab(0).GetComponentInChildren <Battery>()).Field("networkBehaviourID").SetValue(obj);
        placeable_solarpanel.Initialize(999, "placeable_solarpanel", 1);

        list.Add(placeable_solarpanel);

        Traverse.Create(typeof(ItemManager)).Field("allAvailableItems").SetValue(list);

        RAPI.AddItemToBlockQuadType(placeable_solarpanel, RBlockQuadType.quad_floor);
        RAPI.AddItemToBlockQuadType(placeable_solarpanel, RBlockQuadType.quad_foundation);
        RAPI.AddItemToBlockQuadType(placeable_solarpanel, RBlockQuadType.quad_table);

        notification.Close();
    }
Beispiel #3
0
    // Token: 0x06000074 RID: 116
    public static void AddItem(Mod mod, ModItem item)
    {
        ItemType         itemType         = (ItemType)1;
        CraftingCategory craftingCategory = (CraftingCategory)2;
        int       id        = 399 + ModHelper.modItems.Count;
        Item_Base item_Base = new Item_Base();

        item_Base.Initialize(id, item.name, itemType, item.durability);
        item_Base.name = item.name;
        item_Base.settings_Inventory             = new ItemInstance_Inventory(item.inventoryIcon, "Item/" + item.name, item.stackSize);
        item_Base.settings_Inventory.DisplayName = item.displayName;
        item_Base.settings_Inventory.Description = item.description;
        item_Base.settings_usable         = new ItemInstance_Usable("LMD", 0f, 0, false, false, 0, 0, false, false, false, "LMD");
        item_Base.settings_recipe         = new ItemInstance_Recipe(craftingCategory, item.isUnlocked, item.isUnlocked, "", 0);
        item_Base.settings_recipe.NewCost = new CostMultiple[]
        {
            new CostMultiple(new Item_Base[]
            {
                ItemManager.GetItemByName("Scrap")
            }, 1)
        };
        item_Base.settings_equipment   = new ItemInstance_Equipment(0);
        item_Base.settings_cookable    = new ItemInstance_Cookable(0, 0f, null);
        item_Base.settings_consumeable = new ItemInstance_Consumeable(0f, 0f, false, null, 0);
        item_Base.settings_buildable   = new ItemInstance_Buildable(null, false, false);
        try
        {
            BindingFlags     accessPrivateStatic = (BindingFlags)40;
            FieldInfo        field = typeof(ItemManager).GetField("allAvailableItems", accessPrivateStatic);
            List <Item_Base> list  = (List <Item_Base>)field.GetValue(null);
            list.Add(item_Base);
            field.SetValue(null, list);
            item.Initialize(item_Base);
            if (!ModHelper.modItems.ContainsKey(mod))
            {
                ModHelper.modItems[mod] = new List <ModItem>();
            }
            ModHelper.modItems[mod].Add(item);
            RConsole.Log(string.Concat(new object[]
            {
                "Adding item at id ",
                id,
                " ",
                item.displayName,
                " (",
                item.description,
                ")"
            }));
        }
        catch (Exception ex)
        {
            RConsole.Log(string.Concat(new object[]
            {
                "Failed to add item at id ",
                id,
                " and displayName ",
                item.displayName,
                ": ",
                ex.ToString()
            }));
        }
    }
Beispiel #4
0
        /// <summary>
        /// Convert this item to an Item_Base
        /// </summary>
        /// <returns>bool success</returns>
        protected virtual bool Init()
        {
            if (id == 0 || owner == null)
            {
                Console.WriteLine("Couldn't initialize item; it has no owner and/or id");
                return(false);
            }

            Item_Base item = baseItem;

            if (item == null)
            {
                //Item itself

                item = baseItem = ScriptableObject.CreateInstance <Item_Base>();
                item.Initialize(id, fullName, (ItemType)use, durability);
                item.name = fullName;

                //Inventory

                if (sprite == null)      //Look for default sprite
                {
                    sprite = owner.GetAsset <Sprite>("item." + name);
                }

                item.settings_Inventory             = new ItemInstance_Inventory(sprite, "Item/" + fullName, stackSize);
                item.settings_Inventory.Description = description;
                item.settings_Inventory.DisplayName = displayName;

                //Stuff required to make items work; as they are used by ItemInstance constructor

                item.settings_buildable   = new ItemInstance_Buildable(null, false, false);
                item.settings_consumeable = new ItemInstance_Consumeable(0, 0, false, new Cost(null, 0), FoodType.None);
                item.settings_equipment   = new ItemInstance_Equipment(EquipSlotType.None);
                item.settings_usable      = new ItemInstance_Usable("", 0, 0, false, false, PlayerAnimation.None, PlayerAnimation.None, false, false, false, "");

                FieldInfo barGradientf = typeof(Item_Base).GetField("barGradient", BindingFlags.NonPublic | BindingFlags.Instance);

                //If items don't have a gradient and use durability, they can't be stored in the inventory
                //So, just copy the Axe gradient (they are the same per tool)
                barGradientf.SetValue(item, ItemManager.GetItemByName("Axe").BarGradient);

                //'Cooking' Recipe (conversion recipe)

                if (convertRecipe != null)
                {
                    item.settings_cookable = new ItemInstance_Cookable(convertRecipe.slots, convertRecipe.time, new Cost(convertRecipe.output.baseItem, convertRecipe.outputAmount));
                }
                else
                {
                    item.settings_cookable = new ItemInstance_Cookable(0, 0, null);
                }

                //Crafting recipe
                RefreshRecipe();

                //Insertion

                List <Item_Base> items = ItemManager.GetAllItems();

                FieldInfo allAvailableItemsf = typeof(ItemManager).GetField("allAvailableItems", BindingFlags.NonPublic | BindingFlags.Static);

                if (allAvailableItemsf == null)
                {
                    Console.WriteLine("Couldn't find items in ItemManager");
                    return(false);
                }

                items.Add(item);
                allAvailableItemsf.SetValue(null, items);
            }
            else if (Item.items.ContainsKey(item))
            {
                return(true);
            }

            Item.items[item]      = this;
            itemsByName[fullName] = this;
            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Convert this item to an Item_Base
        /// </summary>
        /// <returns>bool success</returns>
        protected bool Init()
        {
            if (id == 0 || owner == null)
            {
                Console.WriteLine("Couldn't initialize item; it has no owner and/or id");
                return(false);
            }

            Item_Base item = baseItem;

            if (item == null)
            {
                //Item itself

                item = baseItem = ScriptableObject.CreateInstance <Item_Base>();
                item.Initialize(id, fullName, (ItemType)use, durability);
                item.name = fullName;

                //Inventory

                if (sprite == null)      //Look for default sprite
                {
                    sprite = owner.GetAsset <Sprite>("item." + name);
                }

                item.settings_Inventory             = new ItemInstance_Inventory(sprite, "Item/" + fullName, stackSize);
                item.settings_Inventory.Description = description;
                item.settings_Inventory.DisplayName = displayName;

                //Stuff required to make items work; as they are used by ItemInstance constructor

                item.settings_buildable   = new ItemInstance_Buildable(null, false, false);
                item.settings_consumeable = new ItemInstance_Consumeable(0, 0, false, new Cost(null, 0), FoodType.None);
                item.settings_equipment   = new ItemInstance_Equipment(EquipSlotType.None);
                item.settings_usable      = new ItemInstance_Usable("", 0, 0, false, false, PlayerAnimation.None, PlayerAnimation.None, false, false, false, "");

                //'Cooking' Recipe (conversion recipe)

                if (convertRecipe != null)
                {
                    item.settings_cookable = new ItemInstance_Cookable(convertRecipe.slots, convertRecipe.time, new Cost(convertRecipe.output.baseItem, convertRecipe.outputAmount));
                }
                else
                {
                    item.settings_cookable = new ItemInstance_Cookable(0, 0, null);
                }

                //Crafting recipe

                item.settings_recipe = new ItemInstance_Recipe((CraftingCategory)category, false, recipe == null ? false : recipe.discoveredByDefault, subcategory, 0);

                if (recipe != null)
                {
                    if (recipe.blueprint != null)
                    {
                        typeof(Item_Base).GetField("BlueprintItem", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item.settings_recipe, recipe.blueprint.baseItem);
                    }

                    typeof(ItemInstance_Recipe).GetField("amountToCraft", BindingFlags.Instance | BindingFlags.NonPublic)
                    .SetValue(item.settings_recipe, recipe.amount);

                    List <CostMultiple> costs = new List <CostMultiple>();

                    foreach (RecipeShape shape in recipe.recipe)
                    {
                        Item_Base[] itemBase = new Item_Base[shape.items.Length];

                        int j = 0;

                        foreach (Item i in shape.items)
                        {
                            itemBase[j++] = i.baseItem;
                        }

                        costs.Add(new CostMultiple(itemBase, shape.amount));
                    }

                    item.settings_recipe.NewCost = costs.ToArray();
                }

                //Insertion

                List <Item_Base> items = ItemManager.GetAllItems();

                FieldInfo allAvailableItemsf = typeof(ItemManager).GetField("allAvailableItems", BindingFlags.NonPublic | BindingFlags.Static);

                if (allAvailableItemsf == null)
                {
                    Console.WriteLine("Couldn't find items in ItemManager");
                    return(false);
                }

                items.Add(item);
                allAvailableItemsf.SetValue(null, items);
            }
            else if (Item.items.ContainsKey(item))
            {
                return(true);
            }

            Item.items[item]      = this;
            itemsByName[fullName] = this;
            return(true);
        }