From f7b423c044c1a57811419e1ebe259ff964b4ed46 Mon Sep 17 00:00:00 2001 From: dartasen Date: Sun, 12 Jan 2025 14:26:43 +0100 Subject: [PATCH 1/2] Add Sync for Stalker Teeth Drop --- .../Dynamic/Stalker_CheckLoseTooth_Patch.cs | 51 ++++++++++++++++--- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/NitroxPatcher/Patches/Dynamic/Stalker_CheckLoseTooth_Patch.cs b/NitroxPatcher/Patches/Dynamic/Stalker_CheckLoseTooth_Patch.cs index 71a6ef6776..280fa1884a 100644 --- a/NitroxPatcher/Patches/Dynamic/Stalker_CheckLoseTooth_Patch.cs +++ b/NitroxPatcher/Patches/Dynamic/Stalker_CheckLoseTooth_Patch.cs @@ -1,4 +1,6 @@ -using System.Reflection; +using System.Reflection; +using NitroxClient.GameLogic; +using NitroxModel.DataStructures; using NitroxModel.Helper; using UnityEngine; @@ -8,22 +10,55 @@ public sealed partial class Stalker_CheckLoseTooth_Patch : NitroxPatch, IDynamic { private static readonly MethodInfo TARGET_METHOD = Reflect.Method((Stalker t) => t.CheckLoseTooth(default(GameObject))); - //GetComponent was returning null for everything instead of a HardnessMixin with a hardness value. Since this component - //isn't used for anything else than the stalker teeth drop, we hard-code the values and bingo. + // HardnessMixin seems to be a bit buggy (ie: undefined values for some scraps, which is a vanilla bug), so we'll just hard-code the values for now. + // Note that HardnessMixin is only used by Stalkers public static bool Prefix(Stalker __instance, GameObject target) { - float dropProbability = 0f; + if (!__instance.TryGetNitroxId(out NitroxId creatureId) + && !Resolve().HasAnyLockType(creatureId)) + { + return false; + } + + TechType techType = CraftData.GetTechType(target); - if (techType == TechType.ScrapMetal) + float dropProbability = techType switch + { + TechType.ScrapMetal => 0.25f, // https://subnautica.fandom.com/wiki/Metal_Salvage_(Subnautica) + TechType.MapRoomCamera => 0.25f, + TechType.Titanium or TechType.Silver or TechType.Gold or TechType.Kyanite or TechType.Copper or TechType.Nickel => 0.15f, + _ => 0f, + }; + + if (dropProbability == 0) { - dropProbability = 0.15f; // 15% probability + return false; } - if (UnityEngine.Random.value < dropProbability) + // Random.value returns a random float within[0.0..1.0] (range is inclusive) + if (Random.value < dropProbability && Random.value < 0.5f) { - __instance.LoseTooth(); + // Code from Stalker.LoseTooth() to avoid having another patch + + GameObject toothGameObject = Object.Instantiate(__instance.toothPrefab); + toothGameObject.transform.position = __instance.loseToothDropLocation.transform.position; + toothGameObject.transform.rotation = __instance.loseToothDropLocation.transform.rotation; + + if (toothGameObject.activeSelf && __instance.isActiveAndEnabled) + { + foreach (Collider collider in toothGameObject.GetComponentsInChildren()) + { + Physics.IgnoreCollision(__instance.stalkerBodyCollider, collider); + } + } + + Utils.PlayFMODAsset(__instance.loseToothSound, toothGameObject.transform, 20f); + LargeWorldEntity.Register(toothGameObject); + + Resolve().Dropped(toothGameObject); } + return false; } } From 630faec80a57d7ba73fe154d414acf3ebc5bf238 Mon Sep 17 00:00:00 2001 From: dartasen Date: Sun, 29 Jun 2025 10:16:05 +0200 Subject: [PATCH 2/2] Add stalker tooth break sound to whitelist --- .../Resources/SoundWhitelist_Subnautica.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nitrox.Assets.Subnautica/Resources/SoundWhitelist_Subnautica.csv b/Nitrox.Assets.Subnautica/Resources/SoundWhitelist_Subnautica.csv index 6282a6fa6e..f634215bd9 100644 --- a/Nitrox.Assets.Subnautica/Resources/SoundWhitelist_Subnautica.csv +++ b/Nitrox.Assets.Subnautica/Resources/SoundWhitelist_Subnautica.csv @@ -123,7 +123,7 @@ event:/creature/tred/stomp;false;false;0 event:/creature/trident/bite;false;false;0 event:/creature/trident/charge;false;false;0 event:/creature/trident/roar;false;false;0 -event:/creature/trident/tooth_break;false;false;0 +event:/creature/trident/tooth_break;true;true;15 event:/creature/trident/wound;false;false;0 event:/creature/warper/idle;false;false;0 event:/creature/warper/portal_close;false;false;0