private void EnchantButton_OnMouseClick(BaseScreenComponent sender, Vector2 position) { const int notEnoughGold = 1650; const int notEnoughEnchantmentPower = 1651; const int itemEnchanted = 1652; const int itemMustBeSelected = 1653; DaggerfallUI.Instance.PlayOneShot(SoundClips.ButtonClick); // Must have an item selected or display "An item must be selected to be enchanted." if (selectedItem == null) { DaggerfallUI.MessageBox(itemMustBeSelected); return; } // Must have enchantments to apply or display "You have not prepared enchantments for this item." if (powersList.EnchantmentCount == 0 && sideEffectsList.EnchantmentCount == 0) { DaggerfallUI.MessageBox(TextManager.Instance.GetText(textDatabase, "noEnchantments")); return; } // Get costs int totalEnchantmentCost = GetTotalEnchantmentCost(); int totalGoldCost = GetTotalGoldCost(); int itemEnchantmentPower = selectedItem.GetEnchantmentPower(); // Check for available gold and display "You do not have the gold to properly pay the enchanter." if not enough int playerGold = GameManager.Instance.PlayerEntity.GetGoldAmount(); if (playerGold < totalGoldCost) { DaggerfallUI.MessageBox(notEnoughGold); return; } // Check for enchantment power and display "You cannot enchant this item beyond its limit." if not enough if (itemEnchantmentPower < totalEnchantmentCost) { DaggerfallUI.MessageBox(notEnoughEnchantmentPower); return; } // Deduct gold from player and display "The item has been enchanted." GameManager.Instance.PlayerEntity.DeductGoldAmount(totalGoldCost); DaggerfallUI.MessageBox(itemEnchanted); // Only enchant one item from stack if (selectedItem.IsAStack()) { selectedItem = GameManager.Instance.PlayerEntity.Items.SplitStack(selectedItem, 1); } // Transfer enchantment settings onto item List <EnchantmentSettings> combinedEnchantments = new List <EnchantmentSettings>(); combinedEnchantments.AddRange(powersList.GetEnchantments()); combinedEnchantments.AddRange(sideEffectsList.GetEnchantments()); selectedItem.SetEnchantments(combinedEnchantments.ToArray(), GameManager.Instance.PlayerEntity); selectedItem.RenameItem(itemNameLabel.Text); // Play enchantment sound effect DaggerfallUI.Instance.PlayOneShot(SoundClips.MakeItem); // Clear selected item and enchantments selectedItem = null; powersList.ClearEnchantments(); sideEffectsList.ClearEnchantments(); Refresh(); }