예제 #1
0
        private string GenerateEnchantTooltip(EnchantRecipe recipe)
        {
            var sb            = new StringBuilder();
            var rarityColor   = EpicLoot.GetRarityColor(SelectedRarity);
            var rarityDisplay = EpicLoot.GetRarityDisplayName(SelectedRarity);

            sb.AppendLine();
            sb.AppendLine();
            sb.AppendLine($"{recipe.FromItem.m_shared.m_name} \u2794 <color={rarityColor}>{rarityDisplay}</color> {recipe.FromItem.GetDecoratedName(rarityColor)}");
            sb.AppendLine($"<color={rarityColor}>");

            var   effectCountWeights = LootRoller.GetEffectCountsPerRarity(SelectedRarity);
            float totalWeight        = effectCountWeights.Sum(x => x.Value);

            foreach (var effectCountEntry in effectCountWeights)
            {
                var count   = effectCountEntry.Key;
                var weight  = effectCountEntry.Value;
                var percent = (int)(weight / totalWeight * 100.0f);
                var label   = count == 1 ? $"{count} $mod_epicloot_enchant_effect" : $"{count} $mod_epicloot_enchant_effects";
                sb.AppendLine($"  ‣ {label} {percent}%");
            }
            sb.Append("</color>");

            return(sb.ToString());
        }
예제 #2
0
        public void Setup(Player player, Heightmap.Biome biome, int treasureMapInterval)
        {
            Reinitialize(biome, treasureMapInterval, false, player.GetPlayerID());

            var container = GetComponent <Container>();
            var zdo       = container?.m_nview.GetZDO();

            if (container != null && zdo != null && zdo.IsValid())
            {
                container.GetInventory().RemoveAll();

                zdo.Set("TreasureMapChest.Interval", Interval);
                zdo.Set("TreasureMapChest.Biome", Biome.ToString());
                zdo.Set("creator", player.GetPlayerID());

                var items = LootRoller.RollLootTable(LootTableName, 1, LootTableName, transform.position);
                items.ForEach(item => container.m_inventory.AddItem(item));

                var biomeConfig = AdventureDataManager.Config.TreasureMap.BiomeInfo.Find(x => x.Biome == biome);
                if (biomeConfig?.ForestTokens > 0)
                {
                    container.m_inventory.AddItem("ForestToken", biomeConfig.ForestTokens, 1, 0, 0, "");
                }

                container.Save();
            }
            else
            {
                EpicLoot.LogError($"Trying to set up TreasureMapChest ({biome} {treasureMapInterval}) but there was no Container component!");
            }
        }
예제 #3
0
        public List <TreasureMapItemInfo> GetTreasureMaps()
        {
            var results = new List <TreasureMapItemInfo>();

            var player          = Player.m_localPlayer;
            var currentInterval = GetCurrentInterval();

            if (player != null)
            {
                var saveData = player.GetAdventureSaveData();
                foreach (var biome in player.m_knownBiome)
                {
                    var lootTableName   = $"TreasureMapChest_{biome}";
                    var lootTableExists = LootRoller.GetLootTable(lootTableName).Count > 0;
                    if (lootTableExists)
                    {
                        var purchased = saveData.HasPurchasedTreasureMap(currentInterval, biome);
                        var cost      = AdventureDataManager.Config.TreasureMap.BiomeInfo.Find(x => x.Biome == biome);
                        results.Add(new TreasureMapItemInfo()
                        {
                            Biome            = biome,
                            Interval         = currentInterval,
                            Cost             = cost?.Cost ?? 99,
                            AlreadyPurchased = purchased
                        });
                    }
                }
            }

            return(results.OrderBy(x => x.Cost).ToList());
        }
