Skip to content

Commit

Permalink
fix load house logic
Browse files Browse the repository at this point in the history
  • Loading branch information
murilo09 committed Oct 30, 2024
1 parent 9f7cc62 commit b260617
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 39 deletions.
99 changes: 66 additions & 33 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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);
Expand All @@ -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> player, std::shared_ptr<House> 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> player, std::shared_ptr<House> 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;
}
11 changes: 5 additions & 6 deletions src/io/iomapserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,33 +300,32 @@ 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);
house->setHighestBid(highestBid);
house->setInternalBid(internalBid);
house->setBidHolderLimit(internalBid);
house->setBidEndDate(bidEndDate);
house->setState(state);
}
} while (result->next());

Expand Down

0 comments on commit b260617

Please sign in to comment.