Skip to content

Commit

Permalink
Free guards changes finished, hopefully.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mthec committed Jul 1, 2019
1 parent 03378c3 commit 4bd3aaf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void sendQuestion() {
float left = (float)plan.moneyLeft / (float)plan.getMonthlyCost();
buf.append("text{text=\"This means that the upkeep should last for about " + left * 28.0F + " days.\"}");
if (Servers.localServer.PVPSERVER || Servers.localServer.id == 3) {
buf.append("text{text=\"A drain would cost " + Economy.getEconomy().getChangeFor(plan.getMoneyDrained()).getChangeString() + ".\"};");
buf.append("text{text=\"A drain would cost " + new Change(plan.getMoneyDrained()).getChangeShortString() + ".\"};");
long minimumDrain = 7500;
try {
minimumDrain = ReflectionUtil.getPrivateField(null, GuardPlan.class.getDeclaredField("minMoneyDrained"));
Expand All @@ -58,15 +58,15 @@ public void sendQuestion() {
logger.warning("Could not get minimum drain value.");
}
if (plan.moneyLeft < minimumDrain * 5) {
buf.append("text{type='bold';text='Since minimum drain is " + minimumDrain + " it may be drained to disband in less than 5 days.'}");
buf.append("text{type='bold';text='Since minimum drain is " + new Change(minimumDrain).getChangeShortString() + " it may be drained to disband in less than 5 days.'}");
}
}

buf.append("text{text=\"\"}");
}

if (Servers.localServer.isChallengeOrEpicServer()) {
buf.append("text{text=\"The only guard type is heavy guards. The running upkeep cost increases the more guards you have in a sort of ladder system. The first guards are cheaper than the last.\"};");
buf.append("text{text=\"The only guard type is heavy guards. The cost for hiring them is " + Villages.GUARD_COST_STRING + " and running upkeep cost increases the more guards you have in a sort of ladder system. The first guards are cheaper than the last.\"};");
buf.append("text{text=\"Make sure to review the cost for upkeep once you are done.\"};");
} else {
buf.append("text{text=\"The only guard type is heavy guards. The cost for hiring them is " + Villages.GUARD_COST_STRING + " and running upkeep is " + Villages.GUARD_UPKEEP_STRING + " per month.\"};");
Expand Down
2 changes: 1 addition & 1 deletion src/locale/UpkeepCosts.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ drain_modifier_increment_not_set=Could not set drain modifier increment for some
# 0 - tile cost, 1 - tile upkeep, 2 - free tiles, 3 - perimeter cost, 4 - perimeter upkeep, 5 - free perimeter,
# 6 - guards cost, 7 - guards upkeep, 8 - minimum upkeep, 9 - into upkeep, 10 - name change
# 11 - min_drain, 12 - max_drain_modifier, 13 - drain_modifier_increment
all_values=Upkeep costs are as follows: Tile %s, %s, %s free tiles - Perimeter %s, %s, %s free tiles - Guards %s, %s, %s free guards - Minimum %s - Into Upkeep %s - Name change %s\n\
all_values=Upkeep costs are as follows: Tile %s, %s, %s free tiles - Perimeter %s, %s, %s free tiles - Guards %s, %s, use Epic guard upkeep scaling %s, %s free guards - Minimum %s - Into Upkeep %s - Name change %s\n\
Draining values are as follows: Minimum drain %s, Maximum drain modifier %s, Drain modifier increment %s

load_properties_error=An error occurred when loading properties:
Expand Down
14 changes: 9 additions & 5 deletions src/mod/wurmonline/mods/upkeepcosts/GuardPlanStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public static Object getCostForGuards(Object o, Method method, Object[] args) {
int nonFreeGuards = (int)args[0];
try {
nonFreeGuards = Math.max(0, nonFreeGuards - Villages.class.getDeclaredField("FREE_GUARDS").getInt(null));
if (!Villages.class.getDeclaredField("EPIC_UPKEEP_SCALING").getBoolean(null)) {
return nonFreeGuards * Villages.GUARD_UPKEEP;
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -247,14 +250,14 @@ static Object parseGuardRentalQuestion(Object o, Method method, Object[] args) {
boolean takeFromBank = Boolean.parseBoolean(props.getProperty("use_bank"));
if (diff > 0) {
long moneyOver = plan.moneyLeft - plan.calculateMonthlyUpkeepTimeforType(0);
// TODO - Surely this isn't right? Uses non-epic upkeep as hiring cost and doesn't factor in guard upkeep in one month test. Or maybe it is just the heat.
if (moneyOver > (long)(10000 * diff)) {
long costForHire = Villages.GUARD_COST * diff;
if (moneyOver > costForHire) {
changed = true;
plan.changePlan(0, nums);
plan.updateGuardPlan(0, plan.moneyLeft - (long)(10000 * diff), nums);
} else if (takeFromBank && responder.getMoney() > (long)(10000 * diff)) {
plan.updateGuardPlan(0, plan.moneyLeft - costForHire, nums);
} else if (takeFromBank && responder.getMoney() > costForHire) {
try {
responder.setMoney(responder.getMoney() - (10000 * diff));
responder.setMoney(responder.getMoney() - costForHire);
changed = true;
plan.changePlan(0, nums);
plan.updateGuardPlan(0, plan.moneyLeft, nums);
Expand All @@ -264,6 +267,7 @@ static Object parseGuardRentalQuestion(Object o, Method method, Object[] args) {
return null;
}
} else {
// TODO - Not really true, as the cost comes after the check?
responder.getCommunicator().sendNormalServerMessage("There was not enough upkeep to increase the number of guards. Please make sure that there is at least one month of upkeep left after you hire the guards.");
}
} else if (diff < 0) {
Expand Down
32 changes: 32 additions & 0 deletions src/mod/wurmonline/mods/upkeepcosts/UpkeepCosts.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class UpkeepCosts implements WurmMod, Configurable, PreInitable, ServerSt
public long normal_guard_upkeep;
public long epic_guard_cost;
public long epic_guard_upkeep;
public boolean epic_guard_upkeep_scaling;
public long minimum_upkeep;
public long into_upkeep;
public long name_change;
Expand All @@ -67,6 +68,7 @@ protected void setDefaults() {
normal_guard_upkeep = 10000;
epic_guard_cost = 30000;
epic_guard_upkeep = 30000;
epic_guard_upkeep_scaling = true;
minimum_upkeep = 10000;
into_upkeep = 30000;
name_change = 50000;
Expand Down Expand Up @@ -118,6 +120,14 @@ else if ((field.getType().isAssignableFrom(float.class))) {
}
field.set(this, value);
}
else if ((field.getType().isAssignableFrom(boolean.class))) {
String property = properties.getProperty(field.getName());
if (property == null || property.equals("")) {
continue;
}
boolean value = Boolean.valueOf(property);
field.set(this, value);
}
} catch (IllegalAccessException ex) {
ex.printStackTrace();
System.exit(-1);
Expand Down Expand Up @@ -167,10 +177,22 @@ public void onServerStarted() {
if (local.isChallengeOrEpicServer()) {
Villages.GUARD_COST = epic_guard_cost;
Villages.GUARD_UPKEEP = epic_guard_upkeep;
try {
Villages.class.getDeclaredField("EPIC_UPKEEP_SCALING").set(null, epic_guard_upkeep_scaling);
} catch (IllegalAccessException | NoSuchFieldException ex) {
logger.warning(messages.getString("epic_upkeep_scaling_not_set"));
ex.printStackTrace();
}
}
else {
Villages.GUARD_COST = normal_guard_cost;
Villages.GUARD_UPKEEP = normal_guard_upkeep;
try {
Villages.class.getDeclaredField("EPIC_UPKEEP_SCALING").set(null, false);
} catch (IllegalAccessException | NoSuchFieldException ex) {
logger.warning(messages.getString("epic_upkeep_scaling_not_set"));
ex.printStackTrace();
}
}

Villages.GUARD_COST_STRING = (new Change(Villages.GUARD_COST)).getChangeString();
Expand Down Expand Up @@ -303,6 +325,12 @@ void logValues () {
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
}
String EPIC_UPKEEP_SCALING = "?";
try {
EPIC_UPKEEP_SCALING = String.valueOf(Villages.class.getDeclaredField("EPIC_UPKEEP_SCALING").getBoolean(null));
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
}
String minMoneyDrained = "?";
try {
minMoneyDrained = String.valueOf(GuardPlan.class.getDeclaredField("minMoneyDrained").getLong(null));
Expand Down Expand Up @@ -332,6 +360,7 @@ void logValues () {
FREE_PERIMETER,
Villages.GUARD_COST_STRING,
Villages.GUARD_UPKEEP_STRING,
EPIC_UPKEEP_SCALING,
FREE_GUARDS,
Villages.MINIMUM_UPKEEP_STRING,
new Change(VillageFoundationQuestion.MINIMUM_LEFT_UPKEEP).getChangeString(),
Expand Down Expand Up @@ -401,6 +430,9 @@ public void preInit() {
CtField freeGuards = new CtField(CtClass.intType, "FREE_GUARDS", villages);
freeGuards.setModifiers(Modifier.setPublic(Modifier.STATIC));
villages.addField(freeGuards);
CtField epicScaling = new CtField(CtClass.booleanType, "EPIC_UPKEEP_SCALING", villages);
epicScaling.setModifiers(Modifier.setPublic(Modifier.STATIC));
villages.addField(epicScaling);


CtClass guardPlan = pool.get("com.wurmonline.server.villages.GuardPlan");
Expand Down
3 changes: 2 additions & 1 deletion src/upkeepcosts.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ name_change=50000
normal_guard_cost=20000
normal_guard_upkeep=10000
epic_guard_cost=30000
epic_guard_upkeep=30000
epic_guard_upkeep=10000
epic_guard_upkeep_scaling=true

# Number of free tiles
free_tiles=0
Expand Down

0 comments on commit 4bd3aaf

Please sign in to comment.