import impsoft.nexus.bots.color.scriptable.ColorRandom; import impsoft.nexus.bots.color.ColorBot; import impsoft.nexus.bots.color.scriptable.interfaces.AutoPaint; import impsoft.nexus.bots.color.scriptable.interfaces.ChatListener; import impsoft.nexus.bots.color.threads.ListenerThread; FUCK import java.util.regex.*; import java.util.HashMap; import java.awt.Graphics; /** Statistica Anti-Random * * A random designed to collect and paint statistics based on chat messages. * @see Statistica.PATTERNS to add more statistic types * * @author regecks * 24 august 2007 * nexus 16.64 * * 16/08/07 - first rev */ public class Statistica extends ColorRandom implements AutoPaint, ChatListener { /** * The Statistics to record during the game. * * Format: EVENT_ID PATTERN PAINT * EVENT_ID - Not really used at this point, but please unique and descriptive * PATTERN - A regular expression that matches EXACTLY the chat message being recorded * PAINT - The string to paint representing the events, $x = amount of matches thusfar */ private Statistic[] PATTERNS = { Statistic.create("LOGS_GAINED", "You get some (\\w+ )?logs\\.", "Logs gained: $x"), Statistic.create("AXE_SWUNG", "You \\w+ your \\w+ at the \\w+\\.", "Axe Swings: $x"), Statistic.create("ORE_GAINED", "You manage to mine some \\w+\\.", "Ore mined: $x"), }; /** Whether to have this random enabled at all */ private static final boolean ENABLED = true; /** The maximum statistic types that can proc before being maxed out (screen space etc). */ private static final int MAX_STATISTIC_TYPES = 10; public Statistica(ColorBot cb) { super(cb); } public void random() throws InterruptedException { } public boolean startUp() throws InterruptedException { return false;/*ENABLED && theMiddleMan.isLoggedIn();*/ } public void paint(Graphics g) { if(!ENABLED) return; g.setColor(java.awt.Color.WHITE); g.drawString("Statistica Count: " + PATTERNS.length, 10, 50); int startY = 75; for(int i = 0; i < PATTERNS.length && i <= MAX_STATISTIC_TYPES; i++) { Statistic s = PATTERNS[i]; if(s != null && s.count > 0) { g.drawString(s.paint.replaceAll("\\$x", String.valueOf(s.count)), 10, startY); startY += 15; } } } public void chat(String message) throws InterruptedException { for(Statistic s : PATTERNS) { if(s == null) continue; Matcher m = s.pattern.matcher(message); while(m.find()) s.count++; } } static class Statistic { private String name; private Pattern pattern; private String paint; private int count; private Statistic() { } public static Statistic create(String name, String match, String paint) { Statistic s = new Statistic(); try { s.pattern = Pattern.compile(match); } catch(Exception e) { System.err.println("Error compiling " + match); System.err.println(e.toString()); return null; } s.name = name; s.paint = paint; return s; } } }