otclient icon indicating copy to clipboard operation
otclient copied to clipboard

Game::useWith improper behavior

Open rookgaard opened this issue 7 years ago • 3 comments

Hello. Having on map ground tile (for example dirt ID:351), border (for example grass ID:4543) and nature item (for example frostbite herb ID:7261) and when using on tile kitchen knife or any other item which have "use with" option, returns border item instead item on top of tile.

Steps to reproduce

  1. Create ground tile, border item and nature item on one tile.
  2. Use on that tile kitchen knife or any other item with "use with" option.

Expected behaviour

Item is used on nature item which is on top of a tile.

Actual behaviour

Item is used on border item which isn't on top of a tile.

Environment

Bug exists on master branch, tested with TFS and compiled OTClient from latest sources.

Trying to find the problem by myself I have found that using one item on another triggers g_game.useWith(selectedThing, tile:getTopMultiUseThing()) from https://github.com/edubart/otclient/blob/master/modules/game_interface/gameinterface.lua#L368 while ThingPtr Tile::getTopMultiUseThing() from https://github.com/edubart/otclient/blob/master/src/client/tile.cpp#L475 iterates by tile things from stackpos 0 up to end of items. When iterating, border item matches !thing->isGround() && !thing->isOnTop() from https://github.com/edubart/otclient/blob/master/src/client/tile.cpp#L500 returning that thing, not checking rest of items on tile.

My workaround was to reverse loop in that way

    for(uint i = m_things.size(); i > 0; --i) {
        ThingPtr thing = m_things[i - 1];
        if(!thing->isGround() && !thing->isOnTop())
            return thing;
    }

which solved my issue, but I'm not sure if it won't break anything else, that's why I'm creating this issue.

rookgaard avatar Oct 24 '17 10:10 rookgaard

I found the same issue when trying to lock a open, unlocked door. When using the key with the door the client will "target" the ground below the open door instead which obviously does not work. Have you found any downsides to your solution so far or would you say it's save to use?

Zolias avatar Nov 26 '17 09:11 Zolias

Probably a duplicate of #644

bpawel10 avatar Nov 27 '17 12:11 bpawel10

Can you check https://github.com/edubart/otclient/pull/1113 ?

vfjpl avatar Mar 16 '21 20:03 vfjpl