Example #1
0
    public float GetTierWeightTotal(ChestTier tier)
    {
        float totalWeights = 0f;

        foreach (ChestLootInfo item in chestLoot)
        {
            switch (tier)
            {
            case ChestTier.Low:
                totalWeights += item.rates.lowTierRate;
                break;

            case ChestTier.Mid:
                totalWeights += item.rates.midTierRate;
                break;

            case ChestTier.High:
                totalWeights += item.rates.highTierRate;
                break;

            default:
                break;
            }
        }

        return(totalWeights);
    }
Example #2
0
        private void Buy(ChestTier chestTier)
        {
            // Get drop list
            List <PickupIndex> dropList = null;

            switch (chestTier)
            {
            case ChestTier.WHITE:
                if (this.master.inventory.currentEquipmentIndex == EquipmentIndex.None && PlayerBotManager.EquipmentBuyChance.Value > UnityEngine.Random.Range(0, 100))
                {
                    this.master.inventory.SetEquipmentIndex(ItemManager.usableEquipment[UnityEngine.Random.Range(0, ItemManager.usableEquipment.Length)]);
                    return;
                }
                dropList = Run.instance.smallChestDropTierSelector.Evaluate(UnityEngine.Random.value);
                break;

            case ChestTier.GREEN:
                dropList = Run.instance.mediumChestDropTierSelector.Evaluate(UnityEngine.Random.value);
                break;

            case ChestTier.RED:
                dropList = Run.instance.largeChestDropTierSelector.Evaluate(UnityEngine.Random.value);
                break;
            }

            // Pickup
            if (dropList != null && dropList.Count > 0)
            {
                PickupIndex dropPickup = Run.instance.treasureRng.NextElementUniform <PickupIndex>(dropList);
                ItemIndex   item       = PickupCatalog.GetPickupDef(dropPickup).itemIndex;
                this.master.inventory.GiveItem(item, 1);
                Debug.Log(this.master.GetBody().GetUserName() + " bought a " + item);
            }
        }
        private void Buy(ChestTier chestTier)
        {
            // Get drop list
            List <PickupIndex> dropList = null;

            switch (chestTier)
            {
            case ChestTier.WHITE:
                if (this.master.inventory.currentEquipmentIndex == EquipmentIndex.None && PlayerBotManager.EquipmentBuyChance.Value > UnityEngine.Random.Range(0, 100))
                {
                    dropList = Run.instance.availableEquipmentDropList;
                    break;
                }
                dropList = Run.instance.smallChestDropTierSelector.Evaluate(UnityEngine.Random.value);
                break;

            case ChestTier.GREEN:
                dropList = Run.instance.mediumChestDropTierSelector.Evaluate(UnityEngine.Random.value);
                break;

            case ChestTier.RED:
                dropList = Run.instance.largeChestDropTierSelector.Evaluate(UnityEngine.Random.value);
                break;
            }

            // Pickup
            if (dropList != null && dropList.Count > 0)
            {
                PickupIndex dropPickup = Run.instance.treasureRng.NextElementUniform <PickupIndex>(dropList);
                PickupDef   pickup     = PickupCatalog.GetPickupDef(dropPickup);
                if (pickup.itemIndex != ItemIndex.None)
                {
                    this.master.inventory.GiveItem(pickup.itemIndex, 1);
                }
                else if (pickup.equipmentIndex != EquipmentIndex.None)
                {
                    this.master.inventory.SetEquipmentIndex(pickup.equipmentIndex);
                }
                else
                {
                    // Neither item nor valid equipment
                    return;
                }
                // Chat
                if (PlayerBotManager.ShowBuyMessages.Value)
                {
                    PickupDef pickupDef = PickupCatalog.GetPickupDef(dropPickup);
                    Chat.SendBroadcastChat(new Chat.PlayerPickupChatMessage
                    {
                        subjectAsCharacterBody = this.master.GetBody(),
                        baseToken      = "PLAYER_PICKUP",
                        pickupToken    = ((pickupDef != null) ? pickupDef.nameToken : null) ?? PickupCatalog.invalidPickupToken,
                        pickupColor    = (pickupDef != null) ? pickupDef.baseColor : Color.black,
                        pickupQuantity = pickup.itemIndex != ItemIndex.None ? (uint)this.master.inventory.GetItemCount(pickup.itemIndex) : 1
                    });
                }
            }
        }
        public void ResetChest()
        {
            this.nextChestTier = this.chestPicker.Evaluate(UnityEngine.Random.value);
            switch (this.nextChestTier)
            {
            case ChestTier.WHITE:
                this.nextChestPrice = Run.instance.GetDifficultyScaledCost(PlayerBotManager.Tier1ChestBotCost.Value);
                break;

            case ChestTier.GREEN:
                this.nextChestPrice = Run.instance.GetDifficultyScaledCost(PlayerBotManager.Tier2ChestBotCost.Value);
                break;

            case ChestTier.RED:
                this.nextChestPrice = Run.instance.GetDifficultyScaledCost(PlayerBotManager.Tier3ChestBotCost.Value);
                break;
            }
        }
