예제 #1
0
void Commands::buyHouse(Player* player, const std::string& cmd, const std::string& param)
{
	if (!player->isPremium()) {
		player->sendCancelMessage(RET_YOUNEEDPREMIUMACCOUNT);
		return;
	}

	Position pos = player->getPosition();
	pos = getNextPosition(player->direction, pos);

	Tile* tile = g_game.getTile(pos.x, pos.y, pos.z);

	if (!tile) {
		player->sendCancel("You have to be looking at the door of the house you would like to buy.");
		return;
	}

	HouseTile* houseTile = dynamic_cast<HouseTile*>(tile);
	if (!houseTile) {
		player->sendCancel("You have to be looking at the door of the house you would like to buy.");
		return;
	}

	House* house = houseTile->getHouse();
	if (!house || !house->getDoorByPosition(pos)) {
		player->sendCancel("You have to be looking at the door of the house you would like to buy.");
		return;
	}

	if (house->getHouseOwner()) {
		player->sendCancel("This house alreadly has an owner.");
		return;
	}

	for (const auto& it : Houses::getInstance().getHouses()) {
		if (it.second->getHouseOwner() == player->guid) {
			player->sendCancel("You are already the owner of a house.");
			return;
		}
	}

	uint64_t price = house->getHouseTiles().size() * g_config.getNumber(ConfigManager::HOUSE_PRICE);
	if (!g_game.removeMoney(player, price)) {
		player->sendCancel("You do not have enough money.");
		return;
	}

	house->setHouseOwner(player->guid);
	player->sendTextMessage(MSG_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in the bank.");
}
예제 #2
0
bool IOMapSerialize::saveMap(Map* map)
{
	int64_t start = OTSYS_TIME();
	Database* db = Database::getInstance();
	std::ostringstream query;

	//Start the transaction
	DBTransaction transaction;
	if (!transaction.begin()) {
		return false;
	}

	if (!db->executeQuery("DELETE FROM `tile_store`")) {
		return false;
	}

	DBInsert stmt;
	stmt.setQuery("INSERT INTO `tile_store` (`house_id`, `data`) VALUES ");

	//clear old tile data
	for (const auto& it : Houses::getInstance().getHouses()) {
		//save house items
		House* house = it.second;
		for (HouseTile* tile : house->getHouseTiles()) {
			PropWriteStream stream;
			saveTile(stream, tile);

			uint32_t attributesSize;
			const char* attributes = stream.getStream(attributesSize);
			if (attributesSize > 0) {
				query << house->getHouseId() << "," << db->escapeBlob(attributes, attributesSize);
				if (!stmt.addRow(query)) {
					return false;
				}
			}
		}
	}

	if (!stmt.execute()) {
		return false;
	}

	//End the transaction
	bool success = transaction.commit();
	std::cout << "> Saved house items in: " <<
	          (OTSYS_TIME() - start) / (1000.) << " s" << std::endl;
	return success;
}
예제 #3
0
bool IOMapSerialize::saveHouseInfo(Map* map)
{
	Database* db = Database::getInstance();

	DBTransaction transaction;
	if (!transaction.begin()) {
		return false;
	}

	if (!db->executeQuery("DELETE FROM `house_lists`")) {
		return false;
	}

	std::ostringstream query;
	for (const auto& it : Houses::getInstance().getHouses()) {
		House* house = it.second;
		query << "SELECT `id` FROM `houses` WHERE `id` = " << house->getHouseId();
		DBResult* result = db->storeQuery(query.str());
		if (result) {
			db->freeResult(result);
			query.str("");
			query << "UPDATE `houses` SET `owner` = " << house->getHouseOwner() << ", `paid` = " << house->getPaidUntil() << ", `warnings` = " << house->getPayRentWarnings() << ", `name` = " << db->escapeString(house->getName()) << ", `town_id` = " << house->getTownId() << ", `rent` = " << house->getRent() << ", `size` = " << house->getHouseTiles().size() << ", `beds` = " << house->getBedCount() << " WHERE `id` = " << house->getHouseId();
		} else {
			query.str("");
			query << "INSERT INTO `houses` (`id`, `owner`, `paid`, `warnings`, `name`, `town_id`, `rent`, `size`, `beds`) VALUES (" << house->getHouseId() << "," << house->getHouseOwner() << "," << house->getPaidUntil() << "," << house->getPayRentWarnings() << "," << db->escapeString(house->getName()) << "," << house->getTownId() << "," << house->getRent() << "," << house->getHouseTiles().size() << "," << house->getBedCount() << ")";
		}

		db->executeQuery(query.str());
		query.str("");
	}

	DBInsert stmt;
	stmt.setQuery("INSERT INTO `house_lists` (`house_id` , `listid` , `list`) VALUES ");

	for (const auto& it : Houses::getInstance().getHouses()) {
		House* house = it.second;

		std::string listText;

		if (house->getAccessList(GUEST_LIST, listText) && listText != "") {
			query << house->getHouseId() << "," << GUEST_LIST << "," << db->escapeString(listText);

			if (!stmt.addRow(query)) {
				return false;
			}
		}

		if (house->getAccessList(SUBOWNER_LIST, listText) && listText != "") {
			query << house->getHouseId() << "," << SUBOWNER_LIST << "," << db->escapeString(listText);
			if (!stmt.addRow(query)) {
				return false;
			}
		}

		for (Door* door : house->getHouseDoors()) {
			if (door->getAccessList(listText) && listText != "") {
				query << house->getHouseId() << "," << door->getDoorId() << "," << db->escapeString(listText);
				if (!stmt.addRow(query)) {
					return false;
				}
			}
		}
	}

	if (!stmt.execute()) {
		return false;
	}

	return transaction.commit();
}