Esempio n. 1
0
        public static void CreateShopItems()
        {
            if (assets == null)
            {
                Debug.LogError("Failed to load tabletcomputer bundle!");
                return;
            }

            Debug.LogWarning($"[DERAIL Digital] Tablet Loader: {assets}");

            InventoryItemSpec itemSpec = assets.LoadAsset <GameObject>("TabletComputer").GetComponent <InventoryItemSpec>();

            Debug.LogWarning($"[DERAIL Digital] Item spec: {itemSpec}");

            GlobalShopController.Instance.shopItemsData.Add(new ShopItemData()
            {
                item      = itemSpec,
                basePrice = 1291,
                amount    = 1,
                isGlobal  = true
            });

            //GlobalShopController.Instance.initialItemAmounts.Add(1);
            ((List <int>) typeof(GlobalShopController).GetField("initialItemAmounts", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GlobalShopController.Instance)).Add(1);

            Debug.LogWarning("Added global shop data");

            Shop[] shops = Object.FindObjectsOfType <Shop>();
            foreach (Shop shop in shops)
            {
                if (!shop.ToString().Contains("FoodFactory"))
                {
                    continue;
                }
                Debug.LogWarning($"adding to shop {shop}");

                ScanItemResourceModule findMax  = shop.scanItemResourceModules.FindMax(r => r.transform.localPosition.x);
                ScanItemResourceModule resource = Object.Instantiate(findMax, findMax.transform.parent);
                resource.gameObject.SetActive(true);
                resource.sellingItemSpec         = itemSpec;
                resource.transform.localRotation = findMax.transform.localRotation;
                resource.transform.localPosition = findMax.transform.localPosition + Vector3.right * 1.2f;

                //resource.Start();
                typeof(ScanItemResourceModule).GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(resource, null);

                Debug.LogWarning($"new item sign: {resource}");

                var arr = new ScanItemResourceModule[shop.scanItemResourceModules.Length + 1];
                Array.Copy(shop.scanItemResourceModules, 0, arr, 0, shop.scanItemResourceModules.Length);
                arr[arr.Length - 1] = resource;
                shop.cashRegister.resourceMachines = Array.ConvertAll(arr, e => (ResourceModule)e);

                resource.ItemPurchased += GlobalShopController.Instance.AddItemToInstatiationQueue;
            }

            Debug.LogWarning("[DERAIL Digital] Tablet Loader: done");
        }
Esempio n. 2
0
        static void CreateShopItems()
        {
            Log.Debug("Create shop items");

            if (!_bundle)
            {
                Log.Error("Failed to load lamps bundle");
                return;
            }

            //var spec = _bundle.LoadAsset<GameObject>("MagicLamp").GetComponent<InventoryItemSpec>();
            var spec = _bundle.LoadAsset <GameObject>("FlashLight").GetComponent <InventoryItemSpec>();

            Log.Debug($"Item spec: {spec}");

            GlobalShopController.Instance.shopItemsData.Add(new ShopItemData()
            {
                item      = spec,
                basePrice = 100,
                amount    = 100,
                isGlobal  = true,
            });
#if PUBLICIZER_ASSEMBLY_CSHARP
            GlobalShopController.Instance.initialItemAmounts
#else
                ((List <int>) typeof(GlobalShopController).GetField("initialItemAmounts", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GlobalShopController.Instance))
#endif
            .Add(100);

            Log.Debug("Added global shop data");

            var shops = Object.FindObjectsOfType <Shop>();
            foreach (var shop in shops)
            {
                Log.Debug($"adding to shop {shop}");

                var findMax  = shop.scanItemResourceModules.FindMax(r => r.transform.localPosition.x);
                var resource = Object.Instantiate(findMax);
                resource.gameObject.SetActive(true);
                resource.sellingItemSpec         = spec;
                resource.transform.parent        = findMax.transform.parent;
                resource.transform.localRotation = findMax.transform.localRotation;
                resource.transform.localPosition = findMax.transform.localPosition + Vector3.right * 0.6f;
#if PUBLICIZER_ASSEMBLY_CSHARP
                resource.Start();                 // call start again to fix texts
#else
                typeof(ScanItemResourceModule).GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(resource, null);
#endif

                Log.Debug($"new item sign: {resource}");

                var arr = new ScanItemResourceModule[shop.scanItemResourceModules.Length + 1];
                Array.Copy(shop.scanItemResourceModules, 0, arr, 0, shop.scanItemResourceModules.Length);
                arr[arr.Length - 1] = resource;
                shop.cashRegister.resourceMachines = Array.ConvertAll(arr, e => (ResourceModule)e);

                resource.ItemPurchased += GlobalShopController.Instance.AddItemToInstatiationQueue;
            }

            Log.Debug("done");
        }