コード例 #1
0
        private static void RandomizeByWeight()
        {
            var selection = new WeightedSelection <ArtifactIndex>();

            foreach (var artifact in ArtifactCatalog.artifactDefs)
            {
                if (!string.IsNullOrWhiteSpace(artifact.unlockableName) && Run.instance.unlockablesUnlockedByAnyUser.Contains(artifact.unlockableName))
                {
                    continue;
                }
                if (ConfigHelper.BlacklistIndices.Contains(artifact.artifactIndex))
                {
                    continue;
                }
                if (!ConfigHelper.ArtifactWeightsDict.TryGetValue(artifact.artifactIndex, out var weight))
                {
                    weight = ConfigHelper.DefaultWeight.Value;
                }
                selection.AddChoice(artifact.artifactIndex, weight);
            }

            var maximum      = Mathf.Max(0, Mathf.Min(selection.Count, ConfigHelper.MaxCount.Value == -1 ? selection.Count : ConfigHelper.MaxCount.Value));
            var minimum      = Mathf.Max(0, Mathf.Min(ConfigHelper.MinCount.Value, maximum));
            var enabledCount = UnityEngine.Random.Range(minimum, maximum + 1);

            for (var i = 1; i <= enabledCount; i++)
            {
                var index = selection.EvaluteToChoiceIndex(UnityEngine.Random.Range(0F, 1F));
                RunArtifactManager.instance.SetArtifactEnabledServer(ArtifactCatalog.GetArtifactDef(selection.GetChoice(index).value), true);
                selection.RemoveChoice(index);
            }
            for (var i = 0; i < selection.Count; i++)
            {
                RunArtifactManager.instance.SetArtifactEnabledServer(ArtifactCatalog.GetArtifactDef(selection.GetChoice(i).value), false);
            }
        }
コード例 #2
0
        public void FlattenInventory(Inventory inventory, ItemTier itemTier)
        {
            var itemDefs = Utils.ItemDefsFromTier(itemTier, true);

            int[] itemCounts  = new int[itemDefs.Length];
            int   lowestCount = int.MaxValue;

            foreach (var itemDef in itemDefs)
            {
                lowestCount = Math.Min(inventory.GetItemCount(itemDef), lowestCount);
                if (lowestCount == 0)
                {
                    break;
                }
            }
            var newCount    = lowestCount + 1;
            var itemBudget  = 0;
            var itemChoices = new WeightedSelection <ItemDef>();

            foreach (var itemDef in itemDefs)
            {
                var count = inventory.GetItemCount(itemDef);
                if (count > newCount)
                {
                    var toRemove = count - newCount;
                    itemBudget += toRemove;
                    inventory.RemoveItem(itemDef, toRemove);
                }
                else
                {
                    itemChoices.AddChoice(itemDef, 1);
                }
            }

            int budgetForAll = 0;

            while (itemBudget > 0)
            {
                if (itemChoices.Count > 0)
                {
                    itemBudget--;
                    var randomIndex = itemChoices.EvaluteToChoiceIndex(UnityEngine.Random.value);

                    itemCounts[Array.IndexOf(itemDefs, itemChoices.GetChoice(randomIndex).value)]++;
                    itemChoices.RemoveChoice(randomIndex);
                }
                else
                {
                    budgetForAll = itemBudget / itemDefs.Length;
                    itemBudget  -= budgetForAll * itemDefs.Length;
                    foreach (var itemDef in itemDefs)
                    {
                        itemChoices.AddChoice(itemDef, 1);
                    }
                }
            }
            for (int i = 0; i < itemDefs.Length; i++)
            {
                var count = budgetForAll + itemCounts[i];
                if (count > 0)
                {
                    inventory.GiveItem(itemDefs[i], count);
                }
            }
        }
