Skip to content

Commit

Permalink
grant template
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Jul 5, 2024
1 parent 18c0be6 commit 89667aa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ protected void setValuesBase(PreparedStatement stmt) throws SQLException {
stmt.setInt(11, this.getMaxGranterTotal());
stmt.setLong(12, this.getDateCreated());
stmt.setLong(13, this.getExpire());
stmt.setLong(15, this.getDecay());
stmt.setBoolean(14, this.allowsIgnore());
stmt.setLong(14, this.getDecay());
stmt.setBoolean(15, this.allowsIgnore());
stmt.setBoolean(16, this.isRepeatable());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,13 @@ public Map<Integer, CityBuild> parse(DBNation receiver, String value) {
}
// ensure no buildings are negative
for (Building building : Buildings.values()) {
if (jc.getBuilding(building) < 0) {
int amt = jc.getBuilding(building);
if (amt < 0) {
throw new IllegalArgumentException("Build has negative " + building.name() + " buildings");
}
if (amt > building.getCap(f -> true)) {
throw new IllegalArgumentException("Build has more than " + building.getCap(f -> true) + " " + building.name() + " buildings");
}
}
// no more than 2 power plants
if (jc.getBuilding(Buildings.NUCLEAR_POWER) > 2) {
Expand All @@ -248,17 +252,17 @@ public Map<Integer, CityBuild> parse(DBNation receiver, String value) {
throw new IllegalArgumentException("Build has more than 8 oil power");
}
// 5,5,5,3 max military buildings
if (jc.getBuilding(Buildings.BARRACKS) > 5) {
throw new IllegalArgumentException("Build has more than 5 barracks");
if (jc.getBuilding(Buildings.BARRACKS) > Buildings.BARRACKS.cap(f -> true)) {
throw new IllegalArgumentException("Build has more than " + Buildings.BARRACKS.cap(f -> true) + " barracks");
}
if (jc.getBuilding(Buildings.FACTORY) > 5) {
throw new IllegalArgumentException("Build has more than 5 factories");
if (jc.getBuilding(Buildings.FACTORY) > Buildings.FACTORY.cap(f -> true)) {
throw new IllegalArgumentException("Build has more than " + Buildings.FACTORY.cap(f -> true) + " factories");
}
if (jc.getBuilding(Buildings.HANGAR) > 5) {
throw new IllegalArgumentException("Build has more than 5 hangars");
if (jc.getBuilding(Buildings.HANGAR) > Buildings.HANGAR.cap(f -> true)) {
throw new IllegalArgumentException("Build has more than " + Buildings.HANGAR.cap(f -> true) + " hangars");
}
if (jc.getBuilding(Buildings.DRYDOCK) > 3) {
throw new IllegalArgumentException("Build has more than 3 drydocks");
if (jc.getBuilding(Buildings.DRYDOCK) > Buildings.DRYDOCK.cap(f -> true)) {
throw new IllegalArgumentException("Build has more than " + Buildings.DRYDOCK.cap(f -> true) + " drydocks");
}
}
// return map of city and build
Expand Down Expand Up @@ -322,6 +326,22 @@ public Boolean apply(DBNation receiver) {
}
}));

list.add(new Grant.Requirement("Cannot build in " + (receiver == null ? "{continent}" : receiver.getContinent()), false, new Function<DBNation, Boolean>() {
@Override
public Boolean apply(DBNation receiver) {
for (CityBuild value : parsed.values()) {
JavaCity city = new JavaCity(value);
for (Building building : Buildings.values()) {
int amt = city.getBuilding(building);
if (amt > 0 && !building.canBuild(receiver.getContinent())) {
return false;
}
}
}
return true;
}
}));

return list;
}

Expand Down

0 comments on commit 89667aa

Please sign in to comment.