Skip to content

Commit

Permalink
fix: transfer items house on server startup (#2316)
Browse files Browse the repository at this point in the history
Resolves #2312
  • Loading branch information
dudantas authored Feb 24, 2024
1 parent c926ea5 commit 5639c1b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/game/scheduling/save_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ void SaveManager::schedulePlayer(std::weak_ptr<Player> playerPtr) {

// Disable save async if the config is set to false
if (!g_configManager().getBoolean(TOGGLE_SAVE_ASYNC, __FUNCTION__)) {
logger.debug("Saving player {}.", playerToSave->getName());
if (g_game().getGameState() == GAME_STATE_NORMAL) {
logger.debug("Saving player {}.", playerToSave->getName());
}
doSavePlayer(playerToSave);
return;
}
Expand Down Expand Up @@ -90,7 +92,9 @@ bool SaveManager::doSavePlayer(std::shared_ptr<Player> player) {
Benchmark bm_savePlayer;
Player::PlayerLock lock(player);
m_playerMap.erase(player->getGUID());
logger.debug("Saving player {}...", player->getName());
if (g_game().getGameState() == GAME_STATE_NORMAL) {
logger.debug("Saving player {}.", player->getName());
}

bool saveSuccess = IOLoginData::savePlayer(player);
if (!saveSuccess) {
Expand Down
5 changes: 3 additions & 2 deletions src/io/iomapserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ void IOMapSerialize::loadHouseItems(Map* map) {

while (item_count--) {
if (auto houseTile = std::dynamic_pointer_cast<HouseTile>(tile)) {
const auto house = houseTile->getHouse();
if (house->getOwner() == 0) {
const auto &house = houseTile->getHouse();
auto isTransferOnRestart = g_configManager().getBoolean(TOGGLE_HOUSE_TRANSFER_ON_SERVER_RESTART, __FUNCTION__);
if (!isTransferOnRestart && house->getOwner() == 0) {
g_logger().trace("Skipping load item from house id: {}, position: {}, house does not have owner", house->getId(), house->getEntryPosition().toString());
house->clearHouseInfo(false);
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/items/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ Attr_ReadValue Item::readAttr(AttrTypes_t attr, PropStream &propStream) {
return ATTR_READ_ERROR;
}

g_logger().debug("Setting flag {} flags, to item id {}", flags, getID());
g_logger().trace("Setting obtain flag {} flags, to item id {}", flags, getID());
setAttribute(ItemAttribute_t::OBTAINCONTAINER, flags);
break;
}
Expand Down

1 comment on commit 5639c1b

@AL-L-S
Copy link

@AL-L-S AL-L-S commented on 5639c1b Feb 24, 2024

Choose a reason for hiding this comment

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

Sugestao para carregar houses de mapas custom:
As casas em mapas custom nao podem ser cerregar, entao encontrei uma soluçao para carregar as casas, os ID das Houses precisam seguir a mesma ordem do ID do mapa maidland, ou seja, as houses precisam está dentro do xml do mapa principal

void CanaryServer::loadMaps() const {
	try {

		// If "mapCustomEnabled" is true on config.lua, then load the custom map
		if (g_configManager().getBoolean(TOGGLE_MAP_CUSTOM, __FUNCTION__)) {
			g_game().loadCustomMaps(g_configManager().getString(DATA_DIRECTORY, __FUNCTION__) + "/world/custom/");
		}

		g_game().loadMainMap(g_configManager().getString(MAP_NAME, __FUNCTION__)); //ALTERADO A ORDEM DE CARREGAMENTO DO MAPA

		Zone::refreshAll();
	} catch (const std::exception &err) {
		throw FailedToInitializeCanary(err.what());
	}
}

if (loadHouses) {
	IOMap::loadHouses(this);

	IOMapSerialize::loadHouseInfo();
	IOMapSerialize::loadHouseItems(this);

	/**
	 * Only load houses items if map custom load is disabled
	 * If map custom is enabled, then it is load in loadMapCustom function
	 * NOTE: This will ensure that the information is not duplicated
	if (g_configManager().getBoolean(TOGGLE_MAP_CUSTOM, __FUNCTION__)) {
		IOMapSerialize::loadHouseInfo();
		IOMapSerialize::loadHouseItems(this); //FECHANDO OS LOADHOUSE CUSTOM
	}
	*/
}

// Must be done after all maps have been loaded
//map.loadHouseInfo(); //FECHANDO OS LOADHOUSE CUSTOM

Please sign in to comment.