//Copied this from the Vehicle class public static bool TorpedoShot(ItemsContainer container, TorpedoType torpedoType, Transform muzzle, Vector3 forward, Quaternion rotation) { if (torpedoType != null && container.DestroyItem(torpedoType.techType)) { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(torpedoType.prefab); Transform component = gameObject.GetComponent <Transform>(); SeamothTorpedo component2 = gameObject.GetComponent <SeamothTorpedo>(); Vector3 zero = Vector3.zero; Rigidbody componentInParent = muzzle.GetComponentInParent <Rigidbody>(); Vector3 rhs = (!(componentInParent != null)) ? Vector3.zero : componentInParent.velocity; float speed = Vector3.Dot(forward, rhs); component2.Shoot(muzzle.position, rotation, speed, -1f); return(true); } return(false); }
public static bool Prefix(Constructable __instance) { if (Player.main.GetVehicle() != null) { Vehicle thisVehicle = Player.main.GetVehicle(); if (__instance._constructed) { return(false); } int count = __instance.resourceMap.Count; int resourceID = __instance.GetResourceID(); float backupConstructedAmount = __instance.constructedAmount; __instance.constructedAmount += Time.deltaTime / (count * Constructable.GetConstructInterval()); __instance.constructedAmount = Mathf.Clamp01(__instance.constructedAmount); int resourceID2 = __instance.GetResourceID(); if (resourceID2 != resourceID) { TechType destroyTechType = __instance.resourceMap[resourceID2 - 1]; if (thisVehicle.GetType().Equals(typeof(Exosuit))) { StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer; if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients()) { storageContainer.container.DestroyItem(destroyTechType); } else { __instance.constructedAmount = backupConstructedAmount; return(true); } } else { var seamoth = (SeaMoth)thisVehicle; bool storageCheck = false; for (int i = 0; i < 12; i++) { try { ItemsContainer storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule); if (storage != null && storage.Contains(destroyTechType) && GameModeUtils.RequiresIngredients()) { storage.DestroyItem(destroyTechType); storageCheck = true; break; } } catch (Exception) { continue; } } if (!storageCheck) { __instance.constructedAmount = backupConstructedAmount; return(true); } } } __instance.UpdateMaterial(); if (__instance.constructedAmount >= 1f) { __instance.SetState(true, true); } return(false); } else { return(true); } }
public static bool Prefix(Constructable __instance) { if (Player.main.GetVehicle() != null && GameModeUtils.RequiresIngredients()) { Type ConstructableType = typeof(Constructable); List <TechType> resourceMapField = (List <TechType>)AccessTools.Field(ConstructableType, "resourceMap").GetValue(__instance); MethodInfo getResourceIDMethod = AccessTools.Method(ConstructableType, "GetResourceID"); MethodInfo GetConstructIntervalMethod = AccessTools.Method(ConstructableType, "GetConstructInterval"); MethodInfo updateMaterialMethod = AccessTools.Method(ConstructableType, "UpdateMaterial"); Vehicle thisVehicle = Player.main.GetVehicle(); if (__instance._constructed) { return(false); } int count = resourceMapField.Count; int resourceID = (int)getResourceIDMethod.Invoke(__instance, null); float backupConstructedAmount = __instance.constructedAmount; __instance.constructedAmount += Time.deltaTime / (count * (float)GetConstructIntervalMethod.Invoke(__instance, null)); __instance.constructedAmount = Mathf.Clamp01(__instance.constructedAmount); int resourceID2 = (int)getResourceIDMethod.Invoke(__instance, null); if (resourceID2 != resourceID) { TechType destroyTechType = resourceMapField[resourceID2 - 1]; if (thisVehicle.GetType().Equals(typeof(Exosuit))) { StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer; if (storageContainer.container.Contains(destroyTechType)) { _ = storageContainer.container.DestroyItem(destroyTechType); } else { __instance.constructedAmount = backupConstructedAmount; return(true); } } else { var seamoth = (SeaMoth)thisVehicle; bool storageCheck = false; for (int i = 0; i < 12; i++) { try { ItemsContainer storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule); if (storage != null && storage.Contains(destroyTechType)) { if (storage.DestroyItem(destroyTechType)) { storageCheck = true; break; } } } catch (Exception) { continue; } } if (!storageCheck) { __instance.constructedAmount = backupConstructedAmount; return(true); } } } _ = updateMaterialMethod.Invoke(__instance, null); if (__instance.constructedAmount >= 1f) { _ = __instance.SetState(true, true); } return(false); } else { return(true); } }