diff --git a/CHANGELOG.md b/CHANGELOG.md index 8141fc9..aaf44f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,3 +8,8 @@ # v0.1.1 | Throw passport anywhere patch - Added PassportPatch.cs and registerd it as GlobalPatch in Plugin.cs + +# v0.1.2 | Bags for Everyone + +- Added BagsForEveryoneModule and BagsForEveryonePatch +- BagsForEveryonePatch adds a postfix to SingleItemSpawner.TrySpawnItems that checks if the spawner is the first one in the biome, and if so, it spawns extra bags based on the player count. \ No newline at end of file diff --git a/src/JordanMod/JordanMod.csproj b/src/JordanMod/JordanMod.csproj index 1dde2ae..25d3644 100644 --- a/src/JordanMod/JordanMod.csproj +++ b/src/JordanMod/JordanMod.csproj @@ -8,7 +8,7 @@ JordanMod - 0.1.1 + 0.1.2 diff --git a/src/JordanMod/modules/bags_for_everyone/BagsForEveryoneModule.cs b/src/JordanMod/modules/bags_for_everyone/BagsForEveryoneModule.cs new file mode 100644 index 0000000..3faa3d1 --- /dev/null +++ b/src/JordanMod/modules/bags_for_everyone/BagsForEveryoneModule.cs @@ -0,0 +1,14 @@ +using System; + +namespace JordanMod.Modules.BagsForEveryone; + +[Module(Enabled = true)] +class BagsForEveryoneModule : Module +{ + public override string ModuleName => "Bags for Everyone Module"; + + public override Type[] GetPatches() + { + return [typeof(BagsForEveryonePatch)]; + } +} \ No newline at end of file diff --git a/src/JordanMod/patches/BagsForEveryonePatch.cs b/src/JordanMod/patches/BagsForEveryonePatch.cs new file mode 100644 index 0000000..f6e3921 --- /dev/null +++ b/src/JordanMod/patches/BagsForEveryonePatch.cs @@ -0,0 +1,41 @@ +using AncestralMod; +using HarmonyLib; +using Photon.Pun; +using UnityEngine; + +namespace JordanMod.Modules.BagsForEveryone; + +public class BagsForEveryonePatch +{ + + [HarmonyPatch(typeof(SingleItemSpawner), "TrySpawnItems")] + [HarmonyPostfix] + static void Postfix(SingleItemSpawner __instance) + { + ForEachPlayer(__instance); + } + + private static void ForEachPlayer(SingleItemSpawner spawner) + { + if (!Helper.IsMasterClient()) return; + + bool isBackpackSPawner = spawner.transform.name == "Backpack_Spawner"; + if (!isBackpackSPawner) return; + + bool isFirstSpawner = spawner.transform.IsChildOf(GameObject.Find("Biome_1").transform); + if (!isFirstSpawner) return; + + int playerCount = PhotonNetwork.PlayerList.Length - 1; + if (playerCount <= 0) return; + for (int i = 1; i <= playerCount; i++) + { + Vector3 spawnPosition = spawner.transform.position + Vector3.up * 0.1f + Vector3.right * i; + PhotonView component = PhotonNetwork.InstantiateItemRoom(spawner.prefab.name, spawnPosition, spawner.transform.rotation).GetComponent(); + if (spawner.isKinematic) + { + component.GetComponent().RPC("SetKinematicRPC", RpcTarget.AllBuffered, true, component.transform.position, component.transform.rotation); + } + } + } + +} \ No newline at end of file