private void GenericPickupController_AttemptGrant(On.RoR2.GenericPickupController.orig_AttemptGrant orig, GenericPickupController self, CharacterBody body) { if (!NetworkServer.active) { Debug.LogWarning("[Server] function 'System.Void RoR2.GenericPickupController::AttemptGrant(RoR2.CharacterBody)' called on client"); return; } if (!self.gameObject.GetComponent <SpiceRolled>()) { self.gameObject.AddComponent <SpiceRolled>(); TeamComponent component = body.GetComponent <TeamComponent>(); if (component && component.teamIndex == TeamIndex.Player) { Inventory inventory = body.inventory; if (inventory) { var spiceCount = inventory.GetItemCount(SpiceTally); var spiceCountAdjusted = spiceCount < SpiceEquipment_MaxPerPlayer ? spiceCount : 0; if (Util.CheckRoll(spiceCountAdjusted)) { self.pickupIndex = PickupCatalog.FindPickupIndex(Spice.instance.EquipmentDef.equipmentIndex); } } } } orig(self, body); }
private void GenericPickupController_AttemptGrant(On.RoR2.GenericPickupController.orig_AttemptGrant orig, GenericPickupController self, CharacterBody body) { if (!CheckIfCurrentStageQualifyForSharing() || !CheckIfItemQualifyForSharing(self.pickupIndex)) { orig(self, body); return; } var user = UsersHelper.GetUser(body); if (printedItemsWatcher.TryConsumeUserPrintedItem(user, self.pickupIndex) || CheckIfUserCanPickItem(user)) { orig(self, body); return; } else if (PluginConfig.HowToHandleItemDisproportion.Value == HowToHandleItemDisproportion.GiveRandomItemToLowestCostsPlayer) { var userWithLeastItems = InventoryCostCounter.GetUserWithLeastItemsCosts().user; BoostPlayerWithRandomItem(userWithLeastItems); orig(self, body); return; } }
private void GenericPickupController_AttemptGrant(On.RoR2.GenericPickupController.orig_AttemptGrant orig, RoR2.GenericPickupController self, RoR2.CharacterBody body) { if (PickupCatalog.GetPickupDef(self.pickupIndex).equipmentIndex != EquipmentIndex.None) { orig(self, body); return; } InventoryLimits limits = null; limits = body.master.gameObject.GetComponent <InventoryLimits>(); if (limits != null && PickupCatalog.GetPickupDef(self.pickupIndex).itemIndex != ItemIndex.None) { if (limits.Limited) { /* * Chat.AddMessage($"<color=#FFFF00>Inventory full: {limits.amount}/{limits.limit}. Gain experience to gain free space.</color>"); */ return; } } orig(self, body); if (limits != null && PickupCatalog.GetPickupDef(self.pickupIndex).itemIndex != ItemIndex.None) { if (NetworkServer.active) { DropperChat.ItemCountMessage(body.GetUserName(), limits.amount, limits.limit); } } }
private void GenericPickupController_AttemptGrant(On.RoR2.GenericPickupController.orig_AttemptGrant orig, GenericPickupController self, CharacterBody body) { if (!NetworkServer.active) { Debug.LogWarning("[Server] function 'System.Void RoR2.GenericPickupController::AttemptGrant(RoR2.CharacterBody)' called on client"); return; } if (!ArtifactEnabled) { return; } if (!body.masterObject) { return; } TeamComponent component = body.GetComponent <TeamComponent>(); if (component) { Inventory inventory = body.inventory; if (inventory) { PlayerCharacterMasterController isPlayer = body.masterObject.GetComponent <PlayerCharacterMasterController>(); self.consumed = true; PickupDef pickupDef = PickupCatalog.GetPickupDef(self.pickupIndex); DropInventoryOnDeath comp = null; if (!isPlayer && body.teamComponent.teamIndex != TeamIndex.Player) { comp = body.gameObject.GetComponent <DropInventoryOnDeath>(); if (!comp) { comp = body.gameObject.AddComponent <DropInventoryOnDeath>(); } } if (pickupDef.itemIndex != ItemIndex.None) { self.GrantItem(body, inventory); } if (pickupDef.coinValue != 0U) { self.GrantLunarCoin(body, pickupDef.coinValue); } if (isPlayer) { if (pickupDef.equipmentIndex != EquipmentIndex.None) { self.GrantEquipment(body, inventory); } if (pickupDef.artifactIndex != ArtifactIndex.None) { self.GrantArtifact(body, pickupDef.artifactIndex); } } } } }
private void GenericPickupController_AttemptGrant(On.RoR2.GenericPickupController.orig_AttemptGrant orig, GenericPickupController self, CharacterBody body) { if (NetworkServer.active) { if (isCurrentStageBazaar()) { if (!bazaar.IsDisplayItem(self.gameObject)) { orig(self, body); } } else { orig(self, body); } } }
private static void OnGrantItem(On.RoR2.GenericPickupController.orig_AttemptGrant orig, GenericPickupController self, CharacterBody body) { var item = PickupCatalog.GetPickupDef(self.pickupIndex); var itemDef = ItemCatalog.GetItemDef(item.itemIndex); var randomizedPlayerDict = new Dictionary <CharacterMaster, PickupDef>(); // If the player is dead, they might not have a body. The game uses inventory.GetComponent, avoiding the issue entirely. var master = body?.master ?? body.inventory?.GetComponent <CharacterMaster>(); if (( //ShareSuite.RandomizeSharedPickups.Value || !Blacklist.HasItem(item.itemIndex)) && NetworkServer.active && IsValidItemPickup(self.pickupIndex) && GeneralHooks.IsMultiplayer()) { if (ShareSuite.RandomizeSharedPickups.Value) { randomizedPlayerDict.Add(master, item); } foreach (var player in PlayerCharacterMasterController.instances.Select(p => p.master)) { // Ensure character is not original player that picked up item if (body != null && player.inventory == body.inventory) { continue; } // Do not reward dead players if not required if (!ShareSuite.DeadPlayersGetItems.Value && player.IsDeadAndOutOfLivesServer()) { continue; } if (ShareSuite.RandomizeSharedPickups.Value) { var pickupIndex = GetRandomItemOfTier(itemDef.tier, item.pickupIndex); if (pickupIndex == null) { // Could not find any not blacklisted item in that tier. You get nothing! Good day, sir! continue; } var giveItem = PickupCatalog.GetPickupDef(pickupIndex.Value); player.inventory.GiveItem(giveItem.itemIndex); // Alternative: Only show pickup text for yourself // var givePickupDef = PickupCatalog.GetPickupDef(givePickupIndex); // Chat.AddPickupMessage(body, givePickupDef.nameToken, givePickupDef.baseColor, 1); // Legacy -- old normal pickup message handler //SendPickupMessage(player, giveItem); randomizedPlayerDict.Add(player, giveItem); } // Otherwise give everyone the same item else { player.inventory.GiveItem(item.itemIndex); } } if (ShareSuite.RandomizeSharedPickups.Value) { orig(self, body); ChatHandler.SendRichRandomizedPickupMessage(master, item, randomizedPlayerDict); return; } } orig(self, body); ChatHandler.SendRichPickupMessage(master, item); }
private static void OnGrantEquipment(On.RoR2.GenericPickupController.orig_AttemptGrant orig, GenericPickupController self, CharacterBody body) { #region Sharedequipment if (!ShareSuite.EquipmentShared.Value || !GeneralHooks.IsMultiplayer() || !NetworkServer.active) { orig(self, body); 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 body.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 }