Optimize shadow siege request/permit gain

This commit is contained in:
Melledy
2026-07-21 04:48:11 -07:00
parent 9c23fc1011
commit a1ad265420
3 changed files with 17 additions and 15 deletions
@@ -58,6 +58,8 @@ public class GameConstants {
public static final int TRACE_HUNT_TOKEN_ID = 37; public static final int TRACE_HUNT_TOKEN_ID = 37;
public static final int TRACE_HUNT_REQUEST_ITEM_ID = 38; public static final int TRACE_HUNT_REQUEST_ITEM_ID = 38;
public static final int TRACE_HUNT_PERMIT_ITEM_ID = 39; public static final int TRACE_HUNT_PERMIT_ITEM_ID = 39;
public static final int TRACE_HUNT_MAX_DAILY_REQUESTS = 20;
public static final int TRACE_HUNT_MAX_DAILY_PERMITS = 4;
public static final int[] TRACE_HUNT_TRACE_IDS = {21, 22, 23, 31, 41}; public static final int[] TRACE_HUNT_TRACE_IDS = {21, 22, 23, 31, 41};
public static final int TRACE_HUNT_MAX_TRACE_PROGRESS = 10_000; public static final int TRACE_HUNT_MAX_TRACE_PROGRESS = 10_000;
public static final int TRACE_HUNT_MAX_HUNT_PROGRESS = 10_000; public static final int TRACE_HUNT_MAX_HUNT_PROGRESS = 10_000;
@@ -591,10 +591,10 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
} }
} }
case TraceRequest -> { case TraceRequest -> {
this.getPlayer().getTraceHuntManager().addTraceRequests(amount, change, true); this.getPlayer().getTraceHuntManager().addTraceRequests(amount, 0, change, true);
} }
case HuntPermit -> { case HuntPermit -> {
this.getPlayer().getTraceHuntManager().addHuntPermits(amount, change, true); this.getPlayer().getTraceHuntManager().addHuntPermits(amount, 0, change, true);
} }
default -> { default -> {
// Not implemented // Not implemented
@@ -95,8 +95,10 @@ public class TraceHuntManager extends PlayerManager implements GameDatabaseObjec
} }
public void onSpendEnergy(int amount, PlayerChangeInfo change) { public void onSpendEnergy(int amount, PlayerChangeInfo change) {
// Save flag // Optimization: Skip if we already have the max daily requests/permits
boolean save = true; if (this.dailyRequests >= GameConstants.TRACE_HUNT_MAX_DAILY_REQUESTS && this.dailyPermits >= GameConstants.TRACE_HUNT_MAX_DAILY_PERMITS) {
return;
}
// Calculate daily request/permits to add // Calculate daily request/permits to add
this.dailyRequestProgress += amount; this.dailyRequestProgress += amount;
@@ -110,30 +112,28 @@ public class TraceHuntManager extends PlayerManager implements GameDatabaseObjec
// Add // Add
if (newRequests > 0) { if (newRequests > 0) {
int max = Math.max(Math.min(60 - this.getTraceRequests(), 20 - this.getDailyRequests()), 0); int max = Math.max(Math.min(60 - this.getTraceRequests(), GameConstants.TRACE_HUNT_MAX_DAILY_REQUESTS - this.getDailyRequests()), 0);
int add = Math.min(newRequests, max); int add = Math.min(newRequests, max);
if (add > 0) { if (add > 0) {
this.dailyRequests += add; this.dailyRequests += add;
this.addTraceRequests(add, change, false); this.addTraceRequests(add, add, change, false);
} }
} }
if (newPermits > 0) { if (newPermits > 0) {
int max = Math.max(Math.min(12 - this.getHuntPermits(), 4 - this.getDailyPermits()), 0); int max = Math.max(Math.min(12 - this.getHuntPermits(), GameConstants.TRACE_HUNT_MAX_DAILY_PERMITS - this.getDailyPermits()), 0);
int add = Math.min(newPermits, max); int add = Math.min(newPermits, max);
if (add > 0) { if (add > 0) {
this.dailyPermits += add; this.dailyPermits += add;
this.addHuntPermits(add, change, false); this.addHuntPermits(add, add, change, false);
} }
} }
// Save to database // Save to database
if (save) {
this.save(); this.save();
} }
}
public void resetDailyQuota() { public void resetDailyQuota() {
// Reset progress and limits // Reset progress and limits
@@ -146,7 +146,7 @@ public class TraceHuntManager extends PlayerManager implements GameDatabaseObjec
this.save(); this.save();
} }
public void addTraceRequests(int amount, PlayerChangeInfo change, boolean shouldSave) { public void addTraceRequests(int amount, int daily, PlayerChangeInfo change, boolean shouldSave) {
// Save old value to check if we need to save this to the database // Save old value to check if we need to save this to the database
int oldValue = this.traceRequests; int oldValue = this.traceRequests;
@@ -162,12 +162,12 @@ public class TraceHuntManager extends PlayerManager implements GameDatabaseObjec
var proto = TraceHuntItem.newInstance() var proto = TraceHuntItem.newInstance()
.setTid(GameConstants.TRACE_HUNT_REQUEST_ITEM_ID) .setTid(GameConstants.TRACE_HUNT_REQUEST_ITEM_ID)
.setGrantQty(this.getTraceRequests() - oldValue) .setGrantQty(this.getTraceRequests() - oldValue)
.setDailyCount(this.getDailyRequests()); .setDailyCount(daily);
change.add(proto); change.add(proto);
} }
public void addHuntPermits(int amount, PlayerChangeInfo change, boolean shouldSave) { public void addHuntPermits(int amount, int daily, PlayerChangeInfo change, boolean shouldSave) {
// Save old value to check if we need to save this to the database // Save old value to check if we need to save this to the database
int oldValue = this.huntPermits; int oldValue = this.huntPermits;
@@ -183,7 +183,7 @@ public class TraceHuntManager extends PlayerManager implements GameDatabaseObjec
var proto = TraceHuntItem.newInstance() var proto = TraceHuntItem.newInstance()
.setTid(GameConstants.TRACE_HUNT_PERMIT_ITEM_ID) .setTid(GameConstants.TRACE_HUNT_PERMIT_ITEM_ID)
.setGrantQty(this.getHuntPermits() - oldValue) .setGrantQty(this.getHuntPermits() - oldValue)
.setDailyCount(this.getDailyPermits()); .setDailyCount(daily);
change.add(proto); change.add(proto);
} }