private static void OnGrantEquipment(On.RoR2.GenericPickupController.orig_GrantEquipment orig, GenericPickupController self, CharacterBody body, Inventory inventory) { #region Sharedequipment var equip = PickupCatalog.GetPickupDef(self.pickupIndex).equipmentIndex; if (!BlackList.HasEquipment(equip) && NetworkServer.active && IsValidEquipmentPickup(self.pickupIndex) && GeneralHooks.IsMultiplayer()) { foreach (var player in PlayerCharacterMasterController.instances.Select(p => p.master) .Where(p => !p.IsDeadAndOutOfLivesServer() || ShareSuite.DeadPlayersGetItems.Value)) { SyncToolbotEquip(player, ref equip); // Sync Mul-T Equipment, but perform primary equipment pickup only for clients if (player.inventory == inventory) { continue; } player.inventory.SetEquipmentIndex(equip); self.NetworkpickupIndex = PickupCatalog.FindPickupIndex(equip); } } orig(self, body, inventory); #endregion }
private void GenericPickupControllerOnGrantEquipment(On.RoR2.GenericPickupController.orig_GrantEquipment orig, GenericPickupController self, CharacterBody body, Inventory inventory) { if (NetworkServer.active) { var tracker = body.master.GetComponent <DurabilityTracker>(); if (tracker != null) { _nextDropDurability = inventory.activeEquipmentSlot == 0 ? tracker.durability : tracker.durabilityAlt; } else { _nextDropDurability = FullDurability; } } orig(self, body, inventory); if (NetworkServer.active) { float durability = FullDurability; var tracker = self.gameObject.GetComponent <DurabilityTracker>(); if (tracker != null) { durability = tracker.durability; tracker.durability = _nextDropDurability; _nextDropDurability = FullDurability; } var masterTracker = body.master.GetComponent <DurabilityTracker>(); if (masterTracker == null) { masterTracker = body.masterObject.AddComponent <DurabilityTracker>(); } if (inventory.activeEquipmentSlot == 0) { masterTracker.durability = durability; } else { masterTracker.durabilityAlt = durability; } var networkUser = body.master?.playerCharacterMasterController?.networkUser; if (networkUser != null && !networkUser.isLocalPlayer) { var message = new UpdateDurabilityMessage { durability = masterTracker.durability, durabilityAlt = masterTracker.durabilityAlt }; _cmdUpdateDurability.Invoke(message, networkUser); } } }
private static void OnGrantEquipment(On.RoR2.GenericPickupController.orig_GrantEquipment orig, GenericPickupController self, CharacterBody body, Inventory inventory) { #region Sharedequipment if (!ShareSuite.EquipmentShared.Value || !GeneralHooks.IsMultiplayer() || !NetworkServer.active) { orig(self, body, inventory); return; } // Get the old and new equipment's index var oldEquip = body.inventory.currentEquipmentIndex; var oldEquipPickupIndex = GetPickupIndex(oldEquip); var newEquip = PickupCatalog.GetPickupDef(self.pickupIndex).equipmentIndex; // Send the pickup message ChatHandler.SendPickupMessage(body.master, self.pickupIndex); // Give the equipment to the picker inventory.SetEquipmentIndex(newEquip); // Destroy the object Object.Destroy(self.gameObject); // If the old equipment was not shared and the new one is, drop the blacklisted equipment and any other // shared equipment that the other players have if (!EquipmentShared(oldEquip) && EquipmentShared(newEquip)) { CreateDropletIfExists(oldEquipPickupIndex, self.transform.position); DropAllOtherSharedEquipment(self, body, oldEquip); } // If the old equipment was shared and the new one isn't, but the picker is the only one alive with the // shared equipment, drop it on the ground and return else if (EquipmentShared(oldEquip) && !EquipmentShared(newEquip) && GetLivingPlayersWithEquipment(oldEquip) < 1 || !EquipmentShared(oldEquip) && !EquipmentShared(newEquip)) { CreateDropletIfExists(oldEquipPickupIndex, self.transform.position); return; } // If the new equip is shared, create a droplet of the old one. else if (EquipmentShared(newEquip)) { CreateDropletIfExists(oldEquipPickupIndex, self.transform.position); } // If the equipment they're picking up is not shared and someone else is alive with the shared equipment, // return else { return; } // Loop over everyone who has an inventory and isn't the picker foreach (var player in PlayerCharacterMasterController.instances.Select(p => p.master) .Where(p => p.inventory && p != body.master)) { var playerInventory = player.inventory; var playerOrigEquipment = playerInventory.currentEquipmentIndex; // If the player currently has an equipment that's blacklisted if (!EquipmentShared(playerOrigEquipment)) { // And the config option is set so that they will drop the item when shared if (!ShareSuite.DropBlacklistedEquipmentOnShare.Value) { continue; } // Create a droplet of their current blacklisted equipment on the ground var transform = player.GetBodyObject().transform; var pickupIndex = PickupCatalog.FindPickupIndex(playerOrigEquipment); PickupDropletController.CreatePickupDroplet(pickupIndex, transform.position, transform.forward * 20f); } // Give the player the new equipment playerInventory.SetEquipmentIndex(newEquip); self.NetworkpickupIndex = PickupCatalog.FindPickupIndex(newEquip); // Sync the equipment if they're playing MUL-T SyncToolbotEquip(player, ref newEquip); } #endregion }
private void GenericPickupController_GrantEquipment(On.RoR2.GenericPickupController.orig_GrantEquipment orig, GenericPickupController self, CharacterBody body, Inventory inventory) { orig(self, body, inventory); LastPickedUpItem[inventory] = PickupCatalog.FindPickupIndex(inventory.GetEquipmentIndex()); }