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--; } }
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 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); } }