示例#1
0
        public double GetEnchantChance(ICanBeEnchanted itemToEnchant, ScrollOfEnchant scrollOfEnchant)
        {
            var levelDiff = itemToEnchant.Level >= scrollOfEnchant.Level
                ? itemToEnchant.Level - scrollOfEnchant.Level
                : 0;
            var enchantChance = BaseEnchantChance * Math.Pow(EnchantmentChanceKoef, itemToEnchant.EnchantmentLevel + levelDiff);

            return(enchantChance);
        }
示例#2
0
        public bool CanBeEnchantedWith(ICanBeEnchanted itemToEnchant, ScrollOfEnchant scrollOfEnchant)
        {
            if (scrollOfEnchant is ScrollOfEnchantWeapon && itemToEnchant is Weapon ||
                scrollOfEnchant is ScrollOfEnchantArmor && itemToEnchant is Armor)
            {
                return(true);
            }

            return(false);
        }
示例#3
0
        public bool TryEnchant(ICanBeEnchanted itemToEnchant, ScrollOfEnchant scrollOfEnchant)
        {
            var enchantResult = Dice.TryGetChance(GetEnchantChance(itemToEnchant, scrollOfEnchant));

            if (enchantResult)
            {
                SetEnchantmentLevel(itemToEnchant, itemToEnchant.EnchantmentLevel + 1);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        private void УлучшитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var item = GetSelectedItem();
            if (item == null)
                return;
                
            if (item is ICanBeEnchanted itemToEnchant)
            {
                _itemToEnchant = itemToEnchant;
                UpdateItemToEnchantSlot(_itemToEnchant);

                if (_scrollOfEnchant != null && !InventoryController.CanBeEnchantedWith(_itemToEnchant, _scrollOfEnchant))
                {
                    _scrollOfEnchant = null;
                    SetPictureBox(ScrollOfEnchantSlot, null);
                }
            }
            else if (item is ScrollOfEnchant scrollOfEnchant)
            {
                if (_itemToEnchant == null || InventoryController.CanBeEnchantedWith(_itemToEnchant, scrollOfEnchant))
                {
                    _scrollOfEnchant = scrollOfEnchant;
                    SetPictureBox(ScrollOfEnchantSlot, scrollOfEnchant);
                }
            }

            if (_itemToEnchant != null && _scrollOfEnchant != null)
            {
                EnchantChanceLabel.Text = InventoryController.GetItemEnchantChance(_itemToEnchant, _scrollOfEnchant)
                    .ToPercentString(2);

                EnchantButton.Text = $"Улучшить на +{_itemToEnchant.EnchantmentLevel + 1}";
            }
            else
            {
                EnchantChanceLabel.Text = "";
                EnchantButton.Text = "";
            }
        }
示例#5
0
        private void EnchantButton_Click(object sender, EventArgs e)
        {
            if (_itemToEnchant != null && _scrollOfEnchant != null)
            {
                var isEnchantSuccesful = InventoryController.EnchantWeapon(_itemToEnchant, _scrollOfEnchant);
                InventoryController.Update();

                _scrollOfEnchant = null;
                SetPictureBox(ScrollOfEnchantSlot, null);

                if (isEnchantSuccesful)
                {
                    UpdateItemToEnchantSlot(_itemToEnchant);
                    EnchantChanceLabel.Text = "Успешно";
                }
                else
                {
                    UpdateItemToEnchantSlot(null);
                    EnchantChanceLabel.Text = "Неуспешно";
                }
                EnchantButton.Text = "";
            }
        }
示例#6
0
 public bool CanBeEnchantedWith(ICanBeEnchanted itemToEnchant, ScrollOfEnchant scrollOfEnchant)
 => ForgeService.CanBeEnchantedWith(itemToEnchant, scrollOfEnchant);
示例#7
0
 public double GetItemEnchantChance(ICanBeEnchanted itemToEnchant, ScrollOfEnchant scrollOfEnchant)
 => ForgeService.EnchantManager.GetEnchantChance(itemToEnchant, scrollOfEnchant);
示例#8
0
 // TODO : Обобщить для интерфейса ICanBeEnchanted<TScrollOfEnchant>.
 public bool EnchantWeapon(ICanBeEnchanted itemToEnchant, ScrollOfEnchant scrollOfEnchant)
 => ForgeService.EnchantItem(itemToEnchant, scrollOfEnchant);