public void Awake() { DropRateModifier = Config.Bind("Main", "SacrificeArtifactDropRate", 5f, "Percent chance an item will drop from a monster on death. 1 is 1% drop rate, 100 is 100%, etc."); CustomWeightsEnabled = Config.Bind("Weights", "CustomWeightsEnabled", true, "If custom weights are enabled. Weights change how often some tiers of items will drop versus others."); IL.RoR2.Artifacts.SacrificeArtifactManager.OnServerCharacterDeath += (il) => // modification for overall drop % chance { ILCursor c = new ILCursor(il); c.GotoNext( x => x.MatchLdloc(0), x => x.MatchLdcR4(0), x => x.MatchLdnull() ); // find location c.Next.OpCode = OpCodes.Ldc_R4; // change from local variable to float32 c.Next.Operand = DropRateModifier.Value; // set to config value }; if (CustomWeightsEnabled.Value) { On.RoR2.BasicPickupDropTable.GenerateWeightedSelection += (orig, self, run) => // modification to add boss items to the droptable { orig(self, run); // call original code first if (BossWeight.Value > 0f) { WeightedSelection <List <PickupIndex> > pi = self.GetFieldValue <WeightedSelection <List <PickupIndex> > >("selector"); // get BasicPickupDropTable.selector print("Adding boss items to the drop table."); pi.AddChoice(run.availableBossDropList, BossWeight.Value); } }; On.RoR2.Artifacts.SacrificeArtifactManager.Init += (orig) => // modification for individual item tier weights { orig(); // call original code first FieldInfo droptb = typeof(RoR2.Artifacts.SacrificeArtifactManager).GetField("dropTable", BindingFlags.NonPublic | BindingFlags.Static); var dropTb = droptb.GetValue(null); float getFieldVal(string name) => dropTb.GetFieldValue <float>(name); void setFieldVal(string name, float val) { dropTb.SetFieldValue <float>(name, val); } // config default values use the game's values in case the devs ever change the weights in the future Tier1Weight = Config.Bind("Weights", "Tier1Weight", getFieldVal("tier1Weight"), "Weight of Tier 1 (white) items."); Tier2Weight = Config.Bind("Weights", "Tier2Weight", getFieldVal("tier2Weight"), "Weight of Tier 2 (lime) items."); Tier3Weight = Config.Bind("Weights", "Tier3Weight", getFieldVal("tier3Weight"), "Weight of Tier 3 (red) items."); EquipmentWeight = Config.Bind("Weights", "EquipmentWeight", getFieldVal("equipmentWeight"), "Weight of Equipment (orange) items."); LunarWeight = Config.Bind("Weights", "LunarWeight", getFieldVal("lunarWeight"), "Weight of Lunar (cyan) items."); BossWeight = Config.Bind("Weights", "BossWeight", 0f, "Weight of Boss (yellow) items."); setFieldVal("tier1Weight", Tier1Weight.Value); setFieldVal("tier2Weight", Tier2Weight.Value); setFieldVal("tier3Weight", Tier3Weight.Value); setFieldVal("equipmentWeight", EquipmentWeight.Value); setFieldVal("lunarWeight", LunarWeight.Value); }; } }
public static EliteAffixCard ChooseEliteAffix(DirectorCard monsterCard, double monsterCredit, Xoroshiro128Plus rng) { if (((CharacterSpawnCard)monsterCard.spawnCard).noElites) { return(null); } var eliteSelection = new WeightedSelection <EliteAffixCard>(); foreach (var card in Cards) { var weight = card.GetSpawnWeight(monsterCard); if (weight > 0 && card.isAvailable()) { var cost = monsterCard.cost * card.costMultiplier; if (cost <= monsterCredit) { eliteSelection.AddChoice(card, weight); } } } if (eliteSelection.Count > 0) { var card = eliteSelection.Evaluate(rng.nextNormalizedFloat); return(card); } return(null); }
// Token: 0x0600090D RID: 2317 RVA: 0x00027270 File Offset: 0x00025470 private void Awake() { this.interactableSelection = this.GenerateDirectorCardWeightedSelection(this.interactableCategories); this.monsterSelection = this.GenerateDirectorCardWeightedSelection(this.monsterCategories); if (NetworkServer.active) { this.rng = new Xoroshiro128Plus(Run.instance.stageRng.nextUlong); if (this.rng.nextNormalizedFloat <= 0.02f) { Debug.Log("Trying to find family selection..."); WeightedSelection <ClassicStageInfo.MonsterFamily> weightedSelection = new WeightedSelection <ClassicStageInfo.MonsterFamily>(8); for (int i = 0; i < this.possibleMonsterFamilies.Length; i++) { if (this.possibleMonsterFamilies[i].minimumStageCompletion <= Run.instance.stageClearCount && this.possibleMonsterFamilies[i].maximumStageCompletion > Run.instance.stageClearCount) { weightedSelection.AddChoice(this.possibleMonsterFamilies[i], this.possibleMonsterFamilies[i].selectionWeight); } } if (weightedSelection.Count > 0) { ClassicStageInfo.MonsterFamily monsterFamily = weightedSelection.Evaluate(this.rng.nextNormalizedFloat); this.monsterSelection = this.GenerateDirectorCardWeightedSelection(monsterFamily.monsterFamilyCategories); base.StartCoroutine("BroadcastFamilySelection", monsterFamily); } } } }
private void GoToNextLevel() { if (NetworkServer.active && !SceneExitController.isRunning) { SceneCollection startingScenes = initialStartingScenes; if (startingScenes == null || startingScenes.isEmpty) { startingScenes = ScriptableObject.CreateInstance <SceneCollection>(); startingScenes.SetSceneEntries(new SceneCollection.SceneEntry[] { new SceneCollection.SceneEntry { sceneDef = SceneCatalog.GetSceneDefFromSceneName("blackbeach"), weight = 1, }, new SceneCollection.SceneEntry { sceneDef = SceneCatalog.GetSceneDefFromSceneName("golemplains"), weight = 1, }, }); } WeightedSelection <SceneDef> sceneDefs = new WeightedSelection <SceneDef>(); startingScenes.AddToWeightedSelection(sceneDefs); run.PickNextStageScene(sceneDefs); SceneExitController exitController = gameObject.AddComponent <SceneExitController>(); exitController.useRunNextStageScene = true; Debug.Log("Advancing to next stage..."); exitController.Begin(); } }
private static void CCGiveRandomItems(ConCommandArgs args) { if (args.Count == 0) { return; } if (args.senderMasterObject) { Inventory component = args.senderMasterObject.GetComponent <Inventory>(); if (component) { try { int num; TextSerialization.TryParseInvariant(args[0], out num); if (num > 0) { WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(8); weightedSelection.AddChoice(Run.instance.availableTier1DropList, 80f); weightedSelection.AddChoice(Run.instance.availableTier2DropList, 19f); weightedSelection.AddChoice(Run.instance.availableTier3DropList, 1f); for (int i = 0; i < num; i++) { List <PickupIndex> list = weightedSelection.Evaluate(UnityEngine.Random.value); component.GiveItem(list[UnityEngine.Random.Range(0, list.Count)].itemIndex, 1); } } } catch (ArgumentException) { } } } }
private static void CombatDirectorOnPrepareNewMonsterWave(On.RoR2.CombatDirector.orig_PrepareNewMonsterWave orig, CombatDirector self, DirectorCard monsterCard) { //NOTE: We're completely rewriting this method, so we don't call back to the orig self.SetFieldValue("currentMonsterCard", monsterCard); ChosenAffix[self] = null; if (!((CharacterSpawnCard)monsterCard.spawnCard).noElites) { var eliteSelection = new WeightedSelection <EliteAffixCard>(); foreach (var card in Cards) { var weight = card.GetSpawnWeight(monsterCard); if (weight > 0 && card.isAvailable()) { var cost = monsterCard.cost * card.costMultiplier; if (cost <= self.monsterCredit) { eliteSelection.AddChoice(card, weight); } } } if (eliteSelection.Count > 0) { var rng = self.GetFieldValue <Xoroshiro128Plus>("rng"); var card = eliteSelection.Evaluate(rng.nextNormalizedFloat); ChosenAffix[self] = card; } } self.lastAttemptedMonsterCard = monsterCard; self.SetFieldValue("spawnCountInCurrentWave", 0); }
// method copied from RoR2.Inventory::GiveRandomItems private void BoostPlayerWithRandomItem(NetworkUser user) { if (!user || !user.master || !user.master.inventory) { return; } var inventory = user.master.inventory; try { WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(8); weightedSelection.AddChoice(Run.instance.availableTier1DropList, 100f); weightedSelection.AddChoice(Run.instance.availableTier2DropList, 20f); List <PickupIndex> list = weightedSelection.Evaluate(UnityEngine.Random.value); PickupDef pickupDef = PickupCatalog.GetPickupDef(list[UnityEngine.Random.Range(0, list.Count)]); inventory.GiveItem((pickupDef != null) ? pickupDef.itemIndex : ItemIndex.None, 1); ChatHelper.PlayerBoostedWithItem(user.userName, pickupDef.nameToken, pickupDef.baseColor); } catch (System.ArgumentException) { } }
private static ItemTier SelectItemTier(Inventory inv) { int itemCount = inv.GetItemCount(ExtraItemPickupItemIndex); ItemTier itemTier = ItemTier.NoTier; var tier1Chance = 0.8f; var tier2Chance = 0.2f; var tier3Chance = 0.01f; if (itemCount > 0) { tier2Chance *= itemCount; tier3Chance *= Mathf.Pow(itemCount, 2f); WeightedSelection <ItemTier> weightedSelection = new WeightedSelection <ItemTier>(8); if (inv.GetTotalItemCountOfTier(ItemTier.Tier1) > 0) { weightedSelection.AddChoice(ItemTier.Tier1, tier1Chance); } if (inv.GetTotalItemCountOfTier(ItemTier.Tier2) > 0) { weightedSelection.AddChoice(ItemTier.Tier2, tier2Chance); } if (inv.GetTotalItemCountOfTier(ItemTier.Tier3) > 0) { weightedSelection.AddChoice(ItemTier.Tier3, tier3Chance); } itemTier = weightedSelection.Evaluate(Run.instance.treasureRng.nextNormalizedFloat); } return(itemTier); }
public void AddShrineStack(Interactor activator) { if (!NetworkServer.active) { Debug.LogWarning("[Server] function 'System.Void RoR2.ShrineChanceBehavior::AddShrineStack(RoR2.Interactor)' called on client"); return; } PickupIndex none = PickupIndex.none; PickupIndex value = Run.instance.availableTier1DropList[this.rng.RangeInt(0, Run.instance.availableTier1DropList.Count - 1)]; PickupIndex value2 = Run.instance.availableTier2DropList[this.rng.RangeInt(0, Run.instance.availableTier2DropList.Count - 1)]; PickupIndex value3 = Run.instance.availableTier3DropList[this.rng.RangeInt(0, Run.instance.availableTier3DropList.Count - 1)]; PickupIndex value4 = Run.instance.availableEquipmentDropList[this.rng.RangeInt(0, Run.instance.availableEquipmentDropList.Count - 1)]; WeightedSelection <PickupIndex> weightedSelection = new WeightedSelection <PickupIndex>(8); weightedSelection.AddChoice(none, this.failureWeight); weightedSelection.AddChoice(value, this.tier1Weight); weightedSelection.AddChoice(value2, this.tier2Weight); weightedSelection.AddChoice(value3, this.tier3Weight); weightedSelection.AddChoice(value4, this.equipmentWeight); PickupIndex pickupIndex = weightedSelection.Evaluate(this.rng.nextNormalizedFloat); bool flag = pickupIndex == PickupIndex.none; if (flag) { Chat.SendBroadcastChat(new Chat.SubjectFormatChatMessage { subjectCharacterBodyGameObject = activator.gameObject, baseToken = "SHRINE_CHANCE_FAIL_MESSAGE" }); } else { this.successfulPurchaseCount++; PickupDropletController.CreatePickupDroplet(pickupIndex, this.dropletOrigin.position, this.dropletOrigin.forward * 20f); Chat.SendBroadcastChat(new Chat.SubjectFormatChatMessage { subjectCharacterBodyGameObject = activator.gameObject, baseToken = "SHRINE_CHANCE_SUCCESS_MESSAGE" }); } Action <bool, Interactor> action = ShrineChanceBehavior.onShrineChancePurchaseGlobal; if (action != null) { action(flag, activator); } this.waitingForRefresh = true; this.refreshTimer = 2f; EffectManager.instance.SpawnEffect(Resources.Load <GameObject>("Prefabs/Effects/ShrineUseEffect"), new EffectData { origin = base.transform.position, rotation = Quaternion.identity, scale = 1f, color = this.shrineColor }, true); if (this.successfulPurchaseCount >= this.maxPurchaseCount) { this.symbolTransform.gameObject.SetActive(false); } }
// Token: 0x06000DBC RID: 3516 RVA: 0x000436C4 File Offset: 0x000418C4 public void SetNextSpawnAsBoss() { WeightedSelection <DirectorCard> weightedSelection = new WeightedSelection <DirectorCard>(8); Debug.LogFormat("CombatDirector.SetNextSpawnAsBoss() monsterCards.Count={0}", new object[] { this.monsterCards.Count }); bool flag = this.rng.nextNormalizedFloat > 0.1f; int i = 0; int count = this.monsterCards.Count; while (i < count) { WeightedSelection <DirectorCard> .ChoiceInfo choice = this.monsterCards.GetChoice(i); if (choice.value.spawnCard.prefab.GetComponent <CharacterMaster>().bodyPrefab.GetComponent <CharacterBody>().isChampion == flag && choice.value.CardIsValid() && !choice.value.spawnCard.name.Contains("cscGolem")) { weightedSelection.AddChoice(choice); Debug.LogFormat("bossCards.AddChoice({0})", new object[] { choice.value.spawnCard.name }); } i++; } if (weightedSelection.Count > 0) { this.currentMonsterCard = weightedSelection.Evaluate(this.rng.nextNormalizedFloat); } this.monsterSpawnTimer = -600f; }
private WeightedSelection <DirectorCard> SceneDirector_GenerateInteractableCardSelection(On.RoR2.SceneDirector.orig_GenerateInteractableCardSelection orig, SceneDirector self) { var retv = orig(self); mostRecentDeck = retv; return(retv); }
public void GiveRandomItems(int count) { if (!NetworkServer.active) { Debug.LogWarning("[Server] function 'System.Void RoR2.Inventory::GiveRandomItems(System.Int32)' called on client"); return; } try { if (count > 0) { WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(8); weightedSelection.AddChoice(Run.instance.availableTier1DropList, 80f); weightedSelection.AddChoice(Run.instance.availableTier2DropList, 19f); weightedSelection.AddChoice(Run.instance.availableTier3DropList, 1f); for (int i = 0; i < count; i++) { List <PickupIndex> list = weightedSelection.Evaluate(UnityEngine.Random.value); this.GiveItem(list[UnityEngine.Random.Range(0, list.Count)].itemIndex, 1); } } } catch (ArgumentException) { } }
public void RollItem() { if (!NetworkServer.active) { Debug.LogWarning("[Server] function 'System.Void RoR2.ScavBackpackBehavior::RollItem()' called on client"); return; } WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(8); weightedSelection.AddChoice((from v in Run.instance.availableTier1DropList where ItemCatalog.GetItemDef(v.itemIndex) != null && ItemCatalog.GetItemDef(v.itemIndex).ContainsTag(this.requiredItemTag) select v).ToList <PickupIndex>(), this.tier1Chance); weightedSelection.AddChoice((from v in Run.instance.availableTier2DropList where ItemCatalog.GetItemDef(v.itemIndex) != null && ItemCatalog.GetItemDef(v.itemIndex).ContainsTag(this.requiredItemTag) select v).ToList <PickupIndex>(), this.tier2Chance); weightedSelection.AddChoice((from v in Run.instance.availableTier3DropList where ItemCatalog.GetItemDef(v.itemIndex) != null && ItemCatalog.GetItemDef(v.itemIndex).ContainsTag(this.requiredItemTag) select v).ToList <PickupIndex>(), this.tier3Chance); weightedSelection.AddChoice((from v in Run.instance.availableLunarDropList where ItemCatalog.GetItemDef(v.itemIndex) != null && ItemCatalog.GetItemDef(v.itemIndex).ContainsTag(this.requiredItemTag) select v).ToList <PickupIndex>(), this.lunarChance); List <PickupIndex> dropList = weightedSelection.Evaluate(Run.instance.treasureRng.nextNormalizedFloat); this.PickFromList(dropList); }
public void SelectItemTest() { int[] weights = new[] { 2, 3, 5, 7 }; WeightedSelection <int> ws = new WeightedSelection <int>( weights.ToList(), i => i); Assert.AreEqual(17, ws.TotalWeights); CollectionAssert.AreEquivalent(weights, ws.Items); CollectionAssert.AreEquivalent(new[] { 2, 5, 10, 17 }, ws.WeightCDF); Assert.AreEqual(2, ws.SelectItem(1)); Assert.AreEqual(2, ws.SelectItem(2)); Assert.AreEqual(3, ws.SelectItem(3)); Assert.AreEqual(3, ws.SelectItem(4)); Assert.AreEqual(3, ws.SelectItem(5)); Assert.AreEqual(5, ws.SelectItem(6)); Assert.AreEqual(5, ws.SelectItem(7)); Assert.AreEqual(5, ws.SelectItem(8)); Assert.AreEqual(5, ws.SelectItem(9)); Assert.AreEqual(5, ws.SelectItem(10)); Assert.AreEqual(7, ws.SelectItem(11)); Assert.AreEqual(7, ws.SelectItem(12)); Assert.AreEqual(7, ws.SelectItem(13)); Assert.AreEqual(7, ws.SelectItem(14)); Assert.AreEqual(7, ws.SelectItem(15)); Assert.AreEqual(7, ws.SelectItem(16)); Assert.AreEqual(7, ws.SelectItem(17)); Assert.Catch <ArgumentOutOfRangeException>(() => ws.SelectItem(18)); }
// Token: 0x0600092D RID: 2349 RVA: 0x00027978 File Offset: 0x00025B78 public void SetNextSpawnAsBoss() { WeightedSelection <DirectorCard> weightedSelection = new WeightedSelection <DirectorCard>(8); bool flag = !Run.instance.ShouldAllowNonChampionBossSpawn() || this.rng.nextNormalizedFloat > 0.1f; int i = 0; int count = this.monsterCards.Count; while (i < count) { WeightedSelection <DirectorCard> .ChoiceInfo choice = this.monsterCards.GetChoice(i); SpawnCard spawnCard = choice.value.spawnCard; bool isChampion = spawnCard.prefab.GetComponent <CharacterMaster>().bodyPrefab.GetComponent <CharacterBody>().isChampion; CharacterSpawnCard characterSpawnCard = spawnCard as CharacterSpawnCard; bool flag2 = characterSpawnCard != null && characterSpawnCard.forbiddenAsBoss; if (isChampion == flag && !flag2 && choice.value.CardIsValid()) { weightedSelection.AddChoice(choice); } i++; } if (weightedSelection.Count > 0) { this.PrepareNewMonsterWave(weightedSelection.Evaluate(this.rng.nextNormalizedFloat)); } this.monsterSpawnTimer = -600f; }
private static void AddDropWeights(WeightedSelection <List <PickupIndex> > weightedSelection, DropWeights dropWeights) { weightedSelection.AddChoice(Run.instance.availableLunarDropList, dropWeights.LunarDropWeight); weightedSelection.AddChoice(Run.instance.availableTier1DropList, dropWeights.Tier1DropWeight); weightedSelection.AddChoice(Run.instance.availableTier2DropList, dropWeights.Tier2DropWeight); weightedSelection.AddChoice(Run.instance.availableTier3DropList, dropWeights.Tier3DropWeight); weightedSelection.AddChoice(Run.instance.availableEquipmentDropList, dropWeights.EquipmentDropWeight); }
// Enemies drop hook public static void enemiesDrop() { On.RoR2.DeathRewards.OnKilledServer += (orig, self, damageInfo) => { orig(self, damageInfo); CharacterBody enemy = self.GetComponent <CharacterBody>(); if (EnemiesWithItems.DropItems.Value && Util.CheckRoll(EnemiesWithItems.ConfigToFloat(EnemiesWithItems.DropChance.Value), 0f, null) && enemy.master.teamIndex.Equals(TeamIndex.Monster)) { Inventory inventory = enemy.master.inventory; List <PickupIndex> tier1Inventory = new List <PickupIndex>(); List <PickupIndex> tier2Inventory = new List <PickupIndex>(); List <PickupIndex> tier3Inventory = new List <PickupIndex>(); List <PickupIndex> lunarTierInventory = new List <PickupIndex>(); foreach (ItemIndex item in ItemCatalog.allItems) { if (EnemiesWithItems.Tier1Items.Value && ItemCatalog.tier1ItemList.Contains(item) && inventory.GetItemCount(item) > 0) { tier1Inventory.Add(PickupCatalog.FindPickupIndex(item)); } else if (EnemiesWithItems.Tier2Items.Value && ItemCatalog.tier2ItemList.Contains(item) && inventory.GetItemCount(item) > 0) { tier2Inventory.Add(PickupCatalog.FindPickupIndex(item)); } else if (EnemiesWithItems.Tier3Items.Value && ItemCatalog.tier3ItemList.Contains(item) && inventory.GetItemCount(item) > 0) { tier3Inventory.Add(PickupCatalog.FindPickupIndex(item)); } else if (EnemiesWithItems.LunarItems.Value && ItemCatalog.lunarItemList.Contains(item) && inventory.GetItemCount(item) > 0) { lunarTierInventory.Add(PickupCatalog.FindPickupIndex(item)); } } WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(8); if (EnemiesWithItems.Tier1Items.Value) { weightedSelection.AddChoice(tier1Inventory, 0.9f); } if (EnemiesWithItems.Tier2Items.Value) { weightedSelection.AddChoice(tier2Inventory, 0.1f); } if (EnemiesWithItems.Tier3Items.Value) { weightedSelection.AddChoice(tier3Inventory, 0.05f); } if (EnemiesWithItems.LunarItems.Value) { weightedSelection.AddChoice(lunarTierInventory, 0.01f); } List <PickupIndex> list = weightedSelection.Evaluate(Run.instance.treasureRng.nextNormalizedFloat); if (list.Count == 0) { return; } PickupDropletController.CreatePickupDroplet(list[Run.instance.treasureRng.RangeInt(0, list.Count)], self.transform.position + Vector3.up * 1.5f, Vector3.up * 20f + self.transform.forward * 2f); } }; }
//Builds loot table for RollItems() public static WeightedSelection <List <ItemIndex> > BuildRollItemsDropTable() { WeightedSelection <List <ItemIndex> > weightedSelection = new WeightedSelection <List <ItemIndex> >(8); ItemIndex itemIndex = ItemIndex.Syringe; ItemIndex itemCount = (ItemIndex)ItemCatalog.itemCount; List <ItemIndex> tier1 = new List <ItemIndex>(); List <ItemIndex> tier2 = new List <ItemIndex>(); List <ItemIndex> tier3 = new List <ItemIndex>(); List <ItemIndex> lunar = new List <ItemIndex>(); List <ItemIndex> boss = new List <ItemIndex>(); while (itemIndex < itemCount) { ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex); switch (itemDef.tier) { case ItemTier.Tier1: { tier1.Add(itemIndex); break; } case ItemTier.Tier2: { tier2.Add(itemIndex); break; } case ItemTier.Tier3: { tier3.Add(itemIndex); break; } case ItemTier.Lunar: { lunar.Add(itemIndex); break; } case ItemTier.Boss: { boss.Add(itemIndex); break; } } itemIndex++; } weightedSelection.AddChoice(tier1, 70f); weightedSelection.AddChoice(tier2, 22f); weightedSelection.AddChoice(tier3, 3f); weightedSelection.AddChoice(lunar, 2.5f); weightedSelection.AddChoice(boss, 2.5f); return(weightedSelection); }
// Token: 0x06000673 RID: 1651 RVA: 0x0001A5CC File Offset: 0x000187CC private void RollChoice() { WeightedSelection <int> weightedSelection = new WeightedSelection <int>(8); for (int i = 0; i < this.unlockableOptions.Length; i++) { weightedSelection.AddChoice(i, this.unlockableOptions[i].weight); } this.unlockableChoice = weightedSelection.Evaluate(UnityEngine.Random.value); this.Rebuild(); }
private PickupIndex RollVoteItem(ChestBehavior self) { 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); return(dropList[Run.instance.treasureRng.RangeInt(0, dropList.Count)]); }
private PickupIndex GenerateReward(int questsCompleted) { WeightedSelection<List<PickupIndex>> weightedSelection = new WeightedSelection<List<PickupIndex>>(); weightedSelection.AddChoice(Run.instance.availableTier1DropList, Config.Questing.chanceCommon - (questsCompleted * Config.Questing.chanceAdjustmentPercent)); weightedSelection.AddChoice(Run.instance.availableTier2DropList, Config.Questing.chanceUncommon + (questsCompleted * Config.Questing.chanceAdjustmentPercent / 2)); weightedSelection.AddChoice(Run.instance.availableTier3DropList, Config.Questing.chanceLegendary + (questsCompleted * Config.Questing.chanceAdjustmentPercent / 2)); List<PickupIndex> pickupList = weightedSelection.Evaluate(UnityEngine.Random.value); PickupIndex pickupIndex = pickupList[UnityEngine.Random.Range(0, pickupList.Count)]; return pickupIndex; }
public void Awake() { this.master = base.gameObject.GetComponent <CharacterMaster>(); this.maxPurchases = PlayerBotManager.MaxBotPurchasesPerStage.Value; this.chestPicker = new WeightedSelection <ChestTier>(); this.chestPicker.AddChoice(ChestTier.WHITE, PlayerBotManager.Tier1ChestBotWeight.Value); this.chestPicker.AddChoice(ChestTier.GREEN, PlayerBotManager.Tier2ChestBotWeight.Value); this.chestPicker.AddChoice(ChestTier.RED, PlayerBotManager.Tier3ChestBotWeight.Value); ResetPurchases(); }
// Token: 0x06002C6A RID: 11370 RVA: 0x000BB74C File Offset: 0x000B994C public override void OnEnter() { base.OnEnter(); this.duration = FindItem.baseDuration / this.attackSpeedStat; base.PlayCrossfade("Body", "SitRummage", "Sit.playbackRate", this.duration, 0.1f); Util.PlaySound(FindItem.sound, base.gameObject); if (base.isAuthority) { WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(8); weightedSelection.AddChoice((from v in Run.instance.availableTier1DropList where ItemCatalog.GetItemDef(v.itemIndex) != null && ItemCatalog.GetItemDef(v.itemIndex).DoesNotContainTag(ItemTag.AIBlacklist) select v).ToList <PickupIndex>(), FindItem.tier1Chance); weightedSelection.AddChoice((from v in Run.instance.availableTier2DropList where ItemCatalog.GetItemDef(v.itemIndex) != null && ItemCatalog.GetItemDef(v.itemIndex).DoesNotContainTag(ItemTag.AIBlacklist) select v).ToList <PickupIndex>(), FindItem.tier2Chance); weightedSelection.AddChoice((from v in Run.instance.availableTier3DropList where ItemCatalog.GetItemDef(v.itemIndex) != null && ItemCatalog.GetItemDef(v.itemIndex).DoesNotContainTag(ItemTag.AIBlacklist) select v).ToList <PickupIndex>(), FindItem.tier3Chance); List <PickupIndex> list = weightedSelection.Evaluate(UnityEngine.Random.value); this.dropPickup = list[UnityEngine.Random.Range(0, list.Count)]; PickupDef pickupDef = PickupCatalog.GetPickupDef(this.dropPickup); if (pickupDef != null) { ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex); if (itemDef != null) { this.itemsToGrant = 0; switch (itemDef.tier) { case ItemTier.Tier1: this.itemsToGrant = FindItem.tier1Count; break; case ItemTier.Tier2: this.itemsToGrant = FindItem.tier2Count; break; case ItemTier.Tier3: this.itemsToGrant = FindItem.tier3Count; break; default: this.itemsToGrant = 1; break; } } } } Transform transform = base.FindModelChild("PickupDisplay"); this.pickupDisplay = transform.GetComponent <PickupDisplay>(); this.pickupDisplay.SetPickupIndex(this.dropPickup, false); }
public void Awake() { // Give player allies the chance to drop items. On.RoR2.DeathRewards.OnKilledServer += (orig, self, damageReport) => { if (damageReport == null || damageReport.damageInfo.attacker == null) { return; } CharacterBody victimBody = self.GetFieldValue <CharacterBody>("characterBody"); //CharacterBody victimBody = (CharacterBody)GetInstanceField(typeof(DeathRewards), self, "characterBody"); CharacterBody attackerBody = damageReport.damageInfo.attacker.GetComponent <CharacterBody>(); GameObject attackerMaster = attackerBody.masterObject; if (attackerMaster == null || victimBody.teamComponent.teamIndex != TeamIndex.Monster) { return; } RollSpawnChance(victimBody, attackerBody); orig(self, damageReport); }; // Remove banned items from cards. This replaces the default card selection behavior. On.RoR2.ClassicStageInfo.GenerateDirectorCardWeightedSelection += (orig, instance, categorySelection) => { // categorySelection is either interactableCategories or monsterCategories and we only want to modify the former if (!IsInteractableCategorySelection(categorySelection)) { return(orig(instance, categorySelection)); } WeightedSelection <DirectorCard> weightedSelection = new WeightedSelection <DirectorCard>(8); foreach (DirectorCardCategorySelection.Category category in categorySelection.categories) { float num = categorySelection.SumAllWeightsInCategory(category); foreach (DirectorCard directorCard in category.cards) { if (!ApplyConfigModifiers(directorCard)) { continue; } directorCard.spawnCard.directorCreditCost = Mathf.RoundToInt(directorCard.cost * interactableCostMultiplier); weightedSelection.AddChoice(directorCard, directorCard.selectionWeight / num * category.selectionWeight); } } return(weightedSelection); }; On.RoR2.SceneDirector.PopulateScene += (orig, self) => { int interactableCredit = self.GetFieldValue <int>("interactableCredit"); interactableCredit = Mathf.RoundToInt(interactableCredit * interactableSpawnMultiplier); self.SetFieldValue("interactableCredit", interactableCredit); orig(self); }; }
// Token: 0x0600020D RID: 525 RVA: 0x0000A280 File Offset: 0x00008480 public void AddChoice(WeightedSelection <T> .ChoiceInfo choice) { if (this.Count == this.Capacity) { this.Capacity *= 2; } WeightedSelection <T> .ChoiceInfo[] array = this.choices; int count = this.Count; this.Count = count + 1; array[count] = choice; this.totalWeight += choice.weight; }
// Gets the drop for the quest public static PickupDef GetQuestDrop() { WeightedSelection<List<PickupIndex>> weightedSelection = new WeightedSelection<List<PickupIndex>>(8); weightedSelection.AddChoice(Run.instance.availableTier1DropList, Config.questChanceCommon); weightedSelection.AddChoice(Run.instance.availableTier2DropList, Config.questChanceUncommon); weightedSelection.AddChoice(Run.instance.availableTier3DropList, Config.questChanceLegendary); List<PickupIndex> list = weightedSelection.Evaluate(Run.instance.spawnRng.nextNormalizedFloat); PickupIndex item = list[Run.instance.spawnRng.RangeInt(0, list.Count)]; return PickupCatalog.GetPickupDef(item); }
public static PickupIndex GetSelection(List <PickupSelection> selections, float normalizedIndex) { var weightedSelection = new WeightedSelection <PickupIndex>(); foreach (var selection in selections.Where(x => x != null)) { foreach (var pickup in selection.Pickups) { weightedSelection.AddChoice(pickup, selection.DropChance / selection.Pickups.Count); } } return(weightedSelection.Evaluate(normalizedIndex)); }
// Token: 0x06000D9B RID: 3483 RVA: 0x00042F4C File Offset: 0x0004114C private WeightedSelection <DirectorCard> GenerateDirectorCardWeightedSelection(DirectorCardCategorySelection categorySelection) { WeightedSelection <DirectorCard> weightedSelection = new WeightedSelection <DirectorCard>(8); foreach (DirectorCardCategorySelection.Category category in categorySelection.categories) { float num = categorySelection.SumAllWeightsInCategory(category); foreach (DirectorCard directorCard in category.cards) { weightedSelection.AddChoice(directorCard, (float)directorCard.selectionWeight / num * category.selectionWeight); } } return(weightedSelection); }
public static PickupIndex GetSelection(DropLocation dropLocation, float normalizedIndex) { var selections = Selection[dropLocation]; WeightedSelection <PickupIndex> weightedSelection = new WeightedSelection <PickupIndex>(); foreach (var selection in selections) { foreach (var pickup in selection.Pickups) { weightedSelection.AddChoice(pickup, selection.DropChance); } } return(weightedSelection.Evaluate(normalizedIndex)); }
public static ItemIndex GenerateItem(float WhiteWeight = 0.8f, float GreenWeight = 0.2f, float RedWeight = 0.05f, float BossWeight = 0f, float LunarWeight = 0f) { System.Random random = new System.Random(); WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(8); weightedSelection.AddChoice(Run.instance.availableTier1DropList, WhiteWeight); weightedSelection.AddChoice(Run.instance.availableTier2DropList, GreenWeight); weightedSelection.AddChoice(Run.instance.availableTier3DropList, RedWeight); weightedSelection.AddChoice(Run.instance.availableLunarDropList, LunarWeight); List <PickupIndex> dropList = weightedSelection.Evaluate(Run.instance.spawnRng.nextNormalizedFloat); PickupIndex itemToGive = dropList[Run.instance.spawnRng.RangeInt(0, dropList.Count)]; return(itemToGive.itemIndex); }