Terraria.Player.SellItem C# (CSharp) Method

SellItem() public method

public SellItem ( int price, int stack ) : bool
price int
stack int
return bool
        public bool SellItem(int price, int stack)
        {
            if (price <= 0)
                return false;
            Item[] objArray = new Item[58];
            for (int index = 0; index < 58; ++index)
            {
                objArray[index] = new Item();
                objArray[index] = this.inventory[index].Clone();
            }
            int num = price / 5 * stack;
            if (num < 1)
                num = 1;
            bool flag = false;
            while (num >= 1000000 && !flag)
            {
                int index = -1;
                for (int i = 53; i >= 0; --i)
                {
                    if (index == -1 && (this.inventory[i].itemId == 0 || this.inventory[i].stack == 0))
                        index = i;
                    while (this.inventory[i].itemId == 74 && this.inventory[i].stack < this.inventory[i].maxStack && num >= 1000000)
                    {
                        ++this.inventory[i].stack;
                        num -= 1000000;
                        this.DoCoins(i);
                        if (this.inventory[i].stack == 0 && index == -1)
                            index = i;
                    }
                }
                if (num >= 1000000)
                {
                    if (index == -1)
                    {
                        flag = true;
                    }
                    else
                    {
                        this.inventory[index].SetDefaults(74, false);
                        num -= 1000000;
                    }
                }
            }
            while (num >= 10000 && !flag)
            {
                int index = -1;
                for (int i = 53; i >= 0; --i)
                {
                    if (index == -1 && (this.inventory[i].itemId == 0 || this.inventory[i].stack == 0))
                        index = i;
                    while (this.inventory[i].itemId == 73 && this.inventory[i].stack < this.inventory[i].maxStack && num >= 10000)
                    {
                        ++this.inventory[i].stack;
                        num -= 10000;
                        this.DoCoins(i);
                        if (this.inventory[i].stack == 0 && index == -1)
                            index = i;
                    }
                }
                if (num >= 10000)
                {
                    if (index == -1)
                    {
                        flag = true;
                    }
                    else
                    {
                        this.inventory[index].SetDefaults(73, false);
                        num -= 10000;
                    }
                }
            }
            while (num >= 100 && !flag)
            {
                int index = -1;
                for (int i = 53; i >= 0; --i)
                {
                    if (index == -1 && (this.inventory[i].itemId == 0 || this.inventory[i].stack == 0))
                        index = i;
                    while (this.inventory[i].itemId == 72 && this.inventory[i].stack < this.inventory[i].maxStack && num >= 100)
                    {
                        ++this.inventory[i].stack;
                        num -= 100;
                        this.DoCoins(i);
                        if (this.inventory[i].stack == 0 && index == -1)
                            index = i;
                    }
                }
                if (num >= 100)
                {
                    if (index == -1)
                    {
                        flag = true;
                    }
                    else
                    {
                        this.inventory[index].SetDefaults(72, false);
                        num -= 100;
                    }
                }
            }
            while (num >= 1 && !flag)
            {
                int index = -1;
                for (int i = 53; i >= 0; --i)
                {
                    if (index == -1 && (this.inventory[i].itemId == 0 || this.inventory[i].stack == 0))
                        index = i;
                    while (this.inventory[i].itemId == 71 && this.inventory[i].stack < this.inventory[i].maxStack && num >= 1)
                    {
                        ++this.inventory[i].stack;
                        --num;
                        this.DoCoins(i);
                        if (this.inventory[i].stack == 0 && index == -1)
                            index = i;
                    }
                }
                if (num >= 1)
                {
                    if (index == -1)
                    {
                        flag = true;
                    }
                    else
                    {
                        this.inventory[index].SetDefaults(71, false);
                        --num;
                    }
                }
            }
            if (!flag)
                return true;
            for (int index = 0; index < 58; ++index)
                this.inventory[index] = objArray[index].Clone();
            return false;
        }
Player