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 backpacks positions on login #144

Merged
merged 12 commits into from
Nov 3, 2021

Conversation

omeranha
Copy link
Contributor

@omeranha omeranha commented Oct 17, 2021

Description

With this fix the backpacks in your inventory now maintain the the exact position in client on login
Thanks to Rick.

and now, with @gerotib help, the containers will be opened when happens an x-log or crash

opinions and code modernization are welcome and appreciate.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I checked the PR checks reports
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

@beats-dh beats-dh linked an issue Oct 18, 2021 that may be closed by this pull request
@beats-dh beats-dh added the Type: Enhancement New feature or request label Oct 18, 2021
@gerotib
Copy link
Contributor

gerotib commented Oct 18, 2021

Theres issue with this system (not pr) that containers are not getting opened after x-log/crash, when player is still in game so we only connect without loggin in again.

I fixed that by function similar to one from iologindata, maybe it could be made cleaner.

In player.h after:

void sendInventoryClientIds() {
			if (client) {
				client->sendInventoryClientIds();
			}
		}

add:
void openPlayerContainers();

In protocolgame.cpp into function
void ProtocolGame::connect(uint32_t playerId, OperatingSystem_t operatingSystem)
add:
player->openPlayerContainers();

In player.cpp add:

void Player::openPlayerContainers()
{
	std::vector<std::pair<uint8_t, Container*>> openContainersList;

	for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; i++) {
		Item* item = inventory[i];
		if (!item) {
			continue;
		}

		Container* itemContainer = item->getContainer();
		if (itemContainer) {
			uint8_t cid = item->getIntAttr(ITEM_ATTRIBUTE_OPENCONTAINER);
			if (cid > 0) {
				openContainersList.emplace_back(std::make_pair(cid, itemContainer));
			}
			for (ContainerIterator it = itemContainer->iterator(); it.hasNext(); it.advance()) {
				Container* subContainer = (*it)->getContainer();
				if (subContainer) {
					uint8_t subcid = (*it)->getIntAttr(ITEM_ATTRIBUTE_OPENCONTAINER);
					if (subcid > 0) {
						openContainersList.emplace_back(std::make_pair(subcid, subContainer));
					}
				}
			}
		}
	}

	std::sort(openContainersList.begin(), openContainersList.end(), [](const std::pair<uint8_t, Container*>& left, const std::pair<uint8_t, Container*>& right) {
		return left.first < right.first;
	});

	for (auto& it : openContainersList) {
		addContainer(it.first - 1, it.second);
		onSendContainer(it.second);
	}
}

@omeranha
Copy link
Contributor Author

omeranha commented Oct 19, 2021

Theres issue with this system (not pr) that containers are not getting opened after x-log/crash, when player is still in game so we only connect without loggin in again.

I fixed that by function similar to one from iologindata, maybe it could be made cleaner.

In player.h after:

void sendInventoryClientIds() {
			if (client) {
				client->sendInventoryClientIds();
			}
		}

add: void openPlayerContainers();

In protocolgame.cpp into function void ProtocolGame::connect(uint32_t playerId, OperatingSystem_t operatingSystem) add: player->openPlayerContainers();

In player.cpp add:

void Player::openPlayerContainers()
{
	std::vector<std::pair<uint8_t, Container*>> openContainersList;

	for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; i++) {
		Item* item = inventory[i];
		if (!item) {
			continue;
		}

		Container* itemContainer = item->getContainer();
		if (itemContainer) {
			uint8_t cid = item->getIntAttr(ITEM_ATTRIBUTE_OPENCONTAINER);
			if (cid > 0) {
				openContainersList.emplace_back(std::make_pair(cid, itemContainer));
			}
			for (ContainerIterator it = itemContainer->iterator(); it.hasNext(); it.advance()) {
				Container* subContainer = (*it)->getContainer();
				if (subContainer) {
					uint8_t subcid = (*it)->getIntAttr(ITEM_ATTRIBUTE_OPENCONTAINER);
					if (subcid > 0) {
						openContainersList.emplace_back(std::make_pair(subcid, subContainer));
					}
				}
			}
		}
	}

	std::sort(openContainersList.begin(), openContainersList.end(), [](const std::pair<uint8_t, Container*>& left, const std::pair<uint8_t, Container*>& right) {
		return left.first < right.first;
	});

	for (auto& it : openContainersList) {
		addContainer(it.first - 1, it.second);
		onSendContainer(it.second);
	}
}

Thank you, tested with X-log out and crash, worked well, i'll update the pull request

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 3, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@majestyotbr majestyotbr changed the title Maintain backpacks positions on login Fix backpacks positions on login Nov 3, 2021
@majestyotbr majestyotbr merged commit 79b0bff into opentibiabr:master Nov 3, 2021
@omeranha omeranha deleted the container-position branch November 5, 2021 01:39
luan pushed a commit that referenced this pull request Jul 11, 2023
The backpacks in the inventory now maintain the exact position in the client on login. 
The containers will be opened when happens an x-log or crash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Source Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Exact container positions and order after relog
6 participants