예제 #4
0
        public override void DoCrafting(InventoryGui __instance, Player player)
        {
            if (SelectedRecipe >= 0 && SelectedRecipe < Recipes.Count)
            {
                var recipe = Recipes[SelectedRecipe];

                if (!recipe.FromItem.IsExtended())
                {
                    var inventory = player.GetInventory();
                    inventory.RemoveItem(recipe.FromItem);
                    var extendedItemData = new ExtendedItemData(recipe.FromItem);
                    inventory.m_inventory.Add(extendedItemData);
                    inventory.Changed();
                    recipe.FromItem = extendedItemData;
                }

                float previousDurabilityPercent = 0;
                if (recipe.FromItem.m_shared.m_useDurability)
                {
                    previousDurabilityPercent = recipe.FromItem.m_durability / recipe.FromItem.GetMaxDurability();
                }

                var luckFactor         = player.GetTotalActiveMagicEffectValue(MagicEffectType.Luck, 0.01f);
                var magicItemComponent = recipe.FromItem.Extended().AddComponent <MagicItemComponent>();
                var magicItem          = LootRoller.RollMagicItem(SelectedRarity, recipe.FromItem.Extended(), luckFactor);
                magicItemComponent.SetMagicItem(magicItem);

                EquipmentEffectCache.Reset(player);

                // Spend Resources
                if (!player.NoCostCheat())
                {
                    player.ConsumeResources(GetRecipeRequirementArray(recipe, SelectedRarity), 1);
                }

                // Maintain durability
                if (recipe.FromItem.m_shared.m_useDurability)
                {
                    recipe.FromItem.m_durability = previousDurabilityPercent * recipe.FromItem.GetMaxDurability();
                }

                __instance.UpdateCraftingPanel();

                if (player.GetCurrentCraftingStation() != null)
                {
                    player.GetCurrentCraftingStation().m_craftItemDoneEffects.Create(player.transform.position, Quaternion.identity);
                }

                SuccessDialog.Show(recipe.FromItem.Extended());

                MagicItemEffects.Indestructible.MakeItemIndestructible(recipe.FromItem);

                Game.instance.GetPlayerProfile().m_playerStats.m_crafts++;
                Gogan.LogEvent("Game", "Enchanted", recipe.FromItem.m_shared.m_name, 1);
            }
        }
예제 #5
0
        public ItemDrop.ItemData GenerateGambleItem(SecretStashItemInfo itemInfo)
        {
            var gambleRarity = AdventureDataManager.Config.Gamble.GambleRarityChance;

            if (itemInfo.GuaranteedRarity)
            {
                gambleRarity = AdventureDataManager.Config.Gamble.GambleRarityChanceByRarity[(int)itemInfo.Rarity];
            }

            var nonMagicWeight = gambleRarity.Length > 0 ? gambleRarity[0] : 1;

            var random      = new Random();
            var totalWeight = gambleRarity.Sum();
            var nonMagic    = (random.NextDouble() * totalWeight) < nonMagicWeight;

            if (nonMagic)
            {
                return(itemInfo.Item.Clone());
            }

            var rarityTable = new[]
            {
                gambleRarity.Length > 1 ? gambleRarity[1] : 1,
                gambleRarity.Length > 2 ? gambleRarity[2] : 1,
                gambleRarity.Length > 3 ? gambleRarity[3] : 1,
                gambleRarity.Length > 4 ? gambleRarity[4] : 1
            };
            var lootTable = new LootTable()
            {
                Object      = "Console",
                LeveledLoot = new List <LeveledLootDef>()
                {
                    new LeveledLootDef()
                    {
                        Level = 1,
                        Drops = new[] { new float[] { 1, 1 } },
                        Loot  = new[] {
                            new LootDrop()
                            {
                                Item   = itemInfo.ItemID,
                                Rarity = rarityTable,
                                Weight = 1
                            }
                        }
                    }
                }
            };

            var previousDisabledState = LootRoller.CheatDisableGating;

            LootRoller.CheatDisableGating = true;
            var loot = LootRoller.RollLootTable(lootTable, 1, "Gamble", Player.m_localPlayer.transform.position);

            LootRoller.CheatDisableGating = previousDisabledState;
            return(loot.Count > 0 ? loot[0] : null);
        }
