Ejemplo n.º 1
0
        private List <SecretStashItemInfo> GetAvailableGambles()
        {
            var availableGambles = new List <SecretStashItemInfo>();

            foreach (var itemConfig in AdventureDataManager.Config.Gamble.Gambles)
            {
                var gatingMode = EpicLoot.GetGatedItemTypeMode();
                if (gatingMode == GatedItemTypeMode.Unlimited)
                {
                    gatingMode = GatedItemTypeMode.MustKnowRecipe;
                }

                var itemId   = GatedItemTypeHelper.GetGatedItemID(itemConfig, gatingMode);
                var itemDrop = CreateItemDrop(itemId);
                if (itemDrop == null)
                {
                    EpicLoot.LogWarning($"[AdventureData] Could not find item type (gated={itemId} orig={itemConfig}) in ObjectDB!");
                    continue;
                }

                var itemData = itemDrop.m_itemData;
                var cost     = GetGambleCost(itemId);
                availableGambles.Add(new SecretStashItemInfo(itemId, itemData, cost, true));
                Object.Destroy(itemDrop.gameObject);
            }

            return(availableGambles);
        }
Ejemplo n.º 2
0
        private static List <GameObject> RollLootTableInternal(LootTable lootTable, int level, string objectName, Vector3 dropPoint, bool initializeObject)
        {
            var results = new List <GameObject>();

            if (lootTable == null || level <= 0 || string.IsNullOrEmpty(objectName))
            {
                return(results);
            }

            var drops = GetDropsForLevel(lootTable, level);

            if (ArrayUtils.IsNullOrEmpty(drops))
            {
                return(results);
            }

            if (EpicLoot.AlwaysDropCheat)
            {
                drops = drops.Where(x => x.Length > 0 && x[0] != 0).ToArray();
            }

            _weightedDropCountTable.Setup(drops, dropPair => dropPair.Length == 2 ? dropPair[1] : 1);
            var dropCountRollResult = _weightedDropCountTable.Roll();
            var dropCount           = dropCountRollResult != null && dropCountRollResult.Length >= 1 ? dropCountRollResult[0] : 0;

            if (dropCount == 0)
            {
                return(results);
            }

            var loot = GetLootForLevel(lootTable, level);

            _weightedLootTable.Setup(loot, x => x.Weight);
            var selectedDrops = _weightedLootTable.Roll(dropCount);

            foreach (var ld in selectedDrops)
            {
                var lootDrop = ResolveLootDrop(ld, ld.Rarity);
                var itemID   = GatedItemTypeHelper.GetGatedItemID(lootDrop.Item);

                var itemPrefab = ObjectDB.instance.GetItemPrefab(itemID);
                if (itemPrefab == null)
                {
                    Debug.LogError($"Tried to spawn loot ({itemID}) for ({objectName}), but the item prefab was not found!");
                    continue;
                }

                var randomRotation = Quaternion.Euler(0.0f, Random.Range(0.0f, 360.0f), 0.0f);
                ZNetView.m_forceDisableInit = !initializeObject;
                var item = Object.Instantiate(itemPrefab, dropPoint, randomRotation);
                ZNetView.m_forceDisableInit = false;
                var itemDrop = item.GetComponent <ItemDrop>();
                if (EpicLoot.CanBeMagicItem(itemDrop.m_itemData) && !ArrayUtils.IsNullOrEmpty(lootDrop.Rarity))
                {
                    var itemData           = new ExtendedItemData(itemDrop.m_itemData);
                    var magicItemComponent = itemData.AddComponent <MagicItemComponent>();
                    var magicItem          = RollMagicItem(lootDrop, itemData);
                    magicItemComponent.SetMagicItem(magicItem);

                    itemDrop.m_itemData = itemData;
                    InitializeMagicItem(itemData);
                    MagicItemGenerated?.Invoke(itemData, magicItem);
                }

                results.Add(item);
            }

            return(results);
        }