public LinkedList<String> getDepositExceptions() {
LinkedList<String> neededItems = new LinkedList<String>();
if (Config.enableAttPot){
neededItems.add("Attack potion(4)");
}
if (Config.enableStrPot){
neededItems.add("Strength potion(4)");
}
if (Config.enableSupAttPot){
neededItems.add("Super attack(4)");
}
if (Config.enableSupStrPot){
neededItems.add("Super strength(4)");
}
if (Config.enableCombatPot){
neededItems.add("Combat potion(4)");
}
neededItems.add("Lobster");
return neededItems;
}
This can be optimised in many ways. Running this is going to be more expensive than something like this:
public enum Supplies {
LOBSTER("Lobster", 15),
ATTACK_POT("Attack potion(4)", 1),
;
private String name;
private int amt;
Supplies(String name, int amt) {
this.name = name;
this.amt = amt;
}
public int getAmount() { return amt; }
public String getName() { return name; }
}
//on start
private List<Supplies> supplyList = new ArrayList<>();
if (Config.isAttackEnabled) supplyList.add(Supplies.ATTACK_POT);
//...
Then you can do something like:
//bank
for (Item item : getInventory().getItems()) {
for (Supplies supply : supplyList) if (!supply.getName().equalsIgnoreCase(item.getName())) item.interact("Deposit-All");
}
You could have a functional interface in your enum and have a static populate(Script) method, kinda looking like:
public interface Functional<T> { public boolean perform(T param); }
//enum
LOBSTER("Lobster", 15, (script) -> true),
ATTACK_POT("Attack potion(4)", 1, (script) -> Config.isAttackEnabled),
COINS("Coins", 10, (script) -> script.getInventory().getAmount("Coins") < 10), //al kharid gate?
;
private String name;
private int amt;
private Functional<Script> condition;
public Functional<Script> getCondition() { return condition; }
public static List<Supplies> populate(Script instance) {
List<Supplies> vals = new ArrayList<>();
for (Supplies supply : values()) if (supply.getCondition().perform(instance)) vals.add(supply);
return vals;
}
List<Supplies> supplyList = Supplies.populate(this);
Obviously, running these conditions at the start would mean that they wouldn't run again (unless you did populate(Script) again), but it's a nice little way to try and keep things a little organised.