December 30, 20169 yr The issue is that the tabs don't actually switch randomly. Code is compatible but not functioning right. private static int rngTab = random(0, 125); private enum Tabs { ATTACK(0, Tab.ATTACK); private int chance; private Tab tab; public int getChance() { return chance; } public Tab getTab() { return tab; } private static Set<Tabs> tab_set = Collections.unmodifiableSet(EnumSet.allOf(Tabs.class)); public static Optional<Tabs> forTabs(int rng) { return tab_set.stream().filter(Objects::nonNull).filter(tabs -> tabs.getChance() == rng).findAny(); } public static void randomTabs(Script script, int chance) { if (rngTab == forTabs(chance).get().getChance()) { script.getTabs().open(forTabs(chance).get().getTab()); } } private Tabs(int chance, Tab tab) { this.chance = chance; this.tab = tab; } } if (getState() == BotState.FISHING) { Tabs.randomTabs(this, 0); return; }
December 30, 20169 yr getTabs().open(Tab.values()[random(0, Tab.values().length-1)]); ^ opens a random tab Edited December 30, 20169 yr by Imateamcape
December 30, 20169 yr Author getTabs().open(Tab.values()[random(0, Tab.values().length-1)]); ^ opens a random tab omg I had a similar thought like this, embarrassing -.-" Thanks though
December 30, 20169 yr Author So much overkill in your code x) I know it's overkill, but little better than using switch.
December 30, 20169 yr The issue is that the tabs don't actually switch randomly. Code is compatible but not functioning right. private static int rngTab = random(0, 125); private enum Tabs { ATTACK(0, Tab.ATTACK); private int chance; private Tab tab; public int getChance() { return chance; } public Tab getTab() { return tab; } private static Set<Tabs> tab_set = Collections.unmodifiableSet(EnumSet.allOf(Tabs.class)); public static Optional<Tabs> forTabs(int rng) { return tab_set.stream().filter(Objects::nonNull).filter(tabs -> tabs.getChance() == rng).findAny(); } public static void randomTabs(Script script, int chance) { if (rngTab == forTabs(chance).get().getChance()) { script.getTabs().open(forTabs(chance).get().getTab()); } } private Tabs(int chance, Tab tab) { this.chance = chance; this.tab = tab; } } if (getState() == BotState.FISHING) { Tabs.randomTabs(this, 0); return; } I know it's overkill, but little better than using switch. Here is something a tad bit more clean and re-usable/generic import java.util.Random; public class EnumUtil { public static <T extends Enum<?>> T getRandomEnumValue(Class<T> clazz, Random random) { int constants = clazz.getEnumConstants().length; if(constants == 0) { throw new IllegalArgumentException("Enum class has no constants"); } return clazz.getEnumConstants()[random.nextInt(constants)]; } public static void main(String[] args) { Random random = new Random(); Tab tab = EnumUtil.getRandomEnumValue(Tab.class, random); } }
Create an account or sign in to comment