当前位置: 首页>>代码示例>>C++>>正文


C++ House::getDoorByPosition方法代码示例

本文整理汇总了C++中House::getDoorByPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ House::getDoorByPosition方法的具体用法?C++ House::getDoorByPosition怎么用?C++ House::getDoorByPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在House的用法示例。


在下文中一共展示了House::getDoorByPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: buyHouse

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.");
}
开发者ID:Remoq7,项目名称:forgottenserver,代码行数:50,代码来源:commands.cpp


注:本文中的House::getDoorByPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。