Example #1
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);
            }
        }
        private void OnAugmentComplete(AugmentRecipe recipe, MagicItemEffect newEffect)
        {
            if (recipe != null)
            {
                var magicItem = recipe.FromItem.GetMagicItem();

                if (magicItem.HasEffect(MagicEffectType.Indestructible))
                {
                    recipe.FromItem.m_shared.m_useDurability = recipe.FromItem.m_dropPrefab?.GetComponent <ItemDrop>().m_itemData.m_shared.m_useDurability ?? false;

                    if (recipe.FromItem.m_shared.m_useDurability)
                    {
                        recipe.FromItem.m_durability = recipe.FromItem.GetMaxDurability();
                    }
                }

                magicItem.ReplaceEffect(recipe.EffectIndex, newEffect);

                if (magicItem.Rarity == ItemRarity.Rare)
                {
                    magicItem.DisplayName = MagicItemNames.GetNameForItem(recipe.FromItem, magicItem);
                }

                // Note: I do not know why I have to do this, but this is the only thing that causes this item to save correctly
                recipe.FromItem.Extended().RemoveComponent <MagicItemComponent>();
                recipe.FromItem.Extended().AddComponent <MagicItemComponent>().SetMagicItem(magicItem);

                InventoryGui.instance?.UpdateCraftingPanel();

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

                OnSelectorValueChanged(recipe.EffectIndex, true);

                MagicItemEffects.Indestructible.MakeItemIndestructible(recipe.FromItem);

                Game.instance.GetPlayerProfile().m_playerStats.m_crafts++;
                Gogan.LogEvent("Game", "Augmented", recipe.FromItem.m_shared.m_name, 1);

                EquipmentEffectCache.Reset(player);
            }
        }