Sphereserver / Source-X

Ultima Online server emulator
Apache License 2.0
58 stars 47 forks source link

Items are out of containers boundaries when dropping them into a container #793

Open a1exp opened 3 years ago

a1exp commented 3 years ago

This is not reroducible with Orion (I guess it has additional client-side checks), but reprodicible with the default client.

First issue. When you drop an item to a bag (just drop on a bag witout opening a bag), or create an item inside container (e.g. add gold to player with gold += 5000000 and check gold piles in the bank). Items may be out of container boundaries. See screenshot. image

Second issue. If you update TDATA3 and TDATA4 of containers then creating items via scripts (e.g. same test with gold += 5000000) will always place items at minX,minY. Seems like GetRandContainerLoc() is not called in such cases.

I fuess this function is bugged https://github.com/Sphereserver/Source-X/blob/12224eef08a5920c7e5248dec4b77fe76b777261/src/game/items/CItemContainer.cpp#L507 since it only calls GetRandContainerLoc() when initial coordinates are invalid (e.g. = 0 which is the case for TDATA3 and TDATA4 not initialized).

Fixing the first issue is more important, imo.

a1exp commented 3 years ago

The seconds issue is pretty straight forward and is caused by this: https://github.com/Sphereserver/Source-X/blob/12224eef08a5920c7e5248dec4b77fe76b777261/src/game/items/CItemContainer.cpp#L556-L563

While the first issue is more complicated.

  1. If you place an item into container like I described above, then initial point is -1,-1. So this case is triggered and GetRandContainerLoc() is called.
  2. I used debug build to see what's wrong with GetRandContainerLoc(). This item (see screenshop below) was placed with p = 150,108, which is within boundaries of gump size defined here. image

This means gump size coordinates do not correspond to x,y set by https://github.com/Sphereserver/Source-X/blob/3dbb44713bec5d720cf3b932970584331637ec18/src/game/CObjBaseTemplate.cpp#L66-L73.

a1exp commented 3 years ago

Perhaps this is the cause of the first issue, I don't understand the logic here. https://github.com/Sphereserver/Source-X/blob/f24687c5330f8fbf7b7ae9f626447fc91e280d77/src/game/items/CItemContainer.cpp#L500-L504

Or it may simply be the case when this struct is not filled right. E.g. if you check item's p.x and p.y in the game for a metal chest gump, the min X and Y seems to be ok, but max X and Y are in reality much less than defined here. https://github.com/Sphereserver/Source-X/blob/f24687c5330f8fbf7b7ae9f626447fc91e280d77/src/game/items/CItemContainer.cpp#L385