コード例 #3
0
        public void BeginRound(GameObject centerPoint)
        {
            //Add monster card to, and activate combat director
            //^ Make directors more powerful if more events are active?
            if (this.roundsStarted >= 5)
            {
                return;
            }
            roundsStarted++;
            if (NetworkServer.active)
            {
                foreach (TeamComponent teamComponent in TeamComponent.GetTeamMembers(TeamIndex.Player))
                {
                    if (teamComponent.body && teamComponent.body.healthComponent)
                    {
                        teamComponent.body.healthComponent.HealFraction(0.75f, new ProcChainMask());
                        teamComponent.body.healthComponent.RechargeShieldFull();
                    }
                }

                if (monsterCards.Count <= 0)
                {
                    Debug.LogWarning("[CRCore3]: CRMissionController.BeginRound - No monsters left to chose from! Attempting to get new SpawnCards...");
                    WeightedSelection <DirectorCard> newCards = Util.CreateReasonableDirectorCardSpawnList(60 * Run.instance.difficultyCoefficient, 6, 2);
                    foreach (var newCardInfo in newCards.choices)
                    {
                        DirectorCard newCard = newCardInfo.value;
                        bool         isUsed  = false;
                        foreach (DirectorCard selectedCard in pickedMonsterCards)
                        {
                            if (selectedCard == newCard)
                            {
                                isUsed = true;
                                break;
                            }
                        }
                        if (!isUsed && newCard != null && newCard.spawnCard)
                        {
                            monsterCards.AddChoice(newCard, newCardInfo.weight);
                            Debug.Log("[CRCore3]: CRMissionController.BeginRound - Found valid SpawnCard " + newCard.spawnCard.name + ". Adding to options.");
                        }
                    }
                }
                if (monsterCards.Count > 0)
                {
                    int selectedIndex = monsterCards.EvaluteToChoiceIndex(this.rng.nextNormalizedFloat);
                    pickedMonsterCards.Add(monsterCards.choices[selectedIndex].value);
                    if (NetworkServer.active)
                    {
                        Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                            baseToken = "<color=#E6B3FF>[WARNING]: " + Language.GetString(monsterCards.choices[selectedIndex].value.spawnCard.prefab.GetComponent <CharacterMaster>().bodyPrefab.GetComponent <CharacterBody>().baseNameToken) + "s were released from the void!</color>"
                        });
                    }
                    monsterCards.RemoveChoice(selectedIndex);
                }
                else
                {
                    Debug.LogWarning("[CRCore3]: CRMissionController.BeginRound - No monsters left to chose from! Reverting to already selected SpawnCard.");
                    pickedMonsterCards.Add(pickedMonsterCards[this.rng.RangeInt(0, pickedMonsterCards.Count)]);
                }


                if (Run.instance)
                {
                    if (availableTier1DropList == null)
                    {
                        availableTier1DropList = Run.instance.availableTier1DropList.Where(new Func <PickupIndex, bool>(ArenaMissionController.IsPickupAllowedForMonsters)).ToList <PickupIndex>();
                    }
                    if (availableTier2DropList == null)
                    {
                        availableTier2DropList = Run.instance.availableTier2DropList.Where(new Func <PickupIndex, bool>(ArenaMissionController.IsPickupAllowedForMonsters)).ToList <PickupIndex>();
                    }
                    if (availableTier3DropList == null)
                    {
                        availableTier3DropList = Run.instance.availableTier3DropList.Where(new Func <PickupIndex, bool>(ArenaMissionController.IsPickupAllowedForMonsters)).ToList <PickupIndex>();
                    }
                    if (monsterCards == null)
                    {
                        monsterCards = Util.CreateReasonableDirectorCardSpawnList(50 * Run.instance.difficultyCoefficient, 6, 2);
                    }
                }
                else
                {
                    Debug.LogError("[CRCore]: Run.instance does not exist!");
                }

                for (int i = 0; i < pickedMonsterCards.Count; i++)
                {
                    if (i >= directors.Length)
                    {
                        break;
                    }
                    directors[i].OverrideCurrentMonsterCard(pickedMonsterCards[i]);
                    directors[i].monsterCredit      = ((CRCore3.creditsBase.Value + CRCore3.creditMultiplier.Value * this.roundsStarted) * Run.instance.difficultyCoefficient) / pickedMonsterCards.Count;
                    directors[i].creditMultiplier   = CRCore3.creditMultiplier.Value * this.roundsStarted / pickedMonsterCards.Count;
                    directors[i].targetPlayers      = false;
                    directors[i].currentSpawnTarget = centerPoint;
                    if (NetworkServer.active)
                    {
                        directors[i].enabled           = true;
                        directors[i].monsterSpawnTimer = 0;
                    }
                    Debug.Log("[CRCore3]: Updated CombatDirector" + i.ToString() + "'s credits to: " + directors[i].monsterCredit.ToString());
                    Debug.Log("[CRCore3]: Updated CombatDirector" + i.ToString() + "'s multiplier to: " + directors[i].creditMultiplier.ToString());
                }

                //Add items to monster inventory

                List <PickupIndex> list;
                int count;
                switch (roundsStarted)
                {
                default:
                    list  = availableTier1DropList;
                    count = rng.RangeInt(3, 6);
                    break;

                case 3:
                case 4:
                    list  = availableTier2DropList;
                    count = rng.RangeInt(2, 4);
                    break;

                case 5:
                    list  = availableTier3DropList;
                    count = 1;
                    break;
                }
                PickupIndex pickupIndex;
                PickupDef   pickupDef;
                ItemIndex   itemIndex = ItemIndex.None;
                for (int i = 0; i < 25; i++)
                {
                    pickupIndex = this.rng.NextElementUniform <PickupIndex>(list);
                    list.Remove(pickupIndex);
                    pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
                    itemIndex = pickupDef.itemIndex;
                    bool badItem = false;
                    foreach (string itemName in CRCore3.AIBlacklist)
                    {
                        if (ItemCatalog.GetItemDef(itemIndex).name.ToLower().Contains(itemName.ToLower()))
                        {
                            badItem = true;
                            break;
                        }
                    }
                    if (!badItem)
                    {
                        break;
                    }
                    Debug.Log("[CRCore]: Item was blacklisted! Trying again.");
                }
                int dictOut;
                if (CRCore3.itemCountOverrides.ContainsKey(ItemCatalog.GetItemDef(itemIndex).name))
                {
                    CRCore3.itemCountOverrides.TryGetValue(ItemCatalog.GetItemDef(itemIndex).name, out dictOut);
                    inventory.GiveItem(itemIndex, dictOut);
                }
                else
                {
                    inventory.GiveItem(itemIndex, count);
                }

                if (NetworkServer.active)
                {
                    Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                        baseToken = "<color=#E6B3FF>[WARNING]: " + Language.GetString(ItemCatalog.GetItemDef(itemIndex).nameToken) + " has integrated into the rift!</color>"
                    });
                }

                if (roundsStarted >= 5)
                {
                    if (this.rng.RangeInt(0, 100) <= 10)
                    {
                        if (this.rng.nextBool)
                        {
                            for (int i = 0; i < 25; i++)
                            {
                                pickupIndex = this.rng.NextElementUniform <PickupIndex>(Run.instance.availableBossDropList);
                                list.Remove(pickupIndex);
                                pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
                                itemIndex = pickupDef.itemIndex;
                                bool badItem = false;
                                foreach (string itemName in CRCore3.AIBlacklistBoss)
                                {
                                    if (ItemCatalog.GetItemDef(itemIndex).name.ToLower().Contains(itemName.ToLower()))
                                    {
                                        badItem = true;
                                        break;
                                    }
                                }
                                if (!badItem)
                                {
                                    break;
                                }
                                Debug.Log("[CRCore]: Boss item was blacklisted! Trying again.");
                            }
                            inventory.GiveItem(itemIndex, 1);
                            if (NetworkServer.active)
                            {
                                Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                                    baseToken = "<color=#E6B3FF>[WARNING]: Rare boss item " + Language.GetString(ItemCatalog.GetItemDef(itemIndex).nameToken) + " has integrated into the rift!</color>"
                                });
                            }
                        }
                        else
                        {
                            for (int i = 0; i < 25; i++)
                            {
                                pickupIndex = this.rng.NextElementUniform <PickupIndex>(Run.instance.availableBossDropList);
                                list.Remove(pickupIndex);
                                pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
                                itemIndex = pickupDef.itemIndex;
                                bool badItem = false;
                                foreach (string itemName in CRCore3.AIBlacklistLunar)
                                {
                                    if (ItemCatalog.GetItemDef(itemIndex).name.ToLower().Contains(itemName.ToLower()))
                                    {
                                        badItem = true;
                                        break;
                                    }
                                }
                                if (!badItem)
                                {
                                    break;
                                }
                                Debug.Log("[CRCore]: Lunar item was blacklisted! Trying again.");
                            }
                            inventory.GiveItem(itemIndex, 1);
                            if (NetworkServer.active)
                            {
                                Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                                    baseToken = "<color=#E6B3FF>[WARNING]: Rare Lunar item " + Language.GetString(ItemCatalog.GetItemDef(itemIndex).nameToken) + " has integrated into the rift!</color>"
                                });
                            }
                        }
                    }
                }

                foreach (GameObject rift in voidRifts)
                {
                    if (rift.GetComponent <EntityStateMachine>().state is RiftOffState)
                    {
                        (rift.GetComponent <EntityStateMachine>().state as RiftOffState).teleportTarget = centerPoint;
                    }
                }
            }
        }
