caioavidal/OpenCoreMMO

incorrect inventory weight

Krztk opened this issue · 3 comments

Describe the bug
The inventory fails to accurately update the total weight.

To Reproduce
Move an item from the player's backpack to the container slot in inventory.
(Alternatively) Move an item from the player's backpack or ground to a non-empty item slot.

Screenshots
If applicable, add screenshots to help explain your problem.

inventory-test1.mp4

Desktop (please complete the following information):

  • OS: Windows
  • Client: Otclient 0.6.6

Hi @Krztk thank you for report it. I’ll validate this and fix

@Krztk Could share the link client, please? I can't reproduce here.

@Krztk Could share the link client, please? I can't reproduce here.

https://github.com/edubart/otclient

I edited the following test case from the project. Should that test pass?

[Fact]
public void Player_swaps_item_from_ground_to_inventory()
{
    //arrange
    var dictionary = new Dictionary<Slot, (IItem Item, ushort Id)>();

    var itemOnInventory = ItemTestData.CreateWeaponItem(200, "axe");
    dictionary.Add(Slot.Left, (itemOnInventory, 200));

    var player = PlayerTestDataBuilder.Build(capacity: 1000);
    var inventory = InventoryTestDataBuilder.Build(player, dictionary);
    var item = ItemTestData.CreateWeaponItem(100, weight: 400F); //the item from the ground - weight 400
    IDynamicTile tile = new DynamicTile(new Coordinate(100, 100, 7), TileFlag.None, null, Array.Empty<IItem>(),
        new[] { item });

    //act
    var result = player.MoveItem(item, tile, inventory, 1, 0, (byte)Slot.Left);

    //assert
    Assert.True(result.Succeeded);
    Assert.Equal(inventory[Slot.Left], item);
    Assert.Equal(itemOnInventory, tile.TopItemOnStack);
    Assert.Equal(400F, inventory.TotalWeight); 
    /*
Message: 
Assert.Equal() Failure
Expected: 400
Actual:   440
    */
}