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; } }
public static bool CheckIfInventoryCostExceedThreshold(int inventoryCost) { var leastInventoryCost = InventoryCostCounter.GetUserWithLeastItemsCosts().cost; int inventoryCostDifference = inventoryCost - Math.Min(leastInventoryCost, inventoryCost); return(inventoryCostDifference >= GetInventoryCostThreshold(inventoryCost)); }
// If "orig" method is fired, GenericPickupController_AttemptGrant will happen next private void GenericPickupController_OnInteractionBegin(On.RoR2.GenericPickupController.orig_OnInteractionBegin orig, GenericPickupController self, Interactor activator) { if (!CheckIfCurrentStageQualifyForSharing() || !CheckIfItemQualifyForSharing(self.pickupIndex)) { orig(self, activator); return; } var user = UsersHelper.GetUser(activator); // get item if (printedItemsWatcher.CheckIfUserHasPrintedItems(user, self.pickupIndex) || CheckIfUserCanPickItem(user)) { orig(self, activator); return; } // give random item to lowest cost player else if (PluginConfig.HowToHandleItemDisproportion.Value == HowToHandleItemDisproportion.GiveRandomItemToLowestCostsPlayer) { orig(self, activator); return; } // share item else if (pingedItemsWatcher.TryConsumeItemPingedByUser(user, self)) { var userWithLeastItems = InventoryCostCounter.GetUserWithLeastItemsCosts().user; var userWithLeastItemsInteractor = UsersHelper.GetUserInteractor(userWithLeastItems); if (userWithLeastItemsInteractor) { self.OnInteractionBegin(userWithLeastItemsInteractor); } } // can't pick item else if (user) { ChatHelper.PlayerHasTooManyItems(user.userName); } }