Example #5
0
    public GameObject Drop(ChestTier tier)
    {
        float total = GetTierWeightTotal(tier);

        insertionSort(chestLoot);

        float num = UnityEngine.Random.Range(0f, total);

        foreach (ChestLootInfo info in chestLoot)
        {
            if (num <= info.GetTierWeight(tier))
            {
                return(info.item);
            }
            else
            {
                num -= info.GetTierWeight(tier);
            }
        }

        return(null);

        void insertionSort(List <ChestLootInfo> unsortedLoot)
        {
            int n = unsortedLoot.Count;

            for (int i = 1; i < n; ++i)
            {
                ChestLootInfo key = unsortedLoot[i];
                int           j   = i - 1;

                while (j >= 0 && unsortedLoot[j].GetTierWeight(tier) > key.GetTierWeight(tier))
                {
                    unsortedLoot[j + 1] = unsortedLoot[j];
                    j = j - 1;
                }
                unsortedLoot[j + 1] = key;
            }

            chestLoot.Reverse();
        }
    }
Example #6
0
    public float GetTierWeight(ChestTier tier)
    {
        float returnVal = 0f;

        switch (tier)
        {
        case ChestTier.Low:
            returnVal = rates.lowTierRate;
            break;

        case ChestTier.Mid:
            returnVal = rates.midTierRate;
            break;

        case ChestTier.High:
            returnVal = rates.highTierRate;
            break;
        }

        return(returnVal);
    }
        public static Chest SpawnChestEasy(IntVector2 location, ChestTier tier, bool locked, Chest.GeneralChestType type = Chest.GeneralChestType.UNSPECIFIED, ThreeStateValue mimic = ThreeStateValue.UNSPECIFIED, ThreeStateValue fused = ThreeStateValue.UNSPECIFIED)
        {
            GameObject chestPrefab = null;

            switch (tier)
            {
            case ChestTier.BLACK:
                chestPrefab = GameManager.Instance.RewardManager.S_Chest.gameObject;
                break;

            case ChestTier.BLUE:
                chestPrefab = GameManager.Instance.RewardManager.C_Chest.gameObject;
                break;

            case ChestTier.BROWN:
                chestPrefab = GameManager.Instance.RewardManager.D_Chest.gameObject;
                break;

            case ChestTier.GREEN:
                chestPrefab = GameManager.Instance.RewardManager.B_Chest.gameObject;
                break;

            case ChestTier.RED:
                chestPrefab = GameManager.Instance.RewardManager.A_Chest.gameObject;
                break;

            case ChestTier.SYNERGY:
                chestPrefab = GameManager.Instance.RewardManager.Synergy_Chest.gameObject;
                break;

            case ChestTier.RAINBOW:
                chestPrefab = GameManager.Instance.RewardManager.Rainbow_Chest.gameObject;
                break;

            case ChestTier.SECRETRAINBOW:
                chestPrefab = GameManager.Instance.RewardManager.D_Chest.gameObject;
                break;

            case ChestTier.GLITCHED:
                chestPrefab = GameManager.Instance.RewardManager.B_Chest.gameObject;
                break;

            case ChestTier.RAT:
                chestPrefab = LoadHelper.LoadAssetFromAnywhere <GameObject>("chest_rat");
                break;

            case ChestTier.TRUTH:
                Debug.LogError("ERROR: Chest Toolbox cannot spawn Truth Chest.");
                break;

            case ChestTier.OTHER:
                Debug.LogError("ERROR: Chest Toolbox cannot spawn 'Other' Chest.");
                break;
            }
            if (chestPrefab != null)
            {
                Chest spawnedChest = Chest.Spawn(chestPrefab.GetComponent <Chest>(), location);
                if (locked)
                {
                    spawnedChest.IsLocked = true;
                }
                else
                {
                    spawnedChest.IsLocked = false;
                }
                if (tier == ChestTier.GLITCHED)
                {
                    spawnedChest.BecomeGlitchChest();
                }
                if (tier == ChestTier.SECRETRAINBOW)
                {
                    spawnedChest.IsRainbowChest  = true;
                    spawnedChest.ChestIdentifier = Chest.SpecialChestIdentifier.SECRET_RAINBOW;
                }
                if (type == Chest.GeneralChestType.ITEM)
                {
                    spawnedChest.lootTable.lootTable = GameManager.Instance.RewardManager.ItemsLootTable;
                }
                else if (type == Chest.GeneralChestType.WEAPON)
                {
                    spawnedChest.lootTable.lootTable = GameManager.Instance.RewardManager.GunsLootTable;
                }
                else if (type == Chest.GeneralChestType.UNSPECIFIED)
                {
                    bool IsAGun = UnityEngine.Random.value <= 0.5f;
                    spawnedChest.lootTable.lootTable = (IsAGun ? GameManager.Instance.RewardManager.GunsLootTable : GameManager.Instance.RewardManager.ItemsLootTable);
                }

                if (mimic == ThreeStateValue.FORCEYES)
                {
                    spawnedChest.overrideMimicChance = 100;
                }
                if (mimic == ThreeStateValue.FORCENO)
                {
                    spawnedChest.overrideMimicChance = 0;
                }
                spawnedChest.MaybeBecomeMimic();

                if (fused == ThreeStateValue.FORCEYES)
                {
                    spawnedChest.AddFuse();
                }
                if (fused == ThreeStateValue.FORCENO)
                {
                    spawnedChest.PreventFuse = true;
                }

                spawnedChest.RegisterChestOnMinimap(spawnedChest.GetAbsoluteParentRoom());

                return(spawnedChest);
            }
            else
            {
                return(null);
            }
        }