Ejemplo n.º 1
0
 private static void TakeItemsFromWeightedSelection(WeightedSelection <ItemIndex> weightedSelection, ref CostTypeDef.PayCostContext context, ref List <ItemIndex> itemsToTake, int halfTotalItemCount)
 {
     while (weightedSelection.Count > 0 && itemsToTake.Count < halfTotalItemCount)
     {
         int choiceIndex = weightedSelection.EvaluateToChoiceIndex(context.rng.nextNormalizedFloat);
         WeightedSelection <ItemIndex> .ChoiceInfo choice = weightedSelection.GetChoice(choiceIndex);
         ItemIndex value = choice.value;
         int       num   = (int)choice.weight;
         num--;
         if (num <= 0)
         {
             weightedSelection.RemoveChoice(choiceIndex);
         }
         else
         {
             weightedSelection.ModifyChoiceWeight(choiceIndex, (float)num);
         }
         itemsToTake.Add(value);
     }
 }
        // Token: 0x06001295 RID: 4757 RVA: 0x0005029C File Offset: 0x0004E49C
        private DirectorCard SelectCard(WeightedSelection <DirectorCard> deck, int maxCost)
        {
            SceneDirector.cardSelector.Clear();
            int i     = 0;
            int count = deck.Count;

            while (i < count)
            {
                WeightedSelection <DirectorCard> .ChoiceInfo choice = deck.GetChoice(i);
                if (choice.value.cost <= maxCost)
                {
                    SceneDirector.cardSelector.AddChoice(choice);
                }
                i++;
            }
            if (SceneDirector.cardSelector.Count == 0)
            {
                return(null);
            }
            return(SceneDirector.cardSelector.Evaluate(this.rng.nextNormalizedFloat));
        }
Ejemplo n.º 3
0
        private static DirectorCard SelectCard(WeightedSelection <DirectorCard> deck, int maxCost)
        {
            WeightedSelection <DirectorCard> cardSelector = new WeightedSelection <DirectorCard>(8);

            cardSelector.Clear();
            int i     = 0;
            int count = deck.Count;

            while (i < count)
            {
                WeightedSelection <DirectorCard> .ChoiceInfo choice = deck.GetChoice(i);
                if (choice.value.cost <= maxCost)
                {
                    cardSelector.AddChoice(choice);
                }
                i++;
            }
            if (cardSelector.Count == 0)
            {
                return(null);
            }
            return(cardSelector.Evaluate(new Xoroshiro128Plus((ulong)Run.instance.stageRng.nextUint).nextNormalizedFloat));
        }
Ejemplo n.º 4
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);
            }
        }
        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);
                }
            }
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
        protected override bool PerformEquipmentAction(EquipmentSlot slot)
        {
            if (slot.currentTarget.rootObject &&
                validObjectNames.Contains(slot.currentTarget.rootObject.name) &&
                !slot.currentTarget.rootObject.GetComponent <RecombobulatorFlag>() &&
                mostRecentDeck != null &&
                Run.instance)
            {
                var oldPurch = slot.currentTarget.rootObject.GetComponent <PurchaseInteraction>();
                if (oldPurch)
                {
                    if (!oldPurch.available)
                    {
                        return(false);
                    }
                }

                var shopcpt = slot.currentTarget.rootObject.GetComponent <ShopTerminalBehavior>();
                if (shopcpt && shopcpt.serverMultiShopController)
                {
                    slot.currentTarget.rootObject = shopcpt.serverMultiShopController.transform.root.gameObject;
                    foreach (var term in shopcpt.serverMultiShopController.terminalGameObjects)
                    {
                        GameObject.Destroy(term);
                    }
                }

                GameObject.Destroy(slot.currentTarget.rootObject);

                var pos = slot.currentTarget.rootObject.transform.position;

                WeightedSelection <DirectorCard> filteredDeck = new WeightedSelection <DirectorCard>(8);
                for (var i = 0; i < mostRecentDeck.Count; i++)
                {
                    var card = mostRecentDeck.GetChoice(i);
                    if (card.value != null && card.value.IsAvailable() && (validObjectNames.Contains(card.value.spawnCard.prefab.name) || validObjectNames.Contains(card.value.spawnCard.prefab.name + "(Clone)")))
                    {
                        filteredDeck.AddChoice(card);
                    }
                }
                if (filteredDeck.Count == 0)
                {
                    return(false);
                }

                var draw = filteredDeck.Evaluate(rng.nextNormalizedFloat);

                if (Compat_ClassicItems.enabled)
                {
                    var rerolls = Compat_ClassicItems.CheckEmbryoProc(slot, equipmentDef);
                    for (var i = 0; i < rerolls; i++)
                    {
                        var draw2 = filteredDeck.Evaluate(rng.nextNormalizedFloat);
                        if (draw2.selectionWeight < draw.selectionWeight)
                        {
                            draw = draw2;
                        }
                    }
                }

                var obj = DirectorCore.instance.TrySpawnObject(
                    new DirectorSpawnRequest(
                        draw.spawnCard,
                        new DirectorPlacementRule {
                    placementMode   = DirectorPlacementRule.PlacementMode.Direct,
                    position        = pos,
                    preventOverhead = false
                },
                        this.rng
                        ));
                if (!obj)
                {
                    TinkersSatchelPlugin._logger.LogError("Recombobulator failed to replace interactable!");
                    return(false);
                }
                var purch = obj.GetComponent <PurchaseInteraction>();
                if (purch && purch.costType == CostTypeIndex.Money)
                {
                    purch.Networkcost = Run.instance.GetDifficultyScaledCost(purch.cost);
                }
                obj.AddComponent <RecombobulatorFlag>();

                var shopcpt2 = obj.GetComponent <MultiShopController>();
                if (shopcpt2)
                {
                    foreach (var term in shopcpt2.terminalGameObjects)
                    {
                        term.AddComponent <RecombobulatorFlag>();
                    }
                }

                return(true);
            }
            return(false);
        }