コード例 #4
0
        // Token: 0x0600138F RID: 5007 RVA: 0x0005F7EC File Offset: 0x0005D9EC
        public void OnInteractionBegin(Interactor activator)
        {
            if (!this.CanBeAffordedByInteractor(activator))
            {
                return;
            }
            CharacterBody component = activator.GetComponent <CharacterBody>();

            switch (this.costType)
            {
            case CostType.Money:
                if (component)
                {
                    CharacterMaster master = component.master;
                    if (master)
                    {
                        master.money -= (uint)this.cost;
                    }
                }
                break;

            case CostType.PercentHealth:
            {
                HealthComponent component2 = activator.GetComponent <HealthComponent>();
                if (component2)
                {
                    float health = component2.health;
                    float num    = component2.fullHealth * (float)this.cost / 100f;
                    if (health > num)
                    {
                        component2.TakeDamage(new DamageInfo
                            {
                                damage     = num,
                                attacker   = base.gameObject,
                                position   = base.transform.position,
                                damageType = DamageType.BypassArmor
                            });
                    }
                }
                break;
            }

            case CostType.Lunar:
            {
                NetworkUser networkUser = Util.LookUpBodyNetworkUser(activator.gameObject);
                if (networkUser)
                {
                    networkUser.DeductLunarCoins((uint)this.cost);
                }
                break;
            }

            case CostType.WhiteItem:
            case CostType.GreenItem:
            case CostType.RedItem:
            {
                ItemTier itemTier = PurchaseInteraction.CostTypeToItemTier(this.costType);
                if (component)
                {
                    Inventory inventory = component.inventory;
                    if (inventory)
                    {
                        ItemIndex            itemIndex  = ItemIndex.None;
                        ShopTerminalBehavior component3 = base.GetComponent <ShopTerminalBehavior>();
                        if (component3)
                        {
                            itemIndex = component3.CurrentPickupIndex().itemIndex;
                        }
                        WeightedSelection <ItemIndex> weightedSelection = new WeightedSelection <ItemIndex>(8);
                        foreach (ItemIndex itemIndex2 in ItemCatalog.allItems)
                        {
                            if (itemIndex2 != itemIndex)
                            {
                                int itemCount = inventory.GetItemCount(itemIndex2);
                                if (itemCount > 0 && ItemCatalog.GetItemDef(itemIndex2).tier == itemTier)
                                {
                                    weightedSelection.AddChoice(itemIndex2, (float)itemCount);
                                }
                            }
                        }
                        List <ItemIndex> list = new List <ItemIndex>();
                        int num2 = 0;
                        while (weightedSelection.Count > 0 && num2 < this.cost)
                        {
                            int num3 = weightedSelection.EvaluteToChoiceIndex(this.rng.nextNormalizedFloat);
                            WeightedSelection <ItemIndex> .ChoiceInfo choice = weightedSelection.GetChoice(num3);
                            ItemIndex value = choice.value;
                            int       num4  = (int)choice.weight;
                            num4--;
                            if (num4 <= 0)
                            {
                                weightedSelection.RemoveChoice(num3);
                            }
                            else
                            {
                                weightedSelection.ModifyChoiceWeight(num3, (float)num4);
                            }
                            list.Add(value);
                            num2++;
                        }
                        for (int i = num2; i < this.cost; i++)
                        {
                            list.Add(itemIndex);
                        }
                        for (int j = 0; j < list.Count; j++)
                        {
                            ItemIndex itemIndex3 = list[j];
                            PurchaseInteraction.CreateItemTakenOrb(component.corePosition, base.gameObject, itemIndex3);
                            inventory.RemoveItem(itemIndex3, 1);
                            if (itemIndex3 != itemIndex)
                            {
                                Action <PurchaseInteraction, Interactor> action = PurchaseInteraction.onItemSpentOnPurchase;
                                if (action != null)
                                {
                                    action(this, activator);
                                }
                            }
                        }
                    }
                }
                break;
            }
            }
            IEnumerable <StatDef> statDefsToIncrement = this.purchaseStatNames.Select(new Func <string, StatDef>(StatDef.Find));

            StatManager.OnPurchase <IEnumerable <StatDef> >(component, this.costType, statDefsToIncrement);
            this.onPurchase.Invoke(activator);
            this.lastActivator = activator;
        }