public static void Prefix(BreakableResource __instance) { TechType Breakable = CraftData.GetTechType(__instance.gameObject); if (prefabs.TryGetValue(Breakable, out List <BreakableResource.RandomPrefab> randomPrefabs)) { __instance.prefabList = randomPrefabs; return; } }
private static void HitResource_Patch_Postfix(BreakableResource __instance) { //as this is Postfix first check if player already hit it down so we do not call the break twice if (__instance.hitsToBreak > 0) { //check if user force fastbreak OR has one of the Glove's if (MetalHands.Config.Config_fastbreak == true | (MetalHands.Config.Config_ModEnable == true && ((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands.MetalHandsMK1TechType) | (Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands.MetalHandsMK2TechType)))) { __instance.hitsToBreak = 0; __instance.BreakIntoResources(); } } }
private static IEnumerator AddbrokenRestoPlayerInv(BreakableResource __instance, AssetReferenceGameObject gameObject) { CoroutineTask <GameObject> task = AddressablesUtility.InstantiateAsync(gameObject.RuntimeKey as string); yield return(task); GameObject prefab = task.GetResult(); var pickupable = prefab.GetComponent <Pickupable>(); pickupable.Initialize(); CraftData.AddToInventory(pickupable.GetTechType()); yield break; }
private static bool AddtoPrawn(BreakableResource __instance, Exosuit exosuit, GameObject gameObject, bool defaultspawn = true, bool skipinstantinate = false) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "30 - Start Add To Prawn"); var installedmodule = exosuit.modules.GetCount(MetalHands.MetalHandsClawModuleTechType); if ((installedmodule > 0) | (MetalHands.Config.Config_fastcollect == true)) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "31 - Has Module installed"); GameObject prefab; if (skipinstantinate) { prefab = gameObject; } else { prefab = GameObject.Instantiate(gameObject); } //var pickupable = prefab.GetComponent<Pickupable>(); var pickupable = prefab.GetComponent <Pickupable>() ?? prefab.GetComponentInParent <Pickupable>(); if (exosuit.storageContainer.container.HasRoomFor(pickupable) && (pickupable != null && pickupable.isPickupable)) { if (skipinstantinate) { //gameObject.SetActive(false); //GameObject.Destroy(gameObject); } else { pickupable = pickupable.Initialize(); } var item = new InventoryItem(pickupable); exosuit.storageContainer.container.UnsafeAdd(item); string name = Language.main.GetOrFallback(pickupable.GetTechType().AsString(), pickupable.GetTechType().AsString()); ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name)); uGUI_IconNotifier.main.Play(pickupable.GetTechType(), uGUI_IconNotifier.AnimationType.From, null); pickupable.PlayPickupSound(); return(true); } } if (defaultspawn) { __instance.SpawnResourceFromPrefab(gameObject); } return(false); }
public static void ChooseRandomResource(BreakableResource __instance, ref AssetReferenceGameObject __result) { var prefabs = __instance.prefabList; if (prefabs.Count != 1) { return; } var prefab = prefabs[0]; var c = C; float[] chances; switch (prefab.prefabTechType) { case TechType.Silver: chances = c.Silver; break; case TechType.Gold: chances = c.Gold; break; case TechType.Copper: chances = c.Copper; break; case TechType.Lead: chances = c.Lead; break; default: return; } if (currIndex >= chances.Length) { return; } var roll = random.NextDouble(); __result = roll > chances[currIndex++] ? __instance.defaultPrefabReference : prefab.prefabReference; }
private static void SpawnResourceFromPrefab(BreakableResource instance, GameObject breakPrefab) { Vector3 position = instance.transform.position + instance.transform.up * instance.verticalSpawnOffset; position.x += UnityEngine.Random.Range(-1f, 1f); position.y += UnityEngine.Random.Range(-1f, 1f); position.z += UnityEngine.Random.Range(-1f, 1f); GameObject gameObject = UnityEngine.Object.Instantiate(breakPrefab, position, Quaternion.identity); if (!gameObject.GetComponent <Rigidbody>()) { gameObject.AddComponent <Rigidbody>(); } gameObject.GetComponent <Rigidbody>().isKinematic = false; gameObject.GetComponent <Rigidbody>().AddTorque(Vector3.right * (float)UnityEngine.Random.Range(3, 6)); gameObject.GetComponent <Rigidbody>().AddForce(instance.transform.up * 0.1f); }
private static bool Prefix(BreakableResource __instance) { // Get call stack StackTrace stackTrace = new StackTrace(); // Get calling method name string callingmethode = stackTrace.GetFrame(1).GetMethod().Name; //if(callingmethode == "PunchRock" | callingmethode == "OnImpact") //OnInpact does not interact with the methode anymore if (callingmethode == "PunchRock") { return(true); } else { BreakIntoResources_Patch(__instance); return(false); } }
private static bool Prefix(BreakableResource __instance) { //Obsolete doint Pre and Postfix anyway /* * //check if the Player force prefix. after that check if a colliding Mod is installed or the player expliziete force Postfix * if( !(MetalHands.Config.Config_forceprefix_opverridepostfix) & (MetalHands.IncreasedChunkDrops_exist | MetalHands.Config.Config_forcepostfix)) * { * //run original * return true; * } * else * { * //run custom * BreakIntoResources_Patch(__instance); * return false; * } */ BreakIntoResources_Patch(__instance); return(false); }
public void OnCollisionEnter(Collision col) { LiveMixin mixin = col.collider.GetComponent <LiveMixin>(); if (mixin && mixin != Player.main.liveMixin) { mixin.TakeDamage(500f); transform.GetChild(0).parent = null; Destroy(gameObject); return; } BreakableResource res = col.collider.GetComponent <BreakableResource>(); if (res) { res.BreakIntoResources(); transform.GetChild(0).parent = null; Destroy(gameObject); return; } }
internal static IEnumerator GenerateDefaults() { Logger.Log(Logger.Level.Info, "Generating Default File", showOnScreen: true); foreach (TechType techType in Enum.GetValues(typeof(TechType))) { CoroutineTask <GameObject> prefabForTechTypeAsync = CraftData.GetPrefabForTechTypeAsync(techType, false); yield return(prefabForTechTypeAsync); GameObject prefab = prefabForTechTypeAsync?.GetResult(); // if techtype has no prefab no need to check further. if (prefab is null) { continue; } BreakableResource breakableResource = prefab.GetComponentInChildren <BreakableResource>(); // if techtype has no BreakableResource no need to check further. if (breakableResource is null) { continue; } Dictionary <TechType, float> prefabs = defaultValues.Breakables[techType] = new Dictionary <TechType, float>(); foreach (BreakableResource.RandomPrefab randomPrefab in breakableResource.prefabList) { TechType tech = CraftData.GetTechType(randomPrefab.prefab); prefabs[tech] = randomPrefab.chance; } prefabs.Add(CraftData.GetTechType(breakableResource.defaultPrefab), 1f); Logger.Log(Logger.Level.Info, $"Added {Language.main.GetOrFallback(techType.AsString(), techType.AsString())} to Defaults File", showOnScreen: true); defaultValues.Save(); } Logger.Log(Logger.Level.Info, "Default File Complete", showOnScreen: true); yield break; }
private static IEnumerator AddtoPrawn(BreakableResource __instance, Exosuit exosuit, AssetReferenceGameObject gameObject) { CoroutineTask <GameObject> task = AddressablesUtility.InstantiateAsync(gameObject.RuntimeKey as string); yield return(task); GameObject prefab = task.GetResult(); var pickupable = prefab.GetComponent <Pickupable>(); pickupable.Initialize(); var item = new InventoryItem(pickupable); exosuit.storageContainer.container.UnsafeAdd(item); string name = Language.main.GetOrFallback(pickupable.GetTechType().AsString(), pickupable.GetTechType().AsString()); ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name)); uGUI_IconNotifier.main.Play(pickupable.GetTechType(), uGUI_IconNotifier.AnimationType.From, null); pickupable.PlayPickupSound(); yield break; }
public static void Postfix(BreakableResource __instance) { var go = __instance.gameObject; var position = go.transform.position + go.transform.up * __instance.verticalSpawnOffset; var extraSpawns = Random.Range(Main.Config.ExtraCount, Main.Config.ExtraCountMax + 1); while (extraSpawns > 0) { #if SUBNAUTICA_STABLE Rigidbody rigidbody = null; var flag = false; for (var i = 0; i < __instance.numChances; i++) { var prefab = __instance.ChooseRandomResource(); if (prefab == null) { continue; } rigidbody = Object.Instantiate(prefab, position, Quaternion.identity).EnsureComponent <Rigidbody>(); flag = true; break; } if (!flag) { rigidbody = Object.Instantiate(__instance.defaultPrefab, position, Quaternion.identity).EnsureComponent <Rigidbody>(); } if (rigidbody != null) { rigidbody.isKinematic = false; rigidbody.maxDepenetrationVelocity = 0.5f; rigidbody.maxAngularVelocity = 1f; rigidbody.AddTorque(Vector3.right * Random.Range(6f, 12f)); rigidbody.AddForce(position * 0.2f); } extraSpawns--; } }
public static void Postfix(BreakableResource __instance) { int extraSpawns = UnityEngine.Random.Range(Config.ExtraCount, Config.ExtraCountMax + 1); while (extraSpawns > 0) { bool flag = false; for (int i = 0; i < __instance.numChances; i++) { GameObject gameObject = __instance.ChooseRandomResource(); if (gameObject) { SpawnResourceFromPrefab(__instance, gameObject); flag = true; } } if (!flag) { SpawnResourceFromPrefab(__instance, __instance.defaultPrefab); } extraSpawns--; } }
public static void BreakIntoResources(BreakableResource __instance) { __instance.numChances = GetSpawnNumber(); currIndex = 0; }
void Shoot() { currentPosition = Vector3.Lerp(currentPosition, startPosition - Vector3.forward * 0.5f, 0.3f); Vector3 rot = startRotation.eulerAngles; rot.x -= 30f; Quaternion rotq = Quaternion.Euler(rot); currentRotation = Quaternion.Lerp(currentRotation, rotq, 0.3f); Transform aimTrans = Player.main.camRoot.GetAimingTransform(); if (Targeting.GetTarget(Player.main.gameObject, 200f, out GameObject hit, out float dist)) { Vector3 hitpoint = aimTrans.forward * dist + transform.position; GameObject beam = Instantiate(beamPrefab); LineRenderer line = beam.GetComponent <LineRenderer>(); beam.AddComponent <LineFade>(); line.positionCount = 2; line.SetPosition(0, transform.GetChild(0).position); line.SetPosition(1, hitpoint); Destroy(beam, 0.3f); LiveMixin health = hit.GetComponent <LiveMixin>(); if (health != null) { health.TakeDamage(500f); } else { health = hit.GetComponentInChildren <LiveMixin>(); if (health != null) { health.TakeDamage(500f); } } BreakableResource res = hit.GetComponent <BreakableResource>(); if (res != null) { res.hitsToBreak = 1; res.HitResource(); } else { res = hit.GetComponentInChildren <BreakableResource>(); if (res != null) { res.hitsToBreak = 1; res.HitResource(); } } Rigidbody rb = hit.GetComponent <Rigidbody>(); if (rb != null) { rb.AddForce(aimTrans.forward.normalized * 20f, ForceMode.Impulse); } else { rb = hit.GetComponentInChildren <Rigidbody>(); if (rb != null) { rb.AddForce(aimTrans.forward.normalized * 20f, ForceMode.Impulse); } } }
private static void BreakIntoResources_Patch(BreakableResource __instance) { __instance.SendMessage("OnBreakResource", null, SendMessageOptions.DontRequireReceiver); if (__instance.gameObject.GetComponent <VFXBurstModel>()) { __instance.gameObject.BroadcastMessage("OnKill"); } else { UnityEngine.Object.Destroy(__instance.gameObject); } if (__instance.customGoalText != "") { GoalManager.main.OnCustomGoalEvent(__instance.customGoalText); } bool flag = false; for (int i = 0; i < __instance.numChances; i++) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-01 - start choose random ress"); AssetReferenceGameObject assetReferenceGameObject = __instance.ChooseRandomResource(); if (assetReferenceGameObject != null) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-02 - Random Resouce is called"); if (Player.main.GetVehicle() is Exosuit exosuit) { var installedmodule = exosuit.modules.GetCount(MetalHands_BZ.MetalHandsClawModuleTechType); if (((installedmodule > 0) | (MetalHands_BZ.Config.Config_fastcollect == true)) & exosuit.storageContainer.container.HasRoomFor(1, 1)) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-10 - Start AddToPrawn over randomress"); CoroutineHost.StartCoroutine(AddtoPrawn(__instance, exosuit, assetReferenceGameObject)); } else { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-11 - Spawn original way randomress"); __instance.SpawnResourceFromPrefab(assetReferenceGameObject); } } else { Inventory inventory = Inventory.Get(); if (((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands_BZ.MetalHandsMK2TechType) | (MetalHands_BZ.Config.Config_fastcollect == true)) & inventory.HasRoomFor(1, 1)) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-20 - Player has glove - randomress"); CoroutineHost.StartCoroutine(AddbrokenRestoPlayerInv(__instance, assetReferenceGameObject)); } else { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "03-04 - Spawn original way - defaultress"); __instance.SpawnResourceFromPrefab(assetReferenceGameObject); } } flag = true; } } if (!flag) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "03-01 - default resouce is called"); if (Player.main.GetVehicle() is Exosuit exosuit) { var installedmodule = exosuit.modules.GetCount(MetalHands_BZ.MetalHandsClawModuleTechType); if (((installedmodule > 0) | (MetalHands_BZ.Config.Config_fastcollect == true)) && exosuit.storageContainer.container.HasRoomFor(1, 1)) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "03-02 - Start AddToPrawn over defaultress"); CoroutineHost.StartCoroutine(AddtoPrawn(__instance, exosuit, __instance.defaultPrefabReference)); } else { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-11 - Spawn original way randomress"); __instance.SpawnResourceFromPrefab(__instance.defaultPrefabReference); } } else { Inventory inventory = Inventory.Get(); if (((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands_BZ.MetalHandsMK2TechType) | (MetalHands_BZ.Config.Config_fastcollect == true)) & inventory.HasRoomFor(1, 1)) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "03-03 - Player has glove - defaultress"); CoroutineHost.StartCoroutine(AddbrokenRestoPlayerInv(__instance, __instance.defaultPrefabReference)); } else { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "03-04 - Spawn original way - defaultress"); __instance.SpawnResourceFromPrefab(__instance.defaultPrefabReference); } } } FMODUWE.PlayOneShot(__instance.breakSound, __instance.transform.position, 1f); if (__instance.hitFX) { global::Utils.PlayOneShotPS(__instance.breakFX, __instance.transform.position, Quaternion.Euler(new Vector3(270f, 0f, 0f)), null); } }
private static void BreakIntoResources_Patch(BreakableResource __instance) { __instance.SendMessage("OnBreakResource", null, SendMessageOptions.DontRequireReceiver); if (__instance.gameObject.GetComponent <VFXBurstModel>()) { __instance.gameObject.BroadcastMessage("OnKill"); } else { UnityEngine.Object.Destroy(__instance.gameObject); } if (__instance.customGoalText != "") { GoalManager.main.OnCustomGoalEvent(__instance.customGoalText); } bool flag = false; for (int i = 0; i < __instance.numChances; i++) { GameObject gameObject = __instance.ChooseRandomResource(); if (gameObject) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "1 - Random Resouce is called"); if (Player.main.GetVehicle() is Exosuit exosuit) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "2 - Start AddToPrawn over randomress"); AddtoPrawn(__instance, exosuit, gameObject); } else { if ((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands.MetalHandsMK2TechType) | (MetalHands.Config.Config_fastcollect == true)) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "3 - Player has glove - randomress"); Vector2int size = CraftData.GetItemSize(CraftData.GetTechType(gameObject)); Inventory inventory = Inventory.Get(); if (inventory.HasRoomFor(size.x, size.y)) { CraftData.AddToInventory(CraftData.GetTechType(gameObject)); } else { __instance.SpawnResourceFromPrefab(gameObject); } } else { __instance.SpawnResourceFromPrefab(gameObject); } } flag = true; } } if (!flag) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "5 - default resouce is called"); if (Player.main.GetVehicle() is Exosuit exosuit) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "6 - Start AddToPrawn over defaultress"); AddtoPrawn(__instance, exosuit, __instance.defaultPrefab); } else if ((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands.MetalHandsMK2TechType) | (MetalHands.Config.Config_fastcollect == true)) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "7 - Player has glove - defaultress"); Vector2int size = CraftData.GetItemSize(CraftData.GetTechType(__instance.defaultPrefab)); Inventory inventory = Inventory.Get(); if (inventory.HasRoomFor(size.x, size.y)) { CraftData.AddToInventory(CraftData.GetTechType(__instance.defaultPrefab)); } else { __instance.SpawnResourceFromPrefab(__instance.defaultPrefab); } } else { __instance.SpawnResourceFromPrefab(__instance.defaultPrefab); } } FMODUWE.PlayOneShot(__instance.breakSound, __instance.transform.position, 1f); if (__instance.hitFX) { Utils.PlayOneShotPS(__instance.breakFX, __instance.transform.position, Quaternion.Euler(new Vector3(270f, 0f, 0f)), null); } QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "9 - Original Methode ending"); }
private static void Postfix(BreakableResource __instance) { HitResource_Patch_Postfix(__instance); }