Terraria.Player.UpdateManaRegen C# (CSharp) Method

UpdateManaRegen() public method

public UpdateManaRegen ( ) : void
return void
        public void UpdateManaRegen()
        {
            if (this.nebulaLevelMana > 0)
            {
                int num = 6;
                this.nebulaManaCounter += this.nebulaLevelMana;
                if (this.nebulaManaCounter >= num)
                {
                    this.nebulaManaCounter -= num;
                    ++this.statMana;
                    if (this.statMana >= this.statManaMax2)
                        this.statMana = this.statManaMax2;
                }
            }
            else
                this.nebulaManaCounter = 0;
            if (this.manaRegenDelay > 0)
            {
                --this.manaRegenDelay;
                this.manaRegenDelay -= this.manaRegenDelayBonus;
                if ((double)this.velocity.X == 0.0 && (double)this.velocity.Y == 0.0 || (this.grappling[0] >= 0 || this.manaRegenBuff))
                    --this.manaRegenDelay;
            }
            if (this.manaRegenBuff && this.manaRegenDelay > 20)
                this.manaRegenDelay = 20;
            if (this.manaRegenDelay <= 0)
            {
                this.manaRegenDelay = 0;
                this.manaRegen = this.statManaMax2 / 7 + 1 + this.manaRegenBonus;
                if ((double)this.velocity.X == 0.0 && (double)this.velocity.Y == 0.0 || (this.grappling[0] >= 0 || this.manaRegenBuff))
                    this.manaRegen += this.statManaMax2 / 2;
                float num = (float)((double)this.statMana / (double)this.statManaMax2 * 0.800000011920929 + 0.200000002980232);
                if (this.manaRegenBuff)
                    num = 1f;
                this.manaRegen = (int)((double)this.manaRegen * (double)num * 1.15);
            }
            else
                this.manaRegen = 0;
            this.manaRegenCount += this.manaRegen;
            while (this.manaRegenCount >= 120)
            {
                bool flag = false;
                this.manaRegenCount -= 120;
                if (this.statMana < this.statManaMax2)
                {
                    ++this.statMana;
                    flag = true;
                }
                if (this.statMana >= this.statManaMax2)
                {
                    if (this.whoAmI == Main.myPlayer && flag)
                    {
                        Main.PlaySound(25, -1, -1, 1);
                        for (int index1 = 0; index1 < 5; ++index1)
                        {
                            int index2 = Dust.NewDust(this.position, this.width, this.height, 45, 0.0f, 0.0f, (int)byte.MaxValue, new Color(), (float)Main.rand.Next(20, 26) * 0.1f);
                            Main.dust[index2].noLight = true;
                            Main.dust[index2].noGravity = true;
                            Main.dust[index2].velocity *= 0.5f;
                        }
                    }
                    this.statMana = this.statManaMax2;
                }
            }
        }
Player