diff --git a/src/game/game.cpp b/src/game/game.cpp index eaaffb05059..7a054bf71c9 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -10905,7 +10905,39 @@ void Game::playerCyclopediaHouseMoveOut(uint32_t playerId, uint32_t houseId, uin const auto house = g_game().map.houses.getHouseByClientId(houseId); if (!house || house->getOwner() != player->getGUID()) { - return; + if (!house || house->getOwner() != player->getGUID() || house->getState() != 2) { + return; + if (!house || house->getOwner() != player->getGUID() || house->getState() != 2) { + return; + } + + house->setBidEndDate(timestamp); + house->setState(4); + + playerCyclopediaHousesByTown(playerId, ""); + } + + void Game::playerCyclopediaHouseCancelMoveOut(uint32_t playerId, uint32_t houseId) { + if (!g_configManager().getBoolean(CYCLOPEDIA_HOUSE_AUCTION)) { + return; + } + + std::shared_ptr player = getPlayerByID(playerId); + if (!player) { + return; + } + + const auto house = g_game().map.houses.getHouseByClientId(houseId); + if (!house || house->getOwner() != player->getGUID() || house->getState() != 4) { + return; + } + + house->setBidEndDate(0); + house->setBidder(0); + house->setState(2); + + playerCyclopediaHousesByTown(playerId, ""); + } } house->setBidEndDate(timestamp); @@ -10927,44 +10959,45 @@ void Game::playerCyclopediaHouseCancelMoveOut(uint32_t playerId, uint32_t houseI const auto house = g_game().map.houses.getHouseByClientId(houseId); if (!house || house->getOwner() != player->getGUID()) { - return; - } - - house->setBidEndDate(0); - house->setBidder(0); - house->setState(2); - - playerCyclopediaHousesByTown(playerId, ""); -} + if (!house || house->getOwner() != player->getGUID() || house->getState() != 4) { + return; + } -bool Game::processBankAuction(std::shared_ptr player, std::shared_ptr house, uint64_t bid, bool replace /* = false*/) { - if (!replace && player->getBankBalance() < (house->getRent() + bid)) { - return false; - } + house->setBidEndDate(0); + house->setBidder(0); + house->setState(2); - if (player->getBankBalance() < bid) { - return false; + playerCyclopediaHousesByTown(playerId, ""); } - uint64_t balance = player->getBankBalance(); - if (replace) { - player->setBankBalance(balance - (bid - house->getInternalBid())); - } else { - player->setBankBalance(balance - (house->getRent() + bid)); - } + bool Game::processBankAuction(std::shared_ptr player, std::shared_ptr house, uint64_t bid, bool replace /* = false*/) { + if (!replace && player->getBankBalance() < (house->getRent() + bid)) { + return false; + } - player->sendResourceBalance(RESOURCE_BANK, player->getBankBalance()); + if (player->getBankBalance() < bid) { + return false; + } - if (house->getBidderName() != player->getName()) { - const auto otherPlayer = g_game().getPlayerByName(house->getBidderName()); - if (!otherPlayer) { - uint32_t bidderGuid = IOLoginData::getGuidByName(house->getBidderName()); - IOLoginData::increaseBankBalance(bidderGuid, (house->getBidHolderLimit() + house->getRent())); + uint64_t balance = player->getBankBalance(); + if (replace) { + player->setBankBalance(balance - (bid - house->getInternalBid())); } else { - otherPlayer->setBankBalance(otherPlayer->getBankBalance() + (house->getBidHolderLimit() + house->getRent())); - otherPlayer->sendResourceBalance(RESOURCE_BANK, otherPlayer->getBankBalance()); + player->setBankBalance(balance - (house->getRent() + bid)); } - } - return true; -} + player->sendResourceBalance(RESOURCE_BANK, player->getBankBalance()); + + if (house->getBidderName() != player->getName()) { + const auto otherPlayer = g_game().getPlayerByName(house->getBidderName()); + if (!otherPlayer) { + uint32_t bidderGuid = IOLoginData::getGuidByName(house->getBidderName()); + IOLoginData::increaseBankBalance(bidderGuid, (house->getBidHolderLimit() + house->getRent())); + } else { + otherPlayer->setBankBalance(otherPlayer->getBankBalance() + (house->getBidHolderLimit() + house->getRent())); + otherPlayer->sendResourceBalance(RESOURCE_BANK, otherPlayer->getBankBalance()); + } + } + + return true; + } diff --git a/src/io/iomapserialize.cpp b/src/io/iomapserialize.cpp index ef6fb1beee4..562aa02a0d7 100644 --- a/src/io/iomapserialize.cpp +++ b/src/io/iomapserialize.cpp @@ -300,25 +300,25 @@ bool IOMapSerialize::loadHouseInfo() { g_logger().debug("Setting house id '{}' owner to player GUID '{}'", houseId, newOwner); house->setOwner(newOwner); } - } else if (state == 0 && bidder > 0 && timeNow > bidEndDate) { + } else if (state == 0 && timeNow > bidEndDate && bidder > 0) { // Available + g_logger().debug("[BID] - Setting house id '{}' owner to player GUID '{}'", houseId, bidder); if (highestBid < internalBid) { uint32_t diff = internalBid - highestBid; IOLoginData::increaseBankBalance(bidder, diff); } - g_logger().debug("Setting house id '{}' owner to player GUID '{}'", houseId, bidder); house->setOwner(bidder); bidder = 0; bidderName = ""; highestBid = 0; internalBid = 0; bidEndDate = 0; - } else if (state == 2 && bidder == -1 && timeNow > bidEndDate) { - g_logger().debug("Removing house id '{}' owner", houseId); + } else if (state == 4 && timeNow > bidEndDate) { // Move Out + g_logger().debug("[MOVE OUT] - Removing house id '{}' owner", houseId); house->setOwner(0); bidEndDate = 0; - bidder = 0; } else { house->setOwner(owner, false); + house->setState(state); } house->setBidder(bidder); house->setBidderName(bidderName); @@ -326,7 +326,6 @@ bool IOMapSerialize::loadHouseInfo() { house->setInternalBid(internalBid); house->setBidHolderLimit(internalBid); house->setBidEndDate(bidEndDate); - house->setState(state); } } while (result->next());