final int number = sentence.getNumeral().getAmount();
// now check if the house they said is free
final String itemName = Integer.toString(number);
final HousePortal houseportal = HouseUtilities.getHousePortal(number);
if (houseportal == null) {
// something bad happened
raiser.say("Sorry I did not understand you, could you try saying the house number you want again please?");
raiser.setCurrentState(ConversationStates.QUEST_OFFERED);
return;
}
final String owner = houseportal.getOwner();
if (owner.length() == 0) {
// it's available, so take money
if (player.isEquipped("money", cost)) {
final Item key = SingletonRepository.getEntityManager().getItem(
"house key");
final String doorId = houseportal.getDoorId();
final int locknumber = houseportal.getLockNumber();
((HouseKey) key).setup(doorId, locknumber, player.getName());
if (player.equipToInventoryOnly(key)) {
raiser.say("Congratulations, here is your key to " + doorId
+ "! Make sure you change the locks if you ever lose it. Do you want to buy a spare key, at a price of "
+ HouseChatAction.COST_OF_SPARE_KEY + " money?");
player.drop("money", cost);
// remember what house they own
player.setQuest(questslot, itemName);
// put nice things and a helpful note in the chest
BuyHouseChatAction.fillChest(HouseUtilities.findChest(houseportal), houseportal.getDoorId());
// set the time so that the taxman can start harassing the player
final long time = System.currentTimeMillis();
houseportal.setExpireTime(time);
houseportal.setOwner(player.getName());
raiser.setCurrentState(ConversationStates.QUESTION_1);
} else {
raiser.say("Sorry, you can't carry more keys!");
}