List <InventoryItem> GetListForSpec(InventoryItemSpec key, bool create) { if (key is InventoryItemWeaponSpec) { return(GetList(mWeapons, (InventoryItemWeaponSpec)key, create)); } else if (key is InventoryItemThrowableSpec) { return(GetList(mThrowables, (InventoryItemThrowableSpec)key, create)); } else if (key is InventoryItemConsumableSpec) { return(GetList(mConsumables, (InventoryItemConsumableSpec)key, create)); } else { string message = $"No inventory for \"{key.GetType().FullName}\"."; if (!create) { Debug.LogError(message); return(null); } throw new Exception(message); } }
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"); }
// Need to know when we have grabbed a Locomotive Remote // Actual Grab Handlers static void OnItemGrabbedRight(InventoryItemSpec iis) { LocomotiveRemoteController lrc = iis?.GetComponent <LocomotiveRemoteController>(); if (lrc != null) { LocoControllerBase locoController = (LocoControllerBase)typeof(LocomotiveRemoteController).GetField("pairedLocomotive", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(lrc); remoteCar = locoController?.GetComponent <TrainCar>(); } }
// Actual Grab Handlers static void OnItemGrabbedLeft(InventoryItemSpec iis) { if (iis == null) { return; } // mod.Logger.Log(string.Format("Picked up a(n) {0} in the left hand.", iis.itemName)); // JobOverview jo = iis.GetComponent<JobOverview>(); // if (jo != null) // holdingLeft = jo.job; }
public InventoryItem AddItem(InventoryItemSpec spec, bool notifyChanged = true) { var item = new InventoryItem { Spec = spec }; List <InventoryItem> list = GetListForSpec(spec, true); list.Add(item); if (notifyChanged) { Changed?.Invoke(); } return(item); }
public static void SetLicenseObjectProperties(GameObject licenseObj, PassBookletType bookletType) { if (licenseObj && BookletProperties.TryGetValue(bookletType, out var licenseInfo)) { licenseObj.name = licenseInfo.Name; // get the renderer of the paper child object MeshRenderer renderer = licenseObj.transform.Find("Paper")?.gameObject?.GetComponent <MeshRenderer>(); if (renderer) { Material newMat = new Material(renderer.material) { mainTexture = licenseInfo.GetTexture() }; renderer.material = newMat; } else { PassengerJobs.ModEntry.Logger.Warning($"Couldn't set texture on {licenseInfo.Name}"); } // get the inventory spec component InventoryItemSpec itemSpec = licenseObj.GetComponent <InventoryItemSpec>(); if (itemSpec) { itemSpec.itemName = licenseInfo.InventoryName; itemSpec.itemPrefabName = licenseInfo.Name; } else { PassengerJobs.ModEntry.Logger.Warning($"Couldn't set inventory name on {licenseInfo.Name}"); } } else { PassengerJobs.ModEntry.Logger.Warning($"Couldn't apply properties to license booklet {Enum.GetName(typeof(PassBookletType), bookletType)}"); } }
static void OnItemGrabbedRight(InventoryItemSpec iis) { if (iis == null) { return; } // mod.Logger.Log(string.Format("Picked up a(n) {0} in the right hand.", iis.itemName)); JobOverview jo = iis.GetComponent <JobOverview>(); if (jo != null) { holdingRight = new JobDispatch(jo.job); showing = false; } else { JobBooklet jb = iis.GetComponent <JobBooklet>(); if (jb != null) { holdingRight = new JobDispatch(jb.job); showing = false; } } }
static void OnItemUngrabbedRight(InventoryItemSpec iis) { holdingRight = null; }
static void OnItemUngrabbedLeft(InventoryItemSpec iis) { // holdingLeft = null; }
// Need to know when we have grabbed a Locomotive Remote // Actual Grab Handlers static void OnItemGrabbedRight(InventoryItemSpec iis) { HoldingLocoRoCo = iis?.GetComponent <LocomotiveRemoteController>(); }