About Item amount (StackSize)

11/30/2019 16:44 alissoncuan#1
Hello guys i have a questions in this code.

Code:
uint Amount = itemUsage.dwExtraInfo > 0 ? itemUsage.dwExtraInfo : 1;
                    ConquerItem item = new ConquerItem(true);
                    switch (shop.MoneyType)
                    {
                        case Database.ShopFile.MoneyType.Gold:
                            {
                                if (iteminfo.BaseInformation.GoldWorth * Amount > client.Entity.Money)
                                    return;
                                if (client.Entity.Money - (iteminfo.BaseInformation.GoldWorth * Amount) > client.Entity.Money)
                                    return;
                                item.ID = itemUsage.dwParam;
                                item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                item.Color = (Game.Enums.Color)3;

                                uint NewAmount = itemUsage.dwExtraInfo > 0 ? itemUsage.dwExtraInfo : 1;
                                while (NewAmount > 0)
                                {
                                    if (iteminfo.BaseInformation.StackSize == 0)
                                    {
                                        item = new ConquerItem(true);
                                        item.ID = itemUsage.dwParam;
                                        item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                        item.Color = (Game.Enums.Color)3;
                                        client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                        item.MaxStackSize = item.StackSize = 1;
                                        NewAmount--;
                                    }
                                    else
                                    {
                                        if (client.Inventory.GetStackContainer(iteminfo.BaseInformation.ID, iteminfo.BaseInformation.StackSize, 1, out _ExistingItem))
                                        {
                                            _ExistingItem.StackSize++;

                                            Database.ConquerItemTable.UpdateStack(_ExistingItem);
                                            _ExistingItem.Mode = Game.Enums.ItemMode.Update;
                                            _ExistingItem.Send(client);
                                            NewAmount -= 1;
                                        }
                                        else
                                        {
                                            item = new ConquerItem(true);
                                            item.ID = itemUsage.dwParam;
                                            item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                            item.Color = (Game.Enums.Color)3;
                                            item.MaxStackSize = iteminfo.BaseInformation.StackSize;
                                            item.StackSize = 1;
                                            if (NewAmount >= item.MaxStackSize)
                                            {
                                                item.StackSize = item.MaxStackSize;
                                                NewAmount -= item.StackSize;
                                            }
                                            else
                                            {
                                                item.StackSize = (ushort)NewAmount;
                                                NewAmount = 0;
                                            }
                                            client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                            Database.ConquerItemTable.UpdateStack(item);
                                        }
                                    }
                                }
                                client.Entity.Money -= (iteminfo.BaseInformation.GoldWorth * Amount);
                                break;
                            }
                        case Database.ShopFile.MoneyType.ConquerPoints:
                            {
                                bool bound = true;
                                if (itemUsage.dwExtraInfo3 == 2 || shop.UID == 20574)
                                {
                                    if (shop.UID == 20574)
                                        bound = false;
                                    if (iteminfo.BaseInformation.ConquerPointsWorth * Amount > client.Entity.BoundCps)
                                        return;
                                    if (client.Entity.BoundCps - (iteminfo.BaseInformation.ConquerPointsWorth * Amount) > client.Entity.BoundCps)
                                        return;
                                    item.ID = itemUsage.dwParam;
                                    if (item.ID % 730000 <= 12)
                                        item.Plus = (Byte)(item.ID % 730000);
                                    item.Color = (Game.Enums.Color)Kernel.Random.Next(4, 8);
                                    item.Bound = bound;
                                    item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                    uint NewAmount = itemUsage.dwExtraInfo > 0 ? itemUsage.dwExtraInfo : 1;
                                    while (NewAmount > 0)
                                    {
                                        if (client.Inventory.Contains(iteminfo.BaseInformation.ID, iteminfo.BaseInformation.StackSize, out _ExistingItem))
                                        {
                                            if (_ExistingItem.StackSize == 0)
                                                _ExistingItem.StackSize = 0;

                                            ushort _StackCount = iteminfo.BaseInformation.StackSize;
                                            _StackCount -= (ushort)_ExistingItem.StackSize;
                                            try
                                            {
                                                _ExistingItem.Bound = bound;
                                            }
                                            catch (Exception e)
                                            {
                                                Console.WriteLine(e);
                                            }
                                            if (_StackCount >= NewAmount)
                                                _StackCount = (ushort)NewAmount;
                                            _ExistingItem.StackSize += _StackCount;

                                            Database.ConquerItemTable.UpdateStack(_ExistingItem);
                                            _ExistingItem.Mode = Game.Enums.ItemMode.Update;
                                            _ExistingItem.Send(client);
                                            _ExistingItem.Mode = Game.Enums.ItemMode.Default;
                                            NewAmount -= _StackCount;
                                        }
                                        else
                                        {
                                            if (iteminfo.BaseInformation.StackSize > 1 && itemUsage.dwExtraInfo > 1)
                                            {
                                                item = new ConquerItem(true);
                                                item.ID = itemUsage.dwParam;
                                                item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                                item.Color = (Game.Enums.Color)3;
                                                item.Bound = bound;
                                                ushort _StackCount = iteminfo.BaseInformation.StackSize;
                                                if (NewAmount <= iteminfo.BaseInformation.StackSize)
                                                    _StackCount = (ushort)NewAmount;
                                                item.StackSize = (ushort)_StackCount;
                                                client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                                Database.ConquerItemTable.UpdateStack(item);
                                                NewAmount -= _StackCount;
                                            }
                                            else
                                            {
                                                if ((itemUsage.dwParam % 730000) <= 12)
                                                {
                                                    ConquerItem newItem = new GamePackets.ConquerItem(true);
                                                    newItem.ID = itemUsage.dwParam;
                                                    newItem.Plus = (Byte)(newItem.ID % 730000);
                                                    newItem.Bound = bound;
                                                    client.Inventory.Add(newItem, Game.Enums.ItemUse.CreateAndAdd);
                                                }
                                                else
                                                {
                                                    item = new ConquerItem(true);
                                                    item.ID = itemUsage.dwParam;
                                                    item.Bound = bound;
                                                    item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                                    item.Color = (Game.Enums.Color)3;
                                                    item.StackSize = 1;
                                                    client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                                }
                                                NewAmount--;
                                            }
                                        }
                                    }
                                    client.Entity.BoundCps -= (iteminfo.BaseInformation.ConquerPointsWorth * Amount);
                                }
                                else
                                {
                                    if (shop.UID == 20574 || iteminfo.BaseInformation.ConquerPointsWorth * Amount > client.Entity.ConquerPoints) return;
                                    if (client.Entity.ConquerPoints - (iteminfo.BaseInformation.ConquerPointsWorth * Amount) > client.Entity.ConquerPoints)
                                        return;
                                    item.ID = itemUsage.dwParam;
                                    if (item.ID % 730000 <= 12)
                                        item.Plus = (Byte)(item.ID % 730000);
                                    item.Color = (Game.Enums.Color)Kernel.Random.Next(4, 8);
                                    item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                    uint NewAmount = itemUsage.dwExtraInfo > 0 ? itemUsage.dwExtraInfo : 1;
                                    while (NewAmount > 0)
                                    {
                                        if (client.Inventory.Contains(iteminfo.BaseInformation.ID, iteminfo.BaseInformation.StackSize, out _ExistingItem))
                                        {
                                            if (_ExistingItem.StackSize == 0)
                                                _ExistingItem.StackSize = 1;

                                            ushort _StackCount = iteminfo.BaseInformation.StackSize;
                                            _StackCount -= (ushort)_ExistingItem.StackSize;

                                            if (_StackCount >= NewAmount)
                                                _StackCount = (ushort)NewAmount;
                                            _ExistingItem.StackSize += _StackCount;

                                            Database.ConquerItemTable.UpdateStack(_ExistingItem);
                                            _ExistingItem.Mode = Game.Enums.ItemMode.Update;
                                            _ExistingItem.Send(client);
                                            _ExistingItem.Mode = Game.Enums.ItemMode.Default;
                                            NewAmount -= _StackCount;
                                        }
                                        else
                                        {
                                            if (iteminfo.BaseInformation.StackSize > 1 && itemUsage.dwExtraInfo > 1)
                                            {
                                                item = new ConquerItem(true);
                                                item.ID = itemUsage.dwParam;
                                                item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                                item.Color = (Game.Enums.Color)3;
                                                ushort _StackCount = iteminfo.BaseInformation.StackSize;
                                                if (NewAmount <= iteminfo.BaseInformation.StackSize)
                                                    _StackCount = (ushort)NewAmount;
                                                item.StackSize = (ushort)_StackCount;
                                                client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                                Database.ConquerItemTable.UpdateStack(item);
                                                NewAmount -= _StackCount;
                                            }
                                            else
                                            {
                                                if ((itemUsage.dwParam % 730000) <= 12)
                                                {
                                                    ConquerItem newItem = new GamePackets.ConquerItem(true);
                                                    newItem.ID = itemUsage.dwParam;
                                                    newItem.Plus = (Byte)(newItem.ID % 730000);
                                                    client.Inventory.Add(newItem, Game.Enums.ItemUse.CreateAndAdd);
                                                }
                                                else
                                                {
                                                    item = new ConquerItem(true);
                                                    item.ID = itemUsage.dwParam;
                                                    item.Durability = item.MaximDurability = iteminfo.BaseInformation.Durability;
                                                    item.Color = (Game.Enums.Color)3;
                                                    item.StackSize = 1;
                                                    client.Inventory.Add(item, Game.Enums.ItemUse.CreateAndAdd);
                                                }
                                                NewAmount--;
                                            }
                                        }
                                    }
                                    client.Entity.ConquerPoints -= (iteminfo.BaseInformation.ConquerPointsWorth * Amount);
                                }
                                break;
                            }
                    }
                }
            }
        }
It allows you to buy more than the size of the bag
11/30/2019 18:04 Spirited#2
That's not a question, and that code is unreadable.
12/02/2019 18:10 pintinho12#3
Brazilians being brazilians.
Okay, I wont give you code but if you want to check if your inventory has space for an specific item you need to calculate:
Free Space = Item.MaxStackAmount * InventorySpace (Single block) + (Sum((Items of the same type).MaxStackAmount) - Sum((Items of the same type).StackAmount))
Good luck

Edit:
Since it can't be copied into any source, I'm leaving my version.
12/02/2019 23:22 alissoncuan#4
Brazilians are the best :D
with what you explained I was able to solve the problem
Thanks
12/03/2019 04:50 Spirited#5
Nothing to do with being Brazilian... Just has to do with level of experience.
12/03/2019 22:17 pintinho12#6
Quote:
Originally Posted by Spirited View Post
Nothing to do with being Brazilian... Just has to do with level of experience.
I mean because of the way the question has been formulated ^^,
There's a small community of good developers and our servers are allies. And this time I've got to admit, I'm surprised and I was totally wrong about him, tho I think I know him XD