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); }
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); }
// 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; }
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 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); }
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) { } } } }
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: 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 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); }
// 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) { } }
// 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; }
// 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); } }; }
// 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 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; }
// 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); }
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)]); }
// 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)); }
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); }
// Token: 0x06001364 RID: 4964 RVA: 0x00052FCC File Offset: 0x000511CC public void SelectMonsterCard() { WeightedSelection <DirectorCard> weightedSelection = Util.CreateReasonableDirectorCardSpawnList(this.monsterCredit, this.combatDirector.maximumNumberToSpawnBeforeSkipping, 1); if (weightedSelection.Count == 0) { if (this.chosenDirectorCard == null) { Debug.Log("Could not find appropriate spawn card for Combat Shrine"); this.purchaseInteraction.SetAvailable(false); } return; } this.chosenDirectorCard = weightedSelection.Evaluate(this.rng.nextNormalizedFloat); }
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 void RollItem() { 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, this.tier1Chance); weightedSelection.AddChoice(Run.instance.availableTier2DropList, this.tier2Chance); weightedSelection.AddChoice(Run.instance.availableTier3DropList, this.tier3Chance); weightedSelection.AddChoice(Run.instance.availableLunarDropList, this.lunarChance); List <PickupIndex> dropList = weightedSelection.Evaluate(Run.instance.treasureRng.nextNormalizedFloat); this.PickFromList(dropList); }
// random items public void RollItems() { try { int num = itemsToRoll; if (num > 0) { for (int i = 0; i < num; i++) { List <ItemIndex> list = weightedSelection.Evaluate(UnityEngine.Random.value); UmbraMenu.LocalPlayerInv.GiveItem(list[UnityEngine.Random.Range(0, list.Count)], 1); } } } catch (ArgumentException) { } }
public ItemIndex GiveAndReturnRandomItem(Inventory inventory) { var tier1 = ItemCatalog.tier1ItemList; var tier2 = ItemCatalog.tier2ItemList; var tier3 = ItemCatalog.tier3ItemList; WeightedSelection <List <ItemIndex> > weightedSelection = new WeightedSelection <List <ItemIndex> >(); weightedSelection.AddChoice(tier1, 80f); weightedSelection.AddChoice(tier2, 19f); weightedSelection.AddChoice(tier3, 1f); List <ItemIndex> list = weightedSelection.Evaluate(UnityEngine.Random.value); var givenItem = list[UnityEngine.Random.Range(0, list.Count)]; inventory.GiveItem(givenItem); return(givenItem); }
public ItemIndex GiveAndReturnRandomItem(Inventory inventory) { var tier1 = ItemDropAPI.GetDefaultDropList(ItemTier.Tier1); var tier2 = ItemDropAPI.GetDefaultDropList(ItemTier.Tier2); var tier3 = ItemDropAPI.GetDefaultDropList(ItemTier.Tier3); WeightedSelection <List <ItemIndex> > weightedSelection = new WeightedSelection <List <ItemIndex> >(); weightedSelection.AddChoice(tier1, 80f); weightedSelection.AddChoice(tier2, 19f); weightedSelection.AddChoice(tier3, 1f); List <ItemIndex> list = weightedSelection.Evaluate(UnityEngine.Random.value); var givenItem = list[UnityEngine.Random.Range(0, list.Count)]; inventory.GiveItem(givenItem); return(givenItem); }
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 }); } }
public static PickupIndex GetSelection(ItemDropLocation dropLocation, float normalizedIndex) { if (!Selection.ContainsKey(dropLocation)) { return(new PickupIndex(ItemIndex.None)); } var selections = Selection[dropLocation]; 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)); }
private void RollSpawnChance(CharacterBody victimBody, CharacterBody attackerBody) { // Roll percent chance has a base value of 7% (configurable), multiplied by 1 + .3 per player above 1. float percentChance = baseDropChance * (1f + ((NetworkUser.readOnlyInstancesList.Count - 1f) * playerScaling)); if (reverseScaling) { percentChance /= Run.instance.difficultyCoefficient * reverseScalingRate; } WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(5); // This is done this way because elite bosses are possible, and should have the option to drop reds than their standard boss counterparts. if (victimBody.isElite) { AddDropWeights(weightedSelection, eliteDropWeights); } if (victimBody.isBoss) { AddDropWeights(weightedSelection, bossDropWeights); } // If the enemy in question is dead, then chances shoulder be the default for chests + some equipment item drop chances. else if (!victimBody.isElite) { AddDropWeights(weightedSelection, normalDropWeights); } // Item to drop is generated before the item pick up is generated for a future update. List <PickupIndex> list = weightedSelection.Evaluate(Run.instance.spawnRng.nextNormalizedFloat); PickupIndex pickupIndex = list[Run.instance.spawnRng.RangeInt(0, list.Count)]; CharacterMaster master = attackerBody.master; float luck = (master && cloverRerollDrops) ? master.luck : 0f; if (Util.CheckRoll(percentChance, luck, null)) { // Drop an item. PickupDropletController.CreatePickupDroplet( pickupIndex, victimBody.transform.position, new Vector3(UnityEngine.Random.Range(-5.0f, 5.0f), 20f, UnityEngine.Random.Range(-5.0f, 5.0f))); } }
//Chance Shrine private static void ShrineChanceBehavior_AddShrineStack(On.RoR2.ShrineChanceBehavior.orig_AddShrineStack orig, ShrineChanceBehavior self, Interactor activator) { orig(self, activator); var characterBody = activator.GetComponent <CharacterBody>(); if (characterBody) { var inv = characterBody.inventory; if (inv) { if (inv.GetItemCount(ExtraShrineRollItemIndex) > 0 && Util.CheckRoll(ItemProcChance * inv.GetItemCount(ExtraShrineRollItemIndex), characterBody.master)) { Xoroshiro128Plus rng = new Xoroshiro128Plus(Run.instance.treasureRng.nextUlong); PickupIndex none = PickupIndex.none; PickupIndex value = rng.NextElementUniform <PickupIndex>(Run.instance.availableTier1DropList); PickupIndex value2 = rng.NextElementUniform <PickupIndex>(Run.instance.availableTier2DropList); PickupIndex value3 = rng.NextElementUniform <PickupIndex>(Run.instance.availableTier3DropList); PickupIndex value4 = rng.NextElementUniform <PickupIndex>(Run.instance.availableEquipmentDropList); WeightedSelection <PickupIndex> weightedSelection = new WeightedSelection <PickupIndex>(8); weightedSelection.AddChoice(none, self.failureWeight); weightedSelection.AddChoice(value, self.tier1Weight); weightedSelection.AddChoice(value2, self.tier2Weight); weightedSelection.AddChoice(value3, self.tier3Weight); weightedSelection.AddChoice(value4, self.equipmentWeight); PickupIndex pickupIndex = weightedSelection.Evaluate(rng.nextNormalizedFloat); bool flag = pickupIndex == PickupIndex.none; if (flag) { Chat.AddMessage("<color=\"green\">Lucky Default Sphere <style=cShrine>has rolled the shrine an additional time for:</style><color=\"white\"> Nothing."); } else { Chat.AddMessage($"<color=\"green\">Lucky Default Sphere <style=cShrine>has rolled the shrine an additional time for:</style><color=\"white\"> {Language.GetString(PickupCatalog.GetPickupDef(pickupIndex).nameToken)}"); PickupDropletController.CreatePickupDroplet(pickupIndex, self.dropletOrigin.position, self.dropletOrigin.forward * 20f); } } } } }
// random items private static void RollItems(string ammount) { try { int num; TextSerialization.TryParseInvariant(ammount, 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); LocalPlayerInv.GiveItem(list[UnityEngine.Random.Range(0, list.Count)].itemIndex, 1); } } } catch (ArgumentException) { } }