예제 #6
0
 public static void InitializeConfig()
 {
     LootRoller.Initialize(_lootConfigFile.Value);
     MagicItemEffectDefinitions.Initialize(_magicEffectsConfigFile.Value);
     GatedItemTypeHelper.Initialize(_itemInfoConfigFile.Value);
     RecipesHelper.Initialize(_recipesConfigFile.Value);
     EnchantCostsHelper.Initialize(_enchantCostsConfigFile.Value);
     MagicItemNames.Initialize(_itemNamesConfigFile.Value);
     AdventureDataManager.Initialize(_adventureDataConfigFile.Value);
 }
예제 #7
0
        private void MakeMagic(ItemRarity rarity, ItemDrop itemDrop, ExtendedItemData itemData, Vector3 position)
        {
            MagicItemComponent magicComponent = itemData.AddComponent <MagicItemComponent>();

            var       luck      = LootRoller.GetLuckFactor(position);
            MagicItem magicItem = magicItem = LootRoller.RollMagicItem(rarity, itemData, luck);

            magicComponent.SetMagicItem(magicItem);
            itemDrop.m_itemData = itemData;

            InitializeMagicItem.Invoke(null, new[] { itemData });
        }
예제 #8
0
        public static ItemDrop.ItemData MakeMagic(ItemRarity rarity, ItemDrop.ItemData itemDrop, ExtendedItemData itemData, Vector3 position)
        {
            MagicItemComponent magicComponent = itemData.AddComponent <MagicItemComponent>();

            var       luck      = LootRoller.GetLuckFactor(position);
            MagicItem magicItem = LootRoller.RollMagicItem(rarity, itemData, luck);

#if DEBUG
            Log.LogTrace("\t" + magicItem.Effects.Join(x => x.EffectType));
#endif

            magicComponent.SetMagicItem(magicItem);
            InitializeMagicItem.Invoke(null, new[] { itemData });

            return(itemData);
        }
예제 #9
0
        public void Show(AugmentTabController.AugmentRecipe recipe, Action <AugmentTabController.AugmentRecipe, MagicItemEffect> onCompleteCallback)
        {
            gameObject.SetActive(true);

            _audioSource.loop   = true;
            _audioSource.clip   = EpicLoot.Assets.ItemLoopSFX;
            _audioSource.volume = 0.5f;
            _audioSource.Play();

            var item        = recipe.FromItem.Extended();
            var rarity      = item.GetRarity();
            var magicItem   = item.GetMagicItem();
            var rarityColor = item.GetRarityColor();

            MagicBG.enabled = item.IsMagic();
            MagicBG.color   = rarityColor;

            NameText.text    = Localization.instance.Localize(item.GetDecoratedName());
            Description.text = Localization.instance.Localize(item.GetTooltip());
            Icon.sprite      = item.GetIcon();

            foreach (var button in EffectChoiceButtons)
            {
                button.gameObject.SetActive(false);
            }

            var newEffectOptions = LootRoller.RollAugmentEffects(item, magicItem, recipe.EffectIndex);

            for (var index = 0; index < newEffectOptions.Count; index++)
            {
                var effect = newEffectOptions[index];
                var button = EffectChoiceButtons[index];
                button.gameObject.SetActive(true);
                var text = button.GetComponentInChildren <Text>();
                text.text  = (index == 0 ? "<color=white>(keep)</color> " : "") + MagicItem.GetEffectText(effect, rarity, true);
                text.color = rarityColor;
                var buttonColor = button.GetComponent <ButtonTextColor>();
                buttonColor.m_defaultColor = rarityColor;
                button.onClick.RemoveAllListeners();
                button.onClick.AddListener(() => {
                    onCompleteCallback(recipe, effect);
                    OnClose();
                });
            }
        }
        public override void DoCrafting(InventoryGui __instance, Player player)
        {
            if (SelectedRecipe >= 0 && SelectedRecipe < Recipes.Count)
            {
                var recipe = Recipes[SelectedRecipe];

                if (!recipe.FromItem.IsExtended())
                {
                    var inventory = player.GetInventory();
                    inventory.RemoveItem(recipe.FromItem);
                    var extendedItemData = new ExtendedItemData(recipe.FromItem);
                    inventory.m_inventory.Add(extendedItemData);
                    inventory.Changed();
                    recipe.FromItem = extendedItemData;
                }

                var magicItemComponent = recipe.FromItem.Extended().AddComponent <MagicItemComponent>();
                var magicItem          = LootRoller.RollMagicItem(recipe.ToRarity, recipe.FromItem.Extended());
                magicItemComponent.SetMagicItem(magicItem);

                // Spend Resources
                if (!player.NoCostCheat())
                {
                    player.ConsumeResources(recipe.GetRequirementArray(), 1);
                }
                __instance.UpdateCraftingPanel();

                if (player.GetCurrentCraftingStation() != null)
                {
                    player.GetCurrentCraftingStation().m_craftItemDoneEffects.Create(player.transform.position, Quaternion.identity);
                }

                Game.instance.GetPlayerProfile().m_playerStats.m_crafts++;
                Gogan.LogEvent("Game", "Disenchanted", recipe.FromItem.m_shared.m_name, 1);
            }
        }
예제 #11
0
        public static ItemDrop.ItemData MakeUnique(ItemDrop.ItemData itemDrop, ExtendedItemData itemData, EpicLootItemConfiguration config)
        {
            var uniqueIds = config.UniqueIDs.Value.SplitByComma();

            if (uniqueIds.Count > 0)
            {
                var randomId = uniqueIds[Random.Range(0, uniqueIds.Count)];

                if (UniqueLegendaryHelper.TryGetLegendaryInfo(randomId, out LegendaryInfo legendaryInfo))
                {
                    MagicItem magicItem = new MagicItem
                    {
                        Rarity      = ItemRarity.Legendary,
                        LegendaryID = legendaryInfo.ID,
                        DisplayName = legendaryInfo.Name,
                    };

                    if (!legendaryInfo.Requirements.CheckRequirements(itemDrop, magicItem))
                    {
                        Log.LogWarning($"Attempted to roll Epic Loot unique legendary with id '{randomId}' for Drop That config entry '{config.SectionKey}' but requirements were not met. Skipping.");
                        return(null);
                    }

                    if (legendaryInfo.IsSetItem)
                    {
                        magicItem.SetID = UniqueLegendaryHelper.GetSetForLegendaryItem(legendaryInfo);
                    }

                    if ((legendaryInfo.GuaranteedMagicEffects?.Count ?? 0) > 0)
                    {
                        foreach (var effect in legendaryInfo.GuaranteedMagicEffects)
                        {
                            if (MagicItemEffectDefinitions.AllDefinitions.TryGetValue(effect.Type, out MagicItemEffectDefinition effectDefinition))
                            {
                                MagicItemEffect itemEffect = LootRoller.RollEffect(effectDefinition, ItemRarity.Legendary, effect.Values);
                                magicItem.Effects.Add(itemEffect);
                            }
                            else
                            {
                                Log.LogWarning($"Unable to find a guaranteed Epic Loot magic effect '{effect.Type}' while rolling unique legendary with id '{randomId}'. Skipping effect.");
                            }
                        }
                    }

                    var randomEffectCount = LootRoller.RollEffectCountPerRarity(ItemRarity.Legendary) - magicItem.Effects.Count;

                    if (randomEffectCount > 0)
                    {
                        List <MagicItemEffectDefinition> availableEffects = MagicItemEffectDefinitions.GetAvailableEffects(itemData, magicItem, -1);

                        for (int i = 0; i < randomEffectCount; ++i)
                        {
                            MagicItemEffectDefinition effectDefinition = RollWeightedEffect(availableEffects, false);
                            MagicItemEffect           itemEffect       = LootRoller.RollEffect(effectDefinition, ItemRarity.Legendary);
                            magicItem.Effects.Add(itemEffect);
                        }
                    }

                    MagicItemComponent magicComponent = itemData.AddComponent <MagicItemComponent>();

                    magicComponent.SetMagicItem(magicItem);

                    InitializeMagicItem.Invoke(null, new[] { itemData });

                    return(itemData);
                }
                else
                {
                    Log.LogWarning($"Attempted to roll Epic Loot unique legendary with id '{randomId}' but was unable to find matching info registered in Epic Loot.");
                }
            }

            return(null);
        }