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)
     {
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 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)
             {
             }
         }
     }
 }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
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)
            {
            }
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
 // 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);
         }
     };
 }
Esempio n. 9
0
        //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);
        }
Esempio n. 10
0
    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;
    }
Esempio n. 11
0
        // 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);
        }
Esempio n. 12
0
        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)]);
        }
Esempio n. 13
0
            // 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);
            }
Esempio n. 14
0
        public void OnStart()
        {
            init_ = true;
            NetworkUser.onNetworkUserDiscovered += UserDiscovered;
            NetworkUser.onNetworkUserLost       += UserLost;
            On.RoR2.GlobalEventManager.OnPlayerCharacterDeath += UserDied;
            On.RoR2.CharacterMaster.OnBodyStart += UserStart;
            On.RoR2.CharacterMaster.OnBodyDeath += CharacterDied;

            selection = new WeightedSelection <List <ItemIndex> >();
            selection.AddChoice(ItemCatalog.tier3ItemList, .35f);
            selection.AddChoice(ItemCatalog.tier2ItemList, .30f);
            selection.AddChoice(ItemCatalog.tier1ItemList, .25f);
            selection.AddChoice(ItemCatalog.lunarItemList, .1f);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        // 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;
        }
Esempio n. 18
0
 // 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);
             }
         }
     }
 }
Esempio n. 19
0
        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);
        }
        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);
                };
            }
        }
        // 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;
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        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);
        }
Esempio n. 25
0
        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 });
            }
        }
Esempio n. 26
0
        // 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();
        }
Esempio n. 27
0
        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);
            };
        }
Esempio n. 28
0
        //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);
                        }
                    }
                }
            }
        }
Esempio n. 29
0
 // 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)
     {
     }
 }
Esempio n. 30
0
        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));
        }