private static void ChestBehaviorOnRollItem(On.RoR2.ChestBehavior.orig_RollItem orig, RoR2.ChestBehavior self) { if (!NetworkServer.active) { Debug.LogWarning("[Server] function 'System.Void RoR2.ChestBehavior::RollItem()' called on client"); return; } if (self.GetFieldValue <PickupIndex>("dropPickup") != PickupIndex.none) { return; } var chestName = self.name.Replace("(Clone)", "").Trim(); Logger.LogDebug($"Dropping {self.name} - {self.requiredItemTag}"); if (ChestLookup.ContainsKey(chestName)) { self.SetFieldValue("dropPickup", GetSelection(ChestLookup[chestName], Run.instance.treasureRng.nextNormalizedFloat)); } else if (self.name.ToLower().Contains(Lockbox.ToLower())) { Logger.LogDebug("Dropping Lockbox"); var lockboxes = CharacterMaster.readOnlyInstancesList.Sum(x => x.inventory.GetItemCount(ItemIndex.TreasureCache)); Selection[ItemDropLocation.Lockbox][1].DropChance = DefaultSmallChestTier2DropChance * lockboxes; Selection[ItemDropLocation.Lockbox][2].DropChance = DefaultSmallChestTier3DropChance * Mathf.Pow(lockboxes, 2f); self.SetFieldValue("dropPickup", GetSelection(ItemDropLocation.Lockbox, Run.instance.treasureRng.nextNormalizedFloat)); } else if (self.name.ToLower().Contains("scavlunarbackpack")) { self.SetFieldValue <PickupIndex>("dropPickup", PickupCatalog.FindPickupIndex("LunarCoin.Coin0")); } else { Logger.LogError($"Unidentified chest type: {self.name}. Dropping normal loot instead."); self.SetFieldValue("dropPickup", GetSelection(ItemDropLocation.SmallChest, Run.instance.treasureRng.nextNormalizedFloat)); } }
private void ChestBehavior_RollItem(On.RoR2.ChestBehavior.orig_RollItem orig, ChestBehavior self) { if (!NetworkServer.active) { Debug.LogWarning("[Server] function 'System.Void RoR2.ChestBehavior::RollItem()' called on client"); return; } WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(8); weightedSelection.AddChoice(Run.instance.availableTier1DropList, self.tier1Chance); weightedSelection.AddChoice(Run.instance.availableTier2DropList, self.tier2Chance); weightedSelection.AddChoice(Run.instance.availableTier3DropList, self.tier3Chance); weightedSelection.AddChoice(Run.instance.availableLunarDropList, self.lunarChance); List <PickupIndex> dropList = weightedSelection.Evaluate(Run.instance.treasureRng.nextNormalizedFloat); if (self.gameObject.name.StartsWith("LunarChest")) { self.GetType().GetMethod("PickFromList", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(self, new object[] { dropList }); } }