public void BeginUpgrade(AttributeHandler handler)
 {
     if (SpendGold(GetCostToUpgrade(handler)))
     {
         handler.Upgrade(ItemToUpgrade, false);
         BeginProcess();
     }
 }
 public void BeginUpgrade(AttributeHandler handler)
 {
     if (GetCostToUpgrade(handler) < 1)
     {
         Owner.SendMessage("This piece of equipment cannot be enhanced with that any further.");
     }
     else if (SpendGold(GetCostToUpgrade(handler)))
     {
         handler.Upgrade(ItemToUpgrade, false);
         BeginProcess();
     }
 }
        public int GetCostToUpgrade(AttributeHandler handler)
        {
            int attrMultiplier = 1;

            if (AttrCountAffectsCost)
            {
                foreach (AttributeHandler h in AttributeHandler.Definitions)
                {
                    if (h.Name != handler.Name && h.Upgrade(ItemToUpgrade, true) > 0)
                    {
                        attrMultiplier++;
                    }
                }
            }

            decimal cost = 0;

            int max   = handler.MaxValue / handler.IncrementValue;
            int level = handler.Upgrade(ItemToUpgrade, true) / handler.IncrementValue;

            decimal currentLevel = 20M / max * level;
            decimal nextLevel    = 20M / max * (level + 1);

            int loopCurrentLevel = (int)currentLevel;
            int loopNextLevel    = (int)nextLevel;

            for (int i = loopCurrentLevel; i < loopNextLevel; i++)
            {
                if (i == loopCurrentLevel && loopCurrentLevel != currentLevel)
                {
                    decimal multiplier = i + 1 - (currentLevel - (decimal)loopCurrentLevel);
                    multiplier = multiplier * multiplier;
                    cost      += multiplier * BaseCost;
                }
                else if (i == loopNextLevel - 1 && loopNextLevel != nextLevel)
                {
                    decimal multiplier = nextLevel;
                    multiplier = multiplier * multiplier;
                    cost      += multiplier * BaseCost;
                }
                else
                {
                    cost += (i + 1) * (i + 1) * BaseCost;
                }
            }

            cost = cost * attrMultiplier;

            return((int)cost);
        }
        public int GetCostToUpgrade(AttributeHandler handler)
        {
            int attrMultiplier = 1;
            int gold           = BaseCost;

            if (IsCraftedByEnhancer(ItemToUpgrade, Owner))
            {
                gold = (int)(gold / 2);
            }

            if (AttrCountAffectsCost)
            {
                foreach (AttributeHandler h in AttributeHandler.Definitions)
                {
                    if (h.Name != handler.Name && h.Upgrade(ItemToUpgrade, true) > 0)
                    {
                        attrMultiplier++;
                    }
                }
            }

            int cost = 0;

            int max = handler.MaxValue;
            int inc = handler.IncrementValue;
            int lvl = handler.Upgrade(ItemToUpgrade, true);

            if (lvl < max)
            {
                cost = ((lvl + 1) * handler.Cost) * gold;
            }

            cost = (int)(cost * attrMultiplier);

            return(cost);
        }