From f17ac65b177dc557326155a442f31c6180a3e8f6 Mon Sep 17 00:00:00 2001 From: Moffein <22742925+Moffein@users.noreply.github.com> Date: Fri, 23 Dec 2022 17:51:07 -0800 Subject: [PATCH] Chirr minions now lose items alongside their owner. Fixed a potential infinite loop related to Chirr inventory sharing. --- Starstorm 2/Modules/Prefabs.cs | 2 ++ Starstorm 2/StarstormPlugin.cs | 2 +- .../Chirr/Components/ChirrFriendController.cs | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Starstorm 2/Modules/Prefabs.cs b/Starstorm 2/Modules/Prefabs.cs index ab780abf..ffe906cd 100644 --- a/Starstorm 2/Modules/Prefabs.cs +++ b/Starstorm 2/Modules/Prefabs.cs @@ -117,6 +117,8 @@ internal static SurvivorDef RegisterNewSurvivor(GameObject bodyPrefab, GameObjec survivorDef.desiredSortPosition = sortPosition; survivorDef.unlockableDef = unlockableDef; + survivorDef.cachedName = namePrefix; + survivorDefinitions.Add(survivorDef); return survivorDef; } diff --git a/Starstorm 2/StarstormPlugin.cs b/Starstorm 2/StarstormPlugin.cs index 59e91646..a6372161 100644 --- a/Starstorm 2/StarstormPlugin.cs +++ b/Starstorm 2/StarstormPlugin.cs @@ -44,7 +44,7 @@ public class StarstormPlugin : BaseUnityPlugin { internal const string guid = "com.ChirrLover.Starstorm2Unofficial"; internal const string modName = "Starstorm 2 Unofficial"; - internal const string version = "0.5.10"; + internal const string version = "0.5.12"; public static StarstormPlugin instance; diff --git a/Starstorm 2/Survivors/Chirr/Components/ChirrFriendController.cs b/Starstorm 2/Survivors/Chirr/Components/ChirrFriendController.cs index a784b1b2..a9f56657 100644 --- a/Starstorm 2/Survivors/Chirr/Components/ChirrFriendController.cs +++ b/Starstorm 2/Survivors/Chirr/Components/ChirrFriendController.cs @@ -133,12 +133,27 @@ private void Awake() trackerUpdateStopwatch = 0f; RoR2.Inventory.onServerItemGiven += UpdateMinionInventory;//Is there a better way with onInventoryChangedGlobal? + On.RoR2.Inventory.RemoveItem_ItemIndex_int += UpdateMinionInventoryItemRemoved; On.RoR2.PingerController.SetCurrentPing += MinionPingRetarget; this.indicatorCannotBefriend = new Indicator(base.gameObject, indicatorCannotBefriendPrefab); this.indicatorReadyToBefriend = new Indicator(base.gameObject, indicatorReadyToBefriendPrefab); this.indicatorFriend = new Indicator(base.gameObject, indicatorFriendPrefab); } + + private void UpdateMinionInventoryItemRemoved(On.RoR2.Inventory.orig_RemoveItem_ItemIndex_int orig, Inventory self, ItemIndex itemIndex, int count) + { + orig(self, itemIndex, count); + if (NetworkServer.active && ownerMaster && this._hasFriend && this.targetMaster && this.targetMaster.inventory && ownerMaster != this.targetMaster) //last case prevents a recursive loop + { + CharacterMaster cm = self.GetComponent(); + if (cm == ownerMaster) + { + this.targetMaster.inventory.RemoveItem(itemIndex, count); + } + } + } + private void Start() { if (ownerBody) ownerMaster = ownerBody.master; @@ -183,11 +198,12 @@ private void OnDestroy() { RoR2.Inventory.onServerItemGiven -= UpdateMinionInventory; On.RoR2.PingerController.SetCurrentPing -= MinionPingRetarget; + On.RoR2.Inventory.RemoveItem_ItemIndex_int -= UpdateMinionInventoryItemRemoved; } private void UpdateMinionInventory(Inventory inventory, ItemIndex itemIndex, int count) { - if (ownerMaster && this._hasFriend && this.targetMaster && this.targetMaster.inventory && !IsBlacklistedItem(itemIndex)) + if (count > 0 && ownerMaster && this._hasFriend && this.targetMaster && this.targetMaster.inventory && !IsBlacklistedItem(itemIndex) && ownerMaster != this.targetMaster) { CharacterMaster cm = inventory.GetComponent(); if (cm == ownerMaster)