Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage items under player #4758

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ArturKnopik
Copy link
Contributor

@ArturKnopik ArturKnopik commented Jun 21, 2024

Pull Request Prelude

  • I have followed [proper The Forgotten Server code styling][code].
  • I have read and understood the [contribution guidelines][cont] before making this PR.
  • I am aware that this PR may be closed if the above-mentioned criteria are not fulfilled.

Changes Proposed

Fix usage items under player
closes #4001

How to test

  1. Put item under player, for example mana potion
  2. Use item

  1. Stay under door
  2. try close the door

Code author: @Zbizu

@Zbizu
Copy link
Contributor

Zbizu commented Jun 22, 2024

correct, original diff (private repo):

diff --git a/src/tile.cpp b/src/tile.cpp
index b748de0c2..5b42a8b8e 100644
--- a/src/tile.cpp
+++ b/src/tile.cpp
@@ -1606,12 +1606,31 @@ bool Tile::isMoveableBlocking() const
 Item* Tile::getUseItem(int32_t index) const
 {
 	const TileItemVector* items = getItemList();
+
+	// no items, get ground
 	if (!items || items->size() == 0) {
 		return ground;
 	}
 
+	// try getting thing by index
 	if (Thing* thing = getThing(index)) {
-		return thing->getItem();
+		Item* thingItem = thing->getItem();
+		if (thingItem) {
+			return thingItem;
+		}
+	}
+
+	// try getting top usable item
+	Item* topDownItem = getTopDownItem();
+	if (topDownItem) {
+		return topDownItem;
+	}
+
+	// try getting door
+	for (auto it = items->rbegin(), end = items->rend(); it != end; ++it) {
+		if ((*it)->getDoor()) {
+			return (*it)->getDoor();
+		}
 	}
 
 	return nullptr;

if (Thing* thing = getThing(index)) {
Item* thingItem = thing->getItem();
if (thingItem) {
return thingItem;
}
}

// try getting top usable item
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

top movable*

}
}

return *items->begin();
return nullptr;
Copy link
Contributor

@Zbizu Zbizu Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to stay. It returns top immovable item (eg. field or splash)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Item usage detection bug
4 participants