Skip to content

Commit

Permalink
Add configurable scaling factor for sponsor map selection
Browse files Browse the repository at this point in the history
Signed-off-by: applenick <[email protected]>
  • Loading branch information
applenick committed Jul 1, 2024
1 parent afed870 commit a3b5dfb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/main/java/dev/pgm/community/requests/RequestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class RequestConfig extends FeatureConfigImpl {
private static final String MAX_TOKENS = SPONSORS + ".max-tokens";
private static final String REFUND = SPONSORS + ".refund";
private static final String MAP_COOLDOWN_MULTIPLY = SPONSORS + ".map-cooldown";
private static final String SCALE_FACTOR = SPONSORS + ".scale-factor";
private static final String LOWER_LIMIT_OFFSET = SPONSORS + ".lower-limit-offset";
private static final String UPPER_LIMIT_OFFSET = SPONSORS + ".upper-limit-offset";
private static final String SUPER_VOTE = KEY + ".super-votes";
Expand All @@ -47,6 +48,8 @@ public class RequestConfig extends FeatureConfigImpl {

private int mapCooldownMultiply; // # to multiply match length by to determine cooldown

private double scaleFactor; // Scaling factor for adjusting the upper bound of map size selection

private int lowerLimitOffset; // Offset to apply on match end to lower map size bound
private int upperLimitOffset; // Offset to apply on match end to upper map size bound

Expand Down Expand Up @@ -125,6 +128,10 @@ public boolean isSuperVoteBroadcast() {
return superVoteBroadcast;
}

public double getScaleFactor() {
return scaleFactor;
}

@Override
public void reload(Configuration config) {
super.reload(config);
Expand All @@ -137,6 +144,7 @@ public void reload(Configuration config) {
this.maxQueue = config.getInt(SPONSORS_LIMIT);
this.refund = config.getBoolean(REFUND);
this.mapCooldownMultiply = config.getInt(MAP_COOLDOWN_MULTIPLY);
this.scaleFactor = config.getDouble(SCALE_FACTOR);
this.lowerLimitOffset = config.getInt(LOWER_LIMIT_OFFSET);
this.upperLimitOffset = config.getInt(UPPER_LIMIT_OFFSET);
this.superVoteEnabled = config.getBoolean(SUPER_VOTE_ENABLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,9 @@ public int queueIndex(SponsorRequest request) {
@Override
public MapSizeBounds getCurrentMapSizeBounds() {
return PGMUtils.getMapSizeBounds(
getRequestConfig().getLowerLimitOffset(), getRequestConfig().getUpperLimitOffset());
getRequestConfig().getLowerLimitOffset(),
getRequestConfig().getUpperLimitOffset(),
getRequestConfig().getScaleFactor());
}

private boolean isACooldownVariant(MapInfo map) {
Expand Down Expand Up @@ -832,7 +834,10 @@ private boolean isPartyActive() {

private boolean isMapSizeAllowed(MapInfo map) {
return PGMUtils.isMapSizeAllowed(
map, getRequestConfig().getLowerLimitOffset(), getRequestConfig().getUpperLimitOffset());
map,
getRequestConfig().getLowerLimitOffset(),
getRequestConfig().getUpperLimitOffset(),
getRequestConfig().getScaleFactor());
}

private void sendWrongSizeMapError(SponsorRequest request) {
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/dev/pgm/community/utils/PGMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ public int getUpperBound() {
}
}

public static boolean isMapSizeAllowed(MapInfo map, int lowerBoundOffset, int upperBoundOffset) {
public static boolean isMapSizeAllowed(
MapInfo map, int lowerBoundOffset, int upperBoundOffset, double scaleFactor) {
if (isPGMEnabled()) {
MapSizeBounds bounds = getMapSizeBounds(lowerBoundOffset, upperBoundOffset);
MapSizeBounds bounds = getMapSizeBounds(lowerBoundOffset, upperBoundOffset, scaleFactor);

int max = getMapMaxSize(map);

Expand All @@ -100,7 +101,8 @@ public static int getMapMaxSize(MapInfo map) {
return map.getMaxPlayers().stream().reduce(0, Integer::sum);
}

public static MapSizeBounds getMapSizeBounds(int lowerBoundOffset, int upperBoundOffset) {
public static MapSizeBounds getMapSizeBounds(
int lowerBoundOffset, int upperBoundOffset, double scalingFactor) {
if (!isPGMEnabled()) return new MapSizeBounds(0, 150);

Match match = getMatch();
Expand All @@ -110,7 +112,7 @@ public static MapSizeBounds getMapSizeBounds(int lowerBoundOffset, int upperBoun
int total = participants + (observers / 4);

int lowerBound = participants;
int upperBound = Math.max(5, total + (int) (total * 0.35));
int upperBound = Math.max(5, total + (int) (total * scalingFactor));

if (isFinished) {
lowerBound = Math.max(0, lowerBound - lowerBoundOffset);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ requests:
weekly-tokens: 1 # Amount of tokens given on a weekly basis (community.token.weekly perm)
max-tokens: 7 # Maximum amount of tokens an account can collect
refund: true # Tokens are refunded when map vote is successful
scale-factor: 0.45 # Scaling factor for adjusting the upper bound of map size selection

# Sponsor bound offset used to modify avaiable maps at the end of each match
lower-limit-offset: 4 # Subtracted from the current minimum
Expand Down

0 comments on commit a3b5dfb

Please sign in to comment.