Example #1
0
bool HousePalettePanel::SelectBrush(const Brush* whatbrush)
{
	const HouseBrush* house_brush = dynamic_cast<const HouseBrush*>(whatbrush);
	const SpawnBrush* spawn_brush = dynamic_cast<const SpawnBrush*>(whatbrush);

	if(house_brush && map != nullptr) {
		for(HouseMap::iterator house_iter = map->houses.begin(); house_iter != map->houses.end(); ++house_iter) {
			if(house_iter->second->id == house_brush->getHouseID()) {
				for(uint32_t i = 0; i < town_choice->GetCount(); ++i) {
					Town* town = reinterpret_cast<Town*>(town_choice->GetClientData(i));
					// If it's "No Town" (nullptr) select it, or if it has the same town ID as the house
					if(town == nullptr || town->getID() == house_iter->second->townid) {
						SelectTown(i);
						for(uint32_t j = 0; j < house_list->GetCount(); ++j) {
							if(house_iter->second->id == reinterpret_cast<House*>(house_list->GetClientData(j))->id) {
								SelectHouse(j);
								return true;
							}
						}
						return true;
					}
				}
			}
		}
	} else if(spawn_brush) {
		SelectExitBrush();
	}
	return false;
}
Example #2
0
bool Houses::payRent(Player* player, House* house, uint32_t bid, time_t _time/* = 0*/)
{
	if(rentPeriod == RENTPERIOD_NEVER || !house->getOwner() ||
		house->getPaidUntil() > _time || !house->getRent() ||
		player->hasCustomFlag(PlayerCustomFlag_IgnoreHouseRent))
		return true;

	Town* town = Towns::getInstance()->getTown(house->getTownId());
	if(!town)
		return false;

	bool paid = false;
	uint32_t amount = house->getRent() + bid;
	if(g_config.getBool(ConfigManager::BANK_SYSTEM) && player->balance >= amount)
	{
		player->balance -= amount;
		paid = true;
	}
	else if(DepotChest* depotChest = player->getDepotChest(town->getID(), true))
		paid = g_game.removeMoney(depotChest, amount, FLAG_NOLIMIT);

	if(!paid)
		return false;

	if(!_time)
		_time = time(NULL);

	uint32_t paidUntil = _time;
	switch(rentPeriod)
	{
		case RENTPERIOD_DAILY:
			paidUntil += 86400;
			break;
		case RENTPERIOD_WEEKLY:
			paidUntil += 7 * 86400;
			break;
		case RENTPERIOD_MONTHLY:
			paidUntil += 30 * 86400;
			break;
		case RENTPERIOD_YEARLY:
			paidUntil += 365 * 86400;
			break;
		default:
			break;
	}

	house->setLastWarning(0);
	house->setRentWarnings(0);

	house->setPaidUntil(paidUntil);
	return true;
}
Example #3
0
bool Mailbox::getDepotId(const std::string& townString, uint32_t& depotId)
{
	Town* town = Towns::getInstance()->getTown(townString);
	if(!town)
		return false;

	std::string disabledTowns = g_config.getString(ConfigManager::MAILBOX_DISABLED_TOWNS);
	if(disabledTowns.size())
	{
		IntegerVec tmpVec = vectorAtoi(explodeString(disabledTowns, ","));
		if(tmpVec[0] != 0)
		{
			for(IntegerVec::iterator it = tmpVec.begin(); it != tmpVec.end(); ++it)
			{
				if(town->getID() == uint32_t(*it))
					return false;
			}
		}
	}

	depotId = town->getID();
	return true;
}
Example #4
0
void HousePalettePanel::OnClickAddHouse(wxCommandEvent& event)
{
	if(map == nullptr)
		return;

	House* new_house = newd House(*map);
	new_house->id = map->houses.getEmptyID();
	
	std::ostringstream os;
	os << "Unnamed House #" << new_house->id;
	new_house->name = os.str();
	Town* town = reinterpret_cast<Town*>(town_choice->GetClientData(town_choice->GetSelection()));
	
	ASSERT(town);
	new_house->townid = town->getID();

	map->houses.addHouse(new_house);
	house_list->Append(wxstr(new_house->getDescription()), new_house);
	SelectHouse(house_list->FindString(wxstr(new_house->getDescription())));
	gui.SelectBrush();
	refresh_timer.Start(300, true);
}
Example #5
0
bool Houses::payHouse(House* house, time_t _time, uint32_t bid)
{
	if(!house->getOwner())
		return true;

	Town* town = server.towns().getTown(house->getTownId());
	if(!town)
		return false;

	uint32_t owner = house->getOwner();
	if(house->isGuild() && !IOGuild::getInstance()->swapGuildIdToOwner(owner))
	{
		house->setOwnerEx(0, true);
		return false;
	}

	std::string name;
	if(!IOLoginData::getInstance()->getNameByGuid(owner, name))
	{
		house->setOwnerEx(0, true);
		return false;
	}

	PlayerP player = server.game().getPlayerByNameEx(name);
	if(!player)
		return false;

	int32_t loginClean = server.configManager().getNumber(ConfigManager::HOUSE_CLEAN_OLD);
	if(player->isVirtual() && loginClean && _time >= (player->getLastLogin() + loginClean))
	{
		house->setOwnerEx(0, true);
		return false;
	}

	if(rentPeriod == RENTPERIOD_NEVER || house->getPaidUntil() > _time || !house->getRent())
		return true;

	bool paid = payRent(player.get(), house, bid, _time), savePlayer = false;
	if(!paid && _time >= (house->getLastWarning() + 86400))
	{
		uint32_t warningsLimit = 7;
		switch(rentPeriod)
		{
			case RENTPERIOD_DAILY:
				warningsLimit = 1;
				break;
			case RENTPERIOD_WEEKLY:
				warningsLimit = 3;
				break;
			case RENTPERIOD_MONTHLY:
				warningsLimit = 7;
				break;
			case RENTPERIOD_YEARLY:
				warningsLimit = 14;
				break;
			default:
				break;
		}

		uint32_t warnings = house->getRentWarnings();
		if(warnings < warningsLimit)
		{
			Depot* depot = player->getDepot(town->getID(), true);
			boost::intrusive_ptr<Item> letter = Item::CreateItem(ITEM_LETTER_STAMPED);
			if(depot && letter)
			{
				std::string period;
				switch(rentPeriod)
				{
					case RENTPERIOD_DAILY:
						period = "daily";
						break;
					case RENTPERIOD_WEEKLY:
						period = "weekly";
						break;
					case RENTPERIOD_MONTHLY:
						period = "monthly";
						break;
					case RENTPERIOD_YEARLY:
						period = "annual";
						break;
					default:
						break;
				}

				std::stringstream s;
				s << "Warning!\nThe " << period << " rent of " << house->getRent() << " gold for your "
				<< (house->isGuild() ? "guild hall" : "house") << " \"" << house->getName()
				<< "\" has to be paid. Have it within " << (warningsLimit - warnings)
				<< " days or you will lose your " << (house->isGuild() ? "guild hall" : "house") << ".";

				letter->setText(s.str().c_str());
				if(server.game().internalAddItem(nullptr, depot, letter.get(), INDEX_WHEREEVER, FLAG_NOLIMIT) == RET_NOERROR)
					savePlayer = true;
			}

			house->setRentWarnings(++warnings);
			house->setLastWarning(_time);
		}
		else
			house->setOwnerEx(0, true);
	}

	if(player->isVirtual())
	{
		if(savePlayer)
			IOLoginData::getInstance()->savePlayer(player.get());
	}

	return paid;
}