Skip to content

Commit

Permalink
Admin script to manage House Buying (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 29, 2024
1 parent a7bdde5 commit 2f39a03
Show file tree
Hide file tree
Showing 5 changed files with 547 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/games/stendhal/server/maps/quests/HouseBuying.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2010 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -16,6 +16,7 @@

import games.stendhal.server.entity.player.Player;
import games.stendhal.server.maps.quests.houses.HouseBuyingMain;
import games.stendhal.server.maps.quests.houses.HouseTax;

public class HouseBuying extends AbstractQuest {
private static final String QUEST_SLOT = "house";
Expand Down Expand Up @@ -62,4 +63,14 @@ public boolean isCompleted(final Player player) {
public String getNPCName() {
return "Barrett Holmes";
}

/**
* Retrieves house tax manager.
*
* @return
* {@code HouseTax} instance.
*/
public HouseTax getHouseTax() {
return quest.getHouseTax();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2010 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand Down Expand Up @@ -121,4 +121,14 @@ public void addToWorld() {
public boolean isCompleted(final Player player) {
return HouseUtilities.getPlayersHouse(player)!=null;
}

/**
* Retrieves house tax manager.
*
* @return
* {@code HouseTax} instance.
*/
public HouseTax getHouseTax() {
return houseTax;
}
}
10 changes: 5 additions & 5 deletions src/games/stendhal/server/maps/quests/houses/HouseTax.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
/**
* House tax, and confiscation of houses.
*/
class HouseTax implements TurnListener {
public class HouseTax implements TurnListener {
/** The base amount of tax per month. */
protected static final int BASE_TAX = 1000;

Expand All @@ -67,7 +67,7 @@ class HouseTax implements TurnListener {

private long previouslyChecked = 0;

public HouseTax() {
HouseTax() {
setupTaxman();
SingletonRepository.getTurnNotifier().notifyInSeconds(TAX_CHECKING_PERIOD, this);
}
Expand All @@ -88,7 +88,7 @@ protected int getTaxDebt(final HousePortal portal) {
* @param periods the number of months the player has to pay at once
* @return the amount of debt
*/
private int getTaxDebt(final int periods) {
public int getTaxDebt(final int periods) {
int debt = 0;

for (int i = 0; i < periods; i++) {
Expand All @@ -104,7 +104,7 @@ private int getTaxDebt(final int periods) {
* @param player the player to be checked
* @return number of periods
*/
protected int getUnpaidTaxPeriods(final Player player) {
public int getUnpaidTaxPeriods(final Player player) {
final HousePortal portal = HouseUtilities.getPlayersHouse(player);
int payments = 0;

Expand All @@ -120,7 +120,7 @@ protected int getUnpaidTaxPeriods(final Player player) {
* @param portal the portal to be checked
* @return number of periods
*/
private int getUnpaidTaxPeriods(final HousePortal portal) {
public int getUnpaidTaxPeriods(final HousePortal portal) {
final int timeDiffSeconds = (int) ((System.currentTimeMillis() - portal.getExpireTime()) / 1000);
return Math.max(0, timeDiffSeconds / TAX_PAYMENT_PERIOD);
}
Expand Down
21 changes: 19 additions & 2 deletions src/games/stendhal/server/maps/quests/houses/HouseUtilities.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2023 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand Down Expand Up @@ -58,7 +58,7 @@ public static void clearCache() {
* @return portal to the house owned by the player, or <code>null</code>
* if he does not own one.
*/
protected static HousePortal getPlayersHouse(final Player player) {
public static HousePortal getPlayersHouse(final Player player) {
if (player.hasQuest(HOUSE_QUEST_SLOT)) {
final String claimedHouse = player.getQuest(HOUSE_QUEST_SLOT);

Expand Down Expand Up @@ -114,6 +114,23 @@ protected static HousePortal getHousePortal(final int houseNumber) {
return null;
}

/**
* Find a portal corresponding to a house ID.
*
* @param doorId
* House portal ID.
* @return
* The portal to the house or {@code null} if no such house exists.
*/
public static HousePortal getHousePortal(final String doorId) {
for (final HousePortal portal: getHousePortals()) {
if (doorId.equals(portal.getDoorId())) {
return portal;
}
}
return null;
}

/**
* Get a list of all house portals available to players.
*
Expand Down
Loading

0 comments on commit 2f39a03

Please sign in to comment.