add illegal only option to vendor filter
This commit is contained in:
@@ -11,6 +11,7 @@ public class VendorFilter {
|
||||
|
||||
private boolean disable;
|
||||
private boolean skipIllegal;
|
||||
private boolean illegalOnly;
|
||||
private boolean dontBuy;
|
||||
private boolean dontSell;
|
||||
private final Collection<Item> buyExcludes;
|
||||
@@ -20,6 +21,7 @@ public class VendorFilter {
|
||||
buyExcludes = new ArrayList<>();
|
||||
sellExcludes = new ArrayList<>();
|
||||
skipIllegal = false;
|
||||
illegalOnly = false;
|
||||
}
|
||||
|
||||
public boolean isDisable() {
|
||||
@@ -38,6 +40,14 @@ public class VendorFilter {
|
||||
this.skipIllegal = skipIllegal;
|
||||
}
|
||||
|
||||
public boolean isIllegalOnly() {
|
||||
return illegalOnly;
|
||||
}
|
||||
|
||||
public void setIllegalOnly(boolean illegalOnly) {
|
||||
this.illegalOnly = illegalOnly;
|
||||
}
|
||||
|
||||
public boolean isDontBuy() {
|
||||
return dontBuy;
|
||||
}
|
||||
@@ -91,17 +101,17 @@ public class VendorFilter {
|
||||
if (skipIllegal && offer.isIllegal()) return true;
|
||||
switch (offer.getType()) {
|
||||
case SELL: return dontSell || sellExcludes.contains(offer.getItem());
|
||||
case BUY: return dontBuy || buyExcludes.contains(offer.getItem());
|
||||
case BUY: return dontBuy || (illegalOnly && !offer.isIllegal()) || buyExcludes.contains(offer.getItem());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFiltered(Vendor vendor, Item item, OFFER_TYPE offerType){
|
||||
if (disable) return false;
|
||||
if (skipIllegal && (item.isIllegal(vendor))) return true;
|
||||
if (skipIllegal && item.isIllegal(vendor)) return true;
|
||||
switch (offerType) {
|
||||
case SELL: return dontSell || sellExcludes.contains(item);
|
||||
case BUY: return dontBuy || buyExcludes.contains(item);
|
||||
case BUY: return dontBuy || (illegalOnly && !item.isIllegal(vendor)) || buyExcludes.contains(item);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class FiltersStore {
|
||||
private static final String DEFAULT_VENDOR_FILTER_KEY = "default";
|
||||
private static final String VENDOR_FILTERS_FIELD = "stations";
|
||||
private static final String LEGAL_ONLY_FIELD = "legalOnly";
|
||||
private static final String SELL_ILLEGAL_ONLY_FIELD = "illegalOnly";
|
||||
private static final String DONT_SELL_FIELD = "notSell";
|
||||
private static final String DONT_BUY_FIELD = "notBuy";
|
||||
private static final String SELL_FILTER_FIELD = "excludeSell";
|
||||
@@ -95,6 +96,7 @@ public class FiltersStore {
|
||||
private void write(String key, VendorFilter filter, JsonGenerator generator) throws IOException {
|
||||
generator.writeObjectFieldStart(key);
|
||||
generator.writeBooleanField(DISABLE_FIELD, filter.isDisable());
|
||||
generator.writeBooleanField(SELL_ILLEGAL_ONLY_FIELD, filter.isIllegalOnly());
|
||||
generator.writeBooleanField(LEGAL_ONLY_FIELD, filter.isSkipIllegal());
|
||||
generator.writeBooleanField(DONT_SELL_FIELD, filter.isDontSell());
|
||||
generator.writeBooleanField(DONT_BUY_FIELD, filter.isDontBuy());
|
||||
@@ -196,6 +198,7 @@ public class FiltersStore {
|
||||
filter.setDisable(node.get(DISABLE_FIELD).asBoolean());
|
||||
filter.setSkipIllegal(node.get(LEGAL_ONLY_FIELD).asBoolean());
|
||||
filter.dontSell(node.get(DONT_SELL_FIELD).asBoolean());
|
||||
filter.setIllegalOnly(node.get(SELL_ILLEGAL_ONLY_FIELD).asBoolean());
|
||||
filter.dontBuy(node.get(DONT_BUY_FIELD).asBoolean());
|
||||
Iterator<JsonNode> iterator = node.get(SELL_FILTER_FIELD).elements();
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
@@ -57,6 +57,7 @@ public class FiltersStoreTest extends Assert {
|
||||
VendorFilter vendorFilter = new VendorFilter();
|
||||
vendorFilter.setDisable(true);
|
||||
vendorFilter.setSkipIllegal(true);
|
||||
vendorFilter.setIllegalOnly(true);
|
||||
vendorFilter.dontBuy(true);
|
||||
vendorFilter.addSellExclude(gold);
|
||||
vendorFilter.addSellExclude(tea);
|
||||
@@ -102,6 +103,7 @@ public class FiltersStoreTest extends Assert {
|
||||
|
||||
private void assertFilter(VendorFilter expected, VendorFilter actual){
|
||||
assertEquals(expected.isDisable(), actual.isDisable());
|
||||
assertEquals(expected.isIllegalOnly(), actual.isIllegalOnly());
|
||||
assertEquals(expected.isSkipIllegal(), actual.isSkipIllegal());
|
||||
assertEquals(expected.isDontBuy(), actual.isDontBuy());
|
||||
assertEquals(expected.isDontSell(), actual.isDontSell());
|
||||
|
||||
Reference in New Issue